blob: ab929731f3e6383888e9e5a20df0d002333ed313 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 16:34:49 -070017#define LOG_TAG "LayerState"
18
Garfield Tan8a3083e2018-12-03 13:21:07 -080019#include <inttypes.h>
20
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021#include <utils/Errors.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070022#include <binder/Parcel.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080023#include <gui/ISurfaceComposerClient.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080024#include <gui/IGraphicBufferProducer.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070025#include <gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026
27namespace android {
28
29status_t layer_state_t::write(Parcel& output) const
30{
Mathias Agopianac9fa422013-02-11 16:40:36 -080031 output.writeStrongBinder(surface);
Garfield Tan8a3083e2018-12-03 13:21:07 -080032 output.writeUint64(what);
Mathias Agopianac9fa422013-02-11 16:40:36 -080033 output.writeFloat(x);
34 output.writeFloat(y);
Robert Carrae060832016-11-28 10:51:00 -080035 output.writeInt32(z);
Dan Stozad723bd72014-11-18 10:24:03 -080036 output.writeUint32(w);
37 output.writeUint32(h);
38 output.writeUint32(layerStack);
Mathias Agopianac9fa422013-02-11 16:40:36 -080039 output.writeFloat(alpha);
Dan Stozad723bd72014-11-18 10:24:03 -080040 output.writeUint32(flags);
41 output.writeUint32(mask);
Mathias Agopianac9fa422013-02-11 16:40:36 -080042 *reinterpret_cast<layer_state_t::matrix22_t *>(
43 output.writeInplace(sizeof(layer_state_t::matrix22_t))) = matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -070044 output.write(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -070045 output.writeStrongBinder(barrierHandle_legacy);
Robert Carr1db73f62016-12-21 12:58:51 -080046 output.writeStrongBinder(reparentHandle);
Marissa Wallf58c14b2018-07-24 10:50:43 -070047 output.writeUint64(frameNumber_legacy);
Robert Carrc3574f72016-03-24 12:19:32 -070048 output.writeInt32(overrideScalingMode);
Marissa Wallf58c14b2018-07-24 10:50:43 -070049 output.writeStrongBinder(IInterface::asBinder(barrierGbp_legacy));
Robert Carrdb66e622017-04-10 16:55:57 -070050 output.writeStrongBinder(relativeLayerHandle);
chaviw06178942017-07-27 10:25:59 -070051 output.writeStrongBinder(parentHandleForChild);
chaviw13fdc492017-06-27 12:40:18 -070052 output.writeFloat(color.r);
53 output.writeFloat(color.g);
54 output.writeFloat(color.b);
Robert Carr2c358bf2018-08-08 15:58:15 -070055#ifndef NO_INPUT
56 inputInfo.write(output);
57#endif
Mathias Agopianac9fa422013-02-11 16:40:36 -080058 output.write(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -070059 output.writeUint32(transform);
60 output.writeBool(transformToDisplayInverse);
61 output.write(crop);
Marissa Wall861616d2018-10-22 12:52:23 -070062 output.write(frame);
Marissa Wall61c58622018-07-18 10:12:20 -070063 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 16:01:31 -070086 memcpy(output.writeInplace(16 * sizeof(float)),
87 colorTransform.asArray(), 16 * sizeof(float));
Lucas Dupin1b6531c2018-07-05 17:18:21 -070088 output.writeFloat(cornerRadius);
Peiyong Lind3788632018-09-18 16:01:31 -070089
Marissa Wallc837b5e2018-10-12 10:04:44 -070090 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-16 19:16:55 -080097 output.writeStrongBinder(cachedBuffer.token);
98 output.writeInt32(cachedBuffer.bufferId);
99
Valerie Haued54efa2019-01-11 20:03:14 -0800100 output.writeFloat(colorAlpha);
101 output.writeUint32(static_cast<uint32_t>(colorDataspace));
102
Mathias Agopianac9fa422013-02-11 16:40:36 -0800103 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104}
105
106status_t layer_state_t::read(const Parcel& input)
107{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800108 surface = input.readStrongBinder();
Garfield Tan8a3083e2018-12-03 13:21:07 -0800109 what = input.readUint64();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800110 x = input.readFloat();
111 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -0800112 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800113 w = input.readUint32();
114 h = input.readUint32();
115 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800116 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800117 flags = static_cast<uint8_t>(input.readUint32());
118 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700119 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
120 if (matrix_data) {
121 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
122 } else {
123 return BAD_VALUE;
124 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700125 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700126 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800127 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700128 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700129 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700130 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700131 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700132 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700133 color.r = input.readFloat();
134 color.g = input.readFloat();
135 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 15:58:15 -0700136
137#ifndef NO_INPUT
138 inputInfo = InputWindowInfo::read(input);
139#endif
140
Mathias Agopianac9fa422013-02-11 16:40:36 -0800141 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700142 transform = input.readUint32();
143 transformToDisplayInverse = input.readBool();
144 input.read(crop);
Marissa Wall861616d2018-10-22 12:52:23 -0700145 input.read(frame);
Marissa Wall61c58622018-07-18 10:12:20 -0700146 buffer = new GraphicBuffer();
147 if (input.readBool()) {
148 input.read(*buffer);
149 }
150 acquireFence = new Fence();
151 if (input.readBool()) {
152 input.read(*acquireFence);
153 }
154 dataspace = static_cast<ui::Dataspace>(input.readUint32());
155 input.read(hdrMetadata);
156 input.read(surfaceDamageRegion);
157 api = input.readInt32();
158 if (input.readBool()) {
159 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
160 }
161
Peiyong Lind3788632018-09-18 16:01:31 -0700162 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700163 cornerRadius = input.readFloat();
Peiyong Lind3788632018-09-18 16:01:31 -0700164
Marissa Wallc837b5e2018-10-12 10:04:44 -0700165 int32_t listenersSize = input.readInt32();
166 for (int32_t i = 0; i < listenersSize; i++) {
167 auto listener = interface_cast<ITransactionCompletedListener>(input.readStrongBinder());
168 std::vector<CallbackId> callbackIds;
169 input.readInt64Vector(&callbackIds);
170 listenerCallbacks.emplace_back(listener, callbackIds);
171 }
172
Marissa Wallebc2c052019-01-16 19:16:55 -0800173 cachedBuffer.token = input.readStrongBinder();
174 cachedBuffer.bufferId = input.readInt32();
175
Valerie Haued54efa2019-01-11 20:03:14 -0800176 colorAlpha = input.readFloat();
177 colorDataspace = static_cast<ui::Dataspace>(input.readUint32());
178
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800179 return NO_ERROR;
180}
181
Mathias Agopian698c0872011-06-28 19:09:31 -0700182status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800183 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700184 return state.write(output);
185}
186
187status_t ComposerState::read(const Parcel& input) {
188 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
189 return state.read(input);
190}
191
Mathias Agopian8b33f032012-07-24 20:43:54 -0700192
Pablo Ceballos60d69222015-08-07 14:47:20 -0700193DisplayState::DisplayState() :
194 what(0),
195 layerStack(0),
196 orientation(eOrientationDefault),
197 viewport(Rect::EMPTY_RECT),
198 frame(Rect::EMPTY_RECT),
199 width(0),
200 height(0) {
201}
202
Mathias Agopian8b33f032012-07-24 20:43:54 -0700203status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700204 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800205 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800206 output.writeUint32(what);
207 output.writeUint32(layerStack);
208 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700209 output.write(viewport);
210 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800211 output.writeUint32(width);
212 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700213 return NO_ERROR;
214}
215
216status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700217 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800218 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800219 what = input.readUint32();
220 layerStack = input.readUint32();
221 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700222 input.read(viewport);
223 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800224 width = input.readUint32();
225 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700226 return NO_ERROR;
227}
228
Robert Carr2c5f6d22017-09-26 12:30:35 -0700229void DisplayState::merge(const DisplayState& other) {
230 if (other.what & eSurfaceChanged) {
231 what |= eSurfaceChanged;
232 surface = other.surface;
233 }
234 if (other.what & eLayerStackChanged) {
235 what |= eLayerStackChanged;
236 layerStack = other.layerStack;
237 }
238 if (other.what & eDisplayProjectionChanged) {
239 what |= eDisplayProjectionChanged;
240 orientation = other.orientation;
241 viewport = other.viewport;
242 frame = other.frame;
243 }
244 if (other.what & eDisplaySizeChanged) {
245 what |= eDisplaySizeChanged;
246 width = other.width;
247 height = other.height;
248 }
249}
250
251void layer_state_t::merge(const layer_state_t& other) {
252 if (other.what & ePositionChanged) {
253 what |= ePositionChanged;
254 x = other.x;
255 y = other.y;
256 }
257 if (other.what & eLayerChanged) {
258 what |= eLayerChanged;
259 z = other.z;
260 }
261 if (other.what & eSizeChanged) {
262 what |= eSizeChanged;
263 w = other.w;
264 h = other.h;
265 }
266 if (other.what & eAlphaChanged) {
267 what |= eAlphaChanged;
268 alpha = other.alpha;
269 }
270 if (other.what & eMatrixChanged) {
271 what |= eMatrixChanged;
272 matrix = other.matrix;
273 }
274 if (other.what & eTransparentRegionChanged) {
275 what |= eTransparentRegionChanged;
276 transparentRegion = other.transparentRegion;
277 }
278 if (other.what & eFlagsChanged) {
279 what |= eFlagsChanged;
280 flags = other.flags;
281 mask = other.mask;
282 }
283 if (other.what & eLayerStackChanged) {
284 what |= eLayerStackChanged;
285 layerStack = other.layerStack;
286 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700287 if (other.what & eCropChanged_legacy) {
288 what |= eCropChanged_legacy;
289 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700290 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700291 if (other.what & eCornerRadiusChanged) {
292 what |= eCornerRadiusChanged;
293 cornerRadius = other.cornerRadius;
294 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700295 if (other.what & eDeferTransaction_legacy) {
296 what |= eDeferTransaction_legacy;
297 barrierHandle_legacy = other.barrierHandle_legacy;
298 barrierGbp_legacy = other.barrierGbp_legacy;
299 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700300 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700301 if (other.what & eOverrideScalingModeChanged) {
302 what |= eOverrideScalingModeChanged;
303 overrideScalingMode = other.overrideScalingMode;
304 }
305 if (other.what & eGeometryAppliesWithResize) {
306 what |= eGeometryAppliesWithResize;
307 }
308 if (other.what & eReparentChildren) {
309 what |= eReparentChildren;
310 reparentHandle = other.reparentHandle;
311 }
312 if (other.what & eDetachChildren) {
313 what |= eDetachChildren;
314 }
315 if (other.what & eRelativeLayerChanged) {
316 what |= eRelativeLayerChanged;
317 z = other.z;
318 relativeLayerHandle = other.relativeLayerHandle;
319 }
320 if (other.what & eReparent) {
321 what |= eReparent;
322 parentHandleForChild = other.parentHandleForChild;
323 }
chaviwca27f252018-02-06 16:46:39 -0800324 if (other.what & eDestroySurface) {
325 what |= eDestroySurface;
326 }
Marissa Wall61c58622018-07-18 10:12:20 -0700327 if (other.what & eTransformChanged) {
328 what |= eTransformChanged;
329 transform = other.transform;
330 }
331 if (other.what & eTransformToDisplayInverseChanged) {
332 what |= eTransformToDisplayInverseChanged;
333 transformToDisplayInverse = other.transformToDisplayInverse;
334 }
335 if (other.what & eCropChanged) {
336 what |= eCropChanged;
337 crop = other.crop;
338 }
Marissa Wall861616d2018-10-22 12:52:23 -0700339 if (other.what & eFrameChanged) {
340 what |= eFrameChanged;
341 frame = other.frame;
342 }
Marissa Wall61c58622018-07-18 10:12:20 -0700343 if (other.what & eBufferChanged) {
344 what |= eBufferChanged;
345 buffer = other.buffer;
346 }
347 if (other.what & eAcquireFenceChanged) {
348 what |= eAcquireFenceChanged;
349 acquireFence = other.acquireFence;
350 }
351 if (other.what & eDataspaceChanged) {
352 what |= eDataspaceChanged;
353 dataspace = other.dataspace;
354 }
355 if (other.what & eHdrMetadataChanged) {
356 what |= eHdrMetadataChanged;
357 hdrMetadata = other.hdrMetadata;
358 }
359 if (other.what & eSurfaceDamageRegionChanged) {
360 what |= eSurfaceDamageRegionChanged;
361 surfaceDamageRegion = other.surfaceDamageRegion;
362 }
363 if (other.what & eApiChanged) {
364 what |= eApiChanged;
365 api = other.api;
366 }
367 if (other.what & eSidebandStreamChanged) {
368 what |= eSidebandStreamChanged;
369 sidebandStream = other.sidebandStream;
370 }
Peiyong Lind3788632018-09-18 16:01:31 -0700371 if (other.what & eColorTransformChanged) {
372 what |= eColorTransformChanged;
373 colorTransform = other.colorTransform;
374 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700375 if (other.what & eListenerCallbacksChanged) {
376 what |= eListenerCallbacksChanged;
377 listenerCallbacks = other.listenerCallbacks;
378 }
Robert Carrd314f162018-08-15 13:12:42 -0700379
Robert Carr2c358bf2018-08-08 15:58:15 -0700380#ifndef NO_INPUT
381 if (other.what & eInputInfoChanged) {
382 what |= eInputInfoChanged;
383 inputInfo = other.inputInfo;
384 }
385#endif
386
Marissa Wallebc2c052019-01-16 19:16:55 -0800387 if (other.what & eCachedBufferChanged) {
388 what |= eCachedBufferChanged;
389 cachedBuffer = other.cachedBuffer;
390 }
Valerie Haued54efa2019-01-11 20:03:14 -0800391 if (other.what & eColorAlphaChanged) {
392 what |= eColorAlphaChanged;
393 colorAlpha = other.colorAlpha;
394 }
395 if (other.what & eColorDataspaceChanged) {
396 what |= eColorDataspaceChanged;
397 colorDataspace = other.colorDataspace;
398 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700399 if ((other.what & what) != other.what) {
400 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 13:21:07 -0800401 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 16:34:49 -0700402 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700403 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700404}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700405
chaviw273171b2018-12-26 11:46:30 -0800406// ------------------------------- InputWindowCommands ----------------------------------------
407
408void InputWindowCommands::merge(const InputWindowCommands& other) {
409 transferTouchFocusCommands
410 .insert(transferTouchFocusCommands.end(),
411 std::make_move_iterator(other.transferTouchFocusCommands.begin()),
412 std::make_move_iterator(other.transferTouchFocusCommands.end()));
413}
414
415void InputWindowCommands::clear() {
416 transferTouchFocusCommands.clear();
417}
418
419void InputWindowCommands::write(Parcel& output) const {
420 output.writeUint32(static_cast<uint32_t>(transferTouchFocusCommands.size()));
421 for (const auto& transferTouchFocusCommand : transferTouchFocusCommands) {
422 output.writeStrongBinder(transferTouchFocusCommand.fromToken);
423 output.writeStrongBinder(transferTouchFocusCommand.toToken);
424 }
425}
426
427void InputWindowCommands::read(const Parcel& input) {
428 size_t count = input.readUint32();
429 transferTouchFocusCommands.clear();
430 for (size_t i = 0; i < count; i++) {
431 TransferTouchFocusCommand transferTouchFocusCommand;
432 transferTouchFocusCommand.fromToken = input.readStrongBinder();
433 transferTouchFocusCommand.toToken = input.readStrongBinder();
434 transferTouchFocusCommands.emplace_back(transferTouchFocusCommand);
435 }
436}
437
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800438}; // namespace android