blob: 1c527d23b6231d1d8c1c99b06fccd86028d9e6f3 [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
Pablo Gamito11dcc222020-09-12 15:49:39 +000058layer_state_t::layer_state_t()
Vishnu Nair685cfef2022-02-02 10:01:25 -080059 : surface(nullptr),
60 layerId(-1),
61 what(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000062 x(0),
63 y(0),
64 z(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000065 flags(0),
66 mask(0),
67 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000068 cornerRadius(0.0f),
69 backgroundBlurRadius(0),
Vishnu Nairbbceb462022-10-10 04:52:13 +000070 color(0),
71 bufferTransform(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000072 transformToDisplayInverse(false),
Vishnu Naira9123c82024-10-03 03:56:44 +000073 crop({0, 0, -1, -1}),
Pablo Gamito11dcc222020-09-12 15:49:39 +000074 dataspace(ui::Dataspace::UNKNOWN),
75 surfaceDamageRegion(),
76 api(-1),
77 colorTransform(mat4()),
Vishnu Naird47bcee2023-02-24 18:08:51 +000078 bgColor(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000079 bgColorDataspace(ui::Dataspace::UNKNOWN),
80 colorSpaceAgnostic(false),
81 shadowRadius(0.0f),
82 frameRateSelectionPriority(-1),
83 frameRate(0.0f),
84 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010085 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Andy Labrada096227e2022-06-15 16:58:11 +000086 defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Rachel Leece6e0042023-06-27 11:22:54 -070087 frameRateCategory(ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT),
Rachel Lee67afbea2023-09-28 15:35:07 -070088 frameRateCategorySmoothSwitchOnly(false),
Rachel Lee70f7b692023-11-22 11:24:02 -080089 frameRateSelectionStrategy(ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_PROPAGATE),
Pablo Gamito11dcc222020-09-12 15:49:39 +000090 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080091 autoRefresh(false),
Vishnu Nair9e0017e2024-05-22 19:02:44 +000092 trustedOverlay(gui::TrustedOverlay::UNSET),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070093 bufferCrop(Rect::INVALID_RECT),
94 destinationFrame(Rect::INVALID_RECT),
Brian Lindahl07dcd492024-10-30 11:43:23 -060095 dropInputMode(gui::DropInputMode::NONE),
96 pictureProfileHandle(PictureProfileHandle::NONE),
97 appContentPriority(0) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000098 matrix.dsdx = matrix.dtdy = 1.0f;
99 matrix.dsdy = matrix.dtdx = 0.0f;
100 hdrMetadata.validTypes = 0;
101}
102
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103status_t layer_state_t::write(Parcel& output) const
104{
chaviw308ddba2020-08-11 16:23:51 -0700105 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000106 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -0700107 SAFE_PARCEL(output.writeUint64, what);
108 SAFE_PARCEL(output.writeFloat, x);
109 SAFE_PARCEL(output.writeFloat, y);
110 SAFE_PARCEL(output.writeInt32, z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700111 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700112 SAFE_PARCEL(output.writeUint32, flags);
113 SAFE_PARCEL(output.writeUint32, mask);
114 SAFE_PARCEL(matrix.write, output);
Vishnu Naira9123c82024-10-03 03:56:44 +0000115 SAFE_PARCEL(output.writeFloat, crop.top);
116 SAFE_PARCEL(output.writeFloat, crop.left);
117 SAFE_PARCEL(output.writeFloat, crop.bottom);
118 SAFE_PARCEL(output.writeFloat, crop.right);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000119 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
120 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -0700121 SAFE_PARCEL(output.writeFloat, color.r);
122 SAFE_PARCEL(output.writeFloat, color.g);
123 SAFE_PARCEL(output.writeFloat, color.b);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000124 SAFE_PARCEL(output.writeFloat, color.a);
chaviw98318de2021-05-19 16:45:23 -0500125 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700126 SAFE_PARCEL(output.write, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000127 SAFE_PARCEL(output.writeUint32, bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700128 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700129 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
130 SAFE_PARCEL(output.write, hdrMetadata);
131 SAFE_PARCEL(output.write, surfaceDamageRegion);
132 SAFE_PARCEL(output.writeInt32, api);
133
Marissa Wall61c58622018-07-18 10:12:20 -0700134 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700135 SAFE_PARCEL(output.writeBool, true);
136 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700137 } else {
chaviw308ddba2020-08-11 16:23:51 -0700138 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700139 }
140
chaviw308ddba2020-08-11 16:23:51 -0700141 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
142 SAFE_PARCEL(output.writeFloat, cornerRadius);
143 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700144 SAFE_PARCEL(output.writeParcelable, metadata);
Vishnu Naird47bcee2023-02-24 18:08:51 +0000145 SAFE_PARCEL(output.writeFloat, bgColor.r);
146 SAFE_PARCEL(output.writeFloat, bgColor.g);
147 SAFE_PARCEL(output.writeFloat, bgColor.b);
148 SAFE_PARCEL(output.writeFloat, bgColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700149 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
150 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
151 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700152
153 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700154 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700155 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700156 }
chaviw308ddba2020-08-11 16:23:51 -0700157 SAFE_PARCEL(output.writeFloat, shadowRadius);
158 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
159 SAFE_PARCEL(output.writeFloat, frameRate);
160 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100161 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000162 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700163 SAFE_PARCEL(output.writeByte, frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700164 SAFE_PARCEL(output.writeBool, frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700165 SAFE_PARCEL(output.writeByte, frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700166 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800167 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700168 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700169
170 SAFE_PARCEL(output.writeUint32, blurRegions.size());
171 for (auto region : blurRegions) {
172 SAFE_PARCEL(output.writeUint32, region.blurRadius);
173 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
174 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
175 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
176 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
177 SAFE_PARCEL(output.writeFloat, region.alpha);
178 SAFE_PARCEL(output.writeInt32, region.left);
179 SAFE_PARCEL(output.writeInt32, region.top);
180 SAFE_PARCEL(output.writeInt32, region.right);
181 SAFE_PARCEL(output.writeInt32, region.bottom);
182 }
John Reckcdb4ed72021-02-04 13:39:33 -0500183
184 SAFE_PARCEL(output.write, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000185 SAFE_PARCEL(output.writeParcelable, edgeExtensionParameters);
chaviwf3f40fe2021-04-27 15:54:02 -0500186 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700187 SAFE_PARCEL(output.write, destinationFrame);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000188 SAFE_PARCEL(output.writeInt32, static_cast<uint32_t>(trustedOverlay));
John Reckcdb4ed72021-02-04 13:39:33 -0500189
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700190 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800191
192 const bool hasBufferData = (bufferData != nullptr);
193 SAFE_PARCEL(output.writeBool, hasBufferData);
194 if (hasBufferData) {
195 SAFE_PARCEL(output.writeParcelable, *bufferData);
196 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000197 SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds);
198 SAFE_PARCEL(output.writeParcelable, trustedPresentationListener);
Sally Qi963049b2023-03-23 14:06:21 -0700199 SAFE_PARCEL(output.writeFloat, currentHdrSdrRatio);
200 SAFE_PARCEL(output.writeFloat, desiredHdrSdrRatio);
Vishnu Nair59a6be32024-01-29 10:26:21 -0800201 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(cachingHint));
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500202
203 const bool hasBufferReleaseChannel = (bufferReleaseChannel != nullptr);
204 SAFE_PARCEL(output.writeBool, hasBufferReleaseChannel);
205 if (hasBufferReleaseChannel) {
206 SAFE_PARCEL(output.writeParcelable, *bufferReleaseChannel);
207 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600208#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
209 SAFE_PARCEL(output.writeInt64, pictureProfileHandle.getId());
210 SAFE_PARCEL(output.writeInt32, appContentPriority);
211#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500212
Mathias Agopianac9fa422013-02-11 16:40:36 -0800213 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800214}
215
216status_t layer_state_t::read(const Parcel& input)
217{
chaviw308ddba2020-08-11 16:23:51 -0700218 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000219 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700220 SAFE_PARCEL(input.readUint64, &what);
221 SAFE_PARCEL(input.readFloat, &x);
222 SAFE_PARCEL(input.readFloat, &y);
223 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700224 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700225
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800226 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700227
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800228 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700229
230 SAFE_PARCEL(matrix.read, input);
Vishnu Naira9123c82024-10-03 03:56:44 +0000231 SAFE_PARCEL(input.readFloat, &crop.top);
232 SAFE_PARCEL(input.readFloat, &crop.left);
233 SAFE_PARCEL(input.readFloat, &crop.bottom);
234 SAFE_PARCEL(input.readFloat, &crop.right);
chaviw308ddba2020-08-11 16:23:51 -0700235
Pablo Gamito11dcc222020-09-12 15:49:39 +0000236 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
237 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
238
chaviw308ddba2020-08-11 16:23:51 -0700239 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700240 SAFE_PARCEL(input.readFloat, &tmpFloat);
241 color.r = tmpFloat;
242 SAFE_PARCEL(input.readFloat, &tmpFloat);
243 color.g = tmpFloat;
244 SAFE_PARCEL(input.readFloat, &tmpFloat);
245 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000246 SAFE_PARCEL(input.readFloat, &tmpFloat);
247 color.a = tmpFloat;
248
chaviw98318de2021-05-19 16:45:23 -0500249 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700250
chaviw308ddba2020-08-11 16:23:51 -0700251 SAFE_PARCEL(input.read, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000252 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700253 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700254
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800255 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700256 SAFE_PARCEL(input.readUint32, &tmpUint32);
257 dataspace = static_cast<ui::Dataspace>(tmpUint32);
258
259 SAFE_PARCEL(input.read, hdrMetadata);
260 SAFE_PARCEL(input.read, surfaceDamageRegion);
261 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500262
263 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700264 SAFE_PARCEL(input.readBool, &tmpBool);
265 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700266 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
267 }
268
chaviw308ddba2020-08-11 16:23:51 -0700269 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
270 SAFE_PARCEL(input.readFloat, &cornerRadius);
271 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700272 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800273
Vishnu Naird47bcee2023-02-24 18:08:51 +0000274 SAFE_PARCEL(input.readFloat, &tmpFloat);
275 bgColor.r = tmpFloat;
276 SAFE_PARCEL(input.readFloat, &tmpFloat);
277 bgColor.g = tmpFloat;
278 SAFE_PARCEL(input.readFloat, &tmpFloat);
279 bgColor.b = tmpFloat;
280 SAFE_PARCEL(input.readFloat, &tmpFloat);
281 bgColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700282 SAFE_PARCEL(input.readUint32, &tmpUint32);
283 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
284 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800285
chaviw308ddba2020-08-11 16:23:51 -0700286 int32_t numListeners = 0;
287 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700288 listeners.clear();
289 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700290 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700291 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700292 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700293 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700294 listeners.emplace_back(listener, callbackIds);
295 }
chaviw308ddba2020-08-11 16:23:51 -0700296 SAFE_PARCEL(input.readFloat, &shadowRadius);
297 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
298 SAFE_PARCEL(input.readFloat, &frameRate);
299 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100300 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000301 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700302 SAFE_PARCEL(input.readByte, &frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700303 SAFE_PARCEL(input.readBool, &frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700304 SAFE_PARCEL(input.readByte, &frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700305 SAFE_PARCEL(input.readUint32, &tmpUint32);
306 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800307 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700308 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700309
310 uint32_t numRegions = 0;
311 SAFE_PARCEL(input.readUint32, &numRegions);
312 blurRegions.clear();
313 for (uint32_t i = 0; i < numRegions; i++) {
314 BlurRegion region;
315 SAFE_PARCEL(input.readUint32, &region.blurRadius);
316 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
317 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
318 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
319 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
320 SAFE_PARCEL(input.readFloat, &region.alpha);
321 SAFE_PARCEL(input.readInt32, &region.left);
322 SAFE_PARCEL(input.readInt32, &region.top);
323 SAFE_PARCEL(input.readInt32, &region.right);
324 SAFE_PARCEL(input.readInt32, &region.bottom);
325 blurRegions.push_back(region);
326 }
John Reckcdb4ed72021-02-04 13:39:33 -0500327
328 SAFE_PARCEL(input.read, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000329 SAFE_PARCEL(input.readParcelable, &edgeExtensionParameters);
chaviwf3f40fe2021-04-27 15:54:02 -0500330 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700331 SAFE_PARCEL(input.read, destinationFrame);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000332 uint32_t trustedOverlayInt;
333 SAFE_PARCEL(input.readUint32, &trustedOverlayInt);
334 trustedOverlay = static_cast<gui::TrustedOverlay>(trustedOverlayInt);
John Reckcdb4ed72021-02-04 13:39:33 -0500335
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700336 uint32_t mode;
337 SAFE_PARCEL(input.readUint32, &mode);
338 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800339
340 bool hasBufferData;
341 SAFE_PARCEL(input.readBool, &hasBufferData);
342 if (hasBufferData) {
343 bufferData = std::make_shared<BufferData>();
344 SAFE_PARCEL(input.readParcelable, bufferData.get());
345 } else {
346 bufferData = nullptr;
347 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000348
349 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
350 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
351
John Reck68796592023-01-25 13:47:12 -0500352 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700353 currentHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500354 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700355 desiredHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500356
Alec Mourif4af03e2023-02-11 00:25:24 +0000357 int32_t tmpInt32;
358 SAFE_PARCEL(input.readInt32, &tmpInt32);
359 cachingHint = static_cast<gui::CachingHint>(tmpInt32);
360
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500361 bool hasBufferReleaseChannel;
362 SAFE_PARCEL(input.readBool, &hasBufferReleaseChannel);
363 if (hasBufferReleaseChannel) {
364 bufferReleaseChannel = std::make_shared<gui::BufferReleaseChannel::ProducerEndpoint>();
365 SAFE_PARCEL(input.readParcelable, bufferReleaseChannel.get());
366 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600367#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
368 int64_t pictureProfileId;
369 SAFE_PARCEL(input.readInt64, &pictureProfileId);
370 pictureProfileHandle = PictureProfileHandle(pictureProfileId);
371 SAFE_PARCEL(input.readInt32, &appContentPriority);
372#endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500373
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800374 return NO_ERROR;
375}
376
Mathias Agopian698c0872011-06-28 19:09:31 -0700377status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700378 return state.write(output);
379}
380
381status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700382 return state.read(input);
383}
384
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700385DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700386
Mathias Agopian8b33f032012-07-24 20:43:54 -0700387status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700388 SAFE_PARCEL(output.writeStrongBinder, token);
389 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
390 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700391 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700392 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700393 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
394 SAFE_PARCEL(output.write, layerStackSpaceRect);
395 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
396 SAFE_PARCEL(output.writeUint32, width);
397 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700398 return NO_ERROR;
399}
400
401status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700402 SAFE_PARCEL(input.readStrongBinder, &token);
403 sp<IBinder> tmpBinder;
404 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
405 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
406
407 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700408 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700409 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700410 uint32_t tmpUint = 0;
411 SAFE_PARCEL(input.readUint32, &tmpUint);
412 orientation = ui::toRotation(tmpUint);
413
414 SAFE_PARCEL(input.read, layerStackSpaceRect);
415 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
416 SAFE_PARCEL(input.readUint32, &width);
417 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700418 return NO_ERROR;
419}
420
Robert Carr2c5f6d22017-09-26 12:30:35 -0700421void DisplayState::merge(const DisplayState& other) {
422 if (other.what & eSurfaceChanged) {
423 what |= eSurfaceChanged;
424 surface = other.surface;
425 }
426 if (other.what & eLayerStackChanged) {
427 what |= eLayerStackChanged;
428 layerStack = other.layerStack;
429 }
Evan Rosky2239b372021-05-20 13:43:47 -0700430 if (other.what & eFlagsChanged) {
431 what |= eFlagsChanged;
432 flags = other.flags;
433 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700434 if (other.what & eDisplayProjectionChanged) {
435 what |= eDisplayProjectionChanged;
436 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200437 layerStackSpaceRect = other.layerStackSpaceRect;
438 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700439 }
440 if (other.what & eDisplaySizeChanged) {
441 what |= eDisplaySizeChanged;
442 width = other.width;
443 height = other.height;
444 }
445}
446
Sally Qi6bb12822022-10-05 11:42:30 -0700447void DisplayState::sanitize(int32_t permissions) {
448 if (what & DisplayState::eLayerStackChanged) {
449 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
450 what &= ~DisplayState::eLayerStackChanged;
451 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
452 }
453 }
454 if (what & DisplayState::eDisplayProjectionChanged) {
455 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
456 what &= ~DisplayState::eDisplayProjectionChanged;
457 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
458 }
459 }
460 if (what & DisplayState::eSurfaceChanged) {
461 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
462 what &= ~DisplayState::eSurfaceChanged;
463 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
464 }
465 }
466}
467
Robert Carrde6d7b42022-01-07 18:23:06 -0800468void layer_state_t::sanitize(int32_t permissions) {
469 // TODO: b/109894387
470 //
471 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
472 // rotation. To see the problem observe that if we have a square parent, and a child
473 // of the same size, then we rotate the child 45 degrees around its center, the child
474 // must now be cropped to a non rectangular 8 sided region.
475 //
476 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
477 // private API, and arbitrary rotation is used in limited use cases, for instance:
478 // - WindowManager only uses rotation in one case, which is on a top level layer in which
479 // cropping is not an issue.
480 // - Launcher, as a privileged app, uses this to transition an application to PiP
481 // (picture-in-picture) mode.
482 //
483 // However given that abuse of rotation matrices could lead to surfaces extending outside
484 // of cropped areas, we need to prevent non-root clients without permission
485 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
486 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
487 // preserving transformations.
488 if (what & eMatrixChanged) {
489 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
490 ui::Transform t;
491 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
492 if (!t.preserveRects()) {
493 what &= ~eMatrixChanged;
494 ALOGE("Stripped non rect preserving matrix in sanitize");
495 }
496 }
497 }
498
499 if (what & eFlagsChanged) {
500 if ((flags & eLayerIsDisplayDecoration) &&
501 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
502 flags &= ~eLayerIsDisplayDecoration;
503 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
504 }
Vishnu Nair59a6be32024-01-29 10:26:21 -0800505 if ((mask & eCanOccludePresentation) &&
506 !(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
507 flags &= ~eCanOccludePresentation;
508 mask &= ~eCanOccludePresentation;
509 ALOGE("Stripped attempt to set eCanOccludePresentation in sanitize");
510 }
Robert Carrde6d7b42022-01-07 18:23:06 -0800511 }
512
513 if (what & layer_state_t::eInputInfoChanged) {
514 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
515 what &= ~eInputInfoChanged;
516 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
517 }
518 }
519 if (what & layer_state_t::eTrustedOverlayChanged) {
520 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
521 what &= ~eTrustedOverlayChanged;
522 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
523 }
524 }
525 if (what & layer_state_t::eDropInputModeChanged) {
526 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
527 what &= ~eDropInputModeChanged;
528 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
529 }
530 }
531 if (what & layer_state_t::eFrameRateSelectionPriority) {
532 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
533 what &= ~eFrameRateSelectionPriority;
534 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
535 }
536 }
537 if (what & layer_state_t::eFrameRateChanged) {
538 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
539 changeFrameRateStrategy,
540 "layer_state_t::sanitize",
541 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
542 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
543 }
544 }
545}
546
Robert Carr2c5f6d22017-09-26 12:30:35 -0700547void layer_state_t::merge(const layer_state_t& other) {
548 if (other.what & ePositionChanged) {
549 what |= ePositionChanged;
550 x = other.x;
551 y = other.y;
552 }
553 if (other.what & eLayerChanged) {
554 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700555 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700556 z = other.z;
557 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700558 if (other.what & eAlphaChanged) {
559 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000560 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700561 }
562 if (other.what & eMatrixChanged) {
563 what |= eMatrixChanged;
564 matrix = other.matrix;
565 }
566 if (other.what & eTransparentRegionChanged) {
567 what |= eTransparentRegionChanged;
568 transparentRegion = other.transparentRegion;
569 }
570 if (other.what & eFlagsChanged) {
571 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700572 flags &= ~other.mask;
573 flags |= (other.flags & other.mask);
574 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700575 }
576 if (other.what & eLayerStackChanged) {
577 what |= eLayerStackChanged;
578 layerStack = other.layerStack;
579 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700580 if (other.what & eCornerRadiusChanged) {
581 what |= eCornerRadiusChanged;
582 cornerRadius = other.cornerRadius;
583 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800584 if (other.what & eBackgroundBlurRadiusChanged) {
585 what |= eBackgroundBlurRadiusChanged;
586 backgroundBlurRadius = other.backgroundBlurRadius;
587 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700588 if (other.what & eBlurRegionsChanged) {
589 what |= eBlurRegionsChanged;
590 blurRegions = other.blurRegions;
591 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700592 if (other.what & eRelativeLayerChanged) {
593 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700594 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700595 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000596 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700597 }
598 if (other.what & eReparent) {
599 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000600 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700601 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000602 if (other.what & eBufferTransformChanged) {
603 what |= eBufferTransformChanged;
604 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700605 }
606 if (other.what & eTransformToDisplayInverseChanged) {
607 what |= eTransformToDisplayInverseChanged;
608 transformToDisplayInverse = other.transformToDisplayInverse;
609 }
610 if (other.what & eCropChanged) {
611 what |= eCropChanged;
612 crop = other.crop;
613 }
614 if (other.what & eBufferChanged) {
615 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500616 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700617 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000618 if (other.what & eTrustedPresentationInfoChanged) {
619 what |= eTrustedPresentationInfoChanged;
620 trustedPresentationListener = other.trustedPresentationListener;
621 trustedPresentationThresholds = other.trustedPresentationThresholds;
622 }
Marissa Wall61c58622018-07-18 10:12:20 -0700623 if (other.what & eDataspaceChanged) {
624 what |= eDataspaceChanged;
625 dataspace = other.dataspace;
626 }
John Reck68796592023-01-25 13:47:12 -0500627 if (other.what & eExtendedRangeBrightnessChanged) {
628 what |= eExtendedRangeBrightnessChanged;
Sally Qi963049b2023-03-23 14:06:21 -0700629 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
630 currentHdrSdrRatio = other.currentHdrSdrRatio;
John Reck68796592023-01-25 13:47:12 -0500631 }
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000632 if (other.what & eDesiredHdrHeadroomChanged) {
633 what |= eDesiredHdrHeadroomChanged;
634 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
635 }
Alec Mourif4af03e2023-02-11 00:25:24 +0000636 if (other.what & eCachingHintChanged) {
637 what |= eCachingHintChanged;
638 cachingHint = other.cachingHint;
639 }
Marissa Wall61c58622018-07-18 10:12:20 -0700640 if (other.what & eHdrMetadataChanged) {
641 what |= eHdrMetadataChanged;
642 hdrMetadata = other.hdrMetadata;
643 }
644 if (other.what & eSurfaceDamageRegionChanged) {
645 what |= eSurfaceDamageRegionChanged;
646 surfaceDamageRegion = other.surfaceDamageRegion;
647 }
648 if (other.what & eApiChanged) {
649 what |= eApiChanged;
650 api = other.api;
651 }
652 if (other.what & eSidebandStreamChanged) {
653 what |= eSidebandStreamChanged;
654 sidebandStream = other.sidebandStream;
655 }
Peiyong Lind3788632018-09-18 16:01:31 -0700656 if (other.what & eColorTransformChanged) {
657 what |= eColorTransformChanged;
658 colorTransform = other.colorTransform;
659 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700660 if (other.what & eHasListenerCallbacksChanged) {
661 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700662 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700663 if (other.what & eInputInfoChanged) {
664 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500665 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700666 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800667 if (other.what & eBackgroundColorChanged) {
668 what |= eBackgroundColorChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000669 bgColor = other.bgColor;
Valerie Haudd0b7572019-01-29 14:59:27 -0800670 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800671 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800672 if (other.what & eMetadataChanged) {
673 what |= eMetadataChanged;
674 metadata.merge(other.metadata);
675 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700676 if (other.what & eShadowRadiusChanged) {
677 what |= eShadowRadiusChanged;
678 shadowRadius = other.shadowRadius;
679 }
Sally Qi0abc4a52024-09-26 16:13:06 -0700680 if (other.what & eLutsChanged) {
681 what |= eLutsChanged;
682 luts = other.luts;
683 }
Andy Labrada096227e2022-06-15 16:58:11 +0000684 if (other.what & eDefaultFrameRateCompatibilityChanged) {
685 what |= eDefaultFrameRateCompatibilityChanged;
686 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
687 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100688 if (other.what & eFrameRateSelectionPriority) {
689 what |= eFrameRateSelectionPriority;
690 frameRateSelectionPriority = other.frameRateSelectionPriority;
691 }
Steven Thomas3172e202020-01-06 19:25:30 -0800692 if (other.what & eFrameRateChanged) {
693 what |= eFrameRateChanged;
694 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800695 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100696 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800697 }
Rachel Leece6e0042023-06-27 11:22:54 -0700698 if (other.what & eFrameRateCategoryChanged) {
699 what |= eFrameRateCategoryChanged;
700 frameRateCategory = other.frameRateCategory;
Rachel Lee67afbea2023-09-28 15:35:07 -0700701 frameRateCategorySmoothSwitchOnly = other.frameRateCategorySmoothSwitchOnly;
Rachel Leece6e0042023-06-27 11:22:54 -0700702 }
Rachel Lee58cc90d2023-09-05 18:50:20 -0700703 if (other.what & eFrameRateSelectionStrategyChanged) {
704 what |= eFrameRateSelectionStrategyChanged;
705 frameRateSelectionStrategy = other.frameRateSelectionStrategy;
706 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700707 if (other.what & eFixedTransformHintChanged) {
708 what |= eFixedTransformHintChanged;
709 fixedTransformHint = other.fixedTransformHint;
710 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800711 if (other.what & eAutoRefreshChanged) {
712 what |= eAutoRefreshChanged;
713 autoRefresh = other.autoRefresh;
714 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700715 if (other.what & eTrustedOverlayChanged) {
716 what |= eTrustedOverlayChanged;
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000717 trustedOverlay = other.trustedOverlay;
Winson Chunga30f7c92021-06-29 15:42:56 -0700718 }
John Reckc00c6692021-02-16 11:37:33 -0500719 if (other.what & eStretchChanged) {
720 what |= eStretchChanged;
721 stretchEffect = other.stretchEffect;
722 }
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000723 if (other.what & eEdgeExtensionChanged) {
724 what |= eEdgeExtensionChanged;
725 edgeExtensionParameters = other.edgeExtensionParameters;
726 }
chaviwf3f40fe2021-04-27 15:54:02 -0500727 if (other.what & eBufferCropChanged) {
728 what |= eBufferCropChanged;
729 bufferCrop = other.bufferCrop;
730 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700731 if (other.what & eDestinationFrameChanged) {
732 what |= eDestinationFrameChanged;
733 destinationFrame = other.destinationFrame;
734 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700735 if (other.what & eProducerDisconnect) {
736 what |= eProducerDisconnect;
737 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700738 if (other.what & eDropInputModeChanged) {
739 what |= eDropInputModeChanged;
740 dropInputMode = other.dropInputMode;
741 }
chaviw4c36cd82021-11-18 10:37:33 -0600742 if (other.what & eColorChanged) {
743 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000744 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600745 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800746 if (other.what & eColorSpaceAgnosticChanged) {
747 what |= eColorSpaceAgnosticChanged;
748 colorSpaceAgnostic = other.colorSpaceAgnostic;
749 }
Sally Qi81d95e62022-03-21 19:41:33 -0700750 if (other.what & eDimmingEnabledChanged) {
751 what |= eDimmingEnabledChanged;
752 dimmingEnabled = other.dimmingEnabled;
753 }
Pascal Muetschardb39918f2023-01-27 11:36:11 +0100754 if (other.what & eFlushJankData) {
755 what |= eFlushJankData;
756 }
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500757 if (other.what & eBufferReleaseChannelChanged) {
758 what |= eBufferReleaseChannelChanged;
759 bufferReleaseChannel = other.bufferReleaseChannel;
760 }
Brian Lindahl07dcd492024-10-30 11:43:23 -0600761 if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
762 if (other.what & ePictureProfileHandleChanged) {
763 what |= ePictureProfileHandleChanged;
764 pictureProfileHandle = other.pictureProfileHandle;
765 }
766 if (other.what & eAppContentPriorityChanged) {
767 what |= eAppContentPriorityChanged;
768 appContentPriority = other.appContentPriority;
769 }
770 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700771 if ((other.what & what) != other.what) {
772 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700773 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
774 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700775 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700776}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700777
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000778uint64_t layer_state_t::diff(const layer_state_t& other) const {
779 uint64_t diff = 0;
780 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
781 if (other.what & eLayerChanged) {
782 diff |= eLayerChanged;
783 diff &= ~eRelativeLayerChanged;
784 }
785 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
786 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
787 if (other.what & eTransparentRegionChanged &&
788 (!transparentRegion.hasSameRects(other.transparentRegion))) {
789 diff |= eTransparentRegionChanged;
790 }
791 if (other.what & eFlagsChanged) {
792 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
793 if (changedFlags) diff |= eFlagsChanged;
794 }
795 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
796 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
797 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
798 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
799 if (other.what & eRelativeLayerChanged) {
800 diff |= eRelativeLayerChanged;
801 diff &= ~eLayerChanged;
802 }
803 if (other.what & eReparent &&
804 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
805 other.parentSurfaceControlForChild)) {
806 diff |= eReparent;
807 }
808 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
809 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
810 CHECK_DIFF(diff, eCropChanged, other, crop);
811 if (other.what & eBufferChanged) diff |= eBufferChanged;
812 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
Sally Qi963049b2023-03-23 14:06:21 -0700813 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio,
814 desiredHdrSdrRatio);
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000815 CHECK_DIFF(diff, eDesiredHdrHeadroomChanged, other, desiredHdrSdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000816 CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000817 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
818 if (other.what & eSurfaceDamageRegionChanged &&
819 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
820 diff |= eSurfaceDamageRegionChanged;
821 }
822 CHECK_DIFF(diff, eApiChanged, other, api);
823 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
824 CHECK_DIFF(diff, eApiChanged, other, api);
825 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
826 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
827 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000828 CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000829 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
830 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000831 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
832 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
833 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
834 changeFrameRateStrategy);
Rachel Lee67afbea2023-09-28 15:35:07 -0700835 CHECK_DIFF2(diff, eFrameRateCategoryChanged, other, frameRateCategory,
836 frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700837 CHECK_DIFF(diff, eFrameRateSelectionStrategyChanged, other, frameRateSelectionStrategy);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000838 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
839 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
Vishnu Nair9e0017e2024-05-22 19:02:44 +0000840 CHECK_DIFF(diff, eTrustedOverlayChanged, other, trustedOverlay);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000841 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000842 CHECK_DIFF(diff, eEdgeExtensionChanged, other, edgeExtensionParameters);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000843 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
844 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
845 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
846 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
847 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
848 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
849 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
Patrick Williamsf693bcf2024-08-02 09:55:23 -0500850 if (other.what & eBufferReleaseChannelChanged) diff |= eBufferReleaseChannelChanged;
Sally Qi0abc4a52024-09-26 16:13:06 -0700851 if (other.what & eLutsChanged) diff |= eLutsChanged;
Brian Lindahl07dcd492024-10-30 11:43:23 -0600852 CHECK_DIFF(diff, ePictureProfileHandleChanged, other, pictureProfileHandle);
853 CHECK_DIFF(diff, eAppContentPriorityChanged, other, appContentPriority);
Sally Qi0abc4a52024-09-26 16:13:06 -0700854
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000855 return diff;
856}
857
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700858bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500859 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700860}
861
Ady Abraham6e8e3642021-07-08 19:44:07 -0700862bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700863 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700864}
865
chaviw308ddba2020-08-11 16:23:51 -0700866status_t layer_state_t::matrix22_t::write(Parcel& output) const {
867 SAFE_PARCEL(output.writeFloat, dsdx);
868 SAFE_PARCEL(output.writeFloat, dtdx);
869 SAFE_PARCEL(output.writeFloat, dtdy);
870 SAFE_PARCEL(output.writeFloat, dsdy);
871 return NO_ERROR;
872}
873
874status_t layer_state_t::matrix22_t::read(const Parcel& input) {
875 SAFE_PARCEL(input.readFloat, &dsdx);
876 SAFE_PARCEL(input.readFloat, &dtdx);
877 SAFE_PARCEL(input.readFloat, &dtdy);
878 SAFE_PARCEL(input.readFloat, &dsdy);
879 return NO_ERROR;
880}
881
chaviw273171b2018-12-26 11:46:30 -0800882// ------------------------------- InputWindowCommands ----------------------------------------
883
Vishnu Naire798b472020-07-23 13:52:21 -0700884bool InputWindowCommands::merge(const InputWindowCommands& other) {
885 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700886 changes |= !other.focusRequests.empty();
887 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
888 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000889 changes |= !other.windowInfosReportedListeners.empty();
890 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
891 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700892 return changes;
chaviw273171b2018-12-26 11:46:30 -0800893}
894
Vishnu Nair958da932020-08-21 17:12:37 -0700895bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000896 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700897}
898
chaviw273171b2018-12-26 11:46:30 -0800899void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700900 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000901 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800902}
903
chaviw308ddba2020-08-11 16:23:51 -0700904status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700905 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000906
907 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
908 for (const auto& listener : windowInfosReportedListeners) {
909 SAFE_PARCEL(output.writeStrongBinder, listener);
910 }
911
chaviw308ddba2020-08-11 16:23:51 -0700912 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800913}
914
chaviw308ddba2020-08-11 16:23:51 -0700915status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700916 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000917
918 int listenerSize = 0;
919 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
920 windowInfosReportedListeners.reserve(listenerSize);
921 for (int i = 0; i < listenerSize; i++) {
922 sp<gui::IWindowInfosReportedListener> listener;
923 SAFE_PARCEL(input.readStrongBinder, &listener);
924 windowInfosReportedListeners.insert(listener);
925 }
926
chaviw308ddba2020-08-11 16:23:51 -0700927 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800928}
929
chaviw618c42d2020-07-24 15:25:08 -0700930// ----------------------------------------------------------------------------
931
chaviw8dd181f2022-01-05 18:36:46 -0600932ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500933 uint64_t bufferId;
934 if (buffer) {
935 bufferId = buffer->getId();
936 } else {
937 bufferId = cachedBuffer.id;
938 }
939 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600940}
941
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800942status_t BufferData::writeToParcel(Parcel* output) const {
943 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500944
945 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800946 SAFE_PARCEL(output->writeBool, true);
947 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500948 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800949 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500950 }
951
952 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800953 SAFE_PARCEL(output->writeBool, true);
954 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500955 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800956 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500957 }
958
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800959 SAFE_PARCEL(output->writeUint64, frameNumber);
960 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
961 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500962
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800963 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
964 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800965 SAFE_PARCEL(output->writeBool, hasBarrier);
966 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +0800967 SAFE_PARCEL(output->writeUint32, producerId);
Nergi Rahardi39f510f2024-05-23 15:16:54 +0900968 SAFE_PARCEL(output->writeInt64, dequeueTime);
chaviwba4320c2021-09-15 15:20:53 -0500969
970 return NO_ERROR;
971}
972
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800973status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500974 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800975 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700976 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500977
978 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800979 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500980 if (tmpBool) {
981 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800982 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500983 }
984
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800985 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500986 if (tmpBool) {
987 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800988 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500989 }
990
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800991 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500992
993 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800994 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500995 if (tmpBinder) {
996 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
997 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800998 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500999
1000 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001001 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001002 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001003 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -05001004
Robert Carr79dc06a2022-02-22 15:28:59 -08001005 SAFE_PARCEL(input->readBool, &hasBarrier);
1006 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001007 SAFE_PARCEL(input->readUint32, &producerId);
Nergi Rahardi39f510f2024-05-23 15:16:54 +09001008 SAFE_PARCEL(input->readInt64, &dequeueTime);
Robert Carr79dc06a2022-02-22 15:28:59 -08001009
chaviwba4320c2021-09-15 15:20:53 -05001010 return NO_ERROR;
1011}
1012
Chavi Weingarten076acac2023-01-19 17:20:43 +00001013status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1014 SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1015 SAFE_PARCEL(parcel->writeInt32, callbackId);
1016 return NO_ERROR;
1017}
1018
1019status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1020 sp<IBinder> tmpBinder = nullptr;
1021 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1022 if (tmpBinder) {
1023 callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1024 }
1025 SAFE_PARCEL(parcel->readInt32, &callbackId);
1026 return NO_ERROR;
1027}
1028
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001029}; // namespace android