blob: d7ee9cf58a0bac325e46b95745341c939ee9874f [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
Sean Paulca699be2016-05-11 16:29:45 -040053class DrmCompositionPlane {
54 public:
Sean Paulbbe39db2016-05-11 16:57:26 -040055 enum class Type : int32_t {
56 kDisable,
57 kLayer,
Sean Paulbbe39db2016-05-11 16:57:26 -040058 };
59
Sean Paulca699be2016-05-11 16:29:45 -040060 DrmCompositionPlane() = default;
61 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
62 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
Sean Paulbbe39db2016-05-11 16:57:26 -040063 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc)
Sean Paulca699be2016-05-11 16:29:45 -040064 : type_(type), plane_(plane), crtc_(crtc) {
65 }
Sean Paulbbe39db2016-05-11 16:57:26 -040066 DrmCompositionPlane(Type type, DrmPlane *plane, DrmCrtc *crtc,
67 size_t source_layer)
Sean Paulca699be2016-05-11 16:29:45 -040068 : type_(type),
69 plane_(plane),
70 crtc_(crtc),
71 source_layers_(1, source_layer) {
72 }
73
Sean Paulbbe39db2016-05-11 16:57:26 -040074 Type type() const {
Sean Paulca699be2016-05-11 16:29:45 -040075 return type_;
76 }
77
78 DrmPlane *plane() const {
79 return plane_;
80 }
81 void set_plane(DrmPlane *plane) {
82 plane_ = plane;
83 }
84
85 DrmCrtc *crtc() const {
86 return crtc_;
87 }
88
89 std::vector<size_t> &source_layers() {
90 return source_layers_;
91 }
92
93 const std::vector<size_t> &source_layers() const {
94 return source_layers_;
95 }
96
97 private:
Sean Paulbbe39db2016-05-11 16:57:26 -040098 Type type_ = Type::kDisable;
Sean Paulca699be2016-05-11 16:29:45 -040099 DrmPlane *plane_ = NULL;
100 DrmCrtc *crtc_ = NULL;
101 std::vector<size_t> source_layers_;
Zach Reizner4a253652015-09-10 18:30:54 -0700102};
Sean Paul98e73c82015-06-24 14:38:49 -0700103
104class DrmDisplayComposition {
105 public:
Zach Reizner92f8e632015-10-12 17:47:13 -0700106 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Matvii Zorin704ea0e2021-01-08 12:55:45 +0200107 DrmDisplayComposition(DrmCrtc *crtc, Planner *planner);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200108 ~DrmDisplayComposition() = default;
Sean Paul98e73c82015-06-24 14:38:49 -0700109
Zach Reizner5757e822015-10-16 19:06:31 -0700110 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul4f4ef692016-05-03 16:40:59 -0700111 int AddPlaneComposition(DrmCompositionPlane plane);
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
Rob Herringaf0d9752018-05-04 16:34:19 -0500116 int Plan(std::vector<DrmPlane *> *primary_planes,
Zach Reizner92f8e632015-10-12 17:47:13 -0700117 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -0700118
Zach Reizner92f8e632015-10-12 17:47:13 -0700119 std::vector<DrmHwcLayer> &layers() {
120 return layers_;
121 }
122
Zach Reizner92f8e632015-10-12 17:47:13 -0700123 std::vector<DrmCompositionPlane> &composition_planes() {
124 return composition_planes_;
125 }
126
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800127 bool geometry_changed() const {
128 return geometry_changed_;
129 }
130
Zach Reizner92f8e632015-10-12 17:47:13 -0700131 DrmCompositionType type() const {
132 return type_;
133 }
134
135 uint32_t dpms_mode() const {
136 return dpms_mode_;
137 }
138
139 const DrmMode &display_mode() const {
140 return display_mode_;
141 }
142
143 DrmCrtc *crtc() const {
144 return crtc_;
145 }
146
Sean Paulaa18d912016-05-12 14:28:05 -0400147 Planner *planner() const {
148 return planner_;
149 }
150
Robert Fossa1ade4e2017-09-27 19:28:15 +0200151 int take_out_fence() {
152 return out_fence_.Release();
153 }
154
155 void set_out_fence(int out_fence) {
156 out_fence_.Set(out_fence);
157 }
158
Zach Reiznerfd6dc332015-10-13 21:12:48 -0700159 void Dump(std::ostringstream *out) const;
160
Zach Reizner92f8e632015-10-12 17:47:13 -0700161 private:
162 bool validate_composition_type(DrmCompositionType desired);
163
Zach Reizner92f8e632015-10-12 17:47:13 -0700164 DrmCrtc *crtc_ = NULL;
Sean Paulaa18d912016-05-12 14:28:05 -0400165 Planner *planner_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700166
Zach Reizner92f8e632015-10-12 17:47:13 -0700167 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
168 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400169 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400170
Robert Fossa1ade4e2017-09-27 19:28:15 +0200171 UniqueFd out_fence_ = -1;
Zach Reizner92f8e632015-10-12 17:47:13 -0700172
Matvii Zorin704ea0e2021-01-08 12:55:45 +0200173 bool geometry_changed_ = true;
Zach Reizner92f8e632015-10-12 17:47:13 -0700174 std::vector<DrmHwcLayer> layers_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700175 std::vector<DrmCompositionPlane> composition_planes_;
Sean Paul98e73c82015-06-24 14:38:49 -0700176};
Sean Paulf72cccd2018-08-27 13:59:08 -0400177} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -0700178
179#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_