blob: 725d3cdfd57047df665afc613bd31128450344cf [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);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020064 output.write(orientedDisplaySpaceRect);
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);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200162 input.read(orientedDisplaySpaceRect);
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
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200219DisplayState::DisplayState()
220 : what(0),
221 layerStack(0),
222 layerStackSpaceRect(Rect::EMPTY_RECT),
223 orientedDisplaySpaceRect(Rect::EMPTY_RECT),
224 width(0),
225 height(0) {}
Pablo Ceballos60d69222015-08-07 14:47:20 -0700226
Mathias Agopian8b33f032012-07-24 20:43:54 -0700227status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700228 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800229 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800230 output.writeUint32(what);
231 output.writeUint32(layerStack);
Dominik Laskowski718f9602019-11-09 20:01:35 -0800232 output.writeUint32(toRotationInt(orientation));
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200233 output.write(layerStackSpaceRect);
234 output.write(orientedDisplaySpaceRect);
Dan Stozad723bd72014-11-18 10:24:03 -0800235 output.writeUint32(width);
236 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700237 return NO_ERROR;
238}
239
240status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700241 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800242 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800243 what = input.readUint32();
244 layerStack = input.readUint32();
Dominik Laskowski718f9602019-11-09 20:01:35 -0800245 orientation = ui::toRotation(input.readUint32());
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200246 input.read(layerStackSpaceRect);
247 input.read(orientedDisplaySpaceRect);
Dan Stozad723bd72014-11-18 10:24:03 -0800248 width = input.readUint32();
249 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700250 return NO_ERROR;
251}
252
Robert Carr2c5f6d22017-09-26 12:30:35 -0700253void DisplayState::merge(const DisplayState& other) {
254 if (other.what & eSurfaceChanged) {
255 what |= eSurfaceChanged;
256 surface = other.surface;
257 }
258 if (other.what & eLayerStackChanged) {
259 what |= eLayerStackChanged;
260 layerStack = other.layerStack;
261 }
262 if (other.what & eDisplayProjectionChanged) {
263 what |= eDisplayProjectionChanged;
264 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200265 layerStackSpaceRect = other.layerStackSpaceRect;
266 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700267 }
268 if (other.what & eDisplaySizeChanged) {
269 what |= eDisplaySizeChanged;
270 width = other.width;
271 height = other.height;
272 }
273}
274
275void layer_state_t::merge(const layer_state_t& other) {
276 if (other.what & ePositionChanged) {
277 what |= ePositionChanged;
278 x = other.x;
279 y = other.y;
280 }
281 if (other.what & eLayerChanged) {
282 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700283 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700284 z = other.z;
285 }
286 if (other.what & eSizeChanged) {
287 what |= eSizeChanged;
288 w = other.w;
289 h = other.h;
290 }
291 if (other.what & eAlphaChanged) {
292 what |= eAlphaChanged;
293 alpha = other.alpha;
294 }
295 if (other.what & eMatrixChanged) {
296 what |= eMatrixChanged;
297 matrix = other.matrix;
298 }
299 if (other.what & eTransparentRegionChanged) {
300 what |= eTransparentRegionChanged;
301 transparentRegion = other.transparentRegion;
302 }
303 if (other.what & eFlagsChanged) {
304 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700305 flags &= ~other.mask;
306 flags |= (other.flags & other.mask);
307 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700308 }
309 if (other.what & eLayerStackChanged) {
310 what |= eLayerStackChanged;
311 layerStack = other.layerStack;
312 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700313 if (other.what & eCropChanged_legacy) {
314 what |= eCropChanged_legacy;
315 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700316 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700317 if (other.what & eCornerRadiusChanged) {
318 what |= eCornerRadiusChanged;
319 cornerRadius = other.cornerRadius;
320 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800321 if (other.what & eBackgroundBlurRadiusChanged) {
322 what |= eBackgroundBlurRadiusChanged;
323 backgroundBlurRadius = other.backgroundBlurRadius;
324 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700325 if (other.what & eDeferTransaction_legacy) {
326 what |= eDeferTransaction_legacy;
327 barrierHandle_legacy = other.barrierHandle_legacy;
328 barrierGbp_legacy = other.barrierGbp_legacy;
329 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700330 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700331 if (other.what & eOverrideScalingModeChanged) {
332 what |= eOverrideScalingModeChanged;
333 overrideScalingMode = other.overrideScalingMode;
334 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700335 if (other.what & eReparentChildren) {
336 what |= eReparentChildren;
337 reparentHandle = other.reparentHandle;
338 }
339 if (other.what & eDetachChildren) {
340 what |= eDetachChildren;
341 }
342 if (other.what & eRelativeLayerChanged) {
343 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700344 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700345 z = other.z;
346 relativeLayerHandle = other.relativeLayerHandle;
347 }
348 if (other.what & eReparent) {
349 what |= eReparent;
350 parentHandleForChild = other.parentHandleForChild;
351 }
chaviwca27f252018-02-06 16:46:39 -0800352 if (other.what & eDestroySurface) {
353 what |= eDestroySurface;
354 }
Marissa Wall61c58622018-07-18 10:12:20 -0700355 if (other.what & eTransformChanged) {
356 what |= eTransformChanged;
357 transform = other.transform;
358 }
359 if (other.what & eTransformToDisplayInverseChanged) {
360 what |= eTransformToDisplayInverseChanged;
361 transformToDisplayInverse = other.transformToDisplayInverse;
362 }
363 if (other.what & eCropChanged) {
364 what |= eCropChanged;
365 crop = other.crop;
366 }
Marissa Wall861616d2018-10-22 12:52:23 -0700367 if (other.what & eFrameChanged) {
368 what |= eFrameChanged;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200369 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Marissa Wall861616d2018-10-22 12:52:23 -0700370 }
Marissa Wall61c58622018-07-18 10:12:20 -0700371 if (other.what & eBufferChanged) {
372 what |= eBufferChanged;
373 buffer = other.buffer;
374 }
375 if (other.what & eAcquireFenceChanged) {
376 what |= eAcquireFenceChanged;
377 acquireFence = other.acquireFence;
378 }
379 if (other.what & eDataspaceChanged) {
380 what |= eDataspaceChanged;
381 dataspace = other.dataspace;
382 }
383 if (other.what & eHdrMetadataChanged) {
384 what |= eHdrMetadataChanged;
385 hdrMetadata = other.hdrMetadata;
386 }
387 if (other.what & eSurfaceDamageRegionChanged) {
388 what |= eSurfaceDamageRegionChanged;
389 surfaceDamageRegion = other.surfaceDamageRegion;
390 }
391 if (other.what & eApiChanged) {
392 what |= eApiChanged;
393 api = other.api;
394 }
395 if (other.what & eSidebandStreamChanged) {
396 what |= eSidebandStreamChanged;
397 sidebandStream = other.sidebandStream;
398 }
Peiyong Lind3788632018-09-18 16:01:31 -0700399 if (other.what & eColorTransformChanged) {
400 what |= eColorTransformChanged;
401 colorTransform = other.colorTransform;
402 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700403 if (other.what & eHasListenerCallbacksChanged) {
404 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700405 }
Robert Carrd314f162018-08-15 13:12:42 -0700406
Robert Carr2c358bf2018-08-08 15:58:15 -0700407#ifndef NO_INPUT
408 if (other.what & eInputInfoChanged) {
409 what |= eInputInfoChanged;
Chris Ye0783e992020-06-02 21:34:49 -0700410 inputHandle = new InputWindowHandle(*other.inputHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700411 }
412#endif
413
Marissa Wallebc2c052019-01-16 19:16:55 -0800414 if (other.what & eCachedBufferChanged) {
415 what |= eCachedBufferChanged;
416 cachedBuffer = other.cachedBuffer;
417 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800418 if (other.what & eBackgroundColorChanged) {
419 what |= eBackgroundColorChanged;
420 color = other.color;
421 bgColorAlpha = other.bgColorAlpha;
422 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800423 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800424 if (other.what & eMetadataChanged) {
425 what |= eMetadataChanged;
426 metadata.merge(other.metadata);
427 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700428 if (other.what & eShadowRadiusChanged) {
429 what |= eShadowRadiusChanged;
430 shadowRadius = other.shadowRadius;
431 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100432 if (other.what & eFrameRateSelectionPriority) {
433 what |= eFrameRateSelectionPriority;
434 frameRateSelectionPriority = other.frameRateSelectionPriority;
435 }
Steven Thomas3172e202020-01-06 19:25:30 -0800436 if (other.what & eFrameRateChanged) {
437 what |= eFrameRateChanged;
438 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800439 frameRateCompatibility = other.frameRateCompatibility;
Steven Thomas3172e202020-01-06 19:25:30 -0800440 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700441 if (other.what & eFixedTransformHintChanged) {
442 what |= eFixedTransformHintChanged;
443 fixedTransformHint = other.fixedTransformHint;
444 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700445 if ((other.what & what) != other.what) {
446 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 13:21:07 -0800447 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 16:34:49 -0700448 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700449 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700450}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700451
chaviw273171b2018-12-26 11:46:30 -0800452// ------------------------------- InputWindowCommands ----------------------------------------
453
Vishnu Naire798b472020-07-23 13:52:21 -0700454bool InputWindowCommands::merge(const InputWindowCommands& other) {
455 bool changes = false;
456#ifndef NO_INPUT
457 changes |= !other.focusRequests.empty();
458 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
459 std::make_move_iterator(other.focusRequests.end()));
460#endif
461 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800462 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700463 return changes;
chaviw273171b2018-12-26 11:46:30 -0800464}
465
466void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700467#ifndef NO_INPUT
468 focusRequests.clear();
469#endif
chaviwa911b102019-02-14 10:18:33 -0800470 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800471}
472
473void InputWindowCommands::write(Parcel& output) const {
Vishnu Naire798b472020-07-23 13:52:21 -0700474#ifndef NO_INPUT
475 output.writeParcelableVector(focusRequests);
476#endif
chaviwa911b102019-02-14 10:18:33 -0800477 output.writeBool(syncInputWindows);
chaviw273171b2018-12-26 11:46:30 -0800478}
479
480void InputWindowCommands::read(const Parcel& input) {
Vishnu Naire798b472020-07-23 13:52:21 -0700481#ifndef NO_INPUT
482 input.readParcelableVector(&focusRequests);
483#endif
chaviwa911b102019-02-14 10:18:33 -0800484 syncInputWindows = input.readBool();
chaviw273171b2018-12-26 11:46:30 -0800485}
486
Steven Thomas62a4cf82020-01-31 12:04:03 -0800487bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* inFunctionName) {
488 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
489 int floatClassification = std::fpclassify(frameRate);
490 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
491 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
492 return false;
493 }
494
495 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
496 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE) {
497 ALOGE("%s failed - invalid compatibility value %d", functionName, compatibility);
498 return false;
499 }
500
501 return true;
502}
503
chaviw618c42d2020-07-24 15:25:08 -0700504// ----------------------------------------------------------------------------
505
506status_t CaptureArgs::write(Parcel& output) const {
507 status_t status = output.writeInt32(static_cast<int32_t>(pixelFormat)) ?:
508 output.write(sourceCrop) ?:
509 output.writeFloat(frameScale) ?:
chaviw4b9d5e12020-08-04 18:30:35 -0700510 output.writeBool(captureSecureLayers) ?:
511 output.writeInt32(uid);
chaviw618c42d2020-07-24 15:25:08 -0700512 return status;
513}
514
515status_t CaptureArgs::read(const Parcel& input) {
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700516 int32_t format = 0;
chaviw618c42d2020-07-24 15:25:08 -0700517 status_t status = input.readInt32(&format) ?:
518 input.read(sourceCrop) ?:
519 input.readFloat(&frameScale) ?:
chaviw4b9d5e12020-08-04 18:30:35 -0700520 input.readBool(&captureSecureLayers) ?:
521 input.readInt32(&uid);
chaviw618c42d2020-07-24 15:25:08 -0700522
523 pixelFormat = static_cast<ui::PixelFormat>(format);
524 return status;
525}
526
527status_t DisplayCaptureArgs::write(Parcel& output) const {
528 status_t status = CaptureArgs::write(output);
529
530 status |= output.writeStrongBinder(displayToken) ?:
531 output.writeUint32(width) ?:
532 output.writeUint32(height) ?:
chaviwc6ad8af2020-08-03 11:33:30 -0700533 output.writeBool(useIdentityTransform);
chaviw618c42d2020-07-24 15:25:08 -0700534 return status;
535}
536
537status_t DisplayCaptureArgs::read(const Parcel& input) {
538 status_t status = CaptureArgs::read(input);
539
chaviw618c42d2020-07-24 15:25:08 -0700540 status |= input.readStrongBinder(&displayToken) ?:
541 input.readUint32(&width) ?:
542 input.readUint32(&height) ?:
chaviwc6ad8af2020-08-03 11:33:30 -0700543 input.readBool(&useIdentityTransform);
chaviw618c42d2020-07-24 15:25:08 -0700544 return status;
545}
546
547status_t LayerCaptureArgs::write(Parcel& output) const {
548 status_t status = CaptureArgs::write(output);
549
550 status |= output.writeStrongBinder(layerHandle);
551 status |= output.writeInt32(excludeHandles.size());
552 for (auto el : excludeHandles) {
553 status |= output.writeStrongBinder(el);
554 }
555 status |= output.writeBool(childrenOnly);
556 return status;
557}
558
559status_t LayerCaptureArgs::read(const Parcel& input) {
560 status_t status = CaptureArgs::read(input);
561
562 status |= input.readStrongBinder(&layerHandle);
563
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700564 int32_t numExcludeHandles = 0;
chaviw618c42d2020-07-24 15:25:08 -0700565 status |= input.readInt32(&numExcludeHandles);
566 excludeHandles.reserve(numExcludeHandles);
567 for (int i = 0; i < numExcludeHandles; i++) {
568 sp<IBinder> binder;
569 status |= input.readStrongBinder(&binder);
570 excludeHandles.emplace(binder);
571 }
572
573 status |= input.readBool(&childrenOnly);
574 return status;
575}
576
577status_t ScreenCaptureResults::write(Parcel& output) const {
578 status_t status = output.write(*buffer) ?:
579 output.writeBool(capturedSecureLayers) ?:
580 output.writeUint32(static_cast<uint32_t>(capturedDataspace));
581 return status;
582}
583
584status_t ScreenCaptureResults::read(const Parcel& input) {
585 buffer = new GraphicBuffer();
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700586 uint32_t dataspace = 0;
chaviw618c42d2020-07-24 15:25:08 -0700587 status_t status = input.read(*buffer) ?:
588 input.readBool(&capturedSecureLayers) ?:
589 input.readUint32(&dataspace);
590
591 capturedDataspace = static_cast<ui::Dataspace>(dataspace);
592
593 return status;
594}
595
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800596}; // namespace android