blob: 139764ac0cacd3ebaeb5d8dc1b0a052c90dc3990 [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>
Ady Abraham6cdd3fd2023-09-07 18:45:58 -070024#include <gui/FrameRateUtils.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080025#include <gui/IGraphicBufferProducer.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070026#include <gui/LayerState.h>
Vishnu Nairaa799bd2022-11-16 23:09:09 +000027#include <gui/SurfaceControl.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010028#include <private/gui/ParcelUtils.h>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070029#include <system/window.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000030#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031
Vishnu Nairaa799bd2022-11-16 23:09:09 +000032#define CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD) \
33 { \
34 if ((OTHER.what & CHANGE_FLAG) && (FIELD != OTHER.FIELD)) { \
35 DIFF_RESULT |= CHANGE_FLAG; \
36 } \
37 }
38
39#define CHECK_DIFF2(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2) \
40 { \
41 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1) \
42 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2) \
43 }
44
45#define CHECK_DIFF3(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2, FIELD3) \
46 { \
47 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1) \
48 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2) \
49 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD3) \
50 }
51
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052namespace android {
53
chaviw98318de2021-05-19 16:45:23 -050054using gui::FocusRequest;
55using gui::WindowInfoHandle;
56
Pablo Gamito11dcc222020-09-12 15:49:39 +000057layer_state_t::layer_state_t()
Vishnu Nair685cfef2022-02-02 10:01:25 -080058 : surface(nullptr),
59 layerId(-1),
60 what(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000061 x(0),
62 y(0),
63 z(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000064 flags(0),
65 mask(0),
66 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000067 cornerRadius(0.0f),
68 backgroundBlurRadius(0),
Vishnu Nairbbceb462022-10-10 04:52:13 +000069 color(0),
70 bufferTransform(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000071 transformToDisplayInverse(false),
Vishnu Naira9123c82024-10-03 03:56:44 +000072 crop({0, 0, -1, -1}),
Pablo Gamito11dcc222020-09-12 15:49:39 +000073 dataspace(ui::Dataspace::UNKNOWN),
74 surfaceDamageRegion(),
75 api(-1),
76 colorTransform(mat4()),
Vishnu Naird47bcee2023-02-24 18:08:51 +000077 bgColor(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000078 bgColorDataspace(ui::Dataspace::UNKNOWN),
79 colorSpaceAgnostic(false),
80 shadowRadius(0.0f),
81 frameRateSelectionPriority(-1),
82 frameRate(0.0f),
83 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010084 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Andy Labrada096227e2022-06-15 16:58:11 +000085 defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Rachel Leece6e0042023-06-27 11:22:54 -070086 frameRateCategory(ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT),
Rachel Lee67afbea2023-09-28 15:35:07 -070087 frameRateCategorySmoothSwitchOnly(false),
Rachel Lee70f7b692023-11-22 11:24:02 -080088 frameRateSelectionStrategy(ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_PROPAGATE),
Pablo Gamito11dcc222020-09-12 15:49:39 +000089 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080090 autoRefresh(false),
Vishnu Nair9e0017e2024-05-22 19:02:44 +000091 trustedOverlay(gui::TrustedOverlay::UNSET),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070092 bufferCrop(Rect::INVALID_RECT),
93 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070094 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000095 matrix.dsdx = matrix.dtdy = 1.0f;
96 matrix.dsdy = matrix.dtdx = 0.0f;
97 hdrMetadata.validTypes = 0;
98}
99
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100status_t layer_state_t::write(Parcel& output) const
101{
chaviw308ddba2020-08-11 16:23:51 -0700102 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000103 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -0700104 SAFE_PARCEL(output.writeUint64, what);
105 SAFE_PARCEL(output.writeFloat, x);
106 SAFE_PARCEL(output.writeFloat, y);
107 SAFE_PARCEL(output.writeInt32, z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700108 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700109 SAFE_PARCEL(output.writeUint32, flags);
110 SAFE_PARCEL(output.writeUint32, mask);
111 SAFE_PARCEL(matrix.write, output);
Vishnu Naira9123c82024-10-03 03:56:44 +0000112 SAFE_PARCEL(output.writeFloat, crop.top);
113 SAFE_PARCEL(output.writeFloat, crop.left);
114 SAFE_PARCEL(output.writeFloat, crop.bottom);
115 SAFE_PARCEL(output.writeFloat, crop.right);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000116 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
117 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -0700118 SAFE_PARCEL(output.writeFloat, color.r);
119 SAFE_PARCEL(output.writeFloat, color.g);
120 SAFE_PARCEL(output.writeFloat, color.b);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000121 SAFE_PARCEL(output.writeFloat, color.a);
chaviw98318de2021-05-19 16:45:23 -0500122 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700123 SAFE_PARCEL(output.write, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000124 SAFE_PARCEL(output.writeUint32, bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700125 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700126 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
127 SAFE_PARCEL(output.write, hdrMetadata);
128 SAFE_PARCEL(output.write, surfaceDamageRegion);
129 SAFE_PARCEL(output.writeInt32, api);
130
Marissa Wall61c58622018-07-18 10:12:20 -0700131 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700132 SAFE_PARCEL(output.writeBool, true);
133 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700134 } else {
chaviw308ddba2020-08-11 16:23:51 -0700135 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700136 }
137
chaviw308ddba2020-08-11 16:23:51 -0700138 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
139 SAFE_PARCEL(output.writeFloat, cornerRadius);
140 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700141 SAFE_PARCEL(output.writeParcelable, metadata);
Vishnu Naird47bcee2023-02-24 18:08:51 +0000142 SAFE_PARCEL(output.writeFloat, bgColor.r);
143 SAFE_PARCEL(output.writeFloat, bgColor.g);
144 SAFE_PARCEL(output.writeFloat, bgColor.b);
145 SAFE_PARCEL(output.writeFloat, bgColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700146 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
147 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
148 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700149
150 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700151 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700152 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700153 }
chaviw308ddba2020-08-11 16:23:51 -0700154 SAFE_PARCEL(output.writeFloat, shadowRadius);
155 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
156 SAFE_PARCEL(output.writeFloat, frameRate);
157 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100158 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000159 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700160 SAFE_PARCEL(output.writeByte, frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700161 SAFE_PARCEL(output.writeBool, frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700162 SAFE_PARCEL(output.writeByte, frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700163 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800164 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700165 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700166
167 SAFE_PARCEL(output.writeUint32, blurRegions.size());
168 for (auto region : blurRegions) {
169 SAFE_PARCEL(output.writeUint32, region.blurRadius);
170 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
171 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
172 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
173 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
174 SAFE_PARCEL(output.writeFloat, region.alpha);
175 SAFE_PARCEL(output.writeInt32, region.left);
176 SAFE_PARCEL(output.writeInt32, region.top);
177 SAFE_PARCEL(output.writeInt32, region.right);
178 SAFE_PARCEL(output.writeInt32, region.bottom);
179 }
John Reckcdb4ed72021-02-04 13:39:33 -0500180
181 SAFE_PARCEL(output.write, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000182 SAFE_PARCEL(output.writeParcelable, edgeExtensionParameters);
chaviwf3f40fe2021-04-27 15:54:02 -0500183 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700184 SAFE_PARCEL(output.write, destinationFrame);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000185 SAFE_PARCEL(output.writeInt32, static_cast<uint32_t>(trustedOverlay));
John Reckcdb4ed72021-02-04 13:39:33 -0500186
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700187 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800188
189 const bool hasBufferData = (bufferData != nullptr);
190 SAFE_PARCEL(output.writeBool, hasBufferData);
191 if (hasBufferData) {
192 SAFE_PARCEL(output.writeParcelable, *bufferData);
193 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000194 SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds);
195 SAFE_PARCEL(output.writeParcelable, trustedPresentationListener);
Sally Qi963049b2023-03-23 14:06:21 -0700196 SAFE_PARCEL(output.writeFloat, currentHdrSdrRatio);
197 SAFE_PARCEL(output.writeFloat, desiredHdrSdrRatio);
Vishnu Nair59a6be32024-01-29 10:26:21 -0800198 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(cachingHint));
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500199
200 const bool hasBufferReleaseChannel = (bufferReleaseChannel != nullptr);
201 SAFE_PARCEL(output.writeBool, hasBufferReleaseChannel);
202 if (hasBufferReleaseChannel) {
203 SAFE_PARCEL(output.writeParcelable, *bufferReleaseChannel);
204 }
205
Sally Qief006582024-10-11 13:23:09 -0700206 const bool hasLuts = (luts != nullptr);
207 SAFE_PARCEL(output.writeBool, hasLuts);
208 if (hasLuts) {
209 SAFE_PARCEL(output.writeParcelable, *luts);
210 }
211
Mathias Agopianac9fa422013-02-11 16:40:36 -0800212 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800213}
214
215status_t layer_state_t::read(const Parcel& input)
216{
chaviw308ddba2020-08-11 16:23:51 -0700217 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000218 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700219 SAFE_PARCEL(input.readUint64, &what);
220 SAFE_PARCEL(input.readFloat, &x);
221 SAFE_PARCEL(input.readFloat, &y);
222 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700223 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700224
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800225 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700226
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800227 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700228
229 SAFE_PARCEL(matrix.read, input);
Vishnu Naira9123c82024-10-03 03:56:44 +0000230 SAFE_PARCEL(input.readFloat, &crop.top);
231 SAFE_PARCEL(input.readFloat, &crop.left);
232 SAFE_PARCEL(input.readFloat, &crop.bottom);
233 SAFE_PARCEL(input.readFloat, &crop.right);
chaviw308ddba2020-08-11 16:23:51 -0700234
Pablo Gamito11dcc222020-09-12 15:49:39 +0000235 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
236 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
237
chaviw308ddba2020-08-11 16:23:51 -0700238 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700239 SAFE_PARCEL(input.readFloat, &tmpFloat);
240 color.r = tmpFloat;
241 SAFE_PARCEL(input.readFloat, &tmpFloat);
242 color.g = tmpFloat;
243 SAFE_PARCEL(input.readFloat, &tmpFloat);
244 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000245 SAFE_PARCEL(input.readFloat, &tmpFloat);
246 color.a = tmpFloat;
247
chaviw98318de2021-05-19 16:45:23 -0500248 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700249
chaviw308ddba2020-08-11 16:23:51 -0700250 SAFE_PARCEL(input.read, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000251 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700252 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700253
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800254 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700255 SAFE_PARCEL(input.readUint32, &tmpUint32);
256 dataspace = static_cast<ui::Dataspace>(tmpUint32);
257
258 SAFE_PARCEL(input.read, hdrMetadata);
259 SAFE_PARCEL(input.read, surfaceDamageRegion);
260 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500261
262 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700263 SAFE_PARCEL(input.readBool, &tmpBool);
264 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700265 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
266 }
267
chaviw308ddba2020-08-11 16:23:51 -0700268 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
269 SAFE_PARCEL(input.readFloat, &cornerRadius);
270 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700271 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800272
Vishnu Naird47bcee2023-02-24 18:08:51 +0000273 SAFE_PARCEL(input.readFloat, &tmpFloat);
274 bgColor.r = tmpFloat;
275 SAFE_PARCEL(input.readFloat, &tmpFloat);
276 bgColor.g = tmpFloat;
277 SAFE_PARCEL(input.readFloat, &tmpFloat);
278 bgColor.b = tmpFloat;
279 SAFE_PARCEL(input.readFloat, &tmpFloat);
280 bgColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700281 SAFE_PARCEL(input.readUint32, &tmpUint32);
282 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
283 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800284
chaviw308ddba2020-08-11 16:23:51 -0700285 int32_t numListeners = 0;
286 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700287 listeners.clear();
288 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700289 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700290 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700291 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700292 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700293 listeners.emplace_back(listener, callbackIds);
294 }
chaviw308ddba2020-08-11 16:23:51 -0700295 SAFE_PARCEL(input.readFloat, &shadowRadius);
296 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
297 SAFE_PARCEL(input.readFloat, &frameRate);
298 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100299 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000300 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700301 SAFE_PARCEL(input.readByte, &frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700302 SAFE_PARCEL(input.readBool, &frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700303 SAFE_PARCEL(input.readByte, &frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700304 SAFE_PARCEL(input.readUint32, &tmpUint32);
305 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800306 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700307 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700308
309 uint32_t numRegions = 0;
310 SAFE_PARCEL(input.readUint32, &numRegions);
311 blurRegions.clear();
312 for (uint32_t i = 0; i < numRegions; i++) {
313 BlurRegion region;
314 SAFE_PARCEL(input.readUint32, &region.blurRadius);
315 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
316 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
317 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
318 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
319 SAFE_PARCEL(input.readFloat, &region.alpha);
320 SAFE_PARCEL(input.readInt32, &region.left);
321 SAFE_PARCEL(input.readInt32, &region.top);
322 SAFE_PARCEL(input.readInt32, &region.right);
323 SAFE_PARCEL(input.readInt32, &region.bottom);
324 blurRegions.push_back(region);
325 }
John Reckcdb4ed72021-02-04 13:39:33 -0500326
327 SAFE_PARCEL(input.read, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000328 SAFE_PARCEL(input.readParcelable, &edgeExtensionParameters);
chaviwf3f40fe2021-04-27 15:54:02 -0500329 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700330 SAFE_PARCEL(input.read, destinationFrame);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000331 uint32_t trustedOverlayInt;
332 SAFE_PARCEL(input.readUint32, &trustedOverlayInt);
333 trustedOverlay = static_cast<gui::TrustedOverlay>(trustedOverlayInt);
John Reckcdb4ed72021-02-04 13:39:33 -0500334
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700335 uint32_t mode;
336 SAFE_PARCEL(input.readUint32, &mode);
337 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800338
339 bool hasBufferData;
340 SAFE_PARCEL(input.readBool, &hasBufferData);
341 if (hasBufferData) {
342 bufferData = std::make_shared<BufferData>();
343 SAFE_PARCEL(input.readParcelable, bufferData.get());
344 } else {
345 bufferData = nullptr;
346 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000347
348 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
349 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
350
John Reck68796592023-01-25 13:47:12 -0500351 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700352 currentHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500353 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700354 desiredHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500355
Alec Mourif4af03e2023-02-11 00:25:24 +0000356 int32_t tmpInt32;
357 SAFE_PARCEL(input.readInt32, &tmpInt32);
358 cachingHint = static_cast<gui::CachingHint>(tmpInt32);
359
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500360 bool hasBufferReleaseChannel;
361 SAFE_PARCEL(input.readBool, &hasBufferReleaseChannel);
362 if (hasBufferReleaseChannel) {
363 bufferReleaseChannel = std::make_shared<gui::BufferReleaseChannel::ProducerEndpoint>();
364 SAFE_PARCEL(input.readParcelable, bufferReleaseChannel.get());
365 }
366
Sally Qief006582024-10-11 13:23:09 -0700367 bool hasLuts;
368 SAFE_PARCEL(input.readBool, &hasLuts);
369 if (hasLuts) {
370 luts = std::make_shared<gui::DisplayLuts>();
371 SAFE_PARCEL(input.readParcelable, luts.get());
372 } else {
373 luts = nullptr;
374 }
375
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800376 return NO_ERROR;
377}
378
Mathias Agopian698c0872011-06-28 19:09:31 -0700379status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700380 return state.write(output);
381}
382
383status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700384 return state.read(input);
385}
386
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700387DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700388
Mathias Agopian8b33f032012-07-24 20:43:54 -0700389status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700390 SAFE_PARCEL(output.writeStrongBinder, token);
391 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
392 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700393 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700394 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700395 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
396 SAFE_PARCEL(output.write, layerStackSpaceRect);
397 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
398 SAFE_PARCEL(output.writeUint32, width);
399 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700400 return NO_ERROR;
401}
402
403status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700404 SAFE_PARCEL(input.readStrongBinder, &token);
405 sp<IBinder> tmpBinder;
406 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
407 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
408
409 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700410 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700411 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700412 uint32_t tmpUint = 0;
413 SAFE_PARCEL(input.readUint32, &tmpUint);
414 orientation = ui::toRotation(tmpUint);
415
416 SAFE_PARCEL(input.read, layerStackSpaceRect);
417 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
418 SAFE_PARCEL(input.readUint32, &width);
419 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700420 return NO_ERROR;
421}
422
Robert Carr2c5f6d22017-09-26 12:30:35 -0700423void DisplayState::merge(const DisplayState& other) {
424 if (other.what & eSurfaceChanged) {
425 what |= eSurfaceChanged;
426 surface = other.surface;
427 }
428 if (other.what & eLayerStackChanged) {
429 what |= eLayerStackChanged;
430 layerStack = other.layerStack;
431 }
Evan Rosky2239b372021-05-20 13:43:47 -0700432 if (other.what & eFlagsChanged) {
433 what |= eFlagsChanged;
434 flags = other.flags;
435 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700436 if (other.what & eDisplayProjectionChanged) {
437 what |= eDisplayProjectionChanged;
438 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200439 layerStackSpaceRect = other.layerStackSpaceRect;
440 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700441 }
442 if (other.what & eDisplaySizeChanged) {
443 what |= eDisplaySizeChanged;
444 width = other.width;
445 height = other.height;
446 }
447}
448
Sally Qi6bb12822022-10-05 11:42:30 -0700449void DisplayState::sanitize(int32_t permissions) {
450 if (what & DisplayState::eLayerStackChanged) {
451 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
452 what &= ~DisplayState::eLayerStackChanged;
453 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
454 }
455 }
456 if (what & DisplayState::eDisplayProjectionChanged) {
457 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
458 what &= ~DisplayState::eDisplayProjectionChanged;
459 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
460 }
461 }
462 if (what & DisplayState::eSurfaceChanged) {
463 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
464 what &= ~DisplayState::eSurfaceChanged;
465 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
466 }
467 }
468}
469
Robert Carrde6d7b42022-01-07 18:23:06 -0800470void layer_state_t::sanitize(int32_t permissions) {
471 // TODO: b/109894387
472 //
473 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
474 // rotation. To see the problem observe that if we have a square parent, and a child
475 // of the same size, then we rotate the child 45 degrees around its center, the child
476 // must now be cropped to a non rectangular 8 sided region.
477 //
478 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
479 // private API, and arbitrary rotation is used in limited use cases, for instance:
480 // - WindowManager only uses rotation in one case, which is on a top level layer in which
481 // cropping is not an issue.
482 // - Launcher, as a privileged app, uses this to transition an application to PiP
483 // (picture-in-picture) mode.
484 //
485 // However given that abuse of rotation matrices could lead to surfaces extending outside
486 // of cropped areas, we need to prevent non-root clients without permission
487 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
488 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
489 // preserving transformations.
490 if (what & eMatrixChanged) {
491 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
492 ui::Transform t;
493 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
494 if (!t.preserveRects()) {
495 what &= ~eMatrixChanged;
496 ALOGE("Stripped non rect preserving matrix in sanitize");
497 }
498 }
499 }
500
501 if (what & eFlagsChanged) {
502 if ((flags & eLayerIsDisplayDecoration) &&
503 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
504 flags &= ~eLayerIsDisplayDecoration;
505 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
506 }
Vishnu Nair59a6be32024-01-29 10:26:21 -0800507 if ((mask & eCanOccludePresentation) &&
508 !(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
509 flags &= ~eCanOccludePresentation;
510 mask &= ~eCanOccludePresentation;
511 ALOGE("Stripped attempt to set eCanOccludePresentation in sanitize");
512 }
Robert Carrde6d7b42022-01-07 18:23:06 -0800513 }
514
515 if (what & layer_state_t::eInputInfoChanged) {
516 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
517 what &= ~eInputInfoChanged;
518 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
519 }
520 }
521 if (what & layer_state_t::eTrustedOverlayChanged) {
522 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
523 what &= ~eTrustedOverlayChanged;
524 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
525 }
526 }
527 if (what & layer_state_t::eDropInputModeChanged) {
528 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
529 what &= ~eDropInputModeChanged;
530 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
531 }
532 }
533 if (what & layer_state_t::eFrameRateSelectionPriority) {
534 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
535 what &= ~eFrameRateSelectionPriority;
536 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
537 }
538 }
539 if (what & layer_state_t::eFrameRateChanged) {
540 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
541 changeFrameRateStrategy,
542 "layer_state_t::sanitize",
543 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
544 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
545 }
546 }
547}
548
Robert Carr2c5f6d22017-09-26 12:30:35 -0700549void layer_state_t::merge(const layer_state_t& other) {
550 if (other.what & ePositionChanged) {
551 what |= ePositionChanged;
552 x = other.x;
553 y = other.y;
554 }
555 if (other.what & eLayerChanged) {
556 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700557 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700558 z = other.z;
559 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700560 if (other.what & eAlphaChanged) {
561 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000562 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700563 }
564 if (other.what & eMatrixChanged) {
565 what |= eMatrixChanged;
566 matrix = other.matrix;
567 }
568 if (other.what & eTransparentRegionChanged) {
569 what |= eTransparentRegionChanged;
570 transparentRegion = other.transparentRegion;
571 }
572 if (other.what & eFlagsChanged) {
573 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700574 flags &= ~other.mask;
575 flags |= (other.flags & other.mask);
576 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700577 }
578 if (other.what & eLayerStackChanged) {
579 what |= eLayerStackChanged;
580 layerStack = other.layerStack;
581 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700582 if (other.what & eCornerRadiusChanged) {
583 what |= eCornerRadiusChanged;
584 cornerRadius = other.cornerRadius;
585 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800586 if (other.what & eBackgroundBlurRadiusChanged) {
587 what |= eBackgroundBlurRadiusChanged;
588 backgroundBlurRadius = other.backgroundBlurRadius;
589 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700590 if (other.what & eBlurRegionsChanged) {
591 what |= eBlurRegionsChanged;
592 blurRegions = other.blurRegions;
593 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700594 if (other.what & eRelativeLayerChanged) {
595 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700596 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700597 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000598 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700599 }
600 if (other.what & eReparent) {
601 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000602 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700603 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000604 if (other.what & eBufferTransformChanged) {
605 what |= eBufferTransformChanged;
606 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700607 }
608 if (other.what & eTransformToDisplayInverseChanged) {
609 what |= eTransformToDisplayInverseChanged;
610 transformToDisplayInverse = other.transformToDisplayInverse;
611 }
612 if (other.what & eCropChanged) {
613 what |= eCropChanged;
614 crop = other.crop;
615 }
616 if (other.what & eBufferChanged) {
617 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500618 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700619 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000620 if (other.what & eTrustedPresentationInfoChanged) {
621 what |= eTrustedPresentationInfoChanged;
622 trustedPresentationListener = other.trustedPresentationListener;
623 trustedPresentationThresholds = other.trustedPresentationThresholds;
624 }
Marissa Wall61c58622018-07-18 10:12:20 -0700625 if (other.what & eDataspaceChanged) {
626 what |= eDataspaceChanged;
627 dataspace = other.dataspace;
628 }
John Reck68796592023-01-25 13:47:12 -0500629 if (other.what & eExtendedRangeBrightnessChanged) {
630 what |= eExtendedRangeBrightnessChanged;
Sally Qi963049b2023-03-23 14:06:21 -0700631 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
632 currentHdrSdrRatio = other.currentHdrSdrRatio;
John Reck68796592023-01-25 13:47:12 -0500633 }
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000634 if (other.what & eDesiredHdrHeadroomChanged) {
635 what |= eDesiredHdrHeadroomChanged;
636 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
637 }
Alec Mourif4af03e2023-02-11 00:25:24 +0000638 if (other.what & eCachingHintChanged) {
639 what |= eCachingHintChanged;
640 cachingHint = other.cachingHint;
641 }
Marissa Wall61c58622018-07-18 10:12:20 -0700642 if (other.what & eHdrMetadataChanged) {
643 what |= eHdrMetadataChanged;
644 hdrMetadata = other.hdrMetadata;
645 }
646 if (other.what & eSurfaceDamageRegionChanged) {
647 what |= eSurfaceDamageRegionChanged;
648 surfaceDamageRegion = other.surfaceDamageRegion;
649 }
650 if (other.what & eApiChanged) {
651 what |= eApiChanged;
652 api = other.api;
653 }
654 if (other.what & eSidebandStreamChanged) {
655 what |= eSidebandStreamChanged;
656 sidebandStream = other.sidebandStream;
657 }
Peiyong Lind3788632018-09-18 16:01:31 -0700658 if (other.what & eColorTransformChanged) {
659 what |= eColorTransformChanged;
660 colorTransform = other.colorTransform;
661 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700662 if (other.what & eHasListenerCallbacksChanged) {
663 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700664 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700665 if (other.what & eInputInfoChanged) {
666 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500667 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700668 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800669 if (other.what & eBackgroundColorChanged) {
670 what |= eBackgroundColorChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000671 bgColor = other.bgColor;
Valerie Haudd0b7572019-01-29 14:59:27 -0800672 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800673 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800674 if (other.what & eMetadataChanged) {
675 what |= eMetadataChanged;
676 metadata.merge(other.metadata);
677 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700678 if (other.what & eShadowRadiusChanged) {
679 what |= eShadowRadiusChanged;
680 shadowRadius = other.shadowRadius;
681 }
Sally Qi0abc4a52024-09-26 16:13:06 -0700682 if (other.what & eLutsChanged) {
683 what |= eLutsChanged;
684 luts = other.luts;
685 }
Andy Labrada096227e2022-06-15 16:58:11 +0000686 if (other.what & eDefaultFrameRateCompatibilityChanged) {
687 what |= eDefaultFrameRateCompatibilityChanged;
688 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
689 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100690 if (other.what & eFrameRateSelectionPriority) {
691 what |= eFrameRateSelectionPriority;
692 frameRateSelectionPriority = other.frameRateSelectionPriority;
693 }
Steven Thomas3172e202020-01-06 19:25:30 -0800694 if (other.what & eFrameRateChanged) {
695 what |= eFrameRateChanged;
696 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800697 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100698 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800699 }
Rachel Leece6e0042023-06-27 11:22:54 -0700700 if (other.what & eFrameRateCategoryChanged) {
701 what |= eFrameRateCategoryChanged;
702 frameRateCategory = other.frameRateCategory;
Rachel Lee67afbea2023-09-28 15:35:07 -0700703 frameRateCategorySmoothSwitchOnly = other.frameRateCategorySmoothSwitchOnly;
Rachel Leece6e0042023-06-27 11:22:54 -0700704 }
Rachel Lee58cc90d2023-09-05 18:50:20 -0700705 if (other.what & eFrameRateSelectionStrategyChanged) {
706 what |= eFrameRateSelectionStrategyChanged;
707 frameRateSelectionStrategy = other.frameRateSelectionStrategy;
708 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700709 if (other.what & eFixedTransformHintChanged) {
710 what |= eFixedTransformHintChanged;
711 fixedTransformHint = other.fixedTransformHint;
712 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800713 if (other.what & eAutoRefreshChanged) {
714 what |= eAutoRefreshChanged;
715 autoRefresh = other.autoRefresh;
716 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700717 if (other.what & eTrustedOverlayChanged) {
718 what |= eTrustedOverlayChanged;
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000719 trustedOverlay = other.trustedOverlay;
Winson Chunga30f7c92021-06-29 15:42:56 -0700720 }
John Reckc00c6692021-02-16 11:37:33 -0500721 if (other.what & eStretchChanged) {
722 what |= eStretchChanged;
723 stretchEffect = other.stretchEffect;
724 }
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000725 if (other.what & eEdgeExtensionChanged) {
726 what |= eEdgeExtensionChanged;
727 edgeExtensionParameters = other.edgeExtensionParameters;
728 }
chaviwf3f40fe2021-04-27 15:54:02 -0500729 if (other.what & eBufferCropChanged) {
730 what |= eBufferCropChanged;
731 bufferCrop = other.bufferCrop;
732 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700733 if (other.what & eDestinationFrameChanged) {
734 what |= eDestinationFrameChanged;
735 destinationFrame = other.destinationFrame;
736 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700737 if (other.what & eProducerDisconnect) {
738 what |= eProducerDisconnect;
739 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700740 if (other.what & eDropInputModeChanged) {
741 what |= eDropInputModeChanged;
742 dropInputMode = other.dropInputMode;
743 }
chaviw4c36cd82021-11-18 10:37:33 -0600744 if (other.what & eColorChanged) {
745 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000746 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600747 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800748 if (other.what & eColorSpaceAgnosticChanged) {
749 what |= eColorSpaceAgnosticChanged;
750 colorSpaceAgnostic = other.colorSpaceAgnostic;
751 }
Sally Qi81d95e62022-03-21 19:41:33 -0700752 if (other.what & eDimmingEnabledChanged) {
753 what |= eDimmingEnabledChanged;
754 dimmingEnabled = other.dimmingEnabled;
755 }
Pascal Muetschardb39918f2023-01-27 11:36:11 +0100756 if (other.what & eFlushJankData) {
757 what |= eFlushJankData;
758 }
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500759 if (other.what & eBufferReleaseChannelChanged) {
760 what |= eBufferReleaseChannelChanged;
761 bufferReleaseChannel = other.bufferReleaseChannel;
762 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700763 if ((other.what & what) != other.what) {
764 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700765 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
766 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700767 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700768}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700769
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000770uint64_t layer_state_t::diff(const layer_state_t& other) const {
771 uint64_t diff = 0;
772 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
773 if (other.what & eLayerChanged) {
774 diff |= eLayerChanged;
775 diff &= ~eRelativeLayerChanged;
776 }
777 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
778 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
779 if (other.what & eTransparentRegionChanged &&
780 (!transparentRegion.hasSameRects(other.transparentRegion))) {
781 diff |= eTransparentRegionChanged;
782 }
783 if (other.what & eFlagsChanged) {
784 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
785 if (changedFlags) diff |= eFlagsChanged;
786 }
787 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
788 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
789 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
790 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
791 if (other.what & eRelativeLayerChanged) {
792 diff |= eRelativeLayerChanged;
793 diff &= ~eLayerChanged;
794 }
795 if (other.what & eReparent &&
796 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
797 other.parentSurfaceControlForChild)) {
798 diff |= eReparent;
799 }
800 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
801 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
802 CHECK_DIFF(diff, eCropChanged, other, crop);
803 if (other.what & eBufferChanged) diff |= eBufferChanged;
804 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
Sally Qi963049b2023-03-23 14:06:21 -0700805 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio,
806 desiredHdrSdrRatio);
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000807 CHECK_DIFF(diff, eDesiredHdrHeadroomChanged, other, desiredHdrSdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000808 CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000809 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
810 if (other.what & eSurfaceDamageRegionChanged &&
811 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
812 diff |= eSurfaceDamageRegionChanged;
813 }
814 CHECK_DIFF(diff, eApiChanged, other, api);
815 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
816 CHECK_DIFF(diff, eApiChanged, other, api);
817 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
818 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
819 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000820 CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000821 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
822 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000823 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
824 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
825 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
826 changeFrameRateStrategy);
Rachel Lee67afbea2023-09-28 15:35:07 -0700827 CHECK_DIFF2(diff, eFrameRateCategoryChanged, other, frameRateCategory,
828 frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700829 CHECK_DIFF(diff, eFrameRateSelectionStrategyChanged, other, frameRateSelectionStrategy);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000830 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
831 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000832 CHECK_DIFF(diff, eTrustedOverlayChanged, other, trustedOverlay);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000833 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000834 CHECK_DIFF(diff, eEdgeExtensionChanged, other, edgeExtensionParameters);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000835 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
836 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
837 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
838 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
839 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
840 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
841 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500842 if (other.what & eBufferReleaseChannelChanged) diff |= eBufferReleaseChannelChanged;
Sally Qi0abc4a52024-09-26 16:13:06 -0700843 if (other.what & eLutsChanged) diff |= eLutsChanged;
844
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000845 return diff;
846}
847
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700848bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500849 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700850}
851
Ady Abraham6e8e3642021-07-08 19:44:07 -0700852bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700853 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700854}
855
chaviw308ddba2020-08-11 16:23:51 -0700856status_t layer_state_t::matrix22_t::write(Parcel& output) const {
857 SAFE_PARCEL(output.writeFloat, dsdx);
858 SAFE_PARCEL(output.writeFloat, dtdx);
859 SAFE_PARCEL(output.writeFloat, dtdy);
860 SAFE_PARCEL(output.writeFloat, dsdy);
861 return NO_ERROR;
862}
863
864status_t layer_state_t::matrix22_t::read(const Parcel& input) {
865 SAFE_PARCEL(input.readFloat, &dsdx);
866 SAFE_PARCEL(input.readFloat, &dtdx);
867 SAFE_PARCEL(input.readFloat, &dtdy);
868 SAFE_PARCEL(input.readFloat, &dsdy);
869 return NO_ERROR;
870}
871
chaviw273171b2018-12-26 11:46:30 -0800872// ------------------------------- InputWindowCommands ----------------------------------------
873
Vishnu Naire798b472020-07-23 13:52:21 -0700874bool InputWindowCommands::merge(const InputWindowCommands& other) {
875 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700876 changes |= !other.focusRequests.empty();
877 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
878 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000879 changes |= !other.windowInfosReportedListeners.empty();
880 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
881 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700882 return changes;
chaviw273171b2018-12-26 11:46:30 -0800883}
884
Vishnu Nair958da932020-08-21 17:12:37 -0700885bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000886 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700887}
888
chaviw273171b2018-12-26 11:46:30 -0800889void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700890 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000891 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800892}
893
chaviw308ddba2020-08-11 16:23:51 -0700894status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700895 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000896
897 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
898 for (const auto& listener : windowInfosReportedListeners) {
899 SAFE_PARCEL(output.writeStrongBinder, listener);
900 }
901
chaviw308ddba2020-08-11 16:23:51 -0700902 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800903}
904
chaviw308ddba2020-08-11 16:23:51 -0700905status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700906 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000907
908 int listenerSize = 0;
909 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
910 windowInfosReportedListeners.reserve(listenerSize);
911 for (int i = 0; i < listenerSize; i++) {
912 sp<gui::IWindowInfosReportedListener> listener;
913 SAFE_PARCEL(input.readStrongBinder, &listener);
914 windowInfosReportedListeners.insert(listener);
915 }
916
chaviw308ddba2020-08-11 16:23:51 -0700917 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800918}
919
chaviw618c42d2020-07-24 15:25:08 -0700920// ----------------------------------------------------------------------------
921
chaviw8dd181f2022-01-05 18:36:46 -0600922ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500923 uint64_t bufferId;
924 if (buffer) {
925 bufferId = buffer->getId();
926 } else {
927 bufferId = cachedBuffer.id;
928 }
929 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600930}
931
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800932status_t BufferData::writeToParcel(Parcel* output) const {
933 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500934
935 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800936 SAFE_PARCEL(output->writeBool, true);
937 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500938 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800939 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500940 }
941
942 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800943 SAFE_PARCEL(output->writeBool, true);
944 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500945 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800946 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500947 }
948
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800949 SAFE_PARCEL(output->writeUint64, frameNumber);
950 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
951 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500952
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800953 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
954 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800955 SAFE_PARCEL(output->writeBool, hasBarrier);
956 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +0800957 SAFE_PARCEL(output->writeUint32, producerId);
Nergi Rahardi39f510f2024-05-23 15:16:54 +0900958 SAFE_PARCEL(output->writeInt64, dequeueTime);
chaviwba4320c2021-09-15 15:20:53 -0500959
960 return NO_ERROR;
961}
962
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800963status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500964 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800965 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700966 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500967
968 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800969 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500970 if (tmpBool) {
971 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800972 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500973 }
974
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800975 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500976 if (tmpBool) {
977 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800978 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500979 }
980
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800981 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500982
983 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800984 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500985 if (tmpBinder) {
986 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
987 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800988 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500989
990 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800991 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500992 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800993 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500994
Robert Carr79dc06a2022-02-22 15:28:59 -0800995 SAFE_PARCEL(input->readBool, &hasBarrier);
996 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +0800997 SAFE_PARCEL(input->readUint32, &producerId);
Nergi Rahardi39f510f2024-05-23 15:16:54 +0900998 SAFE_PARCEL(input->readInt64, &dequeueTime);
Robert Carr79dc06a2022-02-22 15:28:59 -0800999
chaviwba4320c2021-09-15 15:20:53 -05001000 return NO_ERROR;
1001}
1002
Chavi Weingarten076acac2023-01-19 17:20:43 +00001003status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1004 SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1005 SAFE_PARCEL(parcel->writeInt32, callbackId);
1006 return NO_ERROR;
1007}
1008
1009status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1010 sp<IBinder> tmpBinder = nullptr;
1011 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1012 if (tmpBinder) {
1013 callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1014 }
1015 SAFE_PARCEL(parcel->readInt32, &callbackId);
1016 return NO_ERROR;
1017}
1018
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001019}; // namespace android