1 /*
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
19 #include "drmplane.h"
20
21 #include <errno.h>
22 #include <log/log.h>
23 #include <stdint.h>
24 #include <xf86drmMode.h>
25
26 #include <cinttypes>
27
28 #include "drmdevice.h"
29
30 namespace android {
31
DrmPlane(DrmDevice * drm,drmModePlanePtr p)32 DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p)
33 : drm_(drm), id_(p->plane_id), possible_crtc_mask_(p->possible_crtcs) {
34 for (uint32_t i = 0; i < p->count_formats; i++) {
35 formats_.push_back(p->formats[i]);
36 }
37 }
38
Init()39 int DrmPlane::Init() {
40 DrmProperty p;
41
42 int ret = drm_->GetPlaneProperty(*this, "type", &p);
43 if (ret) {
44 ALOGE("Could not get plane type property");
45 return ret;
46 }
47
48 uint64_t type;
49 std::tie(ret, type) = p.value();
50 if (ret) {
51 ALOGE("Failed to get plane type property value");
52 return ret;
53 }
54 switch (type) {
55 case DRM_PLANE_TYPE_OVERLAY:
56 case DRM_PLANE_TYPE_PRIMARY:
57 case DRM_PLANE_TYPE_CURSOR:
58 type_ = (uint32_t)type;
59 break;
60 default:
61 ALOGE("Invalid plane type %" PRIu64, type);
62 return -EINVAL;
63 }
64
65 ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_);
66 if (ret) {
67 ALOGE("Could not get CRTC_ID property");
68 return ret;
69 }
70
71 ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_);
72 if (ret) {
73 ALOGE("Could not get FB_ID property");
74 return ret;
75 }
76
77 ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_);
78 if (ret) {
79 ALOGE("Could not get CRTC_X property");
80 return ret;
81 }
82
83 ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_);
84 if (ret) {
85 ALOGE("Could not get CRTC_Y property");
86 return ret;
87 }
88
89 ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_);
90 if (ret) {
91 ALOGE("Could not get CRTC_W property");
92 return ret;
93 }
94
95 ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_);
96 if (ret) {
97 ALOGE("Could not get CRTC_H property");
98 return ret;
99 }
100
101 ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_);
102 if (ret) {
103 ALOGE("Could not get SRC_X property");
104 return ret;
105 }
106
107 ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_);
108 if (ret) {
109 ALOGE("Could not get SRC_Y property");
110 return ret;
111 }
112
113 ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_);
114 if (ret) {
115 ALOGE("Could not get SRC_W property");
116 return ret;
117 }
118
119 ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_);
120 if (ret) {
121 ALOGE("Could not get SRC_H property");
122 return ret;
123 }
124
125 ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_);
126 if (ret)
127 ALOGE("Could not get zpos property for plane %u", id());
128
129 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
130 if (ret)
131 ALOGE("Could not get rotation property");
132
133 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
134 if (ret)
135 ALOGI("Could not get alpha property");
136
137 ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
138 if (ret)
139 ALOGI("Could not get pixel blend mode property");
140
141 ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
142 if (ret)
143 ALOGI("Could not get IN_FENCE_FD property");
144
145 ret = drm_->GetPlaneProperty(*this, "standard", &standard_);
146 if (ret)
147 ALOGI("Could not get standard property");
148
149 ret = drm_->GetPlaneProperty(*this, "transfer", &transfer_);
150 if (ret)
151 ALOGI("Could not get transfer property");
152
153 ret = drm_->GetPlaneProperty(*this, "range", &range_);
154 if (ret)
155 ALOGI("Could not get range property");
156
157 ret = drm_->GetPlaneProperty(*this, "max_luminance", &max_luminance_);
158 if (ret)
159 ALOGI("Could not get max_luminance property");
160
161 ret = drm_->GetPlaneProperty(*this, "min_luminance", &min_luminance_);
162 if (ret)
163 ALOGI("Could not get min_luminance property");
164
165 ret = drm_->GetPlaneProperty(*this, "hw restrictions", &hw_restrictions_);
166 if (ret)
167 ALOGI("Could not get hw restrictions property");
168
169 if (drm_->GetPlaneProperty(*this, "eotf_lut", &eotf_lut_))
170 ALOGI("Could not get eotf_lut property");
171 if (drm_->GetPlaneProperty(*this, "oetf_lut", &oetf_lut_))
172 ALOGI("Could not get oetf_lut property");
173 if (drm_->GetPlaneProperty(*this, "gammut_matrix", &gammut_matrix_))
174 ALOGI("Could not get gammut_matrix property");
175 if (drm_->GetPlaneProperty(*this, "tone_mapping", &tone_mapping_))
176 ALOGI("Could not get tone_mapping property");
177 if (drm_->GetPlaneProperty(*this, "colormap", &colormap_))
178 ALOGI("Could not get colormap property");
179 if (drm_->GetPlaneProperty(*this, "block", &block_))
180 ALOGI("Could not get block property");
181
182 properties_.push_back(&crtc_property_);
183 properties_.push_back(&fb_property_);
184 properties_.push_back(&crtc_x_property_);
185 properties_.push_back(&crtc_y_property_);
186 properties_.push_back(&crtc_w_property_);
187 properties_.push_back(&crtc_h_property_);
188 properties_.push_back(&src_x_property_);
189 properties_.push_back(&src_y_property_);
190 properties_.push_back(&src_w_property_);
191 properties_.push_back(&src_h_property_);
192 properties_.push_back(&zpos_property_);
193 properties_.push_back(&rotation_property_);
194 properties_.push_back(&alpha_property_);
195 properties_.push_back(&blend_property_);
196 properties_.push_back(&in_fence_fd_property_);
197 properties_.push_back(&standard_);
198 properties_.push_back(&transfer_);
199 properties_.push_back(&range_);
200 properties_.push_back(&max_luminance_);
201 properties_.push_back(&min_luminance_);
202 properties_.push_back(&hw_restrictions_);
203 properties_.push_back(&eotf_lut_);
204 properties_.push_back(&oetf_lut_);
205 properties_.push_back(&gammut_matrix_);
206 properties_.push_back(&tone_mapping_);
207 properties_.push_back(&colormap_);
208 properties_.push_back(&block_);
209
210 return 0;
211 }
212
id() const213 uint32_t DrmPlane::id() const {
214 return id_;
215 }
216
GetCrtcSupported(const DrmCrtc & crtc) const217 bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
218 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
219 }
220
isFormatSupported(const uint32_t format) const221 bool DrmPlane::isFormatSupported(const uint32_t format) const {
222 return std::find(formats_.begin(), formats_.end(), format) != formats_.end();
223 }
224
getNumFormatSupported() const225 uint32_t DrmPlane::getNumFormatSupported() const {
226 return formats_.size();
227 }
228
type() const229 uint32_t DrmPlane::type() const {
230 return type_;
231 }
232
crtc_property() const233 const DrmProperty &DrmPlane::crtc_property() const {
234 return crtc_property_;
235 }
236
fb_property() const237 const DrmProperty &DrmPlane::fb_property() const {
238 return fb_property_;
239 }
240
crtc_x_property() const241 const DrmProperty &DrmPlane::crtc_x_property() const {
242 return crtc_x_property_;
243 }
244
crtc_y_property() const245 const DrmProperty &DrmPlane::crtc_y_property() const {
246 return crtc_y_property_;
247 }
248
crtc_w_property() const249 const DrmProperty &DrmPlane::crtc_w_property() const {
250 return crtc_w_property_;
251 }
252
crtc_h_property() const253 const DrmProperty &DrmPlane::crtc_h_property() const {
254 return crtc_h_property_;
255 }
256
src_x_property() const257 const DrmProperty &DrmPlane::src_x_property() const {
258 return src_x_property_;
259 }
260
src_y_property() const261 const DrmProperty &DrmPlane::src_y_property() const {
262 return src_y_property_;
263 }
264
src_w_property() const265 const DrmProperty &DrmPlane::src_w_property() const {
266 return src_w_property_;
267 }
268
src_h_property() const269 const DrmProperty &DrmPlane::src_h_property() const {
270 return src_h_property_;
271 }
272
zpos_property() const273 const DrmProperty &DrmPlane::zpos_property() const {
274 return zpos_property_;
275 }
276
rotation_property() const277 const DrmProperty &DrmPlane::rotation_property() const {
278 return rotation_property_;
279 }
280
alpha_property() const281 const DrmProperty &DrmPlane::alpha_property() const {
282 return alpha_property_;
283 }
284
blend_property() const285 const DrmProperty &DrmPlane::blend_property() const {
286 return blend_property_;
287 }
288
in_fence_fd_property() const289 const DrmProperty &DrmPlane::in_fence_fd_property() const {
290 return in_fence_fd_property_;
291 }
292
standard_property() const293 const DrmProperty &DrmPlane::standard_property() const {
294 return standard_;
295 }
296
transfer_property() const297 const DrmProperty &DrmPlane::transfer_property() const {
298 return transfer_;
299 }
300
range_property() const301 const DrmProperty &DrmPlane::range_property() const {
302 return range_;
303 }
304
max_luminance_property() const305 const DrmProperty &DrmPlane::max_luminance_property() const {
306 return max_luminance_;
307 }
308
min_luminance_property() const309 const DrmProperty &DrmPlane::min_luminance_property() const {
310 return min_luminance_;
311 }
312
hw_restrictions_property() const313 const DrmProperty &DrmPlane::hw_restrictions_property() const {
314 return hw_restrictions_;
315 }
316
eotf_lut_property() const317 const DrmProperty &DrmPlane::eotf_lut_property() const {
318 return eotf_lut_;
319 }
320
oetf_lut_property() const321 const DrmProperty &DrmPlane::oetf_lut_property() const {
322 return oetf_lut_;
323 }
324
gammut_matrix_property() const325 const DrmProperty &DrmPlane::gammut_matrix_property() const {
326 return gammut_matrix_;
327 }
328
tone_mapping_property() const329 const DrmProperty &DrmPlane::tone_mapping_property() const {
330 return tone_mapping_;
331 }
332
colormap_property() const333 const DrmProperty &DrmPlane::colormap_property() const {
334 return colormap_;
335 }
336
block_property() const337 const DrmProperty &DrmPlane::block_property() const {
338 return block_;
339 }
340
341 } // namespace android
342