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