blob: 40b55fa28be252ab02295c0375ce032dc901ecbc [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
Mathias Agopianac9fa422013-02-11 16:40:36 -0800100 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101}
102
103status_t layer_state_t::read(const Parcel& input)
104{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800105 surface = input.readStrongBinder();
Garfield Tan8a3083e2018-12-03 13:21:07 -0800106 what = input.readUint64();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800107 x = input.readFloat();
108 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -0800109 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800110 w = input.readUint32();
111 h = input.readUint32();
112 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800113 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800114 flags = static_cast<uint8_t>(input.readUint32());
115 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700116 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
117 if (matrix_data) {
118 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
119 } else {
120 return BAD_VALUE;
121 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700122 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700123 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800124 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700125 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700126 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700127 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700128 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700129 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700130 color.r = input.readFloat();
131 color.g = input.readFloat();
132 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 15:58:15 -0700133
134#ifndef NO_INPUT
135 inputInfo = InputWindowInfo::read(input);
136#endif
137
Mathias Agopianac9fa422013-02-11 16:40:36 -0800138 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700139 transform = input.readUint32();
140 transformToDisplayInverse = input.readBool();
141 input.read(crop);
Marissa Wall861616d2018-10-22 12:52:23 -0700142 input.read(frame);
Marissa Wall61c58622018-07-18 10:12:20 -0700143 buffer = new GraphicBuffer();
144 if (input.readBool()) {
145 input.read(*buffer);
146 }
147 acquireFence = new Fence();
148 if (input.readBool()) {
149 input.read(*acquireFence);
150 }
151 dataspace = static_cast<ui::Dataspace>(input.readUint32());
152 input.read(hdrMetadata);
153 input.read(surfaceDamageRegion);
154 api = input.readInt32();
155 if (input.readBool()) {
156 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
157 }
158
Peiyong Lind3788632018-09-18 16:01:31 -0700159 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700160 cornerRadius = input.readFloat();
Peiyong Lind3788632018-09-18 16:01:31 -0700161
Marissa Wallc837b5e2018-10-12 10:04:44 -0700162 int32_t listenersSize = input.readInt32();
163 for (int32_t i = 0; i < listenersSize; i++) {
164 auto listener = interface_cast<ITransactionCompletedListener>(input.readStrongBinder());
165 std::vector<CallbackId> callbackIds;
166 input.readInt64Vector(&callbackIds);
167 listenerCallbacks.emplace_back(listener, callbackIds);
168 }
169
Marissa Wallebc2c052019-01-16 19:16:55 -0800170 cachedBuffer.token = input.readStrongBinder();
171 cachedBuffer.bufferId = input.readInt32();
172
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800173 return NO_ERROR;
174}
175
Mathias Agopian698c0872011-06-28 19:09:31 -0700176status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800177 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700178 return state.write(output);
179}
180
181status_t ComposerState::read(const Parcel& input) {
182 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
183 return state.read(input);
184}
185
Mathias Agopian8b33f032012-07-24 20:43:54 -0700186
Pablo Ceballos60d69222015-08-07 14:47:20 -0700187DisplayState::DisplayState() :
188 what(0),
189 layerStack(0),
190 orientation(eOrientationDefault),
191 viewport(Rect::EMPTY_RECT),
192 frame(Rect::EMPTY_RECT),
193 width(0),
194 height(0) {
195}
196
Mathias Agopian8b33f032012-07-24 20:43:54 -0700197status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700198 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800199 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800200 output.writeUint32(what);
201 output.writeUint32(layerStack);
202 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700203 output.write(viewport);
204 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800205 output.writeUint32(width);
206 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700207 return NO_ERROR;
208}
209
210status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700211 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800212 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800213 what = input.readUint32();
214 layerStack = input.readUint32();
215 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700216 input.read(viewport);
217 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800218 width = input.readUint32();
219 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700220 return NO_ERROR;
221}
222
Robert Carr2c5f6d22017-09-26 12:30:35 -0700223void DisplayState::merge(const DisplayState& other) {
224 if (other.what & eSurfaceChanged) {
225 what |= eSurfaceChanged;
226 surface = other.surface;
227 }
228 if (other.what & eLayerStackChanged) {
229 what |= eLayerStackChanged;
230 layerStack = other.layerStack;
231 }
232 if (other.what & eDisplayProjectionChanged) {
233 what |= eDisplayProjectionChanged;
234 orientation = other.orientation;
235 viewport = other.viewport;
236 frame = other.frame;
237 }
238 if (other.what & eDisplaySizeChanged) {
239 what |= eDisplaySizeChanged;
240 width = other.width;
241 height = other.height;
242 }
243}
244
245void layer_state_t::merge(const layer_state_t& other) {
246 if (other.what & ePositionChanged) {
247 what |= ePositionChanged;
248 x = other.x;
249 y = other.y;
250 }
251 if (other.what & eLayerChanged) {
252 what |= eLayerChanged;
253 z = other.z;
254 }
255 if (other.what & eSizeChanged) {
256 what |= eSizeChanged;
257 w = other.w;
258 h = other.h;
259 }
260 if (other.what & eAlphaChanged) {
261 what |= eAlphaChanged;
262 alpha = other.alpha;
263 }
264 if (other.what & eMatrixChanged) {
265 what |= eMatrixChanged;
266 matrix = other.matrix;
267 }
268 if (other.what & eTransparentRegionChanged) {
269 what |= eTransparentRegionChanged;
270 transparentRegion = other.transparentRegion;
271 }
272 if (other.what & eFlagsChanged) {
273 what |= eFlagsChanged;
274 flags = other.flags;
275 mask = other.mask;
276 }
277 if (other.what & eLayerStackChanged) {
278 what |= eLayerStackChanged;
279 layerStack = other.layerStack;
280 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700281 if (other.what & eCropChanged_legacy) {
282 what |= eCropChanged_legacy;
283 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700284 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700285 if (other.what & eCornerRadiusChanged) {
286 what |= eCornerRadiusChanged;
287 cornerRadius = other.cornerRadius;
288 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700289 if (other.what & eDeferTransaction_legacy) {
290 what |= eDeferTransaction_legacy;
291 barrierHandle_legacy = other.barrierHandle_legacy;
292 barrierGbp_legacy = other.barrierGbp_legacy;
293 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700294 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700295 if (other.what & eOverrideScalingModeChanged) {
296 what |= eOverrideScalingModeChanged;
297 overrideScalingMode = other.overrideScalingMode;
298 }
299 if (other.what & eGeometryAppliesWithResize) {
300 what |= eGeometryAppliesWithResize;
301 }
302 if (other.what & eReparentChildren) {
303 what |= eReparentChildren;
304 reparentHandle = other.reparentHandle;
305 }
306 if (other.what & eDetachChildren) {
307 what |= eDetachChildren;
308 }
309 if (other.what & eRelativeLayerChanged) {
310 what |= eRelativeLayerChanged;
311 z = other.z;
312 relativeLayerHandle = other.relativeLayerHandle;
313 }
314 if (other.what & eReparent) {
315 what |= eReparent;
316 parentHandleForChild = other.parentHandleForChild;
317 }
chaviwca27f252018-02-06 16:46:39 -0800318 if (other.what & eDestroySurface) {
319 what |= eDestroySurface;
320 }
Marissa Wall61c58622018-07-18 10:12:20 -0700321 if (other.what & eTransformChanged) {
322 what |= eTransformChanged;
323 transform = other.transform;
324 }
325 if (other.what & eTransformToDisplayInverseChanged) {
326 what |= eTransformToDisplayInverseChanged;
327 transformToDisplayInverse = other.transformToDisplayInverse;
328 }
329 if (other.what & eCropChanged) {
330 what |= eCropChanged;
331 crop = other.crop;
332 }
Marissa Wall861616d2018-10-22 12:52:23 -0700333 if (other.what & eFrameChanged) {
334 what |= eFrameChanged;
335 frame = other.frame;
336 }
Marissa Wall61c58622018-07-18 10:12:20 -0700337 if (other.what & eBufferChanged) {
338 what |= eBufferChanged;
339 buffer = other.buffer;
340 }
341 if (other.what & eAcquireFenceChanged) {
342 what |= eAcquireFenceChanged;
343 acquireFence = other.acquireFence;
344 }
345 if (other.what & eDataspaceChanged) {
346 what |= eDataspaceChanged;
347 dataspace = other.dataspace;
348 }
349 if (other.what & eHdrMetadataChanged) {
350 what |= eHdrMetadataChanged;
351 hdrMetadata = other.hdrMetadata;
352 }
353 if (other.what & eSurfaceDamageRegionChanged) {
354 what |= eSurfaceDamageRegionChanged;
355 surfaceDamageRegion = other.surfaceDamageRegion;
356 }
357 if (other.what & eApiChanged) {
358 what |= eApiChanged;
359 api = other.api;
360 }
361 if (other.what & eSidebandStreamChanged) {
362 what |= eSidebandStreamChanged;
363 sidebandStream = other.sidebandStream;
364 }
Peiyong Lind3788632018-09-18 16:01:31 -0700365 if (other.what & eColorTransformChanged) {
366 what |= eColorTransformChanged;
367 colorTransform = other.colorTransform;
368 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700369 if (other.what & eListenerCallbacksChanged) {
370 what |= eListenerCallbacksChanged;
371 listenerCallbacks = other.listenerCallbacks;
372 }
Robert Carrd314f162018-08-15 13:12:42 -0700373
Robert Carr2c358bf2018-08-08 15:58:15 -0700374#ifndef NO_INPUT
375 if (other.what & eInputInfoChanged) {
376 what |= eInputInfoChanged;
377 inputInfo = other.inputInfo;
378 }
379#endif
380
Marissa Wallebc2c052019-01-16 19:16:55 -0800381 if (other.what & eCachedBufferChanged) {
382 what |= eCachedBufferChanged;
383 cachedBuffer = other.cachedBuffer;
384 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700385 if ((other.what & what) != other.what) {
386 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 13:21:07 -0800387 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 16:34:49 -0700388 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700389 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700390}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700391
chaviw273171b2018-12-26 11:46:30 -0800392// ------------------------------- InputWindowCommands ----------------------------------------
393
394void InputWindowCommands::merge(const InputWindowCommands& other) {
395 transferTouchFocusCommands
396 .insert(transferTouchFocusCommands.end(),
397 std::make_move_iterator(other.transferTouchFocusCommands.begin()),
398 std::make_move_iterator(other.transferTouchFocusCommands.end()));
399}
400
401void InputWindowCommands::clear() {
402 transferTouchFocusCommands.clear();
403}
404
405void InputWindowCommands::write(Parcel& output) const {
406 output.writeUint32(static_cast<uint32_t>(transferTouchFocusCommands.size()));
407 for (const auto& transferTouchFocusCommand : transferTouchFocusCommands) {
408 output.writeStrongBinder(transferTouchFocusCommand.fromToken);
409 output.writeStrongBinder(transferTouchFocusCommand.toToken);
410 }
411}
412
413void InputWindowCommands::read(const Parcel& input) {
414 size_t count = input.readUint32();
415 transferTouchFocusCommands.clear();
416 for (size_t i = 0; i < count; i++) {
417 TransferTouchFocusCommand transferTouchFocusCommand;
418 transferTouchFocusCommand.fromToken = input.readStrongBinder();
419 transferTouchFocusCommand.toToken = input.readStrongBinder();
420 transferTouchFocusCommands.emplace_back(transferTouchFocusCommand);
421 }
422}
423
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800424}; // namespace android