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" |
| 20 | #include "drmresources.h" |
| 21 | |
| 22 | #include <errno.h> |
| 23 | #include <stdint.h> |
| 24 | |
| 25 | #include <cutils/log.h> |
| 26 | #include <xf86drmMode.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | DrmPlane::DrmPlane(DrmResources *drm, drmModePlanePtr p) |
| 31 | : drm_(drm), id_(p->plane_id), possible_crtc_mask_(p->possible_crtcs) { |
| 32 | } |
| 33 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 34 | int DrmPlane::Init() { |
| 35 | DrmProperty p; |
| 36 | |
| 37 | int ret = drm_->GetPlaneProperty(*this, "type", &p); |
| 38 | if (ret) { |
| 39 | ALOGE("Could not get plane type property"); |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | uint64_t type; |
| 44 | ret = p.value(&type); |
| 45 | if (ret) { |
| 46 | ALOGE("Failed to get plane type property value"); |
| 47 | return ret; |
| 48 | } |
| 49 | switch (type) { |
| 50 | case DRM_PLANE_TYPE_OVERLAY: |
| 51 | case DRM_PLANE_TYPE_PRIMARY: |
| 52 | case DRM_PLANE_TYPE_CURSOR: |
| 53 | type_ = (uint32_t)type; |
| 54 | break; |
| 55 | default: |
| 56 | ALOGE("Invalid plane type %d", type); |
| 57 | return -EINVAL; |
| 58 | } |
| 59 | |
| 60 | ret = drm_->GetPlaneProperty(*this, "CRTC_ID", &crtc_property_); |
| 61 | if (ret) { |
| 62 | ALOGE("Could not get CRTC_ID property"); |
| 63 | return ret; |
| 64 | } |
| 65 | |
| 66 | ret = drm_->GetPlaneProperty(*this, "FB_ID", &fb_property_); |
| 67 | if (ret) { |
| 68 | ALOGE("Could not get FB_ID property"); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | ret = drm_->GetPlaneProperty(*this, "CRTC_X", &crtc_x_property_); |
| 73 | if (ret) { |
| 74 | ALOGE("Could not get CRTC_X property"); |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | ret = drm_->GetPlaneProperty(*this, "CRTC_Y", &crtc_y_property_); |
| 79 | if (ret) { |
| 80 | ALOGE("Could not get CRTC_Y property"); |
| 81 | return ret; |
| 82 | } |
| 83 | |
| 84 | ret = drm_->GetPlaneProperty(*this, "CRTC_W", &crtc_w_property_); |
| 85 | if (ret) { |
| 86 | ALOGE("Could not get CRTC_W property"); |
| 87 | return ret; |
| 88 | } |
| 89 | |
| 90 | ret = drm_->GetPlaneProperty(*this, "CRTC_H", &crtc_h_property_); |
| 91 | if (ret) { |
| 92 | ALOGE("Could not get CRTC_H property"); |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | ret = drm_->GetPlaneProperty(*this, "SRC_X", &src_x_property_); |
| 97 | if (ret) { |
| 98 | ALOGE("Could not get SRC_X property"); |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | ret = drm_->GetPlaneProperty(*this, "SRC_Y", &src_y_property_); |
| 103 | if (ret) { |
| 104 | ALOGE("Could not get SRC_Y property"); |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | ret = drm_->GetPlaneProperty(*this, "SRC_W", &src_w_property_); |
| 109 | if (ret) { |
| 110 | ALOGE("Could not get SRC_W property"); |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | ret = drm_->GetPlaneProperty(*this, "SRC_H", &src_h_property_); |
| 115 | if (ret) { |
| 116 | ALOGE("Could not get SRC_H property"); |
| 117 | return ret; |
| 118 | } |
| 119 | |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 120 | ret = drm_->GetPlaneProperty(*this, "rotation", &rotation_property_); |
| 121 | if (ret) |
| 122 | ALOGE("Could not get rotation property"); |
| 123 | |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 124 | ret = drm_->GetPlaneProperty(*this, "alpha", &alpha_property_); |
| 125 | if (ret) |
| 126 | ALOGI("Could not get alpha property"); |
| 127 | |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | uint32_t DrmPlane::id() const { |
| 132 | return id_; |
| 133 | } |
| 134 | |
| 135 | bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const { |
| 136 | return !!((1 << crtc.pipe()) & possible_crtc_mask_); |
| 137 | } |
| 138 | |
| 139 | uint32_t DrmPlane::type() const { |
| 140 | return type_; |
| 141 | } |
| 142 | |
| 143 | const DrmProperty &DrmPlane::crtc_property() const { |
| 144 | return crtc_property_; |
| 145 | } |
| 146 | |
| 147 | const DrmProperty &DrmPlane::fb_property() const { |
| 148 | return fb_property_; |
| 149 | } |
| 150 | |
| 151 | const DrmProperty &DrmPlane::crtc_x_property() const { |
| 152 | return crtc_x_property_; |
| 153 | } |
| 154 | |
| 155 | const DrmProperty &DrmPlane::crtc_y_property() const { |
| 156 | return crtc_y_property_; |
| 157 | } |
| 158 | |
| 159 | const DrmProperty &DrmPlane::crtc_w_property() const { |
| 160 | return crtc_w_property_; |
| 161 | } |
| 162 | |
| 163 | const DrmProperty &DrmPlane::crtc_h_property() const { |
| 164 | return crtc_h_property_; |
| 165 | } |
| 166 | |
| 167 | const DrmProperty &DrmPlane::src_x_property() const { |
| 168 | return src_x_property_; |
| 169 | } |
| 170 | |
| 171 | const DrmProperty &DrmPlane::src_y_property() const { |
| 172 | return src_y_property_; |
| 173 | } |
| 174 | |
| 175 | const DrmProperty &DrmPlane::src_w_property() const { |
| 176 | return src_w_property_; |
| 177 | } |
| 178 | |
| 179 | const DrmProperty &DrmPlane::src_h_property() const { |
| 180 | return src_h_property_; |
| 181 | } |
Sean Paul | 1c4c326 | 2015-07-14 15:51:52 -0400 | [diff] [blame] | 182 | |
| 183 | const DrmProperty &DrmPlane::rotation_property() const { |
| 184 | return rotation_property_; |
| 185 | } |
Sean Paul | d8aefb6 | 2015-10-15 15:17:31 -0400 | [diff] [blame] | 186 | |
| 187 | const DrmProperty &DrmPlane::alpha_property() const { |
| 188 | return alpha_property_; |
| 189 | } |
Sean Paul | 6a55e9f | 2015-04-30 15:31:06 -0400 | [diff] [blame] | 190 | } |