blob: 616f8aa63c32b4efc6fef3e2d33a3949d35bcec3 [file] [log] [blame]
Dennis Tsiang33f0ece2023-11-29 12:45:04 +00001/*
Drew Davenport5951b112024-08-05 09:44:27 -06002 * Copyright (C) 2024 The Android Open Source Project
Dennis Tsiang33f0ece2023-11-29 12:45:04 +00003 *
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#pragma once
18
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000019#include <memory>
20
Drew Davenport5951b112024-08-05 09:44:27 -060021#include "aidl/android/hardware/graphics/composer3/BnComposerClient.h"
22#include "aidl/android/hardware/graphics/composer3/LayerCommand.h"
23#include "hwc3/CommandResultWriter.h"
24#include "hwc3/ComposerResources.h"
25#include "hwc3/Utils.h"
26#include "utils/Mutex.h"
27
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000028using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
29using AidlNativeHandle = aidl::android::hardware::common::NativeHandle;
30
Drew Davenport5951b112024-08-05 09:44:27 -060031namespace android {
32
33class HwcDisplay;
34class HwcLayer;
35
36} // namespace android
37
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000038namespace aidl::android::hardware::graphics::composer3::impl {
39
Drew Davenport5951b112024-08-05 09:44:27 -060040class DrmHwcThree;
41
42struct HwcLayerWrapper {
43 int64_t layer_id;
44 ::android::HwcLayer* layer;
45};
46
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000047class ComposerClient : public BnComposerClient {
48 public:
Drew Davenport5951b112024-08-05 09:44:27 -060049 ComposerClient();
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000050 ~ComposerClient() override;
51
Drew Davenport5951b112024-08-05 09:44:27 -060052 bool Init();
53 std::string Dump();
54
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000055 // composer3 interface
56 ndk::ScopedAStatus createLayer(int64_t display, int32_t buffer_slot_count,
57 int64_t* layer) override;
58 ndk::ScopedAStatus createVirtualDisplay(int32_t width, int32_t height,
59 AidlPixelFormat format_hint,
60 int32_t output_buffer_slot_count,
61 VirtualDisplay* display) override;
62 ndk::ScopedAStatus destroyLayer(int64_t display, int64_t layer) override;
63 ndk::ScopedAStatus destroyVirtualDisplay(int64_t display) override;
64 ndk::ScopedAStatus executeCommands(
65 const std::vector<DisplayCommand>& commands,
66 std::vector<CommandResultPayload>* results) override;
67 ndk::ScopedAStatus getActiveConfig(int64_t display, int32_t* config) override;
68 ndk::ScopedAStatus getColorModes(
69 int64_t display, std::vector<ColorMode>* color_modes) override;
70 ndk::ScopedAStatus getDataspaceSaturationMatrix(
71 common::Dataspace dataspace, std::vector<float>* matrix) override;
72 ndk::ScopedAStatus getDisplayAttribute(int64_t display, int32_t config,
73 DisplayAttribute attribute,
74 int32_t* value) override;
75 ndk::ScopedAStatus getDisplayCapabilities(
76 int64_t display, std::vector<DisplayCapability>* caps) override;
77 ndk::ScopedAStatus getDisplayConfigs(int64_t display,
78 std::vector<int32_t>* configs) override;
79 ndk::ScopedAStatus getDisplayConnectionType(
80 int64_t display, DisplayConnectionType* type) override;
81 ndk::ScopedAStatus getDisplayIdentificationData(
82 int64_t display, DisplayIdentification* id) override;
83 ndk::ScopedAStatus getDisplayName(int64_t display,
84 std::string* name) override;
85 ndk::ScopedAStatus getDisplayVsyncPeriod(int64_t display,
86 int32_t* vsync_period) override;
87 ndk::ScopedAStatus getDisplayedContentSample(
88 int64_t display, int64_t max_frames, int64_t timestamp,
89 DisplayContentSample* samples) override;
90 ndk::ScopedAStatus getDisplayedContentSamplingAttributes(
91 int64_t display, DisplayContentSamplingAttributes* attrs) override;
92 ndk::ScopedAStatus getDisplayPhysicalOrientation(
93 int64_t display, common::Transform* orientation) override;
94 ndk::ScopedAStatus getHdrCapabilities(int64_t display,
95 HdrCapabilities* caps) override;
96 ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override;
97 ndk::ScopedAStatus getPerFrameMetadataKeys(
98 int64_t display, std::vector<PerFrameMetadataKey>* keys) override;
99 ndk::ScopedAStatus getReadbackBufferAttributes(
100 int64_t display, ReadbackBufferAttributes* attrs) override;
101 ndk::ScopedAStatus getReadbackBufferFence(
102 int64_t display, ndk::ScopedFileDescriptor* acquire_fence) override;
103 ndk::ScopedAStatus getRenderIntents(
104 int64_t display, ColorMode mode,
105 std::vector<RenderIntent>* intents) override;
106 ndk::ScopedAStatus getSupportedContentTypes(
107 int64_t display, std::vector<ContentType>* types) override;
108 ndk::ScopedAStatus getDisplayDecorationSupport(
109 int64_t display,
110 std::optional<common::DisplayDecorationSupport>* support) override;
111 ndk::ScopedAStatus registerCallback(
112 const std::shared_ptr<IComposerCallback>& callback) override;
113 ndk::ScopedAStatus setActiveConfig(int64_t display, int32_t config) override;
114 ndk::ScopedAStatus setActiveConfigWithConstraints(
115 int64_t display, int32_t config,
116 const VsyncPeriodChangeConstraints& constraints,
117 VsyncPeriodChangeTimeline* timeline) override;
118 ndk::ScopedAStatus setBootDisplayConfig(int64_t display,
119 int32_t config) override;
120 ndk::ScopedAStatus clearBootDisplayConfig(int64_t display) override;
121 ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t display,
122 int32_t* config) override;
123 ndk::ScopedAStatus setAutoLowLatencyMode(int64_t display, bool on) override;
124 ndk::ScopedAStatus setClientTargetSlotCount(int64_t display,
125 int32_t count) override;
126 ndk::ScopedAStatus setColorMode(int64_t display, ColorMode mode,
127 RenderIntent intent) override;
128 ndk::ScopedAStatus setContentType(int64_t display, ContentType type) override;
129 ndk::ScopedAStatus setDisplayedContentSamplingEnabled(
130 int64_t display, bool enable, FormatColorComponent component_mask,
131 int64_t max_frames) override;
132 ndk::ScopedAStatus setPowerMode(int64_t display, PowerMode mode) override;
133 ndk::ScopedAStatus setReadbackBuffer(
134 int64_t display, const AidlNativeHandle& buffer,
135 const ndk::ScopedFileDescriptor& release_fence) override;
136 ndk::ScopedAStatus setVsyncEnabled(int64_t display, bool enabled) override;
137 ndk::ScopedAStatus setIdleTimerEnabled(int64_t display,
138 int32_t timeout) override;
139
140 protected:
141 ::ndk::SpAIBinder createBinder() override;
Drew Davenport5951b112024-08-05 09:44:27 -0600142
143 private:
144 // Layer commands
145 void DispatchLayerCommand(int64_t display_id, const LayerCommand& command);
146 void ExecuteSetLayerBuffer(int64_t display_id, HwcLayerWrapper& layer_id,
147 const Buffer& buffer);
148 void ExecuteSetLayerBlendMode(int64_t display_id, HwcLayerWrapper& layer,
149 const ParcelableBlendMode& blend_mode);
150 void ExecuteSetLayerComposition(int64_t display_id, HwcLayerWrapper& layer,
151 const ParcelableComposition& composition);
152 void ExecuteSetLayerDataspace(int64_t display_id, HwcLayerWrapper& layer,
153 const ParcelableDataspace& dataspace);
154 void ExecuteSetLayerDisplayFrame(int64_t display_id, HwcLayerWrapper& layer,
155 const common::Rect& rect);
156 void ExecuteSetLayerPlaneAlpha(int64_t display_id, HwcLayerWrapper& layer,
157 const PlaneAlpha& plane_alpha);
158 void ExecuteSetLayerSourceCrop(int64_t display_id, HwcLayerWrapper& layer,
159 const common::FRect& source_crop);
160 void ExecuteSetLayerTransform(int64_t display_id, HwcLayerWrapper& layer,
161 const ParcelableTransform& transform);
162 void ExecuteSetLayerZOrder(int64_t display_id, HwcLayerWrapper& layer,
163 const ZOrder& z_order);
164 void ExecuteSetLayerBrightness(int64_t display_id, HwcLayerWrapper& layer,
165 const LayerBrightness& brightness);
166
167 // Display commands
168 void ExecuteDisplayCommand(const DisplayCommand& command);
169 void ExecuteSetDisplayBrightness(uint64_t display_id,
170 const DisplayBrightness& command);
171 void ExecuteSetDisplayColorTransform(uint64_t display_id,
172 const std::vector<float>& matrix);
173 void ExecuteSetDisplayClientTarget(uint64_t display_id,
174 const ClientTarget& command);
175 void ExecuteSetDisplayOutputBuffer(uint64_t display_id, const Buffer& buffer);
176 void ExecuteValidateDisplay(
177 int64_t display_id,
178 std::optional<ClockMonotonicTimestamp> expected_present_time);
179 void ExecuteAcceptDisplayChanges(int64_t display_id);
180 void ExecutePresentDisplay(int64_t display_id);
181 void ExecutePresentOrValidateDisplay(
182 int64_t display_id,
183 std::optional<ClockMonotonicTimestamp> expected_present_time);
184
185 static hwc3::Error ValidateDisplayInternal(
186 ::android::HwcDisplay& display, std::vector<int64_t>* out_changed_layers,
187 std::vector<Composition>* out_composition_types,
188 int32_t* out_display_request_mask,
189 std::vector<int64_t>* out_requested_layers,
190 std::vector<int32_t>* out_request_masks,
191 ClientTargetProperty* out_client_target_property,
192 DimmingStage* out_dimming_stage);
193
194 hwc3::Error PresentDisplayInternal(
195 uint64_t display_id, ::android::base::unique_fd& out_display_fence,
196 std::unordered_map<int64_t, ::android::base::unique_fd>&
197 out_release_fences);
198
199 ::android::HwcDisplay* GetDisplay(uint64_t display_id);
200
201 std::unique_ptr<CommandResultWriter> cmd_result_writer_;
202
203 // Manages importing and caching gralloc buffers for displays and layers.
204 std::unique_ptr<ComposerResources> composer_resources_;
205
206 std::unique_ptr<DrmHwcThree> hwc_;
Dennis Tsiang33f0ece2023-11-29 12:45:04 +0000207};
208
209} // namespace aidl::android::hardware::graphics::composer3::impl