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 "drmresources.h"
21
22 #include <cinttypes>
23 #include <errno.h>
24 #include <stdint.h>
25
26 #include <cutils/log.h>
27 #include <xf86drmMode.h>
28
29 namespace android {
30
DrmPlane(DrmResources * drm,drmModePlanePtr p)31 DrmPlane::DrmPlane(DrmResources *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 ret = p.value(&type);
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, "rotation", &rotation_property_);
122 if (ret)
123 ALOGE("Could not get rotation property");
124
125 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
126 if (ret)
127 ALOGI("Could not get alpha property");
128
129 return 0;
130 }
131
id() const132 uint32_t DrmPlane::id() const {
133 return id_;
134 }
135
GetCrtcSupported(const DrmCrtc & crtc) const136 bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
137 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
138 }
139
type() const140 uint32_t DrmPlane::type() const {
141 return type_;
142 }
143
crtc_property() const144 const DrmProperty &DrmPlane::crtc_property() const {
145 return crtc_property_;
146 }
147
fb_property() const148 const DrmProperty &DrmPlane::fb_property() const {
149 return fb_property_;
150 }
151
crtc_x_property() const152 const DrmProperty &DrmPlane::crtc_x_property() const {
153 return crtc_x_property_;
154 }
155
crtc_y_property() const156 const DrmProperty &DrmPlane::crtc_y_property() const {
157 return crtc_y_property_;
158 }
159
crtc_w_property() const160 const DrmProperty &DrmPlane::crtc_w_property() const {
161 return crtc_w_property_;
162 }
163
crtc_h_property() const164 const DrmProperty &DrmPlane::crtc_h_property() const {
165 return crtc_h_property_;
166 }
167
src_x_property() const168 const DrmProperty &DrmPlane::src_x_property() const {
169 return src_x_property_;
170 }
171
src_y_property() const172 const DrmProperty &DrmPlane::src_y_property() const {
173 return src_y_property_;
174 }
175
src_w_property() const176 const DrmProperty &DrmPlane::src_w_property() const {
177 return src_w_property_;
178 }
179
src_h_property() const180 const DrmProperty &DrmPlane::src_h_property() const {
181 return src_h_property_;
182 }
183
rotation_property() const184 const DrmProperty &DrmPlane::rotation_property() const {
185 return rotation_property_;
186 }
187
alpha_property() const188 const DrmProperty &DrmPlane::alpha_property() const {
189 return alpha_property_;
190 }
191 }
192