Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 1 | /* |
| 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 Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 19 | #include "DrmPlane.h" |
Matvii Zorin | 8338c34 | 2020-09-08 16:12:51 +0300 | [diff] [blame^] | 20 | #include "bufferinfo/BufferInfoGetter.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 21 | |
| 22 | #include <errno.h> |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 23 | #include <log/log.h> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 24 | #include <stdint.h> |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 25 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 26 | #include <cinttypes> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 27 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 28 | #include "DrmDevice.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 32 | DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p) |
Roman Kovalivskyi | 859b607 | 2020-03-26 05:03:39 +0200 | [diff] [blame] | 33 | : drm_(drm), |
| 34 | id_(p->plane_id), |
| 35 | possible_crtc_mask_(p->possible_crtcs), |
| 36 | formats_(p->formats, p->formats + p->count_formats) { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 37 | } |
| 38 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 39 | int DrmPlane::Init() { |
| 40 | DrmProperty p; |
| 41 | |
| 42 | int ret = drm_->GetPlaneProperty(*this, "type", &p); |
| 43 | if (ret) { |
| 44 | ALOGE("Could not get plane type property"); |
| 45 | return ret; |
| 46 | } |
| 47 | |
| 48 | uint64_t type; |
Sean Paul | fc0b1da | 2019-03-06 09:48:42 -0500 | [diff] [blame] | 49 | std::tie(ret, type) = p.value(); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 50 | if (ret) { |
| 51 | ALOGE("Failed to get plane type property value"); |
| 52 | return ret; |
| 53 | } |
| 54 | switch (type) { |
| 55 | case DRM_PLANE_TYPE_OVERLAY: |
| 56 | case DRM_PLANE_TYPE_PRIMARY: |
| 57 | case DRM_PLANE_TYPE_CURSOR: |
| 58 | type_ = (uint32_t)type; |
| 59 | break; |
| 60 | default: |
Sean Paul | f741c67 | 2016-05-11 13:49:38 -0400 | [diff] [blame] | 61 | ALOGE("Invalid plane type %" PRIu64, type); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 62 | return -EINVAL; |
| 63 | } |
| 64 | |
| 65 | ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_); |
| 66 | if (ret) { |
| 67 | ALOGE("Could not get CRTC_ID property"); |
| 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_); |
| 72 | if (ret) { |
| 73 | ALOGE("Could not get FB_ID property"); |
| 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_); |
| 78 | if (ret) { |
| 79 | ALOGE("Could not get CRTC_X property"); |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_); |
| 84 | if (ret) { |
| 85 | ALOGE("Could not get CRTC_Y property"); |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_); |
| 90 | if (ret) { |
| 91 | ALOGE("Could not get CRTC_W property"); |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_); |
| 96 | if (ret) { |
| 97 | ALOGE("Could not get CRTC_H property"); |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_); |
| 102 | if (ret) { |
| 103 | ALOGE("Could not get SRC_X property"); |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_); |
| 108 | if (ret) { |
| 109 | ALOGE("Could not get SRC_Y property"); |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_); |
| 114 | if (ret) { |
| 115 | ALOGE("Could not get SRC_W property"); |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_); |
| 120 | if (ret) { |
| 121 | ALOGE("Could not get SRC_H property"); |
| 122 | return ret; |
| 123 | } |
| 124 | |
Alexandru Gheorghe | ea1c5e5 | 2018-09-17 10:48:54 +0100 | [diff] [blame] | 125 | ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_); |
| 126 | if (ret) |
| 127 | ALOGE("Could not get zpos property for plane %u", id()); |
| 128 | |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 129 | ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_); |
| 130 | if (ret) |
| 131 | ALOGE("Could not get rotation property"); |
| 132 | |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 133 | ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_); |
| 134 | if (ret) |
| 135 | ALOGI("Could not get alpha property"); |
| 136 | |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 137 | ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_); |
| 138 | if (ret) |
| 139 | ALOGI("Could not get pixel blend mode property"); |
| 140 | |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 141 | ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_); |
| 142 | if (ret) |
| 143 | ALOGI("Could not get IN_FENCE_FD property"); |
| 144 | |
Matvii Zorin | 8338c34 | 2020-09-08 16:12:51 +0300 | [diff] [blame^] | 145 | if (HasNonRgbFormat()) { |
| 146 | ret = drm_->GetPlaneProperty(*this, "COLOR_ENCODING", |
| 147 | &color_encoding_propery_); |
| 148 | if (ret) |
| 149 | ALOGI("Could not get COLOR_ENCODING property"); |
| 150 | |
| 151 | ret = drm_->GetPlaneProperty(*this, "COLOR_RANGE", &color_range_property_); |
| 152 | if (ret) |
| 153 | ALOGI("Could not get COLOR_RANGE property"); |
| 154 | } |
| 155 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | uint32_t DrmPlane::id() const { |
| 160 | return id_; |
| 161 | } |
| 162 | |
| 163 | bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const { |
| 164 | return !!((1 << crtc.pipe()) & possible_crtc_mask_); |
| 165 | } |
| 166 | |
| 167 | uint32_t DrmPlane::type() const { |
| 168 | return type_; |
| 169 | } |
| 170 | |
Roman Kovalivskyi | 859b607 | 2020-03-26 05:03:39 +0200 | [diff] [blame] | 171 | bool DrmPlane::IsFormatSupported(uint32_t format) const { |
| 172 | return std::find(std::begin(formats_), std::end(formats_), format) != |
| 173 | std::end(formats_); |
| 174 | } |
| 175 | |
Matvii Zorin | 8338c34 | 2020-09-08 16:12:51 +0300 | [diff] [blame^] | 176 | bool DrmPlane::HasNonRgbFormat() const { |
| 177 | return std::find_if_not(std::begin(formats_), std::end(formats_), |
| 178 | [](uint32_t format) { |
| 179 | return BufferInfoGetter::IsDrmFormatRgb(format); |
| 180 | }) != std::end(formats_); |
| 181 | } |
| 182 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 183 | const DrmProperty &DrmPlane::crtc_property() const { |
| 184 | return crtc_property_; |
| 185 | } |
| 186 | |
| 187 | const DrmProperty &DrmPlane::fb_property() const { |
| 188 | return fb_property_; |
| 189 | } |
| 190 | |
| 191 | const DrmProperty &DrmPlane::crtc_x_property() const { |
| 192 | return crtc_x_property_; |
| 193 | } |
| 194 | |
| 195 | const DrmProperty &DrmPlane::crtc_y_property() const { |
| 196 | return crtc_y_property_; |
| 197 | } |
| 198 | |
| 199 | const DrmProperty &DrmPlane::crtc_w_property() const { |
| 200 | return crtc_w_property_; |
| 201 | } |
| 202 | |
| 203 | const DrmProperty &DrmPlane::crtc_h_property() const { |
| 204 | return crtc_h_property_; |
| 205 | } |
| 206 | |
| 207 | const DrmProperty &DrmPlane::src_x_property() const { |
| 208 | return src_x_property_; |
| 209 | } |
| 210 | |
| 211 | const DrmProperty &DrmPlane::src_y_property() const { |
| 212 | return src_y_property_; |
| 213 | } |
| 214 | |
| 215 | const DrmProperty &DrmPlane::src_w_property() const { |
| 216 | return src_w_property_; |
| 217 | } |
| 218 | |
| 219 | const DrmProperty &DrmPlane::src_h_property() const { |
| 220 | return src_h_property_; |
| 221 | } |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 222 | |
Alexandru Gheorghe | ea1c5e5 | 2018-09-17 10:48:54 +0100 | [diff] [blame] | 223 | const DrmProperty &DrmPlane::zpos_property() const { |
| 224 | return zpos_property_; |
| 225 | } |
| 226 | |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 227 | const DrmProperty &DrmPlane::rotation_property() const { |
| 228 | return rotation_property_; |
| 229 | } |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 230 | |
| 231 | const DrmProperty &DrmPlane::alpha_property() const { |
| 232 | return alpha_property_; |
| 233 | } |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 234 | |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 235 | const DrmProperty &DrmPlane::blend_property() const { |
| 236 | return blend_property_; |
| 237 | } |
| 238 | |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 239 | const DrmProperty &DrmPlane::in_fence_fd_property() const { |
| 240 | return in_fence_fd_property_; |
| 241 | } |
Matvii Zorin | 8338c34 | 2020-09-08 16:12:51 +0300 | [diff] [blame^] | 242 | |
| 243 | const DrmProperty &DrmPlane::color_encoding_propery() const { |
| 244 | return color_encoding_propery_; |
| 245 | } |
| 246 | |
| 247 | const DrmProperty &DrmPlane::color_range_property() const { |
| 248 | return color_range_property_; |
| 249 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 250 | } // namespace android |