blob: b2cfb9c40b793fe6f6ab119d6a6a1b7b58d7786f [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 Paul2e46fbd2015-07-09 17:22:22 -0400112 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -0700113 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -0400114 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -0700115
Zach Reizner92f8e632015-10-12 17:47:13 -0700116 int Plan(SquashState *squash, std::vector<DrmPlane *> *primary_planes,
117 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -0700118
Zach Reizner09807052015-08-13 14:53:41 -0700119 int CreateNextTimelineFence();
Zach Reizner92f8e632015-10-12 17:47:13 -0700120 int SignalSquashDone() {
121 return IncreaseTimelineToPoint(timeline_squash_done_);
122 }
123 int SignalPreCompDone() {
124 return IncreaseTimelineToPoint(timeline_pre_comp_done_);
125 }
126 int SignalCompositionDone() {
127 return IncreaseTimelineToPoint(timeline_);
128 }
129
130 std::vector<DrmHwcLayer> &layers() {
131 return layers_;
132 }
133
134 std::vector<DrmCompositionRegion> &squash_regions() {
135 return squash_regions_;
136 }
137
138 std::vector<DrmCompositionRegion> &pre_comp_regions() {
139 return pre_comp_regions_;
140 }
141
142 std::vector<DrmCompositionPlane> &composition_planes() {
143 return composition_planes_;
144 }
145
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800146 bool geometry_changed() const {
147 return geometry_changed_;
148 }
149
Zach Reizner92f8e632015-10-12 17:47:13 -0700150 uint64_t frame_no() const {
151 return frame_no_;
152 }
153
154 DrmCompositionType type() const {
155 return type_;
156 }
157
158 uint32_t dpms_mode() const {
159 return dpms_mode_;
160 }
161
162 const DrmMode &display_mode() const {
163 return display_mode_;
164 }
165
166 DrmCrtc *crtc() const {
167 return crtc_;
168 }
169
170 Importer *importer() const {
171 return importer_;
172 }
173
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700174 void Dump(std::ostringstream *out) const;
175
Zach Reizner92f8e632015-10-12 17:47:13 -0700176 private:
177 bool validate_composition_type(DrmCompositionType desired);
178
Zach Reizner09807052015-08-13 14:53:41 -0700179 int IncreaseTimelineToPoint(int point);
180
Sean Paulbbe39db2016-05-11 16:57:26 -0400181 void EmplaceCompositionPlane(DrmCompositionPlane::Type type,
Sean Paulca699be2016-05-11 16:29:45 -0400182 std::vector<DrmPlane *> *primary_planes,
183 std::vector<DrmPlane *> *overlay_planes);
184 void EmplaceCompositionPlane(size_t source_layer,
Zach Reiznerdb81fce2015-10-27 16:18:06 -0700185 std::vector<DrmPlane *> *primary_planes,
186 std::vector<DrmPlane *> *overlay_planes);
Zach Reizner5757e822015-10-16 19:06:31 -0700187 int CreateAndAssignReleaseFences();
188
Zach Reizner92f8e632015-10-12 17:47:13 -0700189 DrmResources *drm_ = NULL;
190 DrmCrtc *crtc_ = NULL;
191 Importer *importer_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700192
Zach Reizner92f8e632015-10-12 17:47:13 -0700193 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
194 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400195 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400196
Zach Reizner92f8e632015-10-12 17:47:13 -0700197 int timeline_fd_ = -1;
198 int timeline_ = 0;
199 int timeline_current_ = 0;
200 int timeline_squash_done_ = 0;
201 int timeline_pre_comp_done_ = 0;
202
Zach Reizner5757e822015-10-16 19:06:31 -0700203 bool geometry_changed_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700204 std::vector<DrmHwcLayer> layers_;
205 std::vector<DrmCompositionRegion> squash_regions_;
206 std::vector<DrmCompositionRegion> pre_comp_regions_;
207 std::vector<DrmCompositionPlane> composition_planes_;
208
209 uint64_t frame_no_ = 0;
Sean Paul98e73c82015-06-24 14:38:49 -0700210};
211}
212
213#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_