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 | |
Sean Paul | 468a754 | 2024-07-16 19:50:58 +0000 | [diff] [blame] | 17 | #define LOG_TAG "drmhwc" |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 18 | |
| 19 | #include "HwcLayer.h" |
| 20 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 21 | #include "HwcDisplay.h" |
| 22 | #include "bufferinfo/BufferInfoGetter.h" |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 23 | #include "utils/log.h" |
| 24 | |
| 25 | namespace android { |
| 26 | |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 27 | void HwcLayer::SetLayerProperties(const LayerProperties& layer_properties) { |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 28 | if (layer_properties.slot_buffer) { |
| 29 | auto slot_id = layer_properties.slot_buffer->slot_id; |
| 30 | if (!layer_properties.slot_buffer->bi) { |
| 31 | slots_.erase(slot_id); |
| 32 | } else { |
| 33 | slots_[slot_id] = { |
| 34 | .bi = layer_properties.slot_buffer->bi.value(), |
| 35 | .fb = {}, |
| 36 | }; |
| 37 | } |
| 38 | } |
| 39 | if (layer_properties.active_slot) { |
| 40 | active_slot_id_ = layer_properties.active_slot->slot_id; |
| 41 | layer_data_.acquire_fence = layer_properties.active_slot->fence; |
| 42 | buffer_updated_ = true; |
Drew Davenport | e5fbbbb | 2024-10-14 15:49:27 -0600 | [diff] [blame] | 43 | } |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 44 | if (layer_properties.blend_mode) { |
| 45 | blend_mode_ = layer_properties.blend_mode.value(); |
| 46 | } |
Drew Davenport | ac9681e | 2024-09-24 12:17:34 -0600 | [diff] [blame] | 47 | if (layer_properties.color_space) { |
| 48 | color_space_ = layer_properties.color_space.value(); |
| 49 | } |
| 50 | if (layer_properties.sample_range) { |
| 51 | sample_range_ = layer_properties.sample_range.value(); |
| 52 | } |
Drew Davenport | 1b0d8b7 | 2024-09-24 15:31:38 -0600 | [diff] [blame] | 53 | if (layer_properties.composition_type) { |
| 54 | sf_type_ = layer_properties.composition_type.value(); |
| 55 | } |
Drew Davenport | 22d66b4 | 2024-09-24 15:34:57 -0600 | [diff] [blame] | 56 | if (layer_properties.display_frame) { |
| 57 | layer_data_.pi.display_frame = layer_properties.display_frame.value(); |
| 58 | } |
Drew Davenport | 07b96f0 | 2024-09-24 15:37:12 -0600 | [diff] [blame] | 59 | if (layer_properties.alpha) { |
Roman Stratiienko | fb9fed5 | 2025-01-23 02:25:12 +0200 | [diff] [blame] | 60 | layer_data_.pi.alpha = layer_properties.alpha.value(); |
Drew Davenport | 07b96f0 | 2024-09-24 15:37:12 -0600 | [diff] [blame] | 61 | } |
Drew Davenport | 7ab8c18 | 2024-09-24 17:04:26 -0600 | [diff] [blame] | 62 | if (layer_properties.source_crop) { |
| 63 | layer_data_.pi.source_crop = layer_properties.source_crop.value(); |
| 64 | } |
Drew Davenport | 51c61e4 | 2024-09-24 17:13:39 -0600 | [diff] [blame] | 65 | if (layer_properties.transform) { |
| 66 | layer_data_.pi.transform = layer_properties.transform.value(); |
| 67 | } |
Drew Davenport | 5d679b0 | 2024-09-25 10:15:58 -0600 | [diff] [blame] | 68 | if (layer_properties.z_order) { |
| 69 | z_order_ = layer_properties.z_order.value(); |
| 70 | } |
Drew Davenport | a241a77 | 2024-09-24 11:26:30 -0600 | [diff] [blame] | 71 | } |
| 72 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 73 | void HwcLayer::ImportFb() { |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 74 | if (!IsLayerUsableAsDevice() || !buffer_updated_ || |
| 75 | !active_slot_id_.has_value()) { |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 76 | return; |
| 77 | } |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 78 | buffer_updated_ = false; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 79 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 80 | if (slots_[*active_slot_id_].fb) { |
Roman Stratiienko | a32f907 | 2022-05-13 12:12:20 +0300 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 84 | auto& fb_importer = parent_->GetPipe().device->GetDrmFbImporter(); |
| 85 | auto fb = fb_importer.GetOrCreateFbId(&slots_[*active_slot_id_].bi); |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 86 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 87 | if (!fb) { |
| 88 | ALOGE("Unable to create framebuffer object for layer %p", this); |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 89 | fb_import_failed_ = true; |
| 90 | return; |
| 91 | } |
Roman Stratiienko | a32f907 | 2022-05-13 12:12:20 +0300 | [diff] [blame] | 92 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 93 | slots_[*active_slot_id_].fb = fb; |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Roman Stratiienko | 359a9d3 | 2023-01-16 17:41:07 +0200 | [diff] [blame] | 96 | void HwcLayer::PopulateLayerData() { |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 97 | ImportFb(); |
| 98 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 99 | if (!active_slot_id_.has_value()) { |
| 100 | ALOGE("Internal error: populate layer data called without active slot"); |
Roman Stratiienko | a7913de | 2022-10-20 13:18:57 +0300 | [diff] [blame] | 101 | return; |
| 102 | } |
| 103 | |
Roman Stratiienko | 28ec9ee | 2025-02-19 13:30:21 +0200 | [diff] [blame] | 104 | if (slots_.count(*active_slot_id_) == 0) { |
| 105 | return; |
| 106 | } |
| 107 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 108 | layer_data_.bi = slots_[*active_slot_id_].bi; |
| 109 | layer_data_.fb = slots_[*active_slot_id_].fb; |
| 110 | |
Roman Stratiienko | 4b2cc48 | 2022-02-21 14:53:58 +0200 | [diff] [blame] | 111 | if (blend_mode_ != BufferBlendMode::kUndefined) { |
| 112 | layer_data_.bi->blend_mode = blend_mode_; |
| 113 | } |
| 114 | if (color_space_ != BufferColorSpace::kUndefined) { |
| 115 | layer_data_.bi->color_space = color_space_; |
| 116 | } |
| 117 | if (sample_range_ != BufferSampleRange::kUndefined) { |
| 118 | layer_data_.bi->sample_range = sample_range_; |
| 119 | } |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Roman Stratiienko | 7c8cc4e | 2025-01-25 22:41:53 +0200 | [diff] [blame] | 122 | void HwcLayer::ClearSlots() { |
| 123 | slots_.clear(); |
| 124 | active_slot_id_.reset(); |
Roman Stratiienko | a32f907 | 2022-05-13 12:12:20 +0300 | [diff] [blame] | 125 | } |
| 126 | |
Roman Stratiienko | 03fd35c | 2022-01-04 14:30:37 +0200 | [diff] [blame] | 127 | } // namespace android |