blob: eec4a874b91703bb962844a6932a0ef3cb1940a4 [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
Ady Abrahamdd5bfa92021-01-07 17:56:08 -080019#include <apex/window.h>
Garfield Tan8a3083e2018-12-03 13:21:07 -080020#include <inttypes.h>
21
Marin Shalamanovc5986772021-03-16 16:09:49 +010022#include <android/native_window.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080024#include <gui/IGraphicBufferProducer.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000025#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070026#include <gui/LayerState.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010027#include <private/gui/ParcelUtils.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000028#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029
Steven Thomas62a4cf82020-01-31 12:04:03 -080030#include <cmath>
31
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032namespace android {
33
chaviw98318de2021-05-19 16:45:23 -050034using gui::FocusRequest;
35using gui::WindowInfoHandle;
36
Pablo Gamito11dcc222020-09-12 15:49:39 +000037layer_state_t::layer_state_t()
38 : what(0),
39 x(0),
40 y(0),
41 z(0),
42 w(0),
43 h(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000044 alpha(0),
45 flags(0),
46 mask(0),
47 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000048 cornerRadius(0.0f),
49 backgroundBlurRadius(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000050 transform(0),
51 transformToDisplayInverse(false),
52 crop(Rect::INVALID_RECT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000053 dataspace(ui::Dataspace::UNKNOWN),
54 surfaceDamageRegion(),
55 api(-1),
56 colorTransform(mat4()),
57 bgColorAlpha(0),
58 bgColorDataspace(ui::Dataspace::UNKNOWN),
59 colorSpaceAgnostic(false),
60 shadowRadius(0.0f),
61 frameRateSelectionPriority(-1),
62 frameRate(0.0f),
63 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010064 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Pablo Gamito11dcc222020-09-12 15:49:39 +000065 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080066 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070067 isTrustedOverlay(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070068 bufferCrop(Rect::INVALID_RECT),
69 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070070 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000071 matrix.dsdx = matrix.dtdy = 1.0f;
72 matrix.dsdy = matrix.dtdx = 0.0f;
73 hdrMetadata.validTypes = 0;
74}
75
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076status_t layer_state_t::write(Parcel& output) const
77{
chaviw308ddba2020-08-11 16:23:51 -070078 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +000079 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -070080 SAFE_PARCEL(output.writeUint64, what);
81 SAFE_PARCEL(output.writeFloat, x);
82 SAFE_PARCEL(output.writeFloat, y);
83 SAFE_PARCEL(output.writeInt32, z);
84 SAFE_PARCEL(output.writeUint32, w);
85 SAFE_PARCEL(output.writeUint32, h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -070086 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -070087 SAFE_PARCEL(output.writeFloat, alpha);
88 SAFE_PARCEL(output.writeUint32, flags);
89 SAFE_PARCEL(output.writeUint32, mask);
90 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080091 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000092 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
Pablo Gamito11dcc222020-09-12 15:49:39 +000093 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
94 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070095 SAFE_PARCEL(output.writeFloat, color.r);
96 SAFE_PARCEL(output.writeFloat, color.g);
97 SAFE_PARCEL(output.writeFloat, color.b);
chaviw98318de2021-05-19 16:45:23 -050098 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -070099 SAFE_PARCEL(output.write, transparentRegion);
100 SAFE_PARCEL(output.writeUint32, transform);
101 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700102
chaviw308ddba2020-08-11 16:23:51 -0700103 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
104 SAFE_PARCEL(output.write, hdrMetadata);
105 SAFE_PARCEL(output.write, surfaceDamageRegion);
106 SAFE_PARCEL(output.writeInt32, api);
107
Marissa Wall61c58622018-07-18 10:12:20 -0700108 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700109 SAFE_PARCEL(output.writeBool, true);
110 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700111 } else {
chaviw308ddba2020-08-11 16:23:51 -0700112 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700113 }
114
chaviw308ddba2020-08-11 16:23:51 -0700115 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
116 SAFE_PARCEL(output.writeFloat, cornerRadius);
117 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700118 SAFE_PARCEL(output.writeParcelable, metadata);
119 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
120 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
121 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
122 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700123
124 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700125 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700126 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700127 }
chaviw308ddba2020-08-11 16:23:51 -0700128 SAFE_PARCEL(output.writeFloat, shadowRadius);
129 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
130 SAFE_PARCEL(output.writeFloat, frameRate);
131 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100132 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700133 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800134 SAFE_PARCEL(output.writeBool, autoRefresh);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700135
136 SAFE_PARCEL(output.writeUint32, blurRegions.size());
137 for (auto region : blurRegions) {
138 SAFE_PARCEL(output.writeUint32, region.blurRadius);
139 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
140 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
141 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
142 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
143 SAFE_PARCEL(output.writeFloat, region.alpha);
144 SAFE_PARCEL(output.writeInt32, region.left);
145 SAFE_PARCEL(output.writeInt32, region.top);
146 SAFE_PARCEL(output.writeInt32, region.right);
147 SAFE_PARCEL(output.writeInt32, region.bottom);
148 }
John Reckcdb4ed72021-02-04 13:39:33 -0500149
150 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500151 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700152 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700153 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500154
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700155 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800156 SAFE_PARCEL(output.writeNullableParcelable,
157 bufferData ? std::make_optional<BufferData>(*bufferData) : std::nullopt);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800158 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800159}
160
161status_t layer_state_t::read(const Parcel& input)
162{
chaviw308ddba2020-08-11 16:23:51 -0700163 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000164 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700165 SAFE_PARCEL(input.readUint64, &what);
166 SAFE_PARCEL(input.readFloat, &x);
167 SAFE_PARCEL(input.readFloat, &y);
168 SAFE_PARCEL(input.readInt32, &z);
169 SAFE_PARCEL(input.readUint32, &w);
170 SAFE_PARCEL(input.readUint32, &h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700171 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700172 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700173
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800174 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700175
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800176 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700177
178 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800179 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000180 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700181
Pablo Gamito11dcc222020-09-12 15:49:39 +0000182 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
183 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
184
chaviw308ddba2020-08-11 16:23:51 -0700185 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700186 SAFE_PARCEL(input.readFloat, &tmpFloat);
187 color.r = tmpFloat;
188 SAFE_PARCEL(input.readFloat, &tmpFloat);
189 color.g = tmpFloat;
190 SAFE_PARCEL(input.readFloat, &tmpFloat);
191 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500192 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700193
chaviw308ddba2020-08-11 16:23:51 -0700194 SAFE_PARCEL(input.read, transparentRegion);
195 SAFE_PARCEL(input.readUint32, &transform);
196 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700197
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800198 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700199 SAFE_PARCEL(input.readUint32, &tmpUint32);
200 dataspace = static_cast<ui::Dataspace>(tmpUint32);
201
202 SAFE_PARCEL(input.read, hdrMetadata);
203 SAFE_PARCEL(input.read, surfaceDamageRegion);
204 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500205
206 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700207 SAFE_PARCEL(input.readBool, &tmpBool);
208 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700209 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
210 }
211
chaviw308ddba2020-08-11 16:23:51 -0700212 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
213 SAFE_PARCEL(input.readFloat, &cornerRadius);
214 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700215 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800216
chaviw308ddba2020-08-11 16:23:51 -0700217 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
218 SAFE_PARCEL(input.readUint32, &tmpUint32);
219 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
220 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800221
chaviw308ddba2020-08-11 16:23:51 -0700222 int32_t numListeners = 0;
223 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700224 listeners.clear();
225 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700226 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700227 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700228 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700229 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700230 listeners.emplace_back(listener, callbackIds);
231 }
chaviw308ddba2020-08-11 16:23:51 -0700232 SAFE_PARCEL(input.readFloat, &shadowRadius);
233 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
234 SAFE_PARCEL(input.readFloat, &frameRate);
235 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100236 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700237 SAFE_PARCEL(input.readUint32, &tmpUint32);
238 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800239 SAFE_PARCEL(input.readBool, &autoRefresh);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700240
241 uint32_t numRegions = 0;
242 SAFE_PARCEL(input.readUint32, &numRegions);
243 blurRegions.clear();
244 for (uint32_t i = 0; i < numRegions; i++) {
245 BlurRegion region;
246 SAFE_PARCEL(input.readUint32, &region.blurRadius);
247 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
248 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
249 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
250 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
251 SAFE_PARCEL(input.readFloat, &region.alpha);
252 SAFE_PARCEL(input.readInt32, &region.left);
253 SAFE_PARCEL(input.readInt32, &region.top);
254 SAFE_PARCEL(input.readInt32, &region.right);
255 SAFE_PARCEL(input.readInt32, &region.bottom);
256 blurRegions.push_back(region);
257 }
John Reckcdb4ed72021-02-04 13:39:33 -0500258
259 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500260 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700261 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700262 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500263
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700264 uint32_t mode;
265 SAFE_PARCEL(input.readUint32, &mode);
266 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800267 std::optional<BufferData> tmpBufferData;
268 SAFE_PARCEL(input.readParcelable, &tmpBufferData);
269 bufferData = tmpBufferData ? std::make_shared<BufferData>(*tmpBufferData) : nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800270 return NO_ERROR;
271}
272
Mathias Agopian698c0872011-06-28 19:09:31 -0700273status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700274 return state.write(output);
275}
276
277status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700278 return state.read(input);
279}
280
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700281DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700282
Mathias Agopian8b33f032012-07-24 20:43:54 -0700283status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700284 SAFE_PARCEL(output.writeStrongBinder, token);
285 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
286 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700287 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700288 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700289 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
290 SAFE_PARCEL(output.write, layerStackSpaceRect);
291 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
292 SAFE_PARCEL(output.writeUint32, width);
293 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700294 return NO_ERROR;
295}
296
297status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700298 SAFE_PARCEL(input.readStrongBinder, &token);
299 sp<IBinder> tmpBinder;
300 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
301 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
302
303 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700304 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700305 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700306 uint32_t tmpUint = 0;
307 SAFE_PARCEL(input.readUint32, &tmpUint);
308 orientation = ui::toRotation(tmpUint);
309
310 SAFE_PARCEL(input.read, layerStackSpaceRect);
311 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
312 SAFE_PARCEL(input.readUint32, &width);
313 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700314 return NO_ERROR;
315}
316
Robert Carr2c5f6d22017-09-26 12:30:35 -0700317void DisplayState::merge(const DisplayState& other) {
318 if (other.what & eSurfaceChanged) {
319 what |= eSurfaceChanged;
320 surface = other.surface;
321 }
322 if (other.what & eLayerStackChanged) {
323 what |= eLayerStackChanged;
324 layerStack = other.layerStack;
325 }
Evan Rosky2239b372021-05-20 13:43:47 -0700326 if (other.what & eFlagsChanged) {
327 what |= eFlagsChanged;
328 flags = other.flags;
329 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700330 if (other.what & eDisplayProjectionChanged) {
331 what |= eDisplayProjectionChanged;
332 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200333 layerStackSpaceRect = other.layerStackSpaceRect;
334 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700335 }
336 if (other.what & eDisplaySizeChanged) {
337 what |= eDisplaySizeChanged;
338 width = other.width;
339 height = other.height;
340 }
341}
342
Robert Carrde6d7b42022-01-07 18:23:06 -0800343void layer_state_t::sanitize(int32_t permissions) {
344 // TODO: b/109894387
345 //
346 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
347 // rotation. To see the problem observe that if we have a square parent, and a child
348 // of the same size, then we rotate the child 45 degrees around its center, the child
349 // must now be cropped to a non rectangular 8 sided region.
350 //
351 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
352 // private API, and arbitrary rotation is used in limited use cases, for instance:
353 // - WindowManager only uses rotation in one case, which is on a top level layer in which
354 // cropping is not an issue.
355 // - Launcher, as a privileged app, uses this to transition an application to PiP
356 // (picture-in-picture) mode.
357 //
358 // However given that abuse of rotation matrices could lead to surfaces extending outside
359 // of cropped areas, we need to prevent non-root clients without permission
360 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
361 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
362 // preserving transformations.
363 if (what & eMatrixChanged) {
364 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
365 ui::Transform t;
366 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
367 if (!t.preserveRects()) {
368 what &= ~eMatrixChanged;
369 ALOGE("Stripped non rect preserving matrix in sanitize");
370 }
371 }
372 }
373
374 if (what & eFlagsChanged) {
375 if ((flags & eLayerIsDisplayDecoration) &&
376 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
377 flags &= ~eLayerIsDisplayDecoration;
378 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
379 }
380 }
381
382 if (what & layer_state_t::eInputInfoChanged) {
383 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
384 what &= ~eInputInfoChanged;
385 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
386 }
387 }
388 if (what & layer_state_t::eTrustedOverlayChanged) {
389 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
390 what &= ~eTrustedOverlayChanged;
391 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
392 }
393 }
394 if (what & layer_state_t::eDropInputModeChanged) {
395 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
396 what &= ~eDropInputModeChanged;
397 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
398 }
399 }
400 if (what & layer_state_t::eFrameRateSelectionPriority) {
401 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
402 what &= ~eFrameRateSelectionPriority;
403 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
404 }
405 }
406 if (what & layer_state_t::eFrameRateChanged) {
407 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
408 changeFrameRateStrategy,
409 "layer_state_t::sanitize",
410 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
411 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
412 }
413 }
414}
415
Robert Carr2c5f6d22017-09-26 12:30:35 -0700416void layer_state_t::merge(const layer_state_t& other) {
417 if (other.what & ePositionChanged) {
418 what |= ePositionChanged;
419 x = other.x;
420 y = other.y;
421 }
422 if (other.what & eLayerChanged) {
423 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700424 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700425 z = other.z;
426 }
427 if (other.what & eSizeChanged) {
428 what |= eSizeChanged;
429 w = other.w;
430 h = other.h;
431 }
432 if (other.what & eAlphaChanged) {
433 what |= eAlphaChanged;
434 alpha = other.alpha;
435 }
436 if (other.what & eMatrixChanged) {
437 what |= eMatrixChanged;
438 matrix = other.matrix;
439 }
440 if (other.what & eTransparentRegionChanged) {
441 what |= eTransparentRegionChanged;
442 transparentRegion = other.transparentRegion;
443 }
444 if (other.what & eFlagsChanged) {
445 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700446 flags &= ~other.mask;
447 flags |= (other.flags & other.mask);
448 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700449 }
450 if (other.what & eLayerStackChanged) {
451 what |= eLayerStackChanged;
452 layerStack = other.layerStack;
453 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700454 if (other.what & eCornerRadiusChanged) {
455 what |= eCornerRadiusChanged;
456 cornerRadius = other.cornerRadius;
457 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800458 if (other.what & eBackgroundBlurRadiusChanged) {
459 what |= eBackgroundBlurRadiusChanged;
460 backgroundBlurRadius = other.backgroundBlurRadius;
461 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700462 if (other.what & eBlurRegionsChanged) {
463 what |= eBlurRegionsChanged;
464 blurRegions = other.blurRegions;
465 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700466 if (other.what & eRelativeLayerChanged) {
467 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700468 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700469 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000470 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700471 }
472 if (other.what & eReparent) {
473 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000474 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700475 }
chaviwca27f252018-02-06 16:46:39 -0800476 if (other.what & eDestroySurface) {
477 what |= eDestroySurface;
478 }
Marissa Wall61c58622018-07-18 10:12:20 -0700479 if (other.what & eTransformChanged) {
480 what |= eTransformChanged;
481 transform = other.transform;
482 }
483 if (other.what & eTransformToDisplayInverseChanged) {
484 what |= eTransformToDisplayInverseChanged;
485 transformToDisplayInverse = other.transformToDisplayInverse;
486 }
487 if (other.what & eCropChanged) {
488 what |= eCropChanged;
489 crop = other.crop;
490 }
491 if (other.what & eBufferChanged) {
492 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500493 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700494 }
495 if (other.what & eDataspaceChanged) {
496 what |= eDataspaceChanged;
497 dataspace = other.dataspace;
498 }
499 if (other.what & eHdrMetadataChanged) {
500 what |= eHdrMetadataChanged;
501 hdrMetadata = other.hdrMetadata;
502 }
503 if (other.what & eSurfaceDamageRegionChanged) {
504 what |= eSurfaceDamageRegionChanged;
505 surfaceDamageRegion = other.surfaceDamageRegion;
506 }
507 if (other.what & eApiChanged) {
508 what |= eApiChanged;
509 api = other.api;
510 }
511 if (other.what & eSidebandStreamChanged) {
512 what |= eSidebandStreamChanged;
513 sidebandStream = other.sidebandStream;
514 }
Peiyong Lind3788632018-09-18 16:01:31 -0700515 if (other.what & eColorTransformChanged) {
516 what |= eColorTransformChanged;
517 colorTransform = other.colorTransform;
518 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700519 if (other.what & eHasListenerCallbacksChanged) {
520 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700521 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700522 if (other.what & eInputInfoChanged) {
523 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500524 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700525 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800526 if (other.what & eBackgroundColorChanged) {
527 what |= eBackgroundColorChanged;
528 color = other.color;
529 bgColorAlpha = other.bgColorAlpha;
530 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800531 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800532 if (other.what & eMetadataChanged) {
533 what |= eMetadataChanged;
534 metadata.merge(other.metadata);
535 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700536 if (other.what & eShadowRadiusChanged) {
537 what |= eShadowRadiusChanged;
538 shadowRadius = other.shadowRadius;
539 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100540 if (other.what & eFrameRateSelectionPriority) {
541 what |= eFrameRateSelectionPriority;
542 frameRateSelectionPriority = other.frameRateSelectionPriority;
543 }
Steven Thomas3172e202020-01-06 19:25:30 -0800544 if (other.what & eFrameRateChanged) {
545 what |= eFrameRateChanged;
546 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800547 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100548 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800549 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700550 if (other.what & eFixedTransformHintChanged) {
551 what |= eFixedTransformHintChanged;
552 fixedTransformHint = other.fixedTransformHint;
553 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800554 if (other.what & eAutoRefreshChanged) {
555 what |= eAutoRefreshChanged;
556 autoRefresh = other.autoRefresh;
557 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700558 if (other.what & eTrustedOverlayChanged) {
559 what |= eTrustedOverlayChanged;
560 isTrustedOverlay = other.isTrustedOverlay;
561 }
John Reckc00c6692021-02-16 11:37:33 -0500562 if (other.what & eStretchChanged) {
563 what |= eStretchChanged;
564 stretchEffect = other.stretchEffect;
565 }
chaviwf3f40fe2021-04-27 15:54:02 -0500566 if (other.what & eBufferCropChanged) {
567 what |= eBufferCropChanged;
568 bufferCrop = other.bufferCrop;
569 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700570 if (other.what & eDestinationFrameChanged) {
571 what |= eDestinationFrameChanged;
572 destinationFrame = other.destinationFrame;
573 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700574 if (other.what & eProducerDisconnect) {
575 what |= eProducerDisconnect;
576 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700577 if (other.what & eDropInputModeChanged) {
578 what |= eDropInputModeChanged;
579 dropInputMode = other.dropInputMode;
580 }
chaviw4c36cd82021-11-18 10:37:33 -0600581 if (other.what & eColorChanged) {
582 what |= eColorChanged;
583 color = other.color;
584 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700585 if ((other.what & what) != other.what) {
586 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700587 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
588 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700589 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700590}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700591
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700592bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500593 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700594}
595
Ady Abraham6e8e3642021-07-08 19:44:07 -0700596bool layer_state_t::hasValidBuffer() const {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800597 return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700598}
599
chaviw308ddba2020-08-11 16:23:51 -0700600status_t layer_state_t::matrix22_t::write(Parcel& output) const {
601 SAFE_PARCEL(output.writeFloat, dsdx);
602 SAFE_PARCEL(output.writeFloat, dtdx);
603 SAFE_PARCEL(output.writeFloat, dtdy);
604 SAFE_PARCEL(output.writeFloat, dsdy);
605 return NO_ERROR;
606}
607
608status_t layer_state_t::matrix22_t::read(const Parcel& input) {
609 SAFE_PARCEL(input.readFloat, &dsdx);
610 SAFE_PARCEL(input.readFloat, &dtdx);
611 SAFE_PARCEL(input.readFloat, &dtdy);
612 SAFE_PARCEL(input.readFloat, &dsdy);
613 return NO_ERROR;
614}
615
chaviw273171b2018-12-26 11:46:30 -0800616// ------------------------------- InputWindowCommands ----------------------------------------
617
Vishnu Naire798b472020-07-23 13:52:21 -0700618bool InputWindowCommands::merge(const InputWindowCommands& other) {
619 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700620 changes |= !other.focusRequests.empty();
621 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
622 std::make_move_iterator(other.focusRequests.end()));
Vishnu Naire798b472020-07-23 13:52:21 -0700623 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800624 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700625 return changes;
chaviw273171b2018-12-26 11:46:30 -0800626}
627
Vishnu Nair958da932020-08-21 17:12:37 -0700628bool InputWindowCommands::empty() const {
Vishnu Nair03ccbd62021-12-01 17:21:16 -0800629 return focusRequests.empty() && !syncInputWindows;
Vishnu Nair958da932020-08-21 17:12:37 -0700630}
631
chaviw273171b2018-12-26 11:46:30 -0800632void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700633 focusRequests.clear();
chaviwa911b102019-02-14 10:18:33 -0800634 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800635}
636
chaviw308ddba2020-08-11 16:23:51 -0700637status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700638 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700639 SAFE_PARCEL(output.writeBool, syncInputWindows);
640 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800641}
642
chaviw308ddba2020-08-11 16:23:51 -0700643status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700644 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700645 SAFE_PARCEL(input.readBool, &syncInputWindows);
646 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800647}
648
Marin Shalamanovc5986772021-03-16 16:09:49 +0100649bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
650 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800651 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
652 int floatClassification = std::fpclassify(frameRate);
653 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
654 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
655 return false;
656 }
657
658 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800659 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
660 (!privileged || compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT)) {
661 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
662 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800663 return false;
664 }
665
Marin Shalamanovc5986772021-03-16 16:09:49 +0100666 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
667 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
668 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
669 changeFrameRateStrategy);
670 }
671
Steven Thomas62a4cf82020-01-31 12:04:03 -0800672 return true;
673}
674
chaviw618c42d2020-07-24 15:25:08 -0700675// ----------------------------------------------------------------------------
676
677status_t CaptureArgs::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700678 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(pixelFormat));
679 SAFE_PARCEL(output.write, sourceCrop);
chaviw17ac24b2021-01-28 18:50:05 -0800680 SAFE_PARCEL(output.writeFloat, frameScaleX);
681 SAFE_PARCEL(output.writeFloat, frameScaleY);
chaviw308ddba2020-08-11 16:23:51 -0700682 SAFE_PARCEL(output.writeBool, captureSecureLayers);
683 SAFE_PARCEL(output.writeInt32, uid);
Peiyong Lincd261472020-10-06 18:05:25 -0700684 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(dataspace));
Peiyong Lin05cc0112020-10-14 16:16:37 -0700685 SAFE_PARCEL(output.writeBool, allowProtected);
chaviw17ac24b2021-01-28 18:50:05 -0800686 SAFE_PARCEL(output.writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700687 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700688}
689
690status_t CaptureArgs::read(const Parcel& input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700691 int32_t value = 0;
692 SAFE_PARCEL(input.readInt32, &value);
693 pixelFormat = static_cast<ui::PixelFormat>(value);
chaviw308ddba2020-08-11 16:23:51 -0700694 SAFE_PARCEL(input.read, sourceCrop);
chaviw17ac24b2021-01-28 18:50:05 -0800695 SAFE_PARCEL(input.readFloat, &frameScaleX);
696 SAFE_PARCEL(input.readFloat, &frameScaleY);
chaviw308ddba2020-08-11 16:23:51 -0700697 SAFE_PARCEL(input.readBool, &captureSecureLayers);
698 SAFE_PARCEL(input.readInt32, &uid);
Peiyong Lincd261472020-10-06 18:05:25 -0700699 SAFE_PARCEL(input.readInt32, &value);
700 dataspace = static_cast<ui::Dataspace>(value);
Peiyong Lin05cc0112020-10-14 16:16:37 -0700701 SAFE_PARCEL(input.readBool, &allowProtected);
chaviw17ac24b2021-01-28 18:50:05 -0800702 SAFE_PARCEL(input.readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700703 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700704}
705
706status_t DisplayCaptureArgs::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700707 SAFE_PARCEL(CaptureArgs::write, output);
chaviw618c42d2020-07-24 15:25:08 -0700708
chaviw308ddba2020-08-11 16:23:51 -0700709 SAFE_PARCEL(output.writeStrongBinder, displayToken);
710 SAFE_PARCEL(output.writeUint32, width);
711 SAFE_PARCEL(output.writeUint32, height);
712 SAFE_PARCEL(output.writeBool, useIdentityTransform);
713 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700714}
715
716status_t DisplayCaptureArgs::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700717 SAFE_PARCEL(CaptureArgs::read, input);
chaviw618c42d2020-07-24 15:25:08 -0700718
chaviw308ddba2020-08-11 16:23:51 -0700719 SAFE_PARCEL(input.readStrongBinder, &displayToken);
720 SAFE_PARCEL(input.readUint32, &width);
721 SAFE_PARCEL(input.readUint32, &height);
722 SAFE_PARCEL(input.readBool, &useIdentityTransform);
723 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700724}
725
726status_t LayerCaptureArgs::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700727 SAFE_PARCEL(CaptureArgs::write, output);
chaviw618c42d2020-07-24 15:25:08 -0700728
chaviw308ddba2020-08-11 16:23:51 -0700729 SAFE_PARCEL(output.writeStrongBinder, layerHandle);
730 SAFE_PARCEL(output.writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700731 for (auto el : excludeHandles) {
chaviw308ddba2020-08-11 16:23:51 -0700732 SAFE_PARCEL(output.writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700733 }
chaviw308ddba2020-08-11 16:23:51 -0700734 SAFE_PARCEL(output.writeBool, childrenOnly);
735 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700736}
737
738status_t LayerCaptureArgs::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700739 SAFE_PARCEL(CaptureArgs::read, input);
chaviw618c42d2020-07-24 15:25:08 -0700740
chaviw308ddba2020-08-11 16:23:51 -0700741 SAFE_PARCEL(input.readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700742
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700743 int32_t numExcludeHandles = 0;
chaviw308ddba2020-08-11 16:23:51 -0700744 SAFE_PARCEL_READ_SIZE(input.readInt32, &numExcludeHandles, input.dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700745 excludeHandles.reserve(numExcludeHandles);
746 for (int i = 0; i < numExcludeHandles; i++) {
747 sp<IBinder> binder;
chaviw308ddba2020-08-11 16:23:51 -0700748 SAFE_PARCEL(input.readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700749 excludeHandles.emplace(binder);
750 }
751
chaviw308ddba2020-08-11 16:23:51 -0700752 SAFE_PARCEL(input.readBool, &childrenOnly);
753 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700754}
755
chaviw8dd181f2022-01-05 18:36:46 -0600756ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
757 return {buffer->getId(), frameNumber};
758}
759
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800760status_t BufferData::writeToParcel(Parcel* output) const {
761 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500762
763 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800764 SAFE_PARCEL(output->writeBool, true);
765 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500766 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800767 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500768 }
769
770 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800771 SAFE_PARCEL(output->writeBool, true);
772 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500773 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800774 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500775 }
776
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800777 SAFE_PARCEL(output->writeUint64, frameNumber);
778 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
779 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500780
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800781 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
782 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500783
784 return NO_ERROR;
785}
786
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800787status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500788 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800789 SAFE_PARCEL(input->readInt32, &tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500790 flags = Flags<BufferDataChange>(tmpInt32);
791
792 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800793 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500794 if (tmpBool) {
795 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800796 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500797 }
798
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800799 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500800 if (tmpBool) {
801 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800802 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500803 }
804
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800805 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500806
807 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800808 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500809 if (tmpBinder) {
810 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
811 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800812 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500813
814 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800815 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500816 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800817 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500818
819 return NO_ERROR;
820}
821
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800822}; // namespace android