blob: 400ac9b299930dad94f037a8eb207b0746a2f124 [file] [log] [blame]
Roman Stratiienko03fd35c2022-01-04 14:30:37 +02001/*
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 Paul468a7542024-07-16 19:50:58 +000017#define LOG_TAG "drmhwc"
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020018
19#include "HwcLayer.h"
20
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020021#include "HwcDisplay.h"
22#include "bufferinfo/BufferInfoGetter.h"
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020023#include "utils/log.h"
24
25namespace android {
26
Drew Davenporta241a772024-09-24 11:26:30 -060027void HwcLayer::SetLayerProperties(const LayerProperties& layer_properties) {
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020028 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 Davenporte5fbbbb2024-10-14 15:49:27 -060043 }
Drew Davenporta241a772024-09-24 11:26:30 -060044 if (layer_properties.blend_mode) {
45 blend_mode_ = layer_properties.blend_mode.value();
46 }
Drew Davenportac9681e2024-09-24 12:17:34 -060047 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 Davenport1b0d8b72024-09-24 15:31:38 -060053 if (layer_properties.composition_type) {
54 sf_type_ = layer_properties.composition_type.value();
55 }
Drew Davenport22d66b42024-09-24 15:34:57 -060056 if (layer_properties.display_frame) {
57 layer_data_.pi.display_frame = layer_properties.display_frame.value();
58 }
Drew Davenport07b96f02024-09-24 15:37:12 -060059 if (layer_properties.alpha) {
Roman Stratiienkofb9fed52025-01-23 02:25:12 +020060 layer_data_.pi.alpha = layer_properties.alpha.value();
Drew Davenport07b96f02024-09-24 15:37:12 -060061 }
Drew Davenport7ab8c182024-09-24 17:04:26 -060062 if (layer_properties.source_crop) {
63 layer_data_.pi.source_crop = layer_properties.source_crop.value();
64 }
Drew Davenport51c61e42024-09-24 17:13:39 -060065 if (layer_properties.transform) {
66 layer_data_.pi.transform = layer_properties.transform.value();
67 }
Drew Davenport5d679b02024-09-25 10:15:58 -060068 if (layer_properties.z_order) {
69 z_order_ = layer_properties.z_order.value();
70 }
Drew Davenporta241a772024-09-24 11:26:30 -060071}
72
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020073void HwcLayer::ImportFb() {
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020074 if (!IsLayerUsableAsDevice() || !buffer_updated_ ||
75 !active_slot_id_.has_value()) {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020076 return;
77 }
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020078 buffer_updated_ = false;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020079
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020080 if (slots_[*active_slot_id_].fb) {
Roman Stratiienkoa32f9072022-05-13 12:12:20 +030081 return;
82 }
83
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020084 auto& fb_importer = parent_->GetPipe().device->GetDrmFbImporter();
85 auto fb = fb_importer.GetOrCreateFbId(&slots_[*active_slot_id_].bi);
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020086
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020087 if (!fb) {
88 ALOGE("Unable to create framebuffer object for layer %p", this);
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020089 fb_import_failed_ = true;
90 return;
91 }
Roman Stratiienkoa32f9072022-05-13 12:12:20 +030092
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020093 slots_[*active_slot_id_].fb = fb;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020094}
95
Roman Stratiienko359a9d32023-01-16 17:41:07 +020096void HwcLayer::PopulateLayerData() {
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020097 ImportFb();
98
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020099 if (!active_slot_id_.has_value()) {
100 ALOGE("Internal error: populate layer data called without active slot");
Roman Stratiienkoa7913de2022-10-20 13:18:57 +0300101 return;
102 }
103
Roman Stratiienko28ec9ee2025-02-19 13:30:21 +0200104 if (slots_.count(*active_slot_id_) == 0) {
105 return;
106 }
107
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200108 layer_data_.bi = slots_[*active_slot_id_].bi;
109 layer_data_.fb = slots_[*active_slot_id_].fb;
110
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200111 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 Stratiienko03fd35c2022-01-04 14:30:37 +0200120}
121
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200122void HwcLayer::ClearSlots() {
123 slots_.clear();
124 active_slot_id_.reset();
Roman Stratiienkoa32f9072022-05-13 12:12:20 +0300125}
126
Roman Stratiienko03fd35c2022-01-04 14:30:37 +0200127} // namespace android