blob: 6110becd8f52144033ac0f2b96b7423250bd056c [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"
Sean Paul98e73c82015-06-24 14:38:49 -070023
Zach Reiznerfd6dc332015-10-13 21:12:48 -070024#include <sstream>
Sean Paul98e73c82015-06-24 14:38:49 -070025#include <vector>
26
27#include <hardware/hardware.h>
28#include <hardware/hwcomposer.h>
29
30namespace android {
31
Sean Paul4c4646e2016-05-10 04:19:24 -040032class Importer;
Sean Paulaa18d912016-05-12 14:28:05 -040033class Planner;
Sean Paul5325e102016-03-29 13:55:35 -040034class SquashState;
Zach Reizner92f8e632015-10-12 17:47:13 -070035
Sean Paulacb2a442015-06-24 18:43:01 -070036enum DrmCompositionType {
37 DRM_COMPOSITION_TYPE_EMPTY,
38 DRM_COMPOSITION_TYPE_FRAME,
Sean Pauldb7a17d2015-06-24 18:46:05 -070039 DRM_COMPOSITION_TYPE_DPMS,
Sean Paul57355412015-09-19 09:14:34 -040040 DRM_COMPOSITION_TYPE_MODESET,
Sean Paulacb2a442015-06-24 18:43:01 -070041};
42
Sean Pauled45a8e2017-02-28 13:17:34 -050043struct DrmCompositionDisplayLayersMap {
44 int display;
45 bool geometry_changed = true;
46 std::vector<DrmHwcLayer> layers;
47
48 DrmCompositionDisplayLayersMap() = default;
49 DrmCompositionDisplayLayersMap(DrmCompositionDisplayLayersMap &&rhs) =
50 default;
51};
52
Zach Reizner92f8e632015-10-12 17:47:13 -070053struct DrmCompositionRegion {
54 DrmHwcRect<int> frame;
55 std::vector<size_t> source_layers;
56};
Sean Paul98e73c82015-06-24 14:38:49 -070057
Sean Paulca699be2016-05-11 16:29:45 -040058class DrmCompositionPlane {
59 public:
Sean Paulbbe39db2016-05-11 16:57:26 -040060 enum class Type : int32_t {
61 kDisable,
62 kLayer,
Sean Paulbbe39db2016-05-11 16:57:26 -040063 };
64
Sean Paulca699be2016-05-11 16:29:45 -040065 DrmCompositionPlane() = default;
66 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
67 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
Sean Paulbbe39db2016-05-11 16:57:26 -040068 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
Sean Paulca699be2016-05-11 16:29:45 -040069 : type_(type), plane_(plane), crtc_(crtc) {
70 }
Sean Paulbbe39db2016-05-11 16:57:26 -040071 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc,
72 size_t source_layer)
Sean Paulca699be2016-05-11 16:29:45 -040073 : type_(type),
74 plane_(plane),
75 crtc_(crtc),
76 source_layers_(1, source_layer) {
77 }
78
Sean Paulbbe39db2016-05-11 16:57:26 -040079 Type type() const {
Sean Paulca699be2016-05-11 16:29:45 -040080 return type_;
81 }
82
83 DrmPlane *plane() const {
84 return plane_;
85 }
86 void set_plane(DrmPlane *plane) {
87 plane_ = plane;
88 }
89
90 DrmCrtc *crtc() const {
91 return crtc_;
92 }
93
94 std::vector<size_t> &source_layers() {
95 return source_layers_;
96 }
97
98 const std::vector<size_t> &source_layers() const {
99 return source_layers_;
100 }
101
102 private:
Sean Paulbbe39db2016-05-11 16:57:26 -0400103 Type type_ = Type::kDisable;
Sean Paulca699be2016-05-11 16:29:45 -0400104 DrmPlane *plane_ = NULL;
105 DrmCrtc *crtc_ = NULL;
106 std::vector<size_t> source_layers_;
Zach Reizner4a253652015-09-10 18:30:54 -0700107};
Sean Paul98e73c82015-06-24 14:38:49 -0700108
109class DrmDisplayComposition {
110 public:
Zach Reizner92f8e632015-10-12 17:47:13 -0700111 DrmDisplayComposition() = default;
112 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Sean Paul98e73c82015-06-24 14:38:49 -0700113 ~DrmDisplayComposition();
114
Sean Paulbdc67bf2015-09-21 10:04:02 -0400115 int Init(DrmResources *drm, DrmCrtc *crtc, Importer *importer,
Sean Paulaa18d912016-05-12 14:28:05 -0400116 Planner *planner, uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -0700117
Zach Reizner5757e822015-10-16 19:06:31 -0700118 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul4f4ef692016-05-03 16:40:59 -0700119 int AddPlaneComposition(DrmCompositionPlane plane);
Sean Paul2e46fbd2015-07-09 17:22:22 -0400120 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -0700121 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -0400122 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -0700123
Rob Herringaf0d9752018-05-04 16:34:19 -0500124 int Plan(std::vector<DrmPlane *> *primary_planes,
Zach Reizner92f8e632015-10-12 17:47:13 -0700125 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -0700126
Sean Paul4f4ef692016-05-03 16:40:59 -0700127 int FinalizeComposition();
128
Zach Reizner92f8e632015-10-12 17:47:13 -0700129 std::vector<DrmHwcLayer> &layers() {
130 return layers_;
131 }
132
Zach Reizner92f8e632015-10-12 17:47:13 -0700133 std::vector<DrmCompositionPlane> &composition_planes() {
134 return composition_planes_;
135 }
136
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800137 bool geometry_changed() const {
138 return geometry_changed_;
139 }
140
Zach Reizner92f8e632015-10-12 17:47:13 -0700141 uint64_t frame_no() const {
142 return frame_no_;
143 }
144
145 DrmCompositionType type() const {
146 return type_;
147 }
148
149 uint32_t dpms_mode() const {
150 return dpms_mode_;
151 }
152
153 const DrmMode &display_mode() const {
154 return display_mode_;
155 }
156
157 DrmCrtc *crtc() const {
158 return crtc_;
159 }
160
161 Importer *importer() const {
162 return importer_;
163 }
164
Sean Paulaa18d912016-05-12 14:28:05 -0400165 Planner *planner() const {
166 return planner_;
167 }
168
Robert Fossa1ade4e2017-09-27 19:28:15 +0200169 int take_out_fence() {
170 return out_fence_.Release();
171 }
172
173 void set_out_fence(int out_fence) {
174 out_fence_.Set(out_fence);
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
Sean Paulaa18d912016-05-12 14:28:05 -0400182 int FinalizeComposition(DrmHwcRect<int> *exclude_rects,
183 size_t num_exclude_rects);
184 void SeparateLayers(DrmHwcRect<int> *exclude_rects, size_t num_exclude_rects);
Zach Reizner5757e822015-10-16 19:06:31 -0700185
Zach Reizner92f8e632015-10-12 17:47:13 -0700186 DrmResources *drm_ = NULL;
187 DrmCrtc *crtc_ = NULL;
188 Importer *importer_ = NULL;
Sean Paulaa18d912016-05-12 14:28:05 -0400189 Planner *planner_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700190
Zach Reizner92f8e632015-10-12 17:47:13 -0700191 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
192 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400193 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400194
Robert Fossa1ade4e2017-09-27 19:28:15 +0200195 UniqueFd out_fence_ = -1;
Zach Reizner92f8e632015-10-12 17:47:13 -0700196
Zach Reizner5757e822015-10-16 19:06:31 -0700197 bool geometry_changed_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700198 std::vector<DrmHwcLayer> layers_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700199 std::vector<DrmCompositionPlane> composition_planes_;
200
201 uint64_t frame_no_ = 0;
Sean Paul98e73c82015-06-24 14:38:49 -0700202};
203}
204
205#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_