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> |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 22 | #include <log/log.h> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 23 | #include <stdint.h> |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 24 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 25 | #include <cinttypes> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 26 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 27 | #include "DrmDevice.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 31 | DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p) |
Roman Kovalivskyi | 859b607 | 2020-03-26 05:03:39 +0200 | [diff] [blame^] | 32 | : drm_(drm), |
| 33 | id_(p->plane_id), |
| 34 | possible_crtc_mask_(p->possible_crtcs), |
| 35 | formats_(p->formats, p->formats + p->count_formats) { |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 36 | } |
| 37 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 38 | int 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 Paul | fc0b1da | 2019-03-06 09:48:42 -0500 | [diff] [blame] | 48 | std::tie(ret, type) = p.value(); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 49 | 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 Paul | f741c67 | 2016-05-11 13:49:38 -0400 | [diff] [blame] | 60 | ALOGE("Invalid plane type %" PRIu64, type); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 61 | 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 Gheorghe | ea1c5e5 | 2018-09-17 10:48:54 +0100 | [diff] [blame] | 124 | ret = drm_->GetPlaneProperty(*this, "zpos", &zpos_property_); |
| 125 | if (ret) |
| 126 | ALOGE("Could not get zpos property for plane %u", id()); |
| 127 | |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 128 | ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_); |
| 129 | if (ret) |
| 130 | ALOGE("Could not get rotation property"); |
| 131 | |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 132 | ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_); |
| 133 | if (ret) |
| 134 | ALOGI("Could not get alpha property"); |
| 135 | |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 136 | ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_); |
| 137 | if (ret) |
| 138 | ALOGI("Could not get pixel blend mode property"); |
| 139 | |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 140 | 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 Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | uint32_t DrmPlane::id() const { |
| 148 | return id_; |
| 149 | } |
| 150 | |
| 151 | bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const { |
| 152 | return !!((1 << crtc.pipe()) & possible_crtc_mask_); |
| 153 | } |
| 154 | |
| 155 | uint32_t DrmPlane::type() const { |
| 156 | return type_; |
| 157 | } |
| 158 | |
Roman Kovalivskyi | 859b607 | 2020-03-26 05:03:39 +0200 | [diff] [blame^] | 159 | bool DrmPlane::IsFormatSupported(uint32_t format) const { |
| 160 | return std::find(std::begin(formats_), std::end(formats_), format) != |
| 161 | std::end(formats_); |
| 162 | } |
| 163 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 164 | const DrmProperty &DrmPlane::crtc_property() const { |
| 165 | return crtc_property_; |
| 166 | } |
| 167 | |
| 168 | const DrmProperty &DrmPlane::fb_property() const { |
| 169 | return fb_property_; |
| 170 | } |
| 171 | |
| 172 | const DrmProperty &DrmPlane::crtc_x_property() const { |
| 173 | return crtc_x_property_; |
| 174 | } |
| 175 | |
| 176 | const DrmProperty &DrmPlane::crtc_y_property() const { |
| 177 | return crtc_y_property_; |
| 178 | } |
| 179 | |
| 180 | const DrmProperty &DrmPlane::crtc_w_property() const { |
| 181 | return crtc_w_property_; |
| 182 | } |
| 183 | |
| 184 | const DrmProperty &DrmPlane::crtc_h_property() const { |
| 185 | return crtc_h_property_; |
| 186 | } |
| 187 | |
| 188 | const DrmProperty &DrmPlane::src_x_property() const { |
| 189 | return src_x_property_; |
| 190 | } |
| 191 | |
| 192 | const DrmProperty &DrmPlane::src_y_property() const { |
| 193 | return src_y_property_; |
| 194 | } |
| 195 | |
| 196 | const DrmProperty &DrmPlane::src_w_property() const { |
| 197 | return src_w_property_; |
| 198 | } |
| 199 | |
| 200 | const DrmProperty &DrmPlane::src_h_property() const { |
| 201 | return src_h_property_; |
| 202 | } |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 203 | |
Alexandru Gheorghe | ea1c5e5 | 2018-09-17 10:48:54 +0100 | [diff] [blame] | 204 | const DrmProperty &DrmPlane::zpos_property() const { |
| 205 | return zpos_property_; |
| 206 | } |
| 207 | |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 208 | const DrmProperty &DrmPlane::rotation_property() const { |
| 209 | return rotation_property_; |
| 210 | } |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 211 | |
| 212 | const DrmProperty &DrmPlane::alpha_property() const { |
| 213 | return alpha_property_; |
| 214 | } |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 215 | |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame] | 216 | const DrmProperty &DrmPlane::blend_property() const { |
| 217 | return blend_property_; |
| 218 | } |
| 219 | |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 220 | const DrmProperty &DrmPlane::in_fence_fd_property() const { |
| 221 | return in_fence_fd_property_; |
| 222 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 223 | } // namespace android |