blob: 9f300604678bbf6e3666aa904ca230bd2a687bff [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));
85
Marissa Wallc837b5e2018-10-12 10:04:44 -070086 if (output.writeVectorSize(listenerCallbacks) == NO_ERROR) {
87 for (const auto& [listener, callbackIds] : listenerCallbacks) {
88 output.writeStrongBinder(IInterface::asBinder(listener));
89 output.writeInt64Vector(callbackIds);
90 }
91 }
92
Mathias Agopianac9fa422013-02-11 16:40:36 -080093 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094}
95
96status_t layer_state_t::read(const Parcel& input)
97{
Mathias Agopianac9fa422013-02-11 16:40:36 -080098 surface = input.readStrongBinder();
Dan Stozad723bd72014-11-18 10:24:03 -080099 what = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800100 x = input.readFloat();
101 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -0800102 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800103 w = input.readUint32();
104 h = input.readUint32();
105 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800106 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800107 flags = static_cast<uint8_t>(input.readUint32());
108 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700109 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
110 if (matrix_data) {
111 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
112 } else {
113 return BAD_VALUE;
114 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700115 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700116 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800117 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700118 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700119 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700120 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700121 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700122 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700123 color.r = input.readFloat();
124 color.g = input.readFloat();
125 color.b = input.readFloat();
Robert Carr2c358bf2018-08-08 15:58:15 -0700126
127#ifndef NO_INPUT
128 inputInfo = InputWindowInfo::read(input);
129#endif
130
Mathias Agopianac9fa422013-02-11 16:40:36 -0800131 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700132 transform = input.readUint32();
133 transformToDisplayInverse = input.readBool();
134 input.read(crop);
135 buffer = new GraphicBuffer();
136 if (input.readBool()) {
137 input.read(*buffer);
138 }
139 acquireFence = new Fence();
140 if (input.readBool()) {
141 input.read(*acquireFence);
142 }
143 dataspace = static_cast<ui::Dataspace>(input.readUint32());
144 input.read(hdrMetadata);
145 input.read(surfaceDamageRegion);
146 api = input.readInt32();
147 if (input.readBool()) {
148 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
149 }
150
Peiyong Lind3788632018-09-18 16:01:31 -0700151 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
152
Marissa Wallc837b5e2018-10-12 10:04:44 -0700153 int32_t listenersSize = input.readInt32();
154 for (int32_t i = 0; i < listenersSize; i++) {
155 auto listener = interface_cast<ITransactionCompletedListener>(input.readStrongBinder());
156 std::vector<CallbackId> callbackIds;
157 input.readInt64Vector(&callbackIds);
158 listenerCallbacks.emplace_back(listener, callbackIds);
159 }
160
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800161 return NO_ERROR;
162}
163
Mathias Agopian698c0872011-06-28 19:09:31 -0700164status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800165 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700166 return state.write(output);
167}
168
169status_t ComposerState::read(const Parcel& input) {
170 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
171 return state.read(input);
172}
173
Mathias Agopian8b33f032012-07-24 20:43:54 -0700174
Pablo Ceballos60d69222015-08-07 14:47:20 -0700175DisplayState::DisplayState() :
176 what(0),
177 layerStack(0),
178 orientation(eOrientationDefault),
179 viewport(Rect::EMPTY_RECT),
180 frame(Rect::EMPTY_RECT),
181 width(0),
182 height(0) {
183}
184
Mathias Agopian8b33f032012-07-24 20:43:54 -0700185status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700186 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800187 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800188 output.writeUint32(what);
189 output.writeUint32(layerStack);
190 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700191 output.write(viewport);
192 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800193 output.writeUint32(width);
194 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700195 return NO_ERROR;
196}
197
198status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700199 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800200 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800201 what = input.readUint32();
202 layerStack = input.readUint32();
203 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700204 input.read(viewport);
205 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800206 width = input.readUint32();
207 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700208 return NO_ERROR;
209}
210
Robert Carr2c5f6d22017-09-26 12:30:35 -0700211void DisplayState::merge(const DisplayState& other) {
212 if (other.what & eSurfaceChanged) {
213 what |= eSurfaceChanged;
214 surface = other.surface;
215 }
216 if (other.what & eLayerStackChanged) {
217 what |= eLayerStackChanged;
218 layerStack = other.layerStack;
219 }
220 if (other.what & eDisplayProjectionChanged) {
221 what |= eDisplayProjectionChanged;
222 orientation = other.orientation;
223 viewport = other.viewport;
224 frame = other.frame;
225 }
226 if (other.what & eDisplaySizeChanged) {
227 what |= eDisplaySizeChanged;
228 width = other.width;
229 height = other.height;
230 }
231}
232
233void layer_state_t::merge(const layer_state_t& other) {
234 if (other.what & ePositionChanged) {
235 what |= ePositionChanged;
236 x = other.x;
237 y = other.y;
238 }
239 if (other.what & eLayerChanged) {
240 what |= eLayerChanged;
241 z = other.z;
242 }
243 if (other.what & eSizeChanged) {
244 what |= eSizeChanged;
245 w = other.w;
246 h = other.h;
247 }
248 if (other.what & eAlphaChanged) {
249 what |= eAlphaChanged;
250 alpha = other.alpha;
251 }
252 if (other.what & eMatrixChanged) {
253 what |= eMatrixChanged;
254 matrix = other.matrix;
255 }
256 if (other.what & eTransparentRegionChanged) {
257 what |= eTransparentRegionChanged;
258 transparentRegion = other.transparentRegion;
259 }
260 if (other.what & eFlagsChanged) {
261 what |= eFlagsChanged;
262 flags = other.flags;
263 mask = other.mask;
264 }
265 if (other.what & eLayerStackChanged) {
266 what |= eLayerStackChanged;
267 layerStack = other.layerStack;
268 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700269 if (other.what & eCropChanged_legacy) {
270 what |= eCropChanged_legacy;
271 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700272 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700273 if (other.what & eDeferTransaction_legacy) {
274 what |= eDeferTransaction_legacy;
275 barrierHandle_legacy = other.barrierHandle_legacy;
276 barrierGbp_legacy = other.barrierGbp_legacy;
277 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700278 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700279 if (other.what & eOverrideScalingModeChanged) {
280 what |= eOverrideScalingModeChanged;
281 overrideScalingMode = other.overrideScalingMode;
282 }
283 if (other.what & eGeometryAppliesWithResize) {
284 what |= eGeometryAppliesWithResize;
285 }
286 if (other.what & eReparentChildren) {
287 what |= eReparentChildren;
288 reparentHandle = other.reparentHandle;
289 }
290 if (other.what & eDetachChildren) {
291 what |= eDetachChildren;
292 }
293 if (other.what & eRelativeLayerChanged) {
294 what |= eRelativeLayerChanged;
295 z = other.z;
296 relativeLayerHandle = other.relativeLayerHandle;
297 }
298 if (other.what & eReparent) {
299 what |= eReparent;
300 parentHandleForChild = other.parentHandleForChild;
301 }
chaviwca27f252018-02-06 16:46:39 -0800302 if (other.what & eDestroySurface) {
303 what |= eDestroySurface;
304 }
Marissa Wall61c58622018-07-18 10:12:20 -0700305 if (other.what & eTransformChanged) {
306 what |= eTransformChanged;
307 transform = other.transform;
308 }
309 if (other.what & eTransformToDisplayInverseChanged) {
310 what |= eTransformToDisplayInverseChanged;
311 transformToDisplayInverse = other.transformToDisplayInverse;
312 }
313 if (other.what & eCropChanged) {
314 what |= eCropChanged;
315 crop = other.crop;
316 }
317 if (other.what & eBufferChanged) {
318 what |= eBufferChanged;
319 buffer = other.buffer;
320 }
321 if (other.what & eAcquireFenceChanged) {
322 what |= eAcquireFenceChanged;
323 acquireFence = other.acquireFence;
324 }
325 if (other.what & eDataspaceChanged) {
326 what |= eDataspaceChanged;
327 dataspace = other.dataspace;
328 }
329 if (other.what & eHdrMetadataChanged) {
330 what |= eHdrMetadataChanged;
331 hdrMetadata = other.hdrMetadata;
332 }
333 if (other.what & eSurfaceDamageRegionChanged) {
334 what |= eSurfaceDamageRegionChanged;
335 surfaceDamageRegion = other.surfaceDamageRegion;
336 }
337 if (other.what & eApiChanged) {
338 what |= eApiChanged;
339 api = other.api;
340 }
341 if (other.what & eSidebandStreamChanged) {
342 what |= eSidebandStreamChanged;
343 sidebandStream = other.sidebandStream;
344 }
Peiyong Lind3788632018-09-18 16:01:31 -0700345 if (other.what & eColorTransformChanged) {
346 what |= eColorTransformChanged;
347 colorTransform = other.colorTransform;
348 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700349 if (other.what & eListenerCallbacksChanged) {
350 what |= eListenerCallbacksChanged;
351 listenerCallbacks = other.listenerCallbacks;
352 }
Robert Carrd314f162018-08-15 13:12:42 -0700353
Robert Carr2c358bf2018-08-08 15:58:15 -0700354#ifndef NO_INPUT
355 if (other.what & eInputInfoChanged) {
356 what |= eInputInfoChanged;
357 inputInfo = other.inputInfo;
358 }
359#endif
360
Vishnu Nair217d8e62018-09-12 16:34:49 -0700361 if ((other.what & what) != other.what) {
362 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
363 "other.what=0x%X what=0x%X",
364 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700365 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700366}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700367
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368}; // namespace android