blob: e76abf7ecb8516100a8eca78e6861c3db44595e6 [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
Zach Reizner92f8e632015-10-12 17:47:13 -070061 std::tuple<uint32_t, uint32_t, int> GetActiveModeResolution();
62
Sean Paul98e73c82015-06-24 14:38:49 -070063 private:
Sean Paul35301f42015-11-17 14:46:56 -050064 struct ModeState {
Sean Paul35301f42015-11-17 14:46:56 -050065 DrmMode mode;
Roman Stratiienko6ede4662021-09-30 10:18:28 +030066 DrmModeUserPropertyBlobUnique blob;
67 DrmModeUserPropertyBlobUnique old_blob;
Sean Paul35301f42015-11-17 14:46:56 -050068 };
69
Sean Paul98e73c82015-06-24 14:38:49 -070070 DrmDisplayCompositor(const DrmDisplayCompositor &) = delete;
71
Roman Stratiienko74774712021-02-05 16:32:47 +020072 int CommitFrame(DrmDisplayComposition *display_comp, bool test_only);
Sean Paul7b1e4bc2015-10-13 15:47:22 -040073 int DisablePlanes(DrmDisplayComposition *display_comp);
Sean Paul98e73c82015-06-24 14:38:49 -070074
Roman Stratiienko6ede4662021-09-30 10:18:28 +030075 auto CreateModeBlob(const DrmMode &mode) -> DrmModeUserPropertyBlobUnique;
Sean Paul35301f42015-11-17 14:46:56 -050076
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_;
Roman Stratiienko36a7f282021-10-05 18:17:53 +030083 bool active_{true}, active_changed_{true};
Sean Paul98e73c82015-06-24 14:38:49 -070084
Sean Paul35301f42015-11-17 14:46:56 -050085 ModeState mode_;
Sean Paul57355412015-09-19 09:14:34 -040086
Alexandru Gheorgheb6a675e2018-03-27 16:10:55 +010087 std::unique_ptr<Planner> planner_;
Sean Paul98e73c82015-06-24 14:38:49 -070088};
Sean Paulf72cccd2018-08-27 13:59:08 -040089} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -070090
91#endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_