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 | |
Roman Stratiienko | 4e99405 | 2022-02-09 17:40:35 +0200 | [diff] [blame^] | 17 | #ifndef ANDROID_DRM_ATOMIC_STATE_MANAGER_H_ |
| 18 | #define ANDROID_DRM_ATOMIC_STATE_MANAGER_H_ |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 19 | |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 20 | #include <pthread.h> |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 21 | |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 22 | #include <functional> |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 23 | #include <memory> |
Roman Stratiienko | f81d2c8 | 2022-01-11 19:47:24 +0200 | [diff] [blame] | 24 | #include <optional> |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 25 | #include <sstream> |
Zach Reizner | 92f8e63 | 2015-10-12 17:47:13 -0700 | [diff] [blame] | 26 | #include <tuple> |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 27 | |
Roman Stratiienko | 4e99405 | 2022-02-09 17:40:35 +0200 | [diff] [blame^] | 28 | #include "compositor/DrmKmsPlan.h" |
Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 29 | #include "drm/DrmPlane.h" |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 30 | #include "drm/ResourceManager.h" |
| 31 | #include "drm/VSyncWorker.h" |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 32 | #include "drmhwcomposer.h" |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 33 | |
| 34 | namespace android { |
| 35 | |
Roman Stratiienko | dccc6fb | 2021-10-23 17:35:44 +0300 | [diff] [blame] | 36 | struct AtomicCommitArgs { |
| 37 | /* inputs. All fields are optional, but at least one has to be specified */ |
| 38 | bool test_only = false; |
| 39 | std::optional<DrmMode> display_mode; |
| 40 | std::optional<bool> active; |
Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 41 | std::shared_ptr<DrmKmsPlan> composition; |
Roman Stratiienko | dccc6fb | 2021-10-23 17:35:44 +0300 | [diff] [blame] | 42 | |
| 43 | /* out */ |
| 44 | UniqueFd out_fence; |
| 45 | |
| 46 | /* helpers */ |
| 47 | auto HasInputs() -> bool { |
Roman Stratiienko | ef5348b | 2022-02-09 17:19:56 +0200 | [diff] [blame] | 48 | return display_mode || active || composition; |
Roman Stratiienko | dccc6fb | 2021-10-23 17:35:44 +0300 | [diff] [blame] | 49 | } |
| 50 | }; |
| 51 | |
Roman Stratiienko | 4e99405 | 2022-02-09 17:40:35 +0200 | [diff] [blame^] | 52 | class DrmAtomicStateManager { |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 53 | public: |
Roman Stratiienko | 4e99405 | 2022-02-09 17:40:35 +0200 | [diff] [blame^] | 54 | explicit DrmAtomicStateManager(DrmDisplayPipeline *pipe) : pipe_(pipe){}; |
| 55 | DrmAtomicStateManager(const DrmAtomicStateManager &) = delete; |
| 56 | ~DrmAtomicStateManager() = default; |
Roman Kovalivskyi | 8fae156 | 2020-01-30 20:20:47 +0200 | [diff] [blame] | 57 | |
Roman Stratiienko | dccc6fb | 2021-10-23 17:35:44 +0300 | [diff] [blame] | 58 | auto ExecuteAtomicCommit(AtomicCommitArgs &args) -> int; |
Roman Stratiienko | d37b308 | 2022-01-13 16:37:27 +0200 | [diff] [blame] | 59 | auto ActivateDisplayUsingDPMS() -> int; |
| 60 | |
Roman Stratiienko | e78235c | 2021-12-23 17:36:12 +0200 | [diff] [blame] | 61 | private: |
Roman Stratiienko | dccc6fb | 2021-10-23 17:35:44 +0300 | [diff] [blame] | 62 | auto CommitFrame(AtomicCommitArgs &args) -> int; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 63 | |
Roman Stratiienko | 32685ba | 2021-12-15 13:46:05 +0200 | [diff] [blame] | 64 | struct KmsState { |
| 65 | /* Required to cleanup unused planes */ |
Roman Stratiienko | 9362cef | 2022-02-02 09:53:50 +0200 | [diff] [blame] | 66 | std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> used_planes; |
Roman Stratiienko | 32685ba | 2021-12-15 13:46:05 +0200 | [diff] [blame] | 67 | /* We have to hold a reference to framebuffer while displaying it , |
| 68 | * otherwise picture will blink */ |
| 69 | std::vector<std::shared_ptr<DrmFbIdHandle>> used_framebuffers; |
| 70 | |
Roman Stratiienko | dccc6fb | 2021-10-23 17:35:44 +0300 | [diff] [blame] | 71 | DrmModeUserPropertyBlobUnique mode_blob; |
Roman Stratiienko | 32685ba | 2021-12-15 13:46:05 +0200 | [diff] [blame] | 72 | |
| 73 | /* To avoid setting the inactive state twice, which will fail the commit */ |
| 74 | bool crtc_active_state{}; |
Roman Stratiienko | f815d38 | 2021-12-30 19:23:14 +0200 | [diff] [blame] | 75 | } active_frame_state_; |
Roman Stratiienko | 32685ba | 2021-12-15 13:46:05 +0200 | [diff] [blame] | 76 | |
| 77 | auto NewFrameState() -> KmsState { |
| 78 | return (KmsState){ |
Roman Stratiienko | f815d38 | 2021-12-30 19:23:14 +0200 | [diff] [blame] | 79 | .used_planes = active_frame_state_.used_planes, |
| 80 | .used_framebuffers = active_frame_state_.used_framebuffers, |
| 81 | .crtc_active_state = active_frame_state_.crtc_active_state, |
Roman Stratiienko | 32685ba | 2021-12-15 13:46:05 +0200 | [diff] [blame] | 82 | }; |
| 83 | } |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 84 | |
Roman Stratiienko | 19c162f | 2022-02-01 09:35:08 +0200 | [diff] [blame] | 85 | DrmDisplayPipeline *const pipe_; |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 86 | }; |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 87 | } // namespace android |
Sean Paul | 98e73c8 | 2015-06-24 14:38:49 -0700 | [diff] [blame] | 88 | |
| 89 | #endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_ |