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 "drm_hwcomposer.h"
28 #include <hardware/gralloc.h>
29 #include <hardware/hardware.h>
30 #include <hardware/hwcomposer.h>
36 enum DrmCompositionType {
37 DRM_COMPOSITION_TYPE_EMPTY,
38 DRM_COMPOSITION_TYPE_FRAME,
39 DRM_COMPOSITION_TYPE_DPMS,
40 DRM_COMPOSITION_TYPE_MODESET,
43 struct DrmCompositionRegion {
44 DrmHwcRect<int> frame;
45 std::vector<size_t> source_layers;
48 struct DrmCompositionPlane {
49 const static size_t kSourceNone = SIZE_MAX;
50 const static size_t kSourcePreComp = kSourceNone - 1;
51 const static size_t kSourceSquash = kSourcePreComp - 1;
52 const static size_t kSourceLayerMax = kSourceSquash - 1;
58 class DrmDisplayComposition {
60 DrmDisplayComposition() = default;
61 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
62 ~DrmDisplayComposition();
64 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
67 int SetLayers(DrmHwcLayer *layers, size_t num_layers);
68 int AddPlaneDisable(DrmPlane *plane);
69 int SetDpmsMode(uint32_t dpms_mode);
70 int SetDisplayMode(const DrmMode &display_mode);
72 int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
73 std::vector<DrmPlane *> *overlay_planes);
75 int CreateNextTimelineFence();
76 int SignalSquashDone() {
77 return IncreaseTimelineToPoint(timeline_squash_done_);
79 int SignalPreCompDone() {
80 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
82 int SignalCompositionDone() {
83 return IncreaseTimelineToPoint(timeline_);
86 std::vector<DrmHwcLayer> &layers() {
90 std::vector<DrmCompositionRegion> &squash_regions() {
91 return squash_regions_;
94 std::vector<DrmCompositionRegion> &pre_comp_regions() {
95 return pre_comp_regions_;
98 std::vector<DrmCompositionPlane> &composition_planes() {
99 return composition_planes_;
102 uint64_t frame_no() const {
106 DrmCompositionType type() const {
110 uint32_t dpms_mode() const {
114 const DrmMode &display_mode() const {
115 return display_mode_;
118 DrmCrtc *crtc() const {
122 Importer *importer() const {
127 bool validate_composition_type(DrmCompositionType desired);
129 int IncreaseTimelineToPoint(int point);
131 DrmResources *drm_ = NULL;
132 DrmCrtc *crtc_ = NULL;
133 Importer *importer_ = NULL;
135 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
136 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
137 DrmMode display_mode_;
139 int timeline_fd_ = -1;
141 int timeline_current_ = 0;
142 int timeline_squash_done_ = 0;
143 int timeline_pre_comp_done_ = 0;
145 std::vector<DrmHwcLayer> layers_;
146 std::vector<DrmCompositionRegion> squash_regions_;
147 std::vector<DrmCompositionRegion> pre_comp_regions_;
148 std::vector<DrmCompositionPlane> composition_planes_;
150 uint64_t frame_no_ = 0;
154 #endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_