Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 1 | /* |
| 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 Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 20 | #include <hardware/hardware.h> |
| 21 | #include <hardware/hwcomposer.h> |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 22 | #include <pthread.h> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 23 | |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 24 | #include <functional> |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 25 | #include <memory> |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 26 | #include <sstream> |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 27 | #include <tuple> |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 28 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 29 | #include "DrmDisplayComposition.h" |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 30 | #include "Planner.h" |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 31 | #include "drm/ResourceManager.h" |
| 32 | #include "drm/VSyncWorker.h" |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 33 | #include "drmhwcomposer.h" |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | |
| 37 | class DrmDisplayCompositor { |
| 38 | public: |
| 39 | DrmDisplayCompositor(); |
| 40 | ~DrmDisplayCompositor(); |
| 41 | |
Roman Stratiienko | e8c0679 | 2021-09-30 10:09:31 +0300 | [diff] [blame] | 42 | auto Init(ResourceManager *resource_manager, int display) -> int; |
Roman Kovalivskyi | 8fae156 | 2020-01-30 20:20:47 +0200 | [diff] [blame] | 43 | |
Alexandru Gheorghe | b6a675e | 2018-03-27 16:10:55 +0100 | [diff] [blame] | 44 | std::unique_ptr<DrmDisplayComposition> CreateInitializedComposition() const; |
Sean Paul | ed45a8e | 2017-02-28 13:17:34 -0500 | [diff] [blame] | 45 | int ApplyComposition(std::unique_ptr<DrmDisplayComposition> composition); |
Rob Herring | 4f6c62e | 2018-05-17 14:33:02 -0500 | [diff] [blame] | 46 | int TestComposition(DrmDisplayComposition *composition); |
Andrii Chepurnyi | 495e4cc | 2018-08-01 17:42:56 +0300 | [diff] [blame] | 47 | void ClearDisplay(); |
Roman Stratiienko | 36a7f28 | 2021-10-05 18:17:53 +0300 | [diff] [blame^] | 48 | auto SetDisplayMode(const DrmMode &display_mode) -> bool; |
| 49 | auto SetDisplayActive(bool state) -> void { |
| 50 | active_ = state; |
| 51 | active_changed_ = true; |
| 52 | } |
| 53 | |
Roman Stratiienko | 0fade37 | 2021-02-20 13:59:55 +0200 | [diff] [blame] | 54 | UniqueFd TakeOutFence() { |
| 55 | if (!active_composition_) { |
| 56 | return UniqueFd(); |
| 57 | } |
| 58 | return std::move(active_composition_->out_fence_); |
Matteo Franchin | c56eede | 2019-12-03 17:10:38 +0000 | [diff] [blame] | 59 | } |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 60 | |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 61 | std::tuple<uint32_t, uint32_t, int> GetActiveModeResolution(); |
| 62 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 63 | private: |
Sean Paul | 35301f4 | 2015-11-17 14:46:56 -0500 | [diff] [blame] | 64 | struct ModeState { |
Sean Paul | 35301f4 | 2015-11-17 14:46:56 -0500 | [diff] [blame] | 65 | DrmMode mode; |
Roman Stratiienko | 6ede466 | 2021-09-30 10:18:28 +0300 | [diff] [blame] | 66 | DrmModeUserPropertyBlobUnique blob; |
| 67 | DrmModeUserPropertyBlobUnique old_blob; |
Sean Paul | 35301f4 | 2015-11-17 14:46:56 -0500 | [diff] [blame] | 68 | }; |
| 69 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 70 | DrmDisplayCompositor(const DrmDisplayCompositor &) = delete; |
| 71 | |
Roman Stratiienko | 7477471 | 2021-02-05 16:32:47 +0200 | [diff] [blame] | 72 | int CommitFrame(DrmDisplayComposition *display_comp, bool test_only); |
Sean Paul | 7b1e4bc | 2015-10-13 15:47:22 -0400 | [diff] [blame] | 73 | int DisablePlanes(DrmDisplayComposition *display_comp); |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 74 | |
Roman Stratiienko | 6ede466 | 2021-09-30 10:18:28 +0300 | [diff] [blame] | 75 | auto CreateModeBlob(const DrmMode &mode) -> DrmModeUserPropertyBlobUnique; |
Sean Paul | 35301f4 | 2015-11-17 14:46:56 -0500 | [diff] [blame] | 76 | |
Alexandru Gheorghe | 6f0030f | 2018-05-01 17:25:48 +0100 | [diff] [blame] | 77 | ResourceManager *resource_manager_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 78 | int display_; |
| 79 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 80 | std::unique_ptr<DrmDisplayComposition> active_composition_; |
| 81 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 82 | bool initialized_; |
Roman Stratiienko | 36a7f28 | 2021-10-05 18:17:53 +0300 | [diff] [blame^] | 83 | bool active_{true}, active_changed_{true}; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 84 | |
Sean Paul | 35301f4 | 2015-11-17 14:46:56 -0500 | [diff] [blame] | 85 | ModeState mode_; |
Sean Paul | 5735541 | 2015-09-19 09:14:34 -0400 | [diff] [blame] | 86 | |
Alexandru Gheorghe | b6a675e | 2018-03-27 16:10:55 +0100 | [diff] [blame] | 87 | std::unique_ptr<Planner> planner_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 88 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 89 | } // namespace android |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 90 | |
| 91 | #endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_ |