blob: 7742503575d7aa3fb3e4f4cf6ac3c9d4667f8c5c [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
Steven Thomas62a4cf82020-01-31 12:04:03 -080027#include <cmath>
28
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029namespace android {
30
31status_t layer_state_t::write(Parcel& output) const
32{
Mathias Agopianac9fa422013-02-11 16:40:36 -080033 output.writeStrongBinder(surface);
Garfield Tan8a3083e2018-12-03 13:21:07 -080034 output.writeUint64(what);
Mathias Agopianac9fa422013-02-11 16:40:36 -080035 output.writeFloat(x);
36 output.writeFloat(y);
Robert Carrae060832016-11-28 10:51:00 -080037 output.writeInt32(z);
Dan Stozad723bd72014-11-18 10:24:03 -080038 output.writeUint32(w);
39 output.writeUint32(h);
40 output.writeUint32(layerStack);
Mathias Agopianac9fa422013-02-11 16:40:36 -080041 output.writeFloat(alpha);
Dan Stozad723bd72014-11-18 10:24:03 -080042 output.writeUint32(flags);
43 output.writeUint32(mask);
Mathias Agopianac9fa422013-02-11 16:40:36 -080044 *reinterpret_cast<layer_state_t::matrix22_t *>(
45 output.writeInplace(sizeof(layer_state_t::matrix22_t))) = matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -070046 output.write(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -070047 output.writeStrongBinder(barrierHandle_legacy);
Robert Carr1db73f62016-12-21 12:58:51 -080048 output.writeStrongBinder(reparentHandle);
Marissa Wallf58c14b2018-07-24 10:50:43 -070049 output.writeUint64(frameNumber_legacy);
Robert Carrc3574f72016-03-24 12:19:32 -070050 output.writeInt32(overrideScalingMode);
Marissa Wallf58c14b2018-07-24 10:50:43 -070051 output.writeStrongBinder(IInterface::asBinder(barrierGbp_legacy));
Robert Carrdb66e622017-04-10 16:55:57 -070052 output.writeStrongBinder(relativeLayerHandle);
chaviw06178942017-07-27 10:25:59 -070053 output.writeStrongBinder(parentHandleForChild);
chaviw13fdc492017-06-27 12:40:18 -070054 output.writeFloat(color.r);
55 output.writeFloat(color.g);
56 output.writeFloat(color.b);
Robert Carr2c358bf2018-08-08 15:58:15 -070057#ifndef NO_INPUT
Chris Ye0783e992020-06-02 21:34:49 -070058 inputHandle->writeToParcel(&output);
Robert Carr2c358bf2018-08-08 15:58:15 -070059#endif
Mathias Agopianac9fa422013-02-11 16:40:36 -080060 output.write(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -070061 output.writeUint32(transform);
62 output.writeBool(transformToDisplayInverse);
63 output.write(crop);
Marissa Wall861616d2018-10-22 12:52:23 -070064 output.write(frame);
Marissa Wall61c58622018-07-18 10:12:20 -070065 if (buffer) {
66 output.writeBool(true);
67 output.write(*buffer);
68 } else {
69 output.writeBool(false);
70 }
71 if (acquireFence) {
72 output.writeBool(true);
73 output.write(*acquireFence);
74 } else {
75 output.writeBool(false);
76 }
77 output.writeUint32(static_cast<uint32_t>(dataspace));
78 output.write(hdrMetadata);
79 output.write(surfaceDamageRegion);
80 output.writeInt32(api);
81 if (sidebandStream) {
82 output.writeBool(true);
83 output.writeNativeHandle(sidebandStream->handle());
84 } else {
85 output.writeBool(false);
86 }
87
Peiyong Lind3788632018-09-18 16:01:31 -070088 memcpy(output.writeInplace(16 * sizeof(float)),
89 colorTransform.asArray(), 16 * sizeof(float));
Lucas Dupin1b6531c2018-07-05 17:18:21 -070090 output.writeFloat(cornerRadius);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -080091 output.writeUint32(backgroundBlurRadius);
Steven Moreland9d4ce9b2019-07-17 15:23:38 -070092 output.writeStrongBinder(cachedBuffer.token.promote());
Marissa Wall947d34e2019-03-29 14:03:53 -070093 output.writeUint64(cachedBuffer.id);
Evan Rosky1f6d6d52018-12-06 10:47:26 -080094 output.writeParcelable(metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -080095
Valerie Haudd0b7572019-01-29 14:59:27 -080096 output.writeFloat(bgColorAlpha);
97 output.writeUint32(static_cast<uint32_t>(bgColorDataspace));
Peiyong Linc502cb72019-03-01 15:00:23 -080098 output.writeBool(colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -080099
Valerie Hau9dab9732019-08-20 09:29:25 -0700100 auto err = output.writeVectorSize(listeners);
101 if (err) {
102 return err;
103 }
104
105 for (auto listener : listeners) {
106 err = output.writeStrongBinder(listener.transactionCompletedListener);
107 if (err) {
108 return err;
109 }
110 err = output.writeInt64Vector(listener.callbackIds);
111 if (err) {
112 return err;
113 }
114 }
Vishnu Nair440992f2019-12-09 19:53:19 -0800115 output.writeFloat(shadowRadius);
Ana Krulecc84d09b2019-11-02 23:10:29 +0100116 output.writeInt32(frameRateSelectionPriority);
Steven Thomas3172e202020-01-06 19:25:30 -0800117 output.writeFloat(frameRate);
Steven Thomas62a4cf82020-01-31 12:04:03 -0800118 output.writeByte(frameRateCompatibility);
Vishnu Nair6213bd92020-05-08 17:42:25 -0700119 output.writeUint32(fixedTransformHint);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800120 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800121}
122
123status_t layer_state_t::read(const Parcel& input)
124{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800125 surface = input.readStrongBinder();
Garfield Tan8a3083e2018-12-03 13:21:07 -0800126 what = input.readUint64();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800127 x = input.readFloat();
128 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -0800129 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800130 w = input.readUint32();
131 h = input.readUint32();
132 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800133 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800134 flags = static_cast<uint8_t>(input.readUint32());
135 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700136 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
137 if (matrix_data) {
138 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
139 } else {
140 return BAD_VALUE;
141 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700142 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700143 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800144 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700145 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700146 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700147 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700148 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700149 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700150 color.r = input.readFloat();
151 color.g = input.readFloat();
152 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 15:58:15 -0700153
154#ifndef NO_INPUT
Chris Ye0783e992020-06-02 21:34:49 -0700155 inputHandle->readFromParcel(&input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700156#endif
157
Mathias Agopianac9fa422013-02-11 16:40:36 -0800158 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700159 transform = input.readUint32();
160 transformToDisplayInverse = input.readBool();
161 input.read(crop);
Marissa Wall861616d2018-10-22 12:52:23 -0700162 input.read(frame);
Marissa Wall61c58622018-07-18 10:12:20 -0700163 buffer = new GraphicBuffer();
164 if (input.readBool()) {
165 input.read(*buffer);
166 }
167 acquireFence = new Fence();
168 if (input.readBool()) {
169 input.read(*acquireFence);
170 }
171 dataspace = static_cast<ui::Dataspace>(input.readUint32());
172 input.read(hdrMetadata);
173 input.read(surfaceDamageRegion);
174 api = input.readInt32();
175 if (input.readBool()) {
176 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
177 }
178
Denis Hsu8f3da5e2020-07-15 09:31:21 +0800179 const void* color_transform_data = input.readInplace(16 * sizeof(float));
180 if (color_transform_data) {
181 colorTransform = mat4(static_cast<const float*>(color_transform_data));
182 } else {
183 return BAD_VALUE;
184 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700185 cornerRadius = input.readFloat();
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800186 backgroundBlurRadius = input.readUint32();
Steven Moreland9d4ce9b2019-07-17 15:23:38 -0700187 cachedBuffer.token = input.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -0700188 cachedBuffer.id = input.readUint64();
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800189 input.readParcelable(&metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800190
Valerie Haudd0b7572019-01-29 14:59:27 -0800191 bgColorAlpha = input.readFloat();
192 bgColorDataspace = static_cast<ui::Dataspace>(input.readUint32());
Peiyong Linc502cb72019-03-01 15:00:23 -0800193 colorSpaceAgnostic = input.readBool();
Valerie Haued54efa2019-01-11 20:03:14 -0800194
Valerie Hau9dab9732019-08-20 09:29:25 -0700195 int32_t numListeners = input.readInt32();
196 listeners.clear();
197 for (int i = 0; i < numListeners; i++) {
198 auto listener = input.readStrongBinder();
199 std::vector<CallbackId> callbackIds;
200 input.readInt64Vector(&callbackIds);
201 listeners.emplace_back(listener, callbackIds);
202 }
Vishnu Nair440992f2019-12-09 19:53:19 -0800203 shadowRadius = input.readFloat();
Ana Krulecc84d09b2019-11-02 23:10:29 +0100204 frameRateSelectionPriority = input.readInt32();
Steven Thomas3172e202020-01-06 19:25:30 -0800205 frameRate = input.readFloat();
Steven Thomas62a4cf82020-01-31 12:04:03 -0800206 frameRateCompatibility = input.readByte();
Vishnu Nair6213bd92020-05-08 17:42:25 -0700207 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(input.readUint32());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208 return NO_ERROR;
209}
210
Mathias Agopian698c0872011-06-28 19:09:31 -0700211status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700212 return state.write(output);
213}
214
215status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700216 return state.read(input);
217}
218
Mathias Agopian8b33f032012-07-24 20:43:54 -0700219
Pablo Ceballos60d69222015-08-07 14:47:20 -0700220DisplayState::DisplayState() :
221 what(0),
222 layerStack(0),
Pablo Ceballos60d69222015-08-07 14:47:20 -0700223 viewport(Rect::EMPTY_RECT),
224 frame(Rect::EMPTY_RECT),
225 width(0),
226 height(0) {
227}
228
Mathias Agopian8b33f032012-07-24 20:43:54 -0700229status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700230 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800231 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800232 output.writeUint32(what);
233 output.writeUint32(layerStack);
Dominik Laskowski718f9602019-11-09 20:01:35 -0800234 output.writeUint32(toRotationInt(orientation));
Mathias Agopian8683fca2012-08-12 19:37:16 -0700235 output.write(viewport);
236 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800237 output.writeUint32(width);
238 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700239 return NO_ERROR;
240}
241
242status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700243 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800244 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800245 what = input.readUint32();
246 layerStack = input.readUint32();
Dominik Laskowski718f9602019-11-09 20:01:35 -0800247 orientation = ui::toRotation(input.readUint32());
Mathias Agopian8683fca2012-08-12 19:37:16 -0700248 input.read(viewport);
249 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800250 width = input.readUint32();
251 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700252 return NO_ERROR;
253}
254
Robert Carr2c5f6d22017-09-26 12:30:35 -0700255void DisplayState::merge(const DisplayState& other) {
256 if (other.what & eSurfaceChanged) {
257 what |= eSurfaceChanged;
258 surface = other.surface;
259 }
260 if (other.what & eLayerStackChanged) {
261 what |= eLayerStackChanged;
262 layerStack = other.layerStack;
263 }
264 if (other.what & eDisplayProjectionChanged) {
265 what |= eDisplayProjectionChanged;
266 orientation = other.orientation;
267 viewport = other.viewport;
268 frame = other.frame;
269 }
270 if (other.what & eDisplaySizeChanged) {
271 what |= eDisplaySizeChanged;
272 width = other.width;
273 height = other.height;
274 }
275}
276
277void layer_state_t::merge(const layer_state_t& other) {
278 if (other.what & ePositionChanged) {
279 what |= ePositionChanged;
280 x = other.x;
281 y = other.y;
282 }
283 if (other.what & eLayerChanged) {
284 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700285 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700286 z = other.z;
287 }
288 if (other.what & eSizeChanged) {
289 what |= eSizeChanged;
290 w = other.w;
291 h = other.h;
292 }
293 if (other.what & eAlphaChanged) {
294 what |= eAlphaChanged;
295 alpha = other.alpha;
296 }
297 if (other.what & eMatrixChanged) {
298 what |= eMatrixChanged;
299 matrix = other.matrix;
300 }
301 if (other.what & eTransparentRegionChanged) {
302 what |= eTransparentRegionChanged;
303 transparentRegion = other.transparentRegion;
304 }
305 if (other.what & eFlagsChanged) {
306 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700307 flags &= ~other.mask;
308 flags |= (other.flags & other.mask);
309 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700310 }
311 if (other.what & eLayerStackChanged) {
312 what |= eLayerStackChanged;
313 layerStack = other.layerStack;
314 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700315 if (other.what & eCropChanged_legacy) {
316 what |= eCropChanged_legacy;
317 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700318 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700319 if (other.what & eCornerRadiusChanged) {
320 what |= eCornerRadiusChanged;
321 cornerRadius = other.cornerRadius;
322 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800323 if (other.what & eBackgroundBlurRadiusChanged) {
324 what |= eBackgroundBlurRadiusChanged;
325 backgroundBlurRadius = other.backgroundBlurRadius;
326 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700327 if (other.what & eDeferTransaction_legacy) {
328 what |= eDeferTransaction_legacy;
329 barrierHandle_legacy = other.barrierHandle_legacy;
330 barrierGbp_legacy = other.barrierGbp_legacy;
331 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700332 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700333 if (other.what & eOverrideScalingModeChanged) {
334 what |= eOverrideScalingModeChanged;
335 overrideScalingMode = other.overrideScalingMode;
336 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700337 if (other.what & eReparentChildren) {
338 what |= eReparentChildren;
339 reparentHandle = other.reparentHandle;
340 }
341 if (other.what & eDetachChildren) {
342 what |= eDetachChildren;
343 }
344 if (other.what & eRelativeLayerChanged) {
345 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700346 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700347 z = other.z;
348 relativeLayerHandle = other.relativeLayerHandle;
349 }
350 if (other.what & eReparent) {
351 what |= eReparent;
352 parentHandleForChild = other.parentHandleForChild;
353 }
chaviwca27f252018-02-06 16:46:39 -0800354 if (other.what & eDestroySurface) {
355 what |= eDestroySurface;
356 }
Marissa Wall61c58622018-07-18 10:12:20 -0700357 if (other.what & eTransformChanged) {
358 what |= eTransformChanged;
359 transform = other.transform;
360 }
361 if (other.what & eTransformToDisplayInverseChanged) {
362 what |= eTransformToDisplayInverseChanged;
363 transformToDisplayInverse = other.transformToDisplayInverse;
364 }
365 if (other.what & eCropChanged) {
366 what |= eCropChanged;
367 crop = other.crop;
368 }
Marissa Wall861616d2018-10-22 12:52:23 -0700369 if (other.what & eFrameChanged) {
370 what |= eFrameChanged;
371 frame = other.frame;
372 }
Marissa Wall61c58622018-07-18 10:12:20 -0700373 if (other.what & eBufferChanged) {
374 what |= eBufferChanged;
375 buffer = other.buffer;
376 }
377 if (other.what & eAcquireFenceChanged) {
378 what |= eAcquireFenceChanged;
379 acquireFence = other.acquireFence;
380 }
381 if (other.what & eDataspaceChanged) {
382 what |= eDataspaceChanged;
383 dataspace = other.dataspace;
384 }
385 if (other.what & eHdrMetadataChanged) {
386 what |= eHdrMetadataChanged;
387 hdrMetadata = other.hdrMetadata;
388 }
389 if (other.what & eSurfaceDamageRegionChanged) {
390 what |= eSurfaceDamageRegionChanged;
391 surfaceDamageRegion = other.surfaceDamageRegion;
392 }
393 if (other.what & eApiChanged) {
394 what |= eApiChanged;
395 api = other.api;
396 }
397 if (other.what & eSidebandStreamChanged) {
398 what |= eSidebandStreamChanged;
399 sidebandStream = other.sidebandStream;
400 }
Peiyong Lind3788632018-09-18 16:01:31 -0700401 if (other.what & eColorTransformChanged) {
402 what |= eColorTransformChanged;
403 colorTransform = other.colorTransform;
404 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700405 if (other.what & eHasListenerCallbacksChanged) {
406 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700407 }
Robert Carrd314f162018-08-15 13:12:42 -0700408
Robert Carr2c358bf2018-08-08 15:58:15 -0700409#ifndef NO_INPUT
410 if (other.what & eInputInfoChanged) {
411 what |= eInputInfoChanged;
Chris Ye0783e992020-06-02 21:34:49 -0700412 inputHandle = new InputWindowHandle(*other.inputHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700413 }
414#endif
415
Marissa Wallebc2c052019-01-16 19:16:55 -0800416 if (other.what & eCachedBufferChanged) {
417 what |= eCachedBufferChanged;
418 cachedBuffer = other.cachedBuffer;
419 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800420 if (other.what & eBackgroundColorChanged) {
421 what |= eBackgroundColorChanged;
422 color = other.color;
423 bgColorAlpha = other.bgColorAlpha;
424 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800425 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800426 if (other.what & eMetadataChanged) {
427 what |= eMetadataChanged;
428 metadata.merge(other.metadata);
429 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700430 if (other.what & eShadowRadiusChanged) {
431 what |= eShadowRadiusChanged;
432 shadowRadius = other.shadowRadius;
433 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100434 if (other.what & eFrameRateSelectionPriority) {
435 what |= eFrameRateSelectionPriority;
436 frameRateSelectionPriority = other.frameRateSelectionPriority;
437 }
Steven Thomas3172e202020-01-06 19:25:30 -0800438 if (other.what & eFrameRateChanged) {
439 what |= eFrameRateChanged;
440 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800441 frameRateCompatibility = other.frameRateCompatibility;
Steven Thomas3172e202020-01-06 19:25:30 -0800442 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700443 if (other.what & eFixedTransformHintChanged) {
444 what |= eFixedTransformHintChanged;
445 fixedTransformHint = other.fixedTransformHint;
446 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700447 if ((other.what & what) != other.what) {
448 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 13:21:07 -0800449 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 16:34:49 -0700450 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700451 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700452}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700453
chaviw273171b2018-12-26 11:46:30 -0800454// ------------------------------- InputWindowCommands ----------------------------------------
455
Vishnu Naire798b472020-07-23 13:52:21 -0700456bool InputWindowCommands::merge(const InputWindowCommands& other) {
457 bool changes = false;
458#ifndef NO_INPUT
459 changes |= !other.focusRequests.empty();
460 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
461 std::make_move_iterator(other.focusRequests.end()));
462#endif
463 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800464 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700465 return changes;
chaviw273171b2018-12-26 11:46:30 -0800466}
467
468void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700469#ifndef NO_INPUT
470 focusRequests.clear();
471#endif
chaviwa911b102019-02-14 10:18:33 -0800472 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800473}
474
475void InputWindowCommands::write(Parcel& output) const {
Vishnu Naire798b472020-07-23 13:52:21 -0700476#ifndef NO_INPUT
477 output.writeParcelableVector(focusRequests);
478#endif
chaviwa911b102019-02-14 10:18:33 -0800479 output.writeBool(syncInputWindows);
chaviw273171b2018-12-26 11:46:30 -0800480}
481
482void InputWindowCommands::read(const Parcel& input) {
Vishnu Naire798b472020-07-23 13:52:21 -0700483#ifndef NO_INPUT
484 input.readParcelableVector(&focusRequests);
485#endif
chaviwa911b102019-02-14 10:18:33 -0800486 syncInputWindows = input.readBool();
chaviw273171b2018-12-26 11:46:30 -0800487}
488
Steven Thomas62a4cf82020-01-31 12:04:03 -0800489bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* inFunctionName) {
490 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
491 int floatClassification = std::fpclassify(frameRate);
492 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
493 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
494 return false;
495 }
496
497 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
498 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE) {
499 ALOGE("%s failed - invalid compatibility value %d", functionName, compatibility);
500 return false;
501 }
502
503 return true;
504}
505
chaviw618c42d2020-07-24 15:25:08 -0700506// ----------------------------------------------------------------------------
507
508status_t CaptureArgs::write(Parcel& output) const {
509 status_t status = output.writeInt32(static_cast<int32_t>(pixelFormat)) ?:
510 output.write(sourceCrop) ?:
511 output.writeFloat(frameScale) ?:
chaviw4b9d5e12020-08-04 18:30:35 -0700512 output.writeBool(captureSecureLayers) ?:
513 output.writeInt32(uid);
chaviw618c42d2020-07-24 15:25:08 -0700514 return status;
515}
516
517status_t CaptureArgs::read(const Parcel& input) {
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700518 int32_t format = 0;
chaviw618c42d2020-07-24 15:25:08 -0700519 status_t status = input.readInt32(&format) ?:
520 input.read(sourceCrop) ?:
521 input.readFloat(&frameScale) ?:
chaviw4b9d5e12020-08-04 18:30:35 -0700522 input.readBool(&captureSecureLayers) ?:
523 input.readInt32(&uid);
chaviw618c42d2020-07-24 15:25:08 -0700524
525 pixelFormat = static_cast<ui::PixelFormat>(format);
526 return status;
527}
528
529status_t DisplayCaptureArgs::write(Parcel& output) const {
530 status_t status = CaptureArgs::write(output);
531
532 status |= output.writeStrongBinder(displayToken) ?:
533 output.writeUint32(width) ?:
534 output.writeUint32(height) ?:
chaviwc6ad8af2020-08-03 11:33:30 -0700535 output.writeBool(useIdentityTransform);
chaviw618c42d2020-07-24 15:25:08 -0700536 return status;
537}
538
539status_t DisplayCaptureArgs::read(const Parcel& input) {
540 status_t status = CaptureArgs::read(input);
541
chaviw618c42d2020-07-24 15:25:08 -0700542 status |= input.readStrongBinder(&displayToken) ?:
543 input.readUint32(&width) ?:
544 input.readUint32(&height) ?:
chaviwc6ad8af2020-08-03 11:33:30 -0700545 input.readBool(&useIdentityTransform);
chaviw618c42d2020-07-24 15:25:08 -0700546 return status;
547}
548
549status_t LayerCaptureArgs::write(Parcel& output) const {
550 status_t status = CaptureArgs::write(output);
551
552 status |= output.writeStrongBinder(layerHandle);
553 status |= output.writeInt32(excludeHandles.size());
554 for (auto el : excludeHandles) {
555 status |= output.writeStrongBinder(el);
556 }
557 status |= output.writeBool(childrenOnly);
558 return status;
559}
560
561status_t LayerCaptureArgs::read(const Parcel& input) {
562 status_t status = CaptureArgs::read(input);
563
564 status |= input.readStrongBinder(&layerHandle);
565
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700566 int32_t numExcludeHandles = 0;
chaviw618c42d2020-07-24 15:25:08 -0700567 status |= input.readInt32(&numExcludeHandles);
568 excludeHandles.reserve(numExcludeHandles);
569 for (int i = 0; i < numExcludeHandles; i++) {
570 sp<IBinder> binder;
571 status |= input.readStrongBinder(&binder);
572 excludeHandles.emplace(binder);
573 }
574
575 status |= input.readBool(&childrenOnly);
576 return status;
577}
578
579status_t ScreenCaptureResults::write(Parcel& output) const {
580 status_t status = output.write(*buffer) ?:
581 output.writeBool(capturedSecureLayers) ?:
582 output.writeUint32(static_cast<uint32_t>(capturedDataspace));
583 return status;
584}
585
586status_t ScreenCaptureResults::read(const Parcel& input) {
587 buffer = new GraphicBuffer();
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700588 uint32_t dataspace = 0;
chaviw618c42d2020-07-24 15:25:08 -0700589 status_t status = input.read(*buffer) ?:
590 input.readBool(&capturedSecureLayers) ?:
591 input.readUint32(&dataspace);
592
593 capturedDataspace = static_cast<ui::Dataspace>(dataspace);
594
595 return status;
596}
597
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800598}; // namespace android