blob: 6091d3f08a0af4e489b3cdb7f8f40dddf08d4d7e [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);
Peiyong Lind3788632018-09-18 23:01:3189
Marissa Wallc837b5e2018-10-12 17:04:4490 if (output.writeVectorSize(listenerCallbacks) == NO_ERROR) {
91 for (const auto& [listener, callbackIds] : listenerCallbacks) {
92 output.writeStrongBinder(IInterface::asBinder(listener));
93 output.writeInt64Vector(callbackIds);
94 }
95 }
96
Marissa Wallebc2c052019-01-17 03:16:5597 output.writeStrongBinder(cachedBuffer.token);
98 output.writeInt32(cachedBuffer.bufferId);
Evan Rosky1f6d6d52018-12-06 18:47:2699 output.writeParcelable(metadata);
Marissa Wallebc2c052019-01-17 03:16:55100
Valerie Haued54efa2019-01-12 04:03:14101 output.writeFloat(colorAlpha);
102 output.writeUint32(static_cast<uint32_t>(colorDataspace));
103
Mathias Agopianac9fa422013-02-12 00:40:36104 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-04 03:31:44105}
106
107status_t layer_state_t::read(const Parcel& input)
108{
Mathias Agopianac9fa422013-02-12 00:40:36109 surface = input.readStrongBinder();
Garfield Tan8a3083e2018-12-03 21:21:07110 what = input.readUint64();
Mathias Agopianac9fa422013-02-12 00:40:36111 x = input.readFloat();
112 y = input.readFloat();
Robert Carrae060832016-11-28 18:51:00113 z = input.readInt32();
Dan Stozad723bd72014-11-18 18:24:03114 w = input.readUint32();
115 h = input.readUint32();
116 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-12 00:40:36117 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 18:24:03118 flags = static_cast<uint8_t>(input.readUint32());
119 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 18:10:13120 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
121 if (matrix_data) {
122 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
123 } else {
124 return BAD_VALUE;
125 }
Marissa Wallf58c14b2018-07-24 17:50:43126 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 17:50:43127 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 20:58:51128 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 17:50:43129 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 19:19:32130 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 17:50:43131 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 23:55:57132 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 17:25:59133 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 19:40:18134 color.r = input.readFloat();
135 color.g = input.readFloat();
136 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 22:58:15137
138#ifndef NO_INPUT
139 inputInfo = InputWindowInfo::read(input);
140#endif
141
Mathias Agopianac9fa422013-02-12 00:40:36142 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 17:12:20143 transform = input.readUint32();
144 transformToDisplayInverse = input.readBool();
145 input.read(crop);
Marissa Wall861616d2018-10-22 19:52:23146 input.read(frame);
Marissa Wall61c58622018-07-18 17:12:20147 buffer = new GraphicBuffer();
148 if (input.readBool()) {
149 input.read(*buffer);
150 }
151 acquireFence = new Fence();
152 if (input.readBool()) {
153 input.read(*acquireFence);
154 }
155 dataspace = static_cast<ui::Dataspace>(input.readUint32());
156 input.read(hdrMetadata);
157 input.read(surfaceDamageRegion);
158 api = input.readInt32();
159 if (input.readBool()) {
160 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
161 }
162
Peiyong Lind3788632018-09-18 23:01:31163 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-06 00:18:21164 cornerRadius = input.readFloat();
Peiyong Lind3788632018-09-18 23:01:31165
Marissa Wallc837b5e2018-10-12 17:04:44166 int32_t listenersSize = input.readInt32();
167 for (int32_t i = 0; i < listenersSize; i++) {
168 auto listener = interface_cast<ITransactionCompletedListener>(input.readStrongBinder());
169 std::vector<CallbackId> callbackIds;
170 input.readInt64Vector(&callbackIds);
171 listenerCallbacks.emplace_back(listener, callbackIds);
172 }
173
Marissa Wallebc2c052019-01-17 03:16:55174 cachedBuffer.token = input.readStrongBinder();
175 cachedBuffer.bufferId = input.readInt32();
Evan Rosky1f6d6d52018-12-06 18:47:26176 input.readParcelable(&metadata);
Marissa Wallebc2c052019-01-17 03:16:55177
Valerie Haued54efa2019-01-12 04:03:14178 colorAlpha = input.readFloat();
179 colorDataspace = static_cast<ui::Dataspace>(input.readUint32());
180
The Android Open Source Projectedbf3b62009-03-04 03:31:44181 return NO_ERROR;
182}
183
Mathias Agopian698c0872011-06-29 02:09:31184status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 16:01:01185 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-29 02:09:31186 return state.write(output);
187}
188
189status_t ComposerState::read(const Parcel& input) {
190 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
191 return state.read(input);
192}
193
Mathias Agopian8b33f032012-07-25 03:43:54194
Pablo Ceballos60d69222015-08-07 21:47:20195DisplayState::DisplayState() :
196 what(0),
197 layerStack(0),
198 orientation(eOrientationDefault),
199 viewport(Rect::EMPTY_RECT),
200 frame(Rect::EMPTY_RECT),
201 width(0),
202 height(0) {
203}
204
Mathias Agopian8b33f032012-07-25 03:43:54205status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 23:29:12206 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 16:01:01207 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 18:24:03208 output.writeUint32(what);
209 output.writeUint32(layerStack);
210 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-13 02:37:16211 output.write(viewport);
212 output.write(frame);
Dan Stozad723bd72014-11-18 18:24:03213 output.writeUint32(width);
214 output.writeUint32(height);
Mathias Agopian8b33f032012-07-25 03:43:54215 return NO_ERROR;
216}
217
218status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 23:29:12219 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 17:49:45220 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 18:24:03221 what = input.readUint32();
222 layerStack = input.readUint32();
223 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-13 02:37:16224 input.read(viewport);
225 input.read(frame);
Dan Stozad723bd72014-11-18 18:24:03226 width = input.readUint32();
227 height = input.readUint32();
Mathias Agopian8b33f032012-07-25 03:43:54228 return NO_ERROR;
229}
230
Robert Carr2c5f6d22017-09-26 19:30:35231void DisplayState::merge(const DisplayState& other) {
232 if (other.what & eSurfaceChanged) {
233 what |= eSurfaceChanged;
234 surface = other.surface;
235 }
236 if (other.what & eLayerStackChanged) {
237 what |= eLayerStackChanged;
238 layerStack = other.layerStack;
239 }
240 if (other.what & eDisplayProjectionChanged) {
241 what |= eDisplayProjectionChanged;
242 orientation = other.orientation;
243 viewport = other.viewport;
244 frame = other.frame;
245 }
246 if (other.what & eDisplaySizeChanged) {
247 what |= eDisplaySizeChanged;
248 width = other.width;
249 height = other.height;
250 }
251}
252
253void layer_state_t::merge(const layer_state_t& other) {
254 if (other.what & ePositionChanged) {
255 what |= ePositionChanged;
256 x = other.x;
257 y = other.y;
258 }
259 if (other.what & eLayerChanged) {
260 what |= eLayerChanged;
261 z = other.z;
262 }
263 if (other.what & eSizeChanged) {
264 what |= eSizeChanged;
265 w = other.w;
266 h = other.h;
267 }
268 if (other.what & eAlphaChanged) {
269 what |= eAlphaChanged;
270 alpha = other.alpha;
271 }
272 if (other.what & eMatrixChanged) {
273 what |= eMatrixChanged;
274 matrix = other.matrix;
275 }
276 if (other.what & eTransparentRegionChanged) {
277 what |= eTransparentRegionChanged;
278 transparentRegion = other.transparentRegion;
279 }
280 if (other.what & eFlagsChanged) {
281 what |= eFlagsChanged;
282 flags = other.flags;
283 mask = other.mask;
284 }
285 if (other.what & eLayerStackChanged) {
286 what |= eLayerStackChanged;
287 layerStack = other.layerStack;
288 }
Marissa Wallf58c14b2018-07-24 17:50:43289 if (other.what & eCropChanged_legacy) {
290 what |= eCropChanged_legacy;
291 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 19:30:35292 }
Lucas Dupin1b6531c2018-07-06 00:18:21293 if (other.what & eCornerRadiusChanged) {
294 what |= eCornerRadiusChanged;
295 cornerRadius = other.cornerRadius;
296 }
Marissa Wallf58c14b2018-07-24 17:50:43297 if (other.what & eDeferTransaction_legacy) {
298 what |= eDeferTransaction_legacy;
299 barrierHandle_legacy = other.barrierHandle_legacy;
300 barrierGbp_legacy = other.barrierGbp_legacy;
301 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 19:30:35302 }
Robert Carr2c5f6d22017-09-26 19:30:35303 if (other.what & eOverrideScalingModeChanged) {
304 what |= eOverrideScalingModeChanged;
305 overrideScalingMode = other.overrideScalingMode;
306 }
307 if (other.what & eGeometryAppliesWithResize) {
308 what |= eGeometryAppliesWithResize;
309 }
310 if (other.what & eReparentChildren) {
311 what |= eReparentChildren;
312 reparentHandle = other.reparentHandle;
313 }
314 if (other.what & eDetachChildren) {
315 what |= eDetachChildren;
316 }
317 if (other.what & eRelativeLayerChanged) {
318 what |= eRelativeLayerChanged;
319 z = other.z;
320 relativeLayerHandle = other.relativeLayerHandle;
321 }
322 if (other.what & eReparent) {
323 what |= eReparent;
324 parentHandleForChild = other.parentHandleForChild;
325 }
chaviwca27f252018-02-07 00:46:39326 if (other.what & eDestroySurface) {
327 what |= eDestroySurface;
328 }
Marissa Wall61c58622018-07-18 17:12:20329 if (other.what & eTransformChanged) {
330 what |= eTransformChanged;
331 transform = other.transform;
332 }
333 if (other.what & eTransformToDisplayInverseChanged) {
334 what |= eTransformToDisplayInverseChanged;
335 transformToDisplayInverse = other.transformToDisplayInverse;
336 }
337 if (other.what & eCropChanged) {
338 what |= eCropChanged;
339 crop = other.crop;
340 }
Marissa Wall861616d2018-10-22 19:52:23341 if (other.what & eFrameChanged) {
342 what |= eFrameChanged;
343 frame = other.frame;
344 }
Marissa Wall61c58622018-07-18 17:12:20345 if (other.what & eBufferChanged) {
346 what |= eBufferChanged;
347 buffer = other.buffer;
348 }
349 if (other.what & eAcquireFenceChanged) {
350 what |= eAcquireFenceChanged;
351 acquireFence = other.acquireFence;
352 }
353 if (other.what & eDataspaceChanged) {
354 what |= eDataspaceChanged;
355 dataspace = other.dataspace;
356 }
357 if (other.what & eHdrMetadataChanged) {
358 what |= eHdrMetadataChanged;
359 hdrMetadata = other.hdrMetadata;
360 }
361 if (other.what & eSurfaceDamageRegionChanged) {
362 what |= eSurfaceDamageRegionChanged;
363 surfaceDamageRegion = other.surfaceDamageRegion;
364 }
365 if (other.what & eApiChanged) {
366 what |= eApiChanged;
367 api = other.api;
368 }
369 if (other.what & eSidebandStreamChanged) {
370 what |= eSidebandStreamChanged;
371 sidebandStream = other.sidebandStream;
372 }
Peiyong Lind3788632018-09-18 23:01:31373 if (other.what & eColorTransformChanged) {
374 what |= eColorTransformChanged;
375 colorTransform = other.colorTransform;
376 }
Marissa Wallc837b5e2018-10-12 17:04:44377 if (other.what & eListenerCallbacksChanged) {
378 what |= eListenerCallbacksChanged;
379 listenerCallbacks = other.listenerCallbacks;
380 }
Robert Carrd314f162018-08-15 20:12:42381
Robert Carr2c358bf2018-08-08 22:58:15382#ifndef NO_INPUT
383 if (other.what & eInputInfoChanged) {
384 what |= eInputInfoChanged;
385 inputInfo = other.inputInfo;
386 }
387#endif
388
Marissa Wallebc2c052019-01-17 03:16:55389 if (other.what & eCachedBufferChanged) {
390 what |= eCachedBufferChanged;
391 cachedBuffer = other.cachedBuffer;
392 }
Valerie Haued54efa2019-01-12 04:03:14393 if (other.what & eColorAlphaChanged) {
394 what |= eColorAlphaChanged;
395 colorAlpha = other.colorAlpha;
396 }
397 if (other.what & eColorDataspaceChanged) {
398 what |= eColorDataspaceChanged;
399 colorDataspace = other.colorDataspace;
400 }
Evan Rosky1f6d6d52018-12-06 18:47:26401 if (other.what & eMetadataChanged) {
402 what |= eMetadataChanged;
403 metadata.merge(other.metadata);
404 }
Vishnu Nair217d8e62018-09-12 23:34:49405 if ((other.what & what) != other.what) {
406 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 21:21:07407 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 23:34:49408 other.what, what);
Robert Carrd314f162018-08-15 20:12:42409 }
Robert Carr2c5f6d22017-09-26 19:30:35410}
Mathias Agopian8b33f032012-07-25 03:43:54411
chaviw273171b2018-12-26 19:46:30412// ------------------------------- InputWindowCommands ----------------------------------------
413
414void InputWindowCommands::merge(const InputWindowCommands& other) {
415 transferTouchFocusCommands
416 .insert(transferTouchFocusCommands.end(),
417 std::make_move_iterator(other.transferTouchFocusCommands.begin()),
418 std::make_move_iterator(other.transferTouchFocusCommands.end()));
419}
420
421void InputWindowCommands::clear() {
422 transferTouchFocusCommands.clear();
423}
424
425void InputWindowCommands::write(Parcel& output) const {
426 output.writeUint32(static_cast<uint32_t>(transferTouchFocusCommands.size()));
427 for (const auto& transferTouchFocusCommand : transferTouchFocusCommands) {
428 output.writeStrongBinder(transferTouchFocusCommand.fromToken);
429 output.writeStrongBinder(transferTouchFocusCommand.toToken);
430 }
431}
432
433void InputWindowCommands::read(const Parcel& input) {
434 size_t count = input.readUint32();
435 transferTouchFocusCommands.clear();
436 for (size_t i = 0; i < count; i++) {
437 TransferTouchFocusCommand transferTouchFocusCommand;
438 transferTouchFocusCommand.fromToken = input.readStrongBinder();
439 transferTouchFocusCommand.toToken = input.readStrongBinder();
440 transferTouchFocusCommands.emplace_back(transferTouchFocusCommand);
441 }
442}
443
The Android Open Source Projectedbf3b62009-03-04 03:31:44444}; // namespace android