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 }
34
Init()35 int DrmPlane::Init() {
36 DrmProperty p;
37
38 int ret = drm_->GetPlaneProperty(*this, "type", &p);
39 if (ret) {
40 ALOGE("Could not get plane type property");
41 return ret;
42 }
43
44 uint64_t type;
45 std::tie(ret, type) = p.value();
46 if (ret) {
47 ALOGE("Failed to get plane type property value");
48 return ret;
49 }
50 switch (type) {
51 case DRM_PLANE_TYPE_OVERLAY:
52 case DRM_PLANE_TYPE_PRIMARY:
53 case DRM_PLANE_TYPE_CURSOR:
54 type_ = (uint32_t)type;
55 break;
56 default:
57 ALOGE("Invalid plane type %" PRIu64, type);
58 return -EINVAL;
59 }
60
61 ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_);
62 if (ret) {
63 ALOGE("Could not get CRTC_ID property");
64 return ret;
65 }
66
67 ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_);
68 if (ret) {
69 ALOGE("Could not get FB_ID property");
70 return ret;
71 }
72
73 ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_);
74 if (ret) {
75 ALOGE("Could not get CRTC_X property");
76 return ret;
77 }
78
79 ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_);
80 if (ret) {
81 ALOGE("Could not get CRTC_Y property");
82 return ret;
83 }
84
85 ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_);
86 if (ret) {
87 ALOGE("Could not get CRTC_W property");
88 return ret;
89 }
90
91 ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_);
92 if (ret) {
93 ALOGE("Could not get CRTC_H property");
94 return ret;
95 }
96
97 ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_);
98 if (ret) {
99 ALOGE("Could not get SRC_X property");
100 return ret;
101 }
102
103 ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_);
104 if (ret) {
105 ALOGE("Could not get SRC_Y property");
106 return ret;
107 }
108
109 ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_);
110 if (ret) {
111 ALOGE("Could not get SRC_W property");
112 return ret;
113 }
114
115 ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_);
116 if (ret) {
117 ALOGE("Could not get SRC_H property");
118 return ret;
119 }
120
121 ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_);
122 if (ret)
123 ALOGE("Could not get zpos property for plane %u", id());
124
125 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
126 if (ret)
127 ALOGE("Could not get rotation property");
128
129 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
130 if (ret)
131 ALOGI("Could not get alpha property");
132
133 ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
134 if (ret)
135 ALOGI("Could not get pixel blend mode property");
136
137 ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
138 if (ret)
139 ALOGI("Could not get IN_FENCE_FD property");
140
141 return 0;
142 }
143
id() const144 uint32_t DrmPlane::id() const {
145 return id_;
146 }
147
GetCrtcSupported(const DrmCrtc & crtc) const148 bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
149 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
150 }
151
type() const152 uint32_t DrmPlane::type() const {
153 return type_;
154 }
155
crtc_property() const156 const DrmProperty &DrmPlane::crtc_property() const {
157 return crtc_property_;
158 }
159
fb_property() const160 const DrmProperty &DrmPlane::fb_property() const {
161 return fb_property_;
162 }
163
crtc_x_property() const164 const DrmProperty &DrmPlane::crtc_x_property() const {
165 return crtc_x_property_;
166 }
167
crtc_y_property() const168 const DrmProperty &DrmPlane::crtc_y_property() const {
169 return crtc_y_property_;
170 }
171
crtc_w_property() const172 const DrmProperty &DrmPlane::crtc_w_property() const {
173 return crtc_w_property_;
174 }
175
crtc_h_property() const176 const DrmProperty &DrmPlane::crtc_h_property() const {
177 return crtc_h_property_;
178 }
179
src_x_property() const180 const DrmProperty &DrmPlane::src_x_property() const {
181 return src_x_property_;
182 }
183
src_y_property() const184 const DrmProperty &DrmPlane::src_y_property() const {
185 return src_y_property_;
186 }
187
src_w_property() const188 const DrmProperty &DrmPlane::src_w_property() const {
189 return src_w_property_;
190 }
191
src_h_property() const192 const DrmProperty &DrmPlane::src_h_property() const {
193 return src_h_property_;
194 }
195
zpos_property() const196 const DrmProperty &DrmPlane::zpos_property() const {
197 return zpos_property_;
198 }
199
rotation_property() const200 const DrmProperty &DrmPlane::rotation_property() const {
201 return rotation_property_;
202 }
203
alpha_property() const204 const DrmProperty &DrmPlane::alpha_property() const {
205 return alpha_property_;
206 }
207
blend_property() const208 const DrmProperty &DrmPlane::blend_property() const {
209 return blend_property_;
210 }
211
in_fence_fd_property() const212 const DrmProperty &DrmPlane::in_fence_fd_property() const {
213 return in_fence_fd_property_;
214 }
215 } // namespace android
216