blob: 570905f79fcf194fa14fa27f48b07708b1817ddc [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
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#define LOG_TAG "hwc-drm-plane"
18
Roman Stratiienko13cc3662020-08-29 21:35:39 +030019#include "DrmPlane.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040020
21#include <errno.h>
22#include <stdint.h>
Roman Stratiienko13cc3662020-08-29 21:35:39 +030023
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020024#include <cerrno>
Sean Paulf72cccd2018-08-27 13:59:08 -040025#include <cinttypes>
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020026#include <cstdint>
Sean Paul6a55e9f2015-04-30 15:31:06 -040027
Roman Stratiienko13cc3662020-08-29 21:35:39 +030028#include "DrmDevice.h"
Roman Stratiienkod518a052021-02-25 19:15:14 +020029#include "bufferinfo/BufferInfoGetter.h"
30#include "utils/log.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040031
32namespace android {
33
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010034DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p)
Roman Kovalivskyi859b6072020-03-26 05:03:39 +020035 : drm_(drm),
36 id_(p->plane_id),
37 possible_crtc_mask_(p->possible_crtcs),
38 formats_(p->formats, p->formats + p->count_formats) {
Sean Paul6a55e9f2015-04-30 15:31:06 -040039}
40
Sean Paul6a55e9f2015-04-30 15:31:06 -040041int DrmPlane::Init() {
42 DrmProperty p;
43
44 int ret = drm_->GetPlaneProperty(*this, "type", &p);
45 if (ret) {
46 ALOGE("Could not get plane type property");
47 return ret;
48 }
49
Roman Stratiienkob3b5c1e2021-02-15 13:44:19 +020050 uint64_t type = 0;
Sean Paulfc0b1da2019-03-06 09:48:42 -050051 std::tie(ret, type) = p.value();
Sean Paul6a55e9f2015-04-30 15:31:06 -040052 if (ret) {
53 ALOGE("Failed to get plane type property value");
54 return ret;
55 }
56 switch (type) {
57 case DRM_PLANE_TYPE_OVERLAY:
58 case DRM_PLANE_TYPE_PRIMARY:
59 case DRM_PLANE_TYPE_CURSOR:
60 type_ = (uint32_t)type;
61 break;
62 default:
Sean Paulf741c672016-05-11 13:49:38 -040063 ALOGE("Invalid plane type %" PRIu64, type);
Sean Paul6a55e9f2015-04-30 15:31:06 -040064 return -EINVAL;
65 }
66
67 ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_);
68 if (ret) {
69 ALOGE("Could not get CRTC_ID property");
70 return ret;
71 }
72
73 ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_);
74 if (ret) {
75 ALOGE("Could not get FB_ID property");
76 return ret;
77 }
78
79 ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_);
80 if (ret) {
81 ALOGE("Could not get CRTC_X property");
82 return ret;
83 }
84
85 ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_);
86 if (ret) {
87 ALOGE("Could not get CRTC_Y property");
88 return ret;
89 }
90
91 ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_);
92 if (ret) {
93 ALOGE("Could not get CRTC_W property");
94 return ret;
95 }
96
97 ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_);
98 if (ret) {
99 ALOGE("Could not get CRTC_H property");
100 return ret;
101 }
102
103 ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_);
104 if (ret) {
105 ALOGE("Could not get SRC_X property");
106 return ret;
107 }
108
109 ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_);
110 if (ret) {
111 ALOGE("Could not get SRC_Y property");
112 return ret;
113 }
114
115 ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_);
116 if (ret) {
117 ALOGE("Could not get SRC_W property");
118 return ret;
119 }
120
121 ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_);
122 if (ret) {
123 ALOGE("Could not get SRC_H property");
124 return ret;
125 }
126
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +0100127 ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_);
128 if (ret)
129 ALOGE("Could not get zpos property for plane %u", id());
130
Sean Paul1c4c3262015-07-14 15:51:52 -0400131 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
132 if (ret)
133 ALOGE("Could not get rotation property");
134
Sean Pauld8aefb62015-10-15 15:17:31 -0400135 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
136 if (ret)
137 ALOGI("Could not get alpha property");
138
Lowry Li9b6cafd2018-08-28 17:58:21 +0800139 ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
140 if (ret)
141 ALOGI("Could not get pixel blend mode property");
142
Robert Fossa09220c2016-09-30 10:27:23 -0400143 ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
144 if (ret)
145 ALOGI("Could not get IN_FENCE_FD property");
146
Matvii Zorin8338c342020-09-08 16:12:51 +0300147 if (HasNonRgbFormat()) {
148 ret = drm_->GetPlaneProperty(*this, "COLOR_ENCODING",
149 &color_encoding_propery_);
150 if (ret)
151 ALOGI("Could not get COLOR_ENCODING property");
152
153 ret = drm_->GetPlaneProperty(*this, "COLOR_RANGE", &color_range_property_);
154 if (ret)
155 ALOGI("Could not get COLOR_RANGE property");
156 }
157
Sean Paul6a55e9f2015-04-30 15:31:06 -0400158 return 0;
159}
160
161uint32_t DrmPlane::id() const {
162 return id_;
163}
164
165bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +0200166 return ((1 << crtc.pipe()) & possible_crtc_mask_) != 0;
Sean Paul6a55e9f2015-04-30 15:31:06 -0400167}
168
169uint32_t DrmPlane::type() const {
170 return type_;
171}
172
Roman Kovalivskyi859b6072020-03-26 05:03:39 +0200173bool DrmPlane::IsFormatSupported(uint32_t format) const {
174 return std::find(std::begin(formats_), std::end(formats_), format) !=
175 std::end(formats_);
176}
177
Matvii Zorin8338c342020-09-08 16:12:51 +0300178bool DrmPlane::HasNonRgbFormat() const {
179 return std::find_if_not(std::begin(formats_), std::end(formats_),
180 [](uint32_t format) {
181 return BufferInfoGetter::IsDrmFormatRgb(format);
182 }) != std::end(formats_);
183}
184
Sean Paul6a55e9f2015-04-30 15:31:06 -0400185const DrmProperty &DrmPlane::crtc_property() const {
186 return crtc_property_;
187}
188
189const DrmProperty &DrmPlane::fb_property() const {
190 return fb_property_;
191}
192
193const DrmProperty &DrmPlane::crtc_x_property() const {
194 return crtc_x_property_;
195}
196
197const DrmProperty &DrmPlane::crtc_y_property() const {
198 return crtc_y_property_;
199}
200
201const DrmProperty &DrmPlane::crtc_w_property() const {
202 return crtc_w_property_;
203}
204
205const DrmProperty &DrmPlane::crtc_h_property() const {
206 return crtc_h_property_;
207}
208
209const DrmProperty &DrmPlane::src_x_property() const {
210 return src_x_property_;
211}
212
213const DrmProperty &DrmPlane::src_y_property() const {
214 return src_y_property_;
215}
216
217const DrmProperty &DrmPlane::src_w_property() const {
218 return src_w_property_;
219}
220
221const DrmProperty &DrmPlane::src_h_property() const {
222 return src_h_property_;
223}
Sean Paul1c4c3262015-07-14 15:51:52 -0400224
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +0100225const DrmProperty &DrmPlane::zpos_property() const {
226 return zpos_property_;
227}
228
Sean Paul1c4c3262015-07-14 15:51:52 -0400229const DrmProperty &DrmPlane::rotation_property() const {
230 return rotation_property_;
231}
Sean Pauld8aefb62015-10-15 15:17:31 -0400232
233const DrmProperty &DrmPlane::alpha_property() const {
234 return alpha_property_;
235}
Robert Fossa09220c2016-09-30 10:27:23 -0400236
Lowry Li9b6cafd2018-08-28 17:58:21 +0800237const DrmProperty &DrmPlane::blend_property() const {
238 return blend_property_;
239}
240
Robert Fossa09220c2016-09-30 10:27:23 -0400241const DrmProperty &DrmPlane::in_fence_fd_property() const {
242 return in_fence_fd_property_;
243}
Matvii Zorin8338c342020-09-08 16:12:51 +0300244
245const DrmProperty &DrmPlane::color_encoding_propery() const {
246 return color_encoding_propery_;
247}
248
249const DrmProperty &DrmPlane::color_range_property() const {
250 return color_range_property_;
251}
Sean Paulf72cccd2018-08-27 13:59:08 -0400252} // namespace android