blob: bbac0af9d995ee45a4ca3e8e091ec97f25ce4e84 [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;
Zach Reizner92f8e632015-10-12 17:47:13 -070034
Sean Paulacb2a442015-06-24 18:43:01 -070035enum DrmCompositionType {
36 DRM_COMPOSITION_TYPE_EMPTY,
37 DRM_COMPOSITION_TYPE_FRAME,
Sean Pauldb7a17d2015-06-24 18:46:05 -070038 DRM_COMPOSITION_TYPE_DPMS,
Sean Paul57355412015-09-19 09:14:34 -040039 DRM_COMPOSITION_TYPE_MODESET,
Sean Paulacb2a442015-06-24 18:43:01 -070040};
41
Sean Paulca699be2016-05-11 16:29:45 -040042class DrmCompositionPlane {
43 public:
Sean Paulbbe39db2016-05-11 16:57:26 -040044 enum class Type : int32_t {
45 kDisable,
46 kLayer,
Sean Paulbbe39db2016-05-11 16:57:26 -040047 };
48
Sean Paulca699be2016-05-11 16:29:45 -040049 DrmCompositionPlane() = default;
50 DrmCompositionPlane(DrmCompositionPlane &&rhs) = default;
51 DrmCompositionPlane &operator=(DrmCompositionPlane &&other) = default;
Matvii Zorinf0757c22021-01-18 15:54:22 +020052 DrmCompositionPlane(Type type, DrmPlane *plane) : type_(type), plane_(plane) {
Sean Paulca699be2016-05-11 16:29:45 -040053 }
Matvii Zorinf0757c22021-01-18 15:54:22 +020054 DrmCompositionPlane(Type type, DrmPlane *plane, size_t source_layer)
55 : type_(type), plane_(plane), source_layers_(1, source_layer) {
Sean Paulca699be2016-05-11 16:29:45 -040056 }
57
Sean Paulbbe39db2016-05-11 16:57:26 -040058 Type type() const {
Sean Paulca699be2016-05-11 16:29:45 -040059 return type_;
60 }
61
62 DrmPlane *plane() const {
63 return plane_;
64 }
65 void set_plane(DrmPlane *plane) {
66 plane_ = plane;
67 }
68
Sean Paulca699be2016-05-11 16:29:45 -040069 std::vector<size_t> &source_layers() {
70 return source_layers_;
71 }
72
73 const std::vector<size_t> &source_layers() const {
74 return source_layers_;
75 }
76
77 private:
Sean Paulbbe39db2016-05-11 16:57:26 -040078 Type type_ = Type::kDisable;
Sean Paulca699be2016-05-11 16:29:45 -040079 DrmPlane *plane_ = NULL;
Sean Paulca699be2016-05-11 16:29:45 -040080 std::vector<size_t> source_layers_;
Zach Reizner4a253652015-09-10 18:30:54 -070081};
Sean Paul98e73c82015-06-24 14:38:49 -070082
83class DrmDisplayComposition {
84 public:
Zach Reizner92f8e632015-10-12 17:47:13 -070085 DrmDisplayComposition(const DrmDisplayComposition &) = delete;
Matvii Zorin704ea0e2021-01-08 12:55:45 +020086 DrmDisplayComposition(DrmCrtc *crtc, Planner *planner);
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020087 ~DrmDisplayComposition() = default;
Sean Paul98e73c82015-06-24 14:38:49 -070088
Zach Reizner5757e822015-10-16 19:06:31 -070089 int SetLayers(DrmHwcLayer *layers, size_t num_layers, bool geometry_changed);
Sean Paul4f4ef692016-05-03 16:40:59 -070090 int AddPlaneComposition(DrmCompositionPlane plane);
Sean Paul2e46fbd2015-07-09 17:22:22 -040091 int AddPlaneDisable(DrmPlane *plane);
Zach Reizner09807052015-08-13 14:53:41 -070092 int SetDpmsMode(uint32_t dpms_mode);
Sean Paul57355412015-09-19 09:14:34 -040093 int SetDisplayMode(const DrmMode &display_mode);
Sean Paul98e73c82015-06-24 14:38:49 -070094
Rob Herringaf0d9752018-05-04 16:34:19 -050095 int Plan(std::vector<DrmPlane *> *primary_planes,
Zach Reizner92f8e632015-10-12 17:47:13 -070096 std::vector<DrmPlane *> *overlay_planes);
Sean Paulacb2a442015-06-24 18:43:01 -070097
Zach Reizner92f8e632015-10-12 17:47:13 -070098 std::vector<DrmHwcLayer> &layers() {
99 return layers_;
100 }
101
Zach Reizner92f8e632015-10-12 17:47:13 -0700102 std::vector<DrmCompositionPlane> &composition_planes() {
103 return composition_planes_;
104 }
105
Haixia Shi6afbb6a2015-11-24 12:42:45 -0800106 bool geometry_changed() const {
107 return geometry_changed_;
108 }
109
Zach Reizner92f8e632015-10-12 17:47:13 -0700110 DrmCompositionType type() const {
111 return type_;
112 }
113
114 uint32_t dpms_mode() const {
115 return dpms_mode_;
116 }
117
118 const DrmMode &display_mode() const {
119 return display_mode_;
120 }
121
122 DrmCrtc *crtc() const {
123 return crtc_;
124 }
125
Sean Paulaa18d912016-05-12 14:28:05 -0400126 Planner *planner() const {
127 return planner_;
128 }
129
Roman Stratiienko0fade372021-02-20 13:59:55 +0200130 UniqueFd out_fence_;
131
Zach Reizner92f8e632015-10-12 17:47:13 -0700132 private:
133 bool validate_composition_type(DrmCompositionType desired);
134
Zach Reizner92f8e632015-10-12 17:47:13 -0700135 DrmCrtc *crtc_ = NULL;
Sean Paulaa18d912016-05-12 14:28:05 -0400136 Planner *planner_ = NULL;
Sean Paul98e73c82015-06-24 14:38:49 -0700137
Zach Reizner92f8e632015-10-12 17:47:13 -0700138 DrmCompositionType type_ = DRM_COMPOSITION_TYPE_EMPTY;
139 uint32_t dpms_mode_ = DRM_MODE_DPMS_ON;
Sean Paul57355412015-09-19 09:14:34 -0400140 DrmMode display_mode_;
Sean Paulbdc67bf2015-09-21 10:04:02 -0400141
Matvii Zorin704ea0e2021-01-08 12:55:45 +0200142 bool geometry_changed_ = true;
Zach Reizner92f8e632015-10-12 17:47:13 -0700143 std::vector<DrmHwcLayer> layers_;
Zach Reizner92f8e632015-10-12 17:47:13 -0700144 std::vector<DrmCompositionPlane> composition_planes_;
Sean Paul98e73c82015-06-24 14:38:49 -0700145};
Sean Paulf72cccd2018-08-27 13:59:08 -0400146} // namespace android
Sean Paul98e73c82015-06-24 14:38:49 -0700147
148#endif // ANDROID_DRM_DISPLAY_COMPOSITION_H_