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 | |
Roman Stratiienko | a32f907 | 2022-05-13 12:12:20 +0300 | [diff] [blame^] | 22 | #include "bufferinfo/BufferInfoGetter.h" |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 23 | #include "compositor/LayerData.h" |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 27 | class HwcDisplay; |
| 28 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 29 | class HwcLayer { |
| 30 | public: |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 31 | explicit HwcLayer(HwcDisplay *parent_display) : parent_(parent_display){}; |
| 32 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 33 | HWC2::Composition GetSfType() const { |
| 34 | return sf_type_; |
| 35 | } |
| 36 | HWC2::Composition GetValidatedType() const { |
| 37 | return validated_type_; |
| 38 | } |
| 39 | void AcceptTypeChange() { |
| 40 | sf_type_ = validated_type_; |
| 41 | } |
| 42 | void SetValidatedType(HWC2::Composition type) { |
| 43 | validated_type_ = type; |
| 44 | } |
| 45 | bool IsTypeChanged() const { |
| 46 | return sf_type_ != validated_type_; |
| 47 | } |
| 48 | |
Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 49 | bool GetPriorBufferScanOutFlag() const { |
| 50 | return prior_buffer_scanout_flag_; |
| 51 | } |
| 52 | |
| 53 | void SetPriorBufferScanOutFlag(bool state) { |
| 54 | prior_buffer_scanout_flag_ = state; |
| 55 | } |
| 56 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 57 | uint32_t GetZOrder() const { |
| 58 | return z_order_; |
| 59 | } |
| 60 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 61 | auto &GetLayerData() { |
| 62 | return layer_data_; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | // Layer hooks |
| 66 | HWC2::Error SetCursorPosition(int32_t /*x*/, int32_t /*y*/); |
| 67 | HWC2::Error SetLayerBlendMode(int32_t mode); |
| 68 | HWC2::Error SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fence); |
| 69 | HWC2::Error SetLayerColor(hwc_color_t /*color*/); |
| 70 | HWC2::Error SetLayerCompositionType(int32_t type); |
| 71 | HWC2::Error SetLayerDataspace(int32_t dataspace); |
| 72 | HWC2::Error SetLayerDisplayFrame(hwc_rect_t frame); |
| 73 | HWC2::Error SetLayerPlaneAlpha(float alpha); |
| 74 | HWC2::Error SetLayerSidebandStream(const native_handle_t *stream); |
| 75 | HWC2::Error SetLayerSourceCrop(hwc_frect_t crop); |
| 76 | HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage); |
| 77 | HWC2::Error SetLayerTransform(int32_t transform); |
| 78 | HWC2::Error SetLayerVisibleRegion(hwc_region_t visible); |
| 79 | HWC2::Error SetLayerZOrder(uint32_t order); |
| 80 | |
| 81 | private: |
| 82 | // sf_type_ stores the initial type given to us by surfaceflinger, |
| 83 | // validated_type_ stores the type after running ValidateDisplay |
| 84 | HWC2::Composition sf_type_ = HWC2::Composition::Invalid; |
| 85 | HWC2::Composition validated_type_ = HWC2::Composition::Invalid; |
| 86 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 87 | uint32_t z_order_ = 0; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 88 | LayerData layer_data_; |
| 89 | |
| 90 | /* Should be populated to layer_data_.acquire_fence only before presenting */ |
| 91 | UniqueFd acquire_fence_; |
| 92 | |
| 93 | /* The following buffer data can have 2 sources: |
| 94 | * 1 - Mapper@4 metadata API |
| 95 | * 2 - HWC@2 API |
| 96 | * We keep ability to have 2 sources in drm_hwc. It may be useful for CLIENT |
| 97 | * layer, at this moment HWC@2 API can't specify blending mode for this layer, |
| 98 | * but Mapper@4 can do that |
| 99 | */ |
| 100 | BufferColorSpace color_space_{}; |
| 101 | BufferSampleRange sample_range_{}; |
| 102 | BufferBlendMode blend_mode_{}; |
| 103 | buffer_handle_t buffer_handle_{}; |
| 104 | bool buffer_handle_updated_{}; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 105 | |
Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 106 | bool prior_buffer_scanout_flag_{}; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 107 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 108 | HwcDisplay *const parent_; |
| 109 | |
| 110 | /* Layer state */ |
| 111 | public: |
| 112 | void PopulateLayerData(bool test); |
| 113 | |
| 114 | bool IsLayerUsableAsDevice() const { |
| 115 | return !bi_get_failed_ && !fb_import_failed_ && buffer_handle_ != nullptr; |
| 116 | } |
| 117 | |
| 118 | private: |
| 119 | void ImportFb(); |
| 120 | bool bi_get_failed_{}; |
| 121 | bool fb_import_failed_{}; |
Roman Stratiienko | a32f907 | 2022-05-13 12:12:20 +0300 | [diff] [blame^] | 122 | |
| 123 | /* SwapChain Cache */ |
| 124 | public: |
| 125 | void SwChainClearCache(); |
| 126 | |
| 127 | private: |
| 128 | struct SwapChainElement { |
| 129 | std::optional<BufferInfo> bi; |
| 130 | std::shared_ptr<DrmFbIdHandle> fb; |
| 131 | }; |
| 132 | |
| 133 | bool SwChainGetBufferFromCache(BufferUniqueId unique_id); |
| 134 | void SwChainReassemble(BufferUniqueId unique_id); |
| 135 | void SwChainAddCurrentBuffer(BufferUniqueId unique_id); |
| 136 | |
| 137 | std::map<int /*seq_no*/, SwapChainElement> swchain_cache_; |
| 138 | std::map<BufferUniqueId, int /*seq_no*/> swchain_lookup_table_; |
| 139 | bool swchain_reassembled_{}; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | } // namespace android |
| 143 | |
| 144 | #endif |