blob: 2a5b1a43e1746e5d9f8927a37df64a2f5daf83ff [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 {
Zach Reizner92f8e632015-10-12 17:47:13 -070054 std::vector<size_t> source_layers;
55};
Sean Paul98e73c82015-06-24 14:38:49 -070056
Sean Paulca699be2016-05-11 16:29:45 -040057class DrmCompositionPlane {
58 public:
Sean Paulbbe39db2016-05-11 16:57:26 -040059 enum class Type : int32_t {
60 kDisable,
61 kLayer,
Sean Paulbbe39db2016-05-11 16:57:26 -040062 };
63
Sean Paulca699be2016-05-11 16:29:45 -040064 DrmCompositionPlane() = default;
65 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
66 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
Sean Paulbbe39db2016-05-11 16:57:26 -040067 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
Sean Paulca699be2016-05-11 16:29:45 -040068 : type_(type), plane_(plane), crtc_(crtc) {
69 }
Sean Paulbbe39db2016-05-11 16:57:26 -040070 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc,
71 size_t source_layer)
Sean Paulca699be2016-05-11 16:29:45 -040072 : type_(type),
73 plane_(plane),
74 crtc_(crtc),
75 source_layers_(1, source_layer) {
76 }
77
Sean Paulbbe39db2016-05-11 16:57:26 -040078 Type type() const {
Sean Paulca699be2016-05-11 16:29:45 -040079 return type_;
80 }
81
82 DrmPlane *plane() const {
83 return plane_;
84 }
85 void set_plane(DrmPlane *plane) {
86 plane_ = plane;
87 }
88
89 DrmCrtc *crtc() const {
90 return crtc_;
91 }
92
93 std::vector<size_t> &source_layers() {
94 return source_layers_;
95 }
96
97 const std::vector<size_t> &source_layers() const {
98 return source_layers_;
99 }
100
101 private:
Sean Paulbbe39db2016-05-11 16:57:26 -0400102 Type type_ = Type::kDisable;
Sean Paulca699be2016-05-11 16:29:45 -0400103 DrmPlane *plane_ = NULL;
104 DrmCrtc *crtc_ = NULL;
105 std::vector<size_t> source_layers_;
Zach Reizner4a253652015-09-10 18:30:54 -0700106};
Sean Paul98e73c82015-06-24 14:38:49 -0700107
108class DrmDisplayComposition {
109 public:
Zach Reizner92f8e632015-10-12 17:47:13 -0700110 DrmDisplayComposition() = default;
111 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Sean Paul98e73c82015-06-24 14:38:49 -0700112 ~DrmDisplayComposition();
113
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100114 int Init(DrmDevice *drm, DrmCrtc *crtc, Importer *importer, Planner *planner,
115 uint64_t frame_no);
Sean Paul98e73c82015-06-24 14:38:49 -0700116
Zach Reizner5757e822015-10-16 19:06:31 -0700117 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul4f4ef692016-05-03 16:40:59 -0700118 int AddPlaneComposition(DrmCompositionPlane plane);
Sean Paul2e46fbd2015-07-09 17:22:22 -0400119 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -0700120 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -0400121 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -0700122
Rob Herringaf0d9752018-05-04 16:34:19 -0500123 int Plan(std::vector<DrmPlane *> *primary_planes,
Zach Reizner92f8e632015-10-12 17:47:13 -0700124 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -0700125
Zach Reizner92f8e632015-10-12 17:47:13 -0700126 std::vector<DrmHwcLayer> &layers() {
127 return layers_;
128 }
129
Zach Reizner92f8e632015-10-12 17:47:13 -0700130 std::vector<DrmCompositionPlane> &composition_planes() {
131 return composition_planes_;
132 }
133
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800134 bool geometry_changed() const {
135 return geometry_changed_;
136 }
137
Zach Reizner92f8e632015-10-12 17:47:13 -0700138 uint64_t frame_no() const {
139 return frame_no_;
140 }
141
142 DrmCompositionType type() const {
143 return type_;
144 }
145
146 uint32_t dpms_mode() const {
147 return dpms_mode_;
148 }
149
150 const DrmMode &display_mode() const {
151 return display_mode_;
152 }
153
154 DrmCrtc *crtc() const {
155 return crtc_;
156 }
157
158 Importer *importer() const {
159 return importer_;
160 }
161
Sean Paulaa18d912016-05-12 14:28:05 -0400162 Planner *planner() const {
163 return planner_;
164 }
165
Robert Fossa1ade4e2017-09-27 19:28:15 +0200166 int take_out_fence() {
167 return out_fence_.Release();
168 }
169
170 void set_out_fence(int out_fence) {
171 out_fence_.Set(out_fence);
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
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +0100179 DrmDevice *drm_ = NULL;
Zach Reizner92f8e632015-10-12 17:47:13 -0700180 DrmCrtc *crtc_ = NULL;
181 Importer *importer_ = NULL;
Sean Paulaa18d912016-05-12 14:28:05 -0400182 Planner *planner_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700183
Zach Reizner92f8e632015-10-12 17:47:13 -0700184 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
185 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400186 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400187
Robert Fossa1ade4e2017-09-27 19:28:15 +0200188 UniqueFd out_fence_ = -1;
Zach Reizner92f8e632015-10-12 17:47:13 -0700189
Zach Reizner5757e822015-10-16 19:06:31 -0700190 bool geometry_changed_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700191 std::vector<DrmHwcLayer> layers_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700192 std::vector<DrmCompositionPlane> composition_planes_;
193
194 uint64_t frame_no_ = 0;
Sean Paul98e73c82015-06-24 14:38:49 -0700195};
Sean Paulf72cccd2018-08-27 13:59:08 -0400196} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -0700197
198#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_