blob: 6c52664a6cecec3e0a01a5eeccff2d20f572dc82 [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 Paulca699be2016-05-11 16:29:45 -040049class DrmCompositionPlane {
50 public:
Sean Paulbbe39db2016-05-11 16:57:26 -040051 enum class Type : int32_t {
52 kDisable,
53 kLayer,
54 kPrecomp,
55 kSquash,
56 };
57
Sean Paulca699be2016-05-11 16:29:45 -040058 DrmCompositionPlane() = default;
59 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
60 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
Sean Paulbbe39db2016-05-11 16:57:26 -040061 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
Sean Paulca699be2016-05-11 16:29:45 -040062 : type_(type), plane_(plane), crtc_(crtc) {
63 }
Sean Paulbbe39db2016-05-11 16:57:26 -040064 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc,
65 size_t source_layer)
Sean Paulca699be2016-05-11 16:29:45 -040066 : type_(type),
67 plane_(plane),
68 crtc_(crtc),
69 source_layers_(1, source_layer) {
70 }
71
Sean Paulbbe39db2016-05-11 16:57:26 -040072 Type type() const {
Sean Paulca699be2016-05-11 16:29:45 -040073 return type_;
74 }
75
76 DrmPlane *plane() const {
77 return plane_;
78 }
79 void set_plane(DrmPlane *plane) {
80 plane_ = plane;
81 }
82
83 DrmCrtc *crtc() const {
84 return crtc_;
85 }
86
87 std::vector<size_t> &source_layers() {
88 return source_layers_;
89 }
90
91 const std::vector<size_t> &source_layers() const {
92 return source_layers_;
93 }
94
95 private:
Sean Paulbbe39db2016-05-11 16:57:26 -040096 Type type_ = Type::kDisable;
Sean Paulca699be2016-05-11 16:29:45 -040097 DrmPlane *plane_ = NULL;
98 DrmCrtc *crtc_ = NULL;
99 std::vector<size_t> source_layers_;
Zach Reizner4a253652015-09-10 18:30:54 -0700100};
Sean Paul98e73c82015-06-24 14:38:49 -0700101
102class DrmDisplayComposition {
103 public:
Zach Reizner92f8e632015-10-12 17:47:13 -0700104 DrmDisplayComposition() = default;
105 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Sean Paul98e73c82015-06-24 14:38:49 -0700106 ~DrmDisplayComposition();
107
Sean Paulbdc67bf2015-09-21 10:04:02 -0400108 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
109 uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -0700110
Zach Reizner5757e822015-10-16 19:06:31 -0700111 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul4f4ef692016-05-03 16:40:59 -0700112 int AddPlaneComposition(DrmCompositionPlane plane);
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
Sean Paul4f4ef692016-05-03 16:40:59 -0700120 int FinalizeComposition();
121
Zach Reizner09807052015-08-13 14:53:41 -0700122 int CreateNextTimelineFence();
Zach Reizner92f8e632015-10-12 17:47:13 -0700123 int SignalSquashDone() {
124 return IncreaseTimelineToPoint(timeline_squash_done_);
125 }
126 int SignalPreCompDone() {
127 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
128 }
129 int SignalCompositionDone() {
130 return IncreaseTimelineToPoint(timeline_);
131 }
132
133 std::vector<DrmHwcLayer> &layers() {
134 return layers_;
135 }
136
137 std::vector<DrmCompositionRegion> &squash_regions() {
138 return squash_regions_;
139 }
140
141 std::vector<DrmCompositionRegion> &pre_comp_regions() {
142 return pre_comp_regions_;
143 }
144
145 std::vector<DrmCompositionPlane> &composition_planes() {
146 return composition_planes_;
147 }
148
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800149 bool geometry_changed() const {
150 return geometry_changed_;
151 }
152
Zach Reizner92f8e632015-10-12 17:47:13 -0700153 uint64_t frame_no() const {
154 return frame_no_;
155 }
156
157 DrmCompositionType type() const {
158 return type_;
159 }
160
161 uint32_t dpms_mode() const {
162 return dpms_mode_;
163 }
164
165 const DrmMode &display_mode() const {
166 return display_mode_;
167 }
168
169 DrmCrtc *crtc() const {
170 return crtc_;
171 }
172
173 Importer *importer() const {
174 return importer_;
175 }
176
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700177 void Dump(std::ostringstream *out) const;
178
Zach Reizner92f8e632015-10-12 17:47:13 -0700179 private:
180 bool validate_composition_type(DrmCompositionType desired);
181
Zach Reizner09807052015-08-13 14:53:41 -0700182 int IncreaseTimelineToPoint(int point);
183
Sean Paulbbe39db2016-05-11 16:57:26 -0400184 void EmplaceCompositionPlane(DrmCompositionPlane::Type type,
Sean Paulca699be2016-05-11 16:29:45 -0400185 std::vector<DrmPlane *> *primary_planes,
186 std::vector<DrmPlane *> *overlay_planes);
187 void EmplaceCompositionPlane(size_t source_layer,
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700188 std::vector<DrmPlane *> *primary_planes,
189 std::vector<DrmPlane *> *overlay_planes);
Sean Paul3960cdd2016-05-10 04:17:31 -0400190 void SeparateLayers(size_t *used_layers, size_t num_used_layers,
191 DrmHwcRect<int> *exclude_rects, size_t num_exclude_rects);
Zach Reizner5757e822015-10-16 19:06:31 -0700192 int CreateAndAssignReleaseFences();
193
Zach Reizner92f8e632015-10-12 17:47:13 -0700194 DrmResources *drm_ = NULL;
195 DrmCrtc *crtc_ = NULL;
196 Importer *importer_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700197
Zach Reizner92f8e632015-10-12 17:47:13 -0700198 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
199 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400200 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400201
Zach Reizner92f8e632015-10-12 17:47:13 -0700202 int timeline_fd_ = -1;
203 int timeline_ = 0;
204 int timeline_current_ = 0;
205 int timeline_squash_done_ = 0;
206 int timeline_pre_comp_done_ = 0;
207
Zach Reizner5757e822015-10-16 19:06:31 -0700208 bool geometry_changed_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700209 std::vector<DrmHwcLayer> layers_;
210 std::vector<DrmCompositionRegion> squash_regions_;
211 std::vector<DrmCompositionRegion> pre_comp_regions_;
212 std::vector<DrmCompositionPlane> composition_planes_;
213
214 uint64_t frame_no_ = 0;
Sean Paul98e73c82015-06-24 14:38:49 -0700215};
216}
217
218#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_