blob: 9847c056b84d3c073290695a2196c2f99c7a7de7 [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),
Pablo Gamito11dcc222020-09-12 15:49:39 +000088 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080089 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070090 isTrustedOverlay(false),
Tianhao Yao67dd7122022-02-22 17:48:33 +000091 borderEnabled(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070092 bufferCrop(Rect::INVALID_RECT),
93 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070094 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000095 matrix.dsdx = matrix.dtdy = 1.0f;
96 matrix.dsdy = matrix.dtdx = 0.0f;
97 hdrMetadata.validTypes = 0;
98}
99
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100status_t layer_state_t::write(Parcel& output) const
101{
chaviw308ddba2020-08-11 16:23:51 -0700102 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000103 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -0700104 SAFE_PARCEL(output.writeUint64, what);
105 SAFE_PARCEL(output.writeFloat, x);
106 SAFE_PARCEL(output.writeFloat, y);
107 SAFE_PARCEL(output.writeInt32, z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700108 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700109 SAFE_PARCEL(output.writeUint32, flags);
110 SAFE_PARCEL(output.writeUint32, mask);
111 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -0800112 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000113 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
114 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -0700115 SAFE_PARCEL(output.writeFloat, color.r);
116 SAFE_PARCEL(output.writeFloat, color.g);
117 SAFE_PARCEL(output.writeFloat, color.b);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000118 SAFE_PARCEL(output.writeFloat, color.a);
chaviw98318de2021-05-19 16:45:23 -0500119 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700120 SAFE_PARCEL(output.write, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000121 SAFE_PARCEL(output.writeUint32, bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700122 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000123 SAFE_PARCEL(output.writeBool, borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000124 SAFE_PARCEL(output.writeFloat, borderWidth);
125 SAFE_PARCEL(output.writeFloat, borderColor.r);
126 SAFE_PARCEL(output.writeFloat, borderColor.g);
127 SAFE_PARCEL(output.writeFloat, borderColor.b);
128 SAFE_PARCEL(output.writeFloat, borderColor.a);
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);
chaviw308ddba2020-08-11 16:23:51 -0700164 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800165 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700166 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700167
168 SAFE_PARCEL(output.writeUint32, blurRegions.size());
169 for (auto region : blurRegions) {
170 SAFE_PARCEL(output.writeUint32, region.blurRadius);
171 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
172 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
173 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
174 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
175 SAFE_PARCEL(output.writeFloat, region.alpha);
176 SAFE_PARCEL(output.writeInt32, region.left);
177 SAFE_PARCEL(output.writeInt32, region.top);
178 SAFE_PARCEL(output.writeInt32, region.right);
179 SAFE_PARCEL(output.writeInt32, region.bottom);
180 }
John Reckcdb4ed72021-02-04 13:39:33 -0500181
182 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500183 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700184 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700185 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500186
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700187 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800188
189 const bool hasBufferData = (bufferData != nullptr);
190 SAFE_PARCEL(output.writeBool, hasBufferData);
191 if (hasBufferData) {
192 SAFE_PARCEL(output.writeParcelable, *bufferData);
193 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000194 SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds);
195 SAFE_PARCEL(output.writeParcelable, trustedPresentationListener);
Sally Qi963049b2023-03-23 14:06:21 -0700196 SAFE_PARCEL(output.writeFloat, currentHdrSdrRatio);
197 SAFE_PARCEL(output.writeFloat, desiredHdrSdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000198 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(cachingHint))
Mathias Agopianac9fa422013-02-11 16:40:36 -0800199 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800200}
201
202status_t layer_state_t::read(const Parcel& input)
203{
chaviw308ddba2020-08-11 16:23:51 -0700204 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000205 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700206 SAFE_PARCEL(input.readUint64, &what);
207 SAFE_PARCEL(input.readFloat, &x);
208 SAFE_PARCEL(input.readFloat, &y);
209 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700210 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700211
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800212 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700213
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800214 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700215
216 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800217 SAFE_PARCEL(input.read, crop);
chaviw308ddba2020-08-11 16:23:51 -0700218
Pablo Gamito11dcc222020-09-12 15:49:39 +0000219 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
220 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
221
chaviw308ddba2020-08-11 16:23:51 -0700222 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700223 SAFE_PARCEL(input.readFloat, &tmpFloat);
224 color.r = tmpFloat;
225 SAFE_PARCEL(input.readFloat, &tmpFloat);
226 color.g = tmpFloat;
227 SAFE_PARCEL(input.readFloat, &tmpFloat);
228 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000229 SAFE_PARCEL(input.readFloat, &tmpFloat);
230 color.a = tmpFloat;
231
chaviw98318de2021-05-19 16:45:23 -0500232 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700233
chaviw308ddba2020-08-11 16:23:51 -0700234 SAFE_PARCEL(input.read, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000235 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700236 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000237 SAFE_PARCEL(input.readBool, &borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000238 SAFE_PARCEL(input.readFloat, &tmpFloat);
239 borderWidth = tmpFloat;
240 SAFE_PARCEL(input.readFloat, &tmpFloat);
241 borderColor.r = tmpFloat;
242 SAFE_PARCEL(input.readFloat, &tmpFloat);
243 borderColor.g = tmpFloat;
244 SAFE_PARCEL(input.readFloat, &tmpFloat);
245 borderColor.b = tmpFloat;
246 SAFE_PARCEL(input.readFloat, &tmpFloat);
247 borderColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700248
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800249 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700250 SAFE_PARCEL(input.readUint32, &tmpUint32);
251 dataspace = static_cast<ui::Dataspace>(tmpUint32);
252
253 SAFE_PARCEL(input.read, hdrMetadata);
254 SAFE_PARCEL(input.read, surfaceDamageRegion);
255 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500256
257 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700258 SAFE_PARCEL(input.readBool, &tmpBool);
259 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700260 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
261 }
262
chaviw308ddba2020-08-11 16:23:51 -0700263 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
264 SAFE_PARCEL(input.readFloat, &cornerRadius);
265 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700266 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800267
Vishnu Naird47bcee2023-02-24 18:08:51 +0000268 SAFE_PARCEL(input.readFloat, &tmpFloat);
269 bgColor.r = tmpFloat;
270 SAFE_PARCEL(input.readFloat, &tmpFloat);
271 bgColor.g = tmpFloat;
272 SAFE_PARCEL(input.readFloat, &tmpFloat);
273 bgColor.b = tmpFloat;
274 SAFE_PARCEL(input.readFloat, &tmpFloat);
275 bgColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700276 SAFE_PARCEL(input.readUint32, &tmpUint32);
277 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
278 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800279
chaviw308ddba2020-08-11 16:23:51 -0700280 int32_t numListeners = 0;
281 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700282 listeners.clear();
283 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700284 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700285 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700286 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700287 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700288 listeners.emplace_back(listener, callbackIds);
289 }
chaviw308ddba2020-08-11 16:23:51 -0700290 SAFE_PARCEL(input.readFloat, &shadowRadius);
291 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
292 SAFE_PARCEL(input.readFloat, &frameRate);
293 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100294 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000295 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
Rachel Leece6e0042023-06-27 11:22:54 -0700296 SAFE_PARCEL(input.readByte, &frameRateCategory);
chaviw308ddba2020-08-11 16:23:51 -0700297 SAFE_PARCEL(input.readUint32, &tmpUint32);
298 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800299 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700300 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700301
302 uint32_t numRegions = 0;
303 SAFE_PARCEL(input.readUint32, &numRegions);
304 blurRegions.clear();
305 for (uint32_t i = 0; i < numRegions; i++) {
306 BlurRegion region;
307 SAFE_PARCEL(input.readUint32, &region.blurRadius);
308 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
309 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
310 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
311 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
312 SAFE_PARCEL(input.readFloat, &region.alpha);
313 SAFE_PARCEL(input.readInt32, &region.left);
314 SAFE_PARCEL(input.readInt32, &region.top);
315 SAFE_PARCEL(input.readInt32, &region.right);
316 SAFE_PARCEL(input.readInt32, &region.bottom);
317 blurRegions.push_back(region);
318 }
John Reckcdb4ed72021-02-04 13:39:33 -0500319
320 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500321 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700322 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700323 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500324
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700325 uint32_t mode;
326 SAFE_PARCEL(input.readUint32, &mode);
327 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800328
329 bool hasBufferData;
330 SAFE_PARCEL(input.readBool, &hasBufferData);
331 if (hasBufferData) {
332 bufferData = std::make_shared<BufferData>();
333 SAFE_PARCEL(input.readParcelable, bufferData.get());
334 } else {
335 bufferData = nullptr;
336 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000337
338 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
339 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
340
John Reck68796592023-01-25 13:47:12 -0500341 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700342 currentHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500343 SAFE_PARCEL(input.readFloat, &tmpFloat);
Sally Qi963049b2023-03-23 14:06:21 -0700344 desiredHdrSdrRatio = tmpFloat;
John Reck68796592023-01-25 13:47:12 -0500345
Alec Mourif4af03e2023-02-11 00:25:24 +0000346 int32_t tmpInt32;
347 SAFE_PARCEL(input.readInt32, &tmpInt32);
348 cachingHint = static_cast<gui::CachingHint>(tmpInt32);
349
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800350 return NO_ERROR;
351}
352
Mathias Agopian698c0872011-06-28 19:09:31 -0700353status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700354 return state.write(output);
355}
356
357status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700358 return state.read(input);
359}
360
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700361DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700362
Mathias Agopian8b33f032012-07-24 20:43:54 -0700363status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700364 SAFE_PARCEL(output.writeStrongBinder, token);
365 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
366 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700367 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700368 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700369 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
370 SAFE_PARCEL(output.write, layerStackSpaceRect);
371 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
372 SAFE_PARCEL(output.writeUint32, width);
373 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700374 return NO_ERROR;
375}
376
377status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700378 SAFE_PARCEL(input.readStrongBinder, &token);
379 sp<IBinder> tmpBinder;
380 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
381 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
382
383 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700384 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700385 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700386 uint32_t tmpUint = 0;
387 SAFE_PARCEL(input.readUint32, &tmpUint);
388 orientation = ui::toRotation(tmpUint);
389
390 SAFE_PARCEL(input.read, layerStackSpaceRect);
391 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
392 SAFE_PARCEL(input.readUint32, &width);
393 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700394 return NO_ERROR;
395}
396
Robert Carr2c5f6d22017-09-26 12:30:35 -0700397void DisplayState::merge(const DisplayState& other) {
398 if (other.what & eSurfaceChanged) {
399 what |= eSurfaceChanged;
400 surface = other.surface;
401 }
402 if (other.what & eLayerStackChanged) {
403 what |= eLayerStackChanged;
404 layerStack = other.layerStack;
405 }
Evan Rosky2239b372021-05-20 13:43:47 -0700406 if (other.what & eFlagsChanged) {
407 what |= eFlagsChanged;
408 flags = other.flags;
409 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700410 if (other.what & eDisplayProjectionChanged) {
411 what |= eDisplayProjectionChanged;
412 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200413 layerStackSpaceRect = other.layerStackSpaceRect;
414 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700415 }
416 if (other.what & eDisplaySizeChanged) {
417 what |= eDisplaySizeChanged;
418 width = other.width;
419 height = other.height;
420 }
421}
422
Sally Qi6bb12822022-10-05 11:42:30 -0700423void DisplayState::sanitize(int32_t permissions) {
424 if (what & DisplayState::eLayerStackChanged) {
425 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
426 what &= ~DisplayState::eLayerStackChanged;
427 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
428 }
429 }
430 if (what & DisplayState::eDisplayProjectionChanged) {
431 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
432 what &= ~DisplayState::eDisplayProjectionChanged;
433 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
434 }
435 }
436 if (what & DisplayState::eSurfaceChanged) {
437 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
438 what &= ~DisplayState::eSurfaceChanged;
439 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
440 }
441 }
442}
443
Robert Carrde6d7b42022-01-07 18:23:06 -0800444void layer_state_t::sanitize(int32_t permissions) {
445 // TODO: b/109894387
446 //
447 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
448 // rotation. To see the problem observe that if we have a square parent, and a child
449 // of the same size, then we rotate the child 45 degrees around its center, the child
450 // must now be cropped to a non rectangular 8 sided region.
451 //
452 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
453 // private API, and arbitrary rotation is used in limited use cases, for instance:
454 // - WindowManager only uses rotation in one case, which is on a top level layer in which
455 // cropping is not an issue.
456 // - Launcher, as a privileged app, uses this to transition an application to PiP
457 // (picture-in-picture) mode.
458 //
459 // However given that abuse of rotation matrices could lead to surfaces extending outside
460 // of cropped areas, we need to prevent non-root clients without permission
461 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
462 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
463 // preserving transformations.
464 if (what & eMatrixChanged) {
465 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
466 ui::Transform t;
467 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
468 if (!t.preserveRects()) {
469 what &= ~eMatrixChanged;
470 ALOGE("Stripped non rect preserving matrix in sanitize");
471 }
472 }
473 }
474
475 if (what & eFlagsChanged) {
476 if ((flags & eLayerIsDisplayDecoration) &&
477 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
478 flags &= ~eLayerIsDisplayDecoration;
479 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
480 }
481 }
482
483 if (what & layer_state_t::eInputInfoChanged) {
484 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
485 what &= ~eInputInfoChanged;
486 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
487 }
488 }
489 if (what & layer_state_t::eTrustedOverlayChanged) {
490 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
491 what &= ~eTrustedOverlayChanged;
492 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
493 }
494 }
495 if (what & layer_state_t::eDropInputModeChanged) {
496 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
497 what &= ~eDropInputModeChanged;
498 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
499 }
500 }
501 if (what & layer_state_t::eFrameRateSelectionPriority) {
502 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
503 what &= ~eFrameRateSelectionPriority;
504 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
505 }
506 }
507 if (what & layer_state_t::eFrameRateChanged) {
508 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
509 changeFrameRateStrategy,
510 "layer_state_t::sanitize",
511 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
512 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
513 }
514 }
515}
516
Robert Carr2c5f6d22017-09-26 12:30:35 -0700517void layer_state_t::merge(const layer_state_t& other) {
518 if (other.what & ePositionChanged) {
519 what |= ePositionChanged;
520 x = other.x;
521 y = other.y;
522 }
523 if (other.what & eLayerChanged) {
524 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700525 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700526 z = other.z;
527 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700528 if (other.what & eAlphaChanged) {
529 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000530 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700531 }
532 if (other.what & eMatrixChanged) {
533 what |= eMatrixChanged;
534 matrix = other.matrix;
535 }
536 if (other.what & eTransparentRegionChanged) {
537 what |= eTransparentRegionChanged;
538 transparentRegion = other.transparentRegion;
539 }
540 if (other.what & eFlagsChanged) {
541 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700542 flags &= ~other.mask;
543 flags |= (other.flags & other.mask);
544 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700545 }
546 if (other.what & eLayerStackChanged) {
547 what |= eLayerStackChanged;
548 layerStack = other.layerStack;
549 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700550 if (other.what & eCornerRadiusChanged) {
551 what |= eCornerRadiusChanged;
552 cornerRadius = other.cornerRadius;
553 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800554 if (other.what & eBackgroundBlurRadiusChanged) {
555 what |= eBackgroundBlurRadiusChanged;
556 backgroundBlurRadius = other.backgroundBlurRadius;
557 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700558 if (other.what & eBlurRegionsChanged) {
559 what |= eBlurRegionsChanged;
560 blurRegions = other.blurRegions;
561 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700562 if (other.what & eRelativeLayerChanged) {
563 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700564 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700565 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000566 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700567 }
568 if (other.what & eReparent) {
569 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000570 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700571 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000572 if (other.what & eBufferTransformChanged) {
573 what |= eBufferTransformChanged;
574 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700575 }
576 if (other.what & eTransformToDisplayInverseChanged) {
577 what |= eTransformToDisplayInverseChanged;
578 transformToDisplayInverse = other.transformToDisplayInverse;
579 }
580 if (other.what & eCropChanged) {
581 what |= eCropChanged;
582 crop = other.crop;
583 }
584 if (other.what & eBufferChanged) {
585 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500586 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700587 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000588 if (other.what & eTrustedPresentationInfoChanged) {
589 what |= eTrustedPresentationInfoChanged;
590 trustedPresentationListener = other.trustedPresentationListener;
591 trustedPresentationThresholds = other.trustedPresentationThresholds;
592 }
Marissa Wall61c58622018-07-18 10:12:20 -0700593 if (other.what & eDataspaceChanged) {
594 what |= eDataspaceChanged;
595 dataspace = other.dataspace;
596 }
John Reck68796592023-01-25 13:47:12 -0500597 if (other.what & eExtendedRangeBrightnessChanged) {
598 what |= eExtendedRangeBrightnessChanged;
Sally Qi963049b2023-03-23 14:06:21 -0700599 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
600 currentHdrSdrRatio = other.currentHdrSdrRatio;
John Reck68796592023-01-25 13:47:12 -0500601 }
Alec Mourif4af03e2023-02-11 00:25:24 +0000602 if (other.what & eCachingHintChanged) {
603 what |= eCachingHintChanged;
604 cachingHint = other.cachingHint;
605 }
Marissa Wall61c58622018-07-18 10:12:20 -0700606 if (other.what & eHdrMetadataChanged) {
607 what |= eHdrMetadataChanged;
608 hdrMetadata = other.hdrMetadata;
609 }
610 if (other.what & eSurfaceDamageRegionChanged) {
611 what |= eSurfaceDamageRegionChanged;
612 surfaceDamageRegion = other.surfaceDamageRegion;
613 }
614 if (other.what & eApiChanged) {
615 what |= eApiChanged;
616 api = other.api;
617 }
618 if (other.what & eSidebandStreamChanged) {
619 what |= eSidebandStreamChanged;
620 sidebandStream = other.sidebandStream;
621 }
Peiyong Lind3788632018-09-18 16:01:31 -0700622 if (other.what & eColorTransformChanged) {
623 what |= eColorTransformChanged;
624 colorTransform = other.colorTransform;
625 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700626 if (other.what & eHasListenerCallbacksChanged) {
627 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700628 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700629 if (other.what & eInputInfoChanged) {
630 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500631 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700632 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800633 if (other.what & eBackgroundColorChanged) {
634 what |= eBackgroundColorChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000635 bgColor = other.bgColor;
Valerie Haudd0b7572019-01-29 14:59:27 -0800636 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800637 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800638 if (other.what & eMetadataChanged) {
639 what |= eMetadataChanged;
640 metadata.merge(other.metadata);
641 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700642 if (other.what & eShadowRadiusChanged) {
643 what |= eShadowRadiusChanged;
644 shadowRadius = other.shadowRadius;
645 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000646 if (other.what & eRenderBorderChanged) {
647 what |= eRenderBorderChanged;
648 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000649 borderWidth = other.borderWidth;
650 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000651 }
Andy Labrada096227e2022-06-15 16:58:11 +0000652 if (other.what & eDefaultFrameRateCompatibilityChanged) {
653 what |= eDefaultFrameRateCompatibilityChanged;
654 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
655 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100656 if (other.what & eFrameRateSelectionPriority) {
657 what |= eFrameRateSelectionPriority;
658 frameRateSelectionPriority = other.frameRateSelectionPriority;
659 }
Steven Thomas3172e202020-01-06 19:25:30 -0800660 if (other.what & eFrameRateChanged) {
661 what |= eFrameRateChanged;
662 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800663 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100664 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800665 }
Rachel Leece6e0042023-06-27 11:22:54 -0700666 if (other.what & eFrameRateCategoryChanged) {
667 what |= eFrameRateCategoryChanged;
668 frameRateCategory = other.frameRateCategory;
669 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700670 if (other.what & eFixedTransformHintChanged) {
671 what |= eFixedTransformHintChanged;
672 fixedTransformHint = other.fixedTransformHint;
673 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800674 if (other.what & eAutoRefreshChanged) {
675 what |= eAutoRefreshChanged;
676 autoRefresh = other.autoRefresh;
677 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700678 if (other.what & eTrustedOverlayChanged) {
679 what |= eTrustedOverlayChanged;
680 isTrustedOverlay = other.isTrustedOverlay;
681 }
John Reckc00c6692021-02-16 11:37:33 -0500682 if (other.what & eStretchChanged) {
683 what |= eStretchChanged;
684 stretchEffect = other.stretchEffect;
685 }
chaviwf3f40fe2021-04-27 15:54:02 -0500686 if (other.what & eBufferCropChanged) {
687 what |= eBufferCropChanged;
688 bufferCrop = other.bufferCrop;
689 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700690 if (other.what & eDestinationFrameChanged) {
691 what |= eDestinationFrameChanged;
692 destinationFrame = other.destinationFrame;
693 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700694 if (other.what & eProducerDisconnect) {
695 what |= eProducerDisconnect;
696 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700697 if (other.what & eDropInputModeChanged) {
698 what |= eDropInputModeChanged;
699 dropInputMode = other.dropInputMode;
700 }
chaviw4c36cd82021-11-18 10:37:33 -0600701 if (other.what & eColorChanged) {
702 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000703 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600704 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800705 if (other.what & eColorSpaceAgnosticChanged) {
706 what |= eColorSpaceAgnosticChanged;
707 colorSpaceAgnostic = other.colorSpaceAgnostic;
708 }
Sally Qi81d95e62022-03-21 19:41:33 -0700709 if (other.what & eDimmingEnabledChanged) {
710 what |= eDimmingEnabledChanged;
711 dimmingEnabled = other.dimmingEnabled;
712 }
Pascal Muetschardb39918f2023-01-27 11:36:11 +0100713 if (other.what & eFlushJankData) {
714 what |= eFlushJankData;
715 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700716 if ((other.what & what) != other.what) {
717 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700718 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
719 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700720 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700721}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700722
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000723uint64_t layer_state_t::diff(const layer_state_t& other) const {
724 uint64_t diff = 0;
725 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
726 if (other.what & eLayerChanged) {
727 diff |= eLayerChanged;
728 diff &= ~eRelativeLayerChanged;
729 }
730 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
731 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
732 if (other.what & eTransparentRegionChanged &&
733 (!transparentRegion.hasSameRects(other.transparentRegion))) {
734 diff |= eTransparentRegionChanged;
735 }
736 if (other.what & eFlagsChanged) {
737 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
738 if (changedFlags) diff |= eFlagsChanged;
739 }
740 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
741 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
742 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
743 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
744 if (other.what & eRelativeLayerChanged) {
745 diff |= eRelativeLayerChanged;
746 diff &= ~eLayerChanged;
747 }
748 if (other.what & eReparent &&
749 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
750 other.parentSurfaceControlForChild)) {
751 diff |= eReparent;
752 }
753 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
754 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
755 CHECK_DIFF(diff, eCropChanged, other, crop);
756 if (other.what & eBufferChanged) diff |= eBufferChanged;
757 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
Sally Qi963049b2023-03-23 14:06:21 -0700758 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio,
759 desiredHdrSdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000760 CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000761 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
762 if (other.what & eSurfaceDamageRegionChanged &&
763 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
764 diff |= eSurfaceDamageRegionChanged;
765 }
766 CHECK_DIFF(diff, eApiChanged, other, api);
767 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
768 CHECK_DIFF(diff, eApiChanged, other, api);
769 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
770 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
771 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000772 CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000773 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
774 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
775 CHECK_DIFF3(diff, eRenderBorderChanged, other, borderEnabled, borderWidth, borderColor);
776 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
777 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
778 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
779 changeFrameRateStrategy);
Rachel Leece6e0042023-06-27 11:22:54 -0700780 CHECK_DIFF(diff, eFrameRateCategoryChanged, other, frameRateCategory);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000781 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
782 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
783 CHECK_DIFF(diff, eTrustedOverlayChanged, other, isTrustedOverlay);
784 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
785 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
786 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
787 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
788 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
789 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
790 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
791 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
792 return diff;
793}
794
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700795bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500796 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700797}
798
Ady Abraham6e8e3642021-07-08 19:44:07 -0700799bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700800 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700801}
802
chaviw308ddba2020-08-11 16:23:51 -0700803status_t layer_state_t::matrix22_t::write(Parcel& output) const {
804 SAFE_PARCEL(output.writeFloat, dsdx);
805 SAFE_PARCEL(output.writeFloat, dtdx);
806 SAFE_PARCEL(output.writeFloat, dtdy);
807 SAFE_PARCEL(output.writeFloat, dsdy);
808 return NO_ERROR;
809}
810
811status_t layer_state_t::matrix22_t::read(const Parcel& input) {
812 SAFE_PARCEL(input.readFloat, &dsdx);
813 SAFE_PARCEL(input.readFloat, &dtdx);
814 SAFE_PARCEL(input.readFloat, &dtdy);
815 SAFE_PARCEL(input.readFloat, &dsdy);
816 return NO_ERROR;
817}
818
chaviw273171b2018-12-26 11:46:30 -0800819// ------------------------------- InputWindowCommands ----------------------------------------
820
Vishnu Naire798b472020-07-23 13:52:21 -0700821bool InputWindowCommands::merge(const InputWindowCommands& other) {
822 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700823 changes |= !other.focusRequests.empty();
824 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
825 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000826 changes |= !other.windowInfosReportedListeners.empty();
827 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
828 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700829 return changes;
chaviw273171b2018-12-26 11:46:30 -0800830}
831
Vishnu Nair958da932020-08-21 17:12:37 -0700832bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000833 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700834}
835
chaviw273171b2018-12-26 11:46:30 -0800836void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700837 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000838 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800839}
840
chaviw308ddba2020-08-11 16:23:51 -0700841status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700842 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000843
844 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
845 for (const auto& listener : windowInfosReportedListeners) {
846 SAFE_PARCEL(output.writeStrongBinder, listener);
847 }
848
chaviw308ddba2020-08-11 16:23:51 -0700849 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800850}
851
chaviw308ddba2020-08-11 16:23:51 -0700852status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700853 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000854
855 int listenerSize = 0;
856 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
857 windowInfosReportedListeners.reserve(listenerSize);
858 for (int i = 0; i < listenerSize; i++) {
859 sp<gui::IWindowInfosReportedListener> listener;
860 SAFE_PARCEL(input.readStrongBinder, &listener);
861 windowInfosReportedListeners.insert(listener);
862 }
863
chaviw308ddba2020-08-11 16:23:51 -0700864 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800865}
866
chaviw618c42d2020-07-24 15:25:08 -0700867// ----------------------------------------------------------------------------
868
Huihong Luo9e84f332021-12-16 14:33:46 -0800869namespace gui {
870
871status_t CaptureArgs::writeToParcel(Parcel* output) const {
872 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
873 SAFE_PARCEL(output->write, sourceCrop);
874 SAFE_PARCEL(output->writeFloat, frameScaleX);
875 SAFE_PARCEL(output->writeFloat, frameScaleY);
876 SAFE_PARCEL(output->writeBool, captureSecureLayers);
877 SAFE_PARCEL(output->writeInt32, uid);
878 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
879 SAFE_PARCEL(output->writeBool, allowProtected);
880 SAFE_PARCEL(output->writeBool, grayscale);
Ajinkya Chalke02844632023-03-01 12:10:14 +0000881 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
882 for (auto& excludeHandle : excludeHandles) {
883 SAFE_PARCEL(output->writeStrongBinder, excludeHandle);
884 }
Alec Mouri3e5965f2023-04-07 18:00:58 +0000885 SAFE_PARCEL(output->writeBool, hintForSeamlessTransition);
chaviw308ddba2020-08-11 16:23:51 -0700886 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700887}
888
Huihong Luo9e84f332021-12-16 14:33:46 -0800889status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700890 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800891 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700892 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800893 SAFE_PARCEL(input->read, sourceCrop);
894 SAFE_PARCEL(input->readFloat, &frameScaleX);
895 SAFE_PARCEL(input->readFloat, &frameScaleY);
896 SAFE_PARCEL(input->readBool, &captureSecureLayers);
897 SAFE_PARCEL(input->readInt32, &uid);
898 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700899 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800900 SAFE_PARCEL(input->readBool, &allowProtected);
901 SAFE_PARCEL(input->readBool, &grayscale);
Ajinkya Chalke02844632023-03-01 12:10:14 +0000902 int32_t numExcludeHandles = 0;
903 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
904 excludeHandles.reserve(numExcludeHandles);
905 for (int i = 0; i < numExcludeHandles; i++) {
906 sp<IBinder> binder;
907 SAFE_PARCEL(input->readStrongBinder, &binder);
908 excludeHandles.emplace(binder);
909 }
Alec Mouri3e5965f2023-04-07 18:00:58 +0000910 SAFE_PARCEL(input->readBool, &hintForSeamlessTransition);
chaviw308ddba2020-08-11 16:23:51 -0700911 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700912}
913
Huihong Luo9e84f332021-12-16 14:33:46 -0800914status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
915 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700916
Huihong Luo9e84f332021-12-16 14:33:46 -0800917 SAFE_PARCEL(output->writeStrongBinder, displayToken);
918 SAFE_PARCEL(output->writeUint32, width);
919 SAFE_PARCEL(output->writeUint32, height);
920 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700921 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700922}
923
Huihong Luo9e84f332021-12-16 14:33:46 -0800924status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
925 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700926
Huihong Luo9e84f332021-12-16 14:33:46 -0800927 SAFE_PARCEL(input->readStrongBinder, &displayToken);
928 SAFE_PARCEL(input->readUint32, &width);
929 SAFE_PARCEL(input->readUint32, &height);
930 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700931 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700932}
933
Huihong Luo9e84f332021-12-16 14:33:46 -0800934status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
935 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700936
Huihong Luo9e84f332021-12-16 14:33:46 -0800937 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
Huihong Luo9e84f332021-12-16 14:33:46 -0800938 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700939 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700940}
941
Huihong Luo9e84f332021-12-16 14:33:46 -0800942status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
943 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700944
Huihong Luo9e84f332021-12-16 14:33:46 -0800945 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700946
Huihong Luo9e84f332021-12-16 14:33:46 -0800947 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700948 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700949}
950
Huihong Luo9e84f332021-12-16 14:33:46 -0800951}; // namespace gui
952
chaviw8dd181f2022-01-05 18:36:46 -0600953ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500954 uint64_t bufferId;
955 if (buffer) {
956 bufferId = buffer->getId();
957 } else {
958 bufferId = cachedBuffer.id;
959 }
960 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600961}
962
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800963status_t BufferData::writeToParcel(Parcel* output) const {
964 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500965
966 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800967 SAFE_PARCEL(output->writeBool, true);
968 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500969 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800970 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500971 }
972
973 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800974 SAFE_PARCEL(output->writeBool, true);
975 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500976 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800977 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500978 }
979
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800980 SAFE_PARCEL(output->writeUint64, frameNumber);
981 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
982 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500983
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800984 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
985 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800986 SAFE_PARCEL(output->writeBool, hasBarrier);
987 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +0800988 SAFE_PARCEL(output->writeUint32, producerId);
chaviwba4320c2021-09-15 15:20:53 -0500989
990 return NO_ERROR;
991}
992
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800993status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500994 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800995 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700996 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500997
998 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800999 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001000 if (tmpBool) {
1001 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001002 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -05001003 }
1004
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001005 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001006 if (tmpBool) {
1007 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001008 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -05001009 }
1010
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001011 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -05001012
1013 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001014 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001015 if (tmpBinder) {
1016 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1017 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001018 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001019
1020 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001021 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001022 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001023 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -05001024
Robert Carr79dc06a2022-02-22 15:28:59 -08001025 SAFE_PARCEL(input->readBool, &hasBarrier);
1026 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001027 SAFE_PARCEL(input->readUint32, &producerId);
Robert Carr79dc06a2022-02-22 15:28:59 -08001028
chaviwba4320c2021-09-15 15:20:53 -05001029 return NO_ERROR;
1030}
1031
Chavi Weingarten076acac2023-01-19 17:20:43 +00001032status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1033 SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1034 SAFE_PARCEL(parcel->writeInt32, callbackId);
1035 return NO_ERROR;
1036}
1037
1038status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1039 sp<IBinder> tmpBinder = nullptr;
1040 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1041 if (tmpBinder) {
1042 callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1043 }
1044 SAFE_PARCEL(parcel->readInt32, &callbackId);
1045 return NO_ERROR;
1046}
1047
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001048}; // namespace android