blob: 35ce6e393a89b8476f2db9c98e573c24b9ec1e5b [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
Mathias Agopianac9fa422013-02-11 16:40:36 -080097 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098}
99
100status_t layer_state_t::read(const Parcel& input)
101{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800102 surface = input.readStrongBinder();
Garfield Tan8a3083e2018-12-03 13:21:07 -0800103 what = input.readUint64();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800104 x = input.readFloat();
105 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -0800106 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800107 w = input.readUint32();
108 h = input.readUint32();
109 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800110 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800111 flags = static_cast<uint8_t>(input.readUint32());
112 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700113 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
114 if (matrix_data) {
115 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
116 } else {
117 return BAD_VALUE;
118 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700119 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700120 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800121 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700122 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700123 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700124 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700125 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700126 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700127 color.r = input.readFloat();
128 color.g = input.readFloat();
129 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 15:58:15 -0700130
131#ifndef NO_INPUT
132 inputInfo = InputWindowInfo::read(input);
133#endif
134
Mathias Agopianac9fa422013-02-11 16:40:36 -0800135 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700136 transform = input.readUint32();
137 transformToDisplayInverse = input.readBool();
138 input.read(crop);
Marissa Wall861616d2018-10-22 12:52:23 -0700139 input.read(frame);
Marissa Wall61c58622018-07-18 10:12:20 -0700140 buffer = new GraphicBuffer();
141 if (input.readBool()) {
142 input.read(*buffer);
143 }
144 acquireFence = new Fence();
145 if (input.readBool()) {
146 input.read(*acquireFence);
147 }
148 dataspace = static_cast<ui::Dataspace>(input.readUint32());
149 input.read(hdrMetadata);
150 input.read(surfaceDamageRegion);
151 api = input.readInt32();
152 if (input.readBool()) {
153 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
154 }
155
Peiyong Lind3788632018-09-18 16:01:31 -0700156 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700157 cornerRadius = input.readFloat();
Peiyong Lind3788632018-09-18 16:01:31 -0700158
Marissa Wallc837b5e2018-10-12 10:04:44 -0700159 int32_t listenersSize = input.readInt32();
160 for (int32_t i = 0; i < listenersSize; i++) {
161 auto listener = interface_cast<ITransactionCompletedListener>(input.readStrongBinder());
162 std::vector<CallbackId> callbackIds;
163 input.readInt64Vector(&callbackIds);
164 listenerCallbacks.emplace_back(listener, callbackIds);
165 }
166
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800167 return NO_ERROR;
168}
169
Mathias Agopian698c0872011-06-28 19:09:31 -0700170status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800171 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700172 return state.write(output);
173}
174
175status_t ComposerState::read(const Parcel& input) {
176 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
177 return state.read(input);
178}
179
Mathias Agopian8b33f032012-07-24 20:43:54 -0700180
Pablo Ceballos60d69222015-08-07 14:47:20 -0700181DisplayState::DisplayState() :
182 what(0),
183 layerStack(0),
184 orientation(eOrientationDefault),
185 viewport(Rect::EMPTY_RECT),
186 frame(Rect::EMPTY_RECT),
187 width(0),
188 height(0) {
189}
190
Mathias Agopian8b33f032012-07-24 20:43:54 -0700191status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700192 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800193 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800194 output.writeUint32(what);
195 output.writeUint32(layerStack);
196 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700197 output.write(viewport);
198 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800199 output.writeUint32(width);
200 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700201 return NO_ERROR;
202}
203
204status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700205 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800206 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800207 what = input.readUint32();
208 layerStack = input.readUint32();
209 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700210 input.read(viewport);
211 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800212 width = input.readUint32();
213 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700214 return NO_ERROR;
215}
216
Robert Carr2c5f6d22017-09-26 12:30:35 -0700217void DisplayState::merge(const DisplayState& other) {
218 if (other.what & eSurfaceChanged) {
219 what |= eSurfaceChanged;
220 surface = other.surface;
221 }
222 if (other.what & eLayerStackChanged) {
223 what |= eLayerStackChanged;
224 layerStack = other.layerStack;
225 }
226 if (other.what & eDisplayProjectionChanged) {
227 what |= eDisplayProjectionChanged;
228 orientation = other.orientation;
229 viewport = other.viewport;
230 frame = other.frame;
231 }
232 if (other.what & eDisplaySizeChanged) {
233 what |= eDisplaySizeChanged;
234 width = other.width;
235 height = other.height;
236 }
237}
238
239void layer_state_t::merge(const layer_state_t& other) {
240 if (other.what & ePositionChanged) {
241 what |= ePositionChanged;
242 x = other.x;
243 y = other.y;
244 }
245 if (other.what & eLayerChanged) {
246 what |= eLayerChanged;
247 z = other.z;
248 }
249 if (other.what & eSizeChanged) {
250 what |= eSizeChanged;
251 w = other.w;
252 h = other.h;
253 }
254 if (other.what & eAlphaChanged) {
255 what |= eAlphaChanged;
256 alpha = other.alpha;
257 }
258 if (other.what & eMatrixChanged) {
259 what |= eMatrixChanged;
260 matrix = other.matrix;
261 }
262 if (other.what & eTransparentRegionChanged) {
263 what |= eTransparentRegionChanged;
264 transparentRegion = other.transparentRegion;
265 }
266 if (other.what & eFlagsChanged) {
267 what |= eFlagsChanged;
268 flags = other.flags;
269 mask = other.mask;
270 }
271 if (other.what & eLayerStackChanged) {
272 what |= eLayerStackChanged;
273 layerStack = other.layerStack;
274 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700275 if (other.what & eCropChanged_legacy) {
276 what |= eCropChanged_legacy;
277 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700278 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700279 if (other.what & eCornerRadiusChanged) {
280 what |= eCornerRadiusChanged;
281 cornerRadius = other.cornerRadius;
282 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700283 if (other.what & eDeferTransaction_legacy) {
284 what |= eDeferTransaction_legacy;
285 barrierHandle_legacy = other.barrierHandle_legacy;
286 barrierGbp_legacy = other.barrierGbp_legacy;
287 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700288 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700289 if (other.what & eOverrideScalingModeChanged) {
290 what |= eOverrideScalingModeChanged;
291 overrideScalingMode = other.overrideScalingMode;
292 }
293 if (other.what & eGeometryAppliesWithResize) {
294 what |= eGeometryAppliesWithResize;
295 }
296 if (other.what & eReparentChildren) {
297 what |= eReparentChildren;
298 reparentHandle = other.reparentHandle;
299 }
300 if (other.what & eDetachChildren) {
301 what |= eDetachChildren;
302 }
303 if (other.what & eRelativeLayerChanged) {
304 what |= eRelativeLayerChanged;
305 z = other.z;
306 relativeLayerHandle = other.relativeLayerHandle;
307 }
308 if (other.what & eReparent) {
309 what |= eReparent;
310 parentHandleForChild = other.parentHandleForChild;
311 }
chaviwca27f252018-02-06 16:46:39 -0800312 if (other.what & eDestroySurface) {
313 what |= eDestroySurface;
314 }
Marissa Wall61c58622018-07-18 10:12:20 -0700315 if (other.what & eTransformChanged) {
316 what |= eTransformChanged;
317 transform = other.transform;
318 }
319 if (other.what & eTransformToDisplayInverseChanged) {
320 what |= eTransformToDisplayInverseChanged;
321 transformToDisplayInverse = other.transformToDisplayInverse;
322 }
323 if (other.what & eCropChanged) {
324 what |= eCropChanged;
325 crop = other.crop;
326 }
Marissa Wall861616d2018-10-22 12:52:23 -0700327 if (other.what & eFrameChanged) {
328 what |= eFrameChanged;
329 frame = other.frame;
330 }
Marissa Wall61c58622018-07-18 10:12:20 -0700331 if (other.what & eBufferChanged) {
332 what |= eBufferChanged;
333 buffer = other.buffer;
334 }
335 if (other.what & eAcquireFenceChanged) {
336 what |= eAcquireFenceChanged;
337 acquireFence = other.acquireFence;
338 }
339 if (other.what & eDataspaceChanged) {
340 what |= eDataspaceChanged;
341 dataspace = other.dataspace;
342 }
343 if (other.what & eHdrMetadataChanged) {
344 what |= eHdrMetadataChanged;
345 hdrMetadata = other.hdrMetadata;
346 }
347 if (other.what & eSurfaceDamageRegionChanged) {
348 what |= eSurfaceDamageRegionChanged;
349 surfaceDamageRegion = other.surfaceDamageRegion;
350 }
351 if (other.what & eApiChanged) {
352 what |= eApiChanged;
353 api = other.api;
354 }
355 if (other.what & eSidebandStreamChanged) {
356 what |= eSidebandStreamChanged;
357 sidebandStream = other.sidebandStream;
358 }
Peiyong Lind3788632018-09-18 16:01:31 -0700359 if (other.what & eColorTransformChanged) {
360 what |= eColorTransformChanged;
361 colorTransform = other.colorTransform;
362 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700363 if (other.what & eListenerCallbacksChanged) {
364 what |= eListenerCallbacksChanged;
365 listenerCallbacks = other.listenerCallbacks;
366 }
Robert Carrd314f162018-08-15 13:12:42 -0700367
Robert Carr2c358bf2018-08-08 15:58:15 -0700368#ifndef NO_INPUT
369 if (other.what & eInputInfoChanged) {
370 what |= eInputInfoChanged;
371 inputInfo = other.inputInfo;
372 }
373#endif
374
Vishnu Nair217d8e62018-09-12 16:34:49 -0700375 if ((other.what & what) != other.what) {
376 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 13:21:07 -0800377 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 16:34:49 -0700378 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700379 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700380}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700381
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800382}; // namespace android