blob: 3ab9e974bc6c70727119b254a0c1f1d01ba1c706 [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),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070069 bufferCrop(Rect::INVALID_RECT),
70 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070071 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000072 matrix.dsdx = matrix.dtdy = 1.0f;
73 matrix.dsdy = matrix.dtdx = 0.0f;
74 hdrMetadata.validTypes = 0;
75}
76
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077status_t layer_state_t::write(Parcel& output) const
78{
chaviw308ddba2020-08-11 16:23:51 -070079 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +000080 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -070081 SAFE_PARCEL(output.writeUint64, what);
82 SAFE_PARCEL(output.writeFloat, x);
83 SAFE_PARCEL(output.writeFloat, y);
84 SAFE_PARCEL(output.writeInt32, z);
85 SAFE_PARCEL(output.writeUint32, w);
86 SAFE_PARCEL(output.writeUint32, h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -070087 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -070088 SAFE_PARCEL(output.writeFloat, alpha);
89 SAFE_PARCEL(output.writeUint32, flags);
90 SAFE_PARCEL(output.writeUint32, mask);
91 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080092 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000093 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
Pablo Gamito11dcc222020-09-12 15:49:39 +000094 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
95 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070096 SAFE_PARCEL(output.writeFloat, color.r);
97 SAFE_PARCEL(output.writeFloat, color.g);
98 SAFE_PARCEL(output.writeFloat, color.b);
chaviw98318de2021-05-19 16:45:23 -050099 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700100 SAFE_PARCEL(output.write, transparentRegion);
101 SAFE_PARCEL(output.writeUint32, transform);
102 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700103
chaviw308ddba2020-08-11 16:23:51 -0700104 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
105 SAFE_PARCEL(output.write, hdrMetadata);
106 SAFE_PARCEL(output.write, surfaceDamageRegion);
107 SAFE_PARCEL(output.writeInt32, api);
108
Marissa Wall61c58622018-07-18 10:12:20 -0700109 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700110 SAFE_PARCEL(output.writeBool, true);
111 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700112 } else {
chaviw308ddba2020-08-11 16:23:51 -0700113 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700114 }
115
chaviw308ddba2020-08-11 16:23:51 -0700116 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
117 SAFE_PARCEL(output.writeFloat, cornerRadius);
118 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700119 SAFE_PARCEL(output.writeParcelable, metadata);
120 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
121 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
122 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
123 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700124
125 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700126 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700127 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700128 }
chaviw308ddba2020-08-11 16:23:51 -0700129 SAFE_PARCEL(output.writeFloat, shadowRadius);
130 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
131 SAFE_PARCEL(output.writeFloat, frameRate);
132 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100133 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700134 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800135 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700136 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700137
138 SAFE_PARCEL(output.writeUint32, blurRegions.size());
139 for (auto region : blurRegions) {
140 SAFE_PARCEL(output.writeUint32, region.blurRadius);
141 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
142 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
143 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
144 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
145 SAFE_PARCEL(output.writeFloat, region.alpha);
146 SAFE_PARCEL(output.writeInt32, region.left);
147 SAFE_PARCEL(output.writeInt32, region.top);
148 SAFE_PARCEL(output.writeInt32, region.right);
149 SAFE_PARCEL(output.writeInt32, region.bottom);
150 }
John Reckcdb4ed72021-02-04 13:39:33 -0500151
152 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500153 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700154 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700155 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500156
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700157 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800158
159 const bool hasBufferData = (bufferData != nullptr);
160 SAFE_PARCEL(output.writeBool, hasBufferData);
161 if (hasBufferData) {
162 SAFE_PARCEL(output.writeParcelable, *bufferData);
163 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800164 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165}
166
167status_t layer_state_t::read(const Parcel& input)
168{
chaviw308ddba2020-08-11 16:23:51 -0700169 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000170 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700171 SAFE_PARCEL(input.readUint64, &what);
172 SAFE_PARCEL(input.readFloat, &x);
173 SAFE_PARCEL(input.readFloat, &y);
174 SAFE_PARCEL(input.readInt32, &z);
175 SAFE_PARCEL(input.readUint32, &w);
176 SAFE_PARCEL(input.readUint32, &h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700177 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700178 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700179
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800180 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700181
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800182 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700183
184 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800185 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000186 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700187
Pablo Gamito11dcc222020-09-12 15:49:39 +0000188 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
189 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
190
chaviw308ddba2020-08-11 16:23:51 -0700191 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700192 SAFE_PARCEL(input.readFloat, &tmpFloat);
193 color.r = tmpFloat;
194 SAFE_PARCEL(input.readFloat, &tmpFloat);
195 color.g = tmpFloat;
196 SAFE_PARCEL(input.readFloat, &tmpFloat);
197 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500198 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700199
chaviw308ddba2020-08-11 16:23:51 -0700200 SAFE_PARCEL(input.read, transparentRegion);
201 SAFE_PARCEL(input.readUint32, &transform);
202 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700203
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800204 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700205 SAFE_PARCEL(input.readUint32, &tmpUint32);
206 dataspace = static_cast<ui::Dataspace>(tmpUint32);
207
208 SAFE_PARCEL(input.read, hdrMetadata);
209 SAFE_PARCEL(input.read, surfaceDamageRegion);
210 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500211
212 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700213 SAFE_PARCEL(input.readBool, &tmpBool);
214 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700215 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
216 }
217
chaviw308ddba2020-08-11 16:23:51 -0700218 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
219 SAFE_PARCEL(input.readFloat, &cornerRadius);
220 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700221 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800222
chaviw308ddba2020-08-11 16:23:51 -0700223 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
224 SAFE_PARCEL(input.readUint32, &tmpUint32);
225 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
226 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800227
chaviw308ddba2020-08-11 16:23:51 -0700228 int32_t numListeners = 0;
229 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700230 listeners.clear();
231 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700232 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700233 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700234 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700235 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700236 listeners.emplace_back(listener, callbackIds);
237 }
chaviw308ddba2020-08-11 16:23:51 -0700238 SAFE_PARCEL(input.readFloat, &shadowRadius);
239 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
240 SAFE_PARCEL(input.readFloat, &frameRate);
241 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100242 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700243 SAFE_PARCEL(input.readUint32, &tmpUint32);
244 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800245 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700246 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700247
248 uint32_t numRegions = 0;
249 SAFE_PARCEL(input.readUint32, &numRegions);
250 blurRegions.clear();
251 for (uint32_t i = 0; i < numRegions; i++) {
252 BlurRegion region;
253 SAFE_PARCEL(input.readUint32, &region.blurRadius);
254 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
255 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
256 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
257 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
258 SAFE_PARCEL(input.readFloat, &region.alpha);
259 SAFE_PARCEL(input.readInt32, &region.left);
260 SAFE_PARCEL(input.readInt32, &region.top);
261 SAFE_PARCEL(input.readInt32, &region.right);
262 SAFE_PARCEL(input.readInt32, &region.bottom);
263 blurRegions.push_back(region);
264 }
John Reckcdb4ed72021-02-04 13:39:33 -0500265
266 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500267 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700268 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700269 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500270
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700271 uint32_t mode;
272 SAFE_PARCEL(input.readUint32, &mode);
273 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800274
275 bool hasBufferData;
276 SAFE_PARCEL(input.readBool, &hasBufferData);
277 if (hasBufferData) {
278 bufferData = std::make_shared<BufferData>();
279 SAFE_PARCEL(input.readParcelable, bufferData.get());
280 } else {
281 bufferData = nullptr;
282 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800283 return NO_ERROR;
284}
285
Mathias Agopian698c0872011-06-28 19:09:31 -0700286status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700287 return state.write(output);
288}
289
290status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700291 return state.read(input);
292}
293
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700294DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700295
Mathias Agopian8b33f032012-07-24 20:43:54 -0700296status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700297 SAFE_PARCEL(output.writeStrongBinder, token);
298 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
299 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700300 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700301 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700302 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
303 SAFE_PARCEL(output.write, layerStackSpaceRect);
304 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
305 SAFE_PARCEL(output.writeUint32, width);
306 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700307 return NO_ERROR;
308}
309
310status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700311 SAFE_PARCEL(input.readStrongBinder, &token);
312 sp<IBinder> tmpBinder;
313 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
314 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
315
316 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700317 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700318 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700319 uint32_t tmpUint = 0;
320 SAFE_PARCEL(input.readUint32, &tmpUint);
321 orientation = ui::toRotation(tmpUint);
322
323 SAFE_PARCEL(input.read, layerStackSpaceRect);
324 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
325 SAFE_PARCEL(input.readUint32, &width);
326 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700327 return NO_ERROR;
328}
329
Robert Carr2c5f6d22017-09-26 12:30:35 -0700330void DisplayState::merge(const DisplayState& other) {
331 if (other.what & eSurfaceChanged) {
332 what |= eSurfaceChanged;
333 surface = other.surface;
334 }
335 if (other.what & eLayerStackChanged) {
336 what |= eLayerStackChanged;
337 layerStack = other.layerStack;
338 }
Evan Rosky2239b372021-05-20 13:43:47 -0700339 if (other.what & eFlagsChanged) {
340 what |= eFlagsChanged;
341 flags = other.flags;
342 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700343 if (other.what & eDisplayProjectionChanged) {
344 what |= eDisplayProjectionChanged;
345 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200346 layerStackSpaceRect = other.layerStackSpaceRect;
347 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700348 }
349 if (other.what & eDisplaySizeChanged) {
350 what |= eDisplaySizeChanged;
351 width = other.width;
352 height = other.height;
353 }
354}
355
Robert Carrde6d7b42022-01-07 18:23:06 -0800356void layer_state_t::sanitize(int32_t permissions) {
357 // TODO: b/109894387
358 //
359 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
360 // rotation. To see the problem observe that if we have a square parent, and a child
361 // of the same size, then we rotate the child 45 degrees around its center, the child
362 // must now be cropped to a non rectangular 8 sided region.
363 //
364 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
365 // private API, and arbitrary rotation is used in limited use cases, for instance:
366 // - WindowManager only uses rotation in one case, which is on a top level layer in which
367 // cropping is not an issue.
368 // - Launcher, as a privileged app, uses this to transition an application to PiP
369 // (picture-in-picture) mode.
370 //
371 // However given that abuse of rotation matrices could lead to surfaces extending outside
372 // of cropped areas, we need to prevent non-root clients without permission
373 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
374 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
375 // preserving transformations.
376 if (what & eMatrixChanged) {
377 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
378 ui::Transform t;
379 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
380 if (!t.preserveRects()) {
381 what &= ~eMatrixChanged;
382 ALOGE("Stripped non rect preserving matrix in sanitize");
383 }
384 }
385 }
386
387 if (what & eFlagsChanged) {
388 if ((flags & eLayerIsDisplayDecoration) &&
389 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
390 flags &= ~eLayerIsDisplayDecoration;
391 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
392 }
393 }
394
395 if (what & layer_state_t::eInputInfoChanged) {
396 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
397 what &= ~eInputInfoChanged;
398 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
399 }
400 }
401 if (what & layer_state_t::eTrustedOverlayChanged) {
402 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
403 what &= ~eTrustedOverlayChanged;
404 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
405 }
406 }
407 if (what & layer_state_t::eDropInputModeChanged) {
408 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
409 what &= ~eDropInputModeChanged;
410 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
411 }
412 }
413 if (what & layer_state_t::eFrameRateSelectionPriority) {
414 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
415 what &= ~eFrameRateSelectionPriority;
416 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
417 }
418 }
419 if (what & layer_state_t::eFrameRateChanged) {
420 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
421 changeFrameRateStrategy,
422 "layer_state_t::sanitize",
423 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
424 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
425 }
426 }
427}
428
Robert Carr2c5f6d22017-09-26 12:30:35 -0700429void layer_state_t::merge(const layer_state_t& other) {
430 if (other.what & ePositionChanged) {
431 what |= ePositionChanged;
432 x = other.x;
433 y = other.y;
434 }
435 if (other.what & eLayerChanged) {
436 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700437 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700438 z = other.z;
439 }
440 if (other.what & eSizeChanged) {
441 what |= eSizeChanged;
442 w = other.w;
443 h = other.h;
444 }
445 if (other.what & eAlphaChanged) {
446 what |= eAlphaChanged;
447 alpha = other.alpha;
448 }
449 if (other.what & eMatrixChanged) {
450 what |= eMatrixChanged;
451 matrix = other.matrix;
452 }
453 if (other.what & eTransparentRegionChanged) {
454 what |= eTransparentRegionChanged;
455 transparentRegion = other.transparentRegion;
456 }
457 if (other.what & eFlagsChanged) {
458 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700459 flags &= ~other.mask;
460 flags |= (other.flags & other.mask);
461 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700462 }
463 if (other.what & eLayerStackChanged) {
464 what |= eLayerStackChanged;
465 layerStack = other.layerStack;
466 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700467 if (other.what & eCornerRadiusChanged) {
468 what |= eCornerRadiusChanged;
469 cornerRadius = other.cornerRadius;
470 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800471 if (other.what & eBackgroundBlurRadiusChanged) {
472 what |= eBackgroundBlurRadiusChanged;
473 backgroundBlurRadius = other.backgroundBlurRadius;
474 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700475 if (other.what & eBlurRegionsChanged) {
476 what |= eBlurRegionsChanged;
477 blurRegions = other.blurRegions;
478 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700479 if (other.what & eRelativeLayerChanged) {
480 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700481 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700482 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000483 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700484 }
485 if (other.what & eReparent) {
486 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000487 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700488 }
chaviwca27f252018-02-06 16:46:39 -0800489 if (other.what & eDestroySurface) {
490 what |= eDestroySurface;
491 }
Marissa Wall61c58622018-07-18 10:12:20 -0700492 if (other.what & eTransformChanged) {
493 what |= eTransformChanged;
494 transform = other.transform;
495 }
496 if (other.what & eTransformToDisplayInverseChanged) {
497 what |= eTransformToDisplayInverseChanged;
498 transformToDisplayInverse = other.transformToDisplayInverse;
499 }
500 if (other.what & eCropChanged) {
501 what |= eCropChanged;
502 crop = other.crop;
503 }
504 if (other.what & eBufferChanged) {
505 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500506 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700507 }
508 if (other.what & eDataspaceChanged) {
509 what |= eDataspaceChanged;
510 dataspace = other.dataspace;
511 }
512 if (other.what & eHdrMetadataChanged) {
513 what |= eHdrMetadataChanged;
514 hdrMetadata = other.hdrMetadata;
515 }
516 if (other.what & eSurfaceDamageRegionChanged) {
517 what |= eSurfaceDamageRegionChanged;
518 surfaceDamageRegion = other.surfaceDamageRegion;
519 }
520 if (other.what & eApiChanged) {
521 what |= eApiChanged;
522 api = other.api;
523 }
524 if (other.what & eSidebandStreamChanged) {
525 what |= eSidebandStreamChanged;
526 sidebandStream = other.sidebandStream;
527 }
Peiyong Lind3788632018-09-18 16:01:31 -0700528 if (other.what & eColorTransformChanged) {
529 what |= eColorTransformChanged;
530 colorTransform = other.colorTransform;
531 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700532 if (other.what & eHasListenerCallbacksChanged) {
533 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700534 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700535 if (other.what & eInputInfoChanged) {
536 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500537 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700538 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800539 if (other.what & eBackgroundColorChanged) {
540 what |= eBackgroundColorChanged;
541 color = other.color;
542 bgColorAlpha = other.bgColorAlpha;
543 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800544 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800545 if (other.what & eMetadataChanged) {
546 what |= eMetadataChanged;
547 metadata.merge(other.metadata);
548 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700549 if (other.what & eShadowRadiusChanged) {
550 what |= eShadowRadiusChanged;
551 shadowRadius = other.shadowRadius;
552 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100553 if (other.what & eFrameRateSelectionPriority) {
554 what |= eFrameRateSelectionPriority;
555 frameRateSelectionPriority = other.frameRateSelectionPriority;
556 }
Steven Thomas3172e202020-01-06 19:25:30 -0800557 if (other.what & eFrameRateChanged) {
558 what |= eFrameRateChanged;
559 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800560 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100561 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800562 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700563 if (other.what & eFixedTransformHintChanged) {
564 what |= eFixedTransformHintChanged;
565 fixedTransformHint = other.fixedTransformHint;
566 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800567 if (other.what & eAutoRefreshChanged) {
568 what |= eAutoRefreshChanged;
569 autoRefresh = other.autoRefresh;
570 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700571 if (other.what & eTrustedOverlayChanged) {
572 what |= eTrustedOverlayChanged;
573 isTrustedOverlay = other.isTrustedOverlay;
574 }
John Reckc00c6692021-02-16 11:37:33 -0500575 if (other.what & eStretchChanged) {
576 what |= eStretchChanged;
577 stretchEffect = other.stretchEffect;
578 }
chaviwf3f40fe2021-04-27 15:54:02 -0500579 if (other.what & eBufferCropChanged) {
580 what |= eBufferCropChanged;
581 bufferCrop = other.bufferCrop;
582 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700583 if (other.what & eDestinationFrameChanged) {
584 what |= eDestinationFrameChanged;
585 destinationFrame = other.destinationFrame;
586 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700587 if (other.what & eProducerDisconnect) {
588 what |= eProducerDisconnect;
589 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700590 if (other.what & eDropInputModeChanged) {
591 what |= eDropInputModeChanged;
592 dropInputMode = other.dropInputMode;
593 }
chaviw4c36cd82021-11-18 10:37:33 -0600594 if (other.what & eColorChanged) {
595 what |= eColorChanged;
596 color = other.color;
597 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800598 if (other.what & eColorSpaceAgnosticChanged) {
599 what |= eColorSpaceAgnosticChanged;
600 colorSpaceAgnostic = other.colorSpaceAgnostic;
601 }
Sally Qi81d95e62022-03-21 19:41:33 -0700602 if (other.what & eDimmingEnabledChanged) {
603 what |= eDimmingEnabledChanged;
604 dimmingEnabled = other.dimmingEnabled;
605 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700606 if ((other.what & what) != other.what) {
607 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700608 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
609 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700610 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700611}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700612
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700613bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500614 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700615}
616
Ady Abraham6e8e3642021-07-08 19:44:07 -0700617bool layer_state_t::hasValidBuffer() const {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800618 return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700619}
620
chaviw308ddba2020-08-11 16:23:51 -0700621status_t layer_state_t::matrix22_t::write(Parcel& output) const {
622 SAFE_PARCEL(output.writeFloat, dsdx);
623 SAFE_PARCEL(output.writeFloat, dtdx);
624 SAFE_PARCEL(output.writeFloat, dtdy);
625 SAFE_PARCEL(output.writeFloat, dsdy);
626 return NO_ERROR;
627}
628
629status_t layer_state_t::matrix22_t::read(const Parcel& input) {
630 SAFE_PARCEL(input.readFloat, &dsdx);
631 SAFE_PARCEL(input.readFloat, &dtdx);
632 SAFE_PARCEL(input.readFloat, &dtdy);
633 SAFE_PARCEL(input.readFloat, &dsdy);
634 return NO_ERROR;
635}
636
chaviw273171b2018-12-26 11:46:30 -0800637// ------------------------------- InputWindowCommands ----------------------------------------
638
Vishnu Naire798b472020-07-23 13:52:21 -0700639bool InputWindowCommands::merge(const InputWindowCommands& other) {
640 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700641 changes |= !other.focusRequests.empty();
642 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
643 std::make_move_iterator(other.focusRequests.end()));
Vishnu Naire798b472020-07-23 13:52:21 -0700644 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800645 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700646 return changes;
chaviw273171b2018-12-26 11:46:30 -0800647}
648
Vishnu Nair958da932020-08-21 17:12:37 -0700649bool InputWindowCommands::empty() const {
Vishnu Nair03ccbd62021-12-01 17:21:16 -0800650 return focusRequests.empty() && !syncInputWindows;
Vishnu Nair958da932020-08-21 17:12:37 -0700651}
652
chaviw273171b2018-12-26 11:46:30 -0800653void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700654 focusRequests.clear();
chaviwa911b102019-02-14 10:18:33 -0800655 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800656}
657
chaviw308ddba2020-08-11 16:23:51 -0700658status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700659 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700660 SAFE_PARCEL(output.writeBool, syncInputWindows);
661 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800662}
663
chaviw308ddba2020-08-11 16:23:51 -0700664status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700665 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700666 SAFE_PARCEL(input.readBool, &syncInputWindows);
667 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800668}
669
Marin Shalamanovc5986772021-03-16 16:09:49 +0100670bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
671 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800672 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
673 int floatClassification = std::fpclassify(frameRate);
674 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
675 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
676 return false;
677 }
678
679 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800680 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700681 (!privileged ||
682 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
683 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800684 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
685 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800686 return false;
687 }
688
Marin Shalamanovc5986772021-03-16 16:09:49 +0100689 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
690 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
691 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
692 changeFrameRateStrategy);
693 }
694
Steven Thomas62a4cf82020-01-31 12:04:03 -0800695 return true;
696}
697
chaviw618c42d2020-07-24 15:25:08 -0700698// ----------------------------------------------------------------------------
699
Huihong Luo9e84f332021-12-16 14:33:46 -0800700namespace gui {
701
702status_t CaptureArgs::writeToParcel(Parcel* output) const {
703 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
704 SAFE_PARCEL(output->write, sourceCrop);
705 SAFE_PARCEL(output->writeFloat, frameScaleX);
706 SAFE_PARCEL(output->writeFloat, frameScaleY);
707 SAFE_PARCEL(output->writeBool, captureSecureLayers);
708 SAFE_PARCEL(output->writeInt32, uid);
709 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
710 SAFE_PARCEL(output->writeBool, allowProtected);
711 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700712 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700713}
714
Huihong Luo9e84f332021-12-16 14:33:46 -0800715status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700716 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800717 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700718 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800719 SAFE_PARCEL(input->read, sourceCrop);
720 SAFE_PARCEL(input->readFloat, &frameScaleX);
721 SAFE_PARCEL(input->readFloat, &frameScaleY);
722 SAFE_PARCEL(input->readBool, &captureSecureLayers);
723 SAFE_PARCEL(input->readInt32, &uid);
724 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700725 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800726 SAFE_PARCEL(input->readBool, &allowProtected);
727 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700728 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700729}
730
Huihong Luo9e84f332021-12-16 14:33:46 -0800731status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
732 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700733
Huihong Luo9e84f332021-12-16 14:33:46 -0800734 SAFE_PARCEL(output->writeStrongBinder, displayToken);
735 SAFE_PARCEL(output->writeUint32, width);
736 SAFE_PARCEL(output->writeUint32, height);
737 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700738 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700739}
740
Huihong Luo9e84f332021-12-16 14:33:46 -0800741status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
742 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700743
Huihong Luo9e84f332021-12-16 14:33:46 -0800744 SAFE_PARCEL(input->readStrongBinder, &displayToken);
745 SAFE_PARCEL(input->readUint32, &width);
746 SAFE_PARCEL(input->readUint32, &height);
747 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700748 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700749}
750
Huihong Luo9e84f332021-12-16 14:33:46 -0800751status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
752 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700753
Huihong Luo9e84f332021-12-16 14:33:46 -0800754 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
755 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700756 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800757 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700758 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800759 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700760 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700761}
762
Huihong Luo9e84f332021-12-16 14:33:46 -0800763status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
764 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700765
Huihong Luo9e84f332021-12-16 14:33:46 -0800766 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700767
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700768 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800769 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700770 excludeHandles.reserve(numExcludeHandles);
771 for (int i = 0; i < numExcludeHandles; i++) {
772 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800773 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700774 excludeHandles.emplace(binder);
775 }
776
Huihong Luo9e84f332021-12-16 14:33:46 -0800777 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700778 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700779}
780
Huihong Luo9e84f332021-12-16 14:33:46 -0800781}; // namespace gui
782
chaviw8dd181f2022-01-05 18:36:46 -0600783ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500784 uint64_t bufferId;
785 if (buffer) {
786 bufferId = buffer->getId();
787 } else {
788 bufferId = cachedBuffer.id;
789 }
790 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600791}
792
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800793status_t BufferData::writeToParcel(Parcel* output) const {
794 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500795
796 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800797 SAFE_PARCEL(output->writeBool, true);
798 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500799 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800800 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500801 }
802
803 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800804 SAFE_PARCEL(output->writeBool, true);
805 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500806 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800807 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500808 }
809
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800810 SAFE_PARCEL(output->writeUint64, frameNumber);
811 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
812 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500813
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800814 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
815 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800816 SAFE_PARCEL(output->writeBool, hasBarrier);
817 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500818
819 return NO_ERROR;
820}
821
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800822status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500823 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800824 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700825 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500826
827 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800828 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500829 if (tmpBool) {
830 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800831 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500832 }
833
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800834 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500835 if (tmpBool) {
836 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800837 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500838 }
839
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800840 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500841
842 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800843 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500844 if (tmpBinder) {
845 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
846 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800847 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500848
849 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800850 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500851 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800852 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500853
Robert Carr79dc06a2022-02-22 15:28:59 -0800854 SAFE_PARCEL(input->readBool, &hasBarrier);
855 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
856
chaviwba4320c2021-09-15 15:20:53 -0500857 return NO_ERROR;
858}
859
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800860}; // namespace android