blob: 0d3b412842ded35ad9e7b5897860234a4b0aaa8d [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Vishnu Nair217d8e62018-09-12 16:34:49 -070017#define LOG_TAG "LayerState"
18
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070019#include <cinttypes>
20#include <cmath>
Garfield Tan8a3083e2018-12-03 13:21:07 -080021
Huihong Luod3d8f8e2022-03-08 14:48:46 -080022#include <android/gui/ISurfaceComposerClient.h>
Marin Shalamanovc5986772021-03-16 16:09:49 +010023#include <android/native_window.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/Parcel.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080025#include <gui/IGraphicBufferProducer.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070026#include <gui/LayerState.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010027#include <private/gui/ParcelUtils.h>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070028#include <system/window.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000029#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030
31namespace android {
32
chaviw98318de2021-05-19 16:45:23 -050033using gui::FocusRequest;
34using gui::WindowInfoHandle;
35
Pablo Gamito11dcc222020-09-12 15:49:39 +000036layer_state_t::layer_state_t()
Vishnu Nair685cfef2022-02-02 10:01:25 -080037 : surface(nullptr),
38 layerId(-1),
39 what(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000040 x(0),
41 y(0),
42 z(0),
43 w(0),
44 h(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000045 alpha(0),
46 flags(0),
47 mask(0),
48 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000049 cornerRadius(0.0f),
50 backgroundBlurRadius(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000051 transform(0),
52 transformToDisplayInverse(false),
53 crop(Rect::INVALID_RECT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000054 dataspace(ui::Dataspace::UNKNOWN),
55 surfaceDamageRegion(),
56 api(-1),
57 colorTransform(mat4()),
58 bgColorAlpha(0),
59 bgColorDataspace(ui::Dataspace::UNKNOWN),
60 colorSpaceAgnostic(false),
61 shadowRadius(0.0f),
62 frameRateSelectionPriority(-1),
63 frameRate(0.0f),
64 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010065 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Pablo Gamito11dcc222020-09-12 15:49:39 +000066 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080067 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070068 isTrustedOverlay(false),
Tianhao Yao67dd7122022-02-22 17:48:33 +000069 borderEnabled(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070070 bufferCrop(Rect::INVALID_RECT),
71 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070072 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000073 matrix.dsdx = matrix.dtdy = 1.0f;
74 matrix.dsdy = matrix.dtdx = 0.0f;
75 hdrMetadata.validTypes = 0;
76}
77
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078status_t layer_state_t::write(Parcel& output) const
79{
chaviw308ddba2020-08-11 16:23:51 -070080 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +000081 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -070082 SAFE_PARCEL(output.writeUint64, what);
83 SAFE_PARCEL(output.writeFloat, x);
84 SAFE_PARCEL(output.writeFloat, y);
85 SAFE_PARCEL(output.writeInt32, z);
86 SAFE_PARCEL(output.writeUint32, w);
87 SAFE_PARCEL(output.writeUint32, h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -070088 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -070089 SAFE_PARCEL(output.writeFloat, alpha);
90 SAFE_PARCEL(output.writeUint32, flags);
91 SAFE_PARCEL(output.writeUint32, mask);
92 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080093 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000094 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
Pablo Gamito11dcc222020-09-12 15:49:39 +000095 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
96 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070097 SAFE_PARCEL(output.writeFloat, color.r);
98 SAFE_PARCEL(output.writeFloat, color.g);
99 SAFE_PARCEL(output.writeFloat, color.b);
chaviw98318de2021-05-19 16:45:23 -0500100 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700101 SAFE_PARCEL(output.write, transparentRegion);
102 SAFE_PARCEL(output.writeUint32, transform);
103 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000104 SAFE_PARCEL(output.writeBool, borderEnabled);
chaviw308ddba2020-08-11 16:23:51 -0700105 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
106 SAFE_PARCEL(output.write, hdrMetadata);
107 SAFE_PARCEL(output.write, surfaceDamageRegion);
108 SAFE_PARCEL(output.writeInt32, api);
109
Marissa Wall61c58622018-07-18 10:12:20 -0700110 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700111 SAFE_PARCEL(output.writeBool, true);
112 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700113 } else {
chaviw308ddba2020-08-11 16:23:51 -0700114 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700115 }
116
chaviw308ddba2020-08-11 16:23:51 -0700117 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
118 SAFE_PARCEL(output.writeFloat, cornerRadius);
119 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700120 SAFE_PARCEL(output.writeParcelable, metadata);
121 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
122 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
123 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
124 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700125
126 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700127 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700128 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700129 }
chaviw308ddba2020-08-11 16:23:51 -0700130 SAFE_PARCEL(output.writeFloat, shadowRadius);
131 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
132 SAFE_PARCEL(output.writeFloat, frameRate);
133 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100134 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700135 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800136 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700137 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700138
139 SAFE_PARCEL(output.writeUint32, blurRegions.size());
140 for (auto region : blurRegions) {
141 SAFE_PARCEL(output.writeUint32, region.blurRadius);
142 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
143 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
144 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
145 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
146 SAFE_PARCEL(output.writeFloat, region.alpha);
147 SAFE_PARCEL(output.writeInt32, region.left);
148 SAFE_PARCEL(output.writeInt32, region.top);
149 SAFE_PARCEL(output.writeInt32, region.right);
150 SAFE_PARCEL(output.writeInt32, region.bottom);
151 }
John Reckcdb4ed72021-02-04 13:39:33 -0500152
153 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500154 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700155 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700156 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500157
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700158 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800159
160 const bool hasBufferData = (bufferData != nullptr);
161 SAFE_PARCEL(output.writeBool, hasBufferData);
162 if (hasBufferData) {
163 SAFE_PARCEL(output.writeParcelable, *bufferData);
164 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800165 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166}
167
168status_t layer_state_t::read(const Parcel& input)
169{
chaviw308ddba2020-08-11 16:23:51 -0700170 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000171 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700172 SAFE_PARCEL(input.readUint64, &what);
173 SAFE_PARCEL(input.readFloat, &x);
174 SAFE_PARCEL(input.readFloat, &y);
175 SAFE_PARCEL(input.readInt32, &z);
176 SAFE_PARCEL(input.readUint32, &w);
177 SAFE_PARCEL(input.readUint32, &h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700178 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700179 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700180
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800181 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700182
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800183 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700184
185 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800186 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000187 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700188
Pablo Gamito11dcc222020-09-12 15:49:39 +0000189 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
190 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
191
chaviw308ddba2020-08-11 16:23:51 -0700192 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700193 SAFE_PARCEL(input.readFloat, &tmpFloat);
194 color.r = tmpFloat;
195 SAFE_PARCEL(input.readFloat, &tmpFloat);
196 color.g = tmpFloat;
197 SAFE_PARCEL(input.readFloat, &tmpFloat);
198 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500199 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700200
chaviw308ddba2020-08-11 16:23:51 -0700201 SAFE_PARCEL(input.read, transparentRegion);
202 SAFE_PARCEL(input.readUint32, &transform);
203 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000204 SAFE_PARCEL(input.readBool, &borderEnabled);
chaviw308ddba2020-08-11 16:23:51 -0700205
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800206 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700207 SAFE_PARCEL(input.readUint32, &tmpUint32);
208 dataspace = static_cast<ui::Dataspace>(tmpUint32);
209
210 SAFE_PARCEL(input.read, hdrMetadata);
211 SAFE_PARCEL(input.read, surfaceDamageRegion);
212 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500213
214 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700215 SAFE_PARCEL(input.readBool, &tmpBool);
216 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700217 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
218 }
219
chaviw308ddba2020-08-11 16:23:51 -0700220 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
221 SAFE_PARCEL(input.readFloat, &cornerRadius);
222 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700223 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800224
chaviw308ddba2020-08-11 16:23:51 -0700225 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
226 SAFE_PARCEL(input.readUint32, &tmpUint32);
227 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
228 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800229
chaviw308ddba2020-08-11 16:23:51 -0700230 int32_t numListeners = 0;
231 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700232 listeners.clear();
233 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700234 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700235 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700236 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700237 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700238 listeners.emplace_back(listener, callbackIds);
239 }
chaviw308ddba2020-08-11 16:23:51 -0700240 SAFE_PARCEL(input.readFloat, &shadowRadius);
241 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
242 SAFE_PARCEL(input.readFloat, &frameRate);
243 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100244 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700245 SAFE_PARCEL(input.readUint32, &tmpUint32);
246 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800247 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700248 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700249
250 uint32_t numRegions = 0;
251 SAFE_PARCEL(input.readUint32, &numRegions);
252 blurRegions.clear();
253 for (uint32_t i = 0; i < numRegions; i++) {
254 BlurRegion region;
255 SAFE_PARCEL(input.readUint32, &region.blurRadius);
256 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
257 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
258 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
259 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
260 SAFE_PARCEL(input.readFloat, &region.alpha);
261 SAFE_PARCEL(input.readInt32, &region.left);
262 SAFE_PARCEL(input.readInt32, &region.top);
263 SAFE_PARCEL(input.readInt32, &region.right);
264 SAFE_PARCEL(input.readInt32, &region.bottom);
265 blurRegions.push_back(region);
266 }
John Reckcdb4ed72021-02-04 13:39:33 -0500267
268 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500269 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700270 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700271 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500272
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700273 uint32_t mode;
274 SAFE_PARCEL(input.readUint32, &mode);
275 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800276
277 bool hasBufferData;
278 SAFE_PARCEL(input.readBool, &hasBufferData);
279 if (hasBufferData) {
280 bufferData = std::make_shared<BufferData>();
281 SAFE_PARCEL(input.readParcelable, bufferData.get());
282 } else {
283 bufferData = nullptr;
284 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800285 return NO_ERROR;
286}
287
Mathias Agopian698c0872011-06-28 19:09:31 -0700288status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700289 return state.write(output);
290}
291
292status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700293 return state.read(input);
294}
295
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700296DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700297
Mathias Agopian8b33f032012-07-24 20:43:54 -0700298status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700299 SAFE_PARCEL(output.writeStrongBinder, token);
300 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
301 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700302 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700303 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700304 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
305 SAFE_PARCEL(output.write, layerStackSpaceRect);
306 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
307 SAFE_PARCEL(output.writeUint32, width);
308 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700309 return NO_ERROR;
310}
311
312status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700313 SAFE_PARCEL(input.readStrongBinder, &token);
314 sp<IBinder> tmpBinder;
315 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
316 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
317
318 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700319 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700320 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700321 uint32_t tmpUint = 0;
322 SAFE_PARCEL(input.readUint32, &tmpUint);
323 orientation = ui::toRotation(tmpUint);
324
325 SAFE_PARCEL(input.read, layerStackSpaceRect);
326 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
327 SAFE_PARCEL(input.readUint32, &width);
328 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700329 return NO_ERROR;
330}
331
Robert Carr2c5f6d22017-09-26 12:30:35 -0700332void DisplayState::merge(const DisplayState& other) {
333 if (other.what & eSurfaceChanged) {
334 what |= eSurfaceChanged;
335 surface = other.surface;
336 }
337 if (other.what & eLayerStackChanged) {
338 what |= eLayerStackChanged;
339 layerStack = other.layerStack;
340 }
Evan Rosky2239b372021-05-20 13:43:47 -0700341 if (other.what & eFlagsChanged) {
342 what |= eFlagsChanged;
343 flags = other.flags;
344 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700345 if (other.what & eDisplayProjectionChanged) {
346 what |= eDisplayProjectionChanged;
347 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200348 layerStackSpaceRect = other.layerStackSpaceRect;
349 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700350 }
351 if (other.what & eDisplaySizeChanged) {
352 what |= eDisplaySizeChanged;
353 width = other.width;
354 height = other.height;
355 }
356}
357
Robert Carrde6d7b42022-01-07 18:23:06 -0800358void layer_state_t::sanitize(int32_t permissions) {
359 // TODO: b/109894387
360 //
361 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
362 // rotation. To see the problem observe that if we have a square parent, and a child
363 // of the same size, then we rotate the child 45 degrees around its center, the child
364 // must now be cropped to a non rectangular 8 sided region.
365 //
366 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
367 // private API, and arbitrary rotation is used in limited use cases, for instance:
368 // - WindowManager only uses rotation in one case, which is on a top level layer in which
369 // cropping is not an issue.
370 // - Launcher, as a privileged app, uses this to transition an application to PiP
371 // (picture-in-picture) mode.
372 //
373 // However given that abuse of rotation matrices could lead to surfaces extending outside
374 // of cropped areas, we need to prevent non-root clients without permission
375 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
376 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
377 // preserving transformations.
378 if (what & eMatrixChanged) {
379 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
380 ui::Transform t;
381 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
382 if (!t.preserveRects()) {
383 what &= ~eMatrixChanged;
384 ALOGE("Stripped non rect preserving matrix in sanitize");
385 }
386 }
387 }
388
389 if (what & eFlagsChanged) {
390 if ((flags & eLayerIsDisplayDecoration) &&
391 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
392 flags &= ~eLayerIsDisplayDecoration;
393 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
394 }
395 }
396
397 if (what & layer_state_t::eInputInfoChanged) {
398 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
399 what &= ~eInputInfoChanged;
400 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
401 }
402 }
403 if (what & layer_state_t::eTrustedOverlayChanged) {
404 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
405 what &= ~eTrustedOverlayChanged;
406 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
407 }
408 }
409 if (what & layer_state_t::eDropInputModeChanged) {
410 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
411 what &= ~eDropInputModeChanged;
412 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
413 }
414 }
415 if (what & layer_state_t::eFrameRateSelectionPriority) {
416 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
417 what &= ~eFrameRateSelectionPriority;
418 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
419 }
420 }
421 if (what & layer_state_t::eFrameRateChanged) {
422 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
423 changeFrameRateStrategy,
424 "layer_state_t::sanitize",
425 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
426 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
427 }
428 }
429}
430
Robert Carr2c5f6d22017-09-26 12:30:35 -0700431void layer_state_t::merge(const layer_state_t& other) {
432 if (other.what & ePositionChanged) {
433 what |= ePositionChanged;
434 x = other.x;
435 y = other.y;
436 }
437 if (other.what & eLayerChanged) {
438 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700439 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700440 z = other.z;
441 }
442 if (other.what & eSizeChanged) {
443 what |= eSizeChanged;
444 w = other.w;
445 h = other.h;
446 }
447 if (other.what & eAlphaChanged) {
448 what |= eAlphaChanged;
449 alpha = other.alpha;
450 }
451 if (other.what & eMatrixChanged) {
452 what |= eMatrixChanged;
453 matrix = other.matrix;
454 }
455 if (other.what & eTransparentRegionChanged) {
456 what |= eTransparentRegionChanged;
457 transparentRegion = other.transparentRegion;
458 }
459 if (other.what & eFlagsChanged) {
460 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700461 flags &= ~other.mask;
462 flags |= (other.flags & other.mask);
463 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700464 }
465 if (other.what & eLayerStackChanged) {
466 what |= eLayerStackChanged;
467 layerStack = other.layerStack;
468 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700469 if (other.what & eCornerRadiusChanged) {
470 what |= eCornerRadiusChanged;
471 cornerRadius = other.cornerRadius;
472 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800473 if (other.what & eBackgroundBlurRadiusChanged) {
474 what |= eBackgroundBlurRadiusChanged;
475 backgroundBlurRadius = other.backgroundBlurRadius;
476 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700477 if (other.what & eBlurRegionsChanged) {
478 what |= eBlurRegionsChanged;
479 blurRegions = other.blurRegions;
480 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700481 if (other.what & eRelativeLayerChanged) {
482 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700483 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700484 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000485 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700486 }
487 if (other.what & eReparent) {
488 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000489 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700490 }
chaviwca27f252018-02-06 16:46:39 -0800491 if (other.what & eDestroySurface) {
492 what |= eDestroySurface;
493 }
Marissa Wall61c58622018-07-18 10:12:20 -0700494 if (other.what & eTransformChanged) {
495 what |= eTransformChanged;
496 transform = other.transform;
497 }
498 if (other.what & eTransformToDisplayInverseChanged) {
499 what |= eTransformToDisplayInverseChanged;
500 transformToDisplayInverse = other.transformToDisplayInverse;
501 }
502 if (other.what & eCropChanged) {
503 what |= eCropChanged;
504 crop = other.crop;
505 }
506 if (other.what & eBufferChanged) {
507 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500508 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700509 }
510 if (other.what & eDataspaceChanged) {
511 what |= eDataspaceChanged;
512 dataspace = other.dataspace;
513 }
514 if (other.what & eHdrMetadataChanged) {
515 what |= eHdrMetadataChanged;
516 hdrMetadata = other.hdrMetadata;
517 }
518 if (other.what & eSurfaceDamageRegionChanged) {
519 what |= eSurfaceDamageRegionChanged;
520 surfaceDamageRegion = other.surfaceDamageRegion;
521 }
522 if (other.what & eApiChanged) {
523 what |= eApiChanged;
524 api = other.api;
525 }
526 if (other.what & eSidebandStreamChanged) {
527 what |= eSidebandStreamChanged;
528 sidebandStream = other.sidebandStream;
529 }
Peiyong Lind3788632018-09-18 16:01:31 -0700530 if (other.what & eColorTransformChanged) {
531 what |= eColorTransformChanged;
532 colorTransform = other.colorTransform;
533 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700534 if (other.what & eHasListenerCallbacksChanged) {
535 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700536 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700537 if (other.what & eInputInfoChanged) {
538 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500539 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700540 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800541 if (other.what & eBackgroundColorChanged) {
542 what |= eBackgroundColorChanged;
543 color = other.color;
544 bgColorAlpha = other.bgColorAlpha;
545 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800546 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800547 if (other.what & eMetadataChanged) {
548 what |= eMetadataChanged;
549 metadata.merge(other.metadata);
550 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700551 if (other.what & eShadowRadiusChanged) {
552 what |= eShadowRadiusChanged;
553 shadowRadius = other.shadowRadius;
554 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000555 if (other.what & eRenderBorderChanged) {
556 what |= eRenderBorderChanged;
557 borderEnabled = other.borderEnabled;
558 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100559 if (other.what & eFrameRateSelectionPriority) {
560 what |= eFrameRateSelectionPriority;
561 frameRateSelectionPriority = other.frameRateSelectionPriority;
562 }
Steven Thomas3172e202020-01-06 19:25:30 -0800563 if (other.what & eFrameRateChanged) {
564 what |= eFrameRateChanged;
565 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800566 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100567 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800568 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700569 if (other.what & eFixedTransformHintChanged) {
570 what |= eFixedTransformHintChanged;
571 fixedTransformHint = other.fixedTransformHint;
572 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800573 if (other.what & eAutoRefreshChanged) {
574 what |= eAutoRefreshChanged;
575 autoRefresh = other.autoRefresh;
576 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700577 if (other.what & eTrustedOverlayChanged) {
578 what |= eTrustedOverlayChanged;
579 isTrustedOverlay = other.isTrustedOverlay;
580 }
John Reckc00c6692021-02-16 11:37:33 -0500581 if (other.what & eStretchChanged) {
582 what |= eStretchChanged;
583 stretchEffect = other.stretchEffect;
584 }
chaviwf3f40fe2021-04-27 15:54:02 -0500585 if (other.what & eBufferCropChanged) {
586 what |= eBufferCropChanged;
587 bufferCrop = other.bufferCrop;
588 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700589 if (other.what & eDestinationFrameChanged) {
590 what |= eDestinationFrameChanged;
591 destinationFrame = other.destinationFrame;
592 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700593 if (other.what & eProducerDisconnect) {
594 what |= eProducerDisconnect;
595 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700596 if (other.what & eDropInputModeChanged) {
597 what |= eDropInputModeChanged;
598 dropInputMode = other.dropInputMode;
599 }
chaviw4c36cd82021-11-18 10:37:33 -0600600 if (other.what & eColorChanged) {
601 what |= eColorChanged;
602 color = other.color;
603 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800604 if (other.what & eColorSpaceAgnosticChanged) {
605 what |= eColorSpaceAgnosticChanged;
606 colorSpaceAgnostic = other.colorSpaceAgnostic;
607 }
Sally Qi81d95e62022-03-21 19:41:33 -0700608 if (other.what & eDimmingEnabledChanged) {
609 what |= eDimmingEnabledChanged;
610 dimmingEnabled = other.dimmingEnabled;
611 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700612 if ((other.what & what) != other.what) {
613 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700614 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
615 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700616 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700617}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700618
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700619bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500620 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700621}
622
Ady Abraham6e8e3642021-07-08 19:44:07 -0700623bool layer_state_t::hasValidBuffer() const {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800624 return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700625}
626
chaviw308ddba2020-08-11 16:23:51 -0700627status_t layer_state_t::matrix22_t::write(Parcel& output) const {
628 SAFE_PARCEL(output.writeFloat, dsdx);
629 SAFE_PARCEL(output.writeFloat, dtdx);
630 SAFE_PARCEL(output.writeFloat, dtdy);
631 SAFE_PARCEL(output.writeFloat, dsdy);
632 return NO_ERROR;
633}
634
635status_t layer_state_t::matrix22_t::read(const Parcel& input) {
636 SAFE_PARCEL(input.readFloat, &dsdx);
637 SAFE_PARCEL(input.readFloat, &dtdx);
638 SAFE_PARCEL(input.readFloat, &dtdy);
639 SAFE_PARCEL(input.readFloat, &dsdy);
640 return NO_ERROR;
641}
642
chaviw273171b2018-12-26 11:46:30 -0800643// ------------------------------- InputWindowCommands ----------------------------------------
644
Vishnu Naire798b472020-07-23 13:52:21 -0700645bool InputWindowCommands::merge(const InputWindowCommands& other) {
646 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700647 changes |= !other.focusRequests.empty();
648 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
649 std::make_move_iterator(other.focusRequests.end()));
Vishnu Naire798b472020-07-23 13:52:21 -0700650 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800651 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700652 return changes;
chaviw273171b2018-12-26 11:46:30 -0800653}
654
Vishnu Nair958da932020-08-21 17:12:37 -0700655bool InputWindowCommands::empty() const {
Vishnu Nair03ccbd62021-12-01 17:21:16 -0800656 return focusRequests.empty() && !syncInputWindows;
Vishnu Nair958da932020-08-21 17:12:37 -0700657}
658
chaviw273171b2018-12-26 11:46:30 -0800659void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700660 focusRequests.clear();
chaviwa911b102019-02-14 10:18:33 -0800661 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800662}
663
chaviw308ddba2020-08-11 16:23:51 -0700664status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700665 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700666 SAFE_PARCEL(output.writeBool, syncInputWindows);
667 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800668}
669
chaviw308ddba2020-08-11 16:23:51 -0700670status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700671 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700672 SAFE_PARCEL(input.readBool, &syncInputWindows);
673 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800674}
675
Marin Shalamanovc5986772021-03-16 16:09:49 +0100676bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
677 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800678 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
679 int floatClassification = std::fpclassify(frameRate);
680 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
681 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
682 return false;
683 }
684
685 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800686 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700687 (!privileged ||
688 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
689 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800690 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
691 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800692 return false;
693 }
694
Marin Shalamanovc5986772021-03-16 16:09:49 +0100695 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
696 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
697 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
698 changeFrameRateStrategy);
699 }
700
Steven Thomas62a4cf82020-01-31 12:04:03 -0800701 return true;
702}
703
chaviw618c42d2020-07-24 15:25:08 -0700704// ----------------------------------------------------------------------------
705
Huihong Luo9e84f332021-12-16 14:33:46 -0800706namespace gui {
707
708status_t CaptureArgs::writeToParcel(Parcel* output) const {
709 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
710 SAFE_PARCEL(output->write, sourceCrop);
711 SAFE_PARCEL(output->writeFloat, frameScaleX);
712 SAFE_PARCEL(output->writeFloat, frameScaleY);
713 SAFE_PARCEL(output->writeBool, captureSecureLayers);
714 SAFE_PARCEL(output->writeInt32, uid);
715 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
716 SAFE_PARCEL(output->writeBool, allowProtected);
717 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700718 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700719}
720
Huihong Luo9e84f332021-12-16 14:33:46 -0800721status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700722 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800723 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700724 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800725 SAFE_PARCEL(input->read, sourceCrop);
726 SAFE_PARCEL(input->readFloat, &frameScaleX);
727 SAFE_PARCEL(input->readFloat, &frameScaleY);
728 SAFE_PARCEL(input->readBool, &captureSecureLayers);
729 SAFE_PARCEL(input->readInt32, &uid);
730 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700731 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800732 SAFE_PARCEL(input->readBool, &allowProtected);
733 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700734 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700735}
736
Huihong Luo9e84f332021-12-16 14:33:46 -0800737status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
738 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700739
Huihong Luo9e84f332021-12-16 14:33:46 -0800740 SAFE_PARCEL(output->writeStrongBinder, displayToken);
741 SAFE_PARCEL(output->writeUint32, width);
742 SAFE_PARCEL(output->writeUint32, height);
743 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700744 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700745}
746
Huihong Luo9e84f332021-12-16 14:33:46 -0800747status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
748 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700749
Huihong Luo9e84f332021-12-16 14:33:46 -0800750 SAFE_PARCEL(input->readStrongBinder, &displayToken);
751 SAFE_PARCEL(input->readUint32, &width);
752 SAFE_PARCEL(input->readUint32, &height);
753 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700754 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700755}
756
Huihong Luo9e84f332021-12-16 14:33:46 -0800757status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
758 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700759
Huihong Luo9e84f332021-12-16 14:33:46 -0800760 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
761 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700762 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800763 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700764 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800765 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700766 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700767}
768
Huihong Luo9e84f332021-12-16 14:33:46 -0800769status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
770 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700771
Huihong Luo9e84f332021-12-16 14:33:46 -0800772 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700773
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700774 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800775 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700776 excludeHandles.reserve(numExcludeHandles);
777 for (int i = 0; i < numExcludeHandles; i++) {
778 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800779 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700780 excludeHandles.emplace(binder);
781 }
782
Huihong Luo9e84f332021-12-16 14:33:46 -0800783 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700784 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700785}
786
Huihong Luo9e84f332021-12-16 14:33:46 -0800787}; // namespace gui
788
chaviw8dd181f2022-01-05 18:36:46 -0600789ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500790 uint64_t bufferId;
791 if (buffer) {
792 bufferId = buffer->getId();
793 } else {
794 bufferId = cachedBuffer.id;
795 }
796 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600797}
798
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800799status_t BufferData::writeToParcel(Parcel* output) const {
800 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500801
802 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800803 SAFE_PARCEL(output->writeBool, true);
804 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500805 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800806 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500807 }
808
809 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800810 SAFE_PARCEL(output->writeBool, true);
811 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500812 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800813 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500814 }
815
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800816 SAFE_PARCEL(output->writeUint64, frameNumber);
817 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
818 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500819
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800820 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
821 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800822 SAFE_PARCEL(output->writeBool, hasBarrier);
823 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500824
825 return NO_ERROR;
826}
827
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800828status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500829 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800830 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700831 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500832
833 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800834 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500835 if (tmpBool) {
836 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800837 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500838 }
839
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800840 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500841 if (tmpBool) {
842 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800843 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500844 }
845
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800846 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500847
848 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800849 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500850 if (tmpBinder) {
851 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
852 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800853 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500854
855 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800856 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500857 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800858 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500859
Robert Carr79dc06a2022-02-22 15:28:59 -0800860 SAFE_PARCEL(input->readBool, &hasBarrier);
861 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
862
chaviwba4320c2021-09-15 15:20:53 -0500863 return NO_ERROR;
864}
865
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800866}; // namespace android