blob: 2759c58fb16fd42b949975fc66e39244ea4689ba [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),
Pablo Gamito11dcc222020-09-12 15:49:39 +000043 alpha(0),
44 flags(0),
45 mask(0),
46 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000047 cornerRadius(0.0f),
48 backgroundBlurRadius(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000049 transform(0),
50 transformToDisplayInverse(false),
51 crop(Rect::INVALID_RECT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000052 dataspace(ui::Dataspace::UNKNOWN),
53 surfaceDamageRegion(),
54 api(-1),
55 colorTransform(mat4()),
56 bgColorAlpha(0),
57 bgColorDataspace(ui::Dataspace::UNKNOWN),
58 colorSpaceAgnostic(false),
59 shadowRadius(0.0f),
60 frameRateSelectionPriority(-1),
61 frameRate(0.0f),
62 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010063 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Andy Labrada096227e2022-06-15 16:58:11 +000064 defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000065 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080066 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070067 isTrustedOverlay(false),
Tianhao Yao67dd7122022-02-22 17:48:33 +000068 borderEnabled(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);
Dominik Laskowski29fa1462021-04-27 15:51:50 -070085 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -070086 SAFE_PARCEL(output.writeFloat, alpha);
87 SAFE_PARCEL(output.writeUint32, flags);
88 SAFE_PARCEL(output.writeUint32, mask);
89 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080090 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000091 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
Pablo Gamito11dcc222020-09-12 15:49:39 +000092 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
93 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070094 SAFE_PARCEL(output.writeFloat, color.r);
95 SAFE_PARCEL(output.writeFloat, color.g);
96 SAFE_PARCEL(output.writeFloat, color.b);
chaviw98318de2021-05-19 16:45:23 -050097 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -070098 SAFE_PARCEL(output.write, transparentRegion);
99 SAFE_PARCEL(output.writeUint32, transform);
100 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000101 SAFE_PARCEL(output.writeBool, borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000102 SAFE_PARCEL(output.writeFloat, borderWidth);
103 SAFE_PARCEL(output.writeFloat, borderColor.r);
104 SAFE_PARCEL(output.writeFloat, borderColor.g);
105 SAFE_PARCEL(output.writeFloat, borderColor.b);
106 SAFE_PARCEL(output.writeFloat, borderColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700107 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
108 SAFE_PARCEL(output.write, hdrMetadata);
109 SAFE_PARCEL(output.write, surfaceDamageRegion);
110 SAFE_PARCEL(output.writeInt32, api);
111
Marissa Wall61c58622018-07-18 10:12:20 -0700112 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700113 SAFE_PARCEL(output.writeBool, true);
114 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700115 } else {
chaviw308ddba2020-08-11 16:23:51 -0700116 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700117 }
118
chaviw308ddba2020-08-11 16:23:51 -0700119 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
120 SAFE_PARCEL(output.writeFloat, cornerRadius);
121 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700122 SAFE_PARCEL(output.writeParcelable, metadata);
123 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
124 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
125 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
126 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700127
128 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700129 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700130 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700131 }
chaviw308ddba2020-08-11 16:23:51 -0700132 SAFE_PARCEL(output.writeFloat, shadowRadius);
133 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
134 SAFE_PARCEL(output.writeFloat, frameRate);
135 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100136 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000137 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700138 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800139 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700140 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700141
142 SAFE_PARCEL(output.writeUint32, blurRegions.size());
143 for (auto region : blurRegions) {
144 SAFE_PARCEL(output.writeUint32, region.blurRadius);
145 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
146 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
147 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
148 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
149 SAFE_PARCEL(output.writeFloat, region.alpha);
150 SAFE_PARCEL(output.writeInt32, region.left);
151 SAFE_PARCEL(output.writeInt32, region.top);
152 SAFE_PARCEL(output.writeInt32, region.right);
153 SAFE_PARCEL(output.writeInt32, region.bottom);
154 }
John Reckcdb4ed72021-02-04 13:39:33 -0500155
156 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500157 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700158 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700159 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500160
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700161 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800162
163 const bool hasBufferData = (bufferData != nullptr);
164 SAFE_PARCEL(output.writeBool, hasBufferData);
165 if (hasBufferData) {
166 SAFE_PARCEL(output.writeParcelable, *bufferData);
167 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800168 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800169}
170
171status_t layer_state_t::read(const Parcel& input)
172{
chaviw308ddba2020-08-11 16:23:51 -0700173 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000174 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700175 SAFE_PARCEL(input.readUint64, &what);
176 SAFE_PARCEL(input.readFloat, &x);
177 SAFE_PARCEL(input.readFloat, &y);
178 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700179 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700180 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700181
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800182 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700183
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800184 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700185
186 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800187 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000188 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700189
Pablo Gamito11dcc222020-09-12 15:49:39 +0000190 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
191 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
192
chaviw308ddba2020-08-11 16:23:51 -0700193 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700194 SAFE_PARCEL(input.readFloat, &tmpFloat);
195 color.r = tmpFloat;
196 SAFE_PARCEL(input.readFloat, &tmpFloat);
197 color.g = tmpFloat;
198 SAFE_PARCEL(input.readFloat, &tmpFloat);
199 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500200 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700201
chaviw308ddba2020-08-11 16:23:51 -0700202 SAFE_PARCEL(input.read, transparentRegion);
203 SAFE_PARCEL(input.readUint32, &transform);
204 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000205 SAFE_PARCEL(input.readBool, &borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000206 SAFE_PARCEL(input.readFloat, &tmpFloat);
207 borderWidth = tmpFloat;
208 SAFE_PARCEL(input.readFloat, &tmpFloat);
209 borderColor.r = tmpFloat;
210 SAFE_PARCEL(input.readFloat, &tmpFloat);
211 borderColor.g = tmpFloat;
212 SAFE_PARCEL(input.readFloat, &tmpFloat);
213 borderColor.b = tmpFloat;
214 SAFE_PARCEL(input.readFloat, &tmpFloat);
215 borderColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700216
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800217 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700218 SAFE_PARCEL(input.readUint32, &tmpUint32);
219 dataspace = static_cast<ui::Dataspace>(tmpUint32);
220
221 SAFE_PARCEL(input.read, hdrMetadata);
222 SAFE_PARCEL(input.read, surfaceDamageRegion);
223 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500224
225 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700226 SAFE_PARCEL(input.readBool, &tmpBool);
227 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700228 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
229 }
230
chaviw308ddba2020-08-11 16:23:51 -0700231 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
232 SAFE_PARCEL(input.readFloat, &cornerRadius);
233 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700234 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800235
chaviw308ddba2020-08-11 16:23:51 -0700236 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
237 SAFE_PARCEL(input.readUint32, &tmpUint32);
238 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
239 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800240
chaviw308ddba2020-08-11 16:23:51 -0700241 int32_t numListeners = 0;
242 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700243 listeners.clear();
244 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700245 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700246 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700247 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700248 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700249 listeners.emplace_back(listener, callbackIds);
250 }
chaviw308ddba2020-08-11 16:23:51 -0700251 SAFE_PARCEL(input.readFloat, &shadowRadius);
252 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
253 SAFE_PARCEL(input.readFloat, &frameRate);
254 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100255 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000256 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700257 SAFE_PARCEL(input.readUint32, &tmpUint32);
258 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800259 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700260 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700261
262 uint32_t numRegions = 0;
263 SAFE_PARCEL(input.readUint32, &numRegions);
264 blurRegions.clear();
265 for (uint32_t i = 0; i < numRegions; i++) {
266 BlurRegion region;
267 SAFE_PARCEL(input.readUint32, &region.blurRadius);
268 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
269 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
270 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
271 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
272 SAFE_PARCEL(input.readFloat, &region.alpha);
273 SAFE_PARCEL(input.readInt32, &region.left);
274 SAFE_PARCEL(input.readInt32, &region.top);
275 SAFE_PARCEL(input.readInt32, &region.right);
276 SAFE_PARCEL(input.readInt32, &region.bottom);
277 blurRegions.push_back(region);
278 }
John Reckcdb4ed72021-02-04 13:39:33 -0500279
280 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500281 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700282 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700283 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500284
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700285 uint32_t mode;
286 SAFE_PARCEL(input.readUint32, &mode);
287 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800288
289 bool hasBufferData;
290 SAFE_PARCEL(input.readBool, &hasBufferData);
291 if (hasBufferData) {
292 bufferData = std::make_shared<BufferData>();
293 SAFE_PARCEL(input.readParcelable, bufferData.get());
294 } else {
295 bufferData = nullptr;
296 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800297 return NO_ERROR;
298}
299
Mathias Agopian698c0872011-06-28 19:09:31 -0700300status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700301 return state.write(output);
302}
303
304status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700305 return state.read(input);
306}
307
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700308DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700309
Mathias Agopian8b33f032012-07-24 20:43:54 -0700310status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700311 SAFE_PARCEL(output.writeStrongBinder, token);
312 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
313 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700314 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700315 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700316 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
317 SAFE_PARCEL(output.write, layerStackSpaceRect);
318 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
319 SAFE_PARCEL(output.writeUint32, width);
320 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700321 return NO_ERROR;
322}
323
324status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700325 SAFE_PARCEL(input.readStrongBinder, &token);
326 sp<IBinder> tmpBinder;
327 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
328 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
329
330 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700331 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700332 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700333 uint32_t tmpUint = 0;
334 SAFE_PARCEL(input.readUint32, &tmpUint);
335 orientation = ui::toRotation(tmpUint);
336
337 SAFE_PARCEL(input.read, layerStackSpaceRect);
338 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
339 SAFE_PARCEL(input.readUint32, &width);
340 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700341 return NO_ERROR;
342}
343
Robert Carr2c5f6d22017-09-26 12:30:35 -0700344void DisplayState::merge(const DisplayState& other) {
345 if (other.what & eSurfaceChanged) {
346 what |= eSurfaceChanged;
347 surface = other.surface;
348 }
349 if (other.what & eLayerStackChanged) {
350 what |= eLayerStackChanged;
351 layerStack = other.layerStack;
352 }
Evan Rosky2239b372021-05-20 13:43:47 -0700353 if (other.what & eFlagsChanged) {
354 what |= eFlagsChanged;
355 flags = other.flags;
356 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700357 if (other.what & eDisplayProjectionChanged) {
358 what |= eDisplayProjectionChanged;
359 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200360 layerStackSpaceRect = other.layerStackSpaceRect;
361 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700362 }
363 if (other.what & eDisplaySizeChanged) {
364 what |= eDisplaySizeChanged;
365 width = other.width;
366 height = other.height;
367 }
368}
369
Robert Carrde6d7b42022-01-07 18:23:06 -0800370void layer_state_t::sanitize(int32_t permissions) {
371 // TODO: b/109894387
372 //
373 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
374 // rotation. To see the problem observe that if we have a square parent, and a child
375 // of the same size, then we rotate the child 45 degrees around its center, the child
376 // must now be cropped to a non rectangular 8 sided region.
377 //
378 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
379 // private API, and arbitrary rotation is used in limited use cases, for instance:
380 // - WindowManager only uses rotation in one case, which is on a top level layer in which
381 // cropping is not an issue.
382 // - Launcher, as a privileged app, uses this to transition an application to PiP
383 // (picture-in-picture) mode.
384 //
385 // However given that abuse of rotation matrices could lead to surfaces extending outside
386 // of cropped areas, we need to prevent non-root clients without permission
387 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
388 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
389 // preserving transformations.
390 if (what & eMatrixChanged) {
391 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
392 ui::Transform t;
393 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
394 if (!t.preserveRects()) {
395 what &= ~eMatrixChanged;
396 ALOGE("Stripped non rect preserving matrix in sanitize");
397 }
398 }
399 }
400
401 if (what & eFlagsChanged) {
402 if ((flags & eLayerIsDisplayDecoration) &&
403 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
404 flags &= ~eLayerIsDisplayDecoration;
405 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
406 }
407 }
408
409 if (what & layer_state_t::eInputInfoChanged) {
410 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
411 what &= ~eInputInfoChanged;
412 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
413 }
414 }
415 if (what & layer_state_t::eTrustedOverlayChanged) {
416 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
417 what &= ~eTrustedOverlayChanged;
418 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
419 }
420 }
421 if (what & layer_state_t::eDropInputModeChanged) {
422 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
423 what &= ~eDropInputModeChanged;
424 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
425 }
426 }
427 if (what & layer_state_t::eFrameRateSelectionPriority) {
428 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
429 what &= ~eFrameRateSelectionPriority;
430 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
431 }
432 }
433 if (what & layer_state_t::eFrameRateChanged) {
434 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
435 changeFrameRateStrategy,
436 "layer_state_t::sanitize",
437 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
438 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
439 }
440 }
441}
442
Robert Carr2c5f6d22017-09-26 12:30:35 -0700443void layer_state_t::merge(const layer_state_t& other) {
444 if (other.what & ePositionChanged) {
445 what |= ePositionChanged;
446 x = other.x;
447 y = other.y;
448 }
449 if (other.what & eLayerChanged) {
450 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700451 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700452 z = other.z;
453 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700454 if (other.what & eAlphaChanged) {
455 what |= eAlphaChanged;
456 alpha = other.alpha;
457 }
458 if (other.what & eMatrixChanged) {
459 what |= eMatrixChanged;
460 matrix = other.matrix;
461 }
462 if (other.what & eTransparentRegionChanged) {
463 what |= eTransparentRegionChanged;
464 transparentRegion = other.transparentRegion;
465 }
466 if (other.what & eFlagsChanged) {
467 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700468 flags &= ~other.mask;
469 flags |= (other.flags & other.mask);
470 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700471 }
472 if (other.what & eLayerStackChanged) {
473 what |= eLayerStackChanged;
474 layerStack = other.layerStack;
475 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700476 if (other.what & eCornerRadiusChanged) {
477 what |= eCornerRadiusChanged;
478 cornerRadius = other.cornerRadius;
479 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800480 if (other.what & eBackgroundBlurRadiusChanged) {
481 what |= eBackgroundBlurRadiusChanged;
482 backgroundBlurRadius = other.backgroundBlurRadius;
483 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700484 if (other.what & eBlurRegionsChanged) {
485 what |= eBlurRegionsChanged;
486 blurRegions = other.blurRegions;
487 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700488 if (other.what & eRelativeLayerChanged) {
489 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700490 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700491 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000492 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700493 }
494 if (other.what & eReparent) {
495 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000496 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700497 }
chaviwca27f252018-02-06 16:46:39 -0800498 if (other.what & eDestroySurface) {
499 what |= eDestroySurface;
500 }
Marissa Wall61c58622018-07-18 10:12:20 -0700501 if (other.what & eTransformChanged) {
502 what |= eTransformChanged;
503 transform = other.transform;
504 }
505 if (other.what & eTransformToDisplayInverseChanged) {
506 what |= eTransformToDisplayInverseChanged;
507 transformToDisplayInverse = other.transformToDisplayInverse;
508 }
509 if (other.what & eCropChanged) {
510 what |= eCropChanged;
511 crop = other.crop;
512 }
513 if (other.what & eBufferChanged) {
514 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500515 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700516 }
517 if (other.what & eDataspaceChanged) {
518 what |= eDataspaceChanged;
519 dataspace = other.dataspace;
520 }
521 if (other.what & eHdrMetadataChanged) {
522 what |= eHdrMetadataChanged;
523 hdrMetadata = other.hdrMetadata;
524 }
525 if (other.what & eSurfaceDamageRegionChanged) {
526 what |= eSurfaceDamageRegionChanged;
527 surfaceDamageRegion = other.surfaceDamageRegion;
528 }
529 if (other.what & eApiChanged) {
530 what |= eApiChanged;
531 api = other.api;
532 }
533 if (other.what & eSidebandStreamChanged) {
534 what |= eSidebandStreamChanged;
535 sidebandStream = other.sidebandStream;
536 }
Peiyong Lind3788632018-09-18 16:01:31 -0700537 if (other.what & eColorTransformChanged) {
538 what |= eColorTransformChanged;
539 colorTransform = other.colorTransform;
540 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700541 if (other.what & eHasListenerCallbacksChanged) {
542 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700543 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700544 if (other.what & eInputInfoChanged) {
545 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500546 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700547 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800548 if (other.what & eBackgroundColorChanged) {
549 what |= eBackgroundColorChanged;
550 color = other.color;
551 bgColorAlpha = other.bgColorAlpha;
552 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800553 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800554 if (other.what & eMetadataChanged) {
555 what |= eMetadataChanged;
556 metadata.merge(other.metadata);
557 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700558 if (other.what & eShadowRadiusChanged) {
559 what |= eShadowRadiusChanged;
560 shadowRadius = other.shadowRadius;
561 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000562 if (other.what & eRenderBorderChanged) {
563 what |= eRenderBorderChanged;
564 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000565 borderWidth = other.borderWidth;
566 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000567 }
Andy Labrada096227e2022-06-15 16:58:11 +0000568 if (other.what & eDefaultFrameRateCompatibilityChanged) {
569 what |= eDefaultFrameRateCompatibilityChanged;
570 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
571 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100572 if (other.what & eFrameRateSelectionPriority) {
573 what |= eFrameRateSelectionPriority;
574 frameRateSelectionPriority = other.frameRateSelectionPriority;
575 }
Steven Thomas3172e202020-01-06 19:25:30 -0800576 if (other.what & eFrameRateChanged) {
577 what |= eFrameRateChanged;
578 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800579 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100580 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800581 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700582 if (other.what & eFixedTransformHintChanged) {
583 what |= eFixedTransformHintChanged;
584 fixedTransformHint = other.fixedTransformHint;
585 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800586 if (other.what & eAutoRefreshChanged) {
587 what |= eAutoRefreshChanged;
588 autoRefresh = other.autoRefresh;
589 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700590 if (other.what & eTrustedOverlayChanged) {
591 what |= eTrustedOverlayChanged;
592 isTrustedOverlay = other.isTrustedOverlay;
593 }
John Reckc00c6692021-02-16 11:37:33 -0500594 if (other.what & eStretchChanged) {
595 what |= eStretchChanged;
596 stretchEffect = other.stretchEffect;
597 }
chaviwf3f40fe2021-04-27 15:54:02 -0500598 if (other.what & eBufferCropChanged) {
599 what |= eBufferCropChanged;
600 bufferCrop = other.bufferCrop;
601 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700602 if (other.what & eDestinationFrameChanged) {
603 what |= eDestinationFrameChanged;
604 destinationFrame = other.destinationFrame;
605 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700606 if (other.what & eProducerDisconnect) {
607 what |= eProducerDisconnect;
608 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700609 if (other.what & eDropInputModeChanged) {
610 what |= eDropInputModeChanged;
611 dropInputMode = other.dropInputMode;
612 }
chaviw4c36cd82021-11-18 10:37:33 -0600613 if (other.what & eColorChanged) {
614 what |= eColorChanged;
615 color = other.color;
616 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800617 if (other.what & eColorSpaceAgnosticChanged) {
618 what |= eColorSpaceAgnosticChanged;
619 colorSpaceAgnostic = other.colorSpaceAgnostic;
620 }
Sally Qi81d95e62022-03-21 19:41:33 -0700621 if (other.what & eDimmingEnabledChanged) {
622 what |= eDimmingEnabledChanged;
623 dimmingEnabled = other.dimmingEnabled;
624 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700625 if ((other.what & what) != other.what) {
626 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700627 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
628 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700629 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700630}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700631
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700632bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500633 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700634}
635
Ady Abraham6e8e3642021-07-08 19:44:07 -0700636bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700637 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700638}
639
chaviw308ddba2020-08-11 16:23:51 -0700640status_t layer_state_t::matrix22_t::write(Parcel& output) const {
641 SAFE_PARCEL(output.writeFloat, dsdx);
642 SAFE_PARCEL(output.writeFloat, dtdx);
643 SAFE_PARCEL(output.writeFloat, dtdy);
644 SAFE_PARCEL(output.writeFloat, dsdy);
645 return NO_ERROR;
646}
647
648status_t layer_state_t::matrix22_t::read(const Parcel& input) {
649 SAFE_PARCEL(input.readFloat, &dsdx);
650 SAFE_PARCEL(input.readFloat, &dtdx);
651 SAFE_PARCEL(input.readFloat, &dtdy);
652 SAFE_PARCEL(input.readFloat, &dsdy);
653 return NO_ERROR;
654}
655
chaviw273171b2018-12-26 11:46:30 -0800656// ------------------------------- InputWindowCommands ----------------------------------------
657
Vishnu Naire798b472020-07-23 13:52:21 -0700658bool InputWindowCommands::merge(const InputWindowCommands& other) {
659 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700660 changes |= !other.focusRequests.empty();
661 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
662 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000663 changes |= !other.windowInfosReportedListeners.empty();
664 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
665 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700666 return changes;
chaviw273171b2018-12-26 11:46:30 -0800667}
668
Vishnu Nair958da932020-08-21 17:12:37 -0700669bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000670 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700671}
672
chaviw273171b2018-12-26 11:46:30 -0800673void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700674 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000675 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800676}
677
chaviw308ddba2020-08-11 16:23:51 -0700678status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700679 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000680
681 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
682 for (const auto& listener : windowInfosReportedListeners) {
683 SAFE_PARCEL(output.writeStrongBinder, listener);
684 }
685
chaviw308ddba2020-08-11 16:23:51 -0700686 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800687}
688
chaviw308ddba2020-08-11 16:23:51 -0700689status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700690 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000691
692 int listenerSize = 0;
693 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
694 windowInfosReportedListeners.reserve(listenerSize);
695 for (int i = 0; i < listenerSize; i++) {
696 sp<gui::IWindowInfosReportedListener> listener;
697 SAFE_PARCEL(input.readStrongBinder, &listener);
698 windowInfosReportedListeners.insert(listener);
699 }
700
chaviw308ddba2020-08-11 16:23:51 -0700701 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800702}
703
Marin Shalamanovc5986772021-03-16 16:09:49 +0100704bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
705 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800706 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
707 int floatClassification = std::fpclassify(frameRate);
708 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
709 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
710 return false;
711 }
712
713 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800714 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700715 (!privileged ||
716 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
717 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800718 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
719 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800720 return false;
721 }
722
Marin Shalamanovc5986772021-03-16 16:09:49 +0100723 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
724 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
725 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
726 changeFrameRateStrategy);
727 }
728
Steven Thomas62a4cf82020-01-31 12:04:03 -0800729 return true;
730}
731
chaviw618c42d2020-07-24 15:25:08 -0700732// ----------------------------------------------------------------------------
733
Huihong Luo9e84f332021-12-16 14:33:46 -0800734namespace gui {
735
736status_t CaptureArgs::writeToParcel(Parcel* output) const {
737 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
738 SAFE_PARCEL(output->write, sourceCrop);
739 SAFE_PARCEL(output->writeFloat, frameScaleX);
740 SAFE_PARCEL(output->writeFloat, frameScaleY);
741 SAFE_PARCEL(output->writeBool, captureSecureLayers);
742 SAFE_PARCEL(output->writeInt32, uid);
743 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
744 SAFE_PARCEL(output->writeBool, allowProtected);
745 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700746 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700747}
748
Huihong Luo9e84f332021-12-16 14:33:46 -0800749status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700750 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800751 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700752 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800753 SAFE_PARCEL(input->read, sourceCrop);
754 SAFE_PARCEL(input->readFloat, &frameScaleX);
755 SAFE_PARCEL(input->readFloat, &frameScaleY);
756 SAFE_PARCEL(input->readBool, &captureSecureLayers);
757 SAFE_PARCEL(input->readInt32, &uid);
758 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700759 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800760 SAFE_PARCEL(input->readBool, &allowProtected);
761 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700762 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700763}
764
Huihong Luo9e84f332021-12-16 14:33:46 -0800765status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
766 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700767
Huihong Luo9e84f332021-12-16 14:33:46 -0800768 SAFE_PARCEL(output->writeStrongBinder, displayToken);
769 SAFE_PARCEL(output->writeUint32, width);
770 SAFE_PARCEL(output->writeUint32, height);
771 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700772 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700773}
774
Huihong Luo9e84f332021-12-16 14:33:46 -0800775status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
776 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700777
Huihong Luo9e84f332021-12-16 14:33:46 -0800778 SAFE_PARCEL(input->readStrongBinder, &displayToken);
779 SAFE_PARCEL(input->readUint32, &width);
780 SAFE_PARCEL(input->readUint32, &height);
781 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700782 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700783}
784
Huihong Luo9e84f332021-12-16 14:33:46 -0800785status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
786 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700787
Huihong Luo9e84f332021-12-16 14:33:46 -0800788 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
789 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700790 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800791 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700792 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800793 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700794 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700795}
796
Huihong Luo9e84f332021-12-16 14:33:46 -0800797status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
798 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700799
Huihong Luo9e84f332021-12-16 14:33:46 -0800800 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700801
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700802 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800803 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700804 excludeHandles.reserve(numExcludeHandles);
805 for (int i = 0; i < numExcludeHandles; i++) {
806 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800807 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700808 excludeHandles.emplace(binder);
809 }
810
Huihong Luo9e84f332021-12-16 14:33:46 -0800811 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700812 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700813}
814
Huihong Luo9e84f332021-12-16 14:33:46 -0800815}; // namespace gui
816
chaviw8dd181f2022-01-05 18:36:46 -0600817ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500818 uint64_t bufferId;
819 if (buffer) {
820 bufferId = buffer->getId();
821 } else {
822 bufferId = cachedBuffer.id;
823 }
824 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600825}
826
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800827status_t BufferData::writeToParcel(Parcel* output) const {
828 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500829
830 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800831 SAFE_PARCEL(output->writeBool, true);
832 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500833 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800834 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500835 }
836
837 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800838 SAFE_PARCEL(output->writeBool, true);
839 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500840 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800841 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500842 }
843
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800844 SAFE_PARCEL(output->writeUint64, frameNumber);
845 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
846 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500847
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800848 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
849 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800850 SAFE_PARCEL(output->writeBool, hasBarrier);
851 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500852
853 return NO_ERROR;
854}
855
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800856status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500857 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800858 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700859 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500860
861 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800862 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500863 if (tmpBool) {
864 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800865 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500866 }
867
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800868 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500869 if (tmpBool) {
870 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800871 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500872 }
873
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800874 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500875
876 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800877 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500878 if (tmpBinder) {
879 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
880 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800881 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500882
883 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800884 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500885 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800886 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500887
Robert Carr79dc06a2022-02-22 15:28:59 -0800888 SAFE_PARCEL(input->readBool, &hasBarrier);
889 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
890
chaviwba4320c2021-09-15 15:20:53 -0500891 return NO_ERROR;
892}
893
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800894}; // namespace android