blob: 9d16044395c71b2cd3be5d8ed37e58fe0505916b [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#undef LOG_TAG
18#define LOG_TAG "HwcComposer"
19
20#include <inttypes.h>
21#include <log/log.h>
Chia-I Wu06d63de2017-01-04 14:58:51 +080022#include <gui/BufferQueue.h>
Chia-I Wuaab99f52016-10-05 12:59:58 +080023
24#include "ComposerHal.h"
25
26namespace android {
27
28using hardware::Return;
29using hardware::hidl_vec;
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010030using hardware::hidl_handle;
Chia-I Wuaab99f52016-10-05 12:59:58 +080031
32namespace Hwc2 {
33
34namespace {
35
36class BufferHandle {
37public:
38 BufferHandle(const native_handle_t* buffer)
39 {
40 // nullptr is not a valid handle to HIDL
41 mHandle = (buffer) ? buffer : native_handle_init(mStorage, 0, 0);
42 }
43
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010044 operator const hidl_handle&() const
Chia-I Wuaab99f52016-10-05 12:59:58 +080045 {
46 return mHandle;
47 }
48
49private:
50 NATIVE_HANDLE_DECLARE_STORAGE(mStorage, 0, 0);
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010051 hidl_handle mHandle;
Chia-I Wuaab99f52016-10-05 12:59:58 +080052};
53
54class FenceHandle
55{
56public:
57 FenceHandle(int fd, bool owned)
58 : mOwned(owned)
59 {
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010060 native_handle_t* handle;
Chia-I Wuaab99f52016-10-05 12:59:58 +080061 if (fd >= 0) {
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010062 handle = native_handle_init(mStorage, 1, 0);
63 handle->data[0] = fd;
Chia-I Wuaab99f52016-10-05 12:59:58 +080064 } else {
65 // nullptr is not a valid handle to HIDL
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010066 handle = native_handle_init(mStorage, 0, 0);
Chia-I Wuaab99f52016-10-05 12:59:58 +080067 }
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010068 mHandle = handle;
Chia-I Wuaab99f52016-10-05 12:59:58 +080069 }
70
71 ~FenceHandle()
72 {
73 if (mOwned) {
74 native_handle_close(mHandle);
75 }
76 }
77
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010078 operator const hidl_handle&() const
Chia-I Wuaab99f52016-10-05 12:59:58 +080079 {
80 return mHandle;
81 }
82
83private:
84 bool mOwned;
85 NATIVE_HANDLE_DECLARE_STORAGE(mStorage, 1, 0);
Martijn Coenen7c5a92f2016-11-21 10:01:07 +010086 hidl_handle mHandle;
Chia-I Wuaab99f52016-10-05 12:59:58 +080087};
88
89// assume NO_RESOURCES when Status::isOk returns false
90constexpr Error kDefaultError = Error::NO_RESOURCES;
91
92template<typename T, typename U>
93T unwrapRet(Return<T>& ret, const U& default_val)
94{
Steven Moreland9d021002017-01-03 17:10:54 -080095 return (ret.isOk()) ? static_cast<T>(ret) :
Chia-I Wuaab99f52016-10-05 12:59:58 +080096 static_cast<T>(default_val);
97}
98
99Error unwrapRet(Return<Error>& ret)
100{
101 return unwrapRet(ret, kDefaultError);
102}
103
Chia-I Wuaab99f52016-10-05 12:59:58 +0800104} // anonymous namespace
105
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500106Composer::CommandWriter::CommandWriter(uint32_t initialMaxSize)
107 : CommandWriterBase(initialMaxSize) {}
108
109Composer::CommandWriter::~CommandWriter()
Chia-I Wuaab99f52016-10-05 12:59:58 +0800110{
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500111}
112
113void Composer::CommandWriter::setLayerInfo(uint32_t type, uint32_t appId)
114{
115 constexpr uint16_t kSetLayerInfoLength = 2;
116 beginCommand(
117 static_cast<IComposerClient::Command>(
118 IVrComposerClient::VrCommand::SET_LAYER_INFO),
119 kSetLayerInfoLength);
120 write(type);
121 write(appId);
122 endCommand();
123}
124
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400125void Composer::CommandWriter::setClientTargetMetadata(
126 const IVrComposerClient::BufferMetadata& metadata)
127{
128 constexpr uint16_t kSetClientTargetMetadataLength = 7;
129 beginCommand(
130 static_cast<IComposerClient::Command>(
131 IVrComposerClient::VrCommand::SET_CLIENT_TARGET_METADATA),
132 kSetClientTargetMetadataLength);
133 writeBufferMetadata(metadata);
134 endCommand();
135}
136
137void Composer::CommandWriter::setLayerBufferMetadata(
138 const IVrComposerClient::BufferMetadata& metadata)
139{
140 constexpr uint16_t kSetLayerBufferMetadataLength = 7;
141 beginCommand(
142 static_cast<IComposerClient::Command>(
143 IVrComposerClient::VrCommand::SET_LAYER_BUFFER_METADATA),
144 kSetLayerBufferMetadataLength);
145 writeBufferMetadata(metadata);
146 endCommand();
147}
148
149void Composer::CommandWriter::writeBufferMetadata(
150 const IVrComposerClient::BufferMetadata& metadata)
151{
152 write(metadata.width);
153 write(metadata.height);
154 write(metadata.stride);
155 write(metadata.layerCount);
156 writeSigned(static_cast<int32_t>(metadata.format));
157 write64(metadata.usage);
158}
159
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800160Composer::Composer(bool useVrComposer)
161 : mWriter(kWriterInitialSize),
162 mIsUsingVrComposer(useVrComposer)
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500163{
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800164 if (mIsUsingVrComposer) {
Daniel Nicoarae96afe62017-03-24 15:15:50 -0400165 mComposer = IComposer::getService("vr");
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500166 } else {
Chris Phoenixf5eb5e62017-01-24 14:08:33 -0800167 mComposer = IComposer::getService(); // use default name
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500168 }
169
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800170 if (mComposer == nullptr) {
Chia-I Wuaab99f52016-10-05 12:59:58 +0800171 LOG_ALWAYS_FATAL("failed to get hwcomposer service");
172 }
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800173
174 mComposer->createClient(
175 [&](const auto& tmpError, const auto& tmpClient)
176 {
177 if (tmpError == Error::NONE) {
178 mClient = tmpClient;
179 }
180 });
181 if (mClient == nullptr) {
182 LOG_ALWAYS_FATAL("failed to create composer client");
183 }
Chia-I Wuaab99f52016-10-05 12:59:58 +0800184}
185
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800186std::vector<IComposer::Capability> Composer::getCapabilities()
Chia-I Wuaab99f52016-10-05 12:59:58 +0800187{
188 std::vector<IComposer::Capability> capabilities;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800189 mComposer->getCapabilities(
Chia-I Wuaab99f52016-10-05 12:59:58 +0800190 [&](const auto& tmpCapabilities) {
Chia-I Wu67e376d2016-12-19 11:36:22 +0800191 capabilities = tmpCapabilities;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800192 });
193
194 return capabilities;
195}
196
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800197std::string Composer::dumpDebugInfo()
Chia-I Wuaab99f52016-10-05 12:59:58 +0800198{
199 std::string info;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800200 mComposer->dumpDebugInfo([&](const auto& tmpInfo) {
Chia-I Wuaab99f52016-10-05 12:59:58 +0800201 info = tmpInfo.c_str();
202 });
203
204 return info;
205}
206
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800207void Composer::registerCallback(const sp<IComposerCallback>& callback)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800208{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800209 auto ret = mClient->registerCallback(callback);
Steven Moreland9d021002017-01-03 17:10:54 -0800210 if (!ret.isOk()) {
Chia-I Wuaab99f52016-10-05 12:59:58 +0800211 ALOGE("failed to register IComposerCallback");
212 }
213}
214
Steven Thomas0af4b9f2017-04-26 14:34:01 -0700215void Composer::resetCommands() {
216 mWriter.reset();
217}
218
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800219uint32_t Composer::getMaxVirtualDisplayCount()
Chia-I Wuaab99f52016-10-05 12:59:58 +0800220{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800221 auto ret = mClient->getMaxVirtualDisplayCount();
Chia-I Wuaab99f52016-10-05 12:59:58 +0800222 return unwrapRet(ret, 0);
223}
224
225Error Composer::createVirtualDisplay(uint32_t width, uint32_t height,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800226 PixelFormat* format, Display* outDisplay)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800227{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800228 const uint32_t bufferSlotCount = 1;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800229 Error error = kDefaultError;
Chia-I Wu67e376d2016-12-19 11:36:22 +0800230 mClient->createVirtualDisplay(width, height, *format, bufferSlotCount,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800231 [&](const auto& tmpError, const auto& tmpDisplay,
232 const auto& tmpFormat) {
233 error = tmpError;
234 if (error != Error::NONE) {
235 return;
236 }
237
Chia-I Wu67e376d2016-12-19 11:36:22 +0800238 *outDisplay = tmpDisplay;
239 *format = tmpFormat;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800240 });
241
242 return error;
243}
244
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800245Error Composer::destroyVirtualDisplay(Display display)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800246{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800247 auto ret = mClient->destroyVirtualDisplay(display);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800248 return unwrapRet(ret);
249}
250
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800251Error Composer::acceptDisplayChanges(Display display)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800252{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800253 mWriter.selectDisplay(display);
254 mWriter.acceptDisplayChanges();
255 return Error::NONE;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800256}
257
Chia-I Wu67e376d2016-12-19 11:36:22 +0800258Error Composer::createLayer(Display display, Layer* outLayer)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800259{
260 Error error = kDefaultError;
Chia-I Wu06d63de2017-01-04 14:58:51 +0800261 mClient->createLayer(display, BufferQueue::NUM_BUFFER_SLOTS,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800262 [&](const auto& tmpError, const auto& tmpLayer) {
263 error = tmpError;
264 if (error != Error::NONE) {
265 return;
266 }
267
Chia-I Wu67e376d2016-12-19 11:36:22 +0800268 *outLayer = tmpLayer;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800269 });
270
271 return error;
272}
273
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800274Error Composer::destroyLayer(Display display, Layer layer)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800275{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800276 auto ret = mClient->destroyLayer(display, layer);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800277 return unwrapRet(ret);
278}
279
Chia-I Wu67e376d2016-12-19 11:36:22 +0800280Error Composer::getActiveConfig(Display display, Config* outConfig)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800281{
282 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800283 mClient->getActiveConfig(display,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800284 [&](const auto& tmpError, const auto& tmpConfig) {
285 error = tmpError;
286 if (error != Error::NONE) {
287 return;
288 }
289
Chia-I Wu67e376d2016-12-19 11:36:22 +0800290 *outConfig = tmpConfig;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800291 });
292
293 return error;
294}
295
296Error Composer::getChangedCompositionTypes(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800297 std::vector<Layer>* outLayers,
298 std::vector<IComposerClient::Composition>* outTypes)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800299{
Chia-I Wu67e376d2016-12-19 11:36:22 +0800300 mReader.takeChangedCompositionTypes(display, outLayers, outTypes);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800301 return Error::NONE;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800302}
303
304Error Composer::getColorModes(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800305 std::vector<ColorMode>* outModes)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800306{
307 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800308 mClient->getColorModes(display,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800309 [&](const auto& tmpError, const auto& tmpModes) {
310 error = tmpError;
311 if (error != Error::NONE) {
312 return;
313 }
314
Chia-I Wu67e376d2016-12-19 11:36:22 +0800315 *outModes = tmpModes;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800316 });
317
318 return error;
319}
320
321Error Composer::getDisplayAttribute(Display display, Config config,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800322 IComposerClient::Attribute attribute, int32_t* outValue)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800323{
324 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800325 mClient->getDisplayAttribute(display, config, attribute,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800326 [&](const auto& tmpError, const auto& tmpValue) {
327 error = tmpError;
328 if (error != Error::NONE) {
329 return;
330 }
331
Chia-I Wu67e376d2016-12-19 11:36:22 +0800332 *outValue = tmpValue;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800333 });
334
335 return error;
336}
337
338Error Composer::getDisplayConfigs(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800339 std::vector<Config>* outConfigs)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800340{
341 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800342 mClient->getDisplayConfigs(display,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800343 [&](const auto& tmpError, const auto& tmpConfigs) {
344 error = tmpError;
345 if (error != Error::NONE) {
346 return;
347 }
348
Chia-I Wu67e376d2016-12-19 11:36:22 +0800349 *outConfigs = tmpConfigs;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800350 });
351
352 return error;
353}
354
Chia-I Wu67e376d2016-12-19 11:36:22 +0800355Error Composer::getDisplayName(Display display, std::string* outName)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800356{
357 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800358 mClient->getDisplayName(display,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800359 [&](const auto& tmpError, const auto& tmpName) {
360 error = tmpError;
361 if (error != Error::NONE) {
362 return;
363 }
364
Chia-I Wu67e376d2016-12-19 11:36:22 +0800365 *outName = tmpName.c_str();
Chia-I Wuaab99f52016-10-05 12:59:58 +0800366 });
367
368 return error;
369}
370
371Error Composer::getDisplayRequests(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +0800372 uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers,
373 std::vector<uint32_t>* outLayerRequestMasks)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800374{
Chia-I Wu67e376d2016-12-19 11:36:22 +0800375 mReader.takeDisplayRequests(display, outDisplayRequestMask,
376 outLayers, outLayerRequestMasks);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800377 return Error::NONE;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800378}
379
Chia-I Wu67e376d2016-12-19 11:36:22 +0800380Error Composer::getDisplayType(Display display,
381 IComposerClient::DisplayType* outType)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800382{
383 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800384 mClient->getDisplayType(display,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800385 [&](const auto& tmpError, const auto& tmpType) {
386 error = tmpError;
387 if (error != Error::NONE) {
388 return;
389 }
390
Chia-I Wu67e376d2016-12-19 11:36:22 +0800391 *outType = tmpType;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800392 });
393
394 return error;
395}
396
Chia-I Wu67e376d2016-12-19 11:36:22 +0800397Error Composer::getDozeSupport(Display display, bool* outSupport)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800398{
399 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800400 mClient->getDozeSupport(display,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800401 [&](const auto& tmpError, const auto& tmpSupport) {
402 error = tmpError;
403 if (error != Error::NONE) {
404 return;
405 }
406
Chia-I Wu67e376d2016-12-19 11:36:22 +0800407 *outSupport = tmpSupport;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800408 });
409
410 return error;
411}
412
Chia-I Wu67e376d2016-12-19 11:36:22 +0800413Error Composer::getHdrCapabilities(Display display,
414 std::vector<Hdr>* outTypes, float* outMaxLuminance,
415 float* outMaxAverageLuminance, float* outMinLuminance)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800416{
417 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800418 mClient->getHdrCapabilities(display,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800419 [&](const auto& tmpError, const auto& tmpTypes,
420 const auto& tmpMaxLuminance,
421 const auto& tmpMaxAverageLuminance,
422 const auto& tmpMinLuminance) {
423 error = tmpError;
424 if (error != Error::NONE) {
425 return;
426 }
427
Chia-I Wu67e376d2016-12-19 11:36:22 +0800428 *outTypes = tmpTypes;
429 *outMaxLuminance = tmpMaxLuminance;
430 *outMaxAverageLuminance = tmpMaxAverageLuminance;
431 *outMinLuminance = tmpMinLuminance;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800432 });
433
434 return error;
435}
436
Chia-I Wu67e376d2016-12-19 11:36:22 +0800437Error Composer::getReleaseFences(Display display,
438 std::vector<Layer>* outLayers, std::vector<int>* outReleaseFences)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800439{
Chia-I Wu67e376d2016-12-19 11:36:22 +0800440 mReader.takeReleaseFences(display, outLayers, outReleaseFences);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800441 return Error::NONE;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800442}
443
Chia-I Wu67e376d2016-12-19 11:36:22 +0800444Error Composer::presentDisplay(Display display, int* outPresentFence)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800445{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800446 mWriter.selectDisplay(display);
447 mWriter.presentDisplay();
Chia-I Wuaab99f52016-10-05 12:59:58 +0800448
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800449 Error error = execute();
450 if (error != Error::NONE) {
451 return error;
452 }
Chia-I Wuaab99f52016-10-05 12:59:58 +0800453
Chia-I Wu67e376d2016-12-19 11:36:22 +0800454 mReader.takePresentFence(display, outPresentFence);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800455
456 return Error::NONE;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800457}
458
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800459Error Composer::setActiveConfig(Display display, Config config)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800460{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800461 auto ret = mClient->setActiveConfig(display, config);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800462 return unwrapRet(ret);
463}
464
Chia-I Wu06d63de2017-01-04 14:58:51 +0800465Error Composer::setClientTarget(Display display, uint32_t slot,
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400466 const sp<GraphicBuffer>& target,
Chia-I Wuaab99f52016-10-05 12:59:58 +0800467 int acquireFence, Dataspace dataspace,
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800468 const std::vector<IComposerClient::Rect>& damage)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800469{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800470 mWriter.selectDisplay(display);
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400471 if (mIsUsingVrComposer && target.get()) {
472 IVrComposerClient::BufferMetadata metadata = {
473 .width = target->getWidth(),
474 .height = target->getHeight(),
475 .stride = target->getStride(),
476 .layerCount = target->getLayerCount(),
477 .format = static_cast<PixelFormat>(target->getPixelFormat()),
478 .usage = target->getUsage(),
479 };
480 mWriter.setClientTargetMetadata(metadata);
481 }
482
483 const native_handle_t* handle = nullptr;
484 if (target.get()) {
485 handle = target->getNativeBuffer()->handle;
486 }
487
488 mWriter.setClientTarget(slot, handle, acquireFence, dataspace, damage);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800489 return Error::NONE;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800490}
491
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800492Error Composer::setColorMode(Display display, ColorMode mode)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800493{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800494 auto ret = mClient->setColorMode(display, mode);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800495 return unwrapRet(ret);
496}
497
498Error Composer::setColorTransform(Display display, const float* matrix,
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800499 ColorTransform hint)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800500{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800501 mWriter.selectDisplay(display);
502 mWriter.setColorTransform(matrix, hint);
503 return Error::NONE;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800504}
505
506Error Composer::setOutputBuffer(Display display, const native_handle_t* buffer,
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800507 int releaseFence)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800508{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800509 mWriter.selectDisplay(display);
510 mWriter.setOutputBuffer(0, buffer, dup(releaseFence));
511 return Error::NONE;
512}
Chia-I Wuaab99f52016-10-05 12:59:58 +0800513
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800514Error Composer::setPowerMode(Display display, IComposerClient::PowerMode mode)
515{
516 auto ret = mClient->setPowerMode(display, mode);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800517 return unwrapRet(ret);
518}
519
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800520Error Composer::setVsyncEnabled(Display display, IComposerClient::Vsync enabled)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800521{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800522 auto ret = mClient->setVsyncEnabled(display, enabled);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800523 return unwrapRet(ret);
524}
525
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800526Error Composer::setClientTargetSlotCount(Display display)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800527{
Chia-I Wu06d63de2017-01-04 14:58:51 +0800528 const uint32_t bufferSlotCount = BufferQueue::NUM_BUFFER_SLOTS;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800529 auto ret = mClient->setClientTargetSlotCount(display, bufferSlotCount);
Chia-I Wuaab99f52016-10-05 12:59:58 +0800530 return unwrapRet(ret);
531}
532
Chia-I Wu67e376d2016-12-19 11:36:22 +0800533Error Composer::validateDisplay(Display display, uint32_t* outNumTypes,
534 uint32_t* outNumRequests)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800535{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800536 mWriter.selectDisplay(display);
537 mWriter.validateDisplay();
538
539 Error error = execute();
540 if (error != Error::NONE) {
541 return error;
542 }
543
Chia-I Wu67e376d2016-12-19 11:36:22 +0800544 mReader.hasChanges(display, outNumTypes, outNumRequests);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800545
546 return Error::NONE;
547}
548
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700549Error Composer::presentOrValidateDisplay(Display display, uint32_t* outNumTypes,
550 uint32_t* outNumRequests, int* outPresentFence, uint32_t* state) {
551 mWriter.selectDisplay(display);
552 mWriter.presentOrvalidateDisplay();
553
554 Error error = execute();
555 if (error != Error::NONE) {
556 return error;
557 }
558
559 mReader.takePresentOrValidateStage(display, state);
560
561 if (*state == 1) { // Present succeeded
562 mReader.takePresentFence(display, outPresentFence);
563 }
564
565 if (*state == 0) { // Validate succeeded.
566 mReader.hasChanges(display, outNumTypes, outNumRequests);
567 }
568
569 return Error::NONE;
570}
571
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800572Error Composer::setCursorPosition(Display display, Layer layer,
573 int32_t x, int32_t y)
574{
575 mWriter.selectDisplay(display);
576 mWriter.selectLayer(layer);
577 mWriter.setLayerCursorPosition(x, y);
578 return Error::NONE;
579}
580
581Error Composer::setLayerBuffer(Display display, Layer layer,
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400582 uint32_t slot, const sp<GraphicBuffer>& buffer, int acquireFence)
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800583{
584 mWriter.selectDisplay(display);
585 mWriter.selectLayer(layer);
Daniel Nicoara1f42e3a2017-04-10 13:27:32 -0400586 if (mIsUsingVrComposer && buffer.get()) {
587 IVrComposerClient::BufferMetadata metadata = {
588 .width = buffer->getWidth(),
589 .height = buffer->getHeight(),
590 .stride = buffer->getStride(),
591 .layerCount = buffer->getLayerCount(),
592 .format = static_cast<PixelFormat>(buffer->getPixelFormat()),
593 .usage = buffer->getUsage(),
594 };
595 mWriter.setLayerBufferMetadata(metadata);
596 }
597
598 const native_handle_t* handle = nullptr;
599 if (buffer.get()) {
600 handle = buffer->getNativeBuffer()->handle;
601 }
602
603 mWriter.setLayerBuffer(slot, handle, acquireFence);
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800604 return Error::NONE;
605}
606
607Error Composer::setLayerSurfaceDamage(Display display, Layer layer,
608 const std::vector<IComposerClient::Rect>& damage)
609{
610 mWriter.selectDisplay(display);
611 mWriter.selectLayer(layer);
612 mWriter.setLayerSurfaceDamage(damage);
613 return Error::NONE;
614}
615
616Error Composer::setLayerBlendMode(Display display, Layer layer,
617 IComposerClient::BlendMode mode)
618{
619 mWriter.selectDisplay(display);
620 mWriter.selectLayer(layer);
621 mWriter.setLayerBlendMode(mode);
622 return Error::NONE;
623}
624
625Error Composer::setLayerColor(Display display, Layer layer,
626 const IComposerClient::Color& color)
627{
628 mWriter.selectDisplay(display);
629 mWriter.selectLayer(layer);
630 mWriter.setLayerColor(color);
631 return Error::NONE;
632}
633
634Error Composer::setLayerCompositionType(Display display, Layer layer,
635 IComposerClient::Composition type)
636{
637 mWriter.selectDisplay(display);
638 mWriter.selectLayer(layer);
639 mWriter.setLayerCompositionType(type);
640 return Error::NONE;
641}
642
643Error Composer::setLayerDataspace(Display display, Layer layer,
644 Dataspace dataspace)
645{
646 mWriter.selectDisplay(display);
647 mWriter.selectLayer(layer);
648 mWriter.setLayerDataspace(dataspace);
649 return Error::NONE;
650}
651
652Error Composer::setLayerDisplayFrame(Display display, Layer layer,
653 const IComposerClient::Rect& frame)
654{
655 mWriter.selectDisplay(display);
656 mWriter.selectLayer(layer);
657 mWriter.setLayerDisplayFrame(frame);
658 return Error::NONE;
659}
660
661Error Composer::setLayerPlaneAlpha(Display display, Layer layer,
662 float alpha)
663{
664 mWriter.selectDisplay(display);
665 mWriter.selectLayer(layer);
666 mWriter.setLayerPlaneAlpha(alpha);
667 return Error::NONE;
668}
669
670Error Composer::setLayerSidebandStream(Display display, Layer layer,
671 const native_handle_t* stream)
672{
673 mWriter.selectDisplay(display);
674 mWriter.selectLayer(layer);
675 mWriter.setLayerSidebandStream(stream);
676 return Error::NONE;
677}
678
679Error Composer::setLayerSourceCrop(Display display, Layer layer,
680 const IComposerClient::FRect& crop)
681{
682 mWriter.selectDisplay(display);
683 mWriter.selectLayer(layer);
684 mWriter.setLayerSourceCrop(crop);
685 return Error::NONE;
686}
687
688Error Composer::setLayerTransform(Display display, Layer layer,
689 Transform transform)
690{
691 mWriter.selectDisplay(display);
692 mWriter.selectLayer(layer);
693 mWriter.setLayerTransform(transform);
694 return Error::NONE;
695}
696
697Error Composer::setLayerVisibleRegion(Display display, Layer layer,
698 const std::vector<IComposerClient::Rect>& visible)
699{
700 mWriter.selectDisplay(display);
701 mWriter.selectLayer(layer);
702 mWriter.setLayerVisibleRegion(visible);
703 return Error::NONE;
704}
705
706Error Composer::setLayerZOrder(Display display, Layer layer, uint32_t z)
707{
708 mWriter.selectDisplay(display);
709 mWriter.selectLayer(layer);
710 mWriter.setLayerZOrder(z);
711 return Error::NONE;
712}
713
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500714Error Composer::setLayerInfo(Display display, Layer layer, uint32_t type,
715 uint32_t appId)
716{
Hendrik Wagenaar87670ff2017-02-01 12:10:46 -0800717 if (mIsUsingVrComposer) {
Daniel Nicoara2f5f8a52016-12-20 16:11:58 -0500718 mWriter.selectDisplay(display);
719 mWriter.selectLayer(layer);
720 mWriter.setLayerInfo(type, appId);
721 }
722 return Error::NONE;
723}
724
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800725Error Composer::execute()
726{
727 // prepare input command queue
728 bool queueChanged = false;
729 uint32_t commandLength = 0;
730 hidl_vec<hidl_handle> commandHandles;
Chia-I Wu67e376d2016-12-19 11:36:22 +0800731 if (!mWriter.writeQueue(&queueChanged, &commandLength, &commandHandles)) {
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800732 mWriter.reset();
733 return Error::NO_RESOURCES;
734 }
735
736 // set up new input command queue if necessary
737 if (queueChanged) {
738 auto ret = mClient->setInputCommandQueue(*mWriter.getMQDescriptor());
739 auto error = unwrapRet(ret);
740 if (error != Error::NONE) {
741 mWriter.reset();
742 return error;
743 }
744 }
745
Chia-I Wuaab99f52016-10-05 12:59:58 +0800746 Error error = kDefaultError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800747 mClient->executeCommands(commandLength, commandHandles,
748 [&](const auto& tmpError, const auto& tmpOutChanged,
749 const auto& tmpOutLength, const auto& tmpOutHandles)
750 {
Chia-I Wuaab99f52016-10-05 12:59:58 +0800751 error = tmpError;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800752
753 // set up new output command queue if necessary
754 if (error == Error::NONE && tmpOutChanged) {
755 error = kDefaultError;
756 mClient->getOutputCommandQueue(
757 [&](const auto& tmpError,
758 const auto& tmpDescriptor)
759 {
760 error = tmpError;
761 if (error != Error::NONE) {
762 return;
763 }
764
765 mReader.setMQDescriptor(tmpDescriptor);
766 });
767 }
768
Chia-I Wuaab99f52016-10-05 12:59:58 +0800769 if (error != Error::NONE) {
770 return;
771 }
772
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800773 if (mReader.readQueue(tmpOutLength, tmpOutHandles)) {
774 error = mReader.parse();
775 mReader.reset();
776 } else {
777 error = Error::NO_RESOURCES;
778 }
Chia-I Wuaab99f52016-10-05 12:59:58 +0800779 });
780
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800781 if (error == Error::NONE) {
782 std::vector<CommandReader::CommandError> commandErrors =
783 mReader.takeErrors();
784
785 for (const auto& cmdErr : commandErrors) {
786 auto command = mWriter.getCommand(cmdErr.location);
787
788 if (command == IComposerClient::Command::VALIDATE_DISPLAY ||
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700789 command == IComposerClient::Command::PRESENT_DISPLAY ||
790 command == IComposerClient::Command::PRESENT_OR_VALIDATE_DISPLAY) {
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800791 error = cmdErr.error;
792 } else {
793 ALOGW("command 0x%x generated error %d",
794 command, cmdErr.error);
795 }
796 }
797 }
798
799 mWriter.reset();
800
Chia-I Wuaab99f52016-10-05 12:59:58 +0800801 return error;
802}
803
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800804CommandReader::~CommandReader()
Chia-I Wuaab99f52016-10-05 12:59:58 +0800805{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800806 resetData();
Chia-I Wuaab99f52016-10-05 12:59:58 +0800807}
808
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800809Error CommandReader::parse()
Chia-I Wuaab99f52016-10-05 12:59:58 +0800810{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800811 resetData();
Chia-I Wuaab99f52016-10-05 12:59:58 +0800812
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800813 IComposerClient::Command command;
814 uint16_t length = 0;
815
816 while (!isEmpty()) {
Chia-I Wu67e376d2016-12-19 11:36:22 +0800817 if (!beginCommand(&command, &length)) {
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800818 break;
819 }
820
821 bool parsed = false;
822 switch (command) {
823 case IComposerClient::Command::SELECT_DISPLAY:
824 parsed = parseSelectDisplay(length);
825 break;
826 case IComposerClient::Command::SET_ERROR:
827 parsed = parseSetError(length);
828 break;
829 case IComposerClient::Command::SET_CHANGED_COMPOSITION_TYPES:
830 parsed = parseSetChangedCompositionTypes(length);
831 break;
832 case IComposerClient::Command::SET_DISPLAY_REQUESTS:
833 parsed = parseSetDisplayRequests(length);
834 break;
835 case IComposerClient::Command::SET_PRESENT_FENCE:
836 parsed = parseSetPresentFence(length);
837 break;
838 case IComposerClient::Command::SET_RELEASE_FENCES:
839 parsed = parseSetReleaseFences(length);
840 break;
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700841 case IComposerClient::Command ::SET_PRESENT_OR_VALIDATE_DISPLAY_RESULT:
842 parsed = parseSetPresentOrValidateDisplayResult(length);
843 break;
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800844 default:
845 parsed = false;
846 break;
847 }
848
849 endCommand();
850
851 if (!parsed) {
852 ALOGE("failed to parse command 0x%x length %" PRIu16,
853 command, length);
854 break;
855 }
856 }
857
858 return isEmpty() ? Error::NONE : Error::NO_RESOURCES;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800859}
860
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800861bool CommandReader::parseSelectDisplay(uint16_t length)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800862{
Daniel Nicoara3c9cbd42017-01-17 12:04:06 -0500863 if (length != CommandWriterBase::kSelectDisplayLength) {
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800864 return false;
865 }
Chia-I Wuaab99f52016-10-05 12:59:58 +0800866
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800867 mCurrentReturnData = &mReturnData[read64()];
868
869 return true;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800870}
871
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800872bool CommandReader::parseSetError(uint16_t length)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800873{
Daniel Nicoara3c9cbd42017-01-17 12:04:06 -0500874 if (length != CommandWriterBase::kSetErrorLength) {
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800875 return false;
876 }
877
878 auto location = read();
879 auto error = static_cast<Error>(readSigned());
880
881 mErrors.emplace_back(CommandError{location, error});
882
883 return true;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800884}
885
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800886bool CommandReader::parseSetChangedCompositionTypes(uint16_t length)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800887{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800888 // (layer id, composition type) pairs
889 if (length % 3 != 0 || !mCurrentReturnData) {
890 return false;
891 }
892
893 uint32_t count = length / 3;
894 mCurrentReturnData->changedLayers.reserve(count);
895 mCurrentReturnData->compositionTypes.reserve(count);
896 while (count > 0) {
897 auto layer = read64();
898 auto type = static_cast<IComposerClient::Composition>(readSigned());
899
900 mCurrentReturnData->changedLayers.push_back(layer);
901 mCurrentReturnData->compositionTypes.push_back(type);
902
903 count--;
904 }
905
906 return true;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800907}
908
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800909bool CommandReader::parseSetDisplayRequests(uint16_t length)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800910{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800911 // display requests followed by (layer id, layer requests) pairs
912 if (length % 3 != 1 || !mCurrentReturnData) {
913 return false;
914 }
915
916 mCurrentReturnData->displayRequests = read();
917
918 uint32_t count = (length - 1) / 3;
919 mCurrentReturnData->requestedLayers.reserve(count);
920 mCurrentReturnData->requestMasks.reserve(count);
921 while (count > 0) {
922 auto layer = read64();
923 auto layerRequestMask = read();
924
925 mCurrentReturnData->requestedLayers.push_back(layer);
926 mCurrentReturnData->requestMasks.push_back(layerRequestMask);
927
928 count--;
929 }
930
931 return true;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800932}
933
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800934bool CommandReader::parseSetPresentFence(uint16_t length)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800935{
Daniel Nicoara3c9cbd42017-01-17 12:04:06 -0500936 if (length != CommandWriterBase::kSetPresentFenceLength ||
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800937 !mCurrentReturnData) {
938 return false;
939 }
940
941 if (mCurrentReturnData->presentFence >= 0) {
942 close(mCurrentReturnData->presentFence);
943 }
944 mCurrentReturnData->presentFence = readFence();
945
946 return true;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800947}
948
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800949bool CommandReader::parseSetReleaseFences(uint16_t length)
Chia-I Wuaab99f52016-10-05 12:59:58 +0800950{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800951 // (layer id, release fence index) pairs
952 if (length % 3 != 0 || !mCurrentReturnData) {
953 return false;
954 }
955
956 uint32_t count = length / 3;
957 mCurrentReturnData->releasedLayers.reserve(count);
958 mCurrentReturnData->releaseFences.reserve(count);
959 while (count > 0) {
960 auto layer = read64();
961 auto fence = readFence();
962
963 mCurrentReturnData->releasedLayers.push_back(layer);
964 mCurrentReturnData->releaseFences.push_back(fence);
965
966 count--;
967 }
968
969 return true;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800970}
971
Fabien Sanglard249c0ae2017-06-19 19:22:36 -0700972bool CommandReader::parseSetPresentOrValidateDisplayResult(uint16_t length)
973{
974 if (length != CommandWriterBase::kPresentOrValidateDisplayResultLength || !mCurrentReturnData) {
975 return false;
976 }
977 mCurrentReturnData->presentOrValidateState = read();
978 return true;
979}
980
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800981void CommandReader::resetData()
Chia-I Wuaab99f52016-10-05 12:59:58 +0800982{
Chia-I Wucd8d7f02016-11-16 11:02:31 +0800983 mErrors.clear();
984
985 for (auto& data : mReturnData) {
986 if (data.second.presentFence >= 0) {
987 close(data.second.presentFence);
988 }
989 for (auto fence : data.second.releaseFences) {
990 if (fence >= 0) {
991 close(fence);
992 }
993 }
994 }
995
996 mReturnData.clear();
997 mCurrentReturnData = nullptr;
Chia-I Wuaab99f52016-10-05 12:59:58 +0800998}
999
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001000std::vector<CommandReader::CommandError> CommandReader::takeErrors()
Chia-I Wuaab99f52016-10-05 12:59:58 +08001001{
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001002 return std::move(mErrors);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001003}
1004
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001005bool CommandReader::hasChanges(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +08001006 uint32_t* outNumChangedCompositionTypes,
1007 uint32_t* outNumLayerRequestMasks) const
Chia-I Wuaab99f52016-10-05 12:59:58 +08001008{
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001009 auto found = mReturnData.find(display);
1010 if (found == mReturnData.end()) {
Chia-I Wu67e376d2016-12-19 11:36:22 +08001011 *outNumChangedCompositionTypes = 0;
1012 *outNumLayerRequestMasks = 0;
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001013 return false;
1014 }
1015
1016 const ReturnData& data = found->second;
1017
Chia-I Wu67e376d2016-12-19 11:36:22 +08001018 *outNumChangedCompositionTypes = data.compositionTypes.size();
1019 *outNumLayerRequestMasks = data.requestMasks.size();
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001020
1021 return !(data.compositionTypes.empty() && data.requestMasks.empty());
Chia-I Wuaab99f52016-10-05 12:59:58 +08001022}
1023
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001024void CommandReader::takeChangedCompositionTypes(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +08001025 std::vector<Layer>* outLayers,
1026 std::vector<IComposerClient::Composition>* outTypes)
Chia-I Wuaab99f52016-10-05 12:59:58 +08001027{
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001028 auto found = mReturnData.find(display);
1029 if (found == mReturnData.end()) {
Chia-I Wu67e376d2016-12-19 11:36:22 +08001030 outLayers->clear();
1031 outTypes->clear();
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001032 return;
1033 }
1034
1035 ReturnData& data = found->second;
1036
Chia-I Wu67e376d2016-12-19 11:36:22 +08001037 *outLayers = std::move(data.changedLayers);
1038 *outTypes = std::move(data.compositionTypes);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001039}
1040
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001041void CommandReader::takeDisplayRequests(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +08001042 uint32_t* outDisplayRequestMask, std::vector<Layer>* outLayers,
1043 std::vector<uint32_t>* outLayerRequestMasks)
Chia-I Wuaab99f52016-10-05 12:59:58 +08001044{
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001045 auto found = mReturnData.find(display);
1046 if (found == mReturnData.end()) {
Chia-I Wu67e376d2016-12-19 11:36:22 +08001047 *outDisplayRequestMask = 0;
1048 outLayers->clear();
1049 outLayerRequestMasks->clear();
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001050 return;
1051 }
Chia-I Wuaab99f52016-10-05 12:59:58 +08001052
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001053 ReturnData& data = found->second;
1054
Chia-I Wu67e376d2016-12-19 11:36:22 +08001055 *outDisplayRequestMask = data.displayRequests;
1056 *outLayers = std::move(data.requestedLayers);
1057 *outLayerRequestMasks = std::move(data.requestMasks);
Chia-I Wuaab99f52016-10-05 12:59:58 +08001058}
1059
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001060void CommandReader::takeReleaseFences(Display display,
Chia-I Wu67e376d2016-12-19 11:36:22 +08001061 std::vector<Layer>* outLayers, std::vector<int>* outReleaseFences)
Chia-I Wuaab99f52016-10-05 12:59:58 +08001062{
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001063 auto found = mReturnData.find(display);
1064 if (found == mReturnData.end()) {
Chia-I Wu67e376d2016-12-19 11:36:22 +08001065 outLayers->clear();
1066 outReleaseFences->clear();
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001067 return;
1068 }
1069
1070 ReturnData& data = found->second;
1071
Chia-I Wu67e376d2016-12-19 11:36:22 +08001072 *outLayers = std::move(data.releasedLayers);
1073 *outReleaseFences = std::move(data.releaseFences);
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001074}
1075
Chia-I Wu67e376d2016-12-19 11:36:22 +08001076void CommandReader::takePresentFence(Display display, int* outPresentFence)
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001077{
1078 auto found = mReturnData.find(display);
1079 if (found == mReturnData.end()) {
Chia-I Wu67e376d2016-12-19 11:36:22 +08001080 *outPresentFence = -1;
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001081 return;
1082 }
1083
1084 ReturnData& data = found->second;
1085
Chia-I Wu67e376d2016-12-19 11:36:22 +08001086 *outPresentFence = data.presentFence;
Chia-I Wucd8d7f02016-11-16 11:02:31 +08001087 data.presentFence = -1;
Chia-I Wuaab99f52016-10-05 12:59:58 +08001088}
1089
Fabien Sanglard249c0ae2017-06-19 19:22:36 -07001090void CommandReader::takePresentOrValidateStage(Display display, uint32_t* state) {
1091 auto found = mReturnData.find(display);
1092 if (found == mReturnData.end()) {
1093 *state= -1;
1094 return;
1095 }
1096 ReturnData& data = found->second;
1097 *state = data.presentOrValidateState;
1098}
1099
Chia-I Wuaab99f52016-10-05 12:59:58 +08001100} // namespace Hwc2
1101
1102} // namespace android