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 | #ifndef ANDROID_HWC2_DEVICE_HWC_LAYER_H |
| 18 | #define ANDROID_HWC2_DEVICE_HWC_LAYER_H |
| 19 | |
| 20 | #include <hardware/hwcomposer2.h> |
| 21 | |
| 22 | #include <cmath> |
| 23 | |
| 24 | #include "drmhwcomposer.h" |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | class HwcLayer { |
| 29 | public: |
| 30 | HWC2::Composition GetSfType() const { |
| 31 | return sf_type_; |
| 32 | } |
| 33 | HWC2::Composition GetValidatedType() const { |
| 34 | return validated_type_; |
| 35 | } |
| 36 | void AcceptTypeChange() { |
| 37 | sf_type_ = validated_type_; |
| 38 | } |
| 39 | void SetValidatedType(HWC2::Composition type) { |
| 40 | validated_type_ = type; |
| 41 | } |
| 42 | bool IsTypeChanged() const { |
| 43 | return sf_type_ != validated_type_; |
| 44 | } |
| 45 | |
Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame^] | 46 | bool GetPriorBufferScanOutFlag() const { |
| 47 | return prior_buffer_scanout_flag_; |
| 48 | } |
| 49 | |
| 50 | void SetPriorBufferScanOutFlag(bool state) { |
| 51 | prior_buffer_scanout_flag_ = state; |
| 52 | } |
| 53 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 54 | uint32_t GetZOrder() const { |
| 55 | return z_order_; |
| 56 | } |
| 57 | |
| 58 | buffer_handle_t GetBuffer() { |
| 59 | return buffer_; |
| 60 | } |
| 61 | |
| 62 | hwc_rect_t GetDisplayFrame() { |
| 63 | return display_frame_; |
| 64 | } |
| 65 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 66 | void PopulateDrmLayer(DrmHwcLayer *layer); |
| 67 | |
| 68 | bool RequireScalingOrPhasing() const { |
| 69 | float src_width = source_crop_.right - source_crop_.left; |
| 70 | float src_height = source_crop_.bottom - source_crop_.top; |
| 71 | |
| 72 | auto dest_width = float(display_frame_.right - display_frame_.left); |
| 73 | auto dest_height = float(display_frame_.bottom - display_frame_.top); |
| 74 | |
| 75 | bool scaling = src_width != dest_width || src_height != dest_height; |
| 76 | bool phasing = (source_crop_.left - std::floor(source_crop_.left) != 0) || |
| 77 | (source_crop_.top - std::floor(source_crop_.top) != 0); |
| 78 | return scaling || phasing; |
| 79 | } |
| 80 | |
| 81 | // Layer hooks |
| 82 | HWC2::Error SetCursorPosition(int32_t /*x*/, int32_t /*y*/); |
| 83 | HWC2::Error SetLayerBlendMode(int32_t mode); |
| 84 | HWC2::Error SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fence); |
| 85 | HWC2::Error SetLayerColor(hwc_color_t /*color*/); |
| 86 | HWC2::Error SetLayerCompositionType(int32_t type); |
| 87 | HWC2::Error SetLayerDataspace(int32_t dataspace); |
| 88 | HWC2::Error SetLayerDisplayFrame(hwc_rect_t frame); |
| 89 | HWC2::Error SetLayerPlaneAlpha(float alpha); |
| 90 | HWC2::Error SetLayerSidebandStream(const native_handle_t *stream); |
| 91 | HWC2::Error SetLayerSourceCrop(hwc_frect_t crop); |
| 92 | HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage); |
| 93 | HWC2::Error SetLayerTransform(int32_t transform); |
| 94 | HWC2::Error SetLayerVisibleRegion(hwc_region_t visible); |
| 95 | HWC2::Error SetLayerZOrder(uint32_t order); |
| 96 | |
| 97 | private: |
| 98 | // sf_type_ stores the initial type given to us by surfaceflinger, |
| 99 | // validated_type_ stores the type after running ValidateDisplay |
| 100 | HWC2::Composition sf_type_ = HWC2::Composition::Invalid; |
| 101 | HWC2::Composition validated_type_ = HWC2::Composition::Invalid; |
| 102 | |
| 103 | buffer_handle_t buffer_ = nullptr; |
| 104 | hwc_rect_t display_frame_; |
| 105 | static constexpr float kOpaqueFloat = 1.0F; |
| 106 | float alpha_ = kOpaqueFloat; |
| 107 | hwc_frect_t source_crop_; |
| 108 | DrmHwcTransform transform_ = DrmHwcTransform::kIdentity; |
| 109 | uint32_t z_order_ = 0; |
| 110 | DrmHwcBlending blending_ = DrmHwcBlending::kNone; |
| 111 | DrmHwcColorSpace color_space_ = DrmHwcColorSpace::kUndefined; |
| 112 | DrmHwcSampleRange sample_range_ = DrmHwcSampleRange::kUndefined; |
| 113 | |
Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame^] | 114 | bool prior_buffer_scanout_flag_{}; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 115 | |
Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame^] | 116 | UniqueFd acquire_fence_; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | } // namespace android |
| 120 | |
| 121 | #endif |