blob: 2b0a46181b991ee05a1ddadade26de06f70b01de [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
Mathias Agopianac9fa422013-02-11 16:40:36 -080083 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084}
85
86status_t layer_state_t::read(const Parcel& input)
87{
Mathias Agopianac9fa422013-02-11 16:40:36 -080088 surface = input.readStrongBinder();
Dan Stozad723bd72014-11-18 10:24:03 -080089 what = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080090 x = input.readFloat();
91 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -080092 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -080093 w = input.readUint32();
94 h = input.readUint32();
95 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080096 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -080097 flags = static_cast<uint8_t>(input.readUint32());
98 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -070099 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
100 if (matrix_data) {
101 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
102 } else {
103 return BAD_VALUE;
104 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700105 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700106 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800107 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700108 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700109 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700110 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700111 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700112 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700113 color.r = input.readFloat();
114 color.g = input.readFloat();
115 color.b = input.readFloat();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800116 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700117 transform = input.readUint32();
118 transformToDisplayInverse = input.readBool();
119 input.read(crop);
120 buffer = new GraphicBuffer();
121 if (input.readBool()) {
122 input.read(*buffer);
123 }
124 acquireFence = new Fence();
125 if (input.readBool()) {
126 input.read(*acquireFence);
127 }
128 dataspace = static_cast<ui::Dataspace>(input.readUint32());
129 input.read(hdrMetadata);
130 input.read(surfaceDamageRegion);
131 api = input.readInt32();
132 if (input.readBool()) {
133 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
134 }
135
Peiyong Lind3788632018-09-18 16:01:31 -0700136 colorTransform = mat4(static_cast<const float*>(input.readInplace(16 * sizeof(float))));
137
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138 return NO_ERROR;
139}
140
Mathias Agopian698c0872011-06-28 19:09:31 -0700141status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800142 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700143 return state.write(output);
144}
145
146status_t ComposerState::read(const Parcel& input) {
147 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
148 return state.read(input);
149}
150
Mathias Agopian8b33f032012-07-24 20:43:54 -0700151
Pablo Ceballos60d69222015-08-07 14:47:20 -0700152DisplayState::DisplayState() :
153 what(0),
154 layerStack(0),
155 orientation(eOrientationDefault),
156 viewport(Rect::EMPTY_RECT),
157 frame(Rect::EMPTY_RECT),
158 width(0),
159 height(0) {
160}
161
Mathias Agopian8b33f032012-07-24 20:43:54 -0700162status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700163 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800164 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800165 output.writeUint32(what);
166 output.writeUint32(layerStack);
167 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700168 output.write(viewport);
169 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800170 output.writeUint32(width);
171 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700172 return NO_ERROR;
173}
174
175status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700176 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800177 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800178 what = input.readUint32();
179 layerStack = input.readUint32();
180 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700181 input.read(viewport);
182 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800183 width = input.readUint32();
184 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700185 return NO_ERROR;
186}
187
Robert Carr2c5f6d22017-09-26 12:30:35 -0700188void DisplayState::merge(const DisplayState& other) {
189 if (other.what & eSurfaceChanged) {
190 what |= eSurfaceChanged;
191 surface = other.surface;
192 }
193 if (other.what & eLayerStackChanged) {
194 what |= eLayerStackChanged;
195 layerStack = other.layerStack;
196 }
197 if (other.what & eDisplayProjectionChanged) {
198 what |= eDisplayProjectionChanged;
199 orientation = other.orientation;
200 viewport = other.viewport;
201 frame = other.frame;
202 }
203 if (other.what & eDisplaySizeChanged) {
204 what |= eDisplaySizeChanged;
205 width = other.width;
206 height = other.height;
207 }
208}
209
210void layer_state_t::merge(const layer_state_t& other) {
211 if (other.what & ePositionChanged) {
212 what |= ePositionChanged;
213 x = other.x;
214 y = other.y;
215 }
216 if (other.what & eLayerChanged) {
217 what |= eLayerChanged;
218 z = other.z;
219 }
220 if (other.what & eSizeChanged) {
221 what |= eSizeChanged;
222 w = other.w;
223 h = other.h;
224 }
225 if (other.what & eAlphaChanged) {
226 what |= eAlphaChanged;
227 alpha = other.alpha;
228 }
229 if (other.what & eMatrixChanged) {
230 what |= eMatrixChanged;
231 matrix = other.matrix;
232 }
233 if (other.what & eTransparentRegionChanged) {
234 what |= eTransparentRegionChanged;
235 transparentRegion = other.transparentRegion;
236 }
237 if (other.what & eFlagsChanged) {
238 what |= eFlagsChanged;
239 flags = other.flags;
240 mask = other.mask;
241 }
242 if (other.what & eLayerStackChanged) {
243 what |= eLayerStackChanged;
244 layerStack = other.layerStack;
245 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700246 if (other.what & eCropChanged_legacy) {
247 what |= eCropChanged_legacy;
248 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700249 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700250 if (other.what & eDeferTransaction_legacy) {
251 what |= eDeferTransaction_legacy;
252 barrierHandle_legacy = other.barrierHandle_legacy;
253 barrierGbp_legacy = other.barrierGbp_legacy;
254 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700255 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700256 if (other.what & eOverrideScalingModeChanged) {
257 what |= eOverrideScalingModeChanged;
258 overrideScalingMode = other.overrideScalingMode;
259 }
260 if (other.what & eGeometryAppliesWithResize) {
261 what |= eGeometryAppliesWithResize;
262 }
263 if (other.what & eReparentChildren) {
264 what |= eReparentChildren;
265 reparentHandle = other.reparentHandle;
266 }
267 if (other.what & eDetachChildren) {
268 what |= eDetachChildren;
269 }
270 if (other.what & eRelativeLayerChanged) {
271 what |= eRelativeLayerChanged;
272 z = other.z;
273 relativeLayerHandle = other.relativeLayerHandle;
274 }
275 if (other.what & eReparent) {
276 what |= eReparent;
277 parentHandleForChild = other.parentHandleForChild;
278 }
chaviwca27f252018-02-06 16:46:39 -0800279 if (other.what & eDestroySurface) {
280 what |= eDestroySurface;
281 }
Marissa Wall61c58622018-07-18 10:12:20 -0700282 if (other.what & eTransformChanged) {
283 what |= eTransformChanged;
284 transform = other.transform;
285 }
286 if (other.what & eTransformToDisplayInverseChanged) {
287 what |= eTransformToDisplayInverseChanged;
288 transformToDisplayInverse = other.transformToDisplayInverse;
289 }
290 if (other.what & eCropChanged) {
291 what |= eCropChanged;
292 crop = other.crop;
293 }
294 if (other.what & eBufferChanged) {
295 what |= eBufferChanged;
296 buffer = other.buffer;
297 }
298 if (other.what & eAcquireFenceChanged) {
299 what |= eAcquireFenceChanged;
300 acquireFence = other.acquireFence;
301 }
302 if (other.what & eDataspaceChanged) {
303 what |= eDataspaceChanged;
304 dataspace = other.dataspace;
305 }
306 if (other.what & eHdrMetadataChanged) {
307 what |= eHdrMetadataChanged;
308 hdrMetadata = other.hdrMetadata;
309 }
310 if (other.what & eSurfaceDamageRegionChanged) {
311 what |= eSurfaceDamageRegionChanged;
312 surfaceDamageRegion = other.surfaceDamageRegion;
313 }
314 if (other.what & eApiChanged) {
315 what |= eApiChanged;
316 api = other.api;
317 }
318 if (other.what & eSidebandStreamChanged) {
319 what |= eSidebandStreamChanged;
320 sidebandStream = other.sidebandStream;
321 }
Peiyong Lind3788632018-09-18 16:01:31 -0700322 if (other.what & eColorTransformChanged) {
323 what |= eColorTransformChanged;
324 colorTransform = other.colorTransform;
325 }
Robert Carrd314f162018-08-15 13:12:42 -0700326
Vishnu Nair217d8e62018-09-12 16:34:49 -0700327 if ((other.what & what) != other.what) {
328 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
329 "other.what=0x%X what=0x%X",
330 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700331 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700332}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700333
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800334}; // namespace android