blob: dd95b92fd346312ff64e0a6fd9045de44359e520 [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
Peiyong Lind3788632018-09-18 16:01:31 -0700179 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700180 cornerRadius = input.readFloat();
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800181 backgroundBlurRadius = input.readUint32();
Steven Moreland9d4ce9b2019-07-17 15:23:38 -0700182 cachedBuffer.token = input.readStrongBinder();
Marissa Wall947d34e2019-03-29 14:03:53 -0700183 cachedBuffer.id = input.readUint64();
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800184 input.readParcelable(&metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800185
Valerie Haudd0b7572019-01-29 14:59:27 -0800186 bgColorAlpha = input.readFloat();
187 bgColorDataspace = static_cast<ui::Dataspace>(input.readUint32());
Peiyong Linc502cb72019-03-01 15:00:23 -0800188 colorSpaceAgnostic = input.readBool();
Valerie Haued54efa2019-01-11 20:03:14 -0800189
Valerie Hau9dab9732019-08-20 09:29:25 -0700190 int32_t numListeners = input.readInt32();
191 listeners.clear();
192 for (int i = 0; i < numListeners; i++) {
193 auto listener = input.readStrongBinder();
194 std::vector<CallbackId> callbackIds;
195 input.readInt64Vector(&callbackIds);
196 listeners.emplace_back(listener, callbackIds);
197 }
Vishnu Nair440992f2019-12-09 19:53:19 -0800198 shadowRadius = input.readFloat();
Ana Krulecc84d09b2019-11-02 23:10:29 +0100199 frameRateSelectionPriority = input.readInt32();
Steven Thomas3172e202020-01-06 19:25:30 -0800200 frameRate = input.readFloat();
Steven Thomas62a4cf82020-01-31 12:04:03 -0800201 frameRateCompatibility = input.readByte();
Vishnu Nair6213bd92020-05-08 17:42:25 -0700202 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(input.readUint32());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800203 return NO_ERROR;
204}
205
Mathias Agopian698c0872011-06-28 19:09:31 -0700206status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700207 return state.write(output);
208}
209
210status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700211 return state.read(input);
212}
213
Mathias Agopian8b33f032012-07-24 20:43:54 -0700214
Pablo Ceballos60d69222015-08-07 14:47:20 -0700215DisplayState::DisplayState() :
216 what(0),
217 layerStack(0),
Pablo Ceballos60d69222015-08-07 14:47:20 -0700218 viewport(Rect::EMPTY_RECT),
219 frame(Rect::EMPTY_RECT),
220 width(0),
221 height(0) {
222}
223
Mathias Agopian8b33f032012-07-24 20:43:54 -0700224status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700225 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800226 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800227 output.writeUint32(what);
228 output.writeUint32(layerStack);
Dominik Laskowski718f9602019-11-09 20:01:35 -0800229 output.writeUint32(toRotationInt(orientation));
Mathias Agopian8683fca2012-08-12 19:37:16 -0700230 output.write(viewport);
231 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800232 output.writeUint32(width);
233 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700234 return NO_ERROR;
235}
236
237status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700238 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800239 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800240 what = input.readUint32();
241 layerStack = input.readUint32();
Dominik Laskowski718f9602019-11-09 20:01:35 -0800242 orientation = ui::toRotation(input.readUint32());
Mathias Agopian8683fca2012-08-12 19:37:16 -0700243 input.read(viewport);
244 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800245 width = input.readUint32();
246 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700247 return NO_ERROR;
248}
249
Robert Carr2c5f6d22017-09-26 12:30:35 -0700250void DisplayState::merge(const DisplayState& other) {
251 if (other.what & eSurfaceChanged) {
252 what |= eSurfaceChanged;
253 surface = other.surface;
254 }
255 if (other.what & eLayerStackChanged) {
256 what |= eLayerStackChanged;
257 layerStack = other.layerStack;
258 }
259 if (other.what & eDisplayProjectionChanged) {
260 what |= eDisplayProjectionChanged;
261 orientation = other.orientation;
262 viewport = other.viewport;
263 frame = other.frame;
264 }
265 if (other.what & eDisplaySizeChanged) {
266 what |= eDisplaySizeChanged;
267 width = other.width;
268 height = other.height;
269 }
270}
271
272void layer_state_t::merge(const layer_state_t& other) {
273 if (other.what & ePositionChanged) {
274 what |= ePositionChanged;
275 x = other.x;
276 y = other.y;
277 }
278 if (other.what & eLayerChanged) {
279 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700280 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700281 z = other.z;
282 }
283 if (other.what & eSizeChanged) {
284 what |= eSizeChanged;
285 w = other.w;
286 h = other.h;
287 }
288 if (other.what & eAlphaChanged) {
289 what |= eAlphaChanged;
290 alpha = other.alpha;
291 }
292 if (other.what & eMatrixChanged) {
293 what |= eMatrixChanged;
294 matrix = other.matrix;
295 }
296 if (other.what & eTransparentRegionChanged) {
297 what |= eTransparentRegionChanged;
298 transparentRegion = other.transparentRegion;
299 }
300 if (other.what & eFlagsChanged) {
301 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700302 flags &= ~other.mask;
303 flags |= (other.flags & other.mask);
304 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700305 }
306 if (other.what & eLayerStackChanged) {
307 what |= eLayerStackChanged;
308 layerStack = other.layerStack;
309 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700310 if (other.what & eCropChanged_legacy) {
311 what |= eCropChanged_legacy;
312 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700313 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700314 if (other.what & eCornerRadiusChanged) {
315 what |= eCornerRadiusChanged;
316 cornerRadius = other.cornerRadius;
317 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800318 if (other.what & eBackgroundBlurRadiusChanged) {
319 what |= eBackgroundBlurRadiusChanged;
320 backgroundBlurRadius = other.backgroundBlurRadius;
321 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700322 if (other.what & eDeferTransaction_legacy) {
323 what |= eDeferTransaction_legacy;
324 barrierHandle_legacy = other.barrierHandle_legacy;
325 barrierGbp_legacy = other.barrierGbp_legacy;
326 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700327 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700328 if (other.what & eOverrideScalingModeChanged) {
329 what |= eOverrideScalingModeChanged;
330 overrideScalingMode = other.overrideScalingMode;
331 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700332 if (other.what & eReparentChildren) {
333 what |= eReparentChildren;
334 reparentHandle = other.reparentHandle;
335 }
336 if (other.what & eDetachChildren) {
337 what |= eDetachChildren;
338 }
339 if (other.what & eRelativeLayerChanged) {
340 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700341 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700342 z = other.z;
343 relativeLayerHandle = other.relativeLayerHandle;
344 }
345 if (other.what & eReparent) {
346 what |= eReparent;
347 parentHandleForChild = other.parentHandleForChild;
348 }
chaviwca27f252018-02-06 16:46:39 -0800349 if (other.what & eDestroySurface) {
350 what |= eDestroySurface;
351 }
Marissa Wall61c58622018-07-18 10:12:20 -0700352 if (other.what & eTransformChanged) {
353 what |= eTransformChanged;
354 transform = other.transform;
355 }
356 if (other.what & eTransformToDisplayInverseChanged) {
357 what |= eTransformToDisplayInverseChanged;
358 transformToDisplayInverse = other.transformToDisplayInverse;
359 }
360 if (other.what & eCropChanged) {
361 what |= eCropChanged;
362 crop = other.crop;
363 }
Marissa Wall861616d2018-10-22 12:52:23 -0700364 if (other.what & eFrameChanged) {
365 what |= eFrameChanged;
366 frame = other.frame;
367 }
Marissa Wall61c58622018-07-18 10:12:20 -0700368 if (other.what & eBufferChanged) {
369 what |= eBufferChanged;
370 buffer = other.buffer;
371 }
372 if (other.what & eAcquireFenceChanged) {
373 what |= eAcquireFenceChanged;
374 acquireFence = other.acquireFence;
375 }
376 if (other.what & eDataspaceChanged) {
377 what |= eDataspaceChanged;
378 dataspace = other.dataspace;
379 }
380 if (other.what & eHdrMetadataChanged) {
381 what |= eHdrMetadataChanged;
382 hdrMetadata = other.hdrMetadata;
383 }
384 if (other.what & eSurfaceDamageRegionChanged) {
385 what |= eSurfaceDamageRegionChanged;
386 surfaceDamageRegion = other.surfaceDamageRegion;
387 }
388 if (other.what & eApiChanged) {
389 what |= eApiChanged;
390 api = other.api;
391 }
392 if (other.what & eSidebandStreamChanged) {
393 what |= eSidebandStreamChanged;
394 sidebandStream = other.sidebandStream;
395 }
Peiyong Lind3788632018-09-18 16:01:31 -0700396 if (other.what & eColorTransformChanged) {
397 what |= eColorTransformChanged;
398 colorTransform = other.colorTransform;
399 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700400 if (other.what & eHasListenerCallbacksChanged) {
401 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700402 }
Robert Carrd314f162018-08-15 13:12:42 -0700403
Robert Carr2c358bf2018-08-08 15:58:15 -0700404#ifndef NO_INPUT
405 if (other.what & eInputInfoChanged) {
406 what |= eInputInfoChanged;
Chris Ye0783e992020-06-02 21:34:49 -0700407 inputHandle = new InputWindowHandle(*other.inputHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700408 }
409#endif
410
Marissa Wallebc2c052019-01-16 19:16:55 -0800411 if (other.what & eCachedBufferChanged) {
412 what |= eCachedBufferChanged;
413 cachedBuffer = other.cachedBuffer;
414 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800415 if (other.what & eBackgroundColorChanged) {
416 what |= eBackgroundColorChanged;
417 color = other.color;
418 bgColorAlpha = other.bgColorAlpha;
419 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800420 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800421 if (other.what & eMetadataChanged) {
422 what |= eMetadataChanged;
423 metadata.merge(other.metadata);
424 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700425 if (other.what & eShadowRadiusChanged) {
426 what |= eShadowRadiusChanged;
427 shadowRadius = other.shadowRadius;
428 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100429 if (other.what & eFrameRateSelectionPriority) {
430 what |= eFrameRateSelectionPriority;
431 frameRateSelectionPriority = other.frameRateSelectionPriority;
432 }
Steven Thomas3172e202020-01-06 19:25:30 -0800433 if (other.what & eFrameRateChanged) {
434 what |= eFrameRateChanged;
435 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800436 frameRateCompatibility = other.frameRateCompatibility;
Steven Thomas3172e202020-01-06 19:25:30 -0800437 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700438 if (other.what & eFixedTransformHintChanged) {
439 what |= eFixedTransformHintChanged;
440 fixedTransformHint = other.fixedTransformHint;
441 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700442 if ((other.what & what) != other.what) {
443 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 13:21:07 -0800444 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 16:34:49 -0700445 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700446 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700447}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700448
chaviw273171b2018-12-26 11:46:30 -0800449// ------------------------------- InputWindowCommands ----------------------------------------
450
Vishnu Naire798b472020-07-23 13:52:21 -0700451bool InputWindowCommands::merge(const InputWindowCommands& other) {
452 bool changes = false;
453#ifndef NO_INPUT
454 changes |= !other.focusRequests.empty();
455 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
456 std::make_move_iterator(other.focusRequests.end()));
457#endif
458 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800459 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700460 return changes;
chaviw273171b2018-12-26 11:46:30 -0800461}
462
463void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700464#ifndef NO_INPUT
465 focusRequests.clear();
466#endif
chaviwa911b102019-02-14 10:18:33 -0800467 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800468}
469
470void InputWindowCommands::write(Parcel& output) const {
Vishnu Naire798b472020-07-23 13:52:21 -0700471#ifndef NO_INPUT
472 output.writeParcelableVector(focusRequests);
473#endif
chaviwa911b102019-02-14 10:18:33 -0800474 output.writeBool(syncInputWindows);
chaviw273171b2018-12-26 11:46:30 -0800475}
476
477void InputWindowCommands::read(const Parcel& input) {
Vishnu Naire798b472020-07-23 13:52:21 -0700478#ifndef NO_INPUT
479 input.readParcelableVector(&focusRequests);
480#endif
chaviwa911b102019-02-14 10:18:33 -0800481 syncInputWindows = input.readBool();
chaviw273171b2018-12-26 11:46:30 -0800482}
483
Steven Thomas62a4cf82020-01-31 12:04:03 -0800484bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* inFunctionName) {
485 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
486 int floatClassification = std::fpclassify(frameRate);
487 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
488 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
489 return false;
490 }
491
492 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
493 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE) {
494 ALOGE("%s failed - invalid compatibility value %d", functionName, compatibility);
495 return false;
496 }
497
498 return true;
499}
500
chaviw618c42d2020-07-24 15:25:08 -0700501// ----------------------------------------------------------------------------
502
503status_t CaptureArgs::write(Parcel& output) const {
504 status_t status = output.writeInt32(static_cast<int32_t>(pixelFormat)) ?:
505 output.write(sourceCrop) ?:
506 output.writeFloat(frameScale) ?:
507 output.writeBool(captureSecureLayers);
508 return status;
509}
510
511status_t CaptureArgs::read(const Parcel& input) {
512 int32_t format;
513 status_t status = input.readInt32(&format) ?:
514 input.read(sourceCrop) ?:
515 input.readFloat(&frameScale) ?:
516 input.readBool(&captureSecureLayers);
517
518 pixelFormat = static_cast<ui::PixelFormat>(format);
519 return status;
520}
521
522status_t DisplayCaptureArgs::write(Parcel& output) const {
523 status_t status = CaptureArgs::write(output);
524
525 status |= output.writeStrongBinder(displayToken) ?:
526 output.writeUint32(width) ?:
527 output.writeUint32(height) ?:
528 output.writeBool(useIdentityTransform) ?:
529 output.writeInt32(static_cast<int32_t>(rotation));
530 return status;
531}
532
533status_t DisplayCaptureArgs::read(const Parcel& input) {
534 status_t status = CaptureArgs::read(input);
535
536 int32_t rotationInt;
537
538 status |= input.readStrongBinder(&displayToken) ?:
539 input.readUint32(&width) ?:
540 input.readUint32(&height) ?:
541 input.readBool(&useIdentityTransform) ?:
542 input.readInt32(&rotationInt);
543
544 rotation = ui::toRotation(rotationInt);
545 return status;
546}
547
548status_t LayerCaptureArgs::write(Parcel& output) const {
549 status_t status = CaptureArgs::write(output);
550
551 status |= output.writeStrongBinder(layerHandle);
552 status |= output.writeInt32(excludeHandles.size());
553 for (auto el : excludeHandles) {
554 status |= output.writeStrongBinder(el);
555 }
556 status |= output.writeBool(childrenOnly);
557 return status;
558}
559
560status_t LayerCaptureArgs::read(const Parcel& input) {
561 status_t status = CaptureArgs::read(input);
562
563 status |= input.readStrongBinder(&layerHandle);
564
565 int32_t numExcludeHandles;
566 status |= input.readInt32(&numExcludeHandles);
567 excludeHandles.reserve(numExcludeHandles);
568 for (int i = 0; i < numExcludeHandles; i++) {
569 sp<IBinder> binder;
570 status |= input.readStrongBinder(&binder);
571 excludeHandles.emplace(binder);
572 }
573
574 status |= input.readBool(&childrenOnly);
575 return status;
576}
577
578status_t ScreenCaptureResults::write(Parcel& output) const {
579 status_t status = output.write(*buffer) ?:
580 output.writeBool(capturedSecureLayers) ?:
581 output.writeUint32(static_cast<uint32_t>(capturedDataspace));
582 return status;
583}
584
585status_t ScreenCaptureResults::read(const Parcel& input) {
586 buffer = new GraphicBuffer();
587 uint32_t dataspace;
588 status_t status = input.read(*buffer) ?:
589 input.readBool(&capturedSecureLayers) ?:
590 input.readUint32(&dataspace);
591
592 capturedDataspace = static_cast<ui::Dataspace>(dataspace);
593
594 return status;
595}
596
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800597}; // namespace android