blob: 13da19dfe945dcd5eb076b4dcbb71af872496e18 [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 Paul98e73c82015-06-24 14:38:49 -070024
Zach Reiznerfd6dc332015-10-13 21:12:48 -070025#include <sstream>
Sean Paul98e73c82015-06-24 14:38:49 -070026#include <vector>
27
Zach Reiznerb44fd102015-08-07 16:00:01 -070028#include <hardware/gralloc.h>
Sean Paul98e73c82015-06-24 14:38:49 -070029#include <hardware/hardware.h>
30#include <hardware/hwcomposer.h>
31
32namespace android {
33
Sean Paul4c4646e2016-05-10 04:19:24 -040034class Importer;
Sean Paulaa18d912016-05-12 14:28:05 -040035class Planner;
Sean Paul5325e102016-03-29 13:55:35 -040036class SquashState;
Zach Reizner92f8e632015-10-12 17:47:13 -070037
Sean Paulacb2a442015-06-24 18:43:01 -070038enum DrmCompositionType {
39 DRM_COMPOSITION_TYPE_EMPTY,
40 DRM_COMPOSITION_TYPE_FRAME,
Sean Pauldb7a17d2015-06-24 18:46:05 -070041 DRM_COMPOSITION_TYPE_DPMS,
Sean Paul57355412015-09-19 09:14:34 -040042 DRM_COMPOSITION_TYPE_MODESET,
Sean Paulacb2a442015-06-24 18:43:01 -070043};
44
Zach Reizner92f8e632015-10-12 17:47:13 -070045struct DrmCompositionRegion {
46 DrmHwcRect<int> frame;
47 std::vector<size_t> source_layers;
48};
Sean Paul98e73c82015-06-24 14:38:49 -070049
Sean Paulca699be2016-05-11 16:29:45 -040050class DrmCompositionPlane {
51 public:
Sean Paulbbe39db2016-05-11 16:57:26 -040052 enum class Type : int32_t {
53 kDisable,
54 kLayer,
55 kPrecomp,
56 kSquash,
57 };
58
Sean Paulca699be2016-05-11 16:29:45 -040059 DrmCompositionPlane() = default;
60 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
61 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
Sean Paulbbe39db2016-05-11 16:57:26 -040062 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
Sean Paulca699be2016-05-11 16:29:45 -040063 : type_(type), plane_(plane), crtc_(crtc) {
64 }
Sean Paulbbe39db2016-05-11 16:57:26 -040065 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc,
66 size_t source_layer)
Sean Paulca699be2016-05-11 16:29:45 -040067 : type_(type),
68 plane_(plane),
69 crtc_(crtc),
70 source_layers_(1, source_layer) {
71 }
72
Sean Paulbbe39db2016-05-11 16:57:26 -040073 Type type() const {
Sean Paulca699be2016-05-11 16:29:45 -040074 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:
Sean Paulbbe39db2016-05-11 16:57:26 -040097 Type type_ = Type::kDisable;
Sean Paulca699be2016-05-11 16:29:45 -040098 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,
Sean Paulaa18d912016-05-12 14:28:05 -0400110 Planner *planner, 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 Paul4f4ef692016-05-03 16:40:59 -0700113 int AddPlaneComposition(DrmCompositionPlane plane);
Sean Paul2e46fbd2015-07-09 17:22:22 -0400114 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -0700115 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -0400116 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -0700117
Zach Reizner92f8e632015-10-12 17:47:13 -0700118 int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
119 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -0700120
Sean Paul4f4ef692016-05-03 16:40:59 -0700121 int FinalizeComposition();
122
Zach Reizner09807052015-08-13 14:53:41 -0700123 int CreateNextTimelineFence();
Zach Reizner92f8e632015-10-12 17:47:13 -0700124 int SignalSquashDone() {
125 return IncreaseTimelineToPoint(timeline_squash_done_);
126 }
127 int SignalPreCompDone() {
128 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
129 }
130 int SignalCompositionDone() {
131 return IncreaseTimelineToPoint(timeline_);
132 }
133
134 std::vector<DrmHwcLayer> &layers() {
135 return layers_;
136 }
137
138 std::vector<DrmCompositionRegion> &squash_regions() {
139 return squash_regions_;
140 }
141
142 std::vector<DrmCompositionRegion> &pre_comp_regions() {
143 return pre_comp_regions_;
144 }
145
146 std::vector<DrmCompositionPlane> &composition_planes() {
147 return composition_planes_;
148 }
149
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800150 bool geometry_changed() const {
151 return geometry_changed_;
152 }
153
Zach Reizner92f8e632015-10-12 17:47:13 -0700154 uint64_t frame_no() const {
155 return frame_no_;
156 }
157
158 DrmCompositionType type() const {
159 return type_;
160 }
161
162 uint32_t dpms_mode() const {
163 return dpms_mode_;
164 }
165
166 const DrmMode &display_mode() const {
167 return display_mode_;
168 }
169
170 DrmCrtc *crtc() const {
171 return crtc_;
172 }
173
174 Importer *importer() const {
175 return importer_;
176 }
177
Sean Paulaa18d912016-05-12 14:28:05 -0400178 Planner *planner() const {
179 return planner_;
180 }
181
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700182 void Dump(std::ostringstream *out) const;
183
Zach Reizner92f8e632015-10-12 17:47:13 -0700184 private:
185 bool validate_composition_type(DrmCompositionType desired);
186
Zach Reizner09807052015-08-13 14:53:41 -0700187 int IncreaseTimelineToPoint(int point);
188
Sean Paulaa18d912016-05-12 14:28:05 -0400189 int FinalizeComposition(DrmHwcRect<int> *exclude_rects,
190 size_t num_exclude_rects);
191 void SeparateLayers(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 Paulaa18d912016-05-12 14:28:05 -0400197 Planner *planner_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700198
Zach Reizner92f8e632015-10-12 17:47:13 -0700199 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
200 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400201 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400202
Zach Reizner92f8e632015-10-12 17:47:13 -0700203 int timeline_fd_ = -1;
204 int timeline_ = 0;
205 int timeline_current_ = 0;
206 int timeline_squash_done_ = 0;
207 int timeline_pre_comp_done_ = 0;
208
Zach Reizner5757e822015-10-16 19:06:31 -0700209 bool geometry_changed_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700210 std::vector<DrmHwcLayer> layers_;
211 std::vector<DrmCompositionRegion> squash_regions_;
212 std::vector<DrmCompositionRegion> pre_comp_regions_;
213 std::vector<DrmCompositionPlane> composition_planes_;
214
215 uint64_t frame_no_ = 0;
Sean Paul98e73c82015-06-24 14:38:49 -0700216};
217}
218
219#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_