blob: c335d882cb94ef92040124b6f1121a6aa2892b30 [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
Roman Stratiienkobde95662022-12-10 20:27:58 +020017#pragma once
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020018
Drew Davenporta241a772024-09-24 11:26:30 -060019#include <aidl/android/hardware/graphics/common/Transform.h>
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020020#include <hardware/hwcomposer2.h>
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020021#include <memory>
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020022
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020023#include "bufferinfo/BufferInfo.h"
Roman Stratiienkoa32f9072022-05-13 12:12:20 +030024#include "bufferinfo/BufferInfoGetter.h"
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020025#include "compositor/LayerData.h"
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020026#include "utils/fd.h"
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020027
28namespace android {
29
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020030class HwcDisplay;
31
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020032class FrontendLayerBase {
33 public:
34 virtual ~FrontendLayerBase() = default;
35};
36
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020037class HwcLayer {
38 public:
Drew Davenporte5fbbbb2024-10-14 15:49:27 -060039 struct Buffer {
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020040 int32_t slot_id;
41 std::optional<BufferInfo> bi;
42 };
43 struct Slot {
44 int32_t slot_id;
45 SharedFd fence;
Drew Davenporte5fbbbb2024-10-14 15:49:27 -060046 };
Drew Davenporta241a772024-09-24 11:26:30 -060047 // A set of properties to be validated.
48 struct LayerProperties {
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020049 std::optional<Buffer> slot_buffer;
50 std::optional<Slot> active_slot;
Drew Davenporta241a772024-09-24 11:26:30 -060051 std::optional<BufferBlendMode> blend_mode;
Drew Davenportac9681e2024-09-24 12:17:34 -060052 std::optional<BufferColorSpace> color_space;
53 std::optional<BufferSampleRange> sample_range;
Drew Davenport1b0d8b72024-09-24 15:31:38 -060054 std::optional<HWC2::Composition> composition_type;
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020055 std::optional<DstRectInfo> display_frame;
Drew Davenport07b96f02024-09-24 15:37:12 -060056 std::optional<float> alpha;
Roman Stratiienko4e15bfc2025-01-23 01:55:21 +020057 std::optional<SrcRectInfo> source_crop;
Drew Davenport51c61e42024-09-24 17:13:39 -060058 std::optional<LayerTransform> transform;
Drew Davenport5d679b02024-09-25 10:15:58 -060059 std::optional<uint32_t> z_order;
Drew Davenporta241a772024-09-24 11:26:30 -060060 };
61
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020062 explicit HwcLayer(HwcDisplay *parent_display) : parent_(parent_display){};
63
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020064 HWC2::Composition GetSfType() const {
65 return sf_type_;
66 }
67 HWC2::Composition GetValidatedType() const {
68 return validated_type_;
69 }
70 void AcceptTypeChange() {
71 sf_type_ = validated_type_;
72 }
73 void SetValidatedType(HWC2::Composition type) {
74 validated_type_ = type;
75 }
76 bool IsTypeChanged() const {
77 return sf_type_ != validated_type_;
78 }
79
Roman Stratiienkodd214942022-05-03 18:24:49 +030080 bool GetPriorBufferScanOutFlag() const {
81 return prior_buffer_scanout_flag_;
82 }
83
84 void SetPriorBufferScanOutFlag(bool state) {
85 prior_buffer_scanout_flag_ = state;
86 }
87
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020088 uint32_t GetZOrder() const {
89 return z_order_;
90 }
91
Roman Stratiienko4b2cc482022-02-21 14:53:58 +020092 auto &GetLayerData() {
93 return layer_data_;
Roman Stratiienko03fd35c2022-01-04 14:30:37 +020094 }
95
Drew Davenporta241a772024-09-24 11:26:30 -060096 void SetLayerProperties(const LayerProperties &layer_properties);
97
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +020098 auto GetFrontendPrivateData() -> std::shared_ptr<FrontendLayerBase> {
99 return frontend_private_data_;
100 }
101
102 auto SetFrontendPrivateData(std::shared_ptr<FrontendLayerBase> data) {
103 frontend_private_data_ = std::move(data);
104 }
105
Roman Stratiienko03fd35c2022-01-04 14:30:37 +0200106 private:
107 // sf_type_ stores the initial type given to us by surfaceflinger,
108 // validated_type_ stores the type after running ValidateDisplay
109 HWC2::Composition sf_type_ = HWC2::Composition::Invalid;
110 HWC2::Composition validated_type_ = HWC2::Composition::Invalid;
111
Roman Stratiienko03fd35c2022-01-04 14:30:37 +0200112 uint32_t z_order_ = 0;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200113 LayerData layer_data_;
114
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200115 /* The following buffer data can have 2 sources:
116 * 1 - Mapper@4 metadata API
117 * 2 - HWC@2 API
118 * We keep ability to have 2 sources in drm_hwc. It may be useful for CLIENT
119 * layer, at this moment HWC@2 API can't specify blending mode for this layer,
120 * but Mapper@4 can do that
121 */
122 BufferColorSpace color_space_{};
123 BufferSampleRange sample_range_{};
124 BufferBlendMode blend_mode_{};
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200125 bool buffer_updated_{};
Roman Stratiienko03fd35c2022-01-04 14:30:37 +0200126
Roman Stratiienkodd214942022-05-03 18:24:49 +0300127 bool prior_buffer_scanout_flag_{};
Roman Stratiienko03fd35c2022-01-04 14:30:37 +0200128
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200129 HwcDisplay *const parent_;
130
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200131 std::shared_ptr<FrontendLayerBase> frontend_private_data_;
Roman Stratiienko4b2cc482022-02-21 14:53:58 +0200132
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200133 std::optional<int32_t> active_slot_id_;
134 struct BufferSlot {
135 BufferInfo bi;
Roman Stratiienkoa32f9072022-05-13 12:12:20 +0300136 std::shared_ptr<DrmFbIdHandle> fb;
137 };
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200138 std::map<int32_t /*slot*/, BufferSlot> slots_;
Roman Stratiienkoa32f9072022-05-13 12:12:20 +0300139
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200140 void ImportFb();
141 bool fb_import_failed_{};
Roman Stratiienkoa32f9072022-05-13 12:12:20 +0300142
Roman Stratiienko7c8cc4e2025-01-25 22:41:53 +0200143 public:
144 void PopulateLayerData();
145 void ClearSlots();
146
147 bool IsLayerUsableAsDevice() const {
148 return !fb_import_failed_ && active_slot_id_.has_value() &&
149 slots_.count(*active_slot_id_) > 0;
150 }
Roman Stratiienko03fd35c2022-01-04 14:30:37 +0200151};
152
153} // namespace android