blob: ad95d1a85ab011659ae1e652bb3237aa236d2d41 [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);
183 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
184 SAFE_PARCEL(output.writeFloat, frameRate);
185 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100186 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000187 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700188 SAFE_PARCEL(output.writeByte, frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700189 SAFE_PARCEL(output.writeBool, frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700190 SAFE_PARCEL(output.writeByte, frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700191 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800192 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700193 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700194
195 SAFE_PARCEL(output.writeUint32, blurRegions.size());
196 for (auto region : blurRegions) {
197 SAFE_PARCEL(output.writeUint32, region.blurRadius);
198 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
199 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
200 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
201 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
202 SAFE_PARCEL(output.writeFloat, region.alpha);
203 SAFE_PARCEL(output.writeInt32, region.left);
204 SAFE_PARCEL(output.writeInt32, region.top);
205 SAFE_PARCEL(output.writeInt32, region.right);
206 SAFE_PARCEL(output.writeInt32, region.bottom);
207 }
John Reckcdb4ed72021-02-04 13:39:33 -0500208
209 SAFE_PARCEL(output.write, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000210 SAFE_PARCEL(output.writeParcelable, edgeExtensionParameters);
chaviwf3f40fe2021-04-27 15:54:02 -0500211 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700212 SAFE_PARCEL(output.write, destinationFrame);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000213 SAFE_PARCEL(output.writeInt32, static_cast<uint32_t>(trustedOverlay));
John Reckcdb4ed72021-02-04 13:39:33 -0500214
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700215 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800216
217 const bool hasBufferData = (bufferData != nullptr);
218 SAFE_PARCEL(output.writeBool, hasBufferData);
219 if (hasBufferData) {
220 SAFE_PARCEL(output.writeParcelable, *bufferData);
221 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000222 SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds);
223 SAFE_PARCEL(output.writeParcelable, trustedPresentationListener);
Sally Qi963049b2023-03-23 14:06:21 -0700224 SAFE_PARCEL(output.writeFloat, currentHdrSdrRatio);
225 SAFE_PARCEL(output.writeFloat, desiredHdrSdrRatio);
Vishnu Nair59a6be32024-01-29 10:26:21 -0800226 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(cachingHint));
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500227
228 const bool hasBufferReleaseChannel = (bufferReleaseChannel != nullptr);
229 SAFE_PARCEL(output.writeBool, hasBufferReleaseChannel);
230 if (hasBufferReleaseChannel) {
231 SAFE_PARCEL(output.writeParcelable, *bufferReleaseChannel);
232 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600233#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
234 SAFE_PARCEL(output.writeInt64, pictureProfileHandle.getId());
235 SAFE_PARCEL(output.writeInt32, appContentPriority);
236#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500237
Sally Qief006582024-10-11 13:23:09 -0700238 const bool hasLuts = (luts != nullptr);
239 SAFE_PARCEL(output.writeBool, hasLuts);
240 if (hasLuts) {
241 SAFE_PARCEL(output.writeParcelable, *luts);
242 }
243
Mathias Agopianac9fa422013-02-11 16:40:36 -0800244 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800245}
246
247status_t layer_state_t::read(const Parcel& input)
248{
chaviw308ddba2020-08-11 16:23:51 -0700249 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000250 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700251 SAFE_PARCEL(input.readUint64, &what);
252 SAFE_PARCEL(input.readFloat, &x);
253 SAFE_PARCEL(input.readFloat, &y);
254 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700255 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700256
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800257 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700258
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800259 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700260
261 SAFE_PARCEL(matrix.read, input);
Vishnu Naira9123c82024-10-03 03:56:44 +0000262 SAFE_PARCEL(input.readFloat, &crop.top);
263 SAFE_PARCEL(input.readFloat, &crop.left);
264 SAFE_PARCEL(input.readFloat, &crop.bottom);
265 SAFE_PARCEL(input.readFloat, &crop.right);
chaviw308ddba2020-08-11 16:23:51 -0700266
Anton Ivanovc7f87932025-02-25 00:58:09 -0800267 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input,
268 &mNotDefCmpState.relativeLayerSurfaceControl);
269 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input,
270 &mNotDefCmpState.parentSurfaceControlForChild);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000271
chaviw308ddba2020-08-11 16:23:51 -0700272 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700273 SAFE_PARCEL(input.readFloat, &tmpFloat);
274 color.r = tmpFloat;
275 SAFE_PARCEL(input.readFloat, &tmpFloat);
276 color.g = tmpFloat;
277 SAFE_PARCEL(input.readFloat, &tmpFloat);
278 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000279 SAFE_PARCEL(input.readFloat, &tmpFloat);
280 color.a = tmpFloat;
281
Anton Ivanovc7f87932025-02-25 00:58:09 -0800282 SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700283
Anton Ivanovc7f87932025-02-25 00:58:09 -0800284 SAFE_PARCEL(input.read, mNotDefCmpState.transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000285 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700286 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700287
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800288 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700289 SAFE_PARCEL(input.readUint32, &tmpUint32);
290 dataspace = static_cast<ui::Dataspace>(tmpUint32);
291
292 SAFE_PARCEL(input.read, hdrMetadata);
Anton Ivanovc7f87932025-02-25 00:58:09 -0800293 SAFE_PARCEL(input.read, mNotDefCmpState.surfaceDamageRegion);
chaviw308ddba2020-08-11 16:23:51 -0700294 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500295
296 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700297 SAFE_PARCEL(input.readBool, &tmpBool);
298 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700299 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
300 }
301
chaviw308ddba2020-08-11 16:23:51 -0700302 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
303 SAFE_PARCEL(input.readFloat, &cornerRadius);
Surbhi Kadam9674ffa2024-11-14 23:06:27 +0000304 SAFE_PARCEL(input.readFloat, &clientDrawnCornerRadius);
chaviw308ddba2020-08-11 16:23:51 -0700305 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700306 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800307
Vishnu Naird47bcee2023-02-24 18:08:51 +0000308 SAFE_PARCEL(input.readFloat, &tmpFloat);
309 bgColor.r = tmpFloat;
310 SAFE_PARCEL(input.readFloat, &tmpFloat);
311 bgColor.g = tmpFloat;
312 SAFE_PARCEL(input.readFloat, &tmpFloat);
313 bgColor.b = tmpFloat;
314 SAFE_PARCEL(input.readFloat, &tmpFloat);
315 bgColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700316 SAFE_PARCEL(input.readUint32, &tmpUint32);
317 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
318 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800319
chaviw308ddba2020-08-11 16:23:51 -0700320 int32_t numListeners = 0;
321 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700322 listeners.clear();
323 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700324 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700325 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700326 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700327 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700328 listeners.emplace_back(listener, callbackIds);
329 }
chaviw308ddba2020-08-11 16:23:51 -0700330 SAFE_PARCEL(input.readFloat, &shadowRadius);
331 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
332 SAFE_PARCEL(input.readFloat, &frameRate);
333 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100334 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000335 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700336 SAFE_PARCEL(input.readByte, &frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700337 SAFE_PARCEL(input.readBool, &frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700338 SAFE_PARCEL(input.readByte, &frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700339 SAFE_PARCEL(input.readUint32, &tmpUint32);
340 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800341 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700342 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700343
344 uint32_t numRegions = 0;
345 SAFE_PARCEL(input.readUint32, &numRegions);
346 blurRegions.clear();
347 for (uint32_t i = 0; i < numRegions; i++) {
348 BlurRegion region;
349 SAFE_PARCEL(input.readUint32, &region.blurRadius);
350 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
351 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
352 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
353 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
354 SAFE_PARCEL(input.readFloat, &region.alpha);
355 SAFE_PARCEL(input.readInt32, &region.left);
356 SAFE_PARCEL(input.readInt32, &region.top);
357 SAFE_PARCEL(input.readInt32, &region.right);
358 SAFE_PARCEL(input.readInt32, &region.bottom);
359 blurRegions.push_back(region);
360 }
John Reckcdb4ed72021-02-04 13:39:33 -0500361
362 SAFE_PARCEL(input.read, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000363 SAFE_PARCEL(input.readParcelable, &edgeExtensionParameters);
chaviwf3f40fe2021-04-27 15:54:02 -0500364 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700365 SAFE_PARCEL(input.read, destinationFrame);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000366 uint32_t trustedOverlayInt;
367 SAFE_PARCEL(input.readUint32, &trustedOverlayInt);
368 trustedOverlay = static_cast<gui::TrustedOverlay>(trustedOverlayInt);
John Reckcdb4ed72021-02-04 13:39:33 -0500369
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700370 uint32_t mode;
371 SAFE_PARCEL(input.readUint32, &mode);
372 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800373
374 bool hasBufferData;
375 SAFE_PARCEL(input.readBool, &hasBufferData);
376 if (hasBufferData) {
377 bufferData = std::make_shared<BufferData>();
378 SAFE_PARCEL(input.readParcelable, bufferData.get());
379 } else {
380 bufferData = nullptr;
381 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000382
383 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
384 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
385
John Reck68796592023-01-25 13:47:12 -0500386 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700387 currentHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500388 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700389 desiredHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500390
Alec Mourif4af03e2023-02-11 00:25:24 +0000391 int32_t tmpInt32;
392 SAFE_PARCEL(input.readInt32, &tmpInt32);
393 cachingHint = static_cast<gui::CachingHint>(tmpInt32);
394
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500395 bool hasBufferReleaseChannel;
396 SAFE_PARCEL(input.readBool, &hasBufferReleaseChannel);
397 if (hasBufferReleaseChannel) {
398 bufferReleaseChannel = std::make_shared<gui::BufferReleaseChannel::ProducerEndpoint>();
399 SAFE_PARCEL(input.readParcelable, bufferReleaseChannel.get());
400 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600401#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
402 int64_t pictureProfileId;
403 SAFE_PARCEL(input.readInt64, &pictureProfileId);
404 pictureProfileHandle = PictureProfileHandle(pictureProfileId);
405 SAFE_PARCEL(input.readInt32, &appContentPriority);
406#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500407
Sally Qief006582024-10-11 13:23:09 -0700408 bool hasLuts;
409 SAFE_PARCEL(input.readBool, &hasLuts);
410 if (hasLuts) {
411 luts = std::make_shared<gui::DisplayLuts>();
412 SAFE_PARCEL(input.readParcelable, luts.get());
413 } else {
414 luts = nullptr;
415 }
416
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800417 return NO_ERROR;
418}
419
Mathias Agopian698c0872011-06-28 19:09:31 -0700420status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700421 return state.write(output);
422}
423
424status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700425 return state.read(input);
426}
427
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700428DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700429
Mathias Agopian8b33f032012-07-24 20:43:54 -0700430status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700431 SAFE_PARCEL(output.writeStrongBinder, token);
432 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
433 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700434 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700435 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700436 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
437 SAFE_PARCEL(output.write, layerStackSpaceRect);
438 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
439 SAFE_PARCEL(output.writeUint32, width);
440 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700441 return NO_ERROR;
442}
443
444status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700445 SAFE_PARCEL(input.readStrongBinder, &token);
446 sp<IBinder> tmpBinder;
447 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
448 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
449
450 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700451 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700452 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700453 uint32_t tmpUint = 0;
454 SAFE_PARCEL(input.readUint32, &tmpUint);
455 orientation = ui::toRotation(tmpUint);
456
457 SAFE_PARCEL(input.read, layerStackSpaceRect);
458 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
459 SAFE_PARCEL(input.readUint32, &width);
460 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700461 return NO_ERROR;
462}
463
Robert Carr2c5f6d22017-09-26 12:30:35 -0700464void DisplayState::merge(const DisplayState& other) {
465 if (other.what & eSurfaceChanged) {
466 what |= eSurfaceChanged;
467 surface = other.surface;
468 }
469 if (other.what & eLayerStackChanged) {
470 what |= eLayerStackChanged;
471 layerStack = other.layerStack;
472 }
Evan Rosky2239b372021-05-20 13:43:47 -0700473 if (other.what & eFlagsChanged) {
474 what |= eFlagsChanged;
475 flags = other.flags;
476 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700477 if (other.what & eDisplayProjectionChanged) {
478 what |= eDisplayProjectionChanged;
479 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200480 layerStackSpaceRect = other.layerStackSpaceRect;
481 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700482 }
483 if (other.what & eDisplaySizeChanged) {
484 what |= eDisplaySizeChanged;
485 width = other.width;
486 height = other.height;
487 }
488}
489
Sally Qi6bb12822022-10-05 11:42:30 -0700490void DisplayState::sanitize(int32_t permissions) {
491 if (what & DisplayState::eLayerStackChanged) {
492 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
493 what &= ~DisplayState::eLayerStackChanged;
494 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
495 }
496 }
497 if (what & DisplayState::eDisplayProjectionChanged) {
498 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
499 what &= ~DisplayState::eDisplayProjectionChanged;
500 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
501 }
502 }
503 if (what & DisplayState::eSurfaceChanged) {
504 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
505 what &= ~DisplayState::eSurfaceChanged;
506 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
507 }
508 }
509}
510
Robert Carrde6d7b42022-01-07 18:23:06 -0800511void layer_state_t::sanitize(int32_t permissions) {
512 // TODO: b/109894387
513 //
514 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
515 // rotation. To see the problem observe that if we have a square parent, and a child
516 // of the same size, then we rotate the child 45 degrees around its center, the child
517 // must now be cropped to a non rectangular 8 sided region.
518 //
519 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
520 // private API, and arbitrary rotation is used in limited use cases, for instance:
521 // - WindowManager only uses rotation in one case, which is on a top level layer in which
522 // cropping is not an issue.
523 // - Launcher, as a privileged app, uses this to transition an application to PiP
524 // (picture-in-picture) mode.
525 //
526 // However given that abuse of rotation matrices could lead to surfaces extending outside
527 // of cropped areas, we need to prevent non-root clients without permission
528 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
529 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
530 // preserving transformations.
531 if (what & eMatrixChanged) {
532 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
533 ui::Transform t;
534 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
535 if (!t.preserveRects()) {
536 what &= ~eMatrixChanged;
537 ALOGE("Stripped non rect preserving matrix in sanitize");
538 }
539 }
540 }
541
542 if (what & eFlagsChanged) {
543 if ((flags & eLayerIsDisplayDecoration) &&
544 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
545 flags &= ~eLayerIsDisplayDecoration;
546 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
547 }
Vishnu Nair59a6be32024-01-29 10:26:21 -0800548 if ((mask & eCanOccludePresentation) &&
549 !(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
550 flags &= ~eCanOccludePresentation;
551 mask &= ~eCanOccludePresentation;
552 ALOGE("Stripped attempt to set eCanOccludePresentation in sanitize");
553 }
Robert Carrde6d7b42022-01-07 18:23:06 -0800554 }
555
556 if (what & layer_state_t::eInputInfoChanged) {
557 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
558 what &= ~eInputInfoChanged;
559 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
560 }
561 }
562 if (what & layer_state_t::eTrustedOverlayChanged) {
563 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
564 what &= ~eTrustedOverlayChanged;
565 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
566 }
567 }
568 if (what & layer_state_t::eDropInputModeChanged) {
569 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
570 what &= ~eDropInputModeChanged;
571 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
572 }
573 }
574 if (what & layer_state_t::eFrameRateSelectionPriority) {
575 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
576 what &= ~eFrameRateSelectionPriority;
577 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
578 }
579 }
580 if (what & layer_state_t::eFrameRateChanged) {
581 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
582 changeFrameRateStrategy,
583 "layer_state_t::sanitize",
584 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
585 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
586 }
587 }
588}
589
Robert Carr2c5f6d22017-09-26 12:30:35 -0700590void layer_state_t::merge(const layer_state_t& other) {
591 if (other.what & ePositionChanged) {
592 what |= ePositionChanged;
593 x = other.x;
594 y = other.y;
595 }
596 if (other.what & eLayerChanged) {
597 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700598 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700599 z = other.z;
600 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700601 if (other.what & eAlphaChanged) {
602 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000603 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700604 }
605 if (other.what & eMatrixChanged) {
606 what |= eMatrixChanged;
607 matrix = other.matrix;
608 }
609 if (other.what & eTransparentRegionChanged) {
610 what |= eTransparentRegionChanged;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800611 mNotDefCmpState.transparentRegion = other.mNotDefCmpState.transparentRegion;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700612 }
613 if (other.what & eFlagsChanged) {
614 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700615 flags &= ~other.mask;
616 flags |= (other.flags & other.mask);
617 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700618 }
619 if (other.what & eLayerStackChanged) {
620 what |= eLayerStackChanged;
621 layerStack = other.layerStack;
622 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700623 if (other.what & eCornerRadiusChanged) {
624 what |= eCornerRadiusChanged;
625 cornerRadius = other.cornerRadius;
626 }
Surbhi Kadam9674ffa2024-11-14 23:06:27 +0000627 if (other.what & eClientDrawnCornerRadiusChanged) {
628 what |= eClientDrawnCornerRadiusChanged;
629 clientDrawnCornerRadius = other.clientDrawnCornerRadius;
630 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800631 if (other.what & eBackgroundBlurRadiusChanged) {
632 what |= eBackgroundBlurRadiusChanged;
633 backgroundBlurRadius = other.backgroundBlurRadius;
634 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700635 if (other.what & eBlurRegionsChanged) {
636 what |= eBlurRegionsChanged;
637 blurRegions = other.blurRegions;
638 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700639 if (other.what & eRelativeLayerChanged) {
640 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700641 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700642 z = other.z;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800643 mNotDefCmpState.relativeLayerSurfaceControl =
644 other.mNotDefCmpState.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700645 }
646 if (other.what & eReparent) {
647 what |= eReparent;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800648 mNotDefCmpState.parentSurfaceControlForChild =
649 other.mNotDefCmpState.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700650 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000651 if (other.what & eBufferTransformChanged) {
652 what |= eBufferTransformChanged;
653 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700654 }
655 if (other.what & eTransformToDisplayInverseChanged) {
656 what |= eTransformToDisplayInverseChanged;
657 transformToDisplayInverse = other.transformToDisplayInverse;
658 }
659 if (other.what & eCropChanged) {
660 what |= eCropChanged;
661 crop = other.crop;
662 }
663 if (other.what & eBufferChanged) {
664 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500665 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700666 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000667 if (other.what & eTrustedPresentationInfoChanged) {
668 what |= eTrustedPresentationInfoChanged;
669 trustedPresentationListener = other.trustedPresentationListener;
670 trustedPresentationThresholds = other.trustedPresentationThresholds;
671 }
Marissa Wall61c58622018-07-18 10:12:20 -0700672 if (other.what & eDataspaceChanged) {
673 what |= eDataspaceChanged;
674 dataspace = other.dataspace;
675 }
John Reck68796592023-01-25 13:47:12 -0500676 if (other.what & eExtendedRangeBrightnessChanged) {
677 what |= eExtendedRangeBrightnessChanged;
Sally Qi963049b2023-03-23 14:06:21 -0700678 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
679 currentHdrSdrRatio = other.currentHdrSdrRatio;
John Reck68796592023-01-25 13:47:12 -0500680 }
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000681 if (other.what & eDesiredHdrHeadroomChanged) {
682 what |= eDesiredHdrHeadroomChanged;
683 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
684 }
Alec Mourif4af03e2023-02-11 00:25:24 +0000685 if (other.what & eCachingHintChanged) {
686 what |= eCachingHintChanged;
687 cachingHint = other.cachingHint;
688 }
Marissa Wall61c58622018-07-18 10:12:20 -0700689 if (other.what & eHdrMetadataChanged) {
690 what |= eHdrMetadataChanged;
691 hdrMetadata = other.hdrMetadata;
692 }
693 if (other.what & eSurfaceDamageRegionChanged) {
694 what |= eSurfaceDamageRegionChanged;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800695 mNotDefCmpState.surfaceDamageRegion = other.mNotDefCmpState.surfaceDamageRegion;
Marissa Wall61c58622018-07-18 10:12:20 -0700696 }
697 if (other.what & eApiChanged) {
698 what |= eApiChanged;
699 api = other.api;
700 }
701 if (other.what & eSidebandStreamChanged) {
702 what |= eSidebandStreamChanged;
703 sidebandStream = other.sidebandStream;
704 }
Peiyong Lind3788632018-09-18 16:01:31 -0700705 if (other.what & eColorTransformChanged) {
706 what |= eColorTransformChanged;
707 colorTransform = other.colorTransform;
708 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700709 if (other.what & eHasListenerCallbacksChanged) {
710 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700711 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700712 if (other.what & eInputInfoChanged) {
713 what |= eInputInfoChanged;
Anton Ivanovc7f87932025-02-25 00:58:09 -0800714 mNotDefCmpState.windowInfoHandle =
715 sp<WindowInfoHandle>::make(*other.mNotDefCmpState.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700716 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800717 if (other.what & eBackgroundColorChanged) {
718 what |= eBackgroundColorChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000719 bgColor = other.bgColor;
Valerie Haudd0b7572019-01-29 14:59:27 -0800720 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800721 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800722 if (other.what & eMetadataChanged) {
723 what |= eMetadataChanged;
724 metadata.merge(other.metadata);
725 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700726 if (other.what & eShadowRadiusChanged) {
727 what |= eShadowRadiusChanged;
728 shadowRadius = other.shadowRadius;
729 }
Sally Qi0abc4a52024-09-26 16:13:06 -0700730 if (other.what & eLutsChanged) {
731 what |= eLutsChanged;
732 luts = other.luts;
733 }
Andy Labrada096227e2022-06-15 16:58:11 +0000734 if (other.what & eDefaultFrameRateCompatibilityChanged) {
735 what |= eDefaultFrameRateCompatibilityChanged;
736 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
737 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100738 if (other.what & eFrameRateSelectionPriority) {
739 what |= eFrameRateSelectionPriority;
740 frameRateSelectionPriority = other.frameRateSelectionPriority;
741 }
Steven Thomas3172e202020-01-06 19:25:30 -0800742 if (other.what & eFrameRateChanged) {
743 what |= eFrameRateChanged;
744 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800745 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100746 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800747 }
Rachel Leece6e0042023-06-27 11:22:54 -0700748 if (other.what & eFrameRateCategoryChanged) {
749 what |= eFrameRateCategoryChanged;
750 frameRateCategory = other.frameRateCategory;
Rachel Lee67afbea2023-09-28 15:35:07 -0700751 frameRateCategorySmoothSwitchOnly = other.frameRateCategorySmoothSwitchOnly;
Rachel Leece6e0042023-06-27 11:22:54 -0700752 }
Rachel Lee58cc90d2023-09-05 18:50:20 -0700753 if (other.what & eFrameRateSelectionStrategyChanged) {
754 what |= eFrameRateSelectionStrategyChanged;
755 frameRateSelectionStrategy = other.frameRateSelectionStrategy;
756 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700757 if (other.what & eFixedTransformHintChanged) {
758 what |= eFixedTransformHintChanged;
759 fixedTransformHint = other.fixedTransformHint;
760 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800761 if (other.what & eAutoRefreshChanged) {
762 what |= eAutoRefreshChanged;
763 autoRefresh = other.autoRefresh;
764 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700765 if (other.what & eTrustedOverlayChanged) {
766 what |= eTrustedOverlayChanged;
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000767 trustedOverlay = other.trustedOverlay;
Winson Chunga30f7c92021-06-29 15:42:56 -0700768 }
John Reckc00c6692021-02-16 11:37:33 -0500769 if (other.what & eStretchChanged) {
770 what |= eStretchChanged;
771 stretchEffect = other.stretchEffect;
772 }
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000773 if (other.what & eEdgeExtensionChanged) {
774 what |= eEdgeExtensionChanged;
775 edgeExtensionParameters = other.edgeExtensionParameters;
776 }
chaviwf3f40fe2021-04-27 15:54:02 -0500777 if (other.what & eBufferCropChanged) {
778 what |= eBufferCropChanged;
779 bufferCrop = other.bufferCrop;
780 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700781 if (other.what & eDestinationFrameChanged) {
782 what |= eDestinationFrameChanged;
783 destinationFrame = other.destinationFrame;
784 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700785 if (other.what & eProducerDisconnect) {
786 what |= eProducerDisconnect;
787 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700788 if (other.what & eDropInputModeChanged) {
789 what |= eDropInputModeChanged;
790 dropInputMode = other.dropInputMode;
791 }
chaviw4c36cd82021-11-18 10:37:33 -0600792 if (other.what & eColorChanged) {
793 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000794 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600795 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800796 if (other.what & eColorSpaceAgnosticChanged) {
797 what |= eColorSpaceAgnosticChanged;
798 colorSpaceAgnostic = other.colorSpaceAgnostic;
799 }
Sally Qi81d95e62022-03-21 19:41:33 -0700800 if (other.what & eDimmingEnabledChanged) {
801 what |= eDimmingEnabledChanged;
802 dimmingEnabled = other.dimmingEnabled;
803 }
Pascal Muetschardb39918f2023-01-27 11:36:11 +0100804 if (other.what & eFlushJankData) {
805 what |= eFlushJankData;
806 }
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500807 if (other.what & eBufferReleaseChannelChanged) {
808 what |= eBufferReleaseChannelChanged;
809 bufferReleaseChannel = other.bufferReleaseChannel;
810 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600811 if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
812 if (other.what & ePictureProfileHandleChanged) {
813 what |= ePictureProfileHandleChanged;
814 pictureProfileHandle = other.pictureProfileHandle;
815 }
816 if (other.what & eAppContentPriorityChanged) {
817 what |= eAppContentPriorityChanged;
818 appContentPriority = other.appContentPriority;
819 }
820 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700821 if ((other.what & what) != other.what) {
822 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700823 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
824 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700825 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700826}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700827
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000828uint64_t layer_state_t::diff(const layer_state_t& other) const {
829 uint64_t diff = 0;
830 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
831 if (other.what & eLayerChanged) {
832 diff |= eLayerChanged;
833 diff &= ~eRelativeLayerChanged;
834 }
835 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
836 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
837 if (other.what & eTransparentRegionChanged &&
Anton Ivanovc7f87932025-02-25 00:58:09 -0800838 (!mNotDefCmpState.transparentRegion.hasSameRects(
839 other.mNotDefCmpState.transparentRegion))) {
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000840 diff |= eTransparentRegionChanged;
841 }
842 if (other.what & eFlagsChanged) {
843 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
844 if (changedFlags) diff |= eFlagsChanged;
845 }
846 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
847 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
Surbhi Kadam9674ffa2024-11-14 23:06:27 +0000848 CHECK_DIFF(diff, eClientDrawnCornerRadiusChanged, other, clientDrawnCornerRadius);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000849 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
850 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
851 if (other.what & eRelativeLayerChanged) {
852 diff |= eRelativeLayerChanged;
853 diff &= ~eLayerChanged;
854 }
855 if (other.what & eReparent &&
Anton Ivanovc7f87932025-02-25 00:58:09 -0800856 !SurfaceControl::isSameSurface(mNotDefCmpState.parentSurfaceControlForChild,
857 other.mNotDefCmpState.parentSurfaceControlForChild)) {
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000858 diff |= eReparent;
859 }
860 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
861 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
862 CHECK_DIFF(diff, eCropChanged, other, crop);
863 if (other.what & eBufferChanged) diff |= eBufferChanged;
864 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
Sally Qi963049b2023-03-23 14:06:21 -0700865 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio,
866 desiredHdrSdrRatio);
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000867 CHECK_DIFF(diff, eDesiredHdrHeadroomChanged, other, desiredHdrSdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000868 CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000869 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
870 if (other.what & eSurfaceDamageRegionChanged &&
Anton Ivanovc7f87932025-02-25 00:58:09 -0800871 (!mNotDefCmpState.surfaceDamageRegion.hasSameRects(
872 other.mNotDefCmpState.surfaceDamageRegion))) {
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000873 diff |= eSurfaceDamageRegionChanged;
874 }
875 CHECK_DIFF(diff, eApiChanged, other, api);
876 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
877 CHECK_DIFF(diff, eApiChanged, other, api);
878 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
879 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
880 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000881 CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000882 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
883 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000884 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
885 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
886 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
887 changeFrameRateStrategy);
Rachel Lee67afbea2023-09-28 15:35:07 -0700888 CHECK_DIFF2(diff, eFrameRateCategoryChanged, other, frameRateCategory,
889 frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700890 CHECK_DIFF(diff, eFrameRateSelectionStrategyChanged, other, frameRateSelectionStrategy);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000891 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
892 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000893 CHECK_DIFF(diff, eTrustedOverlayChanged, other, trustedOverlay);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000894 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000895 CHECK_DIFF(diff, eEdgeExtensionChanged, other, edgeExtensionParameters);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000896 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
897 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
898 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
899 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
900 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
901 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
902 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500903 if (other.what & eBufferReleaseChannelChanged) diff |= eBufferReleaseChannelChanged;
Sally Qi0abc4a52024-09-26 16:13:06 -0700904 if (other.what & eLutsChanged) diff |= eLutsChanged;
Brian Lindahl07dcd492024-10-30 11:43:23 -0600905 CHECK_DIFF(diff, ePictureProfileHandleChanged, other, pictureProfileHandle);
906 CHECK_DIFF(diff, eAppContentPriorityChanged, other, appContentPriority);
Sally Qi0abc4a52024-09-26 16:13:06 -0700907
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000908 return diff;
909}
910
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700911bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500912 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700913}
914
Ady Abraham6e8e3642021-07-08 19:44:07 -0700915bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700916 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700917}
918
chaviw308ddba2020-08-11 16:23:51 -0700919status_t layer_state_t::matrix22_t::write(Parcel& output) const {
920 SAFE_PARCEL(output.writeFloat, dsdx);
921 SAFE_PARCEL(output.writeFloat, dtdx);
922 SAFE_PARCEL(output.writeFloat, dtdy);
923 SAFE_PARCEL(output.writeFloat, dsdy);
924 return NO_ERROR;
925}
926
927status_t layer_state_t::matrix22_t::read(const Parcel& input) {
928 SAFE_PARCEL(input.readFloat, &dsdx);
929 SAFE_PARCEL(input.readFloat, &dtdx);
930 SAFE_PARCEL(input.readFloat, &dtdy);
931 SAFE_PARCEL(input.readFloat, &dsdy);
932 return NO_ERROR;
933}
Anton Ivanovc7f87932025-02-25 00:58:09 -0800934void layer_state_t::updateTransparentRegion(const Region& transparentRegion) {
935 what |= eTransparentRegionChanged;
936 mNotDefCmpState.transparentRegion = transparentRegion;
937}
938void layer_state_t::updateSurfaceDamageRegion(const Region& surfaceDamageRegion) {
939 what |= eSurfaceDamageRegionChanged;
940 mNotDefCmpState.surfaceDamageRegion = surfaceDamageRegion;
941}
942void layer_state_t::updateRelativeLayer(const sp<SurfaceControl>& relativeTo, int32_t z) {
943 what |= layer_state_t::eRelativeLayerChanged;
944 what &= ~layer_state_t::eLayerChanged;
945 mNotDefCmpState.relativeLayerSurfaceControl = relativeTo;
946 this->z = z;
947}
948void layer_state_t::updateParentLayer(const sp<SurfaceControl>& newParent) {
949 what |= layer_state_t::eReparent;
950 mNotDefCmpState.parentSurfaceControlForChild =
951 newParent ? newParent->getParentingLayer() : nullptr;
952}
953void layer_state_t::updateInputWindowInfo(sp<gui::WindowInfoHandle>&& info) {
954 what |= eInputInfoChanged;
955 mNotDefCmpState.windowInfoHandle = std::move(info);
956}
957
958bool layer_state_t::NotDefaultComparableState::operator==(
959 const NotDefaultComparableState& rhs) const {
960 return transparentRegion.hasSameRects(rhs.transparentRegion) &&
961 surfaceDamageRegion.hasSameRects(rhs.surfaceDamageRegion) &&
962 isSameWindowHandle(windowInfoHandle, rhs.windowInfoHandle) &&
963 isSameSurfaceControl(relativeLayerSurfaceControl, rhs.relativeLayerSurfaceControl) &&
964 isSameSurfaceControl(parentSurfaceControlForChild, rhs.parentSurfaceControlForChild);
965}
chaviw308ddba2020-08-11 16:23:51 -0700966
chaviw273171b2018-12-26 11:46:30 -0800967// ------------------------------- InputWindowCommands ----------------------------------------
968
Vishnu Naire798b472020-07-23 13:52:21 -0700969bool InputWindowCommands::merge(const InputWindowCommands& other) {
970 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700971 changes |= !other.focusRequests.empty();
972 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
973 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000974 changes |= !other.windowInfosReportedListeners.empty();
975 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
976 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700977 return changes;
chaviw273171b2018-12-26 11:46:30 -0800978}
979
Vishnu Nair958da932020-08-21 17:12:37 -0700980bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000981 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700982}
983
chaviw273171b2018-12-26 11:46:30 -0800984void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700985 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000986 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800987}
988
chaviw308ddba2020-08-11 16:23:51 -0700989status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700990 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000991
992 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
993 for (const auto& listener : windowInfosReportedListeners) {
994 SAFE_PARCEL(output.writeStrongBinder, listener);
995 }
996
chaviw308ddba2020-08-11 16:23:51 -0700997 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800998}
999
chaviw308ddba2020-08-11 16:23:51 -07001000status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -07001001 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +00001002
1003 int listenerSize = 0;
1004 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
1005 windowInfosReportedListeners.reserve(listenerSize);
1006 for (int i = 0; i < listenerSize; i++) {
1007 sp<gui::IWindowInfosReportedListener> listener;
1008 SAFE_PARCEL(input.readStrongBinder, &listener);
1009 windowInfosReportedListeners.insert(listener);
1010 }
1011
chaviw308ddba2020-08-11 16:23:51 -07001012 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -08001013}
1014
chaviw618c42d2020-07-24 15:25:08 -07001015// ----------------------------------------------------------------------------
1016
chaviw8dd181f2022-01-05 18:36:46 -06001017ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -05001018 uint64_t bufferId;
1019 if (buffer) {
1020 bufferId = buffer->getId();
1021 } else {
1022 bufferId = cachedBuffer.id;
1023 }
1024 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -06001025}
1026
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001027status_t BufferData::writeToParcel(Parcel* output) const {
1028 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -05001029
1030 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001031 SAFE_PARCEL(output->writeBool, true);
1032 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -05001033 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001034 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -05001035 }
1036
1037 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001038 SAFE_PARCEL(output->writeBool, true);
1039 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -05001040 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001041 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -05001042 }
1043
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001044 SAFE_PARCEL(output->writeUint64, frameNumber);
1045 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
1046 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001047
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001048 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
1049 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -08001050 SAFE_PARCEL(output->writeBool, hasBarrier);
1051 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001052 SAFE_PARCEL(output->writeUint32, producerId);
Nergi Rahardi39f510f2024-05-23 15:16:54 +09001053 SAFE_PARCEL(output->writeInt64, dequeueTime);
chaviwba4320c2021-09-15 15:20:53 -05001054
1055 return NO_ERROR;
1056}
1057
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001058status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -05001059 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001060 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -07001061 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -05001062
1063 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001064 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001065 if (tmpBool) {
Anton Ivanov8ed86592025-02-20 11:52:50 -08001066 buffer = sp<GraphicBuffer>::make();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001067 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -05001068 }
1069
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001070 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001071 if (tmpBool) {
Anton Ivanov8ed86592025-02-20 11:52:50 -08001072 acquireFence = sp<Fence>::make();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001073 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -05001074 }
1075
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001076 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -05001077
1078 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001079 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001080 if (tmpBinder) {
1081 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1082 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001083 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001084
1085 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001086 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001087 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001088 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -05001089
Robert Carr79dc06a2022-02-22 15:28:59 -08001090 SAFE_PARCEL(input->readBool, &hasBarrier);
1091 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001092 SAFE_PARCEL(input->readUint32, &producerId);
Nergi Rahardi39f510f2024-05-23 15:16:54 +09001093 SAFE_PARCEL(input->readInt64, &dequeueTime);
Robert Carr79dc06a2022-02-22 15:28:59 -08001094
chaviwba4320c2021-09-15 15:20:53 -05001095 return NO_ERROR;
1096}
1097
Chavi Weingarten076acac2023-01-19 17:20:43 +00001098status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
Anton Ivanovc7f87932025-02-25 00:58:09 -08001099 SAFE_PARCEL(parcel->writeStrongBinder, mState.callbackInterface);
1100 SAFE_PARCEL(parcel->writeInt32, mState.callbackId);
Chavi Weingarten076acac2023-01-19 17:20:43 +00001101 return NO_ERROR;
1102}
1103
1104status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1105 sp<IBinder> tmpBinder = nullptr;
1106 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1107 if (tmpBinder) {
Anton Ivanovc7f87932025-02-25 00:58:09 -08001108 mState.callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
Chavi Weingarten076acac2023-01-19 17:20:43 +00001109 }
Anton Ivanovc7f87932025-02-25 00:58:09 -08001110 SAFE_PARCEL(parcel->readInt32, &mState.callbackId);
Chavi Weingarten076acac2023-01-19 17:20:43 +00001111 return NO_ERROR;
1112}
1113
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001114}; // namespace android