blob: 98f2f9d387656662dc6cc81634ee81573dd3b17c [file] [log] [blame]
Chia-I Wuaab99f52016-10-05 12:59:58 +08001/*
2 * Copyright 2016 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
17#ifndef ANDROID_SF_COMPOSER_HAL_H
18#define ANDROID_SF_COMPOSER_HAL_H
19
Chia-I Wucd8d7f02016-11-16 11:02:31 +080020#include <memory>
Chia-I Wuaab99f52016-10-05 12:59:58 +080021#include <string>
Chia-I Wucd8d7f02016-11-16 11:02:31 +080022#include <unordered_map>
23#include <utility>
Chia-I Wuaab99f52016-10-05 12:59:58 +080024#include <vector>
25
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -040026#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
Peiyong Lin34beb7a2018-03-28 11:57:12 -070027#include <android/hardware/graphics/common/1.1/types.h>
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070028#include <android/hardware/graphics/composer/2.2/IComposer.h>
29#include <android/hardware/graphics/composer/2.2/IComposerClient.h>
30#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
31#include <gui/HdrMetadata.h>
Lloyd Piqued0094aa2017-12-20 16:43:28 -080032#include <ui/GraphicBuffer.h>
Chia-I Wuaab99f52016-10-05 12:59:58 +080033#include <utils/StrongPointer.h>
34
35namespace android {
36
37namespace Hwc2 {
38
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -040039using android::frameworks::vr::composer::V1_0::IVrComposerClient;
40
Chia-I Wu5901fda2016-11-17 10:26:37 +080041using android::hardware::graphics::common::V1_0::ColorMode;
42using android::hardware::graphics::common::V1_0::ColorTransform;
Chia-I Wu5901fda2016-11-17 10:26:37 +080043using android::hardware::graphics::common::V1_0::Hdr;
Chia-I Wu5901fda2016-11-17 10:26:37 +080044using android::hardware::graphics::common::V1_0::Transform;
Peiyong Lin34beb7a2018-03-28 11:57:12 -070045using android::hardware::graphics::common::V1_1::Dataspace;
46using android::hardware::graphics::common::V1_1::PixelFormat;
Chia-I Wuaab99f52016-10-05 12:59:58 +080047
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070048using android::hardware::graphics::composer::V2_1::Config;
49using android::hardware::graphics::composer::V2_1::Display;
50using android::hardware::graphics::composer::V2_1::Error;
Chia-I Wuaab99f52016-10-05 12:59:58 +080051using android::hardware::graphics::composer::V2_1::IComposer;
52using android::hardware::graphics::composer::V2_1::IComposerCallback;
Chia-I Wuaab99f52016-10-05 12:59:58 +080053using android::hardware::graphics::composer::V2_1::Layer;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070054using android::hardware::graphics::composer::V2_2::IComposerClient;
Chia-I Wuaab99f52016-10-05 12:59:58 +080055
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -070056using android::hardware::graphics::composer::V2_2::CommandReaderBase;
57using android::hardware::graphics::composer::V2_2::CommandWriterBase;
Chia-I Wucd8d7f02016-11-16 11:02:31 +080058
59using android::hardware::kSynchronizedReadWrite;
60using android::hardware::MessageQueue;
61using android::hardware::MQDescriptorSync;
62using android::hardware::hidl_vec;
63using android::hardware::hidl_handle;
64
Lloyd Piquea822d522017-12-20 16:42:57 -080065class Composer {
66public:
67 virtual ~Composer() = 0;
68
69 virtual std::vector<IComposer::Capability> getCapabilities() = 0;
70 virtual std::string dumpDebugInfo() = 0;
71
72 virtual void registerCallback(const sp<IComposerCallback>& callback) = 0;
73
74 // Returns true if the connected composer service is running in a remote
75 // process, false otherwise. This will return false if the service is
76 // configured in passthrough mode, for example.
77 virtual bool isRemote() = 0;
78
79 // Reset all pending commands in the command buffer. Useful if you want to
80 // skip a frame but have already queued some commands.
81 virtual void resetCommands() = 0;
82
83 // Explicitly flush all pending commands in the command buffer.
84 virtual Error executeCommands() = 0;
85
86 virtual uint32_t getMaxVirtualDisplayCount() = 0;
87 virtual bool isUsingVrComposer() const = 0;
88 virtual Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
89 Display* outDisplay) = 0;
90 virtual Error destroyVirtualDisplay(Display display) = 0;
91
92 virtual Error acceptDisplayChanges(Display display) = 0;
93
94 virtual Error createLayer(Display display, Layer* outLayer) = 0;
95 virtual Error destroyLayer(Display display, Layer layer) = 0;
96
97 virtual Error getActiveConfig(Display display, Config* outConfig) = 0;
98 virtual Error getChangedCompositionTypes(
99 Display display, std::vector<Layer>* outLayers,
100 std::vector<IComposerClient::Composition>* outTypes) = 0;
101 virtual Error getColorModes(Display display, std::vector<ColorMode>* outModes) = 0;
102 virtual Error getDisplayAttribute(Display display, Config config,
103 IComposerClient::Attribute attribute, int32_t* outValue) = 0;
104 virtual Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs) = 0;
105 virtual Error getDisplayName(Display display, std::string* outName) = 0;
106
107 virtual Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
108 std::vector<Layer>* outLayers,
109 std::vector<uint32_t>* outLayerRequestMasks) = 0;
110
111 virtual Error getDisplayType(Display display, IComposerClient::DisplayType* outType) = 0;
112 virtual Error getDozeSupport(Display display, bool* outSupport) = 0;
113 virtual Error getHdrCapabilities(Display display, std::vector<Hdr>* outTypes,
114 float* outMaxLuminance, float* outMaxAverageLuminance,
115 float* outMinLuminance) = 0;
116
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700117 virtual Error getPerFrameMetadataKeys(
118 Display display, std::vector<IComposerClient::PerFrameMetadataKey>* outKeys) = 0;
119
Lloyd Piquea822d522017-12-20 16:42:57 -0800120 virtual Error getReleaseFences(Display display, std::vector<Layer>* outLayers,
121 std::vector<int>* outReleaseFences) = 0;
122
123 virtual Error presentDisplay(Display display, int* outPresentFence) = 0;
124
125 virtual Error setActiveConfig(Display display, Config config) = 0;
126
127 /*
128 * The composer caches client targets internally. When target is nullptr,
129 * the composer uses slot to look up the client target from its cache.
130 * When target is not nullptr, the cache is updated with the new target.
131 */
132 virtual Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
133 int acquireFence, Dataspace dataspace,
134 const std::vector<IComposerClient::Rect>& damage) = 0;
135 virtual Error setColorMode(Display display, ColorMode mode) = 0;
136 virtual Error setColorTransform(Display display, const float* matrix, ColorTransform hint) = 0;
137 virtual Error setOutputBuffer(Display display, const native_handle_t* buffer,
138 int releaseFence) = 0;
139 virtual Error setPowerMode(Display display, IComposerClient::PowerMode mode) = 0;
140 virtual Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) = 0;
141
142 virtual Error setClientTargetSlotCount(Display display) = 0;
143
144 virtual Error validateDisplay(Display display, uint32_t* outNumTypes,
145 uint32_t* outNumRequests) = 0;
146
147 virtual Error presentOrValidateDisplay(Display display, uint32_t* outNumTypes,
148 uint32_t* outNumRequests, int* outPresentFence,
149 uint32_t* state) = 0;
150
151 virtual Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) = 0;
152 /* see setClientTarget for the purpose of slot */
153 virtual Error setLayerBuffer(Display display, Layer layer, uint32_t slot,
154 const sp<GraphicBuffer>& buffer, int acquireFence) = 0;
155 virtual Error setLayerSurfaceDamage(Display display, Layer layer,
156 const std::vector<IComposerClient::Rect>& damage) = 0;
157 virtual Error setLayerBlendMode(Display display, Layer layer,
158 IComposerClient::BlendMode mode) = 0;
159 virtual Error setLayerColor(Display display, Layer layer,
160 const IComposerClient::Color& color) = 0;
161 virtual Error setLayerCompositionType(Display display, Layer layer,
162 IComposerClient::Composition type) = 0;
163 virtual Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) = 0;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700164 virtual Error setLayerHdrMetadata(Display display, Layer layer,
165 const HdrMetadata& metadata) = 0;
Lloyd Piquea822d522017-12-20 16:42:57 -0800166 virtual Error setLayerDisplayFrame(Display display, Layer layer,
167 const IComposerClient::Rect& frame) = 0;
168 virtual Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) = 0;
169 virtual Error setLayerSidebandStream(Display display, Layer layer,
170 const native_handle_t* stream) = 0;
171 virtual Error setLayerSourceCrop(Display display, Layer layer,
172 const IComposerClient::FRect& crop) = 0;
173 virtual Error setLayerTransform(Display display, Layer layer, Transform transform) = 0;
174 virtual Error setLayerVisibleRegion(Display display, Layer layer,
175 const std::vector<IComposerClient::Rect>& visible) = 0;
176 virtual Error setLayerZOrder(Display display, Layer layer, uint32_t z) = 0;
177 virtual Error setLayerInfo(Display display, Layer layer, uint32_t type, uint32_t appId) = 0;
178};
179
180namespace impl {
181
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800182class CommandReader : public CommandReaderBase {
183public:
184 ~CommandReader();
185
186 // Parse and execute commands from the command queue. The commands are
187 // actually return values from the server and will be saved in ReturnData.
188 Error parse();
189
190 // Get and clear saved errors.
191 struct CommandError {
192 uint32_t location;
193 Error error;
194 };
195 std::vector<CommandError> takeErrors();
196
Chia-I Wu67e376d2016-12-19 11:36:22 +0800197 bool hasChanges(Display display, uint32_t* outNumChangedCompositionTypes,
198 uint32_t* outNumLayerRequestMasks) const;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800199
200 // Get and clear saved changed composition types.
201 void takeChangedCompositionTypes(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800202 std::vector<Layer>* outLayers,
203 std::vector<IComposerClient::Composition>* outTypes);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800204
205 // Get and clear saved display requests.
206 void takeDisplayRequests(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800207 uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers,
208 std::vector<uint32_t>* outLayerRequestMasks);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800209
210 // Get and clear saved release fences.
Chia-I Wu67e376d2016-12-19 11:36:22 +0800211 void takeReleaseFences(Display display, std::vector<Layer>* outLayers,
212 std::vector<int>* outReleaseFences);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800213
214 // Get and clear saved present fence.
Chia-I Wu67e376d2016-12-19 11:36:22 +0800215 void takePresentFence(Display display, int* outPresentFence);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800216
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700217 // Get what stage succeeded during PresentOrValidate: Present or Validate
218 void takePresentOrValidateStage(Display display, uint32_t * state);
219
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800220private:
221 void resetData();
222
223 bool parseSelectDisplay(uint16_t length);
224 bool parseSetError(uint16_t length);
225 bool parseSetChangedCompositionTypes(uint16_t length);
226 bool parseSetDisplayRequests(uint16_t length);
227 bool parseSetPresentFence(uint16_t length);
228 bool parseSetReleaseFences(uint16_t length);
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700229 bool parseSetPresentOrValidateDisplayResult(uint16_t length);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800230
231 struct ReturnData {
232 uint32_t displayRequests = 0;
233
234 std::vector<Layer> changedLayers;
235 std::vector<IComposerClient::Composition> compositionTypes;
236
237 std::vector<Layer> requestedLayers;
238 std::vector<uint32_t> requestMasks;
239
240 int presentFence = -1;
241
242 std::vector<Layer> releasedLayers;
243 std::vector<int> releaseFences;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700244
245 uint32_t presentOrValidateState;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800246 };
247
248 std::vector<CommandError> mErrors;
249 std::unordered_map<Display, ReturnData> mReturnData;
250
251 // When SELECT_DISPLAY is parsed, this is updated to point to the
252 // display's return data in mReturnData. We use it to avoid repeated
253 // map lookups.
254 ReturnData* mCurrentReturnData;
255};
256
Chia-I Wuaab99f52016-10-05 12:59:58 +0800257// Composer is a wrapper to IComposer, a proxy to server-side composer.
Lloyd Piquea822d522017-12-20 16:42:57 -0800258class Composer final : public Hwc2::Composer {
Chia-I Wuaab99f52016-10-05 12:59:58 +0800259public:
Kalle Raitaa099a242017-01-11 11:17:29 -0800260 Composer(const std::string& serviceName);
Lloyd Piquea822d522017-12-20 16:42:57 -0800261 ~Composer() override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800262
Lloyd Piquea822d522017-12-20 16:42:57 -0800263 std::vector<IComposer::Capability> getCapabilities() override;
264 std::string dumpDebugInfo() override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800265
Lloyd Piquea822d522017-12-20 16:42:57 -0800266 void registerCallback(const sp<IComposerCallback>& callback) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800267
Steven Thomas94e35b92017-07-26 18:48:28 -0700268 // Returns true if the connected composer service is running in a remote
269 // process, false otherwise. This will return false if the service is
270 // configured in passthrough mode, for example.
Lloyd Piquea822d522017-12-20 16:42:57 -0800271 bool isRemote() override;
Steven Thomas94e35b92017-07-26 18:48:28 -0700272
Steven Thomas0af4b9f2017-04-26 14:34:01 -0700273 // Reset all pending commands in the command buffer. Useful if you want to
274 // skip a frame but have already queued some commands.
Lloyd Piquea822d522017-12-20 16:42:57 -0800275 void resetCommands() override;
Steven Thomas0af4b9f2017-04-26 14:34:01 -0700276
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700277 // Explicitly flush all pending commands in the command buffer.
Lloyd Piquea822d522017-12-20 16:42:57 -0800278 Error executeCommands() override;
Chia-I Wuae5a6b82017-10-10 09:09:22 -0700279
Lloyd Piquea822d522017-12-20 16:42:57 -0800280 uint32_t getMaxVirtualDisplayCount() override;
281 bool isUsingVrComposer() const override { return mIsUsingVrComposer; }
282 Error createVirtualDisplay(uint32_t width, uint32_t height, PixelFormat* format,
283 Display* outDisplay) override;
284 Error destroyVirtualDisplay(Display display) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800285
Lloyd Piquea822d522017-12-20 16:42:57 -0800286 Error acceptDisplayChanges(Display display) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800287
Lloyd Piquea822d522017-12-20 16:42:57 -0800288 Error createLayer(Display display, Layer* outLayer) override;
289 Error destroyLayer(Display display, Layer layer) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800290
Lloyd Piquea822d522017-12-20 16:42:57 -0800291 Error getActiveConfig(Display display, Config* outConfig) override;
292 Error getChangedCompositionTypes(Display display, std::vector<Layer>* outLayers,
293 std::vector<IComposerClient::Composition>* outTypes) override;
294 Error getColorModes(Display display, std::vector<ColorMode>* outModes) override;
295 Error getDisplayAttribute(Display display, Config config, IComposerClient::Attribute attribute,
296 int32_t* outValue) override;
Chia-I Wu67e376d2016-12-19 11:36:22 +0800297 Error getDisplayConfigs(Display display, std::vector<Config>* outConfigs);
Lloyd Piquea822d522017-12-20 16:42:57 -0800298 Error getDisplayName(Display display, std::string* outName) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800299
Chia-I Wu67e376d2016-12-19 11:36:22 +0800300 Error getDisplayRequests(Display display, uint32_t* outDisplayRequestMask,
Lloyd Piquea822d522017-12-20 16:42:57 -0800301 std::vector<Layer>* outLayers,
302 std::vector<uint32_t>* outLayerRequestMasks) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800303
Lloyd Piquea822d522017-12-20 16:42:57 -0800304 Error getDisplayType(Display display, IComposerClient::DisplayType* outType) override;
305 Error getDozeSupport(Display display, bool* outSupport) override;
306 Error getHdrCapabilities(Display display, std::vector<Hdr>* outTypes, float* outMaxLuminance,
307 float* outMaxAverageLuminance, float* outMinLuminance) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800308
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700309 Error getPerFrameMetadataKeys(
310 Display display, std::vector<IComposerClient::PerFrameMetadataKey>* outKeys) override;
311
Chia-I Wu67e376d2016-12-19 11:36:22 +0800312 Error getReleaseFences(Display display, std::vector<Layer>* outLayers,
Lloyd Piquea822d522017-12-20 16:42:57 -0800313 std::vector<int>* outReleaseFences) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800314
Lloyd Piquea822d522017-12-20 16:42:57 -0800315 Error presentDisplay(Display display, int* outPresentFence) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800316
Lloyd Piquea822d522017-12-20 16:42:57 -0800317 Error setActiveConfig(Display display, Config config) override;
Chia-I Wu06d63de2017-01-04 14:58:51 +0800318
319 /*
320 * The composer caches client targets internally. When target is nullptr,
321 * the composer uses slot to look up the client target from its cache.
322 * When target is not nullptr, the cache is updated with the new target.
323 */
Lloyd Piquea822d522017-12-20 16:42:57 -0800324 Error setClientTarget(Display display, uint32_t slot, const sp<GraphicBuffer>& target,
325 int acquireFence, Dataspace dataspace,
326 const std::vector<IComposerClient::Rect>& damage) override;
327 Error setColorMode(Display display, ColorMode mode) override;
328 Error setColorTransform(Display display, const float* matrix, ColorTransform hint) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800329 Error setOutputBuffer(Display display, const native_handle_t* buffer,
Lloyd Piquea822d522017-12-20 16:42:57 -0800330 int releaseFence) override;
331 Error setPowerMode(Display display, IComposerClient::PowerMode mode) override;
332 Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) override;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800333
Lloyd Piquea822d522017-12-20 16:42:57 -0800334 Error setClientTargetSlotCount(Display display) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800335
Chia-I Wu67e376d2016-12-19 11:36:22 +0800336 Error validateDisplay(Display display, uint32_t* outNumTypes,
Lloyd Piquea822d522017-12-20 16:42:57 -0800337 uint32_t* outNumRequests) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800338
Lloyd Piquea822d522017-12-20 16:42:57 -0800339 Error presentOrValidateDisplay(Display display, uint32_t* outNumTypes, uint32_t* outNumRequests,
340 int* outPresentFence, uint32_t* state) override;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700341
Lloyd Piquea822d522017-12-20 16:42:57 -0800342 Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) override;
Chia-I Wu06d63de2017-01-04 14:58:51 +0800343 /* see setClientTarget for the purpose of slot */
344 Error setLayerBuffer(Display display, Layer layer, uint32_t slot,
Lloyd Piquea822d522017-12-20 16:42:57 -0800345 const sp<GraphicBuffer>& buffer, int acquireFence) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800346 Error setLayerSurfaceDamage(Display display, Layer layer,
Lloyd Piquea822d522017-12-20 16:42:57 -0800347 const std::vector<IComposerClient::Rect>& damage) override;
348 Error setLayerBlendMode(Display display, Layer layer, IComposerClient::BlendMode mode) override;
349 Error setLayerColor(Display display, Layer layer, const IComposerClient::Color& color) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800350 Error setLayerCompositionType(Display display, Layer layer,
Lloyd Piquea822d522017-12-20 16:42:57 -0800351 IComposerClient::Composition type) override;
352 Error setLayerDataspace(Display display, Layer layer, Dataspace dataspace) override;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700353 Error setLayerHdrMetadata(Display display, Layer layer, const HdrMetadata& metadata) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800354 Error setLayerDisplayFrame(Display display, Layer layer,
Lloyd Piquea822d522017-12-20 16:42:57 -0800355 const IComposerClient::Rect& frame) override;
356 Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800357 Error setLayerSidebandStream(Display display, Layer layer,
Lloyd Piquea822d522017-12-20 16:42:57 -0800358 const native_handle_t* stream) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800359 Error setLayerSourceCrop(Display display, Layer layer,
Lloyd Piquea822d522017-12-20 16:42:57 -0800360 const IComposerClient::FRect& crop) override;
361 Error setLayerTransform(Display display, Layer layer, Transform transform) override;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800362 Error setLayerVisibleRegion(Display display, Layer layer,
Lloyd Piquea822d522017-12-20 16:42:57 -0800363 const std::vector<IComposerClient::Rect>& visible) override;
364 Error setLayerZOrder(Display display, Layer layer, uint32_t z) override;
365 Error setLayerInfo(Display display, Layer layer, uint32_t type, uint32_t appId) override;
366
Chia-I Wuaab99f52016-10-05 12:59:58 +0800367private:
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500368 class CommandWriter : public CommandWriterBase {
369 public:
370 CommandWriter(uint32_t initialMaxSize);
371 ~CommandWriter() override;
372
373 void setLayerInfo(uint32_t type, uint32_t appId);
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400374 void setClientTargetMetadata(
375 const IVrComposerClient::BufferMetadata& metadata);
376 void setLayerBufferMetadata(
377 const IVrComposerClient::BufferMetadata& metadata);
378
379 private:
380 void writeBufferMetadata(
381 const IVrComposerClient::BufferMetadata& metadata);
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500382 };
383
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800384 // Many public functions above simply write a command into the command
385 // queue to batch the calls. validateDisplay and presentDisplay will call
386 // this function to execute the command queue.
387 Error execute();
388
389 sp<IComposer> mComposer;
Courtney Goeltzenleuchterf9c98e52018-02-12 07:23:17 -0700390 sp<hardware::graphics::composer::V2_1::IComposerClient> mClient;
391 sp<IComposerClient> mClient_2_2;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800392
393 // 64KiB minus a small space for metadata such as read/write pointers
394 static constexpr size_t kWriterInitialSize =
395 64 * 1024 / sizeof(uint32_t) - 16;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500396 CommandWriter mWriter;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800397 CommandReader mReader;
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500398
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800399 // When true, the we attach to the vr_hwcomposer service instead of the
400 // hwcomposer. This allows us to redirect surfaces to 3d surfaces in vr.
401 const bool mIsUsingVrComposer;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800402};
403
Lloyd Piquea822d522017-12-20 16:42:57 -0800404} // namespace impl
405
Chia-I Wuaab99f52016-10-05 12:59:58 +0800406} // namespace Hwc2
407
408} // namespace android
409
410#endif // ANDROID_SF_COMPOSER_HAL_H