blob: 407eecb6fbd70d624ef8719ffbe53f3ad141ed99 [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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019#include <utils/Errors.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070020#include <binder/Parcel.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080021#include <gui/ISurfaceComposerClient.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080022#include <gui/IGraphicBufferProducer.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070023#include <gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080024
25namespace android {
26
27status_t layer_state_t::write(Parcel& output) const
28{
Mathias Agopianac9fa422013-02-11 16:40:36 -080029 output.writeStrongBinder(surface);
Dan Stozad723bd72014-11-18 10:24:03 -080030 output.writeUint32(what);
Mathias Agopianac9fa422013-02-11 16:40:36 -080031 output.writeFloat(x);
32 output.writeFloat(y);
Robert Carrae060832016-11-28 10:51:00 -080033 output.writeInt32(z);
Dan Stozad723bd72014-11-18 10:24:03 -080034 output.writeUint32(w);
35 output.writeUint32(h);
36 output.writeUint32(layerStack);
Mathias Agopianac9fa422013-02-11 16:40:36 -080037 output.writeFloat(alpha);
Dan Stozad723bd72014-11-18 10:24:03 -080038 output.writeUint32(flags);
39 output.writeUint32(mask);
Mathias Agopianac9fa422013-02-11 16:40:36 -080040 *reinterpret_cast<layer_state_t::matrix22_t *>(
41 output.writeInplace(sizeof(layer_state_t::matrix22_t))) = matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -070042 output.write(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -070043 output.writeStrongBinder(barrierHandle_legacy);
Robert Carr1db73f62016-12-21 12:58:51 -080044 output.writeStrongBinder(reparentHandle);
Marissa Wallf58c14b2018-07-24 10:50:43 -070045 output.writeUint64(frameNumber_legacy);
Robert Carrc3574f72016-03-24 12:19:32 -070046 output.writeInt32(overrideScalingMode);
Marissa Wallf58c14b2018-07-24 10:50:43 -070047 output.writeStrongBinder(IInterface::asBinder(barrierGbp_legacy));
Robert Carrdb66e622017-04-10 16:55:57 -070048 output.writeStrongBinder(relativeLayerHandle);
chaviw06178942017-07-27 10:25:59 -070049 output.writeStrongBinder(parentHandleForChild);
chaviw13fdc492017-06-27 12:40:18 -070050 output.writeFloat(color.r);
51 output.writeFloat(color.g);
52 output.writeFloat(color.b);
Robert Carr2c358bf2018-08-08 15:58:15 -070053#ifndef NO_INPUT
54 inputInfo.write(output);
55#endif
Mathias Agopianac9fa422013-02-11 16:40:36 -080056 output.write(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -070057 output.writeUint32(transform);
58 output.writeBool(transformToDisplayInverse);
59 output.write(crop);
60 if (buffer) {
61 output.writeBool(true);
62 output.write(*buffer);
63 } else {
64 output.writeBool(false);
65 }
66 if (acquireFence) {
67 output.writeBool(true);
68 output.write(*acquireFence);
69 } else {
70 output.writeBool(false);
71 }
72 output.writeUint32(static_cast<uint32_t>(dataspace));
73 output.write(hdrMetadata);
74 output.write(surfaceDamageRegion);
75 output.writeInt32(api);
76 if (sidebandStream) {
77 output.writeBool(true);
78 output.writeNativeHandle(sidebandStream->handle());
79 } else {
80 output.writeBool(false);
81 }
82
Peiyong Lind3788632018-09-18 16:01:31 -070083 memcpy(output.writeInplace(16 * sizeof(float)),
84 colorTransform.asArray(), 16 * sizeof(float));
Lucas Dupin1b6531c2018-07-05 17:18:21 -070085 output.writeFloat(cornerRadius);
Peiyong Lind3788632018-09-18 16:01:31 -070086
Marissa Wallc837b5e2018-10-12 10:04:44 -070087 if (output.writeVectorSize(listenerCallbacks) == NO_ERROR) {
88 for (const auto& [listener, callbackIds] : listenerCallbacks) {
89 output.writeStrongBinder(IInterface::asBinder(listener));
90 output.writeInt64Vector(callbackIds);
91 }
92 }
93
Mathias Agopianac9fa422013-02-11 16:40:36 -080094 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095}
96
97status_t layer_state_t::read(const Parcel& input)
98{
Mathias Agopianac9fa422013-02-11 16:40:36 -080099 surface = input.readStrongBinder();
Dan Stozad723bd72014-11-18 10:24:03 -0800100 what = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800101 x = input.readFloat();
102 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -0800103 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800104 w = input.readUint32();
105 h = input.readUint32();
106 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800107 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800108 flags = static_cast<uint8_t>(input.readUint32());
109 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700110 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
111 if (matrix_data) {
112 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
113 } else {
114 return BAD_VALUE;
115 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700116 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700117 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800118 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700119 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700120 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700121 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700122 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700123 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700124 color.r = input.readFloat();
125 color.g = input.readFloat();
126 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 15:58:15 -0700127
128#ifndef NO_INPUT
129 inputInfo = InputWindowInfo::read(input);
130#endif
131
Mathias Agopianac9fa422013-02-11 16:40:36 -0800132 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700133 transform = input.readUint32();
134 transformToDisplayInverse = input.readBool();
135 input.read(crop);
136 buffer = new GraphicBuffer();
137 if (input.readBool()) {
138 input.read(*buffer);
139 }
140 acquireFence = new Fence();
141 if (input.readBool()) {
142 input.read(*acquireFence);
143 }
144 dataspace = static_cast<ui::Dataspace>(input.readUint32());
145 input.read(hdrMetadata);
146 input.read(surfaceDamageRegion);
147 api = input.readInt32();
148 if (input.readBool()) {
149 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
150 }
151
Peiyong Lind3788632018-09-18 16:01:31 -0700152 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700153 cornerRadius = input.readFloat();
Peiyong Lind3788632018-09-18 16:01:31 -0700154
Marissa Wallc837b5e2018-10-12 10:04:44 -0700155 int32_t listenersSize = input.readInt32();
156 for (int32_t i = 0; i < listenersSize; i++) {
157 auto listener = interface_cast<ITransactionCompletedListener>(input.readStrongBinder());
158 std::vector<CallbackId> callbackIds;
159 input.readInt64Vector(&callbackIds);
160 listenerCallbacks.emplace_back(listener, callbackIds);
161 }
162
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800163 return NO_ERROR;
164}
165
Mathias Agopian698c0872011-06-28 19:09:31 -0700166status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800167 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700168 return state.write(output);
169}
170
171status_t ComposerState::read(const Parcel& input) {
172 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
173 return state.read(input);
174}
175
Mathias Agopian8b33f032012-07-24 20:43:54 -0700176
Pablo Ceballos60d69222015-08-07 14:47:20 -0700177DisplayState::DisplayState() :
178 what(0),
179 layerStack(0),
180 orientation(eOrientationDefault),
181 viewport(Rect::EMPTY_RECT),
182 frame(Rect::EMPTY_RECT),
183 width(0),
184 height(0) {
185}
186
Mathias Agopian8b33f032012-07-24 20:43:54 -0700187status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700188 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800189 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800190 output.writeUint32(what);
191 output.writeUint32(layerStack);
192 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700193 output.write(viewport);
194 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800195 output.writeUint32(width);
196 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700197 return NO_ERROR;
198}
199
200status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700201 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800202 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800203 what = input.readUint32();
204 layerStack = input.readUint32();
205 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700206 input.read(viewport);
207 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800208 width = input.readUint32();
209 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700210 return NO_ERROR;
211}
212
Robert Carr2c5f6d22017-09-26 12:30:35 -0700213void DisplayState::merge(const DisplayState& other) {
214 if (other.what & eSurfaceChanged) {
215 what |= eSurfaceChanged;
216 surface = other.surface;
217 }
218 if (other.what & eLayerStackChanged) {
219 what |= eLayerStackChanged;
220 layerStack = other.layerStack;
221 }
222 if (other.what & eDisplayProjectionChanged) {
223 what |= eDisplayProjectionChanged;
224 orientation = other.orientation;
225 viewport = other.viewport;
226 frame = other.frame;
227 }
228 if (other.what & eDisplaySizeChanged) {
229 what |= eDisplaySizeChanged;
230 width = other.width;
231 height = other.height;
232 }
233}
234
235void layer_state_t::merge(const layer_state_t& other) {
236 if (other.what & ePositionChanged) {
237 what |= ePositionChanged;
238 x = other.x;
239 y = other.y;
240 }
241 if (other.what & eLayerChanged) {
242 what |= eLayerChanged;
243 z = other.z;
244 }
245 if (other.what & eSizeChanged) {
246 what |= eSizeChanged;
247 w = other.w;
248 h = other.h;
249 }
250 if (other.what & eAlphaChanged) {
251 what |= eAlphaChanged;
252 alpha = other.alpha;
253 }
254 if (other.what & eMatrixChanged) {
255 what |= eMatrixChanged;
256 matrix = other.matrix;
257 }
258 if (other.what & eTransparentRegionChanged) {
259 what |= eTransparentRegionChanged;
260 transparentRegion = other.transparentRegion;
261 }
262 if (other.what & eFlagsChanged) {
263 what |= eFlagsChanged;
264 flags = other.flags;
265 mask = other.mask;
266 }
267 if (other.what & eLayerStackChanged) {
268 what |= eLayerStackChanged;
269 layerStack = other.layerStack;
270 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700271 if (other.what & eCropChanged_legacy) {
272 what |= eCropChanged_legacy;
273 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700274 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700275 if (other.what & eCornerRadiusChanged) {
276 what |= eCornerRadiusChanged;
277 cornerRadius = other.cornerRadius;
278 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700279 if (other.what & eDeferTransaction_legacy) {
280 what |= eDeferTransaction_legacy;
281 barrierHandle_legacy = other.barrierHandle_legacy;
282 barrierGbp_legacy = other.barrierGbp_legacy;
283 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700284 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700285 if (other.what & eOverrideScalingModeChanged) {
286 what |= eOverrideScalingModeChanged;
287 overrideScalingMode = other.overrideScalingMode;
288 }
289 if (other.what & eGeometryAppliesWithResize) {
290 what |= eGeometryAppliesWithResize;
291 }
292 if (other.what & eReparentChildren) {
293 what |= eReparentChildren;
294 reparentHandle = other.reparentHandle;
295 }
296 if (other.what & eDetachChildren) {
297 what |= eDetachChildren;
298 }
299 if (other.what & eRelativeLayerChanged) {
300 what |= eRelativeLayerChanged;
301 z = other.z;
302 relativeLayerHandle = other.relativeLayerHandle;
303 }
304 if (other.what & eReparent) {
305 what |= eReparent;
306 parentHandleForChild = other.parentHandleForChild;
307 }
chaviwca27f252018-02-06 16:46:39 -0800308 if (other.what & eDestroySurface) {
309 what |= eDestroySurface;
310 }
Marissa Wall61c58622018-07-18 10:12:20 -0700311 if (other.what & eTransformChanged) {
312 what |= eTransformChanged;
313 transform = other.transform;
314 }
315 if (other.what & eTransformToDisplayInverseChanged) {
316 what |= eTransformToDisplayInverseChanged;
317 transformToDisplayInverse = other.transformToDisplayInverse;
318 }
319 if (other.what & eCropChanged) {
320 what |= eCropChanged;
321 crop = other.crop;
322 }
323 if (other.what & eBufferChanged) {
324 what |= eBufferChanged;
325 buffer = other.buffer;
326 }
327 if (other.what & eAcquireFenceChanged) {
328 what |= eAcquireFenceChanged;
329 acquireFence = other.acquireFence;
330 }
331 if (other.what & eDataspaceChanged) {
332 what |= eDataspaceChanged;
333 dataspace = other.dataspace;
334 }
335 if (other.what & eHdrMetadataChanged) {
336 what |= eHdrMetadataChanged;
337 hdrMetadata = other.hdrMetadata;
338 }
339 if (other.what & eSurfaceDamageRegionChanged) {
340 what |= eSurfaceDamageRegionChanged;
341 surfaceDamageRegion = other.surfaceDamageRegion;
342 }
343 if (other.what & eApiChanged) {
344 what |= eApiChanged;
345 api = other.api;
346 }
347 if (other.what & eSidebandStreamChanged) {
348 what |= eSidebandStreamChanged;
349 sidebandStream = other.sidebandStream;
350 }
Peiyong Lind3788632018-09-18 16:01:31 -0700351 if (other.what & eColorTransformChanged) {
352 what |= eColorTransformChanged;
353 colorTransform = other.colorTransform;
354 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700355 if (other.what & eListenerCallbacksChanged) {
356 what |= eListenerCallbacksChanged;
357 listenerCallbacks = other.listenerCallbacks;
358 }
Robert Carrd314f162018-08-15 13:12:42 -0700359
Robert Carr2c358bf2018-08-08 15:58:15 -0700360#ifndef NO_INPUT
361 if (other.what & eInputInfoChanged) {
362 what |= eInputInfoChanged;
363 inputInfo = other.inputInfo;
364 }
365#endif
366
Vishnu Nair217d8e62018-09-12 16:34:49 -0700367 if ((other.what & what) != other.what) {
368 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
369 "other.what=0x%X what=0x%X",
370 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700371 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700372}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700373
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374}; // namespace android