blob: deb8ea8f7e7d224f51d3280d26454d1faf5631e9 [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);
Marissa Wallf58c14b2018-07-24 10:50:43 -070041 output.writeStrongBinder(barrierHandle_legacy);
Robert Carr1db73f62016-12-21 12:58:51 -080042 output.writeStrongBinder(reparentHandle);
Marissa Wallf58c14b2018-07-24 10:50:43 -070043 output.writeUint64(frameNumber_legacy);
Robert Carrc3574f72016-03-24 12:19:32 -070044 output.writeInt32(overrideScalingMode);
Marissa Wallf58c14b2018-07-24 10:50:43 -070045 output.writeStrongBinder(IInterface::asBinder(barrierGbp_legacy));
Robert Carrdb66e622017-04-10 16:55:57 -070046 output.writeStrongBinder(relativeLayerHandle);
chaviw06178942017-07-27 10:25:59 -070047 output.writeStrongBinder(parentHandleForChild);
chaviw13fdc492017-06-27 12:40:18 -070048 output.writeFloat(color.r);
49 output.writeFloat(color.g);
50 output.writeFloat(color.b);
Mathias Agopianac9fa422013-02-11 16:40:36 -080051 output.write(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -070052 output.writeUint32(transform);
53 output.writeBool(transformToDisplayInverse);
54 output.write(crop);
55 if (buffer) {
56 output.writeBool(true);
57 output.write(*buffer);
58 } else {
59 output.writeBool(false);
60 }
61 if (acquireFence) {
62 output.writeBool(true);
63 output.write(*acquireFence);
64 } else {
65 output.writeBool(false);
66 }
67 output.writeUint32(static_cast<uint32_t>(dataspace));
68 output.write(hdrMetadata);
69 output.write(surfaceDamageRegion);
70 output.writeInt32(api);
71 if (sidebandStream) {
72 output.writeBool(true);
73 output.writeNativeHandle(sidebandStream->handle());
74 } else {
75 output.writeBool(false);
76 }
77
Mathias Agopianac9fa422013-02-11 16:40:36 -080078 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079}
80
81status_t layer_state_t::read(const Parcel& input)
82{
Mathias Agopianac9fa422013-02-11 16:40:36 -080083 surface = input.readStrongBinder();
Dan Stozad723bd72014-11-18 10:24:03 -080084 what = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080085 x = input.readFloat();
86 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -080087 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -080088 w = input.readUint32();
89 h = input.readUint32();
90 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080091 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -080092 flags = static_cast<uint8_t>(input.readUint32());
93 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -070094 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
95 if (matrix_data) {
96 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
97 } else {
98 return BAD_VALUE;
99 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700100 input.read(crop_legacy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700101 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -0800102 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700103 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -0700104 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -0700105 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -0700106 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -0700107 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -0700108 color.r = input.readFloat();
109 color.g = input.readFloat();
110 color.b = input.readFloat();
Mathias Agopianac9fa422013-02-11 16:40:36 -0800111 input.read(transparentRegion);
Marissa Wall61c58622018-07-18 10:12:20 -0700112 transform = input.readUint32();
113 transformToDisplayInverse = input.readBool();
114 input.read(crop);
115 buffer = new GraphicBuffer();
116 if (input.readBool()) {
117 input.read(*buffer);
118 }
119 acquireFence = new Fence();
120 if (input.readBool()) {
121 input.read(*acquireFence);
122 }
123 dataspace = static_cast<ui::Dataspace>(input.readUint32());
124 input.read(hdrMetadata);
125 input.read(surfaceDamageRegion);
126 api = input.readInt32();
127 if (input.readBool()) {
128 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
129 }
130
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131 return NO_ERROR;
132}
133
Mathias Agopian698c0872011-06-28 19:09:31 -0700134status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800135 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -0700136 return state.write(output);
137}
138
139status_t ComposerState::read(const Parcel& input) {
140 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
141 return state.read(input);
142}
143
Mathias Agopian8b33f032012-07-24 20:43:54 -0700144
Pablo Ceballos60d69222015-08-07 14:47:20 -0700145DisplayState::DisplayState() :
146 what(0),
147 layerStack(0),
148 orientation(eOrientationDefault),
149 viewport(Rect::EMPTY_RECT),
150 frame(Rect::EMPTY_RECT),
151 width(0),
152 height(0) {
153}
154
Mathias Agopian8b33f032012-07-24 20:43:54 -0700155status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700156 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800157 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800158 output.writeUint32(what);
159 output.writeUint32(layerStack);
160 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700161 output.write(viewport);
162 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800163 output.writeUint32(width);
164 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700165 return NO_ERROR;
166}
167
168status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700169 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800170 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800171 what = input.readUint32();
172 layerStack = input.readUint32();
173 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700174 input.read(viewport);
175 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800176 width = input.readUint32();
177 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700178 return NO_ERROR;
179}
180
Robert Carr2c5f6d22017-09-26 12:30:35 -0700181void DisplayState::merge(const DisplayState& other) {
182 if (other.what & eSurfaceChanged) {
183 what |= eSurfaceChanged;
184 surface = other.surface;
185 }
186 if (other.what & eLayerStackChanged) {
187 what |= eLayerStackChanged;
188 layerStack = other.layerStack;
189 }
190 if (other.what & eDisplayProjectionChanged) {
191 what |= eDisplayProjectionChanged;
192 orientation = other.orientation;
193 viewport = other.viewport;
194 frame = other.frame;
195 }
196 if (other.what & eDisplaySizeChanged) {
197 what |= eDisplaySizeChanged;
198 width = other.width;
199 height = other.height;
200 }
201}
202
203void layer_state_t::merge(const layer_state_t& other) {
204 if (other.what & ePositionChanged) {
205 what |= ePositionChanged;
206 x = other.x;
207 y = other.y;
208 }
209 if (other.what & eLayerChanged) {
210 what |= eLayerChanged;
211 z = other.z;
212 }
213 if (other.what & eSizeChanged) {
214 what |= eSizeChanged;
215 w = other.w;
216 h = other.h;
217 }
218 if (other.what & eAlphaChanged) {
219 what |= eAlphaChanged;
220 alpha = other.alpha;
221 }
222 if (other.what & eMatrixChanged) {
223 what |= eMatrixChanged;
224 matrix = other.matrix;
225 }
226 if (other.what & eTransparentRegionChanged) {
227 what |= eTransparentRegionChanged;
228 transparentRegion = other.transparentRegion;
229 }
230 if (other.what & eFlagsChanged) {
231 what |= eFlagsChanged;
232 flags = other.flags;
233 mask = other.mask;
234 }
235 if (other.what & eLayerStackChanged) {
236 what |= eLayerStackChanged;
237 layerStack = other.layerStack;
238 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700239 if (other.what & eCropChanged_legacy) {
240 what |= eCropChanged_legacy;
241 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700242 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700243 if (other.what & eDeferTransaction_legacy) {
244 what |= eDeferTransaction_legacy;
245 barrierHandle_legacy = other.barrierHandle_legacy;
246 barrierGbp_legacy = other.barrierGbp_legacy;
247 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700248 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700249 if (other.what & eOverrideScalingModeChanged) {
250 what |= eOverrideScalingModeChanged;
251 overrideScalingMode = other.overrideScalingMode;
252 }
253 if (other.what & eGeometryAppliesWithResize) {
254 what |= eGeometryAppliesWithResize;
255 }
256 if (other.what & eReparentChildren) {
257 what |= eReparentChildren;
258 reparentHandle = other.reparentHandle;
259 }
260 if (other.what & eDetachChildren) {
261 what |= eDetachChildren;
262 }
263 if (other.what & eRelativeLayerChanged) {
264 what |= eRelativeLayerChanged;
265 z = other.z;
266 relativeLayerHandle = other.relativeLayerHandle;
267 }
268 if (other.what & eReparent) {
269 what |= eReparent;
270 parentHandleForChild = other.parentHandleForChild;
271 }
chaviwca27f252018-02-06 16:46:39 -0800272 if (other.what & eDestroySurface) {
273 what |= eDestroySurface;
274 }
Marissa Wall61c58622018-07-18 10:12:20 -0700275 if (other.what & eTransformChanged) {
276 what |= eTransformChanged;
277 transform = other.transform;
278 }
279 if (other.what & eTransformToDisplayInverseChanged) {
280 what |= eTransformToDisplayInverseChanged;
281 transformToDisplayInverse = other.transformToDisplayInverse;
282 }
283 if (other.what & eCropChanged) {
284 what |= eCropChanged;
285 crop = other.crop;
286 }
287 if (other.what & eBufferChanged) {
288 what |= eBufferChanged;
289 buffer = other.buffer;
290 }
291 if (other.what & eAcquireFenceChanged) {
292 what |= eAcquireFenceChanged;
293 acquireFence = other.acquireFence;
294 }
295 if (other.what & eDataspaceChanged) {
296 what |= eDataspaceChanged;
297 dataspace = other.dataspace;
298 }
299 if (other.what & eHdrMetadataChanged) {
300 what |= eHdrMetadataChanged;
301 hdrMetadata = other.hdrMetadata;
302 }
303 if (other.what & eSurfaceDamageRegionChanged) {
304 what |= eSurfaceDamageRegionChanged;
305 surfaceDamageRegion = other.surfaceDamageRegion;
306 }
307 if (other.what & eApiChanged) {
308 what |= eApiChanged;
309 api = other.api;
310 }
311 if (other.what & eSidebandStreamChanged) {
312 what |= eSidebandStreamChanged;
313 sidebandStream = other.sidebandStream;
314 }
Robert Carrd314f162018-08-15 13:12:42 -0700315
316 if (other.what != what) {
317 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating?");
318 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700319}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700320
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800321}; // namespace android