blob: cf171dcec94d018f82288b66e26a9aec6327376a [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>
Andy McFadden2adaf042012-12-18 09:49:45 -080025#include <gui/IGraphicBufferProducer.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070026#include <gui/LayerState.h>
Vishnu Nairaa799bd2022-11-16 23:09:09 +000027#include <gui/SurfaceControl.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010028#include <private/gui/ParcelUtils.h>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070029#include <system/window.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000030#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031
Vishnu Nairaa799bd2022-11-16 23:09:09 +000032#define CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD) \
33 { \
34 if ((OTHER.what & CHANGE_FLAG) && (FIELD != OTHER.FIELD)) { \
35 DIFF_RESULT |= CHANGE_FLAG; \
36 } \
37 }
38
39#define CHECK_DIFF2(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2) \
40 { \
41 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1) \
42 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2) \
43 }
44
45#define CHECK_DIFF3(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2, FIELD3) \
46 { \
47 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1) \
48 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2) \
49 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD3) \
50 }
51
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052namespace android {
53
chaviw98318de2021-05-19 16:45:23 -050054using gui::FocusRequest;
55using gui::WindowInfoHandle;
56
Pablo Gamito11dcc222020-09-12 15:49:39 +000057layer_state_t::layer_state_t()
Vishnu Nair685cfef2022-02-02 10:01:25 -080058 : surface(nullptr),
59 layerId(-1),
60 what(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000061 x(0),
62 y(0),
63 z(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000064 flags(0),
65 mask(0),
66 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000067 cornerRadius(0.0f),
68 backgroundBlurRadius(0),
Vishnu Nairbbceb462022-10-10 04:52:13 +000069 color(0),
70 bufferTransform(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000071 transformToDisplayInverse(false),
72 crop(Rect::INVALID_RECT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000073 dataspace(ui::Dataspace::UNKNOWN),
74 surfaceDamageRegion(),
75 api(-1),
76 colorTransform(mat4()),
Vishnu Naird47bcee2023-02-24 18:08:51 +000077 bgColor(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000078 bgColorDataspace(ui::Dataspace::UNKNOWN),
79 colorSpaceAgnostic(false),
80 shadowRadius(0.0f),
81 frameRateSelectionPriority(-1),
82 frameRate(0.0f),
83 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010084 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Andy Labrada096227e2022-06-15 16:58:11 +000085 defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000086 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080087 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070088 isTrustedOverlay(false),
Tianhao Yao67dd7122022-02-22 17:48:33 +000089 borderEnabled(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070090 bufferCrop(Rect::INVALID_RECT),
91 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070092 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000093 matrix.dsdx = matrix.dtdy = 1.0f;
94 matrix.dsdy = matrix.dtdx = 0.0f;
95 hdrMetadata.validTypes = 0;
96}
97
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098status_t layer_state_t::write(Parcel& output) const
99{
chaviw308ddba2020-08-11 16:23:51 -0700100 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000101 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -0700102 SAFE_PARCEL(output.writeUint64, what);
103 SAFE_PARCEL(output.writeFloat, x);
104 SAFE_PARCEL(output.writeFloat, y);
105 SAFE_PARCEL(output.writeInt32, z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700106 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700107 SAFE_PARCEL(output.writeUint32, flags);
108 SAFE_PARCEL(output.writeUint32, mask);
109 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -0800110 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000111 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
112 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -0700113 SAFE_PARCEL(output.writeFloat, color.r);
114 SAFE_PARCEL(output.writeFloat, color.g);
115 SAFE_PARCEL(output.writeFloat, color.b);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000116 SAFE_PARCEL(output.writeFloat, color.a);
chaviw98318de2021-05-19 16:45:23 -0500117 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700118 SAFE_PARCEL(output.write, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000119 SAFE_PARCEL(output.writeUint32, bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700120 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000121 SAFE_PARCEL(output.writeBool, borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000122 SAFE_PARCEL(output.writeFloat, borderWidth);
123 SAFE_PARCEL(output.writeFloat, borderColor.r);
124 SAFE_PARCEL(output.writeFloat, borderColor.g);
125 SAFE_PARCEL(output.writeFloat, borderColor.b);
126 SAFE_PARCEL(output.writeFloat, borderColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700127 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
128 SAFE_PARCEL(output.write, hdrMetadata);
129 SAFE_PARCEL(output.write, surfaceDamageRegion);
130 SAFE_PARCEL(output.writeInt32, api);
131
Marissa Wall61c58622018-07-18 10:12:20 -0700132 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700133 SAFE_PARCEL(output.writeBool, true);
134 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700135 } else {
chaviw308ddba2020-08-11 16:23:51 -0700136 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700137 }
138
chaviw308ddba2020-08-11 16:23:51 -0700139 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
140 SAFE_PARCEL(output.writeFloat, cornerRadius);
141 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700142 SAFE_PARCEL(output.writeParcelable, metadata);
Vishnu Naird47bcee2023-02-24 18:08:51 +0000143 SAFE_PARCEL(output.writeFloat, bgColor.r);
144 SAFE_PARCEL(output.writeFloat, bgColor.g);
145 SAFE_PARCEL(output.writeFloat, bgColor.b);
146 SAFE_PARCEL(output.writeFloat, bgColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700147 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
148 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
149 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700150
151 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700152 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700153 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700154 }
chaviw308ddba2020-08-11 16:23:51 -0700155 SAFE_PARCEL(output.writeFloat, shadowRadius);
156 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
157 SAFE_PARCEL(output.writeFloat, frameRate);
158 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100159 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000160 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
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);
John Reck68796592023-01-25 13:47:12 -0500193 SAFE_PARCEL(output.writeFloat, currentSdrHdrRatio);
194 SAFE_PARCEL(output.writeFloat, desiredSdrHdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000195 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);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000234 SAFE_PARCEL(input.readBool, &borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000235 SAFE_PARCEL(input.readFloat, &tmpFloat);
236 borderWidth = tmpFloat;
237 SAFE_PARCEL(input.readFloat, &tmpFloat);
238 borderColor.r = tmpFloat;
239 SAFE_PARCEL(input.readFloat, &tmpFloat);
240 borderColor.g = tmpFloat;
241 SAFE_PARCEL(input.readFloat, &tmpFloat);
242 borderColor.b = tmpFloat;
243 SAFE_PARCEL(input.readFloat, &tmpFloat);
244 borderColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700245
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800246 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700247 SAFE_PARCEL(input.readUint32, &tmpUint32);
248 dataspace = static_cast<ui::Dataspace>(tmpUint32);
249
250 SAFE_PARCEL(input.read, hdrMetadata);
251 SAFE_PARCEL(input.read, surfaceDamageRegion);
252 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500253
254 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700255 SAFE_PARCEL(input.readBool, &tmpBool);
256 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700257 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
258 }
259
chaviw308ddba2020-08-11 16:23:51 -0700260 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
261 SAFE_PARCEL(input.readFloat, &cornerRadius);
262 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700263 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800264
Vishnu Naird47bcee2023-02-24 18:08:51 +0000265 SAFE_PARCEL(input.readFloat, &tmpFloat);
266 bgColor.r = tmpFloat;
267 SAFE_PARCEL(input.readFloat, &tmpFloat);
268 bgColor.g = tmpFloat;
269 SAFE_PARCEL(input.readFloat, &tmpFloat);
270 bgColor.b = tmpFloat;
271 SAFE_PARCEL(input.readFloat, &tmpFloat);
272 bgColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700273 SAFE_PARCEL(input.readUint32, &tmpUint32);
274 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
275 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800276
chaviw308ddba2020-08-11 16:23:51 -0700277 int32_t numListeners = 0;
278 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700279 listeners.clear();
280 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700281 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700282 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700283 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700284 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700285 listeners.emplace_back(listener, callbackIds);
286 }
chaviw308ddba2020-08-11 16:23:51 -0700287 SAFE_PARCEL(input.readFloat, &shadowRadius);
288 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
289 SAFE_PARCEL(input.readFloat, &frameRate);
290 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100291 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000292 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700293 SAFE_PARCEL(input.readUint32, &tmpUint32);
294 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800295 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700296 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700297
298 uint32_t numRegions = 0;
299 SAFE_PARCEL(input.readUint32, &numRegions);
300 blurRegions.clear();
301 for (uint32_t i = 0; i < numRegions; i++) {
302 BlurRegion region;
303 SAFE_PARCEL(input.readUint32, &region.blurRadius);
304 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
305 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
306 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
307 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
308 SAFE_PARCEL(input.readFloat, &region.alpha);
309 SAFE_PARCEL(input.readInt32, &region.left);
310 SAFE_PARCEL(input.readInt32, &region.top);
311 SAFE_PARCEL(input.readInt32, &region.right);
312 SAFE_PARCEL(input.readInt32, &region.bottom);
313 blurRegions.push_back(region);
314 }
John Reckcdb4ed72021-02-04 13:39:33 -0500315
316 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500317 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700318 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700319 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500320
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700321 uint32_t mode;
322 SAFE_PARCEL(input.readUint32, &mode);
323 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800324
325 bool hasBufferData;
326 SAFE_PARCEL(input.readBool, &hasBufferData);
327 if (hasBufferData) {
328 bufferData = std::make_shared<BufferData>();
329 SAFE_PARCEL(input.readParcelable, bufferData.get());
330 } else {
331 bufferData = nullptr;
332 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000333
334 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
335 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
336
John Reck68796592023-01-25 13:47:12 -0500337 SAFE_PARCEL(input.readFloat, &tmpFloat);
338 currentSdrHdrRatio = tmpFloat;
339 SAFE_PARCEL(input.readFloat, &tmpFloat);
340 desiredSdrHdrRatio = tmpFloat;
341
Alec Mourif4af03e2023-02-11 00:25:24 +0000342 int32_t tmpInt32;
343 SAFE_PARCEL(input.readInt32, &tmpInt32);
344 cachingHint = static_cast<gui::CachingHint>(tmpInt32);
345
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800346 return NO_ERROR;
347}
348
Mathias Agopian698c0872011-06-28 19:09:31 -0700349status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700350 return state.write(output);
351}
352
353status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700354 return state.read(input);
355}
356
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700357DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700358
Mathias Agopian8b33f032012-07-24 20:43:54 -0700359status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700360 SAFE_PARCEL(output.writeStrongBinder, token);
361 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
362 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700363 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700364 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700365 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
366 SAFE_PARCEL(output.write, layerStackSpaceRect);
367 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
368 SAFE_PARCEL(output.writeUint32, width);
369 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700370 return NO_ERROR;
371}
372
373status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700374 SAFE_PARCEL(input.readStrongBinder, &token);
375 sp<IBinder> tmpBinder;
376 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
377 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
378
379 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700380 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700381 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700382 uint32_t tmpUint = 0;
383 SAFE_PARCEL(input.readUint32, &tmpUint);
384 orientation = ui::toRotation(tmpUint);
385
386 SAFE_PARCEL(input.read, layerStackSpaceRect);
387 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
388 SAFE_PARCEL(input.readUint32, &width);
389 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700390 return NO_ERROR;
391}
392
Robert Carr2c5f6d22017-09-26 12:30:35 -0700393void DisplayState::merge(const DisplayState& other) {
394 if (other.what & eSurfaceChanged) {
395 what |= eSurfaceChanged;
396 surface = other.surface;
397 }
398 if (other.what & eLayerStackChanged) {
399 what |= eLayerStackChanged;
400 layerStack = other.layerStack;
401 }
Evan Rosky2239b372021-05-20 13:43:47 -0700402 if (other.what & eFlagsChanged) {
403 what |= eFlagsChanged;
404 flags = other.flags;
405 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700406 if (other.what & eDisplayProjectionChanged) {
407 what |= eDisplayProjectionChanged;
408 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200409 layerStackSpaceRect = other.layerStackSpaceRect;
410 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700411 }
412 if (other.what & eDisplaySizeChanged) {
413 what |= eDisplaySizeChanged;
414 width = other.width;
415 height = other.height;
416 }
417}
418
Sally Qi6bb12822022-10-05 11:42:30 -0700419void DisplayState::sanitize(int32_t permissions) {
420 if (what & DisplayState::eLayerStackChanged) {
421 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
422 what &= ~DisplayState::eLayerStackChanged;
423 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
424 }
425 }
426 if (what & DisplayState::eDisplayProjectionChanged) {
427 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
428 what &= ~DisplayState::eDisplayProjectionChanged;
429 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
430 }
431 }
432 if (what & DisplayState::eSurfaceChanged) {
433 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
434 what &= ~DisplayState::eSurfaceChanged;
435 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
436 }
437 }
438}
439
Robert Carrde6d7b42022-01-07 18:23:06 -0800440void layer_state_t::sanitize(int32_t permissions) {
441 // TODO: b/109894387
442 //
443 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
444 // rotation. To see the problem observe that if we have a square parent, and a child
445 // of the same size, then we rotate the child 45 degrees around its center, the child
446 // must now be cropped to a non rectangular 8 sided region.
447 //
448 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
449 // private API, and arbitrary rotation is used in limited use cases, for instance:
450 // - WindowManager only uses rotation in one case, which is on a top level layer in which
451 // cropping is not an issue.
452 // - Launcher, as a privileged app, uses this to transition an application to PiP
453 // (picture-in-picture) mode.
454 //
455 // However given that abuse of rotation matrices could lead to surfaces extending outside
456 // of cropped areas, we need to prevent non-root clients without permission
457 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
458 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
459 // preserving transformations.
460 if (what & eMatrixChanged) {
461 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
462 ui::Transform t;
463 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
464 if (!t.preserveRects()) {
465 what &= ~eMatrixChanged;
466 ALOGE("Stripped non rect preserving matrix in sanitize");
467 }
468 }
469 }
470
471 if (what & eFlagsChanged) {
472 if ((flags & eLayerIsDisplayDecoration) &&
473 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
474 flags &= ~eLayerIsDisplayDecoration;
475 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
476 }
477 }
478
479 if (what & layer_state_t::eInputInfoChanged) {
480 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
481 what &= ~eInputInfoChanged;
482 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
483 }
484 }
485 if (what & layer_state_t::eTrustedOverlayChanged) {
486 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
487 what &= ~eTrustedOverlayChanged;
488 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
489 }
490 }
491 if (what & layer_state_t::eDropInputModeChanged) {
492 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
493 what &= ~eDropInputModeChanged;
494 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
495 }
496 }
497 if (what & layer_state_t::eFrameRateSelectionPriority) {
498 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
499 what &= ~eFrameRateSelectionPriority;
500 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
501 }
502 }
503 if (what & layer_state_t::eFrameRateChanged) {
504 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
505 changeFrameRateStrategy,
506 "layer_state_t::sanitize",
507 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
508 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
509 }
510 }
511}
512
Robert Carr2c5f6d22017-09-26 12:30:35 -0700513void layer_state_t::merge(const layer_state_t& other) {
514 if (other.what & ePositionChanged) {
515 what |= ePositionChanged;
516 x = other.x;
517 y = other.y;
518 }
519 if (other.what & eLayerChanged) {
520 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700521 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700522 z = other.z;
523 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700524 if (other.what & eAlphaChanged) {
525 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000526 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700527 }
528 if (other.what & eMatrixChanged) {
529 what |= eMatrixChanged;
530 matrix = other.matrix;
531 }
532 if (other.what & eTransparentRegionChanged) {
533 what |= eTransparentRegionChanged;
534 transparentRegion = other.transparentRegion;
535 }
536 if (other.what & eFlagsChanged) {
537 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700538 flags &= ~other.mask;
539 flags |= (other.flags & other.mask);
540 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700541 }
542 if (other.what & eLayerStackChanged) {
543 what |= eLayerStackChanged;
544 layerStack = other.layerStack;
545 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700546 if (other.what & eCornerRadiusChanged) {
547 what |= eCornerRadiusChanged;
548 cornerRadius = other.cornerRadius;
549 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800550 if (other.what & eBackgroundBlurRadiusChanged) {
551 what |= eBackgroundBlurRadiusChanged;
552 backgroundBlurRadius = other.backgroundBlurRadius;
553 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700554 if (other.what & eBlurRegionsChanged) {
555 what |= eBlurRegionsChanged;
556 blurRegions = other.blurRegions;
557 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700558 if (other.what & eRelativeLayerChanged) {
559 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700560 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700561 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000562 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700563 }
564 if (other.what & eReparent) {
565 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000566 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700567 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000568 if (other.what & eBufferTransformChanged) {
569 what |= eBufferTransformChanged;
570 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700571 }
572 if (other.what & eTransformToDisplayInverseChanged) {
573 what |= eTransformToDisplayInverseChanged;
574 transformToDisplayInverse = other.transformToDisplayInverse;
575 }
576 if (other.what & eCropChanged) {
577 what |= eCropChanged;
578 crop = other.crop;
579 }
580 if (other.what & eBufferChanged) {
581 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500582 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700583 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000584 if (other.what & eTrustedPresentationInfoChanged) {
585 what |= eTrustedPresentationInfoChanged;
586 trustedPresentationListener = other.trustedPresentationListener;
587 trustedPresentationThresholds = other.trustedPresentationThresholds;
588 }
Marissa Wall61c58622018-07-18 10:12:20 -0700589 if (other.what & eDataspaceChanged) {
590 what |= eDataspaceChanged;
591 dataspace = other.dataspace;
592 }
John Reck68796592023-01-25 13:47:12 -0500593 if (other.what & eExtendedRangeBrightnessChanged) {
594 what |= eExtendedRangeBrightnessChanged;
595 desiredSdrHdrRatio = other.desiredSdrHdrRatio;
596 currentSdrHdrRatio = other.currentSdrHdrRatio;
597 }
Alec Mourif4af03e2023-02-11 00:25:24 +0000598 if (other.what & eCachingHintChanged) {
599 what |= eCachingHintChanged;
600 cachingHint = other.cachingHint;
601 }
Marissa Wall61c58622018-07-18 10:12:20 -0700602 if (other.what & eHdrMetadataChanged) {
603 what |= eHdrMetadataChanged;
604 hdrMetadata = other.hdrMetadata;
605 }
606 if (other.what & eSurfaceDamageRegionChanged) {
607 what |= eSurfaceDamageRegionChanged;
608 surfaceDamageRegion = other.surfaceDamageRegion;
609 }
610 if (other.what & eApiChanged) {
611 what |= eApiChanged;
612 api = other.api;
613 }
614 if (other.what & eSidebandStreamChanged) {
615 what |= eSidebandStreamChanged;
616 sidebandStream = other.sidebandStream;
617 }
Peiyong Lind3788632018-09-18 16:01:31 -0700618 if (other.what & eColorTransformChanged) {
619 what |= eColorTransformChanged;
620 colorTransform = other.colorTransform;
621 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700622 if (other.what & eHasListenerCallbacksChanged) {
623 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700624 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700625 if (other.what & eInputInfoChanged) {
626 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500627 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700628 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800629 if (other.what & eBackgroundColorChanged) {
630 what |= eBackgroundColorChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000631 bgColor = other.bgColor;
Valerie Haudd0b7572019-01-29 14:59:27 -0800632 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800633 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800634 if (other.what & eMetadataChanged) {
635 what |= eMetadataChanged;
636 metadata.merge(other.metadata);
637 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700638 if (other.what & eShadowRadiusChanged) {
639 what |= eShadowRadiusChanged;
640 shadowRadius = other.shadowRadius;
641 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000642 if (other.what & eRenderBorderChanged) {
643 what |= eRenderBorderChanged;
644 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000645 borderWidth = other.borderWidth;
646 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000647 }
Andy Labrada096227e2022-06-15 16:58:11 +0000648 if (other.what & eDefaultFrameRateCompatibilityChanged) {
649 what |= eDefaultFrameRateCompatibilityChanged;
650 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
651 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100652 if (other.what & eFrameRateSelectionPriority) {
653 what |= eFrameRateSelectionPriority;
654 frameRateSelectionPriority = other.frameRateSelectionPriority;
655 }
Steven Thomas3172e202020-01-06 19:25:30 -0800656 if (other.what & eFrameRateChanged) {
657 what |= eFrameRateChanged;
658 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800659 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100660 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800661 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700662 if (other.what & eFixedTransformHintChanged) {
663 what |= eFixedTransformHintChanged;
664 fixedTransformHint = other.fixedTransformHint;
665 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800666 if (other.what & eAutoRefreshChanged) {
667 what |= eAutoRefreshChanged;
668 autoRefresh = other.autoRefresh;
669 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700670 if (other.what & eTrustedOverlayChanged) {
671 what |= eTrustedOverlayChanged;
672 isTrustedOverlay = other.isTrustedOverlay;
673 }
John Reckc00c6692021-02-16 11:37:33 -0500674 if (other.what & eStretchChanged) {
675 what |= eStretchChanged;
676 stretchEffect = other.stretchEffect;
677 }
chaviwf3f40fe2021-04-27 15:54:02 -0500678 if (other.what & eBufferCropChanged) {
679 what |= eBufferCropChanged;
680 bufferCrop = other.bufferCrop;
681 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700682 if (other.what & eDestinationFrameChanged) {
683 what |= eDestinationFrameChanged;
684 destinationFrame = other.destinationFrame;
685 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700686 if (other.what & eProducerDisconnect) {
687 what |= eProducerDisconnect;
688 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700689 if (other.what & eDropInputModeChanged) {
690 what |= eDropInputModeChanged;
691 dropInputMode = other.dropInputMode;
692 }
chaviw4c36cd82021-11-18 10:37:33 -0600693 if (other.what & eColorChanged) {
694 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000695 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600696 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800697 if (other.what & eColorSpaceAgnosticChanged) {
698 what |= eColorSpaceAgnosticChanged;
699 colorSpaceAgnostic = other.colorSpaceAgnostic;
700 }
Sally Qi81d95e62022-03-21 19:41:33 -0700701 if (other.what & eDimmingEnabledChanged) {
702 what |= eDimmingEnabledChanged;
703 dimmingEnabled = other.dimmingEnabled;
704 }
Pascal Muetschardb39918f2023-01-27 11:36:11 +0100705 if (other.what & eFlushJankData) {
706 what |= eFlushJankData;
707 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700708 if ((other.what & what) != other.what) {
709 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700710 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
711 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700712 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700713}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700714
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000715uint64_t layer_state_t::diff(const layer_state_t& other) const {
716 uint64_t diff = 0;
717 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
718 if (other.what & eLayerChanged) {
719 diff |= eLayerChanged;
720 diff &= ~eRelativeLayerChanged;
721 }
722 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
723 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
724 if (other.what & eTransparentRegionChanged &&
725 (!transparentRegion.hasSameRects(other.transparentRegion))) {
726 diff |= eTransparentRegionChanged;
727 }
728 if (other.what & eFlagsChanged) {
729 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
730 if (changedFlags) diff |= eFlagsChanged;
731 }
732 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
733 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
734 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
735 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
736 if (other.what & eRelativeLayerChanged) {
737 diff |= eRelativeLayerChanged;
738 diff &= ~eLayerChanged;
739 }
740 if (other.what & eReparent &&
741 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
742 other.parentSurfaceControlForChild)) {
743 diff |= eReparent;
744 }
745 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
746 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
747 CHECK_DIFF(diff, eCropChanged, other, crop);
748 if (other.what & eBufferChanged) diff |= eBufferChanged;
749 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
John Reck68796592023-01-25 13:47:12 -0500750 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentSdrHdrRatio,
751 desiredSdrHdrRatio);
Alec Mourif4af03e2023-02-11 00:25:24 +0000752 CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000753 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
754 if (other.what & eSurfaceDamageRegionChanged &&
755 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
756 diff |= eSurfaceDamageRegionChanged;
757 }
758 CHECK_DIFF(diff, eApiChanged, other, api);
759 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
760 CHECK_DIFF(diff, eApiChanged, other, api);
761 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
762 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
763 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000764 CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000765 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
766 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
767 CHECK_DIFF3(diff, eRenderBorderChanged, other, borderEnabled, borderWidth, borderColor);
768 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
769 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
770 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
771 changeFrameRateStrategy);
772 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
773 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
774 CHECK_DIFF(diff, eTrustedOverlayChanged, other, isTrustedOverlay);
775 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
776 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
777 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
778 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
779 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
780 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
781 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
782 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
783 return diff;
784}
785
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700786bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500787 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700788}
789
Ady Abraham6e8e3642021-07-08 19:44:07 -0700790bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700791 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700792}
793
chaviw308ddba2020-08-11 16:23:51 -0700794status_t layer_state_t::matrix22_t::write(Parcel& output) const {
795 SAFE_PARCEL(output.writeFloat, dsdx);
796 SAFE_PARCEL(output.writeFloat, dtdx);
797 SAFE_PARCEL(output.writeFloat, dtdy);
798 SAFE_PARCEL(output.writeFloat, dsdy);
799 return NO_ERROR;
800}
801
802status_t layer_state_t::matrix22_t::read(const Parcel& input) {
803 SAFE_PARCEL(input.readFloat, &dsdx);
804 SAFE_PARCEL(input.readFloat, &dtdx);
805 SAFE_PARCEL(input.readFloat, &dtdy);
806 SAFE_PARCEL(input.readFloat, &dsdy);
807 return NO_ERROR;
808}
809
chaviw273171b2018-12-26 11:46:30 -0800810// ------------------------------- InputWindowCommands ----------------------------------------
811
Vishnu Naire798b472020-07-23 13:52:21 -0700812bool InputWindowCommands::merge(const InputWindowCommands& other) {
813 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700814 changes |= !other.focusRequests.empty();
815 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
816 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000817 changes |= !other.windowInfosReportedListeners.empty();
818 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
819 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700820 return changes;
chaviw273171b2018-12-26 11:46:30 -0800821}
822
Vishnu Nair958da932020-08-21 17:12:37 -0700823bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000824 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700825}
826
chaviw273171b2018-12-26 11:46:30 -0800827void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700828 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000829 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800830}
831
chaviw308ddba2020-08-11 16:23:51 -0700832status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700833 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000834
835 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
836 for (const auto& listener : windowInfosReportedListeners) {
837 SAFE_PARCEL(output.writeStrongBinder, listener);
838 }
839
chaviw308ddba2020-08-11 16:23:51 -0700840 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800841}
842
chaviw308ddba2020-08-11 16:23:51 -0700843status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700844 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000845
846 int listenerSize = 0;
847 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
848 windowInfosReportedListeners.reserve(listenerSize);
849 for (int i = 0; i < listenerSize; i++) {
850 sp<gui::IWindowInfosReportedListener> listener;
851 SAFE_PARCEL(input.readStrongBinder, &listener);
852 windowInfosReportedListeners.insert(listener);
853 }
854
chaviw308ddba2020-08-11 16:23:51 -0700855 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800856}
857
Marin Shalamanovc5986772021-03-16 16:09:49 +0100858bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
859 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800860 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
861 int floatClassification = std::fpclassify(frameRate);
862 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
863 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
864 return false;
865 }
866
867 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800868 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700869 (!privileged ||
870 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
871 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800872 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
873 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800874 return false;
875 }
876
Marin Shalamanovc5986772021-03-16 16:09:49 +0100877 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
878 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
879 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
880 changeFrameRateStrategy);
881 }
882
Steven Thomas62a4cf82020-01-31 12:04:03 -0800883 return true;
884}
885
chaviw618c42d2020-07-24 15:25:08 -0700886// ----------------------------------------------------------------------------
887
Huihong Luo9e84f332021-12-16 14:33:46 -0800888namespace gui {
889
890status_t CaptureArgs::writeToParcel(Parcel* output) const {
891 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
892 SAFE_PARCEL(output->write, sourceCrop);
893 SAFE_PARCEL(output->writeFloat, frameScaleX);
894 SAFE_PARCEL(output->writeFloat, frameScaleY);
895 SAFE_PARCEL(output->writeBool, captureSecureLayers);
896 SAFE_PARCEL(output->writeInt32, uid);
897 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
898 SAFE_PARCEL(output->writeBool, allowProtected);
899 SAFE_PARCEL(output->writeBool, grayscale);
Ajinkya Chalke02844632023-03-01 12:10:14 +0000900
901 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
902 for (auto& excludeHandle : excludeHandles) {
903 SAFE_PARCEL(output->writeStrongBinder, excludeHandle);
904 }
chaviw308ddba2020-08-11 16:23:51 -0700905 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700906}
907
Huihong Luo9e84f332021-12-16 14:33:46 -0800908status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700909 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800910 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700911 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800912 SAFE_PARCEL(input->read, sourceCrop);
913 SAFE_PARCEL(input->readFloat, &frameScaleX);
914 SAFE_PARCEL(input->readFloat, &frameScaleY);
915 SAFE_PARCEL(input->readBool, &captureSecureLayers);
916 SAFE_PARCEL(input->readInt32, &uid);
917 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700918 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800919 SAFE_PARCEL(input->readBool, &allowProtected);
920 SAFE_PARCEL(input->readBool, &grayscale);
Ajinkya Chalke02844632023-03-01 12:10:14 +0000921
922 int32_t numExcludeHandles = 0;
923 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
924 excludeHandles.reserve(numExcludeHandles);
925 for (int i = 0; i < numExcludeHandles; i++) {
926 sp<IBinder> binder;
927 SAFE_PARCEL(input->readStrongBinder, &binder);
928 excludeHandles.emplace(binder);
929 }
chaviw308ddba2020-08-11 16:23:51 -0700930 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700931}
932
Huihong Luo9e84f332021-12-16 14:33:46 -0800933status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
934 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700935
Huihong Luo9e84f332021-12-16 14:33:46 -0800936 SAFE_PARCEL(output->writeStrongBinder, displayToken);
937 SAFE_PARCEL(output->writeUint32, width);
938 SAFE_PARCEL(output->writeUint32, height);
939 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700940 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700941}
942
Huihong Luo9e84f332021-12-16 14:33:46 -0800943status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
944 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700945
Huihong Luo9e84f332021-12-16 14:33:46 -0800946 SAFE_PARCEL(input->readStrongBinder, &displayToken);
947 SAFE_PARCEL(input->readUint32, &width);
948 SAFE_PARCEL(input->readUint32, &height);
949 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700950 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700951}
952
Huihong Luo9e84f332021-12-16 14:33:46 -0800953status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
954 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700955
Huihong Luo9e84f332021-12-16 14:33:46 -0800956 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
Huihong Luo9e84f332021-12-16 14:33:46 -0800957 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700958 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700959}
960
Huihong Luo9e84f332021-12-16 14:33:46 -0800961status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
962 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700963
Huihong Luo9e84f332021-12-16 14:33:46 -0800964 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700965
Huihong Luo9e84f332021-12-16 14:33:46 -0800966 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700967 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700968}
969
Huihong Luo9e84f332021-12-16 14:33:46 -0800970}; // namespace gui
971
chaviw8dd181f2022-01-05 18:36:46 -0600972ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500973 uint64_t bufferId;
974 if (buffer) {
975 bufferId = buffer->getId();
976 } else {
977 bufferId = cachedBuffer.id;
978 }
979 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600980}
981
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800982status_t BufferData::writeToParcel(Parcel* output) const {
983 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500984
985 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800986 SAFE_PARCEL(output->writeBool, true);
987 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500988 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800989 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500990 }
991
992 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800993 SAFE_PARCEL(output->writeBool, true);
994 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500995 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800996 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500997 }
998
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800999 SAFE_PARCEL(output->writeUint64, frameNumber);
1000 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
1001 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001002
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001003 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
1004 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -08001005 SAFE_PARCEL(output->writeBool, hasBarrier);
1006 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001007 SAFE_PARCEL(output->writeUint32, producerId);
chaviwba4320c2021-09-15 15:20:53 -05001008
1009 return NO_ERROR;
1010}
1011
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001012status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -05001013 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001014 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -07001015 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -05001016
1017 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001018 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001019 if (tmpBool) {
1020 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001021 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -05001022 }
1023
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001024 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001025 if (tmpBool) {
1026 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001027 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -05001028 }
1029
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001030 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -05001031
1032 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001033 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001034 if (tmpBinder) {
1035 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1036 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001037 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001038
1039 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001040 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001041 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001042 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -05001043
Robert Carr79dc06a2022-02-22 15:28:59 -08001044 SAFE_PARCEL(input->readBool, &hasBarrier);
1045 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
liulijuneb489f62022-10-17 22:02:14 +08001046 SAFE_PARCEL(input->readUint32, &producerId);
Robert Carr79dc06a2022-02-22 15:28:59 -08001047
chaviwba4320c2021-09-15 15:20:53 -05001048 return NO_ERROR;
1049}
1050
Chavi Weingarten076acac2023-01-19 17:20:43 +00001051status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1052 SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1053 SAFE_PARCEL(parcel->writeInt32, callbackId);
1054 return NO_ERROR;
1055}
1056
1057status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1058 sp<IBinder> tmpBinder = nullptr;
1059 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1060 if (tmpBinder) {
1061 callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1062 }
1063 SAFE_PARCEL(parcel->readInt32, &callbackId);
1064 return NO_ERROR;
1065}
1066
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001067}; // namespace android