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 <errno.h>
23 #include <stdint.h>
24
25 #include <cutils/log.h>
26 #include <xf86drmMode.h>
27
28 namespace android {
29
DrmPlane(DrmResources * drm,drmModePlanePtr p)30 DrmPlane::DrmPlane(DrmResources *drm, drmModePlanePtr p)
31 : drm_(drm), id_(p->plane_id), possible_crtc_mask_(p->possible_crtcs) {
32 }
33
~DrmPlane()34 DrmPlane::~DrmPlane() {
35 }
36
Init()37 int DrmPlane::Init() {
38 DrmProperty p;
39
40 int ret = drm_->GetPlaneProperty(*this, "type", &p);
41 if (ret) {
42 ALOGE("Could not get plane type property");
43 return ret;
44 }
45
46 uint64_t type;
47 ret = p.value(&type);
48 if (ret) {
49 ALOGE("Failed to get plane type property value");
50 return ret;
51 }
52 switch (type) {
53 case DRM_PLANE_TYPE_OVERLAY:
54 case DRM_PLANE_TYPE_PRIMARY:
55 case DRM_PLANE_TYPE_CURSOR:
56 type_ = (uint32_t)type;
57 break;
58 default:
59 ALOGE("Invalid plane type %d", type);
60 return -EINVAL;
61 }
62
63 ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_);
64 if (ret) {
65 ALOGE("Could not get CRTC_ID property");
66 return ret;
67 }
68
69 ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_);
70 if (ret) {
71 ALOGE("Could not get FB_ID property");
72 return ret;
73 }
74
75 ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_);
76 if (ret) {
77 ALOGE("Could not get CRTC_X property");
78 return ret;
79 }
80
81 ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_);
82 if (ret) {
83 ALOGE("Could not get CRTC_Y property");
84 return ret;
85 }
86
87 ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_);
88 if (ret) {
89 ALOGE("Could not get CRTC_W property");
90 return ret;
91 }
92
93 ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_);
94 if (ret) {
95 ALOGE("Could not get CRTC_H property");
96 return ret;
97 }
98
99 ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_);
100 if (ret) {
101 ALOGE("Could not get SRC_X property");
102 return ret;
103 }
104
105 ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_);
106 if (ret) {
107 ALOGE("Could not get SRC_Y property");
108 return ret;
109 }
110
111 ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_);
112 if (ret) {
113 ALOGE("Could not get SRC_W property");
114 return ret;
115 }
116
117 ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_);
118 if (ret) {
119 ALOGE("Could not get SRC_H property");
120 return ret;
121 }
122
123 return 0;
124 }
125
id() const126 uint32_t DrmPlane::id() const {
127 return id_;
128 }
129
GetCrtcSupported(const DrmCrtc & crtc) const130 bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
131 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
132 }
133
type() const134 uint32_t DrmPlane::type() const {
135 return type_;
136 }
137
crtc_property() const138 const DrmProperty &DrmPlane::crtc_property() const {
139 return crtc_property_;
140 }
141
fb_property() const142 const DrmProperty &DrmPlane::fb_property() const {
143 return fb_property_;
144 }
145
crtc_x_property() const146 const DrmProperty &DrmPlane::crtc_x_property() const {
147 return crtc_x_property_;
148 }
149
crtc_y_property() const150 const DrmProperty &DrmPlane::crtc_y_property() const {
151 return crtc_y_property_;
152 }
153
crtc_w_property() const154 const DrmProperty &DrmPlane::crtc_w_property() const {
155 return crtc_w_property_;
156 }
157
crtc_h_property() const158 const DrmProperty &DrmPlane::crtc_h_property() const {
159 return crtc_h_property_;
160 }
161
src_x_property() const162 const DrmProperty &DrmPlane::src_x_property() const {
163 return src_x_property_;
164 }
165
src_y_property() const166 const DrmProperty &DrmPlane::src_y_property() const {
167 return src_y_property_;
168 }
169
src_w_property() const170 const DrmProperty &DrmPlane::src_w_property() const {
171 return src_w_property_;
172 }
173
src_h_property() const174 const DrmProperty &DrmPlane::src_h_property() const {
175 return src_h_property_;
176 }
177 }
178