blob: 9f0c0d98a8f79bec4da302ecf5e6550fcdcc12fd [file] [log] [blame]
Sean Paul98e73c82015-06-24 14:38:49 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_DRM_DISPLAY_COMPOSITOR_H_
18#define ANDROID_DRM_DISPLAY_COMPOSITOR_H_
19
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030020#include <hardware/hardware.h>
21#include <hardware/hwcomposer.h>
Sean Paul98e73c82015-06-24 14:38:49 -070022#include <pthread.h>
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030023
Roman Stratiienkod21071f2021-03-09 21:56:50 +020024#include <functional>
Zach Reizner92f8e632015-10-12 17:47:13 -070025#include <memory>
Sean Paul98e73c82015-06-24 14:38:49 -070026#include <sstream>
Zach Reizner92f8e632015-10-12 17:47:13 -070027#include <tuple>
Sean Paul98e73c82015-06-24 14:38:49 -070028
Roman Stratiienko13cc3662020-08-29 21:35:39 +030029#include "DrmDisplayComposition.h"
Roman Stratiienkob2e9fe22020-10-03 10:52:36 +030030#include "Planner.h"
Roman Stratiienko13cc3662020-08-29 21:35:39 +030031#include "drm/ResourceManager.h"
32#include "drm/VSyncWorker.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030033#include "drmhwcomposer.h"
Sean Paul98e73c82015-06-24 14:38:49 -070034
35namespace android {
36
37class DrmDisplayCompositor {
38 public:
39 DrmDisplayCompositor();
40 ~DrmDisplayCompositor();
41
Roman Stratiienkoe8c06792021-09-30 10:09:31 +030042 auto Init(ResourceManager *resource_manager, int display) -> int;
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +020043
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010044 std::unique_ptr<DrmDisplayComposition> CreateInitializedComposition() const;
Sean Pauled45a8e2017-02-28 13:17:34 -050045 int ApplyComposition(std::unique_ptr<DrmDisplayComposition> composition);
Rob Herring4f6c62e2018-05-17 14:33:02 -050046 int TestComposition(DrmDisplayComposition *composition);
Sean Paul98e73c82015-06-24 14:38:49 -070047 int Composite();
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030048 void ClearDisplay();
Roman Stratiienko0fade372021-02-20 13:59:55 +020049 UniqueFd TakeOutFence() {
50 if (!active_composition_) {
51 return UniqueFd();
52 }
53 return std::move(active_composition_->out_fence_);
Matteo Franchinc56eede2019-12-03 17:10:38 +000054 }
Sean Paul98e73c82015-06-24 14:38:49 -070055
Zach Reizner92f8e632015-10-12 17:47:13 -070056 std::tuple<uint32_t, uint32_t, int> GetActiveModeResolution();
57
Sean Paul98e73c82015-06-24 14:38:49 -070058 private:
Sean Paul35301f42015-11-17 14:46:56 -050059 struct ModeState {
60 bool needs_modeset = false;
61 DrmMode mode;
62 uint32_t blob_id = 0;
63 uint32_t old_blob_id = 0;
64 };
65
Sean Paul98e73c82015-06-24 14:38:49 -070066 DrmDisplayCompositor(const DrmDisplayCompositor &) = delete;
67
Roman Stratiienko74774712021-02-05 16:32:47 +020068 int CommitFrame(DrmDisplayComposition *display_comp, bool test_only);
Sean Pauldb7a17d2015-06-24 18:46:05 -070069 int ApplyDpms(DrmDisplayComposition *display_comp);
Sean Paul7b1e4bc2015-10-13 15:47:22 -040070 int DisablePlanes(DrmDisplayComposition *display_comp);
Sean Paul98e73c82015-06-24 14:38:49 -070071
Haixia Shidda2fab2015-10-22 18:12:49 -070072 void ApplyFrame(std::unique_ptr<DrmDisplayComposition> composition,
Roman Stratiienko74774712021-02-05 16:32:47 +020073 int status);
Roman Kovalivskyi8fae1562020-01-30 20:20:47 +020074
Sean Paul35301f42015-11-17 14:46:56 -050075 std::tuple<int, uint32_t> CreateModeBlob(const DrmMode &mode);
76
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +010077 ResourceManager *resource_manager_;
Sean Paul98e73c82015-06-24 14:38:49 -070078 int display_;
79
Sean Paul98e73c82015-06-24 14:38:49 -070080 std::unique_ptr<DrmDisplayComposition> active_composition_;
81
Sean Paul98e73c82015-06-24 14:38:49 -070082 bool initialized_;
Sean Pauldb7a17d2015-06-24 18:46:05 -070083 bool active_;
Sean Paul6c18b3b2015-11-25 11:04:25 -050084 bool use_hw_overlays_;
Sean Paul98e73c82015-06-24 14:38:49 -070085
Sean Paul35301f42015-11-17 14:46:56 -050086 ModeState mode_;
Sean Paul57355412015-09-19 09:14:34 -040087
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010088 std::unique_ptr<Planner> planner_;
Sean Paul98e73c82015-06-24 14:38:49 -070089};
Sean Paulf72cccd2018-08-27 13:59:08 -040090} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -070091
92#endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_