blob: 5a8d8dbc81efa87663647bc269a345f4318211a2 [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
Mathias Agopianac9fa422013-02-11 16:40:36 -080080 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081}
82
83status_t layer_state_t::read(const Parcel& input)
84{
Mathias Agopianac9fa422013-02-11 16:40:36 -080085 surface = input.readStrongBinder();
Dan Stozad723bd72014-11-18 10:24:03 -080086 what = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080087 x = input.readFloat();
88 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -080089 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -080090 w = input.readUint32();
91 h = input.readUint32();
92 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080093 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -080094 flags = static_cast<uint8_t>(input.readUint32());
95 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -070096 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
97 if (matrix_data) {
98 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
99 } else {
100 return BAD_VALUE;
101 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700102 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700103 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800104 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700105 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700106 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700107 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700108 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700109 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700110 color.r = input.readFloat();
111 color.g = input.readFloat();
112 color.b = input.readFloat();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800113 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700114 transform = input.readUint32();
115 transformToDisplayInverse = input.readBool();
116 input.read(crop);
117 buffer = new GraphicBuffer();
118 if (input.readBool()) {
119 input.read(*buffer);
120 }
121 acquireFence = new Fence();
122 if (input.readBool()) {
123 input.read(*acquireFence);
124 }
125 dataspace = static_cast<ui::Dataspace>(input.readUint32());
126 input.read(hdrMetadata);
127 input.read(surfaceDamageRegion);
128 api = input.readInt32();
129 if (input.readBool()) {
130 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
131 }
132
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133 return NO_ERROR;
134}
135
Mathias Agopian698c0872011-06-28 19:09:31 -0700136status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800137 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700138 return state.write(output);
139}
140
141status_t ComposerState::read(const Parcel& input) {
142 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
143 return state.read(input);
144}
145
Mathias Agopian8b33f032012-07-24 20:43:54 -0700146
Pablo Ceballos60d69222015-08-07 14:47:20 -0700147DisplayState::DisplayState() :
148 what(0),
149 layerStack(0),
150 orientation(eOrientationDefault),
151 viewport(Rect::EMPTY_RECT),
152 frame(Rect::EMPTY_RECT),
153 width(0),
154 height(0) {
155}
156
Mathias Agopian8b33f032012-07-24 20:43:54 -0700157status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700158 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800159 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800160 output.writeUint32(what);
161 output.writeUint32(layerStack);
162 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700163 output.write(viewport);
164 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800165 output.writeUint32(width);
166 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700167 return NO_ERROR;
168}
169
170status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700171 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800172 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800173 what = input.readUint32();
174 layerStack = input.readUint32();
175 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700176 input.read(viewport);
177 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800178 width = input.readUint32();
179 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700180 return NO_ERROR;
181}
182
Robert Carr2c5f6d22017-09-26 12:30:35 -0700183void DisplayState::merge(const DisplayState& other) {
184 if (other.what & eSurfaceChanged) {
185 what |= eSurfaceChanged;
186 surface = other.surface;
187 }
188 if (other.what & eLayerStackChanged) {
189 what |= eLayerStackChanged;
190 layerStack = other.layerStack;
191 }
192 if (other.what & eDisplayProjectionChanged) {
193 what |= eDisplayProjectionChanged;
194 orientation = other.orientation;
195 viewport = other.viewport;
196 frame = other.frame;
197 }
198 if (other.what & eDisplaySizeChanged) {
199 what |= eDisplaySizeChanged;
200 width = other.width;
201 height = other.height;
202 }
203}
204
205void layer_state_t::merge(const layer_state_t& other) {
206 if (other.what & ePositionChanged) {
207 what |= ePositionChanged;
208 x = other.x;
209 y = other.y;
210 }
211 if (other.what & eLayerChanged) {
212 what |= eLayerChanged;
213 z = other.z;
214 }
215 if (other.what & eSizeChanged) {
216 what |= eSizeChanged;
217 w = other.w;
218 h = other.h;
219 }
220 if (other.what & eAlphaChanged) {
221 what |= eAlphaChanged;
222 alpha = other.alpha;
223 }
224 if (other.what & eMatrixChanged) {
225 what |= eMatrixChanged;
226 matrix = other.matrix;
227 }
228 if (other.what & eTransparentRegionChanged) {
229 what |= eTransparentRegionChanged;
230 transparentRegion = other.transparentRegion;
231 }
232 if (other.what & eFlagsChanged) {
233 what |= eFlagsChanged;
234 flags = other.flags;
235 mask = other.mask;
236 }
237 if (other.what & eLayerStackChanged) {
238 what |= eLayerStackChanged;
239 layerStack = other.layerStack;
240 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700241 if (other.what & eCropChanged_legacy) {
242 what |= eCropChanged_legacy;
243 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700244 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700245 if (other.what & eDeferTransaction_legacy) {
246 what |= eDeferTransaction_legacy;
247 barrierHandle_legacy = other.barrierHandle_legacy;
248 barrierGbp_legacy = other.barrierGbp_legacy;
249 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700250 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700251 if (other.what & eOverrideScalingModeChanged) {
252 what |= eOverrideScalingModeChanged;
253 overrideScalingMode = other.overrideScalingMode;
254 }
255 if (other.what & eGeometryAppliesWithResize) {
256 what |= eGeometryAppliesWithResize;
257 }
258 if (other.what & eReparentChildren) {
259 what |= eReparentChildren;
260 reparentHandle = other.reparentHandle;
261 }
262 if (other.what & eDetachChildren) {
263 what |= eDetachChildren;
264 }
265 if (other.what & eRelativeLayerChanged) {
266 what |= eRelativeLayerChanged;
267 z = other.z;
268 relativeLayerHandle = other.relativeLayerHandle;
269 }
270 if (other.what & eReparent) {
271 what |= eReparent;
272 parentHandleForChild = other.parentHandleForChild;
273 }
chaviwca27f252018-02-06 16:46:39 -0800274 if (other.what & eDestroySurface) {
275 what |= eDestroySurface;
276 }
Marissa Wall61c58622018-07-18 10:12:20 -0700277 if (other.what & eTransformChanged) {
278 what |= eTransformChanged;
279 transform = other.transform;
280 }
281 if (other.what & eTransformToDisplayInverseChanged) {
282 what |= eTransformToDisplayInverseChanged;
283 transformToDisplayInverse = other.transformToDisplayInverse;
284 }
285 if (other.what & eCropChanged) {
286 what |= eCropChanged;
287 crop = other.crop;
288 }
289 if (other.what & eBufferChanged) {
290 what |= eBufferChanged;
291 buffer = other.buffer;
292 }
293 if (other.what & eAcquireFenceChanged) {
294 what |= eAcquireFenceChanged;
295 acquireFence = other.acquireFence;
296 }
297 if (other.what & eDataspaceChanged) {
298 what |= eDataspaceChanged;
299 dataspace = other.dataspace;
300 }
301 if (other.what & eHdrMetadataChanged) {
302 what |= eHdrMetadataChanged;
303 hdrMetadata = other.hdrMetadata;
304 }
305 if (other.what & eSurfaceDamageRegionChanged) {
306 what |= eSurfaceDamageRegionChanged;
307 surfaceDamageRegion = other.surfaceDamageRegion;
308 }
309 if (other.what & eApiChanged) {
310 what |= eApiChanged;
311 api = other.api;
312 }
313 if (other.what & eSidebandStreamChanged) {
314 what |= eSidebandStreamChanged;
315 sidebandStream = other.sidebandStream;
316 }
Robert Carrd314f162018-08-15 13:12:42 -0700317
Vishnu Nair217d8e62018-09-12 16:34:49 -0700318 if ((other.what & what) != other.what) {
319 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
320 "other.what=0x%X what=0x%X",
321 other.what, what);
Robert Carrd314f162018-08-15 13:12:42 -0700322 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700323}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700324
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800325}; // namespace android