blob: 523ed1d2ce7d47681447d711958567494023f715 [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);
Marissa Wall3dad52d2019-03-22 14:03:19 -070089 output.writeBool(hasListenerCallbacks);
Steven Moreland9d4ce9b2019-07-17 15:23:38 -070090 output.writeStrongBinder(cachedBuffer.token.promote());
Marissa Wall947d34e2019-03-29 14:03:53 -070091 output.writeUint64(cachedBuffer.id);
Evan Rosky1f6d6d52018-12-06 10:47:26 -080092 output.writeParcelable(metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -080093
Valerie Haudd0b7572019-01-29 14:59:27 -080094 output.writeFloat(bgColorAlpha);
95 output.writeUint32(static_cast<uint32_t>(bgColorDataspace));
Peiyong Linc502cb72019-03-01 15:00:23 -080096 output.writeBool(colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -080097
Mathias Agopianac9fa422013-02-11 16:40:36 -080098 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099}
100
101status_t layer_state_t::read(const Parcel& input)
102{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800103 surface = input.readStrongBinder();
Garfield Tan8a3083e2018-12-03 13:21:07 -0800104 what = input.readUint64();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800105 x = input.readFloat();
106 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -0800107 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800108 w = input.readUint32();
109 h = input.readUint32();
110 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800111 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800112 flags = static_cast<uint8_t>(input.readUint32());
113 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700114 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
115 if (matrix_data) {
116 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
117 } else {
118 return BAD_VALUE;
119 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700120 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700121 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800122 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700123 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700124 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700125 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700126 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700127 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700128 color.r = input.readFloat();
129 color.g = input.readFloat();
130 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 15:58:15 -0700131
132#ifndef NO_INPUT
133 inputInfo = InputWindowInfo::read(input);
134#endif
135
Mathias Agopianac9fa422013-02-11 16:40:36 -0800136 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700137 transform = input.readUint32();
138 transformToDisplayInverse = input.readBool();
139 input.read(crop);
Marissa Wall861616d2018-10-22 12:52:23 -0700140 input.read(frame);
Marissa Wall61c58622018-07-18 10:12:20 -0700141 buffer = new GraphicBuffer();
142 if (input.readBool()) {
143 input.read(*buffer);
144 }
145 acquireFence = new Fence();
146 if (input.readBool()) {
147 input.read(*acquireFence);
148 }
149 dataspace = static_cast<ui::Dataspace>(input.readUint32());
150 input.read(hdrMetadata);
151 input.read(surfaceDamageRegion);
152 api = input.readInt32();
153 if (input.readBool()) {
154 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
155 }
156
Peiyong Lind3788632018-09-18 16:01:31 -0700157 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700158 cornerRadius = input.readFloat();
Marissa Wall3dad52d2019-03-22 14:03:19 -0700159 hasListenerCallbacks = input.readBool();
Steven Moreland9d4ce9b2019-07-17 15:23:38 -0700160 cachedBuffer.token = input.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -0700161 cachedBuffer.id = input.readUint64();
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800162 input.readParcelable(&metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800163
Valerie Haudd0b7572019-01-29 14:59:27 -0800164 bgColorAlpha = input.readFloat();
165 bgColorDataspace = static_cast<ui::Dataspace>(input.readUint32());
Peiyong Linc502cb72019-03-01 15:00:23 -0800166 colorSpaceAgnostic = input.readBool();
Valerie Haued54efa2019-01-11 20:03:14 -0800167
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168 return NO_ERROR;
169}
170
Mathias Agopian698c0872011-06-28 19:09:31 -0700171status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700172 return state.write(output);
173}
174
175status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700176 return state.read(input);
177}
178
Mathias Agopian8b33f032012-07-24 20:43:54 -0700179
Pablo Ceballos60d69222015-08-07 14:47:20 -0700180DisplayState::DisplayState() :
181 what(0),
182 layerStack(0),
183 orientation(eOrientationDefault),
184 viewport(Rect::EMPTY_RECT),
185 frame(Rect::EMPTY_RECT),
186 width(0),
187 height(0) {
188}
189
Mathias Agopian8b33f032012-07-24 20:43:54 -0700190status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700191 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800192 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800193 output.writeUint32(what);
194 output.writeUint32(layerStack);
195 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700196 output.write(viewport);
197 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800198 output.writeUint32(width);
199 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700200 return NO_ERROR;
201}
202
203status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700204 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800205 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800206 what = input.readUint32();
207 layerStack = input.readUint32();
208 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700209 input.read(viewport);
210 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800211 width = input.readUint32();
212 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700213 return NO_ERROR;
214}
215
Robert Carr2c5f6d22017-09-26 12:30:35 -0700216void DisplayState::merge(const DisplayState& other) {
217 if (other.what & eSurfaceChanged) {
218 what |= eSurfaceChanged;
219 surface = other.surface;
220 }
221 if (other.what & eLayerStackChanged) {
222 what |= eLayerStackChanged;
223 layerStack = other.layerStack;
224 }
225 if (other.what & eDisplayProjectionChanged) {
226 what |= eDisplayProjectionChanged;
227 orientation = other.orientation;
228 viewport = other.viewport;
229 frame = other.frame;
230 }
231 if (other.what & eDisplaySizeChanged) {
232 what |= eDisplaySizeChanged;
233 width = other.width;
234 height = other.height;
235 }
236}
237
238void layer_state_t::merge(const layer_state_t& other) {
239 if (other.what & ePositionChanged) {
240 what |= ePositionChanged;
241 x = other.x;
242 y = other.y;
243 }
244 if (other.what & eLayerChanged) {
245 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700246 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700247 z = other.z;
248 }
249 if (other.what & eSizeChanged) {
250 what |= eSizeChanged;
251 w = other.w;
252 h = other.h;
253 }
254 if (other.what & eAlphaChanged) {
255 what |= eAlphaChanged;
256 alpha = other.alpha;
257 }
258 if (other.what & eMatrixChanged) {
259 what |= eMatrixChanged;
260 matrix = other.matrix;
261 }
262 if (other.what & eTransparentRegionChanged) {
263 what |= eTransparentRegionChanged;
264 transparentRegion = other.transparentRegion;
265 }
266 if (other.what & eFlagsChanged) {
267 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700268 flags &= ~other.mask;
269 flags |= (other.flags & other.mask);
270 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700271 }
272 if (other.what & eLayerStackChanged) {
273 what |= eLayerStackChanged;
274 layerStack = other.layerStack;
275 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700276 if (other.what & eCropChanged_legacy) {
277 what |= eCropChanged_legacy;
278 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700279 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700280 if (other.what & eCornerRadiusChanged) {
281 what |= eCornerRadiusChanged;
282 cornerRadius = other.cornerRadius;
283 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700284 if (other.what & eDeferTransaction_legacy) {
285 what |= eDeferTransaction_legacy;
286 barrierHandle_legacy = other.barrierHandle_legacy;
287 barrierGbp_legacy = other.barrierGbp_legacy;
288 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700289 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700290 if (other.what & eOverrideScalingModeChanged) {
291 what |= eOverrideScalingModeChanged;
292 overrideScalingMode = other.overrideScalingMode;
293 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700294 if (other.what & eReparentChildren) {
295 what |= eReparentChildren;
296 reparentHandle = other.reparentHandle;
297 }
298 if (other.what & eDetachChildren) {
299 what |= eDetachChildren;
300 }
301 if (other.what & eRelativeLayerChanged) {
302 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700303 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700304 z = other.z;
305 relativeLayerHandle = other.relativeLayerHandle;
306 }
307 if (other.what & eReparent) {
308 what |= eReparent;
309 parentHandleForChild = other.parentHandleForChild;
310 }
chaviwca27f252018-02-06 16:46:39 -0800311 if (other.what & eDestroySurface) {
312 what |= eDestroySurface;
313 }
Marissa Wall61c58622018-07-18 10:12:20 -0700314 if (other.what & eTransformChanged) {
315 what |= eTransformChanged;
316 transform = other.transform;
317 }
318 if (other.what & eTransformToDisplayInverseChanged) {
319 what |= eTransformToDisplayInverseChanged;
320 transformToDisplayInverse = other.transformToDisplayInverse;
321 }
322 if (other.what & eCropChanged) {
323 what |= eCropChanged;
324 crop = other.crop;
325 }
Marissa Wall861616d2018-10-22 12:52:23 -0700326 if (other.what & eFrameChanged) {
327 what |= eFrameChanged;
328 frame = other.frame;
329 }
Marissa Wall61c58622018-07-18 10:12:20 -0700330 if (other.what & eBufferChanged) {
331 what |= eBufferChanged;
332 buffer = other.buffer;
333 }
334 if (other.what & eAcquireFenceChanged) {
335 what |= eAcquireFenceChanged;
336 acquireFence = other.acquireFence;
337 }
338 if (other.what & eDataspaceChanged) {
339 what |= eDataspaceChanged;
340 dataspace = other.dataspace;
341 }
342 if (other.what & eHdrMetadataChanged) {
343 what |= eHdrMetadataChanged;
344 hdrMetadata = other.hdrMetadata;
345 }
346 if (other.what & eSurfaceDamageRegionChanged) {
347 what |= eSurfaceDamageRegionChanged;
348 surfaceDamageRegion = other.surfaceDamageRegion;
349 }
350 if (other.what & eApiChanged) {
351 what |= eApiChanged;
352 api = other.api;
353 }
354 if (other.what & eSidebandStreamChanged) {
355 what |= eSidebandStreamChanged;
356 sidebandStream = other.sidebandStream;
357 }
Peiyong Lind3788632018-09-18 16:01:31 -0700358 if (other.what & eColorTransformChanged) {
359 what |= eColorTransformChanged;
360 colorTransform = other.colorTransform;
361 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700362 if (other.what & eHasListenerCallbacksChanged) {
363 what |= eHasListenerCallbacksChanged;
364 hasListenerCallbacks = other.hasListenerCallbacks;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700365 }
Robert Carrd314f162018-08-15 13:12:42 -0700366
Robert Carr2c358bf2018-08-08 15:58:15 -0700367#ifndef NO_INPUT
368 if (other.what & eInputInfoChanged) {
369 what |= eInputInfoChanged;
370 inputInfo = other.inputInfo;
371 }
372#endif
373
Marissa Wallebc2c052019-01-16 19:16:55 -0800374 if (other.what & eCachedBufferChanged) {
375 what |= eCachedBufferChanged;
376 cachedBuffer = other.cachedBuffer;
377 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800378 if (other.what & eBackgroundColorChanged) {
379 what |= eBackgroundColorChanged;
380 color = other.color;
381 bgColorAlpha = other.bgColorAlpha;
382 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800383 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800384 if (other.what & eMetadataChanged) {
385 what |= eMetadataChanged;
386 metadata.merge(other.metadata);
387 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700388 if ((other.what & what) != other.what) {
389 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 13:21:07 -0800390 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 16:34:49 -0700391 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700392 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700393}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700394
chaviw273171b2018-12-26 11:46:30 -0800395// ------------------------------- InputWindowCommands ----------------------------------------
396
397void InputWindowCommands::merge(const InputWindowCommands& other) {
398 transferTouchFocusCommands
399 .insert(transferTouchFocusCommands.end(),
400 std::make_move_iterator(other.transferTouchFocusCommands.begin()),
401 std::make_move_iterator(other.transferTouchFocusCommands.end()));
chaviwa911b102019-02-14 10:18:33 -0800402
403 syncInputWindows |= other.syncInputWindows;
chaviw273171b2018-12-26 11:46:30 -0800404}
405
406void InputWindowCommands::clear() {
407 transferTouchFocusCommands.clear();
chaviwa911b102019-02-14 10:18:33 -0800408 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800409}
410
411void InputWindowCommands::write(Parcel& output) const {
412 output.writeUint32(static_cast<uint32_t>(transferTouchFocusCommands.size()));
413 for (const auto& transferTouchFocusCommand : transferTouchFocusCommands) {
414 output.writeStrongBinder(transferTouchFocusCommand.fromToken);
415 output.writeStrongBinder(transferTouchFocusCommand.toToken);
416 }
chaviwa911b102019-02-14 10:18:33 -0800417
418 output.writeBool(syncInputWindows);
chaviw273171b2018-12-26 11:46:30 -0800419}
420
421void InputWindowCommands::read(const Parcel& input) {
422 size_t count = input.readUint32();
423 transferTouchFocusCommands.clear();
424 for (size_t i = 0; i < count; i++) {
425 TransferTouchFocusCommand transferTouchFocusCommand;
426 transferTouchFocusCommand.fromToken = input.readStrongBinder();
427 transferTouchFocusCommand.toToken = input.readStrongBinder();
428 transferTouchFocusCommands.emplace_back(transferTouchFocusCommand);
429 }
chaviwa911b102019-02-14 10:18:33 -0800430
431 syncInputWindows = input.readBool();
chaviw273171b2018-12-26 11:46:30 -0800432}
433
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800434}; // namespace android