blob: f9942525e04679dba113d3df759b3d40a75e823f [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)
Roman Kovalivskyi859b6072020-03-26 05:03:39 +020032 : drm_(drm),
33 id_(p->plane_id),
34 possible_crtc_mask_(p->possible_crtcs),
35 formats_(p->formats, p->formats + p->count_formats) {
Sean Paul6a55e9f2015-04-30 15:31:06 -040036}
37
Sean Paul6a55e9f2015-04-30 15:31:06 -040038int DrmPlane::Init() {
39 DrmProperty p;
40
41 int ret = drm_->GetPlaneProperty(*this, "type", &p);
42 if (ret) {
43 ALOGE("Could not get plane type property");
44 return ret;
45 }
46
47 uint64_t type;
Sean Paulfc0b1da2019-03-06 09:48:42 -050048 std::tie(ret, type) = p.value();
Sean Paul6a55e9f2015-04-30 15:31:06 -040049 if (ret) {
50 ALOGE("Failed to get plane type property value");
51 return ret;
52 }
53 switch (type) {
54 case DRM_PLANE_TYPE_OVERLAY:
55 case DRM_PLANE_TYPE_PRIMARY:
56 case DRM_PLANE_TYPE_CURSOR:
57 type_ = (uint32_t)type;
58 break;
59 default:
Sean Paulf741c672016-05-11 13:49:38 -040060 ALOGE("Invalid plane type %" PRIu64, type);
Sean Paul6a55e9f2015-04-30 15:31:06 -040061 return -EINVAL;
62 }
63
64 ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_);
65 if (ret) {
66 ALOGE("Could not get CRTC_ID property");
67 return ret;
68 }
69
70 ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_);
71 if (ret) {
72 ALOGE("Could not get FB_ID property");
73 return ret;
74 }
75
76 ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_);
77 if (ret) {
78 ALOGE("Could not get CRTC_X property");
79 return ret;
80 }
81
82 ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_);
83 if (ret) {
84 ALOGE("Could not get CRTC_Y property");
85 return ret;
86 }
87
88 ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_);
89 if (ret) {
90 ALOGE("Could not get CRTC_W property");
91 return ret;
92 }
93
94 ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_);
95 if (ret) {
96 ALOGE("Could not get CRTC_H property");
97 return ret;
98 }
99
100 ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_);
101 if (ret) {
102 ALOGE("Could not get SRC_X property");
103 return ret;
104 }
105
106 ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_);
107 if (ret) {
108 ALOGE("Could not get SRC_Y property");
109 return ret;
110 }
111
112 ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_);
113 if (ret) {
114 ALOGE("Could not get SRC_W property");
115 return ret;
116 }
117
118 ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_);
119 if (ret) {
120 ALOGE("Could not get SRC_H property");
121 return ret;
122 }
123
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +0100124 ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_);
125 if (ret)
126 ALOGE("Could not get zpos property for plane %u", id());
127
Sean Paul1c4c3262015-07-14 15:51:52 -0400128 ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_);
129 if (ret)
130 ALOGE("Could not get rotation property");
131
Sean Pauld8aefb62015-10-15 15:17:31 -0400132 ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_);
133 if (ret)
134 ALOGI("Could not get alpha property");
135
Lowry Li9b6cafd2018-08-28 17:58:21 +0800136 ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_);
137 if (ret)
138 ALOGI("Could not get pixel blend mode property");
139
Robert Fossa09220c2016-09-30 10:27:23 -0400140 ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_);
141 if (ret)
142 ALOGI("Could not get IN_FENCE_FD property");
143
Sean Paul6a55e9f2015-04-30 15:31:06 -0400144 return 0;
145}
146
147uint32_t DrmPlane::id() const {
148 return id_;
149}
150
151bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
152 return !!((1 << crtc.pipe()) & possible_crtc_mask_);
153}
154
155uint32_t DrmPlane::type() const {
156 return type_;
157}
158
Roman Kovalivskyi859b6072020-03-26 05:03:39 +0200159bool DrmPlane::IsFormatSupported(uint32_t format) const {
160 return std::find(std::begin(formats_), std::end(formats_), format) !=
161 std::end(formats_);
162}
163
Sean Paul6a55e9f2015-04-30 15:31:06 -0400164const DrmProperty &DrmPlane::crtc_property() const {
165 return crtc_property_;
166}
167
168const DrmProperty &DrmPlane::fb_property() const {
169 return fb_property_;
170}
171
172const DrmProperty &DrmPlane::crtc_x_property() const {
173 return crtc_x_property_;
174}
175
176const DrmProperty &DrmPlane::crtc_y_property() const {
177 return crtc_y_property_;
178}
179
180const DrmProperty &DrmPlane::crtc_w_property() const {
181 return crtc_w_property_;
182}
183
184const DrmProperty &DrmPlane::crtc_h_property() const {
185 return crtc_h_property_;
186}
187
188const DrmProperty &DrmPlane::src_x_property() const {
189 return src_x_property_;
190}
191
192const DrmProperty &DrmPlane::src_y_property() const {
193 return src_y_property_;
194}
195
196const DrmProperty &DrmPlane::src_w_property() const {
197 return src_w_property_;
198}
199
200const DrmProperty &DrmPlane::src_h_property() const {
201 return src_h_property_;
202}
Sean Paul1c4c3262015-07-14 15:51:52 -0400203
Alexandru Gheorgheea1c5e52018-09-17 10:48:54 +0100204const DrmProperty &DrmPlane::zpos_property() const {
205 return zpos_property_;
206}
207
Sean Paul1c4c3262015-07-14 15:51:52 -0400208const DrmProperty &DrmPlane::rotation_property() const {
209 return rotation_property_;
210}
Sean Pauld8aefb62015-10-15 15:17:31 -0400211
212const DrmProperty &DrmPlane::alpha_property() const {
213 return alpha_property_;
214}
Robert Fossa09220c2016-09-30 10:27:23 -0400215
Lowry Li9b6cafd2018-08-28 17:58:21 +0800216const DrmProperty &DrmPlane::blend_property() const {
217 return blend_property_;
218}
219
Robert Fossa09220c2016-09-30 10:27:23 -0400220const DrmProperty &DrmPlane::in_fence_fd_property() const {
221 return in_fence_fd_property_;
222}
Sean Paulf72cccd2018-08-27 13:59:08 -0400223} // namespace android