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 
25 #include <cinttypes>
26 
27 #include "DrmDevice.h"
28 
29 namespace android {
30 
DrmPlane(DrmDevice * drm,drmModePlanePtr p)31 DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p)
32     : drm_(drm),
33       id_(p->plane_id),
34       possible_crtc_mask_(p->possible_crtcs),
35       formats_(p->formats, p->formats + p->count_formats) {
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   return 0;
145 }
146 
id() const147 uint32_t DrmPlane::id() const {
148   return id_;
149 }
150 
GetCrtcSupported(const DrmCrtc & crtc) const151 bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
152   return !!((1 << crtc.pipe()) & possible_crtc_mask_);
153 }
154 
type() const155 uint32_t DrmPlane::type() const {
156   return type_;
157 }
158 
IsFormatSupported(uint32_t format) const159 bool DrmPlane::IsFormatSupported(uint32_t format) const {
160   return std::find(std::begin(formats_), std::end(formats_), format) !=
161          std::end(formats_);
162 }
163 
crtc_property() const164 const DrmProperty &DrmPlane::crtc_property() const {
165   return crtc_property_;
166 }
167 
fb_property() const168 const DrmProperty &DrmPlane::fb_property() const {
169   return fb_property_;
170 }
171 
crtc_x_property() const172 const DrmProperty &DrmPlane::crtc_x_property() const {
173   return crtc_x_property_;
174 }
175 
crtc_y_property() const176 const DrmProperty &DrmPlane::crtc_y_property() const {
177   return crtc_y_property_;
178 }
179 
crtc_w_property() const180 const DrmProperty &DrmPlane::crtc_w_property() const {
181   return crtc_w_property_;
182 }
183 
crtc_h_property() const184 const DrmProperty &DrmPlane::crtc_h_property() const {
185   return crtc_h_property_;
186 }
187 
src_x_property() const188 const DrmProperty &DrmPlane::src_x_property() const {
189   return src_x_property_;
190 }
191 
src_y_property() const192 const DrmProperty &DrmPlane::src_y_property() const {
193   return src_y_property_;
194 }
195 
src_w_property() const196 const DrmProperty &DrmPlane::src_w_property() const {
197   return src_w_property_;
198 }
199 
src_h_property() const200 const DrmProperty &DrmPlane::src_h_property() const {
201   return src_h_property_;
202 }
203 
zpos_property() const204 const DrmProperty &DrmPlane::zpos_property() const {
205   return zpos_property_;
206 }
207 
rotation_property() const208 const DrmProperty &DrmPlane::rotation_property() const {
209   return rotation_property_;
210 }
211 
alpha_property() const212 const DrmProperty &DrmPlane::alpha_property() const {
213   return alpha_property_;
214 }
215 
blend_property() const216 const DrmProperty &DrmPlane::blend_property() const {
217   return blend_property_;
218 }
219 
in_fence_fd_property() const220 const DrmProperty &DrmPlane::in_fence_fd_property() const {
221   return in_fence_fd_property_;
222 }
223 }  // namespace android
224