blob: 74e6ae6a9b1729448b9ec0663cc2d64f81af9c2f [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
Marin Shalamanovc5986772021-03-16 16:09:49 +010022#include <android/native_window.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080024#include <gui/IGraphicBufferProducer.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000025#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070026#include <gui/LayerState.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010027#include <private/gui/ParcelUtils.h>
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
Sally Qic7106172022-10-05 11:42:30 -0700356void DisplayState::sanitize(int32_t permissions) {
357 if (what & DisplayState::eLayerStackChanged) {
358 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
359 what &= ~DisplayState::eLayerStackChanged;
360 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
361 }
362 }
363 if (what & DisplayState::eDisplayProjectionChanged) {
364 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
365 what &= ~DisplayState::eDisplayProjectionChanged;
366 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
367 }
368 }
369 if (what & DisplayState::eSurfaceChanged) {
370 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
371 what &= ~DisplayState::eSurfaceChanged;
372 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
373 }
374 }
375}
376
Robert Carrde6d7b42022-01-07 18:23:06 -0800377void layer_state_t::sanitize(int32_t permissions) {
378 // TODO: b/109894387
379 //
380 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
381 // rotation. To see the problem observe that if we have a square parent, and a child
382 // of the same size, then we rotate the child 45 degrees around its center, the child
383 // must now be cropped to a non rectangular 8 sided region.
384 //
385 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
386 // private API, and arbitrary rotation is used in limited use cases, for instance:
387 // - WindowManager only uses rotation in one case, which is on a top level layer in which
388 // cropping is not an issue.
389 // - Launcher, as a privileged app, uses this to transition an application to PiP
390 // (picture-in-picture) mode.
391 //
392 // However given that abuse of rotation matrices could lead to surfaces extending outside
393 // of cropped areas, we need to prevent non-root clients without permission
394 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
395 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
396 // preserving transformations.
397 if (what & eMatrixChanged) {
398 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
399 ui::Transform t;
400 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
401 if (!t.preserveRects()) {
402 what &= ~eMatrixChanged;
403 ALOGE("Stripped non rect preserving matrix in sanitize");
404 }
405 }
406 }
407
408 if (what & eFlagsChanged) {
409 if ((flags & eLayerIsDisplayDecoration) &&
410 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
411 flags &= ~eLayerIsDisplayDecoration;
412 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
413 }
414 }
415
416 if (what & layer_state_t::eInputInfoChanged) {
417 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
418 what &= ~eInputInfoChanged;
419 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
420 }
421 }
422 if (what & layer_state_t::eTrustedOverlayChanged) {
423 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
424 what &= ~eTrustedOverlayChanged;
425 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
426 }
427 }
428 if (what & layer_state_t::eDropInputModeChanged) {
429 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
430 what &= ~eDropInputModeChanged;
431 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
432 }
433 }
434 if (what & layer_state_t::eFrameRateSelectionPriority) {
435 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
436 what &= ~eFrameRateSelectionPriority;
437 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
438 }
439 }
440 if (what & layer_state_t::eFrameRateChanged) {
441 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
442 changeFrameRateStrategy,
443 "layer_state_t::sanitize",
444 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
445 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
446 }
447 }
448}
449
Robert Carr2c5f6d22017-09-26 12:30:35 -0700450void layer_state_t::merge(const layer_state_t& other) {
451 if (other.what & ePositionChanged) {
452 what |= ePositionChanged;
453 x = other.x;
454 y = other.y;
455 }
456 if (other.what & eLayerChanged) {
457 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700458 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700459 z = other.z;
460 }
461 if (other.what & eSizeChanged) {
462 what |= eSizeChanged;
463 w = other.w;
464 h = other.h;
465 }
466 if (other.what & eAlphaChanged) {
467 what |= eAlphaChanged;
468 alpha = other.alpha;
469 }
470 if (other.what & eMatrixChanged) {
471 what |= eMatrixChanged;
472 matrix = other.matrix;
473 }
474 if (other.what & eTransparentRegionChanged) {
475 what |= eTransparentRegionChanged;
476 transparentRegion = other.transparentRegion;
477 }
478 if (other.what & eFlagsChanged) {
479 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700480 flags &= ~other.mask;
481 flags |= (other.flags & other.mask);
482 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700483 }
484 if (other.what & eLayerStackChanged) {
485 what |= eLayerStackChanged;
486 layerStack = other.layerStack;
487 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700488 if (other.what & eCornerRadiusChanged) {
489 what |= eCornerRadiusChanged;
490 cornerRadius = other.cornerRadius;
491 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800492 if (other.what & eBackgroundBlurRadiusChanged) {
493 what |= eBackgroundBlurRadiusChanged;
494 backgroundBlurRadius = other.backgroundBlurRadius;
495 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700496 if (other.what & eBlurRegionsChanged) {
497 what |= eBlurRegionsChanged;
498 blurRegions = other.blurRegions;
499 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700500 if (other.what & eRelativeLayerChanged) {
501 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700502 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700503 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000504 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700505 }
506 if (other.what & eReparent) {
507 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000508 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700509 }
chaviwca27f252018-02-06 16:46:39 -0800510 if (other.what & eDestroySurface) {
511 what |= eDestroySurface;
512 }
Marissa Wall61c58622018-07-18 10:12:20 -0700513 if (other.what & eTransformChanged) {
514 what |= eTransformChanged;
515 transform = other.transform;
516 }
517 if (other.what & eTransformToDisplayInverseChanged) {
518 what |= eTransformToDisplayInverseChanged;
519 transformToDisplayInverse = other.transformToDisplayInverse;
520 }
521 if (other.what & eCropChanged) {
522 what |= eCropChanged;
523 crop = other.crop;
524 }
525 if (other.what & eBufferChanged) {
526 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500527 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700528 }
529 if (other.what & eDataspaceChanged) {
530 what |= eDataspaceChanged;
531 dataspace = other.dataspace;
532 }
533 if (other.what & eHdrMetadataChanged) {
534 what |= eHdrMetadataChanged;
535 hdrMetadata = other.hdrMetadata;
536 }
537 if (other.what & eSurfaceDamageRegionChanged) {
538 what |= eSurfaceDamageRegionChanged;
539 surfaceDamageRegion = other.surfaceDamageRegion;
540 }
541 if (other.what & eApiChanged) {
542 what |= eApiChanged;
543 api = other.api;
544 }
545 if (other.what & eSidebandStreamChanged) {
546 what |= eSidebandStreamChanged;
547 sidebandStream = other.sidebandStream;
548 }
Peiyong Lind3788632018-09-18 16:01:31 -0700549 if (other.what & eColorTransformChanged) {
550 what |= eColorTransformChanged;
551 colorTransform = other.colorTransform;
552 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700553 if (other.what & eHasListenerCallbacksChanged) {
554 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700555 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700556 if (other.what & eInputInfoChanged) {
557 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500558 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700559 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800560 if (other.what & eBackgroundColorChanged) {
561 what |= eBackgroundColorChanged;
562 color = other.color;
563 bgColorAlpha = other.bgColorAlpha;
564 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800565 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800566 if (other.what & eMetadataChanged) {
567 what |= eMetadataChanged;
568 metadata.merge(other.metadata);
569 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700570 if (other.what & eShadowRadiusChanged) {
571 what |= eShadowRadiusChanged;
572 shadowRadius = other.shadowRadius;
573 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100574 if (other.what & eFrameRateSelectionPriority) {
575 what |= eFrameRateSelectionPriority;
576 frameRateSelectionPriority = other.frameRateSelectionPriority;
577 }
Steven Thomas3172e202020-01-06 19:25:30 -0800578 if (other.what & eFrameRateChanged) {
579 what |= eFrameRateChanged;
580 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800581 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100582 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800583 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700584 if (other.what & eFixedTransformHintChanged) {
585 what |= eFixedTransformHintChanged;
586 fixedTransformHint = other.fixedTransformHint;
587 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800588 if (other.what & eAutoRefreshChanged) {
589 what |= eAutoRefreshChanged;
590 autoRefresh = other.autoRefresh;
591 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700592 if (other.what & eTrustedOverlayChanged) {
593 what |= eTrustedOverlayChanged;
594 isTrustedOverlay = other.isTrustedOverlay;
595 }
John Reckc00c6692021-02-16 11:37:33 -0500596 if (other.what & eStretchChanged) {
597 what |= eStretchChanged;
598 stretchEffect = other.stretchEffect;
599 }
chaviwf3f40fe2021-04-27 15:54:02 -0500600 if (other.what & eBufferCropChanged) {
601 what |= eBufferCropChanged;
602 bufferCrop = other.bufferCrop;
603 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700604 if (other.what & eDestinationFrameChanged) {
605 what |= eDestinationFrameChanged;
606 destinationFrame = other.destinationFrame;
607 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700608 if (other.what & eProducerDisconnect) {
609 what |= eProducerDisconnect;
610 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700611 if (other.what & eDropInputModeChanged) {
612 what |= eDropInputModeChanged;
613 dropInputMode = other.dropInputMode;
614 }
chaviw4c36cd82021-11-18 10:37:33 -0600615 if (other.what & eColorChanged) {
616 what |= eColorChanged;
617 color = other.color;
618 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800619 if (other.what & eColorSpaceAgnosticChanged) {
620 what |= eColorSpaceAgnosticChanged;
621 colorSpaceAgnostic = other.colorSpaceAgnostic;
622 }
Sally Qi81d95e62022-03-21 19:41:33 -0700623 if (other.what & eDimmingEnabledChanged) {
624 what |= eDimmingEnabledChanged;
625 dimmingEnabled = other.dimmingEnabled;
626 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700627 if ((other.what & what) != other.what) {
628 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700629 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
630 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700631 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700632}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700633
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700634bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500635 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700636}
637
Ady Abraham6e8e3642021-07-08 19:44:07 -0700638bool layer_state_t::hasValidBuffer() const {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800639 return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700640}
641
chaviw308ddba2020-08-11 16:23:51 -0700642status_t layer_state_t::matrix22_t::write(Parcel& output) const {
643 SAFE_PARCEL(output.writeFloat, dsdx);
644 SAFE_PARCEL(output.writeFloat, dtdx);
645 SAFE_PARCEL(output.writeFloat, dtdy);
646 SAFE_PARCEL(output.writeFloat, dsdy);
647 return NO_ERROR;
648}
649
650status_t layer_state_t::matrix22_t::read(const Parcel& input) {
651 SAFE_PARCEL(input.readFloat, &dsdx);
652 SAFE_PARCEL(input.readFloat, &dtdx);
653 SAFE_PARCEL(input.readFloat, &dtdy);
654 SAFE_PARCEL(input.readFloat, &dsdy);
655 return NO_ERROR;
656}
657
chaviw273171b2018-12-26 11:46:30 -0800658// ------------------------------- InputWindowCommands ----------------------------------------
659
Vishnu Naire798b472020-07-23 13:52:21 -0700660bool InputWindowCommands::merge(const InputWindowCommands& other) {
661 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700662 changes |= !other.focusRequests.empty();
663 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
664 std::make_move_iterator(other.focusRequests.end()));
Vishnu Naire798b472020-07-23 13:52:21 -0700665 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800666 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700667 return changes;
chaviw273171b2018-12-26 11:46:30 -0800668}
669
Vishnu Nair958da932020-08-21 17:12:37 -0700670bool InputWindowCommands::empty() const {
Vishnu Nair03ccbd62021-12-01 17:21:16 -0800671 return focusRequests.empty() && !syncInputWindows;
Vishnu Nair958da932020-08-21 17:12:37 -0700672}
673
chaviw273171b2018-12-26 11:46:30 -0800674void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700675 focusRequests.clear();
chaviwa911b102019-02-14 10:18:33 -0800676 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800677}
678
chaviw308ddba2020-08-11 16:23:51 -0700679status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700680 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700681 SAFE_PARCEL(output.writeBool, syncInputWindows);
682 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800683}
684
chaviw308ddba2020-08-11 16:23:51 -0700685status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700686 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700687 SAFE_PARCEL(input.readBool, &syncInputWindows);
688 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800689}
690
Marin Shalamanovc5986772021-03-16 16:09:49 +0100691bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
692 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800693 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
694 int floatClassification = std::fpclassify(frameRate);
695 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
696 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
697 return false;
698 }
699
700 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800701 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700702 (!privileged ||
703 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
704 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800705 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
706 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800707 return false;
708 }
709
Marin Shalamanovc5986772021-03-16 16:09:49 +0100710 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
711 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
712 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
713 changeFrameRateStrategy);
714 }
715
Steven Thomas62a4cf82020-01-31 12:04:03 -0800716 return true;
717}
718
chaviw618c42d2020-07-24 15:25:08 -0700719// ----------------------------------------------------------------------------
720
Huihong Luo9e84f332021-12-16 14:33:46 -0800721namespace gui {
722
723status_t CaptureArgs::writeToParcel(Parcel* output) const {
724 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
725 SAFE_PARCEL(output->write, sourceCrop);
726 SAFE_PARCEL(output->writeFloat, frameScaleX);
727 SAFE_PARCEL(output->writeFloat, frameScaleY);
728 SAFE_PARCEL(output->writeBool, captureSecureLayers);
729 SAFE_PARCEL(output->writeInt32, uid);
730 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
731 SAFE_PARCEL(output->writeBool, allowProtected);
732 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700733 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700734}
735
Huihong Luo9e84f332021-12-16 14:33:46 -0800736status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700737 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800738 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700739 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800740 SAFE_PARCEL(input->read, sourceCrop);
741 SAFE_PARCEL(input->readFloat, &frameScaleX);
742 SAFE_PARCEL(input->readFloat, &frameScaleY);
743 SAFE_PARCEL(input->readBool, &captureSecureLayers);
744 SAFE_PARCEL(input->readInt32, &uid);
745 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700746 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800747 SAFE_PARCEL(input->readBool, &allowProtected);
748 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700749 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700750}
751
Huihong Luo9e84f332021-12-16 14:33:46 -0800752status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
753 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700754
Huihong Luo9e84f332021-12-16 14:33:46 -0800755 SAFE_PARCEL(output->writeStrongBinder, displayToken);
756 SAFE_PARCEL(output->writeUint32, width);
757 SAFE_PARCEL(output->writeUint32, height);
758 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700759 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700760}
761
Huihong Luo9e84f332021-12-16 14:33:46 -0800762status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
763 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700764
Huihong Luo9e84f332021-12-16 14:33:46 -0800765 SAFE_PARCEL(input->readStrongBinder, &displayToken);
766 SAFE_PARCEL(input->readUint32, &width);
767 SAFE_PARCEL(input->readUint32, &height);
768 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700769 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700770}
771
Huihong Luo9e84f332021-12-16 14:33:46 -0800772status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
773 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700774
Huihong Luo9e84f332021-12-16 14:33:46 -0800775 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
776 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700777 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800778 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700779 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800780 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700781 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700782}
783
Huihong Luo9e84f332021-12-16 14:33:46 -0800784status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
785 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700786
Huihong Luo9e84f332021-12-16 14:33:46 -0800787 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700788
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700789 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800790 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700791 excludeHandles.reserve(numExcludeHandles);
792 for (int i = 0; i < numExcludeHandles; i++) {
793 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800794 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700795 excludeHandles.emplace(binder);
796 }
797
Huihong Luo9e84f332021-12-16 14:33:46 -0800798 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700799 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700800}
801
Huihong Luo9e84f332021-12-16 14:33:46 -0800802}; // namespace gui
803
chaviw8dd181f2022-01-05 18:36:46 -0600804ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500805 uint64_t bufferId;
806 if (buffer) {
807 bufferId = buffer->getId();
808 } else {
809 bufferId = cachedBuffer.id;
810 }
811 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600812}
813
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800814status_t BufferData::writeToParcel(Parcel* output) const {
815 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500816
817 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800818 SAFE_PARCEL(output->writeBool, true);
819 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500820 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800821 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500822 }
823
824 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800825 SAFE_PARCEL(output->writeBool, true);
826 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500827 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800828 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500829 }
830
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800831 SAFE_PARCEL(output->writeUint64, frameNumber);
832 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
833 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500834
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800835 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
836 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800837 SAFE_PARCEL(output->writeBool, hasBarrier);
838 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500839
840 return NO_ERROR;
841}
842
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800843status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500844 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800845 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700846 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500847
848 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800849 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500850 if (tmpBool) {
851 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800852 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500853 }
854
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800855 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500856 if (tmpBool) {
857 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800858 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500859 }
860
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800861 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500862
863 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800864 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500865 if (tmpBinder) {
866 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
867 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800868 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500869
870 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800871 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500872 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800873 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500874
Robert Carr79dc06a2022-02-22 15:28:59 -0800875 SAFE_PARCEL(input->readBool, &hasBarrier);
876 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
877
chaviwba4320c2021-09-15 15:20:53 -0500878 return NO_ERROR;
879}
880
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800881}; // namespace android