blob: ed47cd6260a7a11399624c799683fc1510d7a827 [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"
Drew Davenport14022a32025-01-15 20:12:51 -070023#include "hwc2_device/HwcLayer.h"
Drew Davenport5951b112024-08-05 09:44:27 -060024#include "hwc3/CommandResultWriter.h"
Drew Davenport5951b112024-08-05 09:44:27 -060025#include "hwc3/Utils.h"
26#include "utils/Mutex.h"
27
Huihong Luo012271d2024-10-30 13:19:10 -070028using AidlHdcpLevels = aidl::android::hardware::drm::HdcpLevels;
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000029using AidlPixelFormat = aidl::android::hardware::graphics::common::PixelFormat;
30using AidlNativeHandle = aidl::android::hardware::common::NativeHandle;
31
Drew Davenport5951b112024-08-05 09:44:27 -060032namespace android {
Drew Davenport5951b112024-08-05 09:44:27 -060033class HwcDisplay;
Drew Davenport5951b112024-08-05 09:44:27 -060034} // namespace android
35
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000036namespace aidl::android::hardware::graphics::composer3::impl {
37
Drew Davenport5951b112024-08-05 09:44:27 -060038class DrmHwcThree;
39
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000040class ComposerClient : public BnComposerClient {
41 public:
Drew Davenport5951b112024-08-05 09:44:27 -060042 ComposerClient();
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000043 ~ComposerClient() override;
44
Roman Stratiienkoe501a972025-01-26 14:10:31 +020045 void Init();
Drew Davenport5951b112024-08-05 09:44:27 -060046 std::string Dump();
47
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000048 // composer3 interface
49 ndk::ScopedAStatus createLayer(int64_t display, int32_t buffer_slot_count,
50 int64_t* layer) override;
51 ndk::ScopedAStatus createVirtualDisplay(int32_t width, int32_t height,
52 AidlPixelFormat format_hint,
53 int32_t output_buffer_slot_count,
54 VirtualDisplay* display) override;
55 ndk::ScopedAStatus destroyLayer(int64_t display, int64_t layer) override;
56 ndk::ScopedAStatus destroyVirtualDisplay(int64_t display) override;
57 ndk::ScopedAStatus executeCommands(
58 const std::vector<DisplayCommand>& commands,
59 std::vector<CommandResultPayload>* results) override;
60 ndk::ScopedAStatus getActiveConfig(int64_t display, int32_t* config) override;
61 ndk::ScopedAStatus getColorModes(
62 int64_t display, std::vector<ColorMode>* color_modes) override;
63 ndk::ScopedAStatus getDataspaceSaturationMatrix(
64 common::Dataspace dataspace, std::vector<float>* matrix) override;
65 ndk::ScopedAStatus getDisplayAttribute(int64_t display, int32_t config,
66 DisplayAttribute attribute,
67 int32_t* value) override;
68 ndk::ScopedAStatus getDisplayCapabilities(
69 int64_t display, std::vector<DisplayCapability>* caps) override;
70 ndk::ScopedAStatus getDisplayConfigs(int64_t display,
71 std::vector<int32_t>* configs) override;
72 ndk::ScopedAStatus getDisplayConnectionType(
73 int64_t display, DisplayConnectionType* type) override;
74 ndk::ScopedAStatus getDisplayIdentificationData(
75 int64_t display, DisplayIdentification* id) override;
76 ndk::ScopedAStatus getDisplayName(int64_t display,
77 std::string* name) override;
78 ndk::ScopedAStatus getDisplayVsyncPeriod(int64_t display,
79 int32_t* vsync_period) override;
80 ndk::ScopedAStatus getDisplayedContentSample(
81 int64_t display, int64_t max_frames, int64_t timestamp,
82 DisplayContentSample* samples) override;
83 ndk::ScopedAStatus getDisplayedContentSamplingAttributes(
84 int64_t display, DisplayContentSamplingAttributes* attrs) override;
85 ndk::ScopedAStatus getDisplayPhysicalOrientation(
86 int64_t display, common::Transform* orientation) override;
87 ndk::ScopedAStatus getHdrCapabilities(int64_t display,
88 HdrCapabilities* caps) override;
89 ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override;
90 ndk::ScopedAStatus getPerFrameMetadataKeys(
91 int64_t display, std::vector<PerFrameMetadataKey>* keys) override;
92 ndk::ScopedAStatus getReadbackBufferAttributes(
93 int64_t display, ReadbackBufferAttributes* attrs) override;
94 ndk::ScopedAStatus getReadbackBufferFence(
95 int64_t display, ndk::ScopedFileDescriptor* acquire_fence) override;
96 ndk::ScopedAStatus getRenderIntents(
97 int64_t display, ColorMode mode,
98 std::vector<RenderIntent>* intents) override;
99 ndk::ScopedAStatus getSupportedContentTypes(
100 int64_t display, std::vector<ContentType>* types) override;
101 ndk::ScopedAStatus getDisplayDecorationSupport(
102 int64_t display,
103 std::optional<common::DisplayDecorationSupport>* support) override;
104 ndk::ScopedAStatus registerCallback(
105 const std::shared_ptr<IComposerCallback>& callback) override;
106 ndk::ScopedAStatus setActiveConfig(int64_t display, int32_t config) override;
107 ndk::ScopedAStatus setActiveConfigWithConstraints(
108 int64_t display, int32_t config,
109 const VsyncPeriodChangeConstraints& constraints,
110 VsyncPeriodChangeTimeline* timeline) override;
111 ndk::ScopedAStatus setBootDisplayConfig(int64_t display,
112 int32_t config) override;
113 ndk::ScopedAStatus clearBootDisplayConfig(int64_t display) override;
114 ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t display,
115 int32_t* config) override;
116 ndk::ScopedAStatus setAutoLowLatencyMode(int64_t display, bool on) override;
117 ndk::ScopedAStatus setClientTargetSlotCount(int64_t display,
118 int32_t count) override;
119 ndk::ScopedAStatus setColorMode(int64_t display, ColorMode mode,
120 RenderIntent intent) override;
121 ndk::ScopedAStatus setContentType(int64_t display, ContentType type) override;
122 ndk::ScopedAStatus setDisplayedContentSamplingEnabled(
123 int64_t display, bool enable, FormatColorComponent component_mask,
124 int64_t max_frames) override;
125 ndk::ScopedAStatus setPowerMode(int64_t display, PowerMode mode) override;
126 ndk::ScopedAStatus setReadbackBuffer(
127 int64_t display, const AidlNativeHandle& buffer,
128 const ndk::ScopedFileDescriptor& release_fence) override;
129 ndk::ScopedAStatus setVsyncEnabled(int64_t display, bool enabled) override;
130 ndk::ScopedAStatus setIdleTimerEnabled(int64_t display,
131 int32_t timeout) override;
Roman Stratiienko445ef202024-11-27 00:24:48 +0200132
133#if __ANDROID_API__ >= 34
134
Drew Davenport7f1761b2024-08-20 10:09:43 -0600135 ndk::ScopedAStatus getOverlaySupport(
136 OverlayProperties* out_overlay_properties) override;
137 ndk::ScopedAStatus getHdrConversionCapabilities(
138 std::vector<common::HdrConversionCapability>* out_capabilities) override;
139 ndk::ScopedAStatus setHdrConversionStrategy(
140 const common::HdrConversionStrategy& conversion_strategy,
141 common::Hdr* out_hdr) override;
142 ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(
143 int64_t display, bool enabled) override;
Roman Stratiienko71a8f022024-10-16 23:17:33 +0300144
Roman Stratiienko445ef202024-11-27 00:24:48 +0200145#endif
146
Roman Stratiienko71a8f022024-10-16 23:17:33 +0300147#if __ANDROID_API__ >= 35
148
Drew Davenport7f1761b2024-08-20 10:09:43 -0600149 ndk::ScopedAStatus getDisplayConfigurations(
150 int64_t display, int32_t max_frame_interval_ns,
151 std::vector<DisplayConfiguration>* configurations) override;
152 ndk::ScopedAStatus notifyExpectedPresent(
153 int64_t display, const ClockMonotonicTimestamp& expected_present_time,
154 int32_t frame_interval_ns) override;
Huihong Luo012271d2024-10-30 13:19:10 -0700155 ndk::ScopedAStatus startHdcpNegotiation(int64_t display,
156 const AidlHdcpLevels& levels) override;
Dennis Tsiang33f0ece2023-11-29 12:45:04 +0000157
Roman Stratiienko71a8f022024-10-16 23:17:33 +0300158#endif
159
Brian Lindahle1d49f12024-10-31 08:56:11 -0600160 ndk::ScopedAStatus getMaxLayerPictureProfiles(
161 int64_t display, int32_t* maxProfiles) override;
Sally Qie39af972024-11-21 23:37:58 -0800162 ndk::ScopedAStatus getLuts(int64_t, const std::vector<Buffer>&,
163 std::vector<Luts>* out_luts) override;
Brian Lindahle1d49f12024-10-31 08:56:11 -0600164
Dennis Tsiang33f0ece2023-11-29 12:45:04 +0000165 protected:
166 ::ndk::SpAIBinder createBinder() override;
Drew Davenport5951b112024-08-05 09:44:27 -0600167
168 private:
Drew Davenporte5fbbbb2024-10-14 15:49:27 -0600169 hwc3::Error ImportLayerBuffer(int64_t display_id, int64_t layer_id,
170 const Buffer& buffer,
Drew Davenport14022a32025-01-15 20:12:51 -0700171 ::android::HwcLayer::Buffer* out_buffer);
Drew Davenporte5fbbbb2024-10-14 15:49:27 -0600172
Drew Davenport5951b112024-08-05 09:44:27 -0600173 // Layer commands
174 void DispatchLayerCommand(int64_t display_id, const LayerCommand& command);
Drew Davenport5951b112024-08-05 09:44:27 -0600175
176 // Display commands
177 void ExecuteDisplayCommand(const DisplayCommand& command);
Drew Davenport5951b112024-08-05 09:44:27 -0600178 void ExecuteSetDisplayClientTarget(uint64_t display_id,
179 const ClientTarget& command);
180 void ExecuteSetDisplayOutputBuffer(uint64_t display_id, const Buffer& buffer);
Drew Davenport5951b112024-08-05 09:44:27 -0600181
182 ::android::HwcDisplay* GetDisplay(uint64_t display_id);
183
184 std::unique_ptr<CommandResultWriter> cmd_result_writer_;
185
Drew Davenport5951b112024-08-05 09:44:27 -0600186 std::unique_ptr<DrmHwcThree> hwc_;
Dennis Tsiang33f0ece2023-11-29 12:45:04 +0000187};
188
189} // namespace aidl::android::hardware::graphics::composer3::impl