blob: 86bc97e9d367bdd4db5c87cd3faeb2ad612c4797 [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>
Garfield Tan8a3083e2018-12-03 13:21:07 -080020
Huihong Luod3d8f8e2022-03-08 14:48:46 -080021#include <android/gui/ISurfaceComposerClient.h>
Marin Shalamanovc5986772021-03-16 16:09:49 +010022#include <android/native_window.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Brian Lindahl07dcd492024-10-30 11:43:23 -060024#include <com_android_graphics_libgui_flags.h>
Ady Abraham6cdd3fd2023-09-07 18:45:58 -070025#include <gui/FrameRateUtils.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080026#include <gui/IGraphicBufferProducer.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070027#include <gui/LayerState.h>
Vishnu Nairaa799bd2022-11-16 23:09:09 +000028#include <gui/SurfaceControl.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010029#include <private/gui/ParcelUtils.h>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070030#include <system/window.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000031#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032
Vishnu Nairaa799bd2022-11-16 23:09:09 +000033#define CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD) \
34 { \
35 if ((OTHER.what & CHANGE_FLAG) && (FIELD != OTHER.FIELD)) { \
36 DIFF_RESULT |= CHANGE_FLAG; \
37 } \
38 }
39
40#define CHECK_DIFF2(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2) \
41 { \
42 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1) \
43 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2) \
44 }
45
46#define CHECK_DIFF3(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2, FIELD3) \
47 { \
48 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1) \
49 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2) \
50 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD3) \
51 }
52
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053namespace android {
54
chaviw98318de2021-05-19 16:45:23 -050055using gui::FocusRequest;
56using gui::WindowInfoHandle;
57
Anton Ivanovc7f87932025-02-25 00:58:09 -080058namespace {
59bool isSameWindowHandle(const sp<WindowInfoHandle>& lhs, const sp<WindowInfoHandle>& rhs) {
60 if (lhs == rhs) {
61 return true;
62 }
63
64 if (!lhs || !rhs) {
65 return false;
66 }
67
68 return *lhs->getInfo() == *rhs->getInfo();
69};
70
71bool isSameSurfaceControl(const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs) {
72 if (lhs == rhs) {
73 return true;
74 }
75
76 return SurfaceControl::isSameSurface(lhs, rhs);
77};
78} // namespace
79
Pablo Gamito11dcc222020-09-12 15:49:39 +000080layer_state_t::layer_state_t()
Vishnu Nair685cfef2022-02-02 10:01:25 -080081 : surface(nullptr),
82 layerId(-1),
83 what(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000084 x(0),
85 y(0),
86 z(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000087 flags(0),
88 mask(0),
89 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000090 cornerRadius(0.0f),
Surbhi Kadam9674ffa2024-11-14 23:06:27 +000091 clientDrawnCornerRadius(0.0f),
Pablo Gamito11dcc222020-09-12 15:49:39 +000092 backgroundBlurRadius(0),
Vishnu Nairbbceb462022-10-10 04:52:13 +000093 color(0),
94 bufferTransform(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000095 transformToDisplayInverse(false),
Vishnu Naira9123c82024-10-03 03:56:44 +000096 crop({0, 0, -1, -1}),
Pablo Gamito11dcc222020-09-12 15:49:39 +000097 dataspace(ui::Dataspace::UNKNOWN),
Pablo Gamito11dcc222020-09-12 15:49:39 +000098 api(-1),
99 colorTransform(mat4()),
Vishnu Naird47bcee2023-02-24 18:08:51 +0000100 bgColor(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +0000101 bgColorDataspace(ui::Dataspace::UNKNOWN),
102 colorSpaceAgnostic(false),
103 shadowRadius(0.0f),
104 frameRateSelectionPriority(-1),
105 frameRate(0.0f),
106 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +0100107 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Andy Labrada096227e2022-06-15 16:58:11 +0000108 defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Rachel Leece6e0042023-06-27 11:22:54 -0700109 frameRateCategory(ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT),
Rachel Lee67afbea2023-09-28 15:35:07 -0700110 frameRateCategorySmoothSwitchOnly(false),
Rachel Lee70f7b692023-11-22 11:24:02 -0800111 frameRateSelectionStrategy(ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_PROPAGATE),
Pablo Gamito11dcc222020-09-12 15:49:39 +0000112 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -0800113 autoRefresh(false),
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000114 trustedOverlay(gui::TrustedOverlay::UNSET),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700115 bufferCrop(Rect::INVALID_RECT),
116 destinationFrame(Rect::INVALID_RECT),
Brian Lindahl07dcd492024-10-30 11:43:23 -0600117 dropInputMode(gui::DropInputMode::NONE),
118 pictureProfileHandle(PictureProfileHandle::NONE),
119 appContentPriority(0) {
Pablo Gamito11dcc222020-09-12 15:49:39 +0000120 matrix.dsdx = matrix.dtdy = 1.0f;
121 matrix.dsdy = matrix.dtdx = 0.0f;
122 hdrMetadata.validTypes = 0;
123}
124
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125status_t layer_state_t::write(Parcel& output) const
126{
chaviw308ddba2020-08-11 16:23:51 -0700127 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000128 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -0700129 SAFE_PARCEL(output.writeUint64, what);
130 SAFE_PARCEL(output.writeFloat, x);
131 SAFE_PARCEL(output.writeFloat, y);
132 SAFE_PARCEL(output.writeInt32, z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700133 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700134 SAFE_PARCEL(output.writeUint32, flags);
135 SAFE_PARCEL(output.writeUint32, mask);
136 SAFE_PARCEL(matrix.write, output);
Vishnu Naira9123c82024-10-03 03:56:44 +0000137 SAFE_PARCEL(output.writeFloat, crop.top);
138 SAFE_PARCEL(output.writeFloat, crop.left);
139 SAFE_PARCEL(output.writeFloat, crop.bottom);
140 SAFE_PARCEL(output.writeFloat, crop.right);
Anton Ivanovc7f87932025-02-25 00:58:09 -0800141 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output,
142 mNotDefCmpState.relativeLayerSurfaceControl);
143 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output,
144 mNotDefCmpState.parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -0700145 SAFE_PARCEL(output.writeFloat, color.r);
146 SAFE_PARCEL(output.writeFloat, color.g);
147 SAFE_PARCEL(output.writeFloat, color.b);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000148 SAFE_PARCEL(output.writeFloat, color.a);
Anton Ivanovc7f87932025-02-25 00:58:09 -0800149 SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->writeToParcel, &output);
150 SAFE_PARCEL(output.write, mNotDefCmpState.transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000151 SAFE_PARCEL(output.writeUint32, bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700152 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700153 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
154 SAFE_PARCEL(output.write, hdrMetadata);
Anton Ivanovc7f87932025-02-25 00:58:09 -0800155 SAFE_PARCEL(output.write, mNotDefCmpState.surfaceDamageRegion);
chaviw308ddba2020-08-11 16:23:51 -0700156 SAFE_PARCEL(output.writeInt32, api);
157
Marissa Wall61c58622018-07-18 10:12:20 -0700158 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700159 SAFE_PARCEL(output.writeBool, true);
160 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700161 } else {
chaviw308ddba2020-08-11 16:23:51 -0700162 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700163 }
164
chaviw308ddba2020-08-11 16:23:51 -0700165 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
166 SAFE_PARCEL(output.writeFloat, cornerRadius);
Surbhi Kadam9674ffa2024-11-14 23:06:27 +0000167 SAFE_PARCEL(output.writeFloat, clientDrawnCornerRadius);
chaviw308ddba2020-08-11 16:23:51 -0700168 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700169 SAFE_PARCEL(output.writeParcelable, metadata);
Vishnu Naird47bcee2023-02-24 18:08:51 +0000170 SAFE_PARCEL(output.writeFloat, bgColor.r);
171 SAFE_PARCEL(output.writeFloat, bgColor.g);
172 SAFE_PARCEL(output.writeFloat, bgColor.b);
173 SAFE_PARCEL(output.writeFloat, bgColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700174 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
175 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
176 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700177
178 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700179 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700180 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700181 }
chaviw308ddba2020-08-11 16:23:51 -0700182 SAFE_PARCEL(output.writeFloat, shadowRadius);
YCairn Overturf65fb1c62025-02-24 22:57:09 +0000183 SAFE_PARCEL(output.writeParcelable, borderSettings);
chaviw308ddba2020-08-11 16:23:51 -0700184 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
185 SAFE_PARCEL(output.writeFloat, frameRate);
186 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100187 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000188 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700189 SAFE_PARCEL(output.writeByte, frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700190 SAFE_PARCEL(output.writeBool, frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700191 SAFE_PARCEL(output.writeByte, frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700192 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800193 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700194 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700195
196 SAFE_PARCEL(output.writeUint32, blurRegions.size());
197 for (auto region : blurRegions) {
198 SAFE_PARCEL(output.writeUint32, region.blurRadius);
199 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
200 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
201 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
202 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
203 SAFE_PARCEL(output.writeFloat, region.alpha);
204 SAFE_PARCEL(output.writeInt32, region.left);
205 SAFE_PARCEL(output.writeInt32, region.top);
206 SAFE_PARCEL(output.writeInt32, region.right);
207 SAFE_PARCEL(output.writeInt32, region.bottom);
208 }
John Reckcdb4ed72021-02-04 13:39:33 -0500209
210 SAFE_PARCEL(output.write, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000211 SAFE_PARCEL(output.writeParcelable, edgeExtensionParameters);
chaviwf3f40fe2021-04-27 15:54:02 -0500212 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700213 SAFE_PARCEL(output.write, destinationFrame);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000214 SAFE_PARCEL(output.writeInt32, static_cast<uint32_t>(trustedOverlay));
John Reckcdb4ed72021-02-04 13:39:33 -0500215
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700216 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800217
218 const bool hasBufferData = (bufferData != nullptr);
219 SAFE_PARCEL(output.writeBool, hasBufferData);
220 if (hasBufferData) {
221 SAFE_PARCEL(output.writeParcelable, *bufferData);
222 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000223 SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds);
224 SAFE_PARCEL(output.writeParcelable, trustedPresentationListener);
Sally Qi963049b2023-03-23 14:06:21 -0700225 SAFE_PARCEL(output.writeFloat, currentHdrSdrRatio);
226 SAFE_PARCEL(output.writeFloat, desiredHdrSdrRatio);
Vishnu Nair59a6be32024-01-29 10:26:21 -0800227 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(cachingHint));
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500228
229 const bool hasBufferReleaseChannel = (bufferReleaseChannel != nullptr);
230 SAFE_PARCEL(output.writeBool, hasBufferReleaseChannel);
231 if (hasBufferReleaseChannel) {
232 SAFE_PARCEL(output.writeParcelable, *bufferReleaseChannel);
233 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600234#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
235 SAFE_PARCEL(output.writeInt64, pictureProfileHandle.getId());
236 SAFE_PARCEL(output.writeInt32, appContentPriority);
237#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500238
Sally Qief006582024-10-11 13:23:09 -0700239 const bool hasLuts = (luts != nullptr);
240 SAFE_PARCEL(output.writeBool, hasLuts);
241 if (hasLuts) {
242 SAFE_PARCEL(output.writeParcelable, *luts);
243 }
244
Mathias Agopianac9fa422013-02-11 16:40:36 -0800245 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800246}
247
248status_t layer_state_t::read(const Parcel& input)
249{
chaviw308ddba2020-08-11 16:23:51 -0700250 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000251 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700252 SAFE_PARCEL(input.readUint64, &what);
253 SAFE_PARCEL(input.readFloat, &x);
254 SAFE_PARCEL(input.readFloat, &y);
255 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700256 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700257
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800258 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700259
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800260 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700261
262 SAFE_PARCEL(matrix.read, input);
Vishnu Naira9123c82024-10-03 03:56:44 +0000263 SAFE_PARCEL(input.readFloat, &crop.top);
264 SAFE_PARCEL(input.readFloat, &crop.left);
265 SAFE_PARCEL(input.readFloat, &crop.bottom);
266 SAFE_PARCEL(input.readFloat, &crop.right);
chaviw308ddba2020-08-11 16:23:51 -0700267
Anton Ivanovc7f87932025-02-25 00:58:09 -0800268 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input,
269 &mNotDefCmpState.relativeLayerSurfaceControl);
270 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input,
271 &mNotDefCmpState.parentSurfaceControlForChild);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000272
chaviw308ddba2020-08-11 16:23:51 -0700273 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700274 SAFE_PARCEL(input.readFloat, &tmpFloat);
275 color.r = tmpFloat;
276 SAFE_PARCEL(input.readFloat, &tmpFloat);
277 color.g = tmpFloat;
278 SAFE_PARCEL(input.readFloat, &tmpFloat);
279 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000280 SAFE_PARCEL(input.readFloat, &tmpFloat);
281 color.a = tmpFloat;
282
Anton Ivanovc7f87932025-02-25 00:58:09 -0800283 SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700284
Anton Ivanovc7f87932025-02-25 00:58:09 -0800285 SAFE_PARCEL(input.read, mNotDefCmpState.transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000286 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700287 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700288
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800289 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700290 SAFE_PARCEL(input.readUint32, &tmpUint32);
291 dataspace = static_cast<ui::Dataspace>(tmpUint32);
292
293 SAFE_PARCEL(input.read, hdrMetadata);
Anton Ivanovc7f87932025-02-25 00:58:09 -0800294 SAFE_PARCEL(input.read, mNotDefCmpState.surfaceDamageRegion);
chaviw308ddba2020-08-11 16:23:51 -0700295 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500296
297 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700298 SAFE_PARCEL(input.readBool, &tmpBool);
299 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700300 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
301 }
302
chaviw308ddba2020-08-11 16:23:51 -0700303 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
304 SAFE_PARCEL(input.readFloat, &cornerRadius);
Surbhi Kadam9674ffa2024-11-14 23:06:27 +0000305 SAFE_PARCEL(input.readFloat, &clientDrawnCornerRadius);
chaviw308ddba2020-08-11 16:23:51 -0700306 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700307 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800308
Vishnu Naird47bcee2023-02-24 18:08:51 +0000309 SAFE_PARCEL(input.readFloat, &tmpFloat);
310 bgColor.r = tmpFloat;
311 SAFE_PARCEL(input.readFloat, &tmpFloat);
312 bgColor.g = tmpFloat;
313 SAFE_PARCEL(input.readFloat, &tmpFloat);
314 bgColor.b = tmpFloat;
315 SAFE_PARCEL(input.readFloat, &tmpFloat);
316 bgColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700317 SAFE_PARCEL(input.readUint32, &tmpUint32);
318 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
319 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800320
chaviw308ddba2020-08-11 16:23:51 -0700321 int32_t numListeners = 0;
322 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700323 listeners.clear();
324 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700325 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700326 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700327 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700328 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700329 listeners.emplace_back(listener, callbackIds);
330 }
chaviw308ddba2020-08-11 16:23:51 -0700331 SAFE_PARCEL(input.readFloat, &shadowRadius);
YCairn Overturf65fb1c62025-02-24 22:57:09 +0000332 SAFE_PARCEL(input.readParcelable, &borderSettings);
333
chaviw308ddba2020-08-11 16:23:51 -0700334 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
335 SAFE_PARCEL(input.readFloat, &frameRate);
336 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100337 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000338 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700339 SAFE_PARCEL(input.readByte, &frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700340 SAFE_PARCEL(input.readBool, &frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700341 SAFE_PARCEL(input.readByte, &frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700342 SAFE_PARCEL(input.readUint32, &tmpUint32);
343 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800344 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700345 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700346
347 uint32_t numRegions = 0;
348 SAFE_PARCEL(input.readUint32, &numRegions);
349 blurRegions.clear();
350 for (uint32_t i = 0; i < numRegions; i++) {
351 BlurRegion region;
352 SAFE_PARCEL(input.readUint32, &region.blurRadius);
353 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
354 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
355 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
356 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
357 SAFE_PARCEL(input.readFloat, &region.alpha);
358 SAFE_PARCEL(input.readInt32, &region.left);
359 SAFE_PARCEL(input.readInt32, &region.top);
360 SAFE_PARCEL(input.readInt32, &region.right);
361 SAFE_PARCEL(input.readInt32, &region.bottom);
362 blurRegions.push_back(region);
363 }
John Reckcdb4ed72021-02-04 13:39:33 -0500364
365 SAFE_PARCEL(input.read, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000366 SAFE_PARCEL(input.readParcelable, &edgeExtensionParameters);
chaviwf3f40fe2021-04-27 15:54:02 -0500367 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700368 SAFE_PARCEL(input.read, destinationFrame);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000369 uint32_t trustedOverlayInt;
370 SAFE_PARCEL(input.readUint32, &trustedOverlayInt);
371 trustedOverlay = static_cast<gui::TrustedOverlay>(trustedOverlayInt);
John Reckcdb4ed72021-02-04 13:39:33 -0500372
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700373 uint32_t mode;
374 SAFE_PARCEL(input.readUint32, &mode);
375 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800376
377 bool hasBufferData;
378 SAFE_PARCEL(input.readBool, &hasBufferData);
379 if (hasBufferData) {
380 bufferData = std::make_shared<BufferData>();
381 SAFE_PARCEL(input.readParcelable, bufferData.get());
382 } else {
383 bufferData = nullptr;
384 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000385
386 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
387 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
388
John Reck68796592023-01-25 13:47:12 -0500389 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700390 currentHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500391 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700392 desiredHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500393
Alec Mourif4af03e2023-02-11 00:25:24 +0000394 int32_t tmpInt32;
395 SAFE_PARCEL(input.readInt32, &tmpInt32);
396 cachingHint = static_cast<gui::CachingHint>(tmpInt32);
397
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500398 bool hasBufferReleaseChannel;
399 SAFE_PARCEL(input.readBool, &hasBufferReleaseChannel);
400 if (hasBufferReleaseChannel) {
401 bufferReleaseChannel = std::make_shared<gui::BufferReleaseChannel::ProducerEndpoint>();
402 SAFE_PARCEL(input.readParcelable, bufferReleaseChannel.get());
403 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600404#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
405 int64_t pictureProfileId;
406 SAFE_PARCEL(input.readInt64, &pictureProfileId);
407 pictureProfileHandle = PictureProfileHandle(pictureProfileId);
408 SAFE_PARCEL(input.readInt32, &appContentPriority);
409#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500410
Sally Qief006582024-10-11 13:23:09 -0700411 bool hasLuts;
412 SAFE_PARCEL(input.readBool, &hasLuts);
413 if (hasLuts) {
414 luts = std::make_shared<gui::DisplayLuts>();
415 SAFE_PARCEL(input.readParcelable, luts.get());
416 } else {
417 luts = nullptr;
418 }
419
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800420 return NO_ERROR;
421}
422
Mathias Agopian698c0872011-06-28 19:09:31 -0700423status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700424 return state.write(output);
425}
426
427status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700428 return state.read(input);
429}
430
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700431DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700432
Mathias Agopian8b33f032012-07-24 20:43:54 -0700433status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700434 SAFE_PARCEL(output.writeStrongBinder, token);
435 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
436 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700437 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700438 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700439 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
440 SAFE_PARCEL(output.write, layerStackSpaceRect);
441 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
442 SAFE_PARCEL(output.writeUint32, width);
443 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700444 return NO_ERROR;
445}
446
447status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700448 SAFE_PARCEL(input.readStrongBinder, &token);
449 sp<IBinder> tmpBinder;
450 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
451 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
452
453 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700454 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700455 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700456 uint32_t tmpUint = 0;
457 SAFE_PARCEL(input.readUint32, &tmpUint);
458 orientation = ui::toRotation(tmpUint);
459
460 SAFE_PARCEL(input.read, layerStackSpaceRect);
461 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
462 SAFE_PARCEL(input.readUint32, &width);
463 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700464 return NO_ERROR;
465}
466
Robert Carr2c5f6d22017-09-26 12:30:35 -0700467void DisplayState::merge(const DisplayState& other) {
468 if (other.what & eSurfaceChanged) {
469 what |= eSurfaceChanged;
470 surface = other.surface;
471 }
472 if (other.what & eLayerStackChanged) {
473 what |= eLayerStackChanged;
474 layerStack = other.layerStack;
475 }
Evan Rosky2239b372021-05-20 13:43:47 -0700476 if (other.what & eFlagsChanged) {
477 what |= eFlagsChanged;
478 flags = other.flags;
479 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700480 if (other.what & eDisplayProjectionChanged) {
481 what |= eDisplayProjectionChanged;
482 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200483 layerStackSpaceRect = other.layerStackSpaceRect;
484 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700485 }
486 if (other.what & eDisplaySizeChanged) {
487 what |= eDisplaySizeChanged;
488 width = other.width;
489 height = other.height;
490 }
491}
492
Sally Qi6bb12822022-10-05 11:42:30 -0700493void DisplayState::sanitize(int32_t permissions) {
494 if (what & DisplayState::eLayerStackChanged) {
495 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
496 what &= ~DisplayState::eLayerStackChanged;
497 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
498 }
499 }
500 if (what & DisplayState::eDisplayProjectionChanged) {
501 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
502 what &= ~DisplayState::eDisplayProjectionChanged;
503 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
504 }
505 }
506 if (what & DisplayState::eSurfaceChanged) {
507 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
508 what &= ~DisplayState::eSurfaceChanged;
509 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
510 }
511 }
512}
513
Robert Carrde6d7b42022-01-07 18:23:06 -0800514void layer_state_t::sanitize(int32_t permissions) {
515 // TODO: b/109894387
516 //
517 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
518 // rotation. To see the problem observe that if we have a square parent, and a child
519 // of the same size, then we rotate the child 45 degrees around its center, the child
520 // must now be cropped to a non rectangular 8 sided region.
521 //
522 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
523 // private API, and arbitrary rotation is used in limited use cases, for instance:
524 // - WindowManager only uses rotation in one case, which is on a top level layer in which
525 // cropping is not an issue.
526 // - Launcher, as a privileged app, uses this to transition an application to PiP
527 // (picture-in-picture) mode.
528 //
529 // However given that abuse of rotation matrices could lead to surfaces extending outside
530 // of cropped areas, we need to prevent non-root clients without permission
531 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
532 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
533 // preserving transformations.
534 if (what & eMatrixChanged) {
535 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
536 ui::Transform t;
537 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
538 if (!t.preserveRects()) {
539 what &= ~eMatrixChanged;
540 ALOGE("Stripped non rect preserving matrix in sanitize");
541 }
542 }
543 }
544
545 if (what & eFlagsChanged) {
546 if ((flags & eLayerIsDisplayDecoration) &&
547 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
548 flags &= ~eLayerIsDisplayDecoration;
549 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
550 }
Vishnu Nair59a6be32024-01-29 10:26:21 -0800551 if ((mask & eCanOccludePresentation) &&
552 !(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
553 flags &= ~eCanOccludePresentation;
554 mask &= ~eCanOccludePresentation;
555 ALOGE("Stripped attempt to set eCanOccludePresentation in sanitize");
556 }
Robert Carrde6d7b42022-01-07 18:23:06 -0800557 }
558
559 if (what & layer_state_t::eInputInfoChanged) {
560 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
561 what &= ~eInputInfoChanged;
562 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
563 }
564 }
565 if (what & layer_state_t::eTrustedOverlayChanged) {
566 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
567 what &= ~eTrustedOverlayChanged;
568 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
569 }
570 }
571 if (what & layer_state_t::eDropInputModeChanged) {
572 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
573 what &= ~eDropInputModeChanged;
574 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
575 }
576 }
577 if (what & layer_state_t::eFrameRateSelectionPriority) {
578 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
579 what &= ~eFrameRateSelectionPriority;
580 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
581 }
582 }
583 if (what & layer_state_t::eFrameRateChanged) {
584 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
585 changeFrameRateStrategy,
586 "layer_state_t::sanitize",
587 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
588 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
589 }
590 }
591}
592
Robert Carr2c5f6d22017-09-26 12:30:35 -0700593void layer_state_t::merge(const layer_state_t& other) {
594 if (other.what & ePositionChanged) {
595 what |= ePositionChanged;
596 x = other.x;
597 y = other.y;
598 }
599 if (other.what & eLayerChanged) {
600 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700601 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700602 z = other.z;
603 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700604 if (other.what & eAlphaChanged) {
605 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000606 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700607 }
608 if (other.what & eMatrixChanged) {
609 what |= eMatrixChanged;
610 matrix = other.matrix;
611 }
612 if (other.what & eTransparentRegionChanged) {
613 what |= eTransparentRegionChanged;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800614 mNotDefCmpState.transparentRegion = other.mNotDefCmpState.transparentRegion;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700615 }
616 if (other.what & eFlagsChanged) {
617 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700618 flags &= ~other.mask;
619 flags |= (other.flags & other.mask);
620 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700621 }
622 if (other.what & eLayerStackChanged) {
623 what |= eLayerStackChanged;
624 layerStack = other.layerStack;
625 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700626 if (other.what & eCornerRadiusChanged) {
627 what |= eCornerRadiusChanged;
628 cornerRadius = other.cornerRadius;
629 }
Surbhi Kadam9674ffa2024-11-14 23:06:27 +0000630 if (other.what & eClientDrawnCornerRadiusChanged) {
631 what |= eClientDrawnCornerRadiusChanged;
632 clientDrawnCornerRadius = other.clientDrawnCornerRadius;
633 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800634 if (other.what & eBackgroundBlurRadiusChanged) {
635 what |= eBackgroundBlurRadiusChanged;
636 backgroundBlurRadius = other.backgroundBlurRadius;
637 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700638 if (other.what & eBlurRegionsChanged) {
639 what |= eBlurRegionsChanged;
640 blurRegions = other.blurRegions;
641 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700642 if (other.what & eRelativeLayerChanged) {
643 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700644 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700645 z = other.z;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800646 mNotDefCmpState.relativeLayerSurfaceControl =
647 other.mNotDefCmpState.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700648 }
649 if (other.what & eReparent) {
650 what |= eReparent;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800651 mNotDefCmpState.parentSurfaceControlForChild =
652 other.mNotDefCmpState.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700653 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000654 if (other.what & eBufferTransformChanged) {
655 what |= eBufferTransformChanged;
656 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700657 }
658 if (other.what & eTransformToDisplayInverseChanged) {
659 what |= eTransformToDisplayInverseChanged;
660 transformToDisplayInverse = other.transformToDisplayInverse;
661 }
662 if (other.what & eCropChanged) {
663 what |= eCropChanged;
664 crop = other.crop;
665 }
666 if (other.what & eBufferChanged) {
667 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500668 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700669 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000670 if (other.what & eTrustedPresentationInfoChanged) {
671 what |= eTrustedPresentationInfoChanged;
672 trustedPresentationListener = other.trustedPresentationListener;
673 trustedPresentationThresholds = other.trustedPresentationThresholds;
674 }
Marissa Wall61c58622018-07-18 10:12:20 -0700675 if (other.what & eDataspaceChanged) {
676 what |= eDataspaceChanged;
677 dataspace = other.dataspace;
678 }
John Reck68796592023-01-25 13:47:12 -0500679 if (other.what & eExtendedRangeBrightnessChanged) {
680 what |= eExtendedRangeBrightnessChanged;
Sally Qi963049b2023-03-23 14:06:21 -0700681 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
682 currentHdrSdrRatio = other.currentHdrSdrRatio;
John Reck68796592023-01-25 13:47:12 -0500683 }
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000684 if (other.what & eDesiredHdrHeadroomChanged) {
685 what |= eDesiredHdrHeadroomChanged;
686 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
687 }
Alec Mourif4af03e2023-02-11 00:25:24 +0000688 if (other.what & eCachingHintChanged) {
689 what |= eCachingHintChanged;
690 cachingHint = other.cachingHint;
691 }
Marissa Wall61c58622018-07-18 10:12:20 -0700692 if (other.what & eHdrMetadataChanged) {
693 what |= eHdrMetadataChanged;
694 hdrMetadata = other.hdrMetadata;
695 }
696 if (other.what & eSurfaceDamageRegionChanged) {
697 what |= eSurfaceDamageRegionChanged;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800698 mNotDefCmpState.surfaceDamageRegion = other.mNotDefCmpState.surfaceDamageRegion;
Marissa Wall61c58622018-07-18 10:12:20 -0700699 }
700 if (other.what & eApiChanged) {
701 what |= eApiChanged;
702 api = other.api;
703 }
704 if (other.what & eSidebandStreamChanged) {
705 what |= eSidebandStreamChanged;
706 sidebandStream = other.sidebandStream;
707 }
Peiyong Lind3788632018-09-18 16:01:31 -0700708 if (other.what & eColorTransformChanged) {
709 what |= eColorTransformChanged;
710 colorTransform = other.colorTransform;
711 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700712 if (other.what & eHasListenerCallbacksChanged) {
713 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700714 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700715 if (other.what & eInputInfoChanged) {
716 what |= eInputInfoChanged;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800717 mNotDefCmpState.windowInfoHandle =
718 sp<WindowInfoHandle>::make(*other.mNotDefCmpState.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700719 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800720 if (other.what & eBackgroundColorChanged) {
721 what |= eBackgroundColorChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000722 bgColor = other.bgColor;
Valerie Haudd0b7572019-01-29 14:59:27 -0800723 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800724 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800725 if (other.what & eMetadataChanged) {
726 what |= eMetadataChanged;
727 metadata.merge(other.metadata);
728 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700729 if (other.what & eShadowRadiusChanged) {
730 what |= eShadowRadiusChanged;
731 shadowRadius = other.shadowRadius;
732 }
YCairn Overturf65fb1c62025-02-24 22:57:09 +0000733 if (other.what & eBorderSettingsChanged) {
734 what |= eBorderSettingsChanged;
735 borderSettings = other.borderSettings;
736 }
Sally Qi0abc4a52024-09-26 16:13:06 -0700737 if (other.what & eLutsChanged) {
738 what |= eLutsChanged;
739 luts = other.luts;
740 }
Andy Labrada096227e2022-06-15 16:58:11 +0000741 if (other.what & eDefaultFrameRateCompatibilityChanged) {
742 what |= eDefaultFrameRateCompatibilityChanged;
743 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
744 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100745 if (other.what & eFrameRateSelectionPriority) {
746 what |= eFrameRateSelectionPriority;
747 frameRateSelectionPriority = other.frameRateSelectionPriority;
748 }
Steven Thomas3172e202020-01-06 19:25:30 -0800749 if (other.what & eFrameRateChanged) {
750 what |= eFrameRateChanged;
751 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800752 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100753 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800754 }
Rachel Leece6e0042023-06-27 11:22:54 -0700755 if (other.what & eFrameRateCategoryChanged) {
756 what |= eFrameRateCategoryChanged;
757 frameRateCategory = other.frameRateCategory;
Rachel Lee67afbea2023-09-28 15:35:07 -0700758 frameRateCategorySmoothSwitchOnly = other.frameRateCategorySmoothSwitchOnly;
Rachel Leece6e0042023-06-27 11:22:54 -0700759 }
Rachel Lee58cc90d2023-09-05 18:50:20 -0700760 if (other.what & eFrameRateSelectionStrategyChanged) {
761 what |= eFrameRateSelectionStrategyChanged;
762 frameRateSelectionStrategy = other.frameRateSelectionStrategy;
763 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700764 if (other.what & eFixedTransformHintChanged) {
765 what |= eFixedTransformHintChanged;
766 fixedTransformHint = other.fixedTransformHint;
767 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800768 if (other.what & eAutoRefreshChanged) {
769 what |= eAutoRefreshChanged;
770 autoRefresh = other.autoRefresh;
771 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700772 if (other.what & eTrustedOverlayChanged) {
773 what |= eTrustedOverlayChanged;
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000774 trustedOverlay = other.trustedOverlay;
Winson Chunga30f7c92021-06-29 15:42:56 -0700775 }
John Reckc00c6692021-02-16 11:37:33 -0500776 if (other.what & eStretchChanged) {
777 what |= eStretchChanged;
778 stretchEffect = other.stretchEffect;
779 }
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000780 if (other.what & eEdgeExtensionChanged) {
781 what |= eEdgeExtensionChanged;
782 edgeExtensionParameters = other.edgeExtensionParameters;
783 }
chaviwf3f40fe2021-04-27 15:54:02 -0500784 if (other.what & eBufferCropChanged) {
785 what |= eBufferCropChanged;
786 bufferCrop = other.bufferCrop;
787 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700788 if (other.what & eDestinationFrameChanged) {
789 what |= eDestinationFrameChanged;
790 destinationFrame = other.destinationFrame;
791 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700792 if (other.what & eProducerDisconnect) {
793 what |= eProducerDisconnect;
794 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700795 if (other.what & eDropInputModeChanged) {
796 what |= eDropInputModeChanged;
797 dropInputMode = other.dropInputMode;
798 }
chaviw4c36cd82021-11-18 10:37:33 -0600799 if (other.what & eColorChanged) {
800 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000801 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600802 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800803 if (other.what & eColorSpaceAgnosticChanged) {
804 what |= eColorSpaceAgnosticChanged;
805 colorSpaceAgnostic = other.colorSpaceAgnostic;
806 }
Sally Qi81d95e62022-03-21 19:41:33 -0700807 if (other.what & eDimmingEnabledChanged) {
808 what |= eDimmingEnabledChanged;
809 dimmingEnabled = other.dimmingEnabled;
810 }
Pascal Muetschardb39918f2023-01-27 11:36:11 +0100811 if (other.what & eFlushJankData) {
812 what |= eFlushJankData;
813 }
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500814 if (other.what & eBufferReleaseChannelChanged) {
815 what |= eBufferReleaseChannelChanged;
816 bufferReleaseChannel = other.bufferReleaseChannel;
817 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600818 if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
819 if (other.what & ePictureProfileHandleChanged) {
820 what |= ePictureProfileHandleChanged;
821 pictureProfileHandle = other.pictureProfileHandle;
822 }
823 if (other.what & eAppContentPriorityChanged) {
824 what |= eAppContentPriorityChanged;
825 appContentPriority = other.appContentPriority;
826 }
827 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700828 if ((other.what & what) != other.what) {
829 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700830 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
831 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700832 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700833}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700834
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000835uint64_t layer_state_t::diff(const layer_state_t& other) const {
836 uint64_t diff = 0;
837 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
838 if (other.what & eLayerChanged) {
839 diff |= eLayerChanged;
840 diff &= ~eRelativeLayerChanged;
841 }
842 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
843 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
844 if (other.what & eTransparentRegionChanged &&
Anton Ivanovc7f87932025-02-25 00:58:09 -0800845 (!mNotDefCmpState.transparentRegion.hasSameRects(
846 other.mNotDefCmpState.transparentRegion))) {
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000847 diff |= eTransparentRegionChanged;
848 }
849 if (other.what & eFlagsChanged) {
850 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
851 if (changedFlags) diff |= eFlagsChanged;
852 }
853 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
854 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
Surbhi Kadam9674ffa2024-11-14 23:06:27 +0000855 CHECK_DIFF(diff, eClientDrawnCornerRadiusChanged, other, clientDrawnCornerRadius);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000856 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
857 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
858 if (other.what & eRelativeLayerChanged) {
859 diff |= eRelativeLayerChanged;
860 diff &= ~eLayerChanged;
861 }
862 if (other.what & eReparent &&
Anton Ivanovc7f87932025-02-25 00:58:09 -0800863 !SurfaceControl::isSameSurface(mNotDefCmpState.parentSurfaceControlForChild,
864 other.mNotDefCmpState.parentSurfaceControlForChild)) {
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000865 diff |= eReparent;
866 }
867 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
868 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
869 CHECK_DIFF(diff, eCropChanged, other, crop);
870 if (other.what & eBufferChanged) diff |= eBufferChanged;
871 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
Sally Qi963049b2023-03-23 14:06:21 -0700872 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio,
873 desiredHdrSdrRatio);
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000874 CHECK_DIFF(diff, eDesiredHdrHeadroomChanged, other, desiredHdrSdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000875 CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000876 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
877 if (other.what & eSurfaceDamageRegionChanged &&
Anton Ivanovc7f87932025-02-25 00:58:09 -0800878 (!mNotDefCmpState.surfaceDamageRegion.hasSameRects(
879 other.mNotDefCmpState.surfaceDamageRegion))) {
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000880 diff |= eSurfaceDamageRegionChanged;
881 }
882 CHECK_DIFF(diff, eApiChanged, other, api);
883 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
884 CHECK_DIFF(diff, eApiChanged, other, api);
885 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
886 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
887 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000888 CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000889 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
890 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
YCairn Overturf65fb1c62025-02-24 22:57:09 +0000891 CHECK_DIFF(diff, eBorderSettingsChanged, other, borderSettings);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000892 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
893 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
894 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
895 changeFrameRateStrategy);
Rachel Lee67afbea2023-09-28 15:35:07 -0700896 CHECK_DIFF2(diff, eFrameRateCategoryChanged, other, frameRateCategory,
897 frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700898 CHECK_DIFF(diff, eFrameRateSelectionStrategyChanged, other, frameRateSelectionStrategy);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000899 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
900 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000901 CHECK_DIFF(diff, eTrustedOverlayChanged, other, trustedOverlay);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000902 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000903 CHECK_DIFF(diff, eEdgeExtensionChanged, other, edgeExtensionParameters);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000904 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
905 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
906 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
907 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
908 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
909 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
910 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500911 if (other.what & eBufferReleaseChannelChanged) diff |= eBufferReleaseChannelChanged;
Sally Qi0abc4a52024-09-26 16:13:06 -0700912 if (other.what & eLutsChanged) diff |= eLutsChanged;
Brian Lindahl07dcd492024-10-30 11:43:23 -0600913 CHECK_DIFF(diff, ePictureProfileHandleChanged, other, pictureProfileHandle);
914 CHECK_DIFF(diff, eAppContentPriorityChanged, other, appContentPriority);
Sally Qi0abc4a52024-09-26 16:13:06 -0700915
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000916 return diff;
917}
918
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700919bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500920 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700921}
922
Ady Abraham6e8e3642021-07-08 19:44:07 -0700923bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700924 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700925}
926
chaviw308ddba2020-08-11 16:23:51 -0700927status_t layer_state_t::matrix22_t::write(Parcel& output) const {
928 SAFE_PARCEL(output.writeFloat, dsdx);
929 SAFE_PARCEL(output.writeFloat, dtdx);
930 SAFE_PARCEL(output.writeFloat, dtdy);
931 SAFE_PARCEL(output.writeFloat, dsdy);
932 return NO_ERROR;
933}
934
935status_t layer_state_t::matrix22_t::read(const Parcel& input) {
936 SAFE_PARCEL(input.readFloat, &dsdx);
937 SAFE_PARCEL(input.readFloat, &dtdx);
938 SAFE_PARCEL(input.readFloat, &dtdy);
939 SAFE_PARCEL(input.readFloat, &dsdy);
940 return NO_ERROR;
941}
Anton Ivanovc7f87932025-02-25 00:58:09 -0800942void layer_state_t::updateTransparentRegion(const Region& transparentRegion) {
943 what |= eTransparentRegionChanged;
944 mNotDefCmpState.transparentRegion = transparentRegion;
945}
946void layer_state_t::updateSurfaceDamageRegion(const Region& surfaceDamageRegion) {
947 what |= eSurfaceDamageRegionChanged;
948 mNotDefCmpState.surfaceDamageRegion = surfaceDamageRegion;
949}
950void layer_state_t::updateRelativeLayer(const sp<SurfaceControl>& relativeTo, int32_t z) {
951 what |= layer_state_t::eRelativeLayerChanged;
952 what &= ~layer_state_t::eLayerChanged;
953 mNotDefCmpState.relativeLayerSurfaceControl = relativeTo;
954 this->z = z;
955}
956void layer_state_t::updateParentLayer(const sp<SurfaceControl>& newParent) {
957 what |= layer_state_t::eReparent;
958 mNotDefCmpState.parentSurfaceControlForChild =
959 newParent ? newParent->getParentingLayer() : nullptr;
960}
961void layer_state_t::updateInputWindowInfo(sp<gui::WindowInfoHandle>&& info) {
962 what |= eInputInfoChanged;
963 mNotDefCmpState.windowInfoHandle = std::move(info);
964}
965
966bool layer_state_t::NotDefaultComparableState::operator==(
967 const NotDefaultComparableState& rhs) const {
968 return transparentRegion.hasSameRects(rhs.transparentRegion) &&
969 surfaceDamageRegion.hasSameRects(rhs.surfaceDamageRegion) &&
970 isSameWindowHandle(windowInfoHandle, rhs.windowInfoHandle) &&
971 isSameSurfaceControl(relativeLayerSurfaceControl, rhs.relativeLayerSurfaceControl) &&
972 isSameSurfaceControl(parentSurfaceControlForChild, rhs.parentSurfaceControlForChild);
973}
chaviw308ddba2020-08-11 16:23:51 -0700974
chaviw273171b2018-12-26 11:46:30 -0800975// ------------------------------- InputWindowCommands ----------------------------------------
976
Vishnu Naire798b472020-07-23 13:52:21 -0700977bool InputWindowCommands::merge(const InputWindowCommands& other) {
978 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700979 changes |= !other.focusRequests.empty();
980 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
981 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000982 changes |= !other.windowInfosReportedListeners.empty();
983 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
984 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700985 return changes;
chaviw273171b2018-12-26 11:46:30 -0800986}
987
Vishnu Nair958da932020-08-21 17:12:37 -0700988bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000989 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700990}
991
chaviw273171b2018-12-26 11:46:30 -0800992void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700993 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000994 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800995}
996
chaviw308ddba2020-08-11 16:23:51 -0700997status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700998 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000999
1000 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
1001 for (const auto& listener : windowInfosReportedListeners) {
1002 SAFE_PARCEL(output.writeStrongBinder, listener);
1003 }
1004
chaviw308ddba2020-08-11 16:23:51 -07001005 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -08001006}
1007
chaviw308ddba2020-08-11 16:23:51 -07001008status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -07001009 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +00001010
1011 int listenerSize = 0;
1012 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
1013 windowInfosReportedListeners.reserve(listenerSize);
1014 for (int i = 0; i < listenerSize; i++) {
1015 sp<gui::IWindowInfosReportedListener> listener;
1016 SAFE_PARCEL(input.readStrongBinder, &listener);
1017 windowInfosReportedListeners.insert(listener);
1018 }
1019
chaviw308ddba2020-08-11 16:23:51 -07001020 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -08001021}
1022
chaviw618c42d2020-07-24 15:25:08 -07001023// ----------------------------------------------------------------------------
1024
chaviw8dd181f2022-01-05 18:36:46 -06001025ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -05001026 uint64_t bufferId;
1027 if (buffer) {
1028 bufferId = buffer->getId();
1029 } else {
1030 bufferId = cachedBuffer.id;
1031 }
1032 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -06001033}
1034
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001035status_t BufferData::writeToParcel(Parcel* output) const {
1036 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -05001037
1038 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001039 SAFE_PARCEL(output->writeBool, true);
1040 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -05001041 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001042 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -05001043 }
1044
1045 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001046 SAFE_PARCEL(output->writeBool, true);
1047 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -05001048 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001049 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -05001050 }
1051
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001052 SAFE_PARCEL(output->writeUint64, frameNumber);
1053 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
1054 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001055
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001056 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
1057 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -08001058 SAFE_PARCEL(output->writeBool, hasBarrier);
1059 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001060 SAFE_PARCEL(output->writeUint32, producerId);
Nergi Rahardi39f510f2024-05-23 15:16:54 +09001061 SAFE_PARCEL(output->writeInt64, dequeueTime);
chaviwba4320c2021-09-15 15:20:53 -05001062
1063 return NO_ERROR;
1064}
1065
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001066status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -05001067 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001068 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -07001069 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -05001070
1071 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001072 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001073 if (tmpBool) {
Anton Ivanov8ed86592025-02-20 11:52:50 -08001074 buffer = sp<GraphicBuffer>::make();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001075 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -05001076 }
1077
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001078 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001079 if (tmpBool) {
Anton Ivanov8ed86592025-02-20 11:52:50 -08001080 acquireFence = sp<Fence>::make();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001081 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -05001082 }
1083
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001084 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -05001085
1086 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001087 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001088 if (tmpBinder) {
1089 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1090 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001091 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001092
1093 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001094 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001095 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001096 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -05001097
Robert Carr79dc06a2022-02-22 15:28:59 -08001098 SAFE_PARCEL(input->readBool, &hasBarrier);
1099 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001100 SAFE_PARCEL(input->readUint32, &producerId);
Nergi Rahardi39f510f2024-05-23 15:16:54 +09001101 SAFE_PARCEL(input->readInt64, &dequeueTime);
Robert Carr79dc06a2022-02-22 15:28:59 -08001102
chaviwba4320c2021-09-15 15:20:53 -05001103 return NO_ERROR;
1104}
1105
Chavi Weingarten076acac2023-01-19 17:20:43 +00001106status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
Anton Ivanovc7f87932025-02-25 00:58:09 -08001107 SAFE_PARCEL(parcel->writeStrongBinder, mState.callbackInterface);
1108 SAFE_PARCEL(parcel->writeInt32, mState.callbackId);
Chavi Weingarten076acac2023-01-19 17:20:43 +00001109 return NO_ERROR;
1110}
1111
1112status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1113 sp<IBinder> tmpBinder = nullptr;
1114 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1115 if (tmpBinder) {
Anton Ivanovc7f87932025-02-25 00:58:09 -08001116 mState.callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
Chavi Weingarten076acac2023-01-19 17:20:43 +00001117 }
Anton Ivanovc7f87932025-02-25 00:58:09 -08001118 SAFE_PARCEL(parcel->readInt32, &mState.callbackId);
Chavi Weingarten076acac2023-01-19 17:20:43 +00001119 return NO_ERROR;
1120}
1121
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001122}; // namespace android