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_ATOMIC_STATE_MANAGER_H_ 18 #define ANDROID_DRM_ATOMIC_STATE_MANAGER_H_ 19 20 #include <pthread.h> 21 22 #include <functional> 23 #include <memory> 24 #include <optional> 25 #include <sstream> 26 #include <tuple> 27 28 #include "compositor/DrmKmsPlan.h" 29 #include "drm/DrmPlane.h" 30 #include "drm/ResourceManager.h" 31 #include "drm/VSyncWorker.h" 32 #include "drmhwcomposer.h" 33 34 namespace android { 35 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; 41 std::shared_ptr<DrmKmsPlan> composition; 42 43 /* out */ 44 UniqueFd out_fence; 45 46 /* helpers */ 47 auto HasInputs() -> bool { 48 return display_mode || active || composition; 49 } 50 }; 51 52 class DrmAtomicStateManager { 53 public: DrmAtomicStateManager(DrmDisplayPipeline * pipe)54 explicit DrmAtomicStateManager(DrmDisplayPipeline *pipe) : pipe_(pipe){}; 55 DrmAtomicStateManager(const DrmAtomicStateManager &) = delete; 56 ~DrmAtomicStateManager() = default; 57 58 auto ExecuteAtomicCommit(AtomicCommitArgs &args) -> int; 59 auto ActivateDisplayUsingDPMS() -> int; 60 61 private: 62 auto CommitFrame(AtomicCommitArgs &args) -> int; 63 64 struct KmsState { 65 /* Required to cleanup unused planes */ 66 std::vector<std::shared_ptr<BindingOwner<DrmPlane>>> used_planes; 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 71 DrmModeUserPropertyBlobUnique mode_blob; 72 73 /* To avoid setting the inactive state twice, which will fail the commit */ 74 bool crtc_active_state{}; 75 } active_frame_state_; 76 77 auto NewFrameState() -> KmsState { 78 return (KmsState){ 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, 82 }; 83 } 84 85 DrmDisplayPipeline *const pipe_; 86 }; 87 } // namespace android 88 89 #endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_ 90