blob: 4f6341533d1f7f13465ec4af211008fe8d163b42 [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);
62 if (buffer) {
63 output.writeBool(true);
64 output.write(*buffer);
65 } else {
66 output.writeBool(false);
67 }
68 if (acquireFence) {
69 output.writeBool(true);
70 output.write(*acquireFence);
71 } else {
72 output.writeBool(false);
73 }
74 output.writeUint32(static_cast<uint32_t>(dataspace));
75 output.write(hdrMetadata);
76 output.write(surfaceDamageRegion);
77 output.writeInt32(api);
78 if (sidebandStream) {
79 output.writeBool(true);
80 output.writeNativeHandle(sidebandStream->handle());
81 } else {
82 output.writeBool(false);
83 }
84
Peiyong Lind3788632018-09-18 16:01:31 -070085 memcpy(output.writeInplace(16 * sizeof(float)),
86 colorTransform.asArray(), 16 * sizeof(float));
Lucas Dupin1b6531c2018-07-05 17:18:21 -070087 output.writeFloat(cornerRadius);
Peiyong Lind3788632018-09-18 16:01:31 -070088
Marissa Wallc837b5e2018-10-12 10:04:44 -070089 if (output.writeVectorSize(listenerCallbacks) == NO_ERROR) {
90 for (const auto& [listener, callbackIds] : listenerCallbacks) {
91 output.writeStrongBinder(IInterface::asBinder(listener));
92 output.writeInt64Vector(callbackIds);
93 }
94 }
95
Mathias Agopianac9fa422013-02-11 16:40:36 -080096 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097}
98
99status_t layer_state_t::read(const Parcel& input)
100{
Mathias Agopianac9fa422013-02-11 16:40:36 -0800101 surface = input.readStrongBinder();
Garfield Tan8a3083e2018-12-03 13:21:07 -0800102 what = input.readUint64();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800103 x = input.readFloat();
104 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -0800105 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800106 w = input.readUint32();
107 h = input.readUint32();
108 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800109 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800110 flags = static_cast<uint8_t>(input.readUint32());
111 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700112 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
113 if (matrix_data) {
114 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
115 } else {
116 return BAD_VALUE;
117 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700118 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700119 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800120 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700121 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700122 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700123 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700124 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700125 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700126 color.r = input.readFloat();
127 color.g = input.readFloat();
128 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 15:58:15 -0700129
130#ifndef NO_INPUT
131 inputInfo = InputWindowInfo::read(input);
132#endif
133
Mathias Agopianac9fa422013-02-11 16:40:36 -0800134 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700135 transform = input.readUint32();
136 transformToDisplayInverse = input.readBool();
137 input.read(crop);
138 buffer = new GraphicBuffer();
139 if (input.readBool()) {
140 input.read(*buffer);
141 }
142 acquireFence = new Fence();
143 if (input.readBool()) {
144 input.read(*acquireFence);
145 }
146 dataspace = static_cast<ui::Dataspace>(input.readUint32());
147 input.read(hdrMetadata);
148 input.read(surfaceDamageRegion);
149 api = input.readInt32();
150 if (input.readBool()) {
151 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
152 }
153
Peiyong Lind3788632018-09-18 16:01:31 -0700154 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700155 cornerRadius = input.readFloat();
Peiyong Lind3788632018-09-18 16:01:31 -0700156
Marissa Wallc837b5e2018-10-12 10:04:44 -0700157 int32_t listenersSize = input.readInt32();
158 for (int32_t i = 0; i < listenersSize; i++) {
159 auto listener = interface_cast<ITransactionCompletedListener>(input.readStrongBinder());
160 std::vector<CallbackId> callbackIds;
161 input.readInt64Vector(&callbackIds);
162 listenerCallbacks.emplace_back(listener, callbackIds);
163 }
164
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165 return NO_ERROR;
166}
167
Mathias Agopian698c0872011-06-28 19:09:31 -0700168status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800169 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700170 return state.write(output);
171}
172
173status_t ComposerState::read(const Parcel& input) {
174 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
175 return state.read(input);
176}
177
Mathias Agopian8b33f032012-07-24 20:43:54 -0700178
Pablo Ceballos60d69222015-08-07 14:47:20 -0700179DisplayState::DisplayState() :
180 what(0),
181 layerStack(0),
182 orientation(eOrientationDefault),
183 viewport(Rect::EMPTY_RECT),
184 frame(Rect::EMPTY_RECT),
185 width(0),
186 height(0) {
187}
188
Mathias Agopian8b33f032012-07-24 20:43:54 -0700189status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700190 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800191 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800192 output.writeUint32(what);
193 output.writeUint32(layerStack);
194 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700195 output.write(viewport);
196 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800197 output.writeUint32(width);
198 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700199 return NO_ERROR;
200}
201
202status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700203 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800204 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800205 what = input.readUint32();
206 layerStack = input.readUint32();
207 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700208 input.read(viewport);
209 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800210 width = input.readUint32();
211 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700212 return NO_ERROR;
213}
214
Robert Carr2c5f6d22017-09-26 12:30:35 -0700215void DisplayState::merge(const DisplayState& other) {
216 if (other.what & eSurfaceChanged) {
217 what |= eSurfaceChanged;
218 surface = other.surface;
219 }
220 if (other.what & eLayerStackChanged) {
221 what |= eLayerStackChanged;
222 layerStack = other.layerStack;
223 }
224 if (other.what & eDisplayProjectionChanged) {
225 what |= eDisplayProjectionChanged;
226 orientation = other.orientation;
227 viewport = other.viewport;
228 frame = other.frame;
229 }
230 if (other.what & eDisplaySizeChanged) {
231 what |= eDisplaySizeChanged;
232 width = other.width;
233 height = other.height;
234 }
235}
236
237void layer_state_t::merge(const layer_state_t& other) {
238 if (other.what & ePositionChanged) {
239 what |= ePositionChanged;
240 x = other.x;
241 y = other.y;
242 }
243 if (other.what & eLayerChanged) {
244 what |= eLayerChanged;
245 z = other.z;
246 }
247 if (other.what & eSizeChanged) {
248 what |= eSizeChanged;
249 w = other.w;
250 h = other.h;
251 }
252 if (other.what & eAlphaChanged) {
253 what |= eAlphaChanged;
254 alpha = other.alpha;
255 }
256 if (other.what & eMatrixChanged) {
257 what |= eMatrixChanged;
258 matrix = other.matrix;
259 }
260 if (other.what & eTransparentRegionChanged) {
261 what |= eTransparentRegionChanged;
262 transparentRegion = other.transparentRegion;
263 }
264 if (other.what & eFlagsChanged) {
265 what |= eFlagsChanged;
266 flags = other.flags;
267 mask = other.mask;
268 }
269 if (other.what & eLayerStackChanged) {
270 what |= eLayerStackChanged;
271 layerStack = other.layerStack;
272 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700273 if (other.what & eCropChanged_legacy) {
274 what |= eCropChanged_legacy;
275 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700276 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700277 if (other.what & eCornerRadiusChanged) {
278 what |= eCornerRadiusChanged;
279 cornerRadius = other.cornerRadius;
280 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700281 if (other.what & eDeferTransaction_legacy) {
282 what |= eDeferTransaction_legacy;
283 barrierHandle_legacy = other.barrierHandle_legacy;
284 barrierGbp_legacy = other.barrierGbp_legacy;
285 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700286 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700287 if (other.what & eOverrideScalingModeChanged) {
288 what |= eOverrideScalingModeChanged;
289 overrideScalingMode = other.overrideScalingMode;
290 }
291 if (other.what & eGeometryAppliesWithResize) {
292 what |= eGeometryAppliesWithResize;
293 }
294 if (other.what & eReparentChildren) {
295 what |= eReparentChildren;
296 reparentHandle = other.reparentHandle;
297 }
298 if (other.what & eDetachChildren) {
299 what |= eDetachChildren;
300 }
301 if (other.what & eRelativeLayerChanged) {
302 what |= eRelativeLayerChanged;
303 z = other.z;
304 relativeLayerHandle = other.relativeLayerHandle;
305 }
306 if (other.what & eReparent) {
307 what |= eReparent;
308 parentHandleForChild = other.parentHandleForChild;
309 }
chaviwca27f252018-02-06 16:46:39 -0800310 if (other.what & eDestroySurface) {
311 what |= eDestroySurface;
312 }
Marissa Wall61c58622018-07-18 10:12:20 -0700313 if (other.what & eTransformChanged) {
314 what |= eTransformChanged;
315 transform = other.transform;
316 }
317 if (other.what & eTransformToDisplayInverseChanged) {
318 what |= eTransformToDisplayInverseChanged;
319 transformToDisplayInverse = other.transformToDisplayInverse;
320 }
321 if (other.what & eCropChanged) {
322 what |= eCropChanged;
323 crop = other.crop;
324 }
325 if (other.what & eBufferChanged) {
326 what |= eBufferChanged;
327 buffer = other.buffer;
328 }
329 if (other.what & eAcquireFenceChanged) {
330 what |= eAcquireFenceChanged;
331 acquireFence = other.acquireFence;
332 }
333 if (other.what & eDataspaceChanged) {
334 what |= eDataspaceChanged;
335 dataspace = other.dataspace;
336 }
337 if (other.what & eHdrMetadataChanged) {
338 what |= eHdrMetadataChanged;
339 hdrMetadata = other.hdrMetadata;
340 }
341 if (other.what & eSurfaceDamageRegionChanged) {
342 what |= eSurfaceDamageRegionChanged;
343 surfaceDamageRegion = other.surfaceDamageRegion;
344 }
345 if (other.what & eApiChanged) {
346 what |= eApiChanged;
347 api = other.api;
348 }
349 if (other.what & eSidebandStreamChanged) {
350 what |= eSidebandStreamChanged;
351 sidebandStream = other.sidebandStream;
352 }
Peiyong Lind3788632018-09-18 16:01:31 -0700353 if (other.what & eColorTransformChanged) {
354 what |= eColorTransformChanged;
355 colorTransform = other.colorTransform;
356 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700357 if (other.what & eListenerCallbacksChanged) {
358 what |= eListenerCallbacksChanged;
359 listenerCallbacks = other.listenerCallbacks;
360 }
Robert Carrd314f162018-08-15 13:12:42 -0700361
Robert Carr2c358bf2018-08-08 15:58:15 -0700362#ifndef NO_INPUT
363 if (other.what & eInputInfoChanged) {
364 what |= eInputInfoChanged;
365 inputInfo = other.inputInfo;
366 }
367#endif
368
Vishnu Nair217d8e62018-09-12 16:34:49 -0700369 if ((other.what & what) != other.what) {
370 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Garfield Tan8a3083e2018-12-03 13:21:07 -0800371 "other.what=0x%" PRIu64 " what=0x%" PRIu64,
Vishnu Nair217d8e62018-09-12 16:34:49 -0700372 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700373 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700374}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700375
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800376}; // namespace android