blob: 924e65ec4a90172dfd679fee2fc5958de13bbbcd [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 flags(0),
44 mask(0),
45 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000046 cornerRadius(0.0f),
47 backgroundBlurRadius(0),
Vishnu Nairbbceb462022-10-10 04:52:13 +000048 color(0),
49 bufferTransform(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000050 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.writeUint32, flags);
87 SAFE_PARCEL(output.writeUint32, mask);
88 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080089 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000090 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
91 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070092 SAFE_PARCEL(output.writeFloat, color.r);
93 SAFE_PARCEL(output.writeFloat, color.g);
94 SAFE_PARCEL(output.writeFloat, color.b);
Vishnu Nairbbceb462022-10-10 04:52:13 +000095 SAFE_PARCEL(output.writeFloat, color.a);
chaviw98318de2021-05-19 16:45:23 -050096 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -070097 SAFE_PARCEL(output.write, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +000098 SAFE_PARCEL(output.writeUint32, bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -070099 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000100 SAFE_PARCEL(output.writeBool, borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000101 SAFE_PARCEL(output.writeFloat, borderWidth);
102 SAFE_PARCEL(output.writeFloat, borderColor.r);
103 SAFE_PARCEL(output.writeFloat, borderColor.g);
104 SAFE_PARCEL(output.writeFloat, borderColor.b);
105 SAFE_PARCEL(output.writeFloat, borderColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700106 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
107 SAFE_PARCEL(output.write, hdrMetadata);
108 SAFE_PARCEL(output.write, surfaceDamageRegion);
109 SAFE_PARCEL(output.writeInt32, api);
110
Marissa Wall61c58622018-07-18 10:12:20 -0700111 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700112 SAFE_PARCEL(output.writeBool, true);
113 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700114 } else {
chaviw308ddba2020-08-11 16:23:51 -0700115 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700116 }
117
chaviw308ddba2020-08-11 16:23:51 -0700118 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
119 SAFE_PARCEL(output.writeFloat, cornerRadius);
120 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700121 SAFE_PARCEL(output.writeParcelable, metadata);
122 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
123 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
124 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
125 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700126
127 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700128 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700129 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700130 }
chaviw308ddba2020-08-11 16:23:51 -0700131 SAFE_PARCEL(output.writeFloat, shadowRadius);
132 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
133 SAFE_PARCEL(output.writeFloat, frameRate);
134 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100135 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000136 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700137 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800138 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700139 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700140
141 SAFE_PARCEL(output.writeUint32, blurRegions.size());
142 for (auto region : blurRegions) {
143 SAFE_PARCEL(output.writeUint32, region.blurRadius);
144 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
145 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
146 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
147 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
148 SAFE_PARCEL(output.writeFloat, region.alpha);
149 SAFE_PARCEL(output.writeInt32, region.left);
150 SAFE_PARCEL(output.writeInt32, region.top);
151 SAFE_PARCEL(output.writeInt32, region.right);
152 SAFE_PARCEL(output.writeInt32, region.bottom);
153 }
John Reckcdb4ed72021-02-04 13:39:33 -0500154
155 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500156 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700157 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700158 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500159
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700160 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800161
162 const bool hasBufferData = (bufferData != nullptr);
163 SAFE_PARCEL(output.writeBool, hasBufferData);
164 if (hasBufferData) {
165 SAFE_PARCEL(output.writeParcelable, *bufferData);
166 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800167 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800168}
169
170status_t layer_state_t::read(const Parcel& input)
171{
chaviw308ddba2020-08-11 16:23:51 -0700172 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000173 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700174 SAFE_PARCEL(input.readUint64, &what);
175 SAFE_PARCEL(input.readFloat, &x);
176 SAFE_PARCEL(input.readFloat, &y);
177 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700178 SAFE_PARCEL(input.readUint32, &layerStack.id);
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);
chaviw308ddba2020-08-11 16:23:51 -0700186
Pablo Gamito11dcc222020-09-12 15:49:39 +0000187 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
188 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
189
chaviw308ddba2020-08-11 16:23:51 -0700190 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700191 SAFE_PARCEL(input.readFloat, &tmpFloat);
192 color.r = tmpFloat;
193 SAFE_PARCEL(input.readFloat, &tmpFloat);
194 color.g = tmpFloat;
195 SAFE_PARCEL(input.readFloat, &tmpFloat);
196 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000197 SAFE_PARCEL(input.readFloat, &tmpFloat);
198 color.a = tmpFloat;
199
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);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000203 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700204 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;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000456 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700457 }
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 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000498 if (other.what & eBufferTransformChanged) {
499 what |= eBufferTransformChanged;
500 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700501 }
502 if (other.what & eTransformToDisplayInverseChanged) {
503 what |= eTransformToDisplayInverseChanged;
504 transformToDisplayInverse = other.transformToDisplayInverse;
505 }
506 if (other.what & eCropChanged) {
507 what |= eCropChanged;
508 crop = other.crop;
509 }
510 if (other.what & eBufferChanged) {
511 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500512 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700513 }
514 if (other.what & eDataspaceChanged) {
515 what |= eDataspaceChanged;
516 dataspace = other.dataspace;
517 }
518 if (other.what & eHdrMetadataChanged) {
519 what |= eHdrMetadataChanged;
520 hdrMetadata = other.hdrMetadata;
521 }
522 if (other.what & eSurfaceDamageRegionChanged) {
523 what |= eSurfaceDamageRegionChanged;
524 surfaceDamageRegion = other.surfaceDamageRegion;
525 }
526 if (other.what & eApiChanged) {
527 what |= eApiChanged;
528 api = other.api;
529 }
530 if (other.what & eSidebandStreamChanged) {
531 what |= eSidebandStreamChanged;
532 sidebandStream = other.sidebandStream;
533 }
Peiyong Lind3788632018-09-18 16:01:31 -0700534 if (other.what & eColorTransformChanged) {
535 what |= eColorTransformChanged;
536 colorTransform = other.colorTransform;
537 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700538 if (other.what & eHasListenerCallbacksChanged) {
539 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700540 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700541 if (other.what & eInputInfoChanged) {
542 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500543 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700544 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800545 if (other.what & eBackgroundColorChanged) {
546 what |= eBackgroundColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000547 color.rgb = other.color.rgb;
Valerie Haudd0b7572019-01-29 14:59:27 -0800548 bgColorAlpha = other.bgColorAlpha;
549 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800550 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800551 if (other.what & eMetadataChanged) {
552 what |= eMetadataChanged;
553 metadata.merge(other.metadata);
554 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700555 if (other.what & eShadowRadiusChanged) {
556 what |= eShadowRadiusChanged;
557 shadowRadius = other.shadowRadius;
558 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000559 if (other.what & eRenderBorderChanged) {
560 what |= eRenderBorderChanged;
561 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000562 borderWidth = other.borderWidth;
563 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000564 }
Andy Labrada096227e2022-06-15 16:58:11 +0000565 if (other.what & eDefaultFrameRateCompatibilityChanged) {
566 what |= eDefaultFrameRateCompatibilityChanged;
567 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
568 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100569 if (other.what & eFrameRateSelectionPriority) {
570 what |= eFrameRateSelectionPriority;
571 frameRateSelectionPriority = other.frameRateSelectionPriority;
572 }
Steven Thomas3172e202020-01-06 19:25:30 -0800573 if (other.what & eFrameRateChanged) {
574 what |= eFrameRateChanged;
575 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800576 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100577 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800578 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700579 if (other.what & eFixedTransformHintChanged) {
580 what |= eFixedTransformHintChanged;
581 fixedTransformHint = other.fixedTransformHint;
582 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800583 if (other.what & eAutoRefreshChanged) {
584 what |= eAutoRefreshChanged;
585 autoRefresh = other.autoRefresh;
586 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700587 if (other.what & eTrustedOverlayChanged) {
588 what |= eTrustedOverlayChanged;
589 isTrustedOverlay = other.isTrustedOverlay;
590 }
John Reckc00c6692021-02-16 11:37:33 -0500591 if (other.what & eStretchChanged) {
592 what |= eStretchChanged;
593 stretchEffect = other.stretchEffect;
594 }
chaviwf3f40fe2021-04-27 15:54:02 -0500595 if (other.what & eBufferCropChanged) {
596 what |= eBufferCropChanged;
597 bufferCrop = other.bufferCrop;
598 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700599 if (other.what & eDestinationFrameChanged) {
600 what |= eDestinationFrameChanged;
601 destinationFrame = other.destinationFrame;
602 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700603 if (other.what & eProducerDisconnect) {
604 what |= eProducerDisconnect;
605 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700606 if (other.what & eDropInputModeChanged) {
607 what |= eDropInputModeChanged;
608 dropInputMode = other.dropInputMode;
609 }
chaviw4c36cd82021-11-18 10:37:33 -0600610 if (other.what & eColorChanged) {
611 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000612 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600613 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800614 if (other.what & eColorSpaceAgnosticChanged) {
615 what |= eColorSpaceAgnosticChanged;
616 colorSpaceAgnostic = other.colorSpaceAgnostic;
617 }
Sally Qi81d95e62022-03-21 19:41:33 -0700618 if (other.what & eDimmingEnabledChanged) {
619 what |= eDimmingEnabledChanged;
620 dimmingEnabled = other.dimmingEnabled;
621 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700622 if ((other.what & what) != other.what) {
623 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700624 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
625 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700626 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700627}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700628
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700629bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500630 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700631}
632
Ady Abraham6e8e3642021-07-08 19:44:07 -0700633bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700634 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700635}
636
chaviw308ddba2020-08-11 16:23:51 -0700637status_t layer_state_t::matrix22_t::write(Parcel& output) const {
638 SAFE_PARCEL(output.writeFloat, dsdx);
639 SAFE_PARCEL(output.writeFloat, dtdx);
640 SAFE_PARCEL(output.writeFloat, dtdy);
641 SAFE_PARCEL(output.writeFloat, dsdy);
642 return NO_ERROR;
643}
644
645status_t layer_state_t::matrix22_t::read(const Parcel& input) {
646 SAFE_PARCEL(input.readFloat, &dsdx);
647 SAFE_PARCEL(input.readFloat, &dtdx);
648 SAFE_PARCEL(input.readFloat, &dtdy);
649 SAFE_PARCEL(input.readFloat, &dsdy);
650 return NO_ERROR;
651}
652
chaviw273171b2018-12-26 11:46:30 -0800653// ------------------------------- InputWindowCommands ----------------------------------------
654
Vishnu Naire798b472020-07-23 13:52:21 -0700655bool InputWindowCommands::merge(const InputWindowCommands& other) {
656 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700657 changes |= !other.focusRequests.empty();
658 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
659 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000660 changes |= !other.windowInfosReportedListeners.empty();
661 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
662 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700663 return changes;
chaviw273171b2018-12-26 11:46:30 -0800664}
665
Vishnu Nair958da932020-08-21 17:12:37 -0700666bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000667 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700668}
669
chaviw273171b2018-12-26 11:46:30 -0800670void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700671 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000672 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800673}
674
chaviw308ddba2020-08-11 16:23:51 -0700675status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700676 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000677
678 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
679 for (const auto& listener : windowInfosReportedListeners) {
680 SAFE_PARCEL(output.writeStrongBinder, listener);
681 }
682
chaviw308ddba2020-08-11 16:23:51 -0700683 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800684}
685
chaviw308ddba2020-08-11 16:23:51 -0700686status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700687 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000688
689 int listenerSize = 0;
690 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
691 windowInfosReportedListeners.reserve(listenerSize);
692 for (int i = 0; i < listenerSize; i++) {
693 sp<gui::IWindowInfosReportedListener> listener;
694 SAFE_PARCEL(input.readStrongBinder, &listener);
695 windowInfosReportedListeners.insert(listener);
696 }
697
chaviw308ddba2020-08-11 16:23:51 -0700698 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800699}
700
Marin Shalamanovc5986772021-03-16 16:09:49 +0100701bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
702 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800703 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
704 int floatClassification = std::fpclassify(frameRate);
705 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
706 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
707 return false;
708 }
709
710 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800711 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700712 (!privileged ||
713 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
714 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800715 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
716 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800717 return false;
718 }
719
Marin Shalamanovc5986772021-03-16 16:09:49 +0100720 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
721 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
722 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
723 changeFrameRateStrategy);
724 }
725
Steven Thomas62a4cf82020-01-31 12:04:03 -0800726 return true;
727}
728
chaviw618c42d2020-07-24 15:25:08 -0700729// ----------------------------------------------------------------------------
730
Huihong Luo9e84f332021-12-16 14:33:46 -0800731namespace gui {
732
733status_t CaptureArgs::writeToParcel(Parcel* output) const {
734 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
735 SAFE_PARCEL(output->write, sourceCrop);
736 SAFE_PARCEL(output->writeFloat, frameScaleX);
737 SAFE_PARCEL(output->writeFloat, frameScaleY);
738 SAFE_PARCEL(output->writeBool, captureSecureLayers);
739 SAFE_PARCEL(output->writeInt32, uid);
740 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
741 SAFE_PARCEL(output->writeBool, allowProtected);
742 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700743 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700744}
745
Huihong Luo9e84f332021-12-16 14:33:46 -0800746status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700747 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800748 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700749 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800750 SAFE_PARCEL(input->read, sourceCrop);
751 SAFE_PARCEL(input->readFloat, &frameScaleX);
752 SAFE_PARCEL(input->readFloat, &frameScaleY);
753 SAFE_PARCEL(input->readBool, &captureSecureLayers);
754 SAFE_PARCEL(input->readInt32, &uid);
755 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700756 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800757 SAFE_PARCEL(input->readBool, &allowProtected);
758 SAFE_PARCEL(input->readBool, &grayscale);
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::writeToParcel(Parcel* output) const {
763 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700764
Huihong Luo9e84f332021-12-16 14:33:46 -0800765 SAFE_PARCEL(output->writeStrongBinder, displayToken);
766 SAFE_PARCEL(output->writeUint32, width);
767 SAFE_PARCEL(output->writeUint32, height);
768 SAFE_PARCEL(output->writeBool, 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 DisplayCaptureArgs::readFromParcel(const Parcel* input) {
773 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700774
Huihong Luo9e84f332021-12-16 14:33:46 -0800775 SAFE_PARCEL(input->readStrongBinder, &displayToken);
776 SAFE_PARCEL(input->readUint32, &width);
777 SAFE_PARCEL(input->readUint32, &height);
778 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700779 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700780}
781
Huihong Luo9e84f332021-12-16 14:33:46 -0800782status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
783 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700784
Huihong Luo9e84f332021-12-16 14:33:46 -0800785 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
786 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700787 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800788 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700789 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800790 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700791 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700792}
793
Huihong Luo9e84f332021-12-16 14:33:46 -0800794status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
795 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700796
Huihong Luo9e84f332021-12-16 14:33:46 -0800797 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700798
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700799 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800800 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700801 excludeHandles.reserve(numExcludeHandles);
802 for (int i = 0; i < numExcludeHandles; i++) {
803 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800804 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700805 excludeHandles.emplace(binder);
806 }
807
Huihong Luo9e84f332021-12-16 14:33:46 -0800808 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700809 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700810}
811
Huihong Luo9e84f332021-12-16 14:33:46 -0800812}; // namespace gui
813
chaviw8dd181f2022-01-05 18:36:46 -0600814ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500815 uint64_t bufferId;
816 if (buffer) {
817 bufferId = buffer->getId();
818 } else {
819 bufferId = cachedBuffer.id;
820 }
821 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600822}
823
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800824status_t BufferData::writeToParcel(Parcel* output) const {
825 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500826
827 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800828 SAFE_PARCEL(output->writeBool, true);
829 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500830 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800831 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500832 }
833
834 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800835 SAFE_PARCEL(output->writeBool, true);
836 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500837 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800838 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500839 }
840
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800841 SAFE_PARCEL(output->writeUint64, frameNumber);
842 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
843 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500844
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800845 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
846 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800847 SAFE_PARCEL(output->writeBool, hasBarrier);
848 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500849
850 return NO_ERROR;
851}
852
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800853status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500854 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800855 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700856 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500857
858 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800859 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500860 if (tmpBool) {
861 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800862 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500863 }
864
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800865 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500866 if (tmpBool) {
867 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800868 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500869 }
870
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800871 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500872
873 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800874 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500875 if (tmpBinder) {
876 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
877 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800878 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500879
880 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800881 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500882 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800883 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500884
Robert Carr79dc06a2022-02-22 15:28:59 -0800885 SAFE_PARCEL(input->readBool, &hasBarrier);
886 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
887
chaviwba4320c2021-09-15 15:20:53 -0500888 return NO_ERROR;
889}
890
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800891}; // namespace android