blob: 3a10a8c6347ec921a7d39557382c00a3fac584eb [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
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030020#include <hardware/hardware.h>
21#include <hardware/hwcomposer.h>
Sean Paul98e73c82015-06-24 14:38:49 -070022
Zach Reiznerfd6dc332015-10-13 21:12:48 -070023#include <sstream>
Sean Paul98e73c82015-06-24 14:38:49 -070024#include <vector>
25
Roman Stratiienko13cc3662020-08-29 21:35:39 +030026#include "drm/DrmCrtc.h"
27#include "drm/DrmPlane.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030028#include "drmhwcomposer.h"
Sean Paul98e73c82015-06-24 14:38:49 -070029
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(const DrmDisplayComposition &) = delete;
Matvii Zorin704ea0e2021-01-08 12:55:45 +0200111 DrmDisplayComposition(DrmCrtc *crtc, Planner *planner);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200112 ~DrmDisplayComposition() = default;
Sean Paul98e73c82015-06-24 14:38:49 -0700113
Zach Reizner5757e822015-10-16 19:06:31 -0700114 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul4f4ef692016-05-03 16:40:59 -0700115 int AddPlaneComposition(DrmCompositionPlane plane);
Sean Paul2e46fbd2015-07-09 17:22:22 -0400116 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -0700117 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -0400118 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -0700119
Rob Herringaf0d9752018-05-04 16:34:19 -0500120 int Plan(std::vector<DrmPlane *> *primary_planes,
Zach Reizner92f8e632015-10-12 17:47:13 -0700121 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -0700122
Zach Reizner92f8e632015-10-12 17:47:13 -0700123 std::vector<DrmHwcLayer> &layers() {
124 return layers_;
125 }
126
Zach Reizner92f8e632015-10-12 17:47:13 -0700127 std::vector<DrmCompositionPlane> &composition_planes() {
128 return composition_planes_;
129 }
130
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800131 bool geometry_changed() const {
132 return geometry_changed_;
133 }
134
Zach Reizner92f8e632015-10-12 17:47:13 -0700135 DrmCompositionType type() const {
136 return type_;
137 }
138
139 uint32_t dpms_mode() const {
140 return dpms_mode_;
141 }
142
143 const DrmMode &display_mode() const {
144 return display_mode_;
145 }
146
147 DrmCrtc *crtc() const {
148 return crtc_;
149 }
150
Sean Paulaa18d912016-05-12 14:28:05 -0400151 Planner *planner() const {
152 return planner_;
153 }
154
Robert Fossa1ade4e2017-09-27 19:28:15 +0200155 int take_out_fence() {
156 return out_fence_.Release();
157 }
158
159 void set_out_fence(int out_fence) {
160 out_fence_.Set(out_fence);
161 }
162
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700163 void Dump(std::ostringstream *out) const;
164
Zach Reizner92f8e632015-10-12 17:47:13 -0700165 private:
166 bool validate_composition_type(DrmCompositionType desired);
167
Zach Reizner92f8e632015-10-12 17:47:13 -0700168 DrmCrtc *crtc_ = NULL;
Sean Paulaa18d912016-05-12 14:28:05 -0400169 Planner *planner_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700170
Zach Reizner92f8e632015-10-12 17:47:13 -0700171 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
172 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400173 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400174
Robert Fossa1ade4e2017-09-27 19:28:15 +0200175 UniqueFd out_fence_ = -1;
Zach Reizner92f8e632015-10-12 17:47:13 -0700176
Matvii Zorin704ea0e2021-01-08 12:55:45 +0200177 bool geometry_changed_ = true;
Zach Reizner92f8e632015-10-12 17:47:13 -0700178 std::vector<DrmHwcLayer> layers_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700179 std::vector<DrmCompositionPlane> composition_planes_;
Sean Paul98e73c82015-06-24 14:38:49 -0700180};
Sean Paulf72cccd2018-08-27 13:59:08 -0400181} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -0700182
183#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_