blob: 0a2879975b6ece3a7fb9cb060fd1ba8b451d326b [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Vishnu Nair217d8e62018-09-12 16:34:49 -070017#define LOG_TAG "LayerState"
18
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070019#include <cinttypes>
20#include <cmath>
Garfield Tan8a3083e2018-12-03 13:21:07 -080021
Huihong Luod3d8f8e2022-03-08 14:48:46 -080022#include <android/gui/ISurfaceComposerClient.h>
Marin Shalamanovc5986772021-03-16 16:09:49 +010023#include <android/native_window.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070024#include <binder/Parcel.h>
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),
73 crop(Rect::INVALID_RECT),
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),
Winson Chunga30f7c92021-06-29 15:42:56 -070092 isTrustedOverlay(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070093 bufferCrop(Rect::INVALID_RECT),
94 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070095 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000096 matrix.dsdx = matrix.dtdy = 1.0f;
97 matrix.dsdy = matrix.dtdx = 0.0f;
98 hdrMetadata.validTypes = 0;
99}
100
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101status_t layer_state_t::write(Parcel& output) const
102{
chaviw308ddba2020-08-11 16:23:51 -0700103 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000104 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -0700105 SAFE_PARCEL(output.writeUint64, what);
106 SAFE_PARCEL(output.writeFloat, x);
107 SAFE_PARCEL(output.writeFloat, y);
108 SAFE_PARCEL(output.writeInt32, z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700109 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700110 SAFE_PARCEL(output.writeUint32, flags);
111 SAFE_PARCEL(output.writeUint32, mask);
112 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -0800113 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000114 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
115 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -0700116 SAFE_PARCEL(output.writeFloat, color.r);
117 SAFE_PARCEL(output.writeFloat, color.g);
118 SAFE_PARCEL(output.writeFloat, color.b);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000119 SAFE_PARCEL(output.writeFloat, color.a);
chaviw98318de2021-05-19 16:45:23 -0500120 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700121 SAFE_PARCEL(output.write, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000122 SAFE_PARCEL(output.writeUint32, bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700123 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700124 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
125 SAFE_PARCEL(output.write, hdrMetadata);
126 SAFE_PARCEL(output.write, surfaceDamageRegion);
127 SAFE_PARCEL(output.writeInt32, api);
128
Marissa Wall61c58622018-07-18 10:12:20 -0700129 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700130 SAFE_PARCEL(output.writeBool, true);
131 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700132 } else {
chaviw308ddba2020-08-11 16:23:51 -0700133 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700134 }
135
chaviw308ddba2020-08-11 16:23:51 -0700136 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
137 SAFE_PARCEL(output.writeFloat, cornerRadius);
138 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700139 SAFE_PARCEL(output.writeParcelable, metadata);
Vishnu Naird47bcee2023-02-24 18:08:51 +0000140 SAFE_PARCEL(output.writeFloat, bgColor.r);
141 SAFE_PARCEL(output.writeFloat, bgColor.g);
142 SAFE_PARCEL(output.writeFloat, bgColor.b);
143 SAFE_PARCEL(output.writeFloat, bgColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700144 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
145 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
146 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700147
148 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700149 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700150 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700151 }
chaviw308ddba2020-08-11 16:23:51 -0700152 SAFE_PARCEL(output.writeFloat, shadowRadius);
153 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
154 SAFE_PARCEL(output.writeFloat, frameRate);
155 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100156 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000157 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700158 SAFE_PARCEL(output.writeByte, frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700159 SAFE_PARCEL(output.writeBool, frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700160 SAFE_PARCEL(output.writeByte, frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700161 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800162 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700163 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700164
165 SAFE_PARCEL(output.writeUint32, blurRegions.size());
166 for (auto region : blurRegions) {
167 SAFE_PARCEL(output.writeUint32, region.blurRadius);
168 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
169 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
170 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
171 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
172 SAFE_PARCEL(output.writeFloat, region.alpha);
173 SAFE_PARCEL(output.writeInt32, region.left);
174 SAFE_PARCEL(output.writeInt32, region.top);
175 SAFE_PARCEL(output.writeInt32, region.right);
176 SAFE_PARCEL(output.writeInt32, region.bottom);
177 }
John Reckcdb4ed72021-02-04 13:39:33 -0500178
179 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500180 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700181 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700182 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500183
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700184 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800185
186 const bool hasBufferData = (bufferData != nullptr);
187 SAFE_PARCEL(output.writeBool, hasBufferData);
188 if (hasBufferData) {
189 SAFE_PARCEL(output.writeParcelable, *bufferData);
190 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000191 SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds);
192 SAFE_PARCEL(output.writeParcelable, trustedPresentationListener);
Sally Qi963049b2023-03-23 14:06:21 -0700193 SAFE_PARCEL(output.writeFloat, currentHdrSdrRatio);
194 SAFE_PARCEL(output.writeFloat, desiredHdrSdrRatio);
Vishnu Nair59a6be32024-01-29 10:26:21 -0800195 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(cachingHint));
Mathias Agopianac9fa422013-02-11 16:40:36 -0800196 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800197}
198
199status_t layer_state_t::read(const Parcel& input)
200{
chaviw308ddba2020-08-11 16:23:51 -0700201 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000202 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700203 SAFE_PARCEL(input.readUint64, &what);
204 SAFE_PARCEL(input.readFloat, &x);
205 SAFE_PARCEL(input.readFloat, &y);
206 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700207 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700208
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800209 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700210
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800211 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700212
213 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800214 SAFE_PARCEL(input.read, crop);
chaviw308ddba2020-08-11 16:23:51 -0700215
Pablo Gamito11dcc222020-09-12 15:49:39 +0000216 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
217 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
218
chaviw308ddba2020-08-11 16:23:51 -0700219 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700220 SAFE_PARCEL(input.readFloat, &tmpFloat);
221 color.r = tmpFloat;
222 SAFE_PARCEL(input.readFloat, &tmpFloat);
223 color.g = tmpFloat;
224 SAFE_PARCEL(input.readFloat, &tmpFloat);
225 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000226 SAFE_PARCEL(input.readFloat, &tmpFloat);
227 color.a = tmpFloat;
228
chaviw98318de2021-05-19 16:45:23 -0500229 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700230
chaviw308ddba2020-08-11 16:23:51 -0700231 SAFE_PARCEL(input.read, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000232 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700233 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700234
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800235 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700236 SAFE_PARCEL(input.readUint32, &tmpUint32);
237 dataspace = static_cast<ui::Dataspace>(tmpUint32);
238
239 SAFE_PARCEL(input.read, hdrMetadata);
240 SAFE_PARCEL(input.read, surfaceDamageRegion);
241 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500242
243 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700244 SAFE_PARCEL(input.readBool, &tmpBool);
245 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700246 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
247 }
248
chaviw308ddba2020-08-11 16:23:51 -0700249 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
250 SAFE_PARCEL(input.readFloat, &cornerRadius);
251 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700252 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800253
Vishnu Naird47bcee2023-02-24 18:08:51 +0000254 SAFE_PARCEL(input.readFloat, &tmpFloat);
255 bgColor.r = tmpFloat;
256 SAFE_PARCEL(input.readFloat, &tmpFloat);
257 bgColor.g = tmpFloat;
258 SAFE_PARCEL(input.readFloat, &tmpFloat);
259 bgColor.b = tmpFloat;
260 SAFE_PARCEL(input.readFloat, &tmpFloat);
261 bgColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700262 SAFE_PARCEL(input.readUint32, &tmpUint32);
263 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
264 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800265
chaviw308ddba2020-08-11 16:23:51 -0700266 int32_t numListeners = 0;
267 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700268 listeners.clear();
269 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700270 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700271 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700272 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700273 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700274 listeners.emplace_back(listener, callbackIds);
275 }
chaviw308ddba2020-08-11 16:23:51 -0700276 SAFE_PARCEL(input.readFloat, &shadowRadius);
277 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
278 SAFE_PARCEL(input.readFloat, &frameRate);
279 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100280 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000281 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700282 SAFE_PARCEL(input.readByte, &frameRateCategory);
Rachel Lee67afbea2023-09-28 15:35:07 -0700283 SAFE_PARCEL(input.readBool, &frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700284 SAFE_PARCEL(input.readByte, &frameRateSelectionStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700285 SAFE_PARCEL(input.readUint32, &tmpUint32);
286 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800287 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700288 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700289
290 uint32_t numRegions = 0;
291 SAFE_PARCEL(input.readUint32, &numRegions);
292 blurRegions.clear();
293 for (uint32_t i = 0; i < numRegions; i++) {
294 BlurRegion region;
295 SAFE_PARCEL(input.readUint32, &region.blurRadius);
296 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
297 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
298 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
299 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
300 SAFE_PARCEL(input.readFloat, &region.alpha);
301 SAFE_PARCEL(input.readInt32, &region.left);
302 SAFE_PARCEL(input.readInt32, &region.top);
303 SAFE_PARCEL(input.readInt32, &region.right);
304 SAFE_PARCEL(input.readInt32, &region.bottom);
305 blurRegions.push_back(region);
306 }
John Reckcdb4ed72021-02-04 13:39:33 -0500307
308 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500309 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700310 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700311 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500312
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700313 uint32_t mode;
314 SAFE_PARCEL(input.readUint32, &mode);
315 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800316
317 bool hasBufferData;
318 SAFE_PARCEL(input.readBool, &hasBufferData);
319 if (hasBufferData) {
320 bufferData = std::make_shared<BufferData>();
321 SAFE_PARCEL(input.readParcelable, bufferData.get());
322 } else {
323 bufferData = nullptr;
324 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000325
326 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
327 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
328
John Reck68796592023-01-25 13:47:12 -0500329 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700330 currentHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500331 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700332 desiredHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500333
Alec Mourif4af03e2023-02-11 00:25:24 +0000334 int32_t tmpInt32;
335 SAFE_PARCEL(input.readInt32, &tmpInt32);
336 cachingHint = static_cast<gui::CachingHint>(tmpInt32);
337
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800338 return NO_ERROR;
339}
340
Mathias Agopian698c0872011-06-28 19:09:31 -0700341status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700342 return state.write(output);
343}
344
345status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700346 return state.read(input);
347}
348
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700349DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700350
Mathias Agopian8b33f032012-07-24 20:43:54 -0700351status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700352 SAFE_PARCEL(output.writeStrongBinder, token);
353 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
354 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700355 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700356 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700357 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
358 SAFE_PARCEL(output.write, layerStackSpaceRect);
359 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
360 SAFE_PARCEL(output.writeUint32, width);
361 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700362 return NO_ERROR;
363}
364
365status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700366 SAFE_PARCEL(input.readStrongBinder, &token);
367 sp<IBinder> tmpBinder;
368 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
369 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
370
371 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700372 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700373 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700374 uint32_t tmpUint = 0;
375 SAFE_PARCEL(input.readUint32, &tmpUint);
376 orientation = ui::toRotation(tmpUint);
377
378 SAFE_PARCEL(input.read, layerStackSpaceRect);
379 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
380 SAFE_PARCEL(input.readUint32, &width);
381 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700382 return NO_ERROR;
383}
384
Robert Carr2c5f6d22017-09-26 12:30:35 -0700385void DisplayState::merge(const DisplayState& other) {
386 if (other.what & eSurfaceChanged) {
387 what |= eSurfaceChanged;
388 surface = other.surface;
389 }
390 if (other.what & eLayerStackChanged) {
391 what |= eLayerStackChanged;
392 layerStack = other.layerStack;
393 }
Evan Rosky2239b372021-05-20 13:43:47 -0700394 if (other.what & eFlagsChanged) {
395 what |= eFlagsChanged;
396 flags = other.flags;
397 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700398 if (other.what & eDisplayProjectionChanged) {
399 what |= eDisplayProjectionChanged;
400 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200401 layerStackSpaceRect = other.layerStackSpaceRect;
402 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700403 }
404 if (other.what & eDisplaySizeChanged) {
405 what |= eDisplaySizeChanged;
406 width = other.width;
407 height = other.height;
408 }
409}
410
Sally Qi6bb12822022-10-05 11:42:30 -0700411void DisplayState::sanitize(int32_t permissions) {
412 if (what & DisplayState::eLayerStackChanged) {
413 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
414 what &= ~DisplayState::eLayerStackChanged;
415 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
416 }
417 }
418 if (what & DisplayState::eDisplayProjectionChanged) {
419 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
420 what &= ~DisplayState::eDisplayProjectionChanged;
421 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
422 }
423 }
424 if (what & DisplayState::eSurfaceChanged) {
425 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
426 what &= ~DisplayState::eSurfaceChanged;
427 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
428 }
429 }
430}
431
Robert Carrde6d7b42022-01-07 18:23:06 -0800432void layer_state_t::sanitize(int32_t permissions) {
433 // TODO: b/109894387
434 //
435 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
436 // rotation. To see the problem observe that if we have a square parent, and a child
437 // of the same size, then we rotate the child 45 degrees around its center, the child
438 // must now be cropped to a non rectangular 8 sided region.
439 //
440 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
441 // private API, and arbitrary rotation is used in limited use cases, for instance:
442 // - WindowManager only uses rotation in one case, which is on a top level layer in which
443 // cropping is not an issue.
444 // - Launcher, as a privileged app, uses this to transition an application to PiP
445 // (picture-in-picture) mode.
446 //
447 // However given that abuse of rotation matrices could lead to surfaces extending outside
448 // of cropped areas, we need to prevent non-root clients without permission
449 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
450 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
451 // preserving transformations.
452 if (what & eMatrixChanged) {
453 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
454 ui::Transform t;
455 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
456 if (!t.preserveRects()) {
457 what &= ~eMatrixChanged;
458 ALOGE("Stripped non rect preserving matrix in sanitize");
459 }
460 }
461 }
462
463 if (what & eFlagsChanged) {
464 if ((flags & eLayerIsDisplayDecoration) &&
465 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
466 flags &= ~eLayerIsDisplayDecoration;
467 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
468 }
Vishnu Nair59a6be32024-01-29 10:26:21 -0800469 if ((mask & eCanOccludePresentation) &&
470 !(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
471 flags &= ~eCanOccludePresentation;
472 mask &= ~eCanOccludePresentation;
473 ALOGE("Stripped attempt to set eCanOccludePresentation in sanitize");
474 }
Robert Carrde6d7b42022-01-07 18:23:06 -0800475 }
476
477 if (what & layer_state_t::eInputInfoChanged) {
478 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
479 what &= ~eInputInfoChanged;
480 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
481 }
482 }
483 if (what & layer_state_t::eTrustedOverlayChanged) {
484 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
485 what &= ~eTrustedOverlayChanged;
486 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
487 }
488 }
489 if (what & layer_state_t::eDropInputModeChanged) {
490 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
491 what &= ~eDropInputModeChanged;
492 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
493 }
494 }
495 if (what & layer_state_t::eFrameRateSelectionPriority) {
496 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
497 what &= ~eFrameRateSelectionPriority;
498 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
499 }
500 }
501 if (what & layer_state_t::eFrameRateChanged) {
502 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
503 changeFrameRateStrategy,
504 "layer_state_t::sanitize",
505 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
506 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
507 }
508 }
509}
510
Robert Carr2c5f6d22017-09-26 12:30:35 -0700511void layer_state_t::merge(const layer_state_t& other) {
512 if (other.what & ePositionChanged) {
513 what |= ePositionChanged;
514 x = other.x;
515 y = other.y;
516 }
517 if (other.what & eLayerChanged) {
518 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700519 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700520 z = other.z;
521 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700522 if (other.what & eAlphaChanged) {
523 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000524 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700525 }
526 if (other.what & eMatrixChanged) {
527 what |= eMatrixChanged;
528 matrix = other.matrix;
529 }
530 if (other.what & eTransparentRegionChanged) {
531 what |= eTransparentRegionChanged;
532 transparentRegion = other.transparentRegion;
533 }
534 if (other.what & eFlagsChanged) {
535 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700536 flags &= ~other.mask;
537 flags |= (other.flags & other.mask);
538 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700539 }
540 if (other.what & eLayerStackChanged) {
541 what |= eLayerStackChanged;
542 layerStack = other.layerStack;
543 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700544 if (other.what & eCornerRadiusChanged) {
545 what |= eCornerRadiusChanged;
546 cornerRadius = other.cornerRadius;
547 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800548 if (other.what & eBackgroundBlurRadiusChanged) {
549 what |= eBackgroundBlurRadiusChanged;
550 backgroundBlurRadius = other.backgroundBlurRadius;
551 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700552 if (other.what & eBlurRegionsChanged) {
553 what |= eBlurRegionsChanged;
554 blurRegions = other.blurRegions;
555 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700556 if (other.what & eRelativeLayerChanged) {
557 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700558 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700559 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000560 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700561 }
562 if (other.what & eReparent) {
563 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000564 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700565 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000566 if (other.what & eBufferTransformChanged) {
567 what |= eBufferTransformChanged;
568 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700569 }
570 if (other.what & eTransformToDisplayInverseChanged) {
571 what |= eTransformToDisplayInverseChanged;
572 transformToDisplayInverse = other.transformToDisplayInverse;
573 }
574 if (other.what & eCropChanged) {
575 what |= eCropChanged;
576 crop = other.crop;
577 }
578 if (other.what & eBufferChanged) {
579 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500580 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700581 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000582 if (other.what & eTrustedPresentationInfoChanged) {
583 what |= eTrustedPresentationInfoChanged;
584 trustedPresentationListener = other.trustedPresentationListener;
585 trustedPresentationThresholds = other.trustedPresentationThresholds;
586 }
Marissa Wall61c58622018-07-18 10:12:20 -0700587 if (other.what & eDataspaceChanged) {
588 what |= eDataspaceChanged;
589 dataspace = other.dataspace;
590 }
John Reck68796592023-01-25 13:47:12 -0500591 if (other.what & eExtendedRangeBrightnessChanged) {
592 what |= eExtendedRangeBrightnessChanged;
Sally Qi963049b2023-03-23 14:06:21 -0700593 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
594 currentHdrSdrRatio = other.currentHdrSdrRatio;
John Reck68796592023-01-25 13:47:12 -0500595 }
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000596 if (other.what & eDesiredHdrHeadroomChanged) {
597 what |= eDesiredHdrHeadroomChanged;
598 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
599 }
Alec Mourif4af03e2023-02-11 00:25:24 +0000600 if (other.what & eCachingHintChanged) {
601 what |= eCachingHintChanged;
602 cachingHint = other.cachingHint;
603 }
Marissa Wall61c58622018-07-18 10:12:20 -0700604 if (other.what & eHdrMetadataChanged) {
605 what |= eHdrMetadataChanged;
606 hdrMetadata = other.hdrMetadata;
607 }
608 if (other.what & eSurfaceDamageRegionChanged) {
609 what |= eSurfaceDamageRegionChanged;
610 surfaceDamageRegion = other.surfaceDamageRegion;
611 }
612 if (other.what & eApiChanged) {
613 what |= eApiChanged;
614 api = other.api;
615 }
616 if (other.what & eSidebandStreamChanged) {
617 what |= eSidebandStreamChanged;
618 sidebandStream = other.sidebandStream;
619 }
Peiyong Lind3788632018-09-18 16:01:31 -0700620 if (other.what & eColorTransformChanged) {
621 what |= eColorTransformChanged;
622 colorTransform = other.colorTransform;
623 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700624 if (other.what & eHasListenerCallbacksChanged) {
625 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700626 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700627 if (other.what & eInputInfoChanged) {
628 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500629 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700630 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800631 if (other.what & eBackgroundColorChanged) {
632 what |= eBackgroundColorChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000633 bgColor = other.bgColor;
Valerie Haudd0b7572019-01-29 14:59:27 -0800634 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800635 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800636 if (other.what & eMetadataChanged) {
637 what |= eMetadataChanged;
638 metadata.merge(other.metadata);
639 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700640 if (other.what & eShadowRadiusChanged) {
641 what |= eShadowRadiusChanged;
642 shadowRadius = other.shadowRadius;
643 }
Andy Labrada096227e2022-06-15 16:58:11 +0000644 if (other.what & eDefaultFrameRateCompatibilityChanged) {
645 what |= eDefaultFrameRateCompatibilityChanged;
646 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
647 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100648 if (other.what & eFrameRateSelectionPriority) {
649 what |= eFrameRateSelectionPriority;
650 frameRateSelectionPriority = other.frameRateSelectionPriority;
651 }
Steven Thomas3172e202020-01-06 19:25:30 -0800652 if (other.what & eFrameRateChanged) {
653 what |= eFrameRateChanged;
654 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800655 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100656 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800657 }
Rachel Leece6e0042023-06-27 11:22:54 -0700658 if (other.what & eFrameRateCategoryChanged) {
659 what |= eFrameRateCategoryChanged;
660 frameRateCategory = other.frameRateCategory;
Rachel Lee67afbea2023-09-28 15:35:07 -0700661 frameRateCategorySmoothSwitchOnly = other.frameRateCategorySmoothSwitchOnly;
Rachel Leece6e0042023-06-27 11:22:54 -0700662 }
Rachel Lee58cc90d2023-09-05 18:50:20 -0700663 if (other.what & eFrameRateSelectionStrategyChanged) {
664 what |= eFrameRateSelectionStrategyChanged;
665 frameRateSelectionStrategy = other.frameRateSelectionStrategy;
666 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700667 if (other.what & eFixedTransformHintChanged) {
668 what |= eFixedTransformHintChanged;
669 fixedTransformHint = other.fixedTransformHint;
670 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800671 if (other.what & eAutoRefreshChanged) {
672 what |= eAutoRefreshChanged;
673 autoRefresh = other.autoRefresh;
674 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700675 if (other.what & eTrustedOverlayChanged) {
676 what |= eTrustedOverlayChanged;
677 isTrustedOverlay = other.isTrustedOverlay;
678 }
John Reckc00c6692021-02-16 11:37:33 -0500679 if (other.what & eStretchChanged) {
680 what |= eStretchChanged;
681 stretchEffect = other.stretchEffect;
682 }
chaviwf3f40fe2021-04-27 15:54:02 -0500683 if (other.what & eBufferCropChanged) {
684 what |= eBufferCropChanged;
685 bufferCrop = other.bufferCrop;
686 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700687 if (other.what & eDestinationFrameChanged) {
688 what |= eDestinationFrameChanged;
689 destinationFrame = other.destinationFrame;
690 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700691 if (other.what & eProducerDisconnect) {
692 what |= eProducerDisconnect;
693 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700694 if (other.what & eDropInputModeChanged) {
695 what |= eDropInputModeChanged;
696 dropInputMode = other.dropInputMode;
697 }
chaviw4c36cd82021-11-18 10:37:33 -0600698 if (other.what & eColorChanged) {
699 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000700 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600701 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800702 if (other.what & eColorSpaceAgnosticChanged) {
703 what |= eColorSpaceAgnosticChanged;
704 colorSpaceAgnostic = other.colorSpaceAgnostic;
705 }
Sally Qi81d95e62022-03-21 19:41:33 -0700706 if (other.what & eDimmingEnabledChanged) {
707 what |= eDimmingEnabledChanged;
708 dimmingEnabled = other.dimmingEnabled;
709 }
Pascal Muetschardb39918f2023-01-27 11:36:11 +0100710 if (other.what & eFlushJankData) {
711 what |= eFlushJankData;
712 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700713 if ((other.what & what) != other.what) {
714 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700715 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
716 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700717 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700718}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700719
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000720uint64_t layer_state_t::diff(const layer_state_t& other) const {
721 uint64_t diff = 0;
722 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
723 if (other.what & eLayerChanged) {
724 diff |= eLayerChanged;
725 diff &= ~eRelativeLayerChanged;
726 }
727 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
728 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
729 if (other.what & eTransparentRegionChanged &&
730 (!transparentRegion.hasSameRects(other.transparentRegion))) {
731 diff |= eTransparentRegionChanged;
732 }
733 if (other.what & eFlagsChanged) {
734 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
735 if (changedFlags) diff |= eFlagsChanged;
736 }
737 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
738 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
739 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
740 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
741 if (other.what & eRelativeLayerChanged) {
742 diff |= eRelativeLayerChanged;
743 diff &= ~eLayerChanged;
744 }
745 if (other.what & eReparent &&
746 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
747 other.parentSurfaceControlForChild)) {
748 diff |= eReparent;
749 }
750 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
751 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
752 CHECK_DIFF(diff, eCropChanged, other, crop);
753 if (other.what & eBufferChanged) diff |= eBufferChanged;
754 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
Sally Qi963049b2023-03-23 14:06:21 -0700755 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio,
756 desiredHdrSdrRatio);
Alec Mouri1b0d4e12024-02-12 22:27:19 +0000757 CHECK_DIFF(diff, eDesiredHdrHeadroomChanged, other, desiredHdrSdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000758 CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000759 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
760 if (other.what & eSurfaceDamageRegionChanged &&
761 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
762 diff |= eSurfaceDamageRegionChanged;
763 }
764 CHECK_DIFF(diff, eApiChanged, other, api);
765 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
766 CHECK_DIFF(diff, eApiChanged, other, api);
767 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
768 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
769 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000770 CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000771 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
772 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000773 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
774 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
775 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
776 changeFrameRateStrategy);
Rachel Lee67afbea2023-09-28 15:35:07 -0700777 CHECK_DIFF2(diff, eFrameRateCategoryChanged, other, frameRateCategory,
778 frameRateCategorySmoothSwitchOnly);
Rachel Lee58cc90d2023-09-05 18:50:20 -0700779 CHECK_DIFF(diff, eFrameRateSelectionStrategyChanged, other, frameRateSelectionStrategy);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000780 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
781 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
782 CHECK_DIFF(diff, eTrustedOverlayChanged, other, isTrustedOverlay);
783 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
784 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
785 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
786 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
787 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
788 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
789 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
790 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
791 return diff;
792}
793
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700794bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500795 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700796}
797
Ady Abraham6e8e3642021-07-08 19:44:07 -0700798bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700799 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700800}
801
chaviw308ddba2020-08-11 16:23:51 -0700802status_t layer_state_t::matrix22_t::write(Parcel& output) const {
803 SAFE_PARCEL(output.writeFloat, dsdx);
804 SAFE_PARCEL(output.writeFloat, dtdx);
805 SAFE_PARCEL(output.writeFloat, dtdy);
806 SAFE_PARCEL(output.writeFloat, dsdy);
807 return NO_ERROR;
808}
809
810status_t layer_state_t::matrix22_t::read(const Parcel& input) {
811 SAFE_PARCEL(input.readFloat, &dsdx);
812 SAFE_PARCEL(input.readFloat, &dtdx);
813 SAFE_PARCEL(input.readFloat, &dtdy);
814 SAFE_PARCEL(input.readFloat, &dsdy);
815 return NO_ERROR;
816}
817
chaviw273171b2018-12-26 11:46:30 -0800818// ------------------------------- InputWindowCommands ----------------------------------------
819
Vishnu Naire798b472020-07-23 13:52:21 -0700820bool InputWindowCommands::merge(const InputWindowCommands& other) {
821 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700822 changes |= !other.focusRequests.empty();
823 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
824 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000825 changes |= !other.windowInfosReportedListeners.empty();
826 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
827 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700828 return changes;
chaviw273171b2018-12-26 11:46:30 -0800829}
830
Vishnu Nair958da932020-08-21 17:12:37 -0700831bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000832 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700833}
834
chaviw273171b2018-12-26 11:46:30 -0800835void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700836 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000837 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800838}
839
chaviw308ddba2020-08-11 16:23:51 -0700840status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700841 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000842
843 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
844 for (const auto& listener : windowInfosReportedListeners) {
845 SAFE_PARCEL(output.writeStrongBinder, listener);
846 }
847
chaviw308ddba2020-08-11 16:23:51 -0700848 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800849}
850
chaviw308ddba2020-08-11 16:23:51 -0700851status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700852 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000853
854 int listenerSize = 0;
855 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
856 windowInfosReportedListeners.reserve(listenerSize);
857 for (int i = 0; i < listenerSize; i++) {
858 sp<gui::IWindowInfosReportedListener> listener;
859 SAFE_PARCEL(input.readStrongBinder, &listener);
860 windowInfosReportedListeners.insert(listener);
861 }
862
chaviw308ddba2020-08-11 16:23:51 -0700863 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800864}
865
chaviw618c42d2020-07-24 15:25:08 -0700866// ----------------------------------------------------------------------------
867
Huihong Luo9e84f332021-12-16 14:33:46 -0800868namespace gui {
869
870status_t CaptureArgs::writeToParcel(Parcel* output) const {
871 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
872 SAFE_PARCEL(output->write, sourceCrop);
873 SAFE_PARCEL(output->writeFloat, frameScaleX);
874 SAFE_PARCEL(output->writeFloat, frameScaleY);
875 SAFE_PARCEL(output->writeBool, captureSecureLayers);
876 SAFE_PARCEL(output->writeInt32, uid);
877 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
878 SAFE_PARCEL(output->writeBool, allowProtected);
879 SAFE_PARCEL(output->writeBool, grayscale);
Ajinkya Chalke02844632023-03-01 12:10:14 +0000880 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
881 for (auto& excludeHandle : excludeHandles) {
882 SAFE_PARCEL(output->writeStrongBinder, excludeHandle);
883 }
Alec Mouri3e5965f2023-04-07 18:00:58 +0000884 SAFE_PARCEL(output->writeBool, hintForSeamlessTransition);
chaviw308ddba2020-08-11 16:23:51 -0700885 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700886}
887
Huihong Luo9e84f332021-12-16 14:33:46 -0800888status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700889 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800890 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700891 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800892 SAFE_PARCEL(input->read, sourceCrop);
893 SAFE_PARCEL(input->readFloat, &frameScaleX);
894 SAFE_PARCEL(input->readFloat, &frameScaleY);
895 SAFE_PARCEL(input->readBool, &captureSecureLayers);
896 SAFE_PARCEL(input->readInt32, &uid);
897 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700898 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800899 SAFE_PARCEL(input->readBool, &allowProtected);
900 SAFE_PARCEL(input->readBool, &grayscale);
Ajinkya Chalke02844632023-03-01 12:10:14 +0000901 int32_t numExcludeHandles = 0;
902 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
903 excludeHandles.reserve(numExcludeHandles);
904 for (int i = 0; i < numExcludeHandles; i++) {
905 sp<IBinder> binder;
906 SAFE_PARCEL(input->readStrongBinder, &binder);
907 excludeHandles.emplace(binder);
908 }
Alec Mouri3e5965f2023-04-07 18:00:58 +0000909 SAFE_PARCEL(input->readBool, &hintForSeamlessTransition);
chaviw308ddba2020-08-11 16:23:51 -0700910 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700911}
912
Huihong Luo9e84f332021-12-16 14:33:46 -0800913status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
914 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700915
Huihong Luo9e84f332021-12-16 14:33:46 -0800916 SAFE_PARCEL(output->writeStrongBinder, displayToken);
917 SAFE_PARCEL(output->writeUint32, width);
918 SAFE_PARCEL(output->writeUint32, height);
chaviw308ddba2020-08-11 16:23:51 -0700919 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700920}
921
Huihong Luo9e84f332021-12-16 14:33:46 -0800922status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
923 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700924
Huihong Luo9e84f332021-12-16 14:33:46 -0800925 SAFE_PARCEL(input->readStrongBinder, &displayToken);
926 SAFE_PARCEL(input->readUint32, &width);
927 SAFE_PARCEL(input->readUint32, &height);
chaviw308ddba2020-08-11 16:23:51 -0700928 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700929}
930
Huihong Luo9e84f332021-12-16 14:33:46 -0800931status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
932 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700933
Huihong Luo9e84f332021-12-16 14:33:46 -0800934 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
Huihong Luo9e84f332021-12-16 14:33:46 -0800935 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700936 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700937}
938
Huihong Luo9e84f332021-12-16 14:33:46 -0800939status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
940 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700941
Huihong Luo9e84f332021-12-16 14:33:46 -0800942 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700943
Huihong Luo9e84f332021-12-16 14:33:46 -0800944 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700945 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700946}
947
Huihong Luo9e84f332021-12-16 14:33:46 -0800948}; // namespace gui
949
chaviw8dd181f2022-01-05 18:36:46 -0600950ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500951 uint64_t bufferId;
952 if (buffer) {
953 bufferId = buffer->getId();
954 } else {
955 bufferId = cachedBuffer.id;
956 }
957 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600958}
959
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800960status_t BufferData::writeToParcel(Parcel* output) const {
961 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500962
963 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800964 SAFE_PARCEL(output->writeBool, true);
965 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500966 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800967 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500968 }
969
970 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800971 SAFE_PARCEL(output->writeBool, true);
972 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500973 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800974 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500975 }
976
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800977 SAFE_PARCEL(output->writeUint64, frameNumber);
978 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
979 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500980
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800981 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
982 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800983 SAFE_PARCEL(output->writeBool, hasBarrier);
984 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +0800985 SAFE_PARCEL(output->writeUint32, producerId);
chaviwba4320c2021-09-15 15:20:53 -0500986
987 return NO_ERROR;
988}
989
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800990status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500991 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800992 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700993 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500994
995 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800996 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500997 if (tmpBool) {
998 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800999 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -05001000 }
1001
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001002 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001003 if (tmpBool) {
1004 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001005 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -05001006 }
1007
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001008 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -05001009
1010 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001011 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001012 if (tmpBinder) {
1013 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1014 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001015 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001016
1017 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001018 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001019 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001020 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -05001021
Robert Carr79dc06a2022-02-22 15:28:59 -08001022 SAFE_PARCEL(input->readBool, &hasBarrier);
1023 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001024 SAFE_PARCEL(input->readUint32, &producerId);
Robert Carr79dc06a2022-02-22 15:28:59 -08001025
chaviwba4320c2021-09-15 15:20:53 -05001026 return NO_ERROR;
1027}
1028
Chavi Weingarten076acac2023-01-19 17:20:43 +00001029status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1030 SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1031 SAFE_PARCEL(parcel->writeInt32, callbackId);
1032 return NO_ERROR;
1033}
1034
1035status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1036 sp<IBinder> tmpBinder = nullptr;
1037 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1038 if (tmpBinder) {
1039 callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1040 }
1041 SAFE_PARCEL(parcel->readInt32, &callbackId);
1042 return NO_ERROR;
1043}
1044
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001045}; // namespace android