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_
20 #include "drmhwcomposer.h"
29 #include <hardware/gralloc.h>
30 #include <hardware/hardware.h>
31 #include <hardware/hwcomposer.h>
37 enum DrmCompositionType {
38 DRM_COMPOSITION_TYPE_EMPTY,
39 DRM_COMPOSITION_TYPE_FRAME,
40 DRM_COMPOSITION_TYPE_DPMS,
41 DRM_COMPOSITION_TYPE_MODESET,
44 struct DrmCompositionRegion {
45 DrmHwcRect<int> frame;
46 std::vector<size_t> source_layers;
49 struct DrmCompositionPlane {
50 const static size_t kSourceNone = SIZE_MAX;
51 const static size_t kSourcePreComp = kSourceNone - 1;
52 const static size_t kSourceSquash = kSourcePreComp - 1;
53 const static size_t kSourceLayerMax = kSourceSquash - 1;
59 class DrmDisplayComposition {
61 DrmDisplayComposition() = default;
62 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
63 ~DrmDisplayComposition();
65 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
68 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
69 int AddPlaneDisable(DrmPlane *plane);
70 int SetDpmsMode(uint32_t dpms_mode);
71 int SetDisplayMode(const DrmMode &display_mode);
73 int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
74 std::vector<DrmPlane *> *overlay_planes);
76 int CreateNextTimelineFence();
77 int SignalSquashDone() {
78 return IncreaseTimelineToPoint(timeline_squash_done_);
80 int SignalPreCompDone() {
81 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
83 int SignalCompositionDone() {
84 return IncreaseTimelineToPoint(timeline_);
87 std::vector<DrmHwcLayer> &layers() {
91 std::vector<DrmCompositionRegion> &squash_regions() {
92 return squash_regions_;
95 std::vector<DrmCompositionRegion> &pre_comp_regions() {
96 return pre_comp_regions_;
99 std::vector<DrmCompositionPlane> &composition_planes() {
100 return composition_planes_;
103 uint64_t frame_no() const {
107 DrmCompositionType type() const {
111 uint32_t dpms_mode() const {
115 const DrmMode &display_mode() const {
116 return display_mode_;
119 DrmCrtc *crtc() const {
123 Importer *importer() const {
127 void Dump(std::ostringstream *out) const;
130 bool validate_composition_type(DrmCompositionType desired);
132 int IncreaseTimelineToPoint(int point);
134 int CreateAndAssignReleaseFences();
136 DrmResources *drm_ = NULL;
137 DrmCrtc *crtc_ = NULL;
138 Importer *importer_ = NULL;
140 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
141 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
142 DrmMode display_mode_;
144 int timeline_fd_ = -1;
146 int timeline_current_ = 0;
147 int timeline_squash_done_ = 0;
148 int timeline_pre_comp_done_ = 0;
150 bool geometry_changed_;
151 std::vector<DrmHwcLayer> layers_;
152 std::vector<DrmCompositionRegion> squash_regions_;
153 std::vector<DrmCompositionRegion> pre_comp_regions_;
154 std::vector<DrmCompositionPlane> composition_planes_;
156 uint64_t frame_no_ = 0;
160 #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_