Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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-layer" |
| 18 | |
| 19 | #include "HwcLayer.h" |
| 20 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 21 | #include "utils/log.h" |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | // NOLINTNEXTLINE(readability-convert-member-functions-to-static) |
| 26 | HWC2::Error HwcLayer::SetCursorPosition(int32_t /*x*/, int32_t /*y*/) { |
| 27 | return HWC2::Error::None; |
| 28 | } |
| 29 | |
| 30 | HWC2::Error HwcLayer::SetLayerBlendMode(int32_t mode) { |
| 31 | switch (static_cast<HWC2::BlendMode>(mode)) { |
| 32 | case HWC2::BlendMode::None: |
| 33 | blending_ = DrmHwcBlending::kNone; |
| 34 | break; |
| 35 | case HWC2::BlendMode::Premultiplied: |
| 36 | blending_ = DrmHwcBlending::kPreMult; |
| 37 | break; |
| 38 | case HWC2::BlendMode::Coverage: |
| 39 | blending_ = DrmHwcBlending::kCoverage; |
| 40 | break; |
| 41 | default: |
| 42 | ALOGE("Unknown blending mode b=%d", blending_); |
| 43 | blending_ = DrmHwcBlending::kNone; |
| 44 | break; |
| 45 | } |
| 46 | return HWC2::Error::None; |
| 47 | } |
| 48 | |
| 49 | /* Find API details at: |
| 50 | * https://cs.android.com/android/platform/superproject/+/android-11.0.0_r3:hardware/libhardware/include/hardware/hwcomposer2.h;l=2314 |
| 51 | */ |
| 52 | HWC2::Error HwcLayer::SetLayerBuffer(buffer_handle_t buffer, |
| 53 | int32_t acquire_fence) { |
| 54 | buffer_ = buffer; |
| 55 | acquire_fence_ = UniqueFd(acquire_fence); |
| 56 | return HWC2::Error::None; |
| 57 | } |
| 58 | |
| 59 | // NOLINTNEXTLINE(readability-convert-member-functions-to-static) |
| 60 | HWC2::Error HwcLayer::SetLayerColor(hwc_color_t /*color*/) { |
| 61 | // TODO(nobody): Put to client composition here? |
| 62 | return HWC2::Error::None; |
| 63 | } |
| 64 | |
| 65 | HWC2::Error HwcLayer::SetLayerCompositionType(int32_t type) { |
| 66 | sf_type_ = static_cast<HWC2::Composition>(type); |
| 67 | return HWC2::Error::None; |
| 68 | } |
| 69 | |
| 70 | HWC2::Error HwcLayer::SetLayerDataspace(int32_t dataspace) { |
| 71 | switch (dataspace & HAL_DATASPACE_STANDARD_MASK) { |
| 72 | case HAL_DATASPACE_STANDARD_BT709: |
| 73 | color_space_ = DrmHwcColorSpace::kItuRec709; |
| 74 | break; |
| 75 | case HAL_DATASPACE_STANDARD_BT601_625: |
| 76 | case HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED: |
| 77 | case HAL_DATASPACE_STANDARD_BT601_525: |
| 78 | case HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED: |
| 79 | color_space_ = DrmHwcColorSpace::kItuRec601; |
| 80 | break; |
| 81 | case HAL_DATASPACE_STANDARD_BT2020: |
| 82 | case HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE: |
| 83 | color_space_ = DrmHwcColorSpace::kItuRec2020; |
| 84 | break; |
| 85 | default: |
| 86 | color_space_ = DrmHwcColorSpace::kUndefined; |
| 87 | } |
| 88 | |
| 89 | switch (dataspace & HAL_DATASPACE_RANGE_MASK) { |
| 90 | case HAL_DATASPACE_RANGE_FULL: |
| 91 | sample_range_ = DrmHwcSampleRange::kFullRange; |
| 92 | break; |
| 93 | case HAL_DATASPACE_RANGE_LIMITED: |
| 94 | sample_range_ = DrmHwcSampleRange::kLimitedRange; |
| 95 | break; |
| 96 | default: |
| 97 | sample_range_ = DrmHwcSampleRange::kUndefined; |
| 98 | } |
| 99 | return HWC2::Error::None; |
| 100 | } |
| 101 | |
| 102 | HWC2::Error HwcLayer::SetLayerDisplayFrame(hwc_rect_t frame) { |
| 103 | display_frame_ = frame; |
| 104 | return HWC2::Error::None; |
| 105 | } |
| 106 | |
| 107 | HWC2::Error HwcLayer::SetLayerPlaneAlpha(float alpha) { |
| 108 | alpha_ = alpha; |
| 109 | return HWC2::Error::None; |
| 110 | } |
| 111 | |
| 112 | // NOLINTNEXTLINE(readability-convert-member-functions-to-static) |
| 113 | HWC2::Error HwcLayer::SetLayerSidebandStream( |
| 114 | const native_handle_t * /*stream*/) { |
| 115 | // TODO(nobody): We don't support sideband |
| 116 | return HWC2::Error::Unsupported; |
| 117 | } |
| 118 | |
| 119 | HWC2::Error HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) { |
| 120 | source_crop_ = crop; |
| 121 | return HWC2::Error::None; |
| 122 | } |
| 123 | |
| 124 | // NOLINTNEXTLINE(readability-convert-member-functions-to-static) |
| 125 | HWC2::Error HwcLayer::SetLayerSurfaceDamage(hwc_region_t /*damage*/) { |
| 126 | // TODO(nobody): We don't use surface damage, marking as unsupported |
| 127 | return HWC2::Error::None; |
| 128 | } |
| 129 | |
| 130 | HWC2::Error HwcLayer::SetLayerTransform(int32_t transform) { |
| 131 | uint32_t l_transform = 0; |
| 132 | |
| 133 | // 270* and 180* cannot be combined with flips. More specifically, they |
| 134 | // already contain both horizontal and vertical flips, so those fields are |
| 135 | // redundant in this case. 90* rotation can be combined with either horizontal |
| 136 | // flip or vertical flip, so treat it differently |
| 137 | if (transform == HWC_TRANSFORM_ROT_270) { |
| 138 | l_transform = DrmHwcTransform::kRotate270; |
| 139 | } else if (transform == HWC_TRANSFORM_ROT_180) { |
| 140 | l_transform = DrmHwcTransform::kRotate180; |
| 141 | } else { |
| 142 | if ((transform & HWC_TRANSFORM_FLIP_H) != 0) |
| 143 | l_transform |= DrmHwcTransform::kFlipH; |
| 144 | if ((transform & HWC_TRANSFORM_FLIP_V) != 0) |
| 145 | l_transform |= DrmHwcTransform::kFlipV; |
| 146 | if ((transform & HWC_TRANSFORM_ROT_90) != 0) |
| 147 | l_transform |= DrmHwcTransform::kRotate90; |
| 148 | } |
| 149 | |
| 150 | transform_ = static_cast<DrmHwcTransform>(l_transform); |
| 151 | return HWC2::Error::None; |
| 152 | } |
| 153 | |
| 154 | // NOLINTNEXTLINE(readability-convert-member-functions-to-static) |
| 155 | HWC2::Error HwcLayer::SetLayerVisibleRegion(hwc_region_t /*visible*/) { |
| 156 | // TODO(nobody): We don't use this information, marking as unsupported |
| 157 | return HWC2::Error::None; |
| 158 | } |
| 159 | |
| 160 | HWC2::Error HwcLayer::SetLayerZOrder(uint32_t order) { |
| 161 | z_order_ = order; |
| 162 | return HWC2::Error::None; |
| 163 | } |
| 164 | |
| 165 | void HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) { |
| 166 | layer->sf_handle = buffer_; |
| 167 | // TODO(rsglobal): Avoid extra fd duplication |
Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 168 | layer->acquire_fence = UniqueFd::Dup(acquire_fence_.Get()); |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 169 | layer->display_frame = display_frame_; |
| 170 | layer->alpha = std::lround(alpha_ * UINT16_MAX); |
| 171 | layer->blending = blending_; |
| 172 | layer->source_crop = source_crop_; |
| 173 | layer->transform = transform_; |
| 174 | layer->color_space = color_space_; |
| 175 | layer->sample_range = sample_range_; |
| 176 | } |
| 177 | |
| 178 | } // namespace android |