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 | |
Roman Stratiienko | bde9566 | 2022-12-10 20:27:58 +0200 | [diff] [blame] | 17 | #pragma once |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 18 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 19 | #include <aidl/android/hardware/graphics/common/Transform.h> |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 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: |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 31 | struct Buffer { |
| 32 | buffer_handle_t buffer_handle; |
| 33 | SharedFd acquire_fence; |
| 34 | }; |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 35 | // A set of properties to be validated. |
| 36 | struct LayerProperties { |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 37 | std::optional<Buffer> buffer; |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 38 | std::optional<BufferBlendMode> blend_mode; |
Drew Davenport | ac9681e | 2024-09-24 12:17:34 -0600 | [diff] [blame] | 39 | std::optional<BufferColorSpace> color_space; |
| 40 | std::optional<BufferSampleRange> sample_range; |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 41 | std::optional<HWC2::Composition> composition_type; |
Roman Stratiienko | 4e15bfc | 2025-01-23 01:55:21 +0200 | [diff] [blame] | 42 | std::optional<DstRectInfo> display_frame; |
Drew Davenport | 07b96f0 | 2024-09-24 15:37:12 -0600 | [diff] [blame] | 43 | std::optional<float> alpha; |
Roman Stratiienko | 4e15bfc | 2025-01-23 01:55:21 +0200 | [diff] [blame] | 44 | std::optional<SrcRectInfo> source_crop; |
Drew Davenport | 51c61e4 | 2024-09-24 17:13:39 -0600 | [diff] [blame] | 45 | std::optional<LayerTransform> transform; |
Drew Davenport | 5d679b0 | 2024-09-25 10:15:58 -0600 | [diff] [blame] | 46 | std::optional<uint32_t> z_order; |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 47 | }; |
| 48 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 49 | explicit HwcLayer(HwcDisplay *parent_display) : parent_(parent_display){}; |
| 50 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 51 | HWC2::Composition GetSfType() const { |
| 52 | return sf_type_; |
| 53 | } |
| 54 | HWC2::Composition GetValidatedType() const { |
| 55 | return validated_type_; |
| 56 | } |
| 57 | void AcceptTypeChange() { |
| 58 | sf_type_ = validated_type_; |
| 59 | } |
| 60 | void SetValidatedType(HWC2::Composition type) { |
| 61 | validated_type_ = type; |
| 62 | } |
| 63 | bool IsTypeChanged() const { |
| 64 | return sf_type_ != validated_type_; |
| 65 | } |
| 66 | |
Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 67 | bool GetPriorBufferScanOutFlag() const { |
| 68 | return prior_buffer_scanout_flag_; |
| 69 | } |
| 70 | |
| 71 | void SetPriorBufferScanOutFlag(bool state) { |
| 72 | prior_buffer_scanout_flag_ = state; |
| 73 | } |
| 74 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 75 | uint32_t GetZOrder() const { |
| 76 | return z_order_; |
| 77 | } |
| 78 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 79 | auto &GetLayerData() { |
| 80 | return layer_data_; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 83 | void SetLayerProperties(const LayerProperties &layer_properties); |
| 84 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 85 | private: |
| 86 | // sf_type_ stores the initial type given to us by surfaceflinger, |
| 87 | // validated_type_ stores the type after running ValidateDisplay |
| 88 | HWC2::Composition sf_type_ = HWC2::Composition::Invalid; |
| 89 | HWC2::Composition validated_type_ = HWC2::Composition::Invalid; |
| 90 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 91 | uint32_t z_order_ = 0; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 92 | LayerData layer_data_; |
| 93 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 94 | /* The following buffer data can have 2 sources: |
| 95 | * 1 - Mapper@4 metadata API |
| 96 | * 2 - HWC@2 API |
| 97 | * We keep ability to have 2 sources in drm_hwc. It may be useful for CLIENT |
| 98 | * layer, at this moment HWC@2 API can't specify blending mode for this layer, |
| 99 | * but Mapper@4 can do that |
| 100 | */ |
| 101 | BufferColorSpace color_space_{}; |
| 102 | BufferSampleRange sample_range_{}; |
| 103 | BufferBlendMode blend_mode_{}; |
| 104 | buffer_handle_t buffer_handle_{}; |
| 105 | bool buffer_handle_updated_{}; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 106 | |
Roman Stratiienko | dd21494 | 2022-05-03 18:24:49 +0300 | [diff] [blame] | 107 | bool prior_buffer_scanout_flag_{}; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 108 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 109 | HwcDisplay *const parent_; |
| 110 | |
| 111 | /* Layer state */ |
| 112 | public: |
Roman Stratiienko | 359a9d3 | 2023-01-16 17:41:07 +0200 | [diff] [blame] | 113 | void PopulateLayerData(); |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 114 | |
| 115 | bool IsLayerUsableAsDevice() const { |
| 116 | return !bi_get_failed_ && !fb_import_failed_ && buffer_handle_ != nullptr; |
| 117 | } |
| 118 | |
| 119 | private: |
| 120 | void ImportFb(); |
| 121 | bool bi_get_failed_{}; |
| 122 | bool fb_import_failed_{}; |
Roman Stratiienko | a32f907 | 2022-05-13 12:12:20 +0300 | [diff] [blame] | 123 | |
| 124 | /* SwapChain Cache */ |
| 125 | public: |
| 126 | void SwChainClearCache(); |
| 127 | |
| 128 | private: |
| 129 | struct SwapChainElement { |
| 130 | std::optional<BufferInfo> bi; |
| 131 | std::shared_ptr<DrmFbIdHandle> fb; |
| 132 | }; |
| 133 | |
| 134 | bool SwChainGetBufferFromCache(BufferUniqueId unique_id); |
| 135 | void SwChainReassemble(BufferUniqueId unique_id); |
| 136 | void SwChainAddCurrentBuffer(BufferUniqueId unique_id); |
| 137 | |
| 138 | std::map<int /*seq_no*/, SwapChainElement> swchain_cache_; |
| 139 | std::map<BufferUniqueId, int /*seq_no*/> swchain_lookup_table_; |
| 140 | bool swchain_reassembled_{}; |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | } // namespace android |