blob: 59c4c5db8a5ba0bea6dda29b4488b92ecab2d580 [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),
Pablo Gamito11dcc222020-09-12 15:49:39 +000066 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080067 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070068 isTrustedOverlay(false),
Tianhao Yao67dd7122022-02-22 17:48:33 +000069 borderEnabled(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070070 bufferCrop(Rect::INVALID_RECT),
71 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070072 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000073 matrix.dsdx = matrix.dtdy = 1.0f;
74 matrix.dsdy = matrix.dtdx = 0.0f;
75 hdrMetadata.validTypes = 0;
76}
77
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078status_t layer_state_t::write(Parcel& output) const
79{
chaviw308ddba2020-08-11 16:23:51 -070080 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +000081 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -070082 SAFE_PARCEL(output.writeUint64, what);
83 SAFE_PARCEL(output.writeFloat, x);
84 SAFE_PARCEL(output.writeFloat, y);
85 SAFE_PARCEL(output.writeInt32, z);
86 SAFE_PARCEL(output.writeUint32, w);
87 SAFE_PARCEL(output.writeUint32, h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -070088 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -070089 SAFE_PARCEL(output.writeFloat, alpha);
90 SAFE_PARCEL(output.writeUint32, flags);
91 SAFE_PARCEL(output.writeUint32, mask);
92 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080093 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000094 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
Pablo Gamito11dcc222020-09-12 15:49:39 +000095 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
96 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070097 SAFE_PARCEL(output.writeFloat, color.r);
98 SAFE_PARCEL(output.writeFloat, color.g);
99 SAFE_PARCEL(output.writeFloat, color.b);
chaviw98318de2021-05-19 16:45:23 -0500100 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700101 SAFE_PARCEL(output.write, transparentRegion);
102 SAFE_PARCEL(output.writeUint32, transform);
103 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000104 SAFE_PARCEL(output.writeBool, borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000105 SAFE_PARCEL(output.writeFloat, borderWidth);
106 SAFE_PARCEL(output.writeFloat, borderColor.r);
107 SAFE_PARCEL(output.writeFloat, borderColor.g);
108 SAFE_PARCEL(output.writeFloat, borderColor.b);
109 SAFE_PARCEL(output.writeFloat, borderColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700110 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
111 SAFE_PARCEL(output.write, hdrMetadata);
112 SAFE_PARCEL(output.write, surfaceDamageRegion);
113 SAFE_PARCEL(output.writeInt32, api);
114
Marissa Wall61c58622018-07-18 10:12:20 -0700115 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700116 SAFE_PARCEL(output.writeBool, true);
117 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700118 } else {
chaviw308ddba2020-08-11 16:23:51 -0700119 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700120 }
121
chaviw308ddba2020-08-11 16:23:51 -0700122 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
123 SAFE_PARCEL(output.writeFloat, cornerRadius);
124 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700125 SAFE_PARCEL(output.writeParcelable, metadata);
126 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
127 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
128 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
129 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700130
131 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700132 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700133 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700134 }
chaviw308ddba2020-08-11 16:23:51 -0700135 SAFE_PARCEL(output.writeFloat, shadowRadius);
136 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
137 SAFE_PARCEL(output.writeFloat, frameRate);
138 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100139 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700140 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800141 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700142 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700143
144 SAFE_PARCEL(output.writeUint32, blurRegions.size());
145 for (auto region : blurRegions) {
146 SAFE_PARCEL(output.writeUint32, region.blurRadius);
147 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
148 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
149 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
150 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
151 SAFE_PARCEL(output.writeFloat, region.alpha);
152 SAFE_PARCEL(output.writeInt32, region.left);
153 SAFE_PARCEL(output.writeInt32, region.top);
154 SAFE_PARCEL(output.writeInt32, region.right);
155 SAFE_PARCEL(output.writeInt32, region.bottom);
156 }
John Reckcdb4ed72021-02-04 13:39:33 -0500157
158 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500159 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700160 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700161 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500162
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700163 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800164
165 const bool hasBufferData = (bufferData != nullptr);
166 SAFE_PARCEL(output.writeBool, hasBufferData);
167 if (hasBufferData) {
168 SAFE_PARCEL(output.writeParcelable, *bufferData);
169 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800170 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171}
172
173status_t layer_state_t::read(const Parcel& input)
174{
chaviw308ddba2020-08-11 16:23:51 -0700175 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000176 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700177 SAFE_PARCEL(input.readUint64, &what);
178 SAFE_PARCEL(input.readFloat, &x);
179 SAFE_PARCEL(input.readFloat, &y);
180 SAFE_PARCEL(input.readInt32, &z);
181 SAFE_PARCEL(input.readUint32, &w);
182 SAFE_PARCEL(input.readUint32, &h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700183 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700184 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700185
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800186 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700187
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800188 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700189
190 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800191 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000192 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700193
Pablo Gamito11dcc222020-09-12 15:49:39 +0000194 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
195 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
196
chaviw308ddba2020-08-11 16:23:51 -0700197 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700198 SAFE_PARCEL(input.readFloat, &tmpFloat);
199 color.r = tmpFloat;
200 SAFE_PARCEL(input.readFloat, &tmpFloat);
201 color.g = tmpFloat;
202 SAFE_PARCEL(input.readFloat, &tmpFloat);
203 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500204 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700205
chaviw308ddba2020-08-11 16:23:51 -0700206 SAFE_PARCEL(input.read, transparentRegion);
207 SAFE_PARCEL(input.readUint32, &transform);
208 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000209 SAFE_PARCEL(input.readBool, &borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000210 SAFE_PARCEL(input.readFloat, &tmpFloat);
211 borderWidth = tmpFloat;
212 SAFE_PARCEL(input.readFloat, &tmpFloat);
213 borderColor.r = tmpFloat;
214 SAFE_PARCEL(input.readFloat, &tmpFloat);
215 borderColor.g = tmpFloat;
216 SAFE_PARCEL(input.readFloat, &tmpFloat);
217 borderColor.b = tmpFloat;
218 SAFE_PARCEL(input.readFloat, &tmpFloat);
219 borderColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700220
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800221 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700222 SAFE_PARCEL(input.readUint32, &tmpUint32);
223 dataspace = static_cast<ui::Dataspace>(tmpUint32);
224
225 SAFE_PARCEL(input.read, hdrMetadata);
226 SAFE_PARCEL(input.read, surfaceDamageRegion);
227 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500228
229 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700230 SAFE_PARCEL(input.readBool, &tmpBool);
231 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700232 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
233 }
234
chaviw308ddba2020-08-11 16:23:51 -0700235 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
236 SAFE_PARCEL(input.readFloat, &cornerRadius);
237 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700238 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800239
chaviw308ddba2020-08-11 16:23:51 -0700240 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
241 SAFE_PARCEL(input.readUint32, &tmpUint32);
242 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
243 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800244
chaviw308ddba2020-08-11 16:23:51 -0700245 int32_t numListeners = 0;
246 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700247 listeners.clear();
248 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700249 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700250 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700251 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700252 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700253 listeners.emplace_back(listener, callbackIds);
254 }
chaviw308ddba2020-08-11 16:23:51 -0700255 SAFE_PARCEL(input.readFloat, &shadowRadius);
256 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
257 SAFE_PARCEL(input.readFloat, &frameRate);
258 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100259 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700260 SAFE_PARCEL(input.readUint32, &tmpUint32);
261 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800262 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700263 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700264
265 uint32_t numRegions = 0;
266 SAFE_PARCEL(input.readUint32, &numRegions);
267 blurRegions.clear();
268 for (uint32_t i = 0; i < numRegions; i++) {
269 BlurRegion region;
270 SAFE_PARCEL(input.readUint32, &region.blurRadius);
271 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
272 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
273 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
274 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
275 SAFE_PARCEL(input.readFloat, &region.alpha);
276 SAFE_PARCEL(input.readInt32, &region.left);
277 SAFE_PARCEL(input.readInt32, &region.top);
278 SAFE_PARCEL(input.readInt32, &region.right);
279 SAFE_PARCEL(input.readInt32, &region.bottom);
280 blurRegions.push_back(region);
281 }
John Reckcdb4ed72021-02-04 13:39:33 -0500282
283 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500284 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700285 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700286 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500287
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700288 uint32_t mode;
289 SAFE_PARCEL(input.readUint32, &mode);
290 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800291
292 bool hasBufferData;
293 SAFE_PARCEL(input.readBool, &hasBufferData);
294 if (hasBufferData) {
295 bufferData = std::make_shared<BufferData>();
296 SAFE_PARCEL(input.readParcelable, bufferData.get());
297 } else {
298 bufferData = nullptr;
299 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800300 return NO_ERROR;
301}
302
Mathias Agopian698c0872011-06-28 19:09:31 -0700303status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700304 return state.write(output);
305}
306
307status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700308 return state.read(input);
309}
310
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700311DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700312
Mathias Agopian8b33f032012-07-24 20:43:54 -0700313status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700314 SAFE_PARCEL(output.writeStrongBinder, token);
315 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
316 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700317 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700318 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700319 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
320 SAFE_PARCEL(output.write, layerStackSpaceRect);
321 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
322 SAFE_PARCEL(output.writeUint32, width);
323 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700324 return NO_ERROR;
325}
326
327status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700328 SAFE_PARCEL(input.readStrongBinder, &token);
329 sp<IBinder> tmpBinder;
330 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
331 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
332
333 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700334 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700335 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700336 uint32_t tmpUint = 0;
337 SAFE_PARCEL(input.readUint32, &tmpUint);
338 orientation = ui::toRotation(tmpUint);
339
340 SAFE_PARCEL(input.read, layerStackSpaceRect);
341 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
342 SAFE_PARCEL(input.readUint32, &width);
343 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700344 return NO_ERROR;
345}
346
Robert Carr2c5f6d22017-09-26 12:30:35 -0700347void DisplayState::merge(const DisplayState& other) {
348 if (other.what & eSurfaceChanged) {
349 what |= eSurfaceChanged;
350 surface = other.surface;
351 }
352 if (other.what & eLayerStackChanged) {
353 what |= eLayerStackChanged;
354 layerStack = other.layerStack;
355 }
Evan Rosky2239b372021-05-20 13:43:47 -0700356 if (other.what & eFlagsChanged) {
357 what |= eFlagsChanged;
358 flags = other.flags;
359 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700360 if (other.what & eDisplayProjectionChanged) {
361 what |= eDisplayProjectionChanged;
362 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200363 layerStackSpaceRect = other.layerStackSpaceRect;
364 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700365 }
366 if (other.what & eDisplaySizeChanged) {
367 what |= eDisplaySizeChanged;
368 width = other.width;
369 height = other.height;
370 }
371}
372
Robert Carrde6d7b42022-01-07 18:23:06 -0800373void layer_state_t::sanitize(int32_t permissions) {
374 // TODO: b/109894387
375 //
376 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
377 // rotation. To see the problem observe that if we have a square parent, and a child
378 // of the same size, then we rotate the child 45 degrees around its center, the child
379 // must now be cropped to a non rectangular 8 sided region.
380 //
381 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
382 // private API, and arbitrary rotation is used in limited use cases, for instance:
383 // - WindowManager only uses rotation in one case, which is on a top level layer in which
384 // cropping is not an issue.
385 // - Launcher, as a privileged app, uses this to transition an application to PiP
386 // (picture-in-picture) mode.
387 //
388 // However given that abuse of rotation matrices could lead to surfaces extending outside
389 // of cropped areas, we need to prevent non-root clients without permission
390 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
391 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
392 // preserving transformations.
393 if (what & eMatrixChanged) {
394 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
395 ui::Transform t;
396 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
397 if (!t.preserveRects()) {
398 what &= ~eMatrixChanged;
399 ALOGE("Stripped non rect preserving matrix in sanitize");
400 }
401 }
402 }
403
404 if (what & eFlagsChanged) {
405 if ((flags & eLayerIsDisplayDecoration) &&
406 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
407 flags &= ~eLayerIsDisplayDecoration;
408 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
409 }
410 }
411
412 if (what & layer_state_t::eInputInfoChanged) {
413 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
414 what &= ~eInputInfoChanged;
415 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
416 }
417 }
418 if (what & layer_state_t::eTrustedOverlayChanged) {
419 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
420 what &= ~eTrustedOverlayChanged;
421 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
422 }
423 }
424 if (what & layer_state_t::eDropInputModeChanged) {
425 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
426 what &= ~eDropInputModeChanged;
427 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
428 }
429 }
430 if (what & layer_state_t::eFrameRateSelectionPriority) {
431 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
432 what &= ~eFrameRateSelectionPriority;
433 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
434 }
435 }
436 if (what & layer_state_t::eFrameRateChanged) {
437 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
438 changeFrameRateStrategy,
439 "layer_state_t::sanitize",
440 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
441 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
442 }
443 }
444}
445
Robert Carr2c5f6d22017-09-26 12:30:35 -0700446void layer_state_t::merge(const layer_state_t& other) {
447 if (other.what & ePositionChanged) {
448 what |= ePositionChanged;
449 x = other.x;
450 y = other.y;
451 }
452 if (other.what & eLayerChanged) {
453 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700454 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700455 z = other.z;
456 }
457 if (other.what & eSizeChanged) {
458 what |= eSizeChanged;
459 w = other.w;
460 h = other.h;
461 }
462 if (other.what & eAlphaChanged) {
463 what |= eAlphaChanged;
464 alpha = other.alpha;
465 }
466 if (other.what & eMatrixChanged) {
467 what |= eMatrixChanged;
468 matrix = other.matrix;
469 }
470 if (other.what & eTransparentRegionChanged) {
471 what |= eTransparentRegionChanged;
472 transparentRegion = other.transparentRegion;
473 }
474 if (other.what & eFlagsChanged) {
475 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700476 flags &= ~other.mask;
477 flags |= (other.flags & other.mask);
478 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700479 }
480 if (other.what & eLayerStackChanged) {
481 what |= eLayerStackChanged;
482 layerStack = other.layerStack;
483 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700484 if (other.what & eCornerRadiusChanged) {
485 what |= eCornerRadiusChanged;
486 cornerRadius = other.cornerRadius;
487 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800488 if (other.what & eBackgroundBlurRadiusChanged) {
489 what |= eBackgroundBlurRadiusChanged;
490 backgroundBlurRadius = other.backgroundBlurRadius;
491 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700492 if (other.what & eBlurRegionsChanged) {
493 what |= eBlurRegionsChanged;
494 blurRegions = other.blurRegions;
495 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700496 if (other.what & eRelativeLayerChanged) {
497 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700498 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700499 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000500 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700501 }
502 if (other.what & eReparent) {
503 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000504 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700505 }
chaviwca27f252018-02-06 16:46:39 -0800506 if (other.what & eDestroySurface) {
507 what |= eDestroySurface;
508 }
Marissa Wall61c58622018-07-18 10:12:20 -0700509 if (other.what & eTransformChanged) {
510 what |= eTransformChanged;
511 transform = other.transform;
512 }
513 if (other.what & eTransformToDisplayInverseChanged) {
514 what |= eTransformToDisplayInverseChanged;
515 transformToDisplayInverse = other.transformToDisplayInverse;
516 }
517 if (other.what & eCropChanged) {
518 what |= eCropChanged;
519 crop = other.crop;
520 }
521 if (other.what & eBufferChanged) {
522 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500523 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700524 }
525 if (other.what & eDataspaceChanged) {
526 what |= eDataspaceChanged;
527 dataspace = other.dataspace;
528 }
529 if (other.what & eHdrMetadataChanged) {
530 what |= eHdrMetadataChanged;
531 hdrMetadata = other.hdrMetadata;
532 }
533 if (other.what & eSurfaceDamageRegionChanged) {
534 what |= eSurfaceDamageRegionChanged;
535 surfaceDamageRegion = other.surfaceDamageRegion;
536 }
537 if (other.what & eApiChanged) {
538 what |= eApiChanged;
539 api = other.api;
540 }
541 if (other.what & eSidebandStreamChanged) {
542 what |= eSidebandStreamChanged;
543 sidebandStream = other.sidebandStream;
544 }
Peiyong Lind3788632018-09-18 16:01:31 -0700545 if (other.what & eColorTransformChanged) {
546 what |= eColorTransformChanged;
547 colorTransform = other.colorTransform;
548 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700549 if (other.what & eHasListenerCallbacksChanged) {
550 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700551 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700552 if (other.what & eInputInfoChanged) {
553 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500554 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700555 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800556 if (other.what & eBackgroundColorChanged) {
557 what |= eBackgroundColorChanged;
558 color = other.color;
559 bgColorAlpha = other.bgColorAlpha;
560 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800561 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800562 if (other.what & eMetadataChanged) {
563 what |= eMetadataChanged;
564 metadata.merge(other.metadata);
565 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700566 if (other.what & eShadowRadiusChanged) {
567 what |= eShadowRadiusChanged;
568 shadowRadius = other.shadowRadius;
569 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000570 if (other.what & eRenderBorderChanged) {
571 what |= eRenderBorderChanged;
572 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000573 borderWidth = other.borderWidth;
574 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000575 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100576 if (other.what & eFrameRateSelectionPriority) {
577 what |= eFrameRateSelectionPriority;
578 frameRateSelectionPriority = other.frameRateSelectionPriority;
579 }
Steven Thomas3172e202020-01-06 19:25:30 -0800580 if (other.what & eFrameRateChanged) {
581 what |= eFrameRateChanged;
582 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800583 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100584 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800585 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700586 if (other.what & eFixedTransformHintChanged) {
587 what |= eFixedTransformHintChanged;
588 fixedTransformHint = other.fixedTransformHint;
589 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800590 if (other.what & eAutoRefreshChanged) {
591 what |= eAutoRefreshChanged;
592 autoRefresh = other.autoRefresh;
593 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700594 if (other.what & eTrustedOverlayChanged) {
595 what |= eTrustedOverlayChanged;
596 isTrustedOverlay = other.isTrustedOverlay;
597 }
John Reckc00c6692021-02-16 11:37:33 -0500598 if (other.what & eStretchChanged) {
599 what |= eStretchChanged;
600 stretchEffect = other.stretchEffect;
601 }
chaviwf3f40fe2021-04-27 15:54:02 -0500602 if (other.what & eBufferCropChanged) {
603 what |= eBufferCropChanged;
604 bufferCrop = other.bufferCrop;
605 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700606 if (other.what & eDestinationFrameChanged) {
607 what |= eDestinationFrameChanged;
608 destinationFrame = other.destinationFrame;
609 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700610 if (other.what & eProducerDisconnect) {
611 what |= eProducerDisconnect;
612 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700613 if (other.what & eDropInputModeChanged) {
614 what |= eDropInputModeChanged;
615 dropInputMode = other.dropInputMode;
616 }
chaviw4c36cd82021-11-18 10:37:33 -0600617 if (other.what & eColorChanged) {
618 what |= eColorChanged;
619 color = other.color;
620 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800621 if (other.what & eColorSpaceAgnosticChanged) {
622 what |= eColorSpaceAgnosticChanged;
623 colorSpaceAgnostic = other.colorSpaceAgnostic;
624 }
Sally Qi81d95e62022-03-21 19:41:33 -0700625 if (other.what & eDimmingEnabledChanged) {
626 what |= eDimmingEnabledChanged;
627 dimmingEnabled = other.dimmingEnabled;
628 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700629 if ((other.what & what) != other.what) {
630 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700631 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
632 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700633 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700634}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700635
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700636bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500637 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700638}
639
Ady Abraham6e8e3642021-07-08 19:44:07 -0700640bool layer_state_t::hasValidBuffer() const {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800641 return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700642}
643
chaviw308ddba2020-08-11 16:23:51 -0700644status_t layer_state_t::matrix22_t::write(Parcel& output) const {
645 SAFE_PARCEL(output.writeFloat, dsdx);
646 SAFE_PARCEL(output.writeFloat, dtdx);
647 SAFE_PARCEL(output.writeFloat, dtdy);
648 SAFE_PARCEL(output.writeFloat, dsdy);
649 return NO_ERROR;
650}
651
652status_t layer_state_t::matrix22_t::read(const Parcel& input) {
653 SAFE_PARCEL(input.readFloat, &dsdx);
654 SAFE_PARCEL(input.readFloat, &dtdx);
655 SAFE_PARCEL(input.readFloat, &dtdy);
656 SAFE_PARCEL(input.readFloat, &dsdy);
657 return NO_ERROR;
658}
659
chaviw273171b2018-12-26 11:46:30 -0800660// ------------------------------- InputWindowCommands ----------------------------------------
661
Vishnu Naire798b472020-07-23 13:52:21 -0700662bool InputWindowCommands::merge(const InputWindowCommands& other) {
663 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700664 changes |= !other.focusRequests.empty();
665 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
666 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000667 changes |= !other.windowInfosReportedListeners.empty();
668 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
669 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700670 return changes;
chaviw273171b2018-12-26 11:46:30 -0800671}
672
Vishnu Nair958da932020-08-21 17:12:37 -0700673bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000674 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700675}
676
chaviw273171b2018-12-26 11:46:30 -0800677void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700678 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000679 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800680}
681
chaviw308ddba2020-08-11 16:23:51 -0700682status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700683 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000684
685 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
686 for (const auto& listener : windowInfosReportedListeners) {
687 SAFE_PARCEL(output.writeStrongBinder, listener);
688 }
689
chaviw308ddba2020-08-11 16:23:51 -0700690 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800691}
692
chaviw308ddba2020-08-11 16:23:51 -0700693status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700694 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000695
696 int listenerSize = 0;
697 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
698 windowInfosReportedListeners.reserve(listenerSize);
699 for (int i = 0; i < listenerSize; i++) {
700 sp<gui::IWindowInfosReportedListener> listener;
701 SAFE_PARCEL(input.readStrongBinder, &listener);
702 windowInfosReportedListeners.insert(listener);
703 }
704
chaviw308ddba2020-08-11 16:23:51 -0700705 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800706}
707
Marin Shalamanovc5986772021-03-16 16:09:49 +0100708bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
709 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800710 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
711 int floatClassification = std::fpclassify(frameRate);
712 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
713 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
714 return false;
715 }
716
717 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800718 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700719 (!privileged ||
720 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
721 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800722 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
723 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800724 return false;
725 }
726
Marin Shalamanovc5986772021-03-16 16:09:49 +0100727 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
728 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
729 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
730 changeFrameRateStrategy);
731 }
732
Steven Thomas62a4cf82020-01-31 12:04:03 -0800733 return true;
734}
735
chaviw618c42d2020-07-24 15:25:08 -0700736// ----------------------------------------------------------------------------
737
Huihong Luo9e84f332021-12-16 14:33:46 -0800738namespace gui {
739
740status_t CaptureArgs::writeToParcel(Parcel* output) const {
741 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
742 SAFE_PARCEL(output->write, sourceCrop);
743 SAFE_PARCEL(output->writeFloat, frameScaleX);
744 SAFE_PARCEL(output->writeFloat, frameScaleY);
745 SAFE_PARCEL(output->writeBool, captureSecureLayers);
746 SAFE_PARCEL(output->writeInt32, uid);
747 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
748 SAFE_PARCEL(output->writeBool, allowProtected);
749 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700750 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700751}
752
Huihong Luo9e84f332021-12-16 14:33:46 -0800753status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700754 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800755 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700756 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800757 SAFE_PARCEL(input->read, sourceCrop);
758 SAFE_PARCEL(input->readFloat, &frameScaleX);
759 SAFE_PARCEL(input->readFloat, &frameScaleY);
760 SAFE_PARCEL(input->readBool, &captureSecureLayers);
761 SAFE_PARCEL(input->readInt32, &uid);
762 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700763 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800764 SAFE_PARCEL(input->readBool, &allowProtected);
765 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700766 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700767}
768
Huihong Luo9e84f332021-12-16 14:33:46 -0800769status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
770 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700771
Huihong Luo9e84f332021-12-16 14:33:46 -0800772 SAFE_PARCEL(output->writeStrongBinder, displayToken);
773 SAFE_PARCEL(output->writeUint32, width);
774 SAFE_PARCEL(output->writeUint32, height);
775 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700776 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700777}
778
Huihong Luo9e84f332021-12-16 14:33:46 -0800779status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
780 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700781
Huihong Luo9e84f332021-12-16 14:33:46 -0800782 SAFE_PARCEL(input->readStrongBinder, &displayToken);
783 SAFE_PARCEL(input->readUint32, &width);
784 SAFE_PARCEL(input->readUint32, &height);
785 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700786 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700787}
788
Huihong Luo9e84f332021-12-16 14:33:46 -0800789status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
790 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700791
Huihong Luo9e84f332021-12-16 14:33:46 -0800792 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
793 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700794 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800795 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700796 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800797 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700798 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700799}
800
Huihong Luo9e84f332021-12-16 14:33:46 -0800801status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
802 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700803
Huihong Luo9e84f332021-12-16 14:33:46 -0800804 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700805
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700806 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800807 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700808 excludeHandles.reserve(numExcludeHandles);
809 for (int i = 0; i < numExcludeHandles; i++) {
810 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800811 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700812 excludeHandles.emplace(binder);
813 }
814
Huihong Luo9e84f332021-12-16 14:33:46 -0800815 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700816 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700817}
818
Huihong Luo9e84f332021-12-16 14:33:46 -0800819}; // namespace gui
820
chaviw8dd181f2022-01-05 18:36:46 -0600821ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500822 uint64_t bufferId;
823 if (buffer) {
824 bufferId = buffer->getId();
825 } else {
826 bufferId = cachedBuffer.id;
827 }
828 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600829}
830
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800831status_t BufferData::writeToParcel(Parcel* output) const {
832 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500833
834 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800835 SAFE_PARCEL(output->writeBool, true);
836 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500837 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800838 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500839 }
840
841 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800842 SAFE_PARCEL(output->writeBool, true);
843 SAFE_PARCEL(output->write, *acquireFence);
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
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800848 SAFE_PARCEL(output->writeUint64, frameNumber);
849 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
850 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500851
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800852 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
853 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800854 SAFE_PARCEL(output->writeBool, hasBarrier);
855 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500856
857 return NO_ERROR;
858}
859
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800860status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500861 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800862 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700863 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500864
865 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800866 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500867 if (tmpBool) {
868 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800869 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500870 }
871
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800872 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500873 if (tmpBool) {
874 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800875 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500876 }
877
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800878 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500879
880 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800881 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500882 if (tmpBinder) {
883 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
884 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800885 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500886
887 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800888 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500889 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800890 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500891
Robert Carr79dc06a2022-02-22 15:28:59 -0800892 SAFE_PARCEL(input->readBool, &hasBarrier);
893 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
894
chaviwba4320c2021-09-15 15:20:53 -0500895 return NO_ERROR;
896}
897
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800898}; // namespace android