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 | |
| 19 | #include "drmplane.h" |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 20 | #include "drmdevice.h" |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 21 | |
| 22 | #include <errno.h> |
| 23 | #include <stdint.h> |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 24 | #include <cinttypes> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 25 | |
John Stultz | 9057a6f | 2018-04-26 12:05:55 -0700 | [diff] [blame] | 26 | #include <log/log.h> |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 27 | #include <xf86drmMode.h> |
| 28 | |
| 29 | namespace android { |
| 30 | |
Alexandru Gheorghe | 0f5abd7 | 2018-05-01 14:37:10 +0100 | [diff] [blame] | 31 | DrmPlane::DrmPlane(DrmDevice *drm, drmModePlanePtr p) |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 32 | : drm_(drm), id_(p->plane_id), possible_crtc_mask_(p->possible_crtcs) { |
| 33 | } |
| 34 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 35 | int 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; |
| 45 | ret = p.value(&type); |
| 46 | 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 Paul | f741c67 | 2016-05-11 13:49:38 -0400 | [diff] [blame] | 57 | ALOGE("Invalid plane type %" PRIu64, type); |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 58 | 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 | |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 121 | ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_); |
| 122 | if (ret) |
| 123 | ALOGE("Could not get rotation property"); |
| 124 | |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 125 | ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_); |
| 126 | if (ret) |
| 127 | ALOGI("Could not get alpha property"); |
| 128 | |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame^] | 129 | ret = drm_->GetPlaneProperty(*this, "pixel blend mode", &blend_property_); |
| 130 | if (ret) |
| 131 | ALOGI("Could not get pixel blend mode property"); |
| 132 | |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 133 | ret = drm_->GetPlaneProperty(*this, "IN_FENCE_FD", &in_fence_fd_property_); |
| 134 | if (ret) |
| 135 | ALOGI("Could not get IN_FENCE_FD property"); |
| 136 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | uint32_t DrmPlane::id() const { |
| 141 | return id_; |
| 142 | } |
| 143 | |
| 144 | bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const { |
| 145 | return !!((1 << crtc.pipe()) & possible_crtc_mask_); |
| 146 | } |
| 147 | |
| 148 | uint32_t DrmPlane::type() const { |
| 149 | return type_; |
| 150 | } |
| 151 | |
| 152 | const DrmProperty &DrmPlane::crtc_property() const { |
| 153 | return crtc_property_; |
| 154 | } |
| 155 | |
| 156 | const DrmProperty &DrmPlane::fb_property() const { |
| 157 | return fb_property_; |
| 158 | } |
| 159 | |
| 160 | const DrmProperty &DrmPlane::crtc_x_property() const { |
| 161 | return crtc_x_property_; |
| 162 | } |
| 163 | |
| 164 | const DrmProperty &DrmPlane::crtc_y_property() const { |
| 165 | return crtc_y_property_; |
| 166 | } |
| 167 | |
| 168 | const DrmProperty &DrmPlane::crtc_w_property() const { |
| 169 | return crtc_w_property_; |
| 170 | } |
| 171 | |
| 172 | const DrmProperty &DrmPlane::crtc_h_property() const { |
| 173 | return crtc_h_property_; |
| 174 | } |
| 175 | |
| 176 | const DrmProperty &DrmPlane::src_x_property() const { |
| 177 | return src_x_property_; |
| 178 | } |
| 179 | |
| 180 | const DrmProperty &DrmPlane::src_y_property() const { |
| 181 | return src_y_property_; |
| 182 | } |
| 183 | |
| 184 | const DrmProperty &DrmPlane::src_w_property() const { |
| 185 | return src_w_property_; |
| 186 | } |
| 187 | |
| 188 | const DrmProperty &DrmPlane::src_h_property() const { |
| 189 | return src_h_property_; |
| 190 | } |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 191 | |
| 192 | const DrmProperty &DrmPlane::rotation_property() const { |
| 193 | return rotation_property_; |
| 194 | } |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 195 | |
| 196 | const DrmProperty &DrmPlane::alpha_property() const { |
| 197 | return alpha_property_; |
| 198 | } |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 199 | |
Lowry Li | 9b6cafd | 2018-08-28 17:58:21 +0800 | [diff] [blame^] | 200 | const DrmProperty &DrmPlane::blend_property() const { |
| 201 | return blend_property_; |
| 202 | } |
| 203 | |
Robert Foss | a09220c | 2016-09-30 10:27:23 -0400 | [diff] [blame] | 204 | const DrmProperty &DrmPlane::in_fence_fd_property() const { |
| 205 | return in_fence_fd_property_; |
| 206 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 207 | } // namespace android |