blob: bb660854c843c1f0c46533c07e794cbaaebc8e1f [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
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070019#include <cinttypes>
20#include <cmath>
Garfield Tan8a3083e2018-12-03 13:21:07 -080021
Huihong Luod3d8f8e2022-03-08 14:48:46 -080022#include <android/gui/ISurfaceComposerClient.h>
Marin Shalamanovc5986772021-03-16 16:09:49 +010023#include <android/native_window.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/Parcel.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080025#include <gui/IGraphicBufferProducer.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>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070028#include <system/window.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000029#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030
31namespace android {
32
chaviw98318de2021-05-19 16:45:23 -050033using gui::FocusRequest;
34using gui::WindowInfoHandle;
35
Pablo Gamito11dcc222020-09-12 15:49:39 +000036layer_state_t::layer_state_t()
Vishnu Nair685cfef2022-02-02 10:01:25 -080037 : surface(nullptr),
38 layerId(-1),
39 what(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000040 x(0),
41 y(0),
42 z(0),
43 w(0),
44 h(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000045 alpha(0),
46 flags(0),
47 mask(0),
48 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000049 cornerRadius(0.0f),
50 backgroundBlurRadius(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000051 transform(0),
52 transformToDisplayInverse(false),
53 crop(Rect::INVALID_RECT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000054 dataspace(ui::Dataspace::UNKNOWN),
55 surfaceDamageRegion(),
56 api(-1),
57 colorTransform(mat4()),
58 bgColorAlpha(0),
59 bgColorDataspace(ui::Dataspace::UNKNOWN),
60 colorSpaceAgnostic(false),
61 shadowRadius(0.0f),
62 frameRateSelectionPriority(-1),
63 frameRate(0.0f),
64 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010065 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Andy Labrada096227e2022-06-15 16:58:11 +000066 defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000067 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080068 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070069 isTrustedOverlay(false),
Tianhao Yao67dd7122022-02-22 17:48:33 +000070 borderEnabled(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070071 bufferCrop(Rect::INVALID_RECT),
72 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070073 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000074 matrix.dsdx = matrix.dtdy = 1.0f;
75 matrix.dsdy = matrix.dtdx = 0.0f;
76 hdrMetadata.validTypes = 0;
77}
78
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079status_t layer_state_t::write(Parcel& output) const
80{
chaviw308ddba2020-08-11 16:23:51 -070081 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +000082 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -070083 SAFE_PARCEL(output.writeUint64, what);
84 SAFE_PARCEL(output.writeFloat, x);
85 SAFE_PARCEL(output.writeFloat, y);
86 SAFE_PARCEL(output.writeInt32, z);
87 SAFE_PARCEL(output.writeUint32, w);
88 SAFE_PARCEL(output.writeUint32, h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -070089 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -070090 SAFE_PARCEL(output.writeFloat, alpha);
91 SAFE_PARCEL(output.writeUint32, flags);
92 SAFE_PARCEL(output.writeUint32, mask);
93 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080094 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000095 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
Pablo Gamito11dcc222020-09-12 15:49:39 +000096 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
97 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070098 SAFE_PARCEL(output.writeFloat, color.r);
99 SAFE_PARCEL(output.writeFloat, color.g);
100 SAFE_PARCEL(output.writeFloat, color.b);
chaviw98318de2021-05-19 16:45:23 -0500101 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700102 SAFE_PARCEL(output.write, transparentRegion);
103 SAFE_PARCEL(output.writeUint32, transform);
104 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000105 SAFE_PARCEL(output.writeBool, borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000106 SAFE_PARCEL(output.writeFloat, borderWidth);
107 SAFE_PARCEL(output.writeFloat, borderColor.r);
108 SAFE_PARCEL(output.writeFloat, borderColor.g);
109 SAFE_PARCEL(output.writeFloat, borderColor.b);
110 SAFE_PARCEL(output.writeFloat, borderColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700111 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
112 SAFE_PARCEL(output.write, hdrMetadata);
113 SAFE_PARCEL(output.write, surfaceDamageRegion);
114 SAFE_PARCEL(output.writeInt32, api);
115
Marissa Wall61c58622018-07-18 10:12:20 -0700116 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700117 SAFE_PARCEL(output.writeBool, true);
118 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700119 } else {
chaviw308ddba2020-08-11 16:23:51 -0700120 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700121 }
122
chaviw308ddba2020-08-11 16:23:51 -0700123 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
124 SAFE_PARCEL(output.writeFloat, cornerRadius);
125 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700126 SAFE_PARCEL(output.writeParcelable, metadata);
127 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
128 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
129 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
130 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700131
132 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700133 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700134 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700135 }
chaviw308ddba2020-08-11 16:23:51 -0700136 SAFE_PARCEL(output.writeFloat, shadowRadius);
137 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
138 SAFE_PARCEL(output.writeFloat, frameRate);
139 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100140 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000141 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700142 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800143 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700144 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700145
146 SAFE_PARCEL(output.writeUint32, blurRegions.size());
147 for (auto region : blurRegions) {
148 SAFE_PARCEL(output.writeUint32, region.blurRadius);
149 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
150 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
151 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
152 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
153 SAFE_PARCEL(output.writeFloat, region.alpha);
154 SAFE_PARCEL(output.writeInt32, region.left);
155 SAFE_PARCEL(output.writeInt32, region.top);
156 SAFE_PARCEL(output.writeInt32, region.right);
157 SAFE_PARCEL(output.writeInt32, region.bottom);
158 }
John Reckcdb4ed72021-02-04 13:39:33 -0500159
160 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500161 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700162 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700163 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500164
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700165 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800166
167 const bool hasBufferData = (bufferData != nullptr);
168 SAFE_PARCEL(output.writeBool, hasBufferData);
169 if (hasBufferData) {
170 SAFE_PARCEL(output.writeParcelable, *bufferData);
171 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800172 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800173}
174
175status_t layer_state_t::read(const Parcel& input)
176{
chaviw308ddba2020-08-11 16:23:51 -0700177 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000178 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700179 SAFE_PARCEL(input.readUint64, &what);
180 SAFE_PARCEL(input.readFloat, &x);
181 SAFE_PARCEL(input.readFloat, &y);
182 SAFE_PARCEL(input.readInt32, &z);
183 SAFE_PARCEL(input.readUint32, &w);
184 SAFE_PARCEL(input.readUint32, &h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700185 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700186 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700187
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800188 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700189
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800190 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700191
192 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800193 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000194 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700195
Pablo Gamito11dcc222020-09-12 15:49:39 +0000196 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
197 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
198
chaviw308ddba2020-08-11 16:23:51 -0700199 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700200 SAFE_PARCEL(input.readFloat, &tmpFloat);
201 color.r = tmpFloat;
202 SAFE_PARCEL(input.readFloat, &tmpFloat);
203 color.g = tmpFloat;
204 SAFE_PARCEL(input.readFloat, &tmpFloat);
205 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500206 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700207
chaviw308ddba2020-08-11 16:23:51 -0700208 SAFE_PARCEL(input.read, transparentRegion);
209 SAFE_PARCEL(input.readUint32, &transform);
210 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000211 SAFE_PARCEL(input.readBool, &borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000212 SAFE_PARCEL(input.readFloat, &tmpFloat);
213 borderWidth = tmpFloat;
214 SAFE_PARCEL(input.readFloat, &tmpFloat);
215 borderColor.r = tmpFloat;
216 SAFE_PARCEL(input.readFloat, &tmpFloat);
217 borderColor.g = tmpFloat;
218 SAFE_PARCEL(input.readFloat, &tmpFloat);
219 borderColor.b = tmpFloat;
220 SAFE_PARCEL(input.readFloat, &tmpFloat);
221 borderColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700222
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800223 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700224 SAFE_PARCEL(input.readUint32, &tmpUint32);
225 dataspace = static_cast<ui::Dataspace>(tmpUint32);
226
227 SAFE_PARCEL(input.read, hdrMetadata);
228 SAFE_PARCEL(input.read, surfaceDamageRegion);
229 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500230
231 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700232 SAFE_PARCEL(input.readBool, &tmpBool);
233 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700234 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
235 }
236
chaviw308ddba2020-08-11 16:23:51 -0700237 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
238 SAFE_PARCEL(input.readFloat, &cornerRadius);
239 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700240 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800241
chaviw308ddba2020-08-11 16:23:51 -0700242 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
243 SAFE_PARCEL(input.readUint32, &tmpUint32);
244 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
245 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800246
chaviw308ddba2020-08-11 16:23:51 -0700247 int32_t numListeners = 0;
248 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700249 listeners.clear();
250 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700251 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700252 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700253 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700254 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700255 listeners.emplace_back(listener, callbackIds);
256 }
chaviw308ddba2020-08-11 16:23:51 -0700257 SAFE_PARCEL(input.readFloat, &shadowRadius);
258 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
259 SAFE_PARCEL(input.readFloat, &frameRate);
260 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100261 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000262 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700263 SAFE_PARCEL(input.readUint32, &tmpUint32);
264 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800265 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700266 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700267
268 uint32_t numRegions = 0;
269 SAFE_PARCEL(input.readUint32, &numRegions);
270 blurRegions.clear();
271 for (uint32_t i = 0; i < numRegions; i++) {
272 BlurRegion region;
273 SAFE_PARCEL(input.readUint32, &region.blurRadius);
274 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
275 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
276 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
277 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
278 SAFE_PARCEL(input.readFloat, &region.alpha);
279 SAFE_PARCEL(input.readInt32, &region.left);
280 SAFE_PARCEL(input.readInt32, &region.top);
281 SAFE_PARCEL(input.readInt32, &region.right);
282 SAFE_PARCEL(input.readInt32, &region.bottom);
283 blurRegions.push_back(region);
284 }
John Reckcdb4ed72021-02-04 13:39:33 -0500285
286 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500287 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700288 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700289 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500290
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700291 uint32_t mode;
292 SAFE_PARCEL(input.readUint32, &mode);
293 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800294
295 bool hasBufferData;
296 SAFE_PARCEL(input.readBool, &hasBufferData);
297 if (hasBufferData) {
298 bufferData = std::make_shared<BufferData>();
299 SAFE_PARCEL(input.readParcelable, bufferData.get());
300 } else {
301 bufferData = nullptr;
302 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800303 return NO_ERROR;
304}
305
Mathias Agopian698c0872011-06-28 19:09:31 -0700306status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700307 return state.write(output);
308}
309
310status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700311 return state.read(input);
312}
313
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700314DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700315
Mathias Agopian8b33f032012-07-24 20:43:54 -0700316status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700317 SAFE_PARCEL(output.writeStrongBinder, token);
318 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
319 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700320 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700321 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700322 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
323 SAFE_PARCEL(output.write, layerStackSpaceRect);
324 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
325 SAFE_PARCEL(output.writeUint32, width);
326 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700327 return NO_ERROR;
328}
329
330status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700331 SAFE_PARCEL(input.readStrongBinder, &token);
332 sp<IBinder> tmpBinder;
333 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
334 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
335
336 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700337 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700338 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700339 uint32_t tmpUint = 0;
340 SAFE_PARCEL(input.readUint32, &tmpUint);
341 orientation = ui::toRotation(tmpUint);
342
343 SAFE_PARCEL(input.read, layerStackSpaceRect);
344 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
345 SAFE_PARCEL(input.readUint32, &width);
346 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700347 return NO_ERROR;
348}
349
Robert Carr2c5f6d22017-09-26 12:30:35 -0700350void DisplayState::merge(const DisplayState& other) {
351 if (other.what & eSurfaceChanged) {
352 what |= eSurfaceChanged;
353 surface = other.surface;
354 }
355 if (other.what & eLayerStackChanged) {
356 what |= eLayerStackChanged;
357 layerStack = other.layerStack;
358 }
Evan Rosky2239b372021-05-20 13:43:47 -0700359 if (other.what & eFlagsChanged) {
360 what |= eFlagsChanged;
361 flags = other.flags;
362 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700363 if (other.what & eDisplayProjectionChanged) {
364 what |= eDisplayProjectionChanged;
365 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200366 layerStackSpaceRect = other.layerStackSpaceRect;
367 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700368 }
369 if (other.what & eDisplaySizeChanged) {
370 what |= eDisplaySizeChanged;
371 width = other.width;
372 height = other.height;
373 }
374}
375
Robert Carrde6d7b42022-01-07 18:23:06 -0800376void layer_state_t::sanitize(int32_t permissions) {
377 // TODO: b/109894387
378 //
379 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
380 // rotation. To see the problem observe that if we have a square parent, and a child
381 // of the same size, then we rotate the child 45 degrees around its center, the child
382 // must now be cropped to a non rectangular 8 sided region.
383 //
384 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
385 // private API, and arbitrary rotation is used in limited use cases, for instance:
386 // - WindowManager only uses rotation in one case, which is on a top level layer in which
387 // cropping is not an issue.
388 // - Launcher, as a privileged app, uses this to transition an application to PiP
389 // (picture-in-picture) mode.
390 //
391 // However given that abuse of rotation matrices could lead to surfaces extending outside
392 // of cropped areas, we need to prevent non-root clients without permission
393 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
394 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
395 // preserving transformations.
396 if (what & eMatrixChanged) {
397 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
398 ui::Transform t;
399 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
400 if (!t.preserveRects()) {
401 what &= ~eMatrixChanged;
402 ALOGE("Stripped non rect preserving matrix in sanitize");
403 }
404 }
405 }
406
407 if (what & eFlagsChanged) {
408 if ((flags & eLayerIsDisplayDecoration) &&
409 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
410 flags &= ~eLayerIsDisplayDecoration;
411 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
412 }
413 }
414
415 if (what & layer_state_t::eInputInfoChanged) {
416 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
417 what &= ~eInputInfoChanged;
418 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
419 }
420 }
421 if (what & layer_state_t::eTrustedOverlayChanged) {
422 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
423 what &= ~eTrustedOverlayChanged;
424 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
425 }
426 }
427 if (what & layer_state_t::eDropInputModeChanged) {
428 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
429 what &= ~eDropInputModeChanged;
430 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
431 }
432 }
433 if (what & layer_state_t::eFrameRateSelectionPriority) {
434 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
435 what &= ~eFrameRateSelectionPriority;
436 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
437 }
438 }
439 if (what & layer_state_t::eFrameRateChanged) {
440 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
441 changeFrameRateStrategy,
442 "layer_state_t::sanitize",
443 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
444 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
445 }
446 }
447}
448
Robert Carr2c5f6d22017-09-26 12:30:35 -0700449void layer_state_t::merge(const layer_state_t& other) {
450 if (other.what & ePositionChanged) {
451 what |= ePositionChanged;
452 x = other.x;
453 y = other.y;
454 }
455 if (other.what & eLayerChanged) {
456 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700457 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700458 z = other.z;
459 }
460 if (other.what & eSizeChanged) {
461 what |= eSizeChanged;
462 w = other.w;
463 h = other.h;
464 }
465 if (other.what & eAlphaChanged) {
466 what |= eAlphaChanged;
467 alpha = other.alpha;
468 }
469 if (other.what & eMatrixChanged) {
470 what |= eMatrixChanged;
471 matrix = other.matrix;
472 }
473 if (other.what & eTransparentRegionChanged) {
474 what |= eTransparentRegionChanged;
475 transparentRegion = other.transparentRegion;
476 }
477 if (other.what & eFlagsChanged) {
478 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700479 flags &= ~other.mask;
480 flags |= (other.flags & other.mask);
481 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700482 }
483 if (other.what & eLayerStackChanged) {
484 what |= eLayerStackChanged;
485 layerStack = other.layerStack;
486 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700487 if (other.what & eCornerRadiusChanged) {
488 what |= eCornerRadiusChanged;
489 cornerRadius = other.cornerRadius;
490 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800491 if (other.what & eBackgroundBlurRadiusChanged) {
492 what |= eBackgroundBlurRadiusChanged;
493 backgroundBlurRadius = other.backgroundBlurRadius;
494 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700495 if (other.what & eBlurRegionsChanged) {
496 what |= eBlurRegionsChanged;
497 blurRegions = other.blurRegions;
498 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700499 if (other.what & eRelativeLayerChanged) {
500 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700501 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700502 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000503 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700504 }
505 if (other.what & eReparent) {
506 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000507 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700508 }
chaviwca27f252018-02-06 16:46:39 -0800509 if (other.what & eDestroySurface) {
510 what |= eDestroySurface;
511 }
Marissa Wall61c58622018-07-18 10:12:20 -0700512 if (other.what & eTransformChanged) {
513 what |= eTransformChanged;
514 transform = other.transform;
515 }
516 if (other.what & eTransformToDisplayInverseChanged) {
517 what |= eTransformToDisplayInverseChanged;
518 transformToDisplayInverse = other.transformToDisplayInverse;
519 }
520 if (other.what & eCropChanged) {
521 what |= eCropChanged;
522 crop = other.crop;
523 }
524 if (other.what & eBufferChanged) {
525 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500526 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700527 }
528 if (other.what & eDataspaceChanged) {
529 what |= eDataspaceChanged;
530 dataspace = other.dataspace;
531 }
532 if (other.what & eHdrMetadataChanged) {
533 what |= eHdrMetadataChanged;
534 hdrMetadata = other.hdrMetadata;
535 }
536 if (other.what & eSurfaceDamageRegionChanged) {
537 what |= eSurfaceDamageRegionChanged;
538 surfaceDamageRegion = other.surfaceDamageRegion;
539 }
540 if (other.what & eApiChanged) {
541 what |= eApiChanged;
542 api = other.api;
543 }
544 if (other.what & eSidebandStreamChanged) {
545 what |= eSidebandStreamChanged;
546 sidebandStream = other.sidebandStream;
547 }
Peiyong Lind3788632018-09-18 16:01:31 -0700548 if (other.what & eColorTransformChanged) {
549 what |= eColorTransformChanged;
550 colorTransform = other.colorTransform;
551 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700552 if (other.what & eHasListenerCallbacksChanged) {
553 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700554 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700555 if (other.what & eInputInfoChanged) {
556 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500557 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700558 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800559 if (other.what & eBackgroundColorChanged) {
560 what |= eBackgroundColorChanged;
561 color = other.color;
562 bgColorAlpha = other.bgColorAlpha;
563 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800564 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800565 if (other.what & eMetadataChanged) {
566 what |= eMetadataChanged;
567 metadata.merge(other.metadata);
568 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700569 if (other.what & eShadowRadiusChanged) {
570 what |= eShadowRadiusChanged;
571 shadowRadius = other.shadowRadius;
572 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000573 if (other.what & eRenderBorderChanged) {
574 what |= eRenderBorderChanged;
575 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000576 borderWidth = other.borderWidth;
577 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000578 }
Andy Labrada096227e2022-06-15 16:58:11 +0000579 if (other.what & eDefaultFrameRateCompatibilityChanged) {
580 what |= eDefaultFrameRateCompatibilityChanged;
581 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
582 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100583 if (other.what & eFrameRateSelectionPriority) {
584 what |= eFrameRateSelectionPriority;
585 frameRateSelectionPriority = other.frameRateSelectionPriority;
586 }
Steven Thomas3172e202020-01-06 19:25:30 -0800587 if (other.what & eFrameRateChanged) {
588 what |= eFrameRateChanged;
589 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800590 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100591 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800592 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700593 if (other.what & eFixedTransformHintChanged) {
594 what |= eFixedTransformHintChanged;
595 fixedTransformHint = other.fixedTransformHint;
596 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800597 if (other.what & eAutoRefreshChanged) {
598 what |= eAutoRefreshChanged;
599 autoRefresh = other.autoRefresh;
600 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700601 if (other.what & eTrustedOverlayChanged) {
602 what |= eTrustedOverlayChanged;
603 isTrustedOverlay = other.isTrustedOverlay;
604 }
John Reckc00c6692021-02-16 11:37:33 -0500605 if (other.what & eStretchChanged) {
606 what |= eStretchChanged;
607 stretchEffect = other.stretchEffect;
608 }
chaviwf3f40fe2021-04-27 15:54:02 -0500609 if (other.what & eBufferCropChanged) {
610 what |= eBufferCropChanged;
611 bufferCrop = other.bufferCrop;
612 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700613 if (other.what & eDestinationFrameChanged) {
614 what |= eDestinationFrameChanged;
615 destinationFrame = other.destinationFrame;
616 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700617 if (other.what & eProducerDisconnect) {
618 what |= eProducerDisconnect;
619 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700620 if (other.what & eDropInputModeChanged) {
621 what |= eDropInputModeChanged;
622 dropInputMode = other.dropInputMode;
623 }
chaviw4c36cd82021-11-18 10:37:33 -0600624 if (other.what & eColorChanged) {
625 what |= eColorChanged;
626 color = other.color;
627 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800628 if (other.what & eColorSpaceAgnosticChanged) {
629 what |= eColorSpaceAgnosticChanged;
630 colorSpaceAgnostic = other.colorSpaceAgnostic;
631 }
Sally Qi81d95e62022-03-21 19:41:33 -0700632 if (other.what & eDimmingEnabledChanged) {
633 what |= eDimmingEnabledChanged;
634 dimmingEnabled = other.dimmingEnabled;
635 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700636 if ((other.what & what) != other.what) {
637 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700638 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
639 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700640 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700641}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700642
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700643bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500644 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700645}
646
Ady Abraham6e8e3642021-07-08 19:44:07 -0700647bool layer_state_t::hasValidBuffer() const {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800648 return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700649}
650
chaviw308ddba2020-08-11 16:23:51 -0700651status_t layer_state_t::matrix22_t::write(Parcel& output) const {
652 SAFE_PARCEL(output.writeFloat, dsdx);
653 SAFE_PARCEL(output.writeFloat, dtdx);
654 SAFE_PARCEL(output.writeFloat, dtdy);
655 SAFE_PARCEL(output.writeFloat, dsdy);
656 return NO_ERROR;
657}
658
659status_t layer_state_t::matrix22_t::read(const Parcel& input) {
660 SAFE_PARCEL(input.readFloat, &dsdx);
661 SAFE_PARCEL(input.readFloat, &dtdx);
662 SAFE_PARCEL(input.readFloat, &dtdy);
663 SAFE_PARCEL(input.readFloat, &dsdy);
664 return NO_ERROR;
665}
666
chaviw273171b2018-12-26 11:46:30 -0800667// ------------------------------- InputWindowCommands ----------------------------------------
668
Vishnu Naire798b472020-07-23 13:52:21 -0700669bool InputWindowCommands::merge(const InputWindowCommands& other) {
670 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700671 changes |= !other.focusRequests.empty();
672 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
673 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000674 changes |= !other.windowInfosReportedListeners.empty();
675 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
676 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700677 return changes;
chaviw273171b2018-12-26 11:46:30 -0800678}
679
Vishnu Nair958da932020-08-21 17:12:37 -0700680bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000681 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700682}
683
chaviw273171b2018-12-26 11:46:30 -0800684void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700685 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000686 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800687}
688
chaviw308ddba2020-08-11 16:23:51 -0700689status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700690 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000691
692 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
693 for (const auto& listener : windowInfosReportedListeners) {
694 SAFE_PARCEL(output.writeStrongBinder, listener);
695 }
696
chaviw308ddba2020-08-11 16:23:51 -0700697 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800698}
699
chaviw308ddba2020-08-11 16:23:51 -0700700status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700701 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000702
703 int listenerSize = 0;
704 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
705 windowInfosReportedListeners.reserve(listenerSize);
706 for (int i = 0; i < listenerSize; i++) {
707 sp<gui::IWindowInfosReportedListener> listener;
708 SAFE_PARCEL(input.readStrongBinder, &listener);
709 windowInfosReportedListeners.insert(listener);
710 }
711
chaviw308ddba2020-08-11 16:23:51 -0700712 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800713}
714
Marin Shalamanovc5986772021-03-16 16:09:49 +0100715bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
716 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800717 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
718 int floatClassification = std::fpclassify(frameRate);
719 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
720 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
721 return false;
722 }
723
724 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800725 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700726 (!privileged ||
727 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
728 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800729 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
730 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800731 return false;
732 }
733
Marin Shalamanovc5986772021-03-16 16:09:49 +0100734 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
735 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
736 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
737 changeFrameRateStrategy);
738 }
739
Steven Thomas62a4cf82020-01-31 12:04:03 -0800740 return true;
741}
742
chaviw618c42d2020-07-24 15:25:08 -0700743// ----------------------------------------------------------------------------
744
Huihong Luo9e84f332021-12-16 14:33:46 -0800745namespace gui {
746
747status_t CaptureArgs::writeToParcel(Parcel* output) const {
748 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
749 SAFE_PARCEL(output->write, sourceCrop);
750 SAFE_PARCEL(output->writeFloat, frameScaleX);
751 SAFE_PARCEL(output->writeFloat, frameScaleY);
752 SAFE_PARCEL(output->writeBool, captureSecureLayers);
753 SAFE_PARCEL(output->writeInt32, uid);
754 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
755 SAFE_PARCEL(output->writeBool, allowProtected);
756 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700757 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700758}
759
Huihong Luo9e84f332021-12-16 14:33:46 -0800760status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700761 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800762 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700763 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800764 SAFE_PARCEL(input->read, sourceCrop);
765 SAFE_PARCEL(input->readFloat, &frameScaleX);
766 SAFE_PARCEL(input->readFloat, &frameScaleY);
767 SAFE_PARCEL(input->readBool, &captureSecureLayers);
768 SAFE_PARCEL(input->readInt32, &uid);
769 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700770 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800771 SAFE_PARCEL(input->readBool, &allowProtected);
772 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700773 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700774}
775
Huihong Luo9e84f332021-12-16 14:33:46 -0800776status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
777 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700778
Huihong Luo9e84f332021-12-16 14:33:46 -0800779 SAFE_PARCEL(output->writeStrongBinder, displayToken);
780 SAFE_PARCEL(output->writeUint32, width);
781 SAFE_PARCEL(output->writeUint32, height);
782 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700783 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700784}
785
Huihong Luo9e84f332021-12-16 14:33:46 -0800786status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
787 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700788
Huihong Luo9e84f332021-12-16 14:33:46 -0800789 SAFE_PARCEL(input->readStrongBinder, &displayToken);
790 SAFE_PARCEL(input->readUint32, &width);
791 SAFE_PARCEL(input->readUint32, &height);
792 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700793 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700794}
795
Huihong Luo9e84f332021-12-16 14:33:46 -0800796status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
797 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700798
Huihong Luo9e84f332021-12-16 14:33:46 -0800799 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
800 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700801 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800802 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700803 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800804 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700805 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700806}
807
Huihong Luo9e84f332021-12-16 14:33:46 -0800808status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
809 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700810
Huihong Luo9e84f332021-12-16 14:33:46 -0800811 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700812
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700813 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800814 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700815 excludeHandles.reserve(numExcludeHandles);
816 for (int i = 0; i < numExcludeHandles; i++) {
817 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800818 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700819 excludeHandles.emplace(binder);
820 }
821
Huihong Luo9e84f332021-12-16 14:33:46 -0800822 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700823 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700824}
825
Huihong Luo9e84f332021-12-16 14:33:46 -0800826}; // namespace gui
827
chaviw8dd181f2022-01-05 18:36:46 -0600828ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500829 uint64_t bufferId;
830 if (buffer) {
831 bufferId = buffer->getId();
832 } else {
833 bufferId = cachedBuffer.id;
834 }
835 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600836}
837
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800838status_t BufferData::writeToParcel(Parcel* output) const {
839 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500840
841 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800842 SAFE_PARCEL(output->writeBool, true);
843 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500844 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800845 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500846 }
847
848 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800849 SAFE_PARCEL(output->writeBool, true);
850 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500851 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800852 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500853 }
854
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800855 SAFE_PARCEL(output->writeUint64, frameNumber);
856 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
857 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500858
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800859 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
860 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800861 SAFE_PARCEL(output->writeBool, hasBarrier);
862 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500863
864 return NO_ERROR;
865}
866
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800867status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500868 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800869 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700870 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500871
872 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800873 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500874 if (tmpBool) {
875 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800876 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500877 }
878
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800879 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500880 if (tmpBool) {
881 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800882 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500883 }
884
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800885 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500886
887 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800888 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500889 if (tmpBinder) {
890 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
891 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800892 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500893
894 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800895 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500896 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800897 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500898
Robert Carr79dc06a2022-02-22 15:28:59 -0800899 SAFE_PARCEL(input->readBool, &hasBarrier);
900 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
901
chaviwba4320c2021-09-15 15:20:53 -0500902 return NO_ERROR;
903}
904
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800905}; // namespace android