blob: f0c7559db3dceca59e3e3af018de3c156fdaab4b [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"
Sean Paulf72cccd2018-08-27 13:59:08 -040020#include "drmdevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040021
22#include <errno.h>
23#include <stdint.h>
Sean Paulf72cccd2018-08-27 13:59:08 -040024#include <cinttypes>
Sean Paul6a55e9f2015-04-30 15:31:06 -040025
John Stultz9057a6f2018-04-26 12:05:55 -070026#include <log/log.h>
Sean Paul6a55e9f2015-04-30 15:31:06 -040027
28namespace android {
29
Alexandru Gheorghe0f5abd72018-05-01 14:37:10 +010030DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p)
Sean Paul6a55e9f2015-04-30 15:31:06 -040031 : drm_(drm), id_(p->plane_id), possible_crtc_mask_(p->possible_crtcs) {
32}
33
Sean Paul6a55e9f2015-04-30 15:31:06 -040034int DrmPlane::Init() {
35 DrmProperty p;
36
37 int ret = drm_->GetPlaneProperty(*this, "type", &p);
38 if (ret) {
39 ALOGE("Could not get plane type property");
40 return ret;
41 }
42
43 uint64_t type;
Sean Paulfc0b1da2019-03-06 09:48:42 -050044 std::tie(ret, type) = p.value();
Sean Paul6a55e9f2015-04-30 15:31:06 -040045 if (ret) {
46 ALOGE("Failed to get plane type property value");
47 return ret;
48 }
49 switch (type) {
50 case DRM_PLANE_TYPE_OVERLAY:
51 case DRM_PLANE_TYPE_PRIMARY:
52 case DRM_PLANE_TYPE_CURSOR:
53 type_ = (uint32_t)type;
54 break;
55 default:
Sean Paulf741c672016-05-11 13:49:38 -040056 ALOGE("Invalid plane type %" PRIu64, type);
Sean Paul6a55e9f2015-04-30 15:31:06 -040057 return -EINVAL;
58 }
59
60 ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_);
61 if (ret) {
62 ALOGE("Could not get CRTC_ID property");
63 return ret;
64 }
65
66 ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_);
67 if (ret) {
68 ALOGE("Could not get FB_ID property");
69 return ret;
70 }
71
72 ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_);
73 if (ret) {
74 ALOGE("Could not get CRTC_X property");
75 return ret;
76 }
77
78 ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_);
79 if (ret) {
80 ALOGE("Could not get CRTC_Y property");
81 return ret;
82 }
83
84 ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_);
85 if (ret) {
86 ALOGE("Could not get CRTC_W property");
87 return ret;
88 }
89
90 ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_);
91 if (ret) {
92 ALOGE("Could not get CRTC_H property");
93 return ret;
94 }
95
96 ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_);
97 if (ret) {
98 ALOGE("Could not get SRC_X property");
99 return ret;
100 }
101
102 ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_);
103 if (ret) {
104 ALOGE("Could not get SRC_Y property");
105 return ret;
106 }
107
108 ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_);
109 if (ret) {
110 ALOGE("Could not get SRC_W property");
111 return ret;
112 }
113
114 ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_);
115 if (ret) {
116 ALOGE("Could not get SRC_H property");
117 return ret;
118 }
119
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +0100120 ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_);
121 if (ret)
122 ALOGE("Could not get zpos property for plane %u", id());
123
Sean Paul1c4c3262015-07-14 15:51:52 -0400124 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
125 if (ret)
126 ALOGE("Could not get rotation property");
127
Sean Pauld8aefb62015-10-15 15:17:31 -0400128 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
129 if (ret)
130 ALOGI("Could not get alpha property");
131
Lowry Li9b6cafd2018-08-28 17:58:21 +0800132 ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
133 if (ret)
134 ALOGI("Could not get pixel blend mode property");
135
Robert Fossa09220c2016-09-30 10:27:23 -0400136 ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
137 if (ret)
138 ALOGI("Could not get IN_FENCE_FD property");
139
Sean Paul6a55e9f2015-04-30 15:31:06 -0400140 return 0;
141}
142
143uint32_t DrmPlane::id() const {
144 return id_;
145}
146
147bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
148 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
149}
150
151uint32_t DrmPlane::type() const {
152 return type_;
153}
154
155const DrmProperty &DrmPlane::crtc_property() const {
156 return crtc_property_;
157}
158
159const DrmProperty &DrmPlane::fb_property() const {
160 return fb_property_;
161}
162
163const DrmProperty &DrmPlane::crtc_x_property() const {
164 return crtc_x_property_;
165}
166
167const DrmProperty &DrmPlane::crtc_y_property() const {
168 return crtc_y_property_;
169}
170
171const DrmProperty &DrmPlane::crtc_w_property() const {
172 return crtc_w_property_;
173}
174
175const DrmProperty &DrmPlane::crtc_h_property() const {
176 return crtc_h_property_;
177}
178
179const DrmProperty &DrmPlane::src_x_property() const {
180 return src_x_property_;
181}
182
183const DrmProperty &DrmPlane::src_y_property() const {
184 return src_y_property_;
185}
186
187const DrmProperty &DrmPlane::src_w_property() const {
188 return src_w_property_;
189}
190
191const DrmProperty &DrmPlane::src_h_property() const {
192 return src_h_property_;
193}
Sean Paul1c4c3262015-07-14 15:51:52 -0400194
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +0100195const DrmProperty &DrmPlane::zpos_property() const {
196 return zpos_property_;
197}
198
Sean Paul1c4c3262015-07-14 15:51:52 -0400199const DrmProperty &DrmPlane::rotation_property() const {
200 return rotation_property_;
201}
Sean Pauld8aefb62015-10-15 15:17:31 -0400202
203const DrmProperty &DrmPlane::alpha_property() const {
204 return alpha_property_;
205}
Robert Fossa09220c2016-09-30 10:27:23 -0400206
Lowry Li9b6cafd2018-08-28 17:58:21 +0800207const DrmProperty &DrmPlane::blend_property() const {
208 return blend_property_;
209}
210
Robert Fossa09220c2016-09-30 10:27:23 -0400211const DrmProperty &DrmPlane::in_fence_fd_property() const {
212 return in_fence_fd_property_;
213}
Sean Paulf72cccd2018-08-27 13:59:08 -0400214} // namespace android