2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_DRM_DISPLAY_COMPOSITOR_H_
18 #define ANDROID_DRM_DISPLAY_COMPOSITOR_H_
20 #include <hardware/hardware.h>
21 #include <hardware/hwcomposer.h>
29 #include "DrmDisplayComposition.h"
31 #include "drm/ResourceManager.h"
32 #include "drm/VSyncWorker.h"
33 #include "drmhwcomposer.h"
37 struct AtomicCommitArgs {
38 /* inputs. All fields are optional, but at least one has to be specified */
39 bool test_only = false;
40 std::optional<DrmMode> display_mode;
41 std::optional<bool> active;
42 std::shared_ptr<DrmDisplayComposition> composition;
43 /* 'clear' should never be used together with 'composition' */
44 bool clear_active_composition = false;
50 auto HasInputs() -> bool {
51 return display_mode || active || composition || clear_active_composition;
55 class DrmDisplayCompositor {
57 DrmDisplayCompositor() = default;
58 ~DrmDisplayCompositor() = default;
59 auto Init(ResourceManager *resource_manager, int display) -> int;
61 std::unique_ptr<DrmDisplayComposition> CreateInitializedComposition() const;
63 auto ExecuteAtomicCommit(AtomicCommitArgs &args) -> int;
66 DrmDisplayCompositor(const DrmDisplayCompositor &) = delete;
68 auto CommitFrame(AtomicCommitArgs &args) -> int;
71 /* Required to cleanup unused planes */
72 std::vector<DrmPlane *> used_planes;
73 /* We have to hold a reference to framebuffer while displaying it ,
74 * otherwise picture will blink */
75 std::vector<std::shared_ptr<DrmFbIdHandle>> used_framebuffers;
77 DrmModeUserPropertyBlobUnique mode_blob;
79 /* To avoid setting the inactive state twice, which will fail the commit */
80 bool crtc_active_state{};
83 auto NewFrameState() -> KmsState {
85 .used_planes = active_frame_state.used_planes,
86 .used_framebuffers = active_frame_state.used_framebuffers,
87 .crtc_active_state = active_frame_state.crtc_active_state,
91 ResourceManager *resource_manager_ = nullptr;
92 std::unique_ptr<Planner> planner_;
96 } // namespace android
98 #endif // ANDROID_DRM_DISPLAY_COMPOSITOR_H_