blob: 434668fc95d21a343c35ded27753f532fef2120f [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);
Andrii Chepurnyi495e4cc2018-08-01 17:42:56 +030047 void ClearDisplay();
Roman Stratiienko36a7f282021-10-05 18:17:53 +030048 auto SetDisplayMode(const DrmMode &display_mode) -> bool;
49 auto SetDisplayActive(bool state) -> void {
50 active_ = state;
51 active_changed_ = true;
52 }
53
Roman Stratiienko0fade372021-02-20 13:59:55 +020054 UniqueFd TakeOutFence() {
55 if (!active_composition_) {
56 return UniqueFd();
57 }
58 return std::move(active_composition_->out_fence_);
Matteo Franchinc56eede2019-12-03 17:10:38 +000059 }
Sean Paul98e73c82015-06-24 14:38:49 -070060
Sean Paul98e73c82015-06-24 14:38:49 -070061 private:
Sean Paul35301f42015-11-17 14:46:56 -050062 struct ModeState {
Sean Paul35301f42015-11-17 14:46:56 -050063 DrmMode mode;
Roman Stratiienko6ede4662021-09-30 10:18:28 +030064 DrmModeUserPropertyBlobUnique blob;
65 DrmModeUserPropertyBlobUnique old_blob;
Sean Paul35301f42015-11-17 14:46:56 -050066 };
67
Sean Paul98e73c82015-06-24 14:38:49 -070068 DrmDisplayCompositor(const DrmDisplayCompositor &) = delete;
69
Roman Stratiienko74774712021-02-05 16:32:47 +020070 int CommitFrame(DrmDisplayComposition *display_comp, bool test_only);
Sean Paul7b1e4bc2015-10-13 15:47:22 -040071 int DisablePlanes(DrmDisplayComposition *display_comp);
Sean Paul98e73c82015-06-24 14:38:49 -070072
Alexandru Gheorghe6f0030f2018-05-01 17:25:48 +010073 ResourceManager *resource_manager_;
Sean Paul98e73c82015-06-24 14:38:49 -070074 int display_;
75
Sean Paul98e73c82015-06-24 14:38:49 -070076 std::unique_ptr<DrmDisplayComposition> active_composition_;
77
Sean Paul98e73c82015-06-24 14:38:49 -070078 bool initialized_;
Roman Stratiienko36a7f282021-10-05 18:17:53 +030079 bool active_{true}, active_changed_{true};
Sean Paul98e73c82015-06-24 14:38:49 -070080
Sean Paul35301f42015-11-17 14:46:56 -050081 ModeState mode_;
Sean Paul57355412015-09-19 09:14:34 -040082
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010083 std::unique_ptr<Planner> planner_;
Sean Paul98e73c82015-06-24 14:38:49 -070084};
Sean Paulf72cccd2018-08-27 13:59:08 -040085} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -070086
87#endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_