blob: 931c446275da5e8c0434b44d72699f56aaeef521 [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
17#include <utils/Errors.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070018#include <binder/Parcel.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080019#include <gui/ISurfaceComposerClient.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080020#include <gui/IGraphicBufferProducer.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070021#include <gui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022
23namespace android {
24
25status_t layer_state_t::write(Parcel& output) const
26{
Mathias Agopianac9fa422013-02-11 16:40:36 -080027 output.writeStrongBinder(surface);
Dan Stozad723bd72014-11-18 10:24:03 -080028 output.writeUint32(what);
Mathias Agopianac9fa422013-02-11 16:40:36 -080029 output.writeFloat(x);
30 output.writeFloat(y);
Robert Carrae060832016-11-28 10:51:00 -080031 output.writeInt32(z);
Dan Stozad723bd72014-11-18 10:24:03 -080032 output.writeUint32(w);
33 output.writeUint32(h);
34 output.writeUint32(layerStack);
Mathias Agopianac9fa422013-02-11 16:40:36 -080035 output.writeFloat(alpha);
Dan Stozad723bd72014-11-18 10:24:03 -080036 output.writeUint32(flags);
37 output.writeUint32(mask);
Mathias Agopianac9fa422013-02-11 16:40:36 -080038 *reinterpret_cast<layer_state_t::matrix22_t *>(
39 output.writeInplace(sizeof(layer_state_t::matrix22_t))) = matrix;
Marissa Wallf58c14b2018-07-24 10:50:43 -070040 output.write(crop_legacy);
41 output.write(finalCrop_legacy);
42 output.writeStrongBinder(barrierHandle_legacy);
Robert Carr1db73f62016-12-21 12:58:51 -080043 output.writeStrongBinder(reparentHandle);
Marissa Wallf58c14b2018-07-24 10:50:43 -070044 output.writeUint64(frameNumber_legacy);
Robert Carrc3574f72016-03-24 12:19:32 -070045 output.writeInt32(overrideScalingMode);
Marissa Wallf58c14b2018-07-24 10:50:43 -070046 output.writeStrongBinder(IInterface::asBinder(barrierGbp_legacy));
Robert Carrdb66e622017-04-10 16:55:57 -070047 output.writeStrongBinder(relativeLayerHandle);
chaviw06178942017-07-27 10:25:59 -070048 output.writeStrongBinder(parentHandleForChild);
chaviw13fdc492017-06-27 12:40:18 -070049 output.writeFloat(color.r);
50 output.writeFloat(color.g);
51 output.writeFloat(color.b);
Mathias Agopianac9fa422013-02-11 16:40:36 -080052 output.write(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -070053 output.writeUint32(transform);
54 output.writeBool(transformToDisplayInverse);
55 output.write(crop);
56 if (buffer) {
57 output.writeBool(true);
58 output.write(*buffer);
59 } else {
60 output.writeBool(false);
61 }
62 if (acquireFence) {
63 output.writeBool(true);
64 output.write(*acquireFence);
65 } else {
66 output.writeBool(false);
67 }
68 output.writeUint32(static_cast<uint32_t>(dataspace));
69 output.write(hdrMetadata);
70 output.write(surfaceDamageRegion);
71 output.writeInt32(api);
72 if (sidebandStream) {
73 output.writeBool(true);
74 output.writeNativeHandle(sidebandStream->handle());
75 } else {
76 output.writeBool(false);
77 }
78
Mathias Agopianac9fa422013-02-11 16:40:36 -080079 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080}
81
82status_t layer_state_t::read(const Parcel& input)
83{
Mathias Agopianac9fa422013-02-11 16:40:36 -080084 surface = input.readStrongBinder();
Dan Stozad723bd72014-11-18 10:24:03 -080085 what = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080086 x = input.readFloat();
87 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -080088 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -080089 w = input.readUint32();
90 h = input.readUint32();
91 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080092 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -080093 flags = static_cast<uint8_t>(input.readUint32());
94 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -070095 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
96 if (matrix_data) {
97 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
98 } else {
99 return BAD_VALUE;
100 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700101 input.read(crop_legacy);
102 input.read(finalCrop_legacy);
103 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 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700251 if (other.what & eFinalCropChanged_legacy) {
252 what |= eFinalCropChanged_legacy;
253 finalCrop_legacy = other.finalCrop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700254 }
255 if (other.what & eOverrideScalingModeChanged) {
256 what |= eOverrideScalingModeChanged;
257 overrideScalingMode = other.overrideScalingMode;
258 }
259 if (other.what & eGeometryAppliesWithResize) {
260 what |= eGeometryAppliesWithResize;
261 }
262 if (other.what & eReparentChildren) {
263 what |= eReparentChildren;
264 reparentHandle = other.reparentHandle;
265 }
266 if (other.what & eDetachChildren) {
267 what |= eDetachChildren;
268 }
269 if (other.what & eRelativeLayerChanged) {
270 what |= eRelativeLayerChanged;
271 z = other.z;
272 relativeLayerHandle = other.relativeLayerHandle;
273 }
274 if (other.what & eReparent) {
275 what |= eReparent;
276 parentHandleForChild = other.parentHandleForChild;
277 }
chaviwca27f252018-02-06 16:46:39 -0800278 if (other.what & eDestroySurface) {
279 what |= eDestroySurface;
280 }
Marissa Wall61c58622018-07-18 10:12:20 -0700281 if (other.what & eTransformChanged) {
282 what |= eTransformChanged;
283 transform = other.transform;
284 }
285 if (other.what & eTransformToDisplayInverseChanged) {
286 what |= eTransformToDisplayInverseChanged;
287 transformToDisplayInverse = other.transformToDisplayInverse;
288 }
289 if (other.what & eCropChanged) {
290 what |= eCropChanged;
291 crop = other.crop;
292 }
293 if (other.what & eBufferChanged) {
294 what |= eBufferChanged;
295 buffer = other.buffer;
296 }
297 if (other.what & eAcquireFenceChanged) {
298 what |= eAcquireFenceChanged;
299 acquireFence = other.acquireFence;
300 }
301 if (other.what & eDataspaceChanged) {
302 what |= eDataspaceChanged;
303 dataspace = other.dataspace;
304 }
305 if (other.what & eHdrMetadataChanged) {
306 what |= eHdrMetadataChanged;
307 hdrMetadata = other.hdrMetadata;
308 }
309 if (other.what & eSurfaceDamageRegionChanged) {
310 what |= eSurfaceDamageRegionChanged;
311 surfaceDamageRegion = other.surfaceDamageRegion;
312 }
313 if (other.what & eApiChanged) {
314 what |= eApiChanged;
315 api = other.api;
316 }
317 if (other.what & eSidebandStreamChanged) {
318 what |= eSidebandStreamChanged;
319 sidebandStream = other.sidebandStream;
320 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700321}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700322
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800323}; // namespace android