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_COMPOSITION_H_
18 #define ANDROID_DRM_DISPLAY_COMPOSITION_H_
21 #include "drmhwcomposer.h"
28 #include <hardware/gralloc.h>
29 #include <hardware/hardware.h>
30 #include <hardware/hwcomposer.h>
38 enum DrmCompositionType {
39 DRM_COMPOSITION_TYPE_EMPTY,
40 DRM_COMPOSITION_TYPE_FRAME,
41 DRM_COMPOSITION_TYPE_DPMS,
42 DRM_COMPOSITION_TYPE_MODESET,
45 struct DrmCompositionDisplayLayersMap {
47 bool geometry_changed = true;
48 std::vector<DrmHwcLayer> layers;
50 DrmCompositionDisplayLayersMap() = default;
51 DrmCompositionDisplayLayersMap(DrmCompositionDisplayLayersMap &&rhs) =
55 struct DrmCompositionRegion {
56 DrmHwcRect<int> frame;
57 std::vector<size_t> source_layers;
60 class DrmCompositionPlane {
62 enum class Type : int32_t {
69 DrmCompositionPlane() = default;
70 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
71 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
72 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
73 : type_(type), plane_(plane), crtc_(crtc) {
75 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc,
80 source_layers_(1, source_layer) {
87 DrmPlane *plane() const {
90 void set_plane(DrmPlane *plane) {
94 DrmCrtc *crtc() const {
98 std::vector<size_t> &source_layers() {
99 return source_layers_;
102 const std::vector<size_t> &source_layers() const {
103 return source_layers_;
107 Type type_ = Type::kDisable;
108 DrmPlane *plane_ = NULL;
109 DrmCrtc *crtc_ = NULL;
110 std::vector<size_t> source_layers_;
113 class DrmDisplayComposition {
115 DrmDisplayComposition() = default;
116 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
117 ~DrmDisplayComposition();
119 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
120 Planner *planner, uint64_t frame_no);
122 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
123 int AddPlaneComposition(DrmCompositionPlane plane);
124 int AddPlaneDisable(DrmPlane *plane);
125 int SetDpmsMode(uint32_t dpms_mode);
126 int SetDisplayMode(const DrmMode &display_mode);
128 int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
129 std::vector<DrmPlane *> *overlay_planes);
131 int FinalizeComposition();
133 int CreateNextTimelineFence();
134 int SignalSquashDone() {
135 return IncreaseTimelineToPoint(timeline_squash_done_);
137 int SignalPreCompDone() {
138 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
140 int SignalCompositionDone() {
141 return IncreaseTimelineToPoint(timeline_);
144 std::vector<DrmHwcLayer> &layers() {
148 std::vector<DrmCompositionRegion> &squash_regions() {
149 return squash_regions_;
152 std::vector<DrmCompositionRegion> &pre_comp_regions() {
153 return pre_comp_regions_;
156 std::vector<DrmCompositionPlane> &composition_planes() {
157 return composition_planes_;
160 bool geometry_changed() const {
161 return geometry_changed_;
164 uint64_t frame_no() const {
168 DrmCompositionType type() const {
172 uint32_t dpms_mode() const {
176 const DrmMode &display_mode() const {
177 return display_mode_;
180 DrmCrtc *crtc() const {
184 Importer *importer() const {
188 Planner *planner() const {
192 int take_out_fence() {
193 return out_fence_.Release();
196 void set_out_fence(int out_fence) {
197 out_fence_.Set(out_fence);
200 void Dump(std::ostringstream *out) const;
203 bool validate_composition_type(DrmCompositionType desired);
205 int IncreaseTimelineToPoint(int point);
207 int FinalizeComposition(DrmHwcRect<int> *exclude_rects,
208 size_t num_exclude_rects);
209 void SeparateLayers(DrmHwcRect<int> *exclude_rects, size_t num_exclude_rects);
210 int CreateAndAssignReleaseFences();
212 DrmResources *drm_ = NULL;
213 DrmCrtc *crtc_ = NULL;
214 Importer *importer_ = NULL;
215 Planner *planner_ = NULL;
217 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
218 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
219 DrmMode display_mode_;
221 int timeline_fd_ = -1;
223 int timeline_current_ = 0;
224 int timeline_squash_done_ = 0;
225 int timeline_pre_comp_done_ = 0;
226 UniqueFd out_fence_ = -1;
228 bool geometry_changed_;
229 std::vector<DrmHwcLayer> layers_;
230 std::vector<DrmCompositionRegion> squash_regions_;
231 std::vector<DrmCompositionRegion> pre_comp_regions_;
232 std::vector<DrmCompositionPlane> composition_planes_;
234 uint64_t frame_no_ = 0;
238 #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_