blob: 051d59171a5f20eca97a38c37c601df066f946af [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
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010019#include "drmdevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040020#include "drmplane.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040021
Sean Paulf741c672016-05-11 13:49:38 -040022#include <cinttypes>
Sean Paul6a55e9f2015-04-30 15:31:06 -040023#include <errno.h>
24#include <stdint.h>
25
John Stultz9057a6f2018-04-26 12:05:55 -070026#include <log/log.h>
Sean Paul6a55e9f2015-04-30 15:31:06 -040027#include <xf86drmMode.h>
28
29namespace android {
30
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010031DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p)
Sean Paul6a55e9f2015-04-30 15:31:06 -040032 : drm_(drm), id_(p->plane_id), possible_crtc_mask_(p->possible_crtcs) {
33}
34
Sean Paul6a55e9f2015-04-30 15:31:06 -040035int 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:
Sean Paulf741c672016-05-11 13:49:38 -040057 ALOGE("Invalid plane type %" PRIu64, type);
Sean Paul6a55e9f2015-04-30 15:31:06 -040058 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
Sean Paul1c4c3262015-07-14 15:51:52 -0400121 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
122 if (ret)
123 ALOGE("Could not get rotation property");
124
Sean Pauld8aefb62015-10-15 15:17:31 -0400125 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
126 if (ret)
127 ALOGI("Could not get alpha property");
128
Robert Fossa09220c2016-09-30 10:27:23 -0400129 ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
130 if (ret)
131 ALOGI("Could not get IN_FENCE_FD property");
132
Sean Paul6a55e9f2015-04-30 15:31:06 -0400133 return 0;
134}
135
136uint32_t DrmPlane::id() const {
137 return id_;
138}
139
140bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
141 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
142}
143
144uint32_t DrmPlane::type() const {
145 return type_;
146}
147
148const DrmProperty &DrmPlane::crtc_property() const {
149 return crtc_property_;
150}
151
152const DrmProperty &DrmPlane::fb_property() const {
153 return fb_property_;
154}
155
156const DrmProperty &DrmPlane::crtc_x_property() const {
157 return crtc_x_property_;
158}
159
160const DrmProperty &DrmPlane::crtc_y_property() const {
161 return crtc_y_property_;
162}
163
164const DrmProperty &DrmPlane::crtc_w_property() const {
165 return crtc_w_property_;
166}
167
168const DrmProperty &DrmPlane::crtc_h_property() const {
169 return crtc_h_property_;
170}
171
172const DrmProperty &DrmPlane::src_x_property() const {
173 return src_x_property_;
174}
175
176const DrmProperty &DrmPlane::src_y_property() const {
177 return src_y_property_;
178}
179
180const DrmProperty &DrmPlane::src_w_property() const {
181 return src_w_property_;
182}
183
184const DrmProperty &DrmPlane::src_h_property() const {
185 return src_h_property_;
186}
Sean Paul1c4c3262015-07-14 15:51:52 -0400187
188const DrmProperty &DrmPlane::rotation_property() const {
189 return rotation_property_;
190}
Sean Pauld8aefb62015-10-15 15:17:31 -0400191
192const DrmProperty &DrmPlane::alpha_property() const {
193 return alpha_property_;
194}
Robert Fossa09220c2016-09-30 10:27:23 -0400195
196const DrmProperty &DrmPlane::in_fence_fd_property() const {
197 return in_fence_fd_property_;
198}
Sean Paul6a55e9f2015-04-30 15:31:06 -0400199}