blob: 0414a486e688f135d825fbd0f08e286da7ee79dd [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);
53 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054}
55
56status_t layer_state_t::read(const Parcel& input)
57{
Mathias Agopianac9fa422013-02-11 16:40:36 -080058 surface = input.readStrongBinder();
Dan Stozad723bd72014-11-18 10:24:03 -080059 what = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080060 x = input.readFloat();
61 y = input.readFloat();
Robert Carrae060832016-11-28 10:51:00 -080062 z = input.readInt32();
Dan Stozad723bd72014-11-18 10:24:03 -080063 w = input.readUint32();
64 h = input.readUint32();
65 layerStack = input.readUint32();
Mathias Agopianac9fa422013-02-11 16:40:36 -080066 alpha = input.readFloat();
Dan Stozad723bd72014-11-18 10:24:03 -080067 flags = static_cast<uint8_t>(input.readUint32());
68 mask = static_cast<uint8_t>(input.readUint32());
Michael Lentine8afa1c42014-10-31 11:10:13 -070069 const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t));
70 if (matrix_data) {
71 matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data);
72 } else {
73 return BAD_VALUE;
74 }
Marissa Wallf58c14b2018-07-24 10:50:43 -070075 input.read(crop_legacy);
76 input.read(finalCrop_legacy);
77 barrierHandle_legacy = input.readStrongBinder();
Robert Carr1db73f62016-12-21 12:58:51 -080078 reparentHandle = input.readStrongBinder();
Marissa Wallf58c14b2018-07-24 10:50:43 -070079 frameNumber_legacy = input.readUint64();
Robert Carrc3574f72016-03-24 12:19:32 -070080 overrideScalingMode = input.readInt32();
Marissa Wallf58c14b2018-07-24 10:50:43 -070081 barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Robert Carrdb66e622017-04-10 16:55:57 -070082 relativeLayerHandle = input.readStrongBinder();
chaviw06178942017-07-27 10:25:59 -070083 parentHandleForChild = input.readStrongBinder();
chaviw13fdc492017-06-27 12:40:18 -070084 color.r = input.readFloat();
85 color.g = input.readFloat();
86 color.b = input.readFloat();
Mathias Agopianac9fa422013-02-11 16:40:36 -080087 input.read(transparentRegion);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088 return NO_ERROR;
89}
90
Mathias Agopian698c0872011-06-28 19:09:31 -070091status_t ComposerState::write(Parcel& output) const {
Marco Nelissen2ea926b2014-11-14 08:01:01 -080092 output.writeStrongBinder(IInterface::asBinder(client));
Mathias Agopian698c0872011-06-28 19:09:31 -070093 return state.write(output);
94}
95
96status_t ComposerState::read(const Parcel& input) {
97 client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder());
98 return state.read(input);
99}
100
Mathias Agopian8b33f032012-07-24 20:43:54 -0700101
Pablo Ceballos60d69222015-08-07 14:47:20 -0700102DisplayState::DisplayState() :
103 what(0),
104 layerStack(0),
105 orientation(eOrientationDefault),
106 viewport(Rect::EMPTY_RECT),
107 frame(Rect::EMPTY_RECT),
108 width(0),
109 height(0) {
110}
111
Mathias Agopian8b33f032012-07-24 20:43:54 -0700112status_t DisplayState::write(Parcel& output) const {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700113 output.writeStrongBinder(token);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800114 output.writeStrongBinder(IInterface::asBinder(surface));
Dan Stozad723bd72014-11-18 10:24:03 -0800115 output.writeUint32(what);
116 output.writeUint32(layerStack);
117 output.writeUint32(orientation);
Mathias Agopian8683fca2012-08-12 19:37:16 -0700118 output.write(viewport);
119 output.write(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800120 output.writeUint32(width);
121 output.writeUint32(height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700122 return NO_ERROR;
123}
124
125status_t DisplayState::read(const Parcel& input) {
Mathias Agopiane57f2922012-08-09 16:29:12 -0700126 token = input.readStrongBinder();
Andy McFadden2adaf042012-12-18 09:49:45 -0800127 surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder());
Dan Stozad723bd72014-11-18 10:24:03 -0800128 what = input.readUint32();
129 layerStack = input.readUint32();
130 orientation = input.readUint32();
Mathias Agopian8683fca2012-08-12 19:37:16 -0700131 input.read(viewport);
132 input.read(frame);
Dan Stozad723bd72014-11-18 10:24:03 -0800133 width = input.readUint32();
134 height = input.readUint32();
Mathias Agopian8b33f032012-07-24 20:43:54 -0700135 return NO_ERROR;
136}
137
Robert Carr2c5f6d22017-09-26 12:30:35 -0700138void DisplayState::merge(const DisplayState& other) {
139 if (other.what & eSurfaceChanged) {
140 what |= eSurfaceChanged;
141 surface = other.surface;
142 }
143 if (other.what & eLayerStackChanged) {
144 what |= eLayerStackChanged;
145 layerStack = other.layerStack;
146 }
147 if (other.what & eDisplayProjectionChanged) {
148 what |= eDisplayProjectionChanged;
149 orientation = other.orientation;
150 viewport = other.viewport;
151 frame = other.frame;
152 }
153 if (other.what & eDisplaySizeChanged) {
154 what |= eDisplaySizeChanged;
155 width = other.width;
156 height = other.height;
157 }
158}
159
160void layer_state_t::merge(const layer_state_t& other) {
161 if (other.what & ePositionChanged) {
162 what |= ePositionChanged;
163 x = other.x;
164 y = other.y;
165 }
166 if (other.what & eLayerChanged) {
167 what |= eLayerChanged;
168 z = other.z;
169 }
170 if (other.what & eSizeChanged) {
171 what |= eSizeChanged;
172 w = other.w;
173 h = other.h;
174 }
175 if (other.what & eAlphaChanged) {
176 what |= eAlphaChanged;
177 alpha = other.alpha;
178 }
179 if (other.what & eMatrixChanged) {
180 what |= eMatrixChanged;
181 matrix = other.matrix;
182 }
183 if (other.what & eTransparentRegionChanged) {
184 what |= eTransparentRegionChanged;
185 transparentRegion = other.transparentRegion;
186 }
187 if (other.what & eFlagsChanged) {
188 what |= eFlagsChanged;
189 flags = other.flags;
190 mask = other.mask;
191 }
192 if (other.what & eLayerStackChanged) {
193 what |= eLayerStackChanged;
194 layerStack = other.layerStack;
195 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700196 if (other.what & eCropChanged_legacy) {
197 what |= eCropChanged_legacy;
198 crop_legacy = other.crop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700199 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700200 if (other.what & eDeferTransaction_legacy) {
201 what |= eDeferTransaction_legacy;
202 barrierHandle_legacy = other.barrierHandle_legacy;
203 barrierGbp_legacy = other.barrierGbp_legacy;
204 frameNumber_legacy = other.frameNumber_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700205 }
Marissa Wallf58c14b2018-07-24 10:50:43 -0700206 if (other.what & eFinalCropChanged_legacy) {
207 what |= eFinalCropChanged_legacy;
208 finalCrop_legacy = other.finalCrop_legacy;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700209 }
210 if (other.what & eOverrideScalingModeChanged) {
211 what |= eOverrideScalingModeChanged;
212 overrideScalingMode = other.overrideScalingMode;
213 }
214 if (other.what & eGeometryAppliesWithResize) {
215 what |= eGeometryAppliesWithResize;
216 }
217 if (other.what & eReparentChildren) {
218 what |= eReparentChildren;
219 reparentHandle = other.reparentHandle;
220 }
221 if (other.what & eDetachChildren) {
222 what |= eDetachChildren;
223 }
224 if (other.what & eRelativeLayerChanged) {
225 what |= eRelativeLayerChanged;
226 z = other.z;
227 relativeLayerHandle = other.relativeLayerHandle;
228 }
229 if (other.what & eReparent) {
230 what |= eReparent;
231 parentHandleForChild = other.parentHandleForChild;
232 }
chaviwca27f252018-02-06 16:46:39 -0800233 if (other.what & eDestroySurface) {
234 what |= eDestroySurface;
235 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700236}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700237
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800238}; // namespace android