blob: 25dc0ca5066917b7b2c4f28b2e0614f7567d8b6e [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
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 {
Drew Davenport5951b112024-08-05 09:44:27 -060032class HwcDisplay;
Drew Davenport5951b112024-08-05 09:44:27 -060033} // namespace android
34
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000035namespace aidl::android::hardware::graphics::composer3::impl {
36
Drew Davenport5951b112024-08-05 09:44:27 -060037class DrmHwcThree;
38
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000039class ComposerClient : public BnComposerClient {
40 public:
Drew Davenport5951b112024-08-05 09:44:27 -060041 ComposerClient();
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000042 ~ComposerClient() override;
43
Roman Stratiienkoe501a972025-01-26 14:10:31 +020044 void Init();
Drew Davenport5951b112024-08-05 09:44:27 -060045 std::string Dump();
46
Dennis Tsiang33f0ece2023-11-29 12:45:04 +000047 // composer3 interface
48 ndk::ScopedAStatus createLayer(int64_t display, int32_t buffer_slot_count,
49 int64_t* layer) override;
50 ndk::ScopedAStatus createVirtualDisplay(int32_t width, int32_t height,
51 AidlPixelFormat format_hint,
52 int32_t output_buffer_slot_count,
53 VirtualDisplay* display) override;
54 ndk::ScopedAStatus destroyLayer(int64_t display, int64_t layer) override;
55 ndk::ScopedAStatus destroyVirtualDisplay(int64_t display) override;
56 ndk::ScopedAStatus executeCommands(
57 const std::vector<DisplayCommand>& commands,
58 std::vector<CommandResultPayload>* results) override;
59 ndk::ScopedAStatus getActiveConfig(int64_t display, int32_t* config) override;
60 ndk::ScopedAStatus getColorModes(
61 int64_t display, std::vector<ColorMode>* color_modes) override;
62 ndk::ScopedAStatus getDataspaceSaturationMatrix(
63 common::Dataspace dataspace, std::vector<float>* matrix) override;
64 ndk::ScopedAStatus getDisplayAttribute(int64_t display, int32_t config,
65 DisplayAttribute attribute,
66 int32_t* value) override;
67 ndk::ScopedAStatus getDisplayCapabilities(
68 int64_t display, std::vector<DisplayCapability>* caps) override;
69 ndk::ScopedAStatus getDisplayConfigs(int64_t display,
70 std::vector<int32_t>* configs) override;
71 ndk::ScopedAStatus getDisplayConnectionType(
72 int64_t display, DisplayConnectionType* type) override;
73 ndk::ScopedAStatus getDisplayIdentificationData(
74 int64_t display, DisplayIdentification* id) override;
75 ndk::ScopedAStatus getDisplayName(int64_t display,
76 std::string* name) override;
77 ndk::ScopedAStatus getDisplayVsyncPeriod(int64_t display,
78 int32_t* vsync_period) override;
79 ndk::ScopedAStatus getDisplayedContentSample(
80 int64_t display, int64_t max_frames, int64_t timestamp,
81 DisplayContentSample* samples) override;
82 ndk::ScopedAStatus getDisplayedContentSamplingAttributes(
83 int64_t display, DisplayContentSamplingAttributes* attrs) override;
84 ndk::ScopedAStatus getDisplayPhysicalOrientation(
85 int64_t display, common::Transform* orientation) override;
86 ndk::ScopedAStatus getHdrCapabilities(int64_t display,
87 HdrCapabilities* caps) override;
88 ndk::ScopedAStatus getMaxVirtualDisplayCount(int32_t* count) override;
89 ndk::ScopedAStatus getPerFrameMetadataKeys(
90 int64_t display, std::vector<PerFrameMetadataKey>* keys) override;
91 ndk::ScopedAStatus getReadbackBufferAttributes(
92 int64_t display, ReadbackBufferAttributes* attrs) override;
93 ndk::ScopedAStatus getReadbackBufferFence(
94 int64_t display, ndk::ScopedFileDescriptor* acquire_fence) override;
95 ndk::ScopedAStatus getRenderIntents(
96 int64_t display, ColorMode mode,
97 std::vector<RenderIntent>* intents) override;
98 ndk::ScopedAStatus getSupportedContentTypes(
99 int64_t display, std::vector<ContentType>* types) override;
100 ndk::ScopedAStatus getDisplayDecorationSupport(
101 int64_t display,
102 std::optional<common::DisplayDecorationSupport>* support) override;
103 ndk::ScopedAStatus registerCallback(
104 const std::shared_ptr<IComposerCallback>& callback) override;
105 ndk::ScopedAStatus setActiveConfig(int64_t display, int32_t config) override;
106 ndk::ScopedAStatus setActiveConfigWithConstraints(
107 int64_t display, int32_t config,
108 const VsyncPeriodChangeConstraints& constraints,
109 VsyncPeriodChangeTimeline* timeline) override;
110 ndk::ScopedAStatus setBootDisplayConfig(int64_t display,
111 int32_t config) override;
112 ndk::ScopedAStatus clearBootDisplayConfig(int64_t display) override;
113 ndk::ScopedAStatus getPreferredBootDisplayConfig(int64_t display,
114 int32_t* config) override;
115 ndk::ScopedAStatus setAutoLowLatencyMode(int64_t display, bool on) override;
116 ndk::ScopedAStatus setClientTargetSlotCount(int64_t display,
117 int32_t count) override;
118 ndk::ScopedAStatus setColorMode(int64_t display, ColorMode mode,
119 RenderIntent intent) override;
120 ndk::ScopedAStatus setContentType(int64_t display, ContentType type) override;
121 ndk::ScopedAStatus setDisplayedContentSamplingEnabled(
122 int64_t display, bool enable, FormatColorComponent component_mask,
123 int64_t max_frames) override;
124 ndk::ScopedAStatus setPowerMode(int64_t display, PowerMode mode) override;
125 ndk::ScopedAStatus setReadbackBuffer(
126 int64_t display, const AidlNativeHandle& buffer,
127 const ndk::ScopedFileDescriptor& release_fence) override;
128 ndk::ScopedAStatus setVsyncEnabled(int64_t display, bool enabled) override;
129 ndk::ScopedAStatus setIdleTimerEnabled(int64_t display,
130 int32_t timeout) override;
Roman Stratiienko445ef202024-11-27 00:24:48 +0200131
132#if __ANDROID_API__ >= 34
133
Drew Davenport7f1761b2024-08-20 10:09:43 -0600134 ndk::ScopedAStatus getOverlaySupport(
135 OverlayProperties* out_overlay_properties) override;
136 ndk::ScopedAStatus getHdrConversionCapabilities(
137 std::vector<common::HdrConversionCapability>* out_capabilities) override;
138 ndk::ScopedAStatus setHdrConversionStrategy(
139 const common::HdrConversionStrategy& conversion_strategy,
140 common::Hdr* out_hdr) override;
141 ndk::ScopedAStatus setRefreshRateChangedCallbackDebugEnabled(
142 int64_t display, bool enabled) override;
Roman Stratiienko71a8f022024-10-16 23:17:33 +0300143
Roman Stratiienko445ef202024-11-27 00:24:48 +0200144#endif
145
Roman Stratiienko71a8f022024-10-16 23:17:33 +0300146#if __ANDROID_API__ >= 35
147
Drew Davenport7f1761b2024-08-20 10:09:43 -0600148 ndk::ScopedAStatus getDisplayConfigurations(
149 int64_t display, int32_t max_frame_interval_ns,
150 std::vector<DisplayConfiguration>* configurations) override;
151 ndk::ScopedAStatus notifyExpectedPresent(
152 int64_t display, const ClockMonotonicTimestamp& expected_present_time,
153 int32_t frame_interval_ns) override;
Dennis Tsiang33f0ece2023-11-29 12:45:04 +0000154
Roman Stratiienko71a8f022024-10-16 23:17:33 +0300155#endif
156
Dennis Tsiang33f0ece2023-11-29 12:45:04 +0000157 protected:
158 ::ndk::SpAIBinder createBinder() override;
Drew Davenport5951b112024-08-05 09:44:27 -0600159
160 private:
Drew Davenporte5fbbbb2024-10-14 15:49:27 -0600161 hwc3::Error ImportLayerBuffer(int64_t display_id, int64_t layer_id,
162 const Buffer& buffer,
Drew Davenport14022a32025-01-15 20:12:51 -0700163 ::android::HwcLayer::Buffer* out_buffer);
Drew Davenporte5fbbbb2024-10-14 15:49:27 -0600164
Drew Davenport5951b112024-08-05 09:44:27 -0600165 // Layer commands
166 void DispatchLayerCommand(int64_t display_id, const LayerCommand& command);
Drew Davenport5951b112024-08-05 09:44:27 -0600167
168 // Display commands
169 void ExecuteDisplayCommand(const DisplayCommand& command);
Drew Davenport5951b112024-08-05 09:44:27 -0600170 void ExecuteSetDisplayClientTarget(uint64_t display_id,
171 const ClientTarget& command);
172 void ExecuteSetDisplayOutputBuffer(uint64_t display_id, const Buffer& buffer);
Drew Davenport5951b112024-08-05 09:44:27 -0600173
174 ::android::HwcDisplay* GetDisplay(uint64_t display_id);
175
176 std::unique_ptr<CommandResultWriter> cmd_result_writer_;
177
Drew Davenport5951b112024-08-05 09:44:27 -0600178 std::unique_ptr<DrmHwcThree> hwc_;
Dennis Tsiang33f0ece2023-11-29 12:45:04 +0000179};
180
181} // namespace aidl::android::hardware::graphics::composer3::impl