blob: 1fb131667fe0c16b267f69245c243fb387b3e290 [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
Roman Stratiienko13cc3662020-08-29 21:35:39 +030019#include "DrmPlane.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040020
21#include <errno.h>
Roman Stratiienko13cc3662020-08-29 21:35:39 +030022#include <log/log.h>
Sean Paul6a55e9f2015-04-30 15:31:06 -040023#include <stdint.h>
Roman Stratiienko13cc3662020-08-29 21:35:39 +030024
Sean Paulf72cccd2018-08-27 13:59:08 -040025#include <cinttypes>
Sean Paul6a55e9f2015-04-30 15:31:06 -040026
Roman Stratiienko13cc3662020-08-29 21:35:39 +030027#include "DrmDevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040028
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;
Sean Paulfc0b1da2019-03-06 09:48:42 -050045 std::tie(ret, type) = p.value();
Sean Paul6a55e9f2015-04-30 15:31:06 -040046 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
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +0100121 ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_);
122 if (ret)
123 ALOGE("Could not get zpos property for plane %u", id());
124
Sean Paul1c4c3262015-07-14 15:51:52 -0400125 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
126 if (ret)
127 ALOGE("Could not get rotation property");
128
Sean Pauld8aefb62015-10-15 15:17:31 -0400129 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
130 if (ret)
131 ALOGI("Could not get alpha property");
132
Lowry Li9b6cafd2018-08-28 17:58:21 +0800133 ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
134 if (ret)
135 ALOGI("Could not get pixel blend mode property");
136
Robert Fossa09220c2016-09-30 10:27:23 -0400137 ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
138 if (ret)
139 ALOGI("Could not get IN_FENCE_FD property");
140
Sean Paul6a55e9f2015-04-30 15:31:06 -0400141 return 0;
142}
143
144uint32_t DrmPlane::id() const {
145 return id_;
146}
147
148bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
149 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
150}
151
152uint32_t DrmPlane::type() const {
153 return type_;
154}
155
156const DrmProperty &DrmPlane::crtc_property() const {
157 return crtc_property_;
158}
159
160const DrmProperty &DrmPlane::fb_property() const {
161 return fb_property_;
162}
163
164const DrmProperty &DrmPlane::crtc_x_property() const {
165 return crtc_x_property_;
166}
167
168const DrmProperty &DrmPlane::crtc_y_property() const {
169 return crtc_y_property_;
170}
171
172const DrmProperty &DrmPlane::crtc_w_property() const {
173 return crtc_w_property_;
174}
175
176const DrmProperty &DrmPlane::crtc_h_property() const {
177 return crtc_h_property_;
178}
179
180const DrmProperty &DrmPlane::src_x_property() const {
181 return src_x_property_;
182}
183
184const DrmProperty &DrmPlane::src_y_property() const {
185 return src_y_property_;
186}
187
188const DrmProperty &DrmPlane::src_w_property() const {
189 return src_w_property_;
190}
191
192const DrmProperty &DrmPlane::src_h_property() const {
193 return src_h_property_;
194}
Sean Paul1c4c3262015-07-14 15:51:52 -0400195
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +0100196const DrmProperty &DrmPlane::zpos_property() const {
197 return zpos_property_;
198}
199
Sean Paul1c4c3262015-07-14 15:51:52 -0400200const DrmProperty &DrmPlane::rotation_property() const {
201 return rotation_property_;
202}
Sean Pauld8aefb62015-10-15 15:17:31 -0400203
204const DrmProperty &DrmPlane::alpha_property() const {
205 return alpha_property_;
206}
Robert Fossa09220c2016-09-30 10:27:23 -0400207
Lowry Li9b6cafd2018-08-28 17:58:21 +0800208const DrmProperty &DrmPlane::blend_property() const {
209 return blend_property_;
210}
211
Robert Fossa09220c2016-09-30 10:27:23 -0400212const DrmProperty &DrmPlane::in_fence_fd_property() const {
213 return in_fence_fd_property_;
214}
Sean Paulf72cccd2018-08-27 13:59:08 -0400215} // namespace android