blob: 7b71b39ce0cce476cc632ecfc3e0b08c937dffbf [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);
Mathias Agopianac9fa422013-02-11 16:40:36 -080053 output.write(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -070054 output.writeUint32(transform);
55 output.writeBool(transformToDisplayInverse);
56 output.write(crop);
57 if (buffer) {
58 output.writeBool(true);
59 output.write(*buffer);
60 } else {
61 output.writeBool(false);
62 }
63 if (acquireFence) {
64 output.writeBool(true);
65 output.write(*acquireFence);
66 } else {
67 output.writeBool(false);
68 }
69 output.writeUint32(static_cast<uint32_t>(dataspace));
70 output.write(hdrMetadata);
71 output.write(surfaceDamageRegion);
72 output.writeInt32(api);
73 if (sidebandStream) {
74 output.writeBool(true);
75 output.writeNativeHandle(sidebandStream->handle());
76 } else {
77 output.writeBool(false);
78 }
79
Peiyong Lind3788632018-09-18 16:01:31 -070080 memcpy(output.writeInplace(16 * sizeof(float)),
81 colorTransform.asArray(), 16 * sizeof(float));
82
Marissa Wallc837b5e2018-10-12 10:04:44 -070083 if (output.writeVectorSize(listenerCallbacks) == NO_ERROR) {
84 for (const auto& [listener, callbackIds] : listenerCallbacks) {
85 output.writeStrongBinder(IInterface::asBinder(listener));
86 output.writeInt64Vector(callbackIds);
87 }
88 }
89
Mathias Agopianac9fa422013-02-11 16:40:36 -080090 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091}
92
93status_t layer_state_t::read(const Parcel& input)
94{
Mathias Agopianac9fa422013-02-11 16:40:36 -080095 surface = input.readStrongBinder();
Dan Stozad723bd72014-11-18 10:24:03 -080096 what = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080097 x = input.readFloat();
98 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -080099 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -0800100 w = input.readUint32();
101 h = input.readUint32();
102 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800103 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -0800104 flags = static_cast<uint8_t>(input.readUint32());
105 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -0700106 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
107 if (matrix_data) {
108 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
109 } else {
110 return BAD_VALUE;
111 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700112 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700113 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800114 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700115 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700116 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700117 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700118 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700119 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700120 color.r = input.readFloat();
121 color.g = input.readFloat();
122 color.b = input.readFloat();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800123 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700124 transform = input.readUint32();
125 transformToDisplayInverse = input.readBool();
126 input.read(crop);
127 buffer = new GraphicBuffer();
128 if (input.readBool()) {
129 input.read(*buffer);
130 }
131 acquireFence = new Fence();
132 if (input.readBool()) {
133 input.read(*acquireFence);
134 }
135 dataspace = static_cast<ui::Dataspace>(input.readUint32());
136 input.read(hdrMetadata);
137 input.read(surfaceDamageRegion);
138 api = input.readInt32();
139 if (input.readBool()) {
140 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
141 }
142
Peiyong Lind3788632018-09-18 16:01:31 -0700143 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
144
Marissa Wallc837b5e2018-10-12 10:04:44 -0700145 int32_t listenersSize = input.readInt32();
146 for (int32_t i = 0; i < listenersSize; i++) {
147 auto listener = interface_cast<ITransactionCompletedListener>(input.readStrongBinder());
148 std::vector<CallbackId> callbackIds;
149 input.readInt64Vector(&callbackIds);
150 listenerCallbacks.emplace_back(listener, callbackIds);
151 }
152
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153 return NO_ERROR;
154}
155
Mathias Agopian698c0872011-06-28 19:09:31 -0700156status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800157 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700158 return state.write(output);
159}
160
161status_t ComposerState::read(const Parcel& input) {
162 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
163 return state.read(input);
164}
165
Mathias Agopian8b33f032012-07-24 20:43:54 -0700166
Pablo Ceballos60d69222015-08-07 14:47:20 -0700167DisplayState::DisplayState() :
168 what(0),
169 layerStack(0),
170 orientation(eOrientationDefault),
171 viewport(Rect::EMPTY_RECT),
172 frame(Rect::EMPTY_RECT),
173 width(0),
174 height(0) {
175}
176
Mathias Agopian8b33f032012-07-24 20:43:54 -0700177status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700178 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800179 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800180 output.writeUint32(what);
181 output.writeUint32(layerStack);
182 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700183 output.write(viewport);
184 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800185 output.writeUint32(width);
186 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700187 return NO_ERROR;
188}
189
190status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700191 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800192 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800193 what = input.readUint32();
194 layerStack = input.readUint32();
195 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700196 input.read(viewport);
197 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800198 width = input.readUint32();
199 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700200 return NO_ERROR;
201}
202
Robert Carr2c5f6d22017-09-26 12:30:35 -0700203void DisplayState::merge(const DisplayState& other) {
204 if (other.what & eSurfaceChanged) {
205 what |= eSurfaceChanged;
206 surface = other.surface;
207 }
208 if (other.what & eLayerStackChanged) {
209 what |= eLayerStackChanged;
210 layerStack = other.layerStack;
211 }
212 if (other.what & eDisplayProjectionChanged) {
213 what |= eDisplayProjectionChanged;
214 orientation = other.orientation;
215 viewport = other.viewport;
216 frame = other.frame;
217 }
218 if (other.what & eDisplaySizeChanged) {
219 what |= eDisplaySizeChanged;
220 width = other.width;
221 height = other.height;
222 }
223}
224
225void layer_state_t::merge(const layer_state_t& other) {
226 if (other.what & ePositionChanged) {
227 what |= ePositionChanged;
228 x = other.x;
229 y = other.y;
230 }
231 if (other.what & eLayerChanged) {
232 what |= eLayerChanged;
233 z = other.z;
234 }
235 if (other.what & eSizeChanged) {
236 what |= eSizeChanged;
237 w = other.w;
238 h = other.h;
239 }
240 if (other.what & eAlphaChanged) {
241 what |= eAlphaChanged;
242 alpha = other.alpha;
243 }
244 if (other.what & eMatrixChanged) {
245 what |= eMatrixChanged;
246 matrix = other.matrix;
247 }
248 if (other.what & eTransparentRegionChanged) {
249 what |= eTransparentRegionChanged;
250 transparentRegion = other.transparentRegion;
251 }
252 if (other.what & eFlagsChanged) {
253 what |= eFlagsChanged;
254 flags = other.flags;
255 mask = other.mask;
256 }
257 if (other.what & eLayerStackChanged) {
258 what |= eLayerStackChanged;
259 layerStack = other.layerStack;
260 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700261 if (other.what & eCropChanged_legacy) {
262 what |= eCropChanged_legacy;
263 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700264 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700265 if (other.what & eDeferTransaction_legacy) {
266 what |= eDeferTransaction_legacy;
267 barrierHandle_legacy = other.barrierHandle_legacy;
268 barrierGbp_legacy = other.barrierGbp_legacy;
269 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700270 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700271 if (other.what & eOverrideScalingModeChanged) {
272 what |= eOverrideScalingModeChanged;
273 overrideScalingMode = other.overrideScalingMode;
274 }
275 if (other.what & eGeometryAppliesWithResize) {
276 what |= eGeometryAppliesWithResize;
277 }
278 if (other.what & eReparentChildren) {
279 what |= eReparentChildren;
280 reparentHandle = other.reparentHandle;
281 }
282 if (other.what & eDetachChildren) {
283 what |= eDetachChildren;
284 }
285 if (other.what & eRelativeLayerChanged) {
286 what |= eRelativeLayerChanged;
287 z = other.z;
288 relativeLayerHandle = other.relativeLayerHandle;
289 }
290 if (other.what & eReparent) {
291 what |= eReparent;
292 parentHandleForChild = other.parentHandleForChild;
293 }
chaviwca27f252018-02-06 16:46:39 -0800294 if (other.what & eDestroySurface) {
295 what |= eDestroySurface;
296 }
Marissa Wall61c58622018-07-18 10:12:20 -0700297 if (other.what & eTransformChanged) {
298 what |= eTransformChanged;
299 transform = other.transform;
300 }
301 if (other.what & eTransformToDisplayInverseChanged) {
302 what |= eTransformToDisplayInverseChanged;
303 transformToDisplayInverse = other.transformToDisplayInverse;
304 }
305 if (other.what & eCropChanged) {
306 what |= eCropChanged;
307 crop = other.crop;
308 }
309 if (other.what & eBufferChanged) {
310 what |= eBufferChanged;
311 buffer = other.buffer;
312 }
313 if (other.what & eAcquireFenceChanged) {
314 what |= eAcquireFenceChanged;
315 acquireFence = other.acquireFence;
316 }
317 if (other.what & eDataspaceChanged) {
318 what |= eDataspaceChanged;
319 dataspace = other.dataspace;
320 }
321 if (other.what & eHdrMetadataChanged) {
322 what |= eHdrMetadataChanged;
323 hdrMetadata = other.hdrMetadata;
324 }
325 if (other.what & eSurfaceDamageRegionChanged) {
326 what |= eSurfaceDamageRegionChanged;
327 surfaceDamageRegion = other.surfaceDamageRegion;
328 }
329 if (other.what & eApiChanged) {
330 what |= eApiChanged;
331 api = other.api;
332 }
333 if (other.what & eSidebandStreamChanged) {
334 what |= eSidebandStreamChanged;
335 sidebandStream = other.sidebandStream;
336 }
Peiyong Lind3788632018-09-18 16:01:31 -0700337 if (other.what & eColorTransformChanged) {
338 what |= eColorTransformChanged;
339 colorTransform = other.colorTransform;
340 }
Marissa Wallc837b5e2018-10-12 10:04:44 -0700341 if (other.what & eListenerCallbacksChanged) {
342 what |= eListenerCallbacksChanged;
343 listenerCallbacks = other.listenerCallbacks;
344 }
Robert Carrd314f162018-08-15 13:12:42 -0700345
Vishnu Nair217d8e62018-09-12 16:34:49 -0700346 if ((other.what & what) != other.what) {
347 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
348 "other.what=0x%X what=0x%X",
349 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700350 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700351}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700352
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800353}; // namespace android