blob: 5785d5a4432784332b266493ad1a27e72992a421 [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
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
28namespace android {
29
30DrmPlane::DrmPlane(DrmResources *drm, drmModePlanePtr p)
31 : drm_(drm), id_(p->plane_id), possible_crtc_mask_(p->possible_crtcs) {
32}
33
34DrmPlane::~DrmPlane() {
35}
36
37int 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
Sean Paul1c4c3262015-07-14 15:51:52 -0400123 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
124 if (ret)
125 ALOGE("Could not get rotation property");
126
Sean Pauld8aefb62015-10-15 15:17:31 -0400127 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
128 if (ret)
129 ALOGI("Could not get alpha property");
130
Sean Paul6a55e9f2015-04-30 15:31:06 -0400131 return 0;
132}
133
134uint32_t DrmPlane::id() const {
135 return id_;
136}
137
138bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
139 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
140}
141
142uint32_t DrmPlane::type() const {
143 return type_;
144}
145
146const DrmProperty &DrmPlane::crtc_property() const {
147 return crtc_property_;
148}
149
150const DrmProperty &DrmPlane::fb_property() const {
151 return fb_property_;
152}
153
154const DrmProperty &DrmPlane::crtc_x_property() const {
155 return crtc_x_property_;
156}
157
158const DrmProperty &DrmPlane::crtc_y_property() const {
159 return crtc_y_property_;
160}
161
162const DrmProperty &DrmPlane::crtc_w_property() const {
163 return crtc_w_property_;
164}
165
166const DrmProperty &DrmPlane::crtc_h_property() const {
167 return crtc_h_property_;
168}
169
170const DrmProperty &DrmPlane::src_x_property() const {
171 return src_x_property_;
172}
173
174const DrmProperty &DrmPlane::src_y_property() const {
175 return src_y_property_;
176}
177
178const DrmProperty &DrmPlane::src_w_property() const {
179 return src_w_property_;
180}
181
182const DrmProperty &DrmPlane::src_h_property() const {
183 return src_h_property_;
184}
Sean Paul1c4c3262015-07-14 15:51:52 -0400185
186const DrmProperty &DrmPlane::rotation_property() const {
187 return rotation_property_;
188}
Sean Pauld8aefb62015-10-15 15:17:31 -0400189
190const DrmProperty &DrmPlane::alpha_property() const {
191 return alpha_property_;
192}
Sean Paul6a55e9f2015-04-30 15:31:06 -0400193}