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 #include "drmdevice.h"
21
22 #include <errno.h>
23 #include <stdint.h>
24 #include <cinttypes>
25
26 #include <log/log.h>
27 #include <xf86drmMode.h>
28
29 namespace android {
30
DrmPlane(DrmDevice * drm,drmModePlanePtr p)31 DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p)
32 : drm_(drm), id_(p->plane_id), possible_crtc_mask_(p->possible_crtcs) {
33 for (uint32_t i = 0; i < p->count_formats; i++) {
34 formats_.push_back(p->formats[i]);
35 }
36 }
37
Init()38 int DrmPlane::Init() {
39 DrmProperty p;
40
41 int ret = drm_->GetPlaneProperty(*this, "type", &p);
42 if (ret) {
43 ALOGE("Could not get plane type property");
44 return ret;
45 }
46
47 uint64_t type;
48 std::tie(ret, type) = p.value();
49 if (ret) {
50 ALOGE("Failed to get plane type property value");
51 return ret;
52 }
53 switch (type) {
54 case DRM_PLANE_TYPE_OVERLAY:
55 case DRM_PLANE_TYPE_PRIMARY:
56 case DRM_PLANE_TYPE_CURSOR:
57 type_ = (uint32_t)type;
58 break;
59 default:
60 ALOGE("Invalid plane type %" PRIu64, type);
61 return -EINVAL;
62 }
63
64 ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_);
65 if (ret) {
66 ALOGE("Could not get CRTC_ID property");
67 return ret;
68 }
69
70 ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_);
71 if (ret) {
72 ALOGE("Could not get FB_ID property");
73 return ret;
74 }
75
76 ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_);
77 if (ret) {
78 ALOGE("Could not get CRTC_X property");
79 return ret;
80 }
81
82 ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_);
83 if (ret) {
84 ALOGE("Could not get CRTC_Y property");
85 return ret;
86 }
87
88 ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_);
89 if (ret) {
90 ALOGE("Could not get CRTC_W property");
91 return ret;
92 }
93
94 ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_);
95 if (ret) {
96 ALOGE("Could not get CRTC_H property");
97 return ret;
98 }
99
100 ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_);
101 if (ret) {
102 ALOGE("Could not get SRC_X property");
103 return ret;
104 }
105
106 ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_);
107 if (ret) {
108 ALOGE("Could not get SRC_Y property");
109 return ret;
110 }
111
112 ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_);
113 if (ret) {
114 ALOGE("Could not get SRC_W property");
115 return ret;
116 }
117
118 ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_);
119 if (ret) {
120 ALOGE("Could not get SRC_H property");
121 return ret;
122 }
123
124 ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_);
125 if (ret)
126 ALOGE("Could not get zpos property for plane %u", id());
127
128 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
129 if (ret)
130 ALOGE("Could not get rotation property");
131
132 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
133 if (ret)
134 ALOGI("Could not get alpha property");
135
136 ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
137 if (ret)
138 ALOGI("Could not get pixel blend mode property");
139
140 ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
141 if (ret)
142 ALOGI("Could not get IN_FENCE_FD property");
143
144 ret = drm_->GetPlaneProperty(*this, "standard", &standard_);
145 if (ret)
146 ALOGI("Could not get standard property");
147
148 ret = drm_->GetPlaneProperty(*this, "transfer", &transfer_);
149 if (ret)
150 ALOGI("Could not get transfer property");
151
152 ret = drm_->GetPlaneProperty(*this, "range", &range_);
153 if (ret)
154 ALOGI("Could not get range property");
155
156 ret = drm_->GetPlaneProperty(*this, "max_luminance", &max_luminance_);
157 if (ret)
158 ALOGI("Could not get max_luminance property");
159
160 ret = drm_->GetPlaneProperty(*this, "min_luminance", &min_luminance_);
161 if (ret)
162 ALOGI("Could not get min_luminance property");
163
164 ret = drm_->GetPlaneProperty(*this, "hw restrictions", &hw_restrictions_);
165 if (ret)
166 ALOGI("Could not get hw restrictions property");
167
168 if (drm_->GetPlaneProperty(*this, "eotf_lut", &eotf_lut_))
169 ALOGI("Could not get eotf_lut property");
170 if (drm_->GetPlaneProperty(*this, "oetf_lut", &oetf_lut_))
171 ALOGI("Could not get oetf_lut property");
172 if (drm_->GetPlaneProperty(*this, "gammut_matrix", &gammut_matrix_))
173 ALOGI("Could not get gammut_matrix property");
174 if (drm_->GetPlaneProperty(*this, "tone_mapping", &tone_mapping_))
175 ALOGI("Could not get tone_mapping property");
176
177 if (drm_->GetPlaneProperty(*this, "colormap", &colormap_))
178 ALOGI("Could not get colormap property");
179
180 properties_.push_back(&crtc_property_);
181 properties_.push_back(&fb_property_);
182 properties_.push_back(&crtc_x_property_);
183 properties_.push_back(&crtc_y_property_);
184 properties_.push_back(&crtc_w_property_);
185 properties_.push_back(&crtc_h_property_);
186 properties_.push_back(&src_x_property_);
187 properties_.push_back(&src_y_property_);
188 properties_.push_back(&src_w_property_);
189 properties_.push_back(&src_h_property_);
190 properties_.push_back(&zpos_property_);
191 properties_.push_back(&rotation_property_);
192 properties_.push_back(&alpha_property_);
193 properties_.push_back(&blend_property_);
194 properties_.push_back(&in_fence_fd_property_);
195 properties_.push_back(&standard_);
196 properties_.push_back(&transfer_);
197 properties_.push_back(&range_);
198 properties_.push_back(&max_luminance_);
199 properties_.push_back(&min_luminance_);
200 properties_.push_back(&hw_restrictions_);
201 properties_.push_back(&eotf_lut_);
202 properties_.push_back(&oetf_lut_);
203 properties_.push_back(&gammut_matrix_);
204 properties_.push_back(&tone_mapping_);
205 properties_.push_back(&colormap_);
206
207 return 0;
208 }
209
id() const210 uint32_t DrmPlane::id() const {
211 return id_;
212 }
213
GetCrtcSupported(const DrmCrtc & crtc) const214 bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
215 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
216 }
217
type() const218 uint32_t DrmPlane::type() const {
219 return type_;
220 }
221
crtc_property() const222 const DrmProperty &DrmPlane::crtc_property() const {
223 return crtc_property_;
224 }
225
fb_property() const226 const DrmProperty &DrmPlane::fb_property() const {
227 return fb_property_;
228 }
229
crtc_x_property() const230 const DrmProperty &DrmPlane::crtc_x_property() const {
231 return crtc_x_property_;
232 }
233
crtc_y_property() const234 const DrmProperty &DrmPlane::crtc_y_property() const {
235 return crtc_y_property_;
236 }
237
crtc_w_property() const238 const DrmProperty &DrmPlane::crtc_w_property() const {
239 return crtc_w_property_;
240 }
241
crtc_h_property() const242 const DrmProperty &DrmPlane::crtc_h_property() const {
243 return crtc_h_property_;
244 }
245
src_x_property() const246 const DrmProperty &DrmPlane::src_x_property() const {
247 return src_x_property_;
248 }
249
src_y_property() const250 const DrmProperty &DrmPlane::src_y_property() const {
251 return src_y_property_;
252 }
253
src_w_property() const254 const DrmProperty &DrmPlane::src_w_property() const {
255 return src_w_property_;
256 }
257
src_h_property() const258 const DrmProperty &DrmPlane::src_h_property() const {
259 return src_h_property_;
260 }
261
zpos_property() const262 const DrmProperty &DrmPlane::zpos_property() const {
263 return zpos_property_;
264 }
265
rotation_property() const266 const DrmProperty &DrmPlane::rotation_property() const {
267 return rotation_property_;
268 }
269
alpha_property() const270 const DrmProperty &DrmPlane::alpha_property() const {
271 return alpha_property_;
272 }
273
blend_property() const274 const DrmProperty &DrmPlane::blend_property() const {
275 return blend_property_;
276 }
277
in_fence_fd_property() const278 const DrmProperty &DrmPlane::in_fence_fd_property() const {
279 return in_fence_fd_property_;
280 }
281
standard_property() const282 const DrmProperty &DrmPlane::standard_property() const {
283 return standard_;
284 }
285
transfer_property() const286 const DrmProperty &DrmPlane::transfer_property() const {
287 return transfer_;
288 }
289
range_property() const290 const DrmProperty &DrmPlane::range_property() const {
291 return range_;
292 }
293
max_luminance_property() const294 const DrmProperty &DrmPlane::max_luminance_property() const {
295 return max_luminance_;
296 }
297
min_luminance_property() const298 const DrmProperty &DrmPlane::min_luminance_property() const {
299 return min_luminance_;
300 }
301
hw_restrictions_property() const302 const DrmProperty &DrmPlane::hw_restrictions_property() const {
303 return hw_restrictions_;
304 }
305
eotf_lut_property() const306 const DrmProperty &DrmPlane::eotf_lut_property() const {
307 return eotf_lut_;
308 }
309
oetf_lut_property() const310 const DrmProperty &DrmPlane::oetf_lut_property() const {
311 return oetf_lut_;
312 }
313
gammut_matrix_property() const314 const DrmProperty &DrmPlane::gammut_matrix_property() const {
315 return gammut_matrix_;
316 }
317
tone_mapping_property() const318 const DrmProperty &DrmPlane::tone_mapping_property() const {
319 return tone_mapping_;
320 }
321
colormap_property() const322 const DrmProperty &DrmPlane::colormap_property() const {
323 return colormap_;
324 }
325
326 } // namespace android
327