blob: e033f932862cb8b113ea5d951346878ff9ee75f8 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-04 03:31:441/*
2 * Copyright (C) 2008 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
Vishnu Nair217d8e62018-09-12 23:34:4917#define LOG_TAG "LayerState"
18
Garfield Tan8a3083e2018-12-03 21:21:0719#include <inttypes.h>
20
The Android Open Source Projectedbf3b62009-03-04 03:31:4421#include <utils/Errors.h>
Mathias Agopianc5b2c0b2009-05-20 02:08:1022#include <binder/Parcel.h>
Mathias Agopian90ac7992012-02-26 02:48:3523#include <gui/ISurfaceComposerClient.h>
Andy McFadden2adaf042012-12-18 17:49:4524#include <gui/IGraphicBufferProducer.h>
Robert Carr4cdc58f2017-08-23 21:22:2025#include <gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-04 03:31:4426
27namespace android {
28
29status_t layer_state_t::write(Parcel& output) const
30{
Mathias Agopianac9fa422013-02-12 00:40:3631 output.writeStrongBinder(surface);
Garfield Tan8a3083e2018-12-03 21:21:0732 output.writeUint64(what);
Mathias Agopianac9fa422013-02-12 00:40:3633 output.writeFloat(x);
34 output.writeFloat(y);
Robert Carrae060832016-11-28 18:51:0035 output.writeInt32(z);
Dan Stozad723bd72014-11-18 18:24:0336 output.writeUint32(w);
37 output.writeUint32(h);
38 output.writeUint32(layerStack);
Mathias Agopianac9fa422013-02-12 00:40:3639 output.writeFloat(alpha);
Dan Stozad723bd72014-11-18 18:24:0340 output.writeUint32(flags);
41 output.writeUint32(mask);
Mathias Agopianac9fa422013-02-12 00:40:3642 *reinterpret_cast<layer_state_t::matrix22_t *>(
43 output.writeInplace(sizeof(layer_state_t::matrix22_t))) = matrix;
Marissa Wallf58c14b2018-07-24 17:50:4344 output.write(crop_legacy);
Marissa Wallf58c14b2018-07-24 17:50:4345 output.writeStrongBinder(barrierHandle_legacy);
Robert Carr1db73f62016-12-21 20:58:5146 output.writeStrongBinder(reparentHandle);
Marissa Wallf58c14b2018-07-24 17:50:4347 output.writeUint64(frameNumber_legacy);
Robert Carrc3574f72016-03-24 19:19:3248 output.writeInt32(overrideScalingMode);
Marissa Wallf58c14b2018-07-24 17:50:4349 output.writeStrongBinder(IInterface::asBinder(barrierGbp_legacy));
Robert Carrdb66e622017-04-10 23:55:5750 output.writeStrongBinder(relativeLayerHandle);
chaviw06178942017-07-27 17:25:5951 output.writeStrongBinder(parentHandleForChild);
chaviw13fdc492017-06-27 19:40:1852 output.writeFloat(color.r);
53 output.writeFloat(color.g);
54 output.writeFloat(color.b);
Robert Carr2c358bf2018-08-08 22:58:1555#ifndef NO_INPUT
56 inputInfo.write(output);
57#endif
Mathias Agopianac9fa422013-02-12 00:40:3658 output.write(transparentRegion);
Marissa Wall61c58622018-07-18 17:12:2059 output.writeUint32(transform);
60 output.writeBool(transformToDisplayInverse);
61 output.write(crop);
Marissa Wall861616d2018-10-22 19:52:2362 output.write(frame);
Marissa Wall61c58622018-07-18 17:12:2063 if (buffer) {
64 output.writeBool(true);
65 output.write(*buffer);
66 } else {
67 output.writeBool(false);
68 }
69 if (acquireFence) {
70 output.writeBool(true);
71 output.write(*acquireFence);
72 } else {
73 output.writeBool(false);
74 }
75 output.writeUint32(static_cast<uint32_t>(dataspace));
76 output.write(hdrMetadata);
77 output.write(surfaceDamageRegion);
78 output.writeInt32(api);
79 if (sidebandStream) {
80 output.writeBool(true);
81 output.writeNativeHandle(sidebandStream->handle());
82 } else {
83 output.writeBool(false);
84 }
85
Peiyong Lind3788632018-09-18 23:01:3186 memcpy(output.writeInplace(16 * sizeof(float)),
87 colorTransform.asArray(), 16 * sizeof(float));
Lucas Dupin1b6531c2018-07-06 00:18:2188 output.writeFloat(cornerRadius);
Steven Moreland9d4ce9b2019-07-17 22:23:3889 output.writeStrongBinder(cachedBuffer.token.promote());
Marissa Wall947d34e2019-03-29 21:03:5390 output.writeUint64(cachedBuffer.id);
Evan Rosky1f6d6d52018-12-06 18:47:2691 output.writeParcelable(metadata);
Marissa Wallebc2c052019-01-17 03:16:5592
Valerie Haudd0b7572019-01-29 22:59:2793 output.writeFloat(bgColorAlpha);
94 output.writeUint32(static_cast<uint32_t>(bgColorDataspace));
Peiyong Linc502cb72019-03-01 23:00:2395 output.writeBool(colorSpaceAgnostic);
Valerie Haued54efa2019-01-12 04:03:1496
Valerie Hau9dab9732019-08-20 16:29:2597 auto err = output.writeVectorSize(listeners);
98 if (err) {
99 return err;
100 }
101
102 for (auto listener : listeners) {
103 err = output.writeStrongBinder(listener.transactionCompletedListener);
104 if (err) {
105 return err;
106 }
107 err = output.writeInt64Vector(listener.callbackIds);
108 if (err) {
109 return err;
110 }
111 }
Vishnu Nair440992f2019-12-10 03:53:19112 output.writeFloat(shadowRadius);
Mathias Agopianac9fa422013-02-12 00:40:36113 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-04 03:31:44114}
115
116status_t layer_state_t::read(const Parcel& input)
117{
Mathias Agopianac9fa422013-02-12 00:40:36118 surface = input.readStrongBinder();
Garfield Tan8a3083e2018-12-03 21:21:07119 what = input.readUint64();
Mathias Agopianac9fa422013-02-12 00:40:36120 x = input.readFloat();
121 y = input.readFloat();
Robert Carrae060832016-11-28 18:51:00122 z = input.readInt32();
Dan Stozad723bd72014-11-18 18:24:03123 w = input.readUint32();
124 h = input.readUint32();
125 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-12 00:40:36126 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 18:24:03127 flags = static_cast<uint8_t>(input.readUint32());
128 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 18:10:13129 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
130 if (matrix_data) {
131 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
132 } else {
133 return BAD_VALUE;
134 }
Marissa Wallf58c14b2018-07-24 17:50:43135 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 17:50:43136 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 20:58:51137 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 17:50:43138 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 19:19:32139 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 17:50:43140 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 23:55:57141 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 17:25:59142 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 19:40:18143 color.r = input.readFloat();
144 color.g = input.readFloat();
145 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 22:58:15146
147#ifndef NO_INPUT
148 inputInfo = InputWindowInfo::read(input);
149#endif
150
Mathias Agopianac9fa422013-02-12 00:40:36151 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 17:12:20152 transform = input.readUint32();
153 transformToDisplayInverse = input.readBool();
154 input.read(crop);
Marissa Wall861616d2018-10-22 19:52:23155 input.read(frame);
Marissa Wall61c58622018-07-18 17:12:20156 buffer = new GraphicBuffer();
157 if (input.readBool()) {
158 input.read(*buffer);
159 }
160 acquireFence = new Fence();
161 if (input.readBool()) {
162 input.read(*acquireFence);
163 }
164 dataspace = static_cast<ui::Dataspace>(input.readUint32());
165 input.read(hdrMetadata);
166 input.read(surfaceDamageRegion);
167 api = input.readInt32();
168 if (input.readBool()) {
169 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
170 }
171
Peiyong Lind3788632018-09-18 23:01:31172 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-06 00:18:21173 cornerRadius = input.readFloat();
Steven Moreland9d4ce9b2019-07-17 22:23:38174 cachedBuffer.token = input.readStrongBinder();
Marissa Wall947d34e2019-03-29 21:03:53175 cachedBuffer.id = input.readUint64();
Evan Rosky1f6d6d52018-12-06 18:47:26176 input.readParcelable(&metadata);
Marissa Wallebc2c052019-01-17 03:16:55177
Valerie Haudd0b7572019-01-29 22:59:27178 bgColorAlpha = input.readFloat();
179 bgColorDataspace = static_cast<ui::Dataspace>(input.readUint32());
Peiyong Linc502cb72019-03-01 23:00:23180 colorSpaceAgnostic = input.readBool();
Valerie Haued54efa2019-01-12 04:03:14181
Valerie Hau9dab9732019-08-20 16:29:25182 int32_t numListeners = input.readInt32();
183 listeners.clear();
184 for (int i = 0; i < numListeners; i++) {
185 auto listener = input.readStrongBinder();
186 std::vector<CallbackId> callbackIds;
187 input.readInt64Vector(&callbackIds);
188 listeners.emplace_back(listener, callbackIds);
189 }
Vishnu Nair440992f2019-12-10 03:53:19190 shadowRadius = input.readFloat();
The Android Open Source Projectedbf3b62009-03-04 03:31:44191 return NO_ERROR;
192}
193
Mathias Agopian698c0872011-06-29 02:09:31194status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-29 02:09:31195 return state.write(output);
196}
197
198status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-29 02:09:31199 return state.read(input);
200}
201
Mathias Agopian8b33f032012-07-25 03:43:54202
Pablo Ceballos60d69222015-08-07 21:47:20203DisplayState::DisplayState() :
204 what(0),
205 layerStack(0),
206 orientation(eOrientationDefault),
207 viewport(Rect::EMPTY_RECT),
208 frame(Rect::EMPTY_RECT),
209 width(0),
210 height(0) {
211}
212
Mathias Agopian8b33f032012-07-25 03:43:54213status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 23:29:12214 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 16:01:01215 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 18:24:03216 output.writeUint32(what);
217 output.writeUint32(layerStack);
218 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-13 02:37:16219 output.write(viewport);
220 output.write(frame);
Dan Stozad723bd72014-11-18 18:24:03221 output.writeUint32(width);
222 output.writeUint32(height);
Mathias Agopian8b33f032012-07-25 03:43:54223 return NO_ERROR;
224}
225
226status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 23:29:12227 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 17:49:45228 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 18:24:03229 what = input.readUint32();
230 layerStack = input.readUint32();
231 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-13 02:37:16232 input.read(viewport);
233 input.read(frame);
Dan Stozad723bd72014-11-18 18:24:03234 width = input.readUint32();
235 height = input.readUint32();
Mathias Agopian8b33f032012-07-25 03:43:54236 return NO_ERROR;
237}
238
Robert Carr2c5f6d22017-09-26 19:30:35239void DisplayState::merge(const DisplayState& other) {
240 if (other.what & eSurfaceChanged) {
241 what |= eSurfaceChanged;
242 surface = other.surface;
243 }
244 if (other.what & eLayerStackChanged) {
245 what |= eLayerStackChanged;
246 layerStack = other.layerStack;
247 }
248 if (other.what & eDisplayProjectionChanged) {
249 what |= eDisplayProjectionChanged;
250 orientation = other.orientation;
251 viewport = other.viewport;
252 frame = other.frame;
253 }
254 if (other.what & eDisplaySizeChanged) {
255 what |= eDisplaySizeChanged;
256 width = other.width;
257 height = other.height;
258 }
259}
260
261void layer_state_t::merge(const layer_state_t& other) {
262 if (other.what & ePositionChanged) {
263 what |= ePositionChanged;
264 x = other.x;
265 y = other.y;
266 }
267 if (other.what & eLayerChanged) {
268 what |= eLayerChanged;
chaviw32377582019-05-13 18:15:19269 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 19:30:35270 z = other.z;
271 }
272 if (other.what & eSizeChanged) {
273 what |= eSizeChanged;
274 w = other.w;
275 h = other.h;
276 }
277 if (other.what & eAlphaChanged) {
278 what |= eAlphaChanged;
279 alpha = other.alpha;
280 }
281 if (other.what & eMatrixChanged) {
282 what |= eMatrixChanged;
283 matrix = other.matrix;
284 }
285 if (other.what & eTransparentRegionChanged) {
286 what |= eTransparentRegionChanged;
287 transparentRegion = other.transparentRegion;
288 }
289 if (other.what & eFlagsChanged) {
290 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 21:15:33291 flags &= ~other.mask;
292 flags |= (other.flags & other.mask);
293 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 19:30:35294 }
295 if (other.what & eLayerStackChanged) {
296 what |= eLayerStackChanged;
297 layerStack = other.layerStack;
298 }
Marissa Wallf58c14b2018-07-24 17:50:43299 if (other.what & eCropChanged_legacy) {
300 what |= eCropChanged_legacy;
301 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 19:30:35302 }
Lucas Dupin1b6531c2018-07-06 00:18:21303 if (other.what & eCornerRadiusChanged) {
304 what |= eCornerRadiusChanged;
305 cornerRadius = other.cornerRadius;
306 }
Marissa Wallf58c14b2018-07-24 17:50:43307 if (other.what & eDeferTransaction_legacy) {
308 what |= eDeferTransaction_legacy;
309 barrierHandle_legacy = other.barrierHandle_legacy;
310 barrierGbp_legacy = other.barrierGbp_legacy;
311 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 19:30:35312 }
Robert Carr2c5f6d22017-09-26 19:30:35313 if (other.what & eOverrideScalingModeChanged) {
314 what |= eOverrideScalingModeChanged;
315 overrideScalingMode = other.overrideScalingMode;
316 }
Robert Carr2c5f6d22017-09-26 19:30:35317 if (other.what & eReparentChildren) {
318 what |= eReparentChildren;
319 reparentHandle = other.reparentHandle;
320 }
321 if (other.what & eDetachChildren) {
322 what |= eDetachChildren;
323 }
324 if (other.what & eRelativeLayerChanged) {
325 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 18:15:19326 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 19:30:35327 z = other.z;
328 relativeLayerHandle = other.relativeLayerHandle;
329 }
330 if (other.what & eReparent) {
331 what |= eReparent;
332 parentHandleForChild = other.parentHandleForChild;
333 }
chaviwca27f252018-02-07 00:46:39334 if (other.what & eDestroySurface) {
335 what |= eDestroySurface;
336 }
Marissa Wall61c58622018-07-18 17:12:20337 if (other.what & eTransformChanged) {
338 what |= eTransformChanged;
339 transform = other.transform;
340 }
341 if (other.what & eTransformToDisplayInverseChanged) {
342 what |= eTransformToDisplayInverseChanged;
343 transformToDisplayInverse = other.transformToDisplayInverse;
344 }
345 if (other.what & eCropChanged) {
346 what |= eCropChanged;
347 crop = other.crop;
348 }
Marissa Wall861616d2018-10-22 19:52:23349 if (other.what & eFrameChanged) {
350 what |= eFrameChanged;
351 frame = other.frame;
352 }
Marissa Wall61c58622018-07-18 17:12:20353 if (other.what & eBufferChanged) {
354 what |= eBufferChanged;
355 buffer = other.buffer;
356 }
357 if (other.what & eAcquireFenceChanged) {
358 what |= eAcquireFenceChanged;
359 acquireFence = other.acquireFence;
360 }
361 if (other.what & eDataspaceChanged) {
362 what |= eDataspaceChanged;
363 dataspace = other.dataspace;
364 }
365 if (other.what & eHdrMetadataChanged) {
366 what |= eHdrMetadataChanged;
367 hdrMetadata = other.hdrMetadata;
368 }
369 if (other.what & eSurfaceDamageRegionChanged) {
370 what |= eSurfaceDamageRegionChanged;
371 surfaceDamageRegion = other.surfaceDamageRegion;
372 }
373 if (other.what & eApiChanged) {
374 what |= eApiChanged;
375 api = other.api;
376 }
377 if (other.what & eSidebandStreamChanged) {
378 what |= eSidebandStreamChanged;
379 sidebandStream = other.sidebandStream;
380 }
Peiyong Lind3788632018-09-18 23:01:31381 if (other.what & eColorTransformChanged) {
382 what |= eColorTransformChanged;
383 colorTransform = other.colorTransform;
384 }
Marissa Wall3dad52d2019-03-22 21:03:19385 if (other.what & eHasListenerCallbacksChanged) {
386 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 17:04:44387 }
Robert Carrd314f162018-08-15 20:12:42388
Robert Carr2c358bf2018-08-08 22:58:15389#ifndef NO_INPUT
390 if (other.what & eInputInfoChanged) {
391 what |= eInputInfoChanged;
392 inputInfo = other.inputInfo;
393 }
394#endif
395
Marissa Wallebc2c052019-01-17 03:16:55396 if (other.what & eCachedBufferChanged) {
397 what |= eCachedBufferChanged;
398 cachedBuffer = other.cachedBuffer;
399 }
Valerie Haudd0b7572019-01-29 22:59:27400 if (other.what & eBackgroundColorChanged) {
401 what |= eBackgroundColorChanged;
402 color = other.color;
403 bgColorAlpha = other.bgColorAlpha;
404 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-12 04:03:14405 }
Evan Rosky1f6d6d52018-12-06 18:47:26406 if (other.what & eMetadataChanged) {
407 what |= eMetadataChanged;
408 metadata.merge(other.metadata);
409 }
Vishnu Nairc97b8db2019-10-30 01:19:35410
411 if (other.what & eShadowRadiusChanged) {
412 what |= eShadowRadiusChanged;
413 shadowRadius = other.shadowRadius;
414 }
415
Vishnu Nair217d8e62018-09-12 23:34:49416 if ((other.what & what) != other.what) {
417 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 21:21:07418 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 23:34:49419 other.what, what);
Robert Carrd314f162018-08-15 20:12:42420 }
Robert Carr2c5f6d22017-09-26 19:30:35421}
Mathias Agopian8b33f032012-07-25 03:43:54422
chaviw273171b2018-12-26 19:46:30423// ------------------------------- InputWindowCommands ----------------------------------------
424
425void InputWindowCommands::merge(const InputWindowCommands& other) {
426 transferTouchFocusCommands
427 .insert(transferTouchFocusCommands.end(),
428 std::make_move_iterator(other.transferTouchFocusCommands.begin()),
429 std::make_move_iterator(other.transferTouchFocusCommands.end()));
chaviwa911b102019-02-14 18:18:33430
431 syncInputWindows |= other.syncInputWindows;
chaviw273171b2018-12-26 19:46:30432}
433
434void InputWindowCommands::clear() {
435 transferTouchFocusCommands.clear();
chaviwa911b102019-02-14 18:18:33436 syncInputWindows = false;
chaviw273171b2018-12-26 19:46:30437}
438
439void InputWindowCommands::write(Parcel& output) const {
440 output.writeUint32(static_cast<uint32_t>(transferTouchFocusCommands.size()));
441 for (const auto& transferTouchFocusCommand : transferTouchFocusCommands) {
442 output.writeStrongBinder(transferTouchFocusCommand.fromToken);
443 output.writeStrongBinder(transferTouchFocusCommand.toToken);
444 }
chaviwa911b102019-02-14 18:18:33445
446 output.writeBool(syncInputWindows);
chaviw273171b2018-12-26 19:46:30447}
448
449void InputWindowCommands::read(const Parcel& input) {
450 size_t count = input.readUint32();
451 transferTouchFocusCommands.clear();
452 for (size_t i = 0; i < count; i++) {
453 TransferTouchFocusCommand transferTouchFocusCommand;
454 transferTouchFocusCommand.fromToken = input.readStrongBinder();
455 transferTouchFocusCommand.toToken = input.readStrongBinder();
456 transferTouchFocusCommands.emplace_back(transferTouchFocusCommand);
457 }
chaviwa911b102019-02-14 18:18:33458
459 syncInputWindows = input.readBool();
chaviw273171b2018-12-26 19:46:30460}
461
The Android Open Source Projectedbf3b62009-03-04 03:31:44462}; // namespace android