blob: 768ccfb16415b0724e2293ae2f5c3bdd3c1da958 [file] [log] [blame]
Sean Paul98e73c82015-06-24 14:38:49 -07001/*
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_DISPLAY_COMPOSITION_H_
18#define ANDROID_DRM_DISPLAY_COMPOSITION_H_
19
Zach Reizner09807052015-08-13 14:53:41 -070020#include "drmcrtc.h"
Haixia Shi6afbb6a2015-11-24 12:42:45 -080021#include "drmhwcomposer.h"
Sean Paul98e73c82015-06-24 14:38:49 -070022#include "drmplane.h"
Zach Reizner09807052015-08-13 14:53:41 -070023#include "glworker.h"
Sean Paul63769962016-04-21 16:25:06 -040024#include "platform.h"
Sean Paul98e73c82015-06-24 14:38:49 -070025
Zach Reiznerfd6dc332015-10-13 21:12:48 -070026#include <sstream>
Sean Paul98e73c82015-06-24 14:38:49 -070027#include <vector>
28
Zach Reiznerb44fd102015-08-07 16:00:01 -070029#include <hardware/gralloc.h>
Sean Paul98e73c82015-06-24 14:38:49 -070030#include <hardware/hardware.h>
31#include <hardware/hwcomposer.h>
32
33namespace android {
34
Sean Paul5325e102016-03-29 13:55:35 -040035class SquashState;
Zach Reizner92f8e632015-10-12 17:47:13 -070036
Sean Paulacb2a442015-06-24 18:43:01 -070037enum DrmCompositionType {
38 DRM_COMPOSITION_TYPE_EMPTY,
39 DRM_COMPOSITION_TYPE_FRAME,
Sean Pauldb7a17d2015-06-24 18:46:05 -070040 DRM_COMPOSITION_TYPE_DPMS,
Sean Paul57355412015-09-19 09:14:34 -040041 DRM_COMPOSITION_TYPE_MODESET,
Sean Paulacb2a442015-06-24 18:43:01 -070042};
43
Zach Reizner92f8e632015-10-12 17:47:13 -070044struct DrmCompositionRegion {
45 DrmHwcRect<int> frame;
46 std::vector<size_t> source_layers;
47};
Sean Paul98e73c82015-06-24 14:38:49 -070048
Sean Paul39b37842016-05-11 13:50:28 -040049enum class DrmCompositionPlaneType : int32_t {
50 kDisable,
51 kLayer,
52 kPrecomp,
53 kSquash,
54};
55
Sean Paulca699be2016-05-11 16:29:45 -040056class DrmCompositionPlane {
57 public:
58 DrmCompositionPlane() = default;
59 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
60 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
61 DrmCompositionPlane(DrmCompositionPlaneType type, DrmPlane *plane,
62 DrmCrtc *crtc)
63 : type_(type), plane_(plane), crtc_(crtc) {
64 }
65 DrmCompositionPlane(DrmCompositionPlaneType type, DrmPlane *plane,
66 DrmCrtc *crtc, size_t source_layer)
67 : type_(type),
68 plane_(plane),
69 crtc_(crtc),
70 source_layers_(1, source_layer) {
71 }
72
73 DrmCompositionPlaneType type() const {
74 return type_;
75 }
76
77 DrmPlane *plane() const {
78 return plane_;
79 }
80 void set_plane(DrmPlane *plane) {
81 plane_ = plane;
82 }
83
84 DrmCrtc *crtc() const {
85 return crtc_;
86 }
87
88 std::vector<size_t> &source_layers() {
89 return source_layers_;
90 }
91
92 const std::vector<size_t> &source_layers() const {
93 return source_layers_;
94 }
95
96 private:
97 DrmCompositionPlaneType type_ = DrmCompositionPlaneType::kDisable;
98 DrmPlane *plane_ = NULL;
99 DrmCrtc *crtc_ = NULL;
100 std::vector<size_t> source_layers_;
Zach Reizner4a253652015-09-10 18:30:54 -0700101};
Sean Paul98e73c82015-06-24 14:38:49 -0700102
103class DrmDisplayComposition {
104 public:
Zach Reizner92f8e632015-10-12 17:47:13 -0700105 DrmDisplayComposition() = default;
106 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Sean Paul98e73c82015-06-24 14:38:49 -0700107 ~DrmDisplayComposition();
108
Sean Paulbdc67bf2015-09-21 10:04:02 -0400109 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
110 uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -0700111
Zach Reizner5757e822015-10-16 19:06:31 -0700112 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul2e46fbd2015-07-09 17:22:22 -0400113 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -0700114 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -0400115 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -0700116
Zach Reizner92f8e632015-10-12 17:47:13 -0700117 int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
118 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -0700119
Zach Reizner09807052015-08-13 14:53:41 -0700120 int CreateNextTimelineFence();
Zach Reizner92f8e632015-10-12 17:47:13 -0700121 int SignalSquashDone() {
122 return IncreaseTimelineToPoint(timeline_squash_done_);
123 }
124 int SignalPreCompDone() {
125 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
126 }
127 int SignalCompositionDone() {
128 return IncreaseTimelineToPoint(timeline_);
129 }
130
131 std::vector<DrmHwcLayer> &layers() {
132 return layers_;
133 }
134
135 std::vector<DrmCompositionRegion> &squash_regions() {
136 return squash_regions_;
137 }
138
139 std::vector<DrmCompositionRegion> &pre_comp_regions() {
140 return pre_comp_regions_;
141 }
142
143 std::vector<DrmCompositionPlane> &composition_planes() {
144 return composition_planes_;
145 }
146
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800147 bool geometry_changed() const {
148 return geometry_changed_;
149 }
150
Zach Reizner92f8e632015-10-12 17:47:13 -0700151 uint64_t frame_no() const {
152 return frame_no_;
153 }
154
155 DrmCompositionType type() const {
156 return type_;
157 }
158
159 uint32_t dpms_mode() const {
160 return dpms_mode_;
161 }
162
163 const DrmMode &display_mode() const {
164 return display_mode_;
165 }
166
167 DrmCrtc *crtc() const {
168 return crtc_;
169 }
170
171 Importer *importer() const {
172 return importer_;
173 }
174
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700175 void Dump(std::ostringstream *out) const;
176
Zach Reizner92f8e632015-10-12 17:47:13 -0700177 private:
178 bool validate_composition_type(DrmCompositionType desired);
179
Zach Reizner09807052015-08-13 14:53:41 -0700180 int IncreaseTimelineToPoint(int point);
181
Sean Paulca699be2016-05-11 16:29:45 -0400182 void EmplaceCompositionPlane(DrmCompositionPlaneType type,
183 std::vector<DrmPlane *> *primary_planes,
184 std::vector<DrmPlane *> *overlay_planes);
185 void EmplaceCompositionPlane(size_t source_layer,
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700186 std::vector<DrmPlane *> *primary_planes,
187 std::vector<DrmPlane *> *overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700188 int CreateAndAssignReleaseFences();
189
Zach Reizner92f8e632015-10-12 17:47:13 -0700190 DrmResources *drm_ = NULL;
191 DrmCrtc *crtc_ = NULL;
192 Importer *importer_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700193
Zach Reizner92f8e632015-10-12 17:47:13 -0700194 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
195 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400196 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400197
Zach Reizner92f8e632015-10-12 17:47:13 -0700198 int timeline_fd_ = -1;
199 int timeline_ = 0;
200 int timeline_current_ = 0;
201 int timeline_squash_done_ = 0;
202 int timeline_pre_comp_done_ = 0;
203
Zach Reizner5757e822015-10-16 19:06:31 -0700204 bool geometry_changed_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700205 std::vector<DrmHwcLayer> layers_;
206 std::vector<DrmCompositionRegion> squash_regions_;
207 std::vector<DrmCompositionRegion> pre_comp_regions_;
208 std::vector<DrmCompositionPlane> composition_planes_;
209
210 uint64_t frame_no_ = 0;
Sean Paul98e73c82015-06-24 14:38:49 -0700211};
212}
213
214#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_