blob: 7772a65dae03106204caba6696186e1bc7e5bb32 [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()),
77 bgColorAlpha(0),
78 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);
143 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
144 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
145 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
146 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700147
148 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700149 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700150 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700151 }
chaviw308ddba2020-08-11 16:23:51 -0700152 SAFE_PARCEL(output.writeFloat, shadowRadius);
153 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
154 SAFE_PARCEL(output.writeFloat, frameRate);
155 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100156 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000157 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700158 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800159 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700160 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700161
162 SAFE_PARCEL(output.writeUint32, blurRegions.size());
163 for (auto region : blurRegions) {
164 SAFE_PARCEL(output.writeUint32, region.blurRadius);
165 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
166 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
167 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
168 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
169 SAFE_PARCEL(output.writeFloat, region.alpha);
170 SAFE_PARCEL(output.writeInt32, region.left);
171 SAFE_PARCEL(output.writeInt32, region.top);
172 SAFE_PARCEL(output.writeInt32, region.right);
173 SAFE_PARCEL(output.writeInt32, region.bottom);
174 }
John Reckcdb4ed72021-02-04 13:39:33 -0500175
176 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500177 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700178 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700179 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500180
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700181 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800182
183 const bool hasBufferData = (bufferData != nullptr);
184 SAFE_PARCEL(output.writeBool, hasBufferData);
185 if (hasBufferData) {
186 SAFE_PARCEL(output.writeParcelable, *bufferData);
187 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000188 SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds);
189 SAFE_PARCEL(output.writeParcelable, trustedPresentationListener);
John Reck68796592023-01-25 13:47:12 -0500190 SAFE_PARCEL(output.writeFloat, currentSdrHdrRatio);
191 SAFE_PARCEL(output.writeFloat, desiredSdrHdrRatio);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800192 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800193}
194
195status_t layer_state_t::read(const Parcel& input)
196{
chaviw308ddba2020-08-11 16:23:51 -0700197 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000198 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700199 SAFE_PARCEL(input.readUint64, &what);
200 SAFE_PARCEL(input.readFloat, &x);
201 SAFE_PARCEL(input.readFloat, &y);
202 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700203 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700204
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800205 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700206
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800207 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700208
209 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800210 SAFE_PARCEL(input.read, crop);
chaviw308ddba2020-08-11 16:23:51 -0700211
Pablo Gamito11dcc222020-09-12 15:49:39 +0000212 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
213 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
214
chaviw308ddba2020-08-11 16:23:51 -0700215 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700216 SAFE_PARCEL(input.readFloat, &tmpFloat);
217 color.r = tmpFloat;
218 SAFE_PARCEL(input.readFloat, &tmpFloat);
219 color.g = tmpFloat;
220 SAFE_PARCEL(input.readFloat, &tmpFloat);
221 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000222 SAFE_PARCEL(input.readFloat, &tmpFloat);
223 color.a = tmpFloat;
224
chaviw98318de2021-05-19 16:45:23 -0500225 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700226
chaviw308ddba2020-08-11 16:23:51 -0700227 SAFE_PARCEL(input.read, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000228 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700229 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000230 SAFE_PARCEL(input.readBool, &borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000231 SAFE_PARCEL(input.readFloat, &tmpFloat);
232 borderWidth = tmpFloat;
233 SAFE_PARCEL(input.readFloat, &tmpFloat);
234 borderColor.r = tmpFloat;
235 SAFE_PARCEL(input.readFloat, &tmpFloat);
236 borderColor.g = tmpFloat;
237 SAFE_PARCEL(input.readFloat, &tmpFloat);
238 borderColor.b = tmpFloat;
239 SAFE_PARCEL(input.readFloat, &tmpFloat);
240 borderColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700241
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800242 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700243 SAFE_PARCEL(input.readUint32, &tmpUint32);
244 dataspace = static_cast<ui::Dataspace>(tmpUint32);
245
246 SAFE_PARCEL(input.read, hdrMetadata);
247 SAFE_PARCEL(input.read, surfaceDamageRegion);
248 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500249
250 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700251 SAFE_PARCEL(input.readBool, &tmpBool);
252 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700253 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
254 }
255
chaviw308ddba2020-08-11 16:23:51 -0700256 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
257 SAFE_PARCEL(input.readFloat, &cornerRadius);
258 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700259 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800260
chaviw308ddba2020-08-11 16:23:51 -0700261 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
262 SAFE_PARCEL(input.readUint32, &tmpUint32);
263 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
264 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800265
chaviw308ddba2020-08-11 16:23:51 -0700266 int32_t numListeners = 0;
267 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700268 listeners.clear();
269 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700270 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700271 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700272 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700273 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700274 listeners.emplace_back(listener, callbackIds);
275 }
chaviw308ddba2020-08-11 16:23:51 -0700276 SAFE_PARCEL(input.readFloat, &shadowRadius);
277 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
278 SAFE_PARCEL(input.readFloat, &frameRate);
279 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100280 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000281 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700282 SAFE_PARCEL(input.readUint32, &tmpUint32);
283 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800284 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700285 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700286
287 uint32_t numRegions = 0;
288 SAFE_PARCEL(input.readUint32, &numRegions);
289 blurRegions.clear();
290 for (uint32_t i = 0; i < numRegions; i++) {
291 BlurRegion region;
292 SAFE_PARCEL(input.readUint32, &region.blurRadius);
293 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
294 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
295 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
296 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
297 SAFE_PARCEL(input.readFloat, &region.alpha);
298 SAFE_PARCEL(input.readInt32, &region.left);
299 SAFE_PARCEL(input.readInt32, &region.top);
300 SAFE_PARCEL(input.readInt32, &region.right);
301 SAFE_PARCEL(input.readInt32, &region.bottom);
302 blurRegions.push_back(region);
303 }
John Reckcdb4ed72021-02-04 13:39:33 -0500304
305 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500306 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700307 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700308 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500309
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700310 uint32_t mode;
311 SAFE_PARCEL(input.readUint32, &mode);
312 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800313
314 bool hasBufferData;
315 SAFE_PARCEL(input.readBool, &hasBufferData);
316 if (hasBufferData) {
317 bufferData = std::make_shared<BufferData>();
318 SAFE_PARCEL(input.readParcelable, bufferData.get());
319 } else {
320 bufferData = nullptr;
321 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000322
323 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
324 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
325
John Reck68796592023-01-25 13:47:12 -0500326 SAFE_PARCEL(input.readFloat, &tmpFloat);
327 currentSdrHdrRatio = tmpFloat;
328 SAFE_PARCEL(input.readFloat, &tmpFloat);
329 desiredSdrHdrRatio = tmpFloat;
330
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800331 return NO_ERROR;
332}
333
Mathias Agopian698c0872011-06-28 19:09:31 -0700334status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700335 return state.write(output);
336}
337
338status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700339 return state.read(input);
340}
341
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700342DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700343
Mathias Agopian8b33f032012-07-24 20:43:54 -0700344status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700345 SAFE_PARCEL(output.writeStrongBinder, token);
346 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
347 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700348 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700349 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700350 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
351 SAFE_PARCEL(output.write, layerStackSpaceRect);
352 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
353 SAFE_PARCEL(output.writeUint32, width);
354 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700355 return NO_ERROR;
356}
357
358status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700359 SAFE_PARCEL(input.readStrongBinder, &token);
360 sp<IBinder> tmpBinder;
361 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
362 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
363
364 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700365 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700366 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700367 uint32_t tmpUint = 0;
368 SAFE_PARCEL(input.readUint32, &tmpUint);
369 orientation = ui::toRotation(tmpUint);
370
371 SAFE_PARCEL(input.read, layerStackSpaceRect);
372 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
373 SAFE_PARCEL(input.readUint32, &width);
374 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700375 return NO_ERROR;
376}
377
Robert Carr2c5f6d22017-09-26 12:30:35 -0700378void DisplayState::merge(const DisplayState& other) {
379 if (other.what & eSurfaceChanged) {
380 what |= eSurfaceChanged;
381 surface = other.surface;
382 }
383 if (other.what & eLayerStackChanged) {
384 what |= eLayerStackChanged;
385 layerStack = other.layerStack;
386 }
Evan Rosky2239b372021-05-20 13:43:47 -0700387 if (other.what & eFlagsChanged) {
388 what |= eFlagsChanged;
389 flags = other.flags;
390 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700391 if (other.what & eDisplayProjectionChanged) {
392 what |= eDisplayProjectionChanged;
393 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200394 layerStackSpaceRect = other.layerStackSpaceRect;
395 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700396 }
397 if (other.what & eDisplaySizeChanged) {
398 what |= eDisplaySizeChanged;
399 width = other.width;
400 height = other.height;
401 }
402}
403
Sally Qi6bb12822022-10-05 11:42:30 -0700404void DisplayState::sanitize(int32_t permissions) {
405 if (what & DisplayState::eLayerStackChanged) {
406 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
407 what &= ~DisplayState::eLayerStackChanged;
408 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
409 }
410 }
411 if (what & DisplayState::eDisplayProjectionChanged) {
412 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
413 what &= ~DisplayState::eDisplayProjectionChanged;
414 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
415 }
416 }
417 if (what & DisplayState::eSurfaceChanged) {
418 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
419 what &= ~DisplayState::eSurfaceChanged;
420 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
421 }
422 }
423}
424
Robert Carrde6d7b42022-01-07 18:23:06 -0800425void layer_state_t::sanitize(int32_t permissions) {
426 // TODO: b/109894387
427 //
428 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
429 // rotation. To see the problem observe that if we have a square parent, and a child
430 // of the same size, then we rotate the child 45 degrees around its center, the child
431 // must now be cropped to a non rectangular 8 sided region.
432 //
433 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
434 // private API, and arbitrary rotation is used in limited use cases, for instance:
435 // - WindowManager only uses rotation in one case, which is on a top level layer in which
436 // cropping is not an issue.
437 // - Launcher, as a privileged app, uses this to transition an application to PiP
438 // (picture-in-picture) mode.
439 //
440 // However given that abuse of rotation matrices could lead to surfaces extending outside
441 // of cropped areas, we need to prevent non-root clients without permission
442 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
443 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
444 // preserving transformations.
445 if (what & eMatrixChanged) {
446 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
447 ui::Transform t;
448 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
449 if (!t.preserveRects()) {
450 what &= ~eMatrixChanged;
451 ALOGE("Stripped non rect preserving matrix in sanitize");
452 }
453 }
454 }
455
456 if (what & eFlagsChanged) {
457 if ((flags & eLayerIsDisplayDecoration) &&
458 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
459 flags &= ~eLayerIsDisplayDecoration;
460 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
461 }
462 }
463
464 if (what & layer_state_t::eInputInfoChanged) {
465 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
466 what &= ~eInputInfoChanged;
467 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
468 }
469 }
470 if (what & layer_state_t::eTrustedOverlayChanged) {
471 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
472 what &= ~eTrustedOverlayChanged;
473 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
474 }
475 }
476 if (what & layer_state_t::eDropInputModeChanged) {
477 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
478 what &= ~eDropInputModeChanged;
479 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
480 }
481 }
482 if (what & layer_state_t::eFrameRateSelectionPriority) {
483 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
484 what &= ~eFrameRateSelectionPriority;
485 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
486 }
487 }
488 if (what & layer_state_t::eFrameRateChanged) {
489 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
490 changeFrameRateStrategy,
491 "layer_state_t::sanitize",
492 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
493 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
494 }
495 }
496}
497
Robert Carr2c5f6d22017-09-26 12:30:35 -0700498void layer_state_t::merge(const layer_state_t& other) {
499 if (other.what & ePositionChanged) {
500 what |= ePositionChanged;
501 x = other.x;
502 y = other.y;
503 }
504 if (other.what & eLayerChanged) {
505 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700506 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700507 z = other.z;
508 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700509 if (other.what & eAlphaChanged) {
510 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000511 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700512 }
513 if (other.what & eMatrixChanged) {
514 what |= eMatrixChanged;
515 matrix = other.matrix;
516 }
517 if (other.what & eTransparentRegionChanged) {
518 what |= eTransparentRegionChanged;
519 transparentRegion = other.transparentRegion;
520 }
521 if (other.what & eFlagsChanged) {
522 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700523 flags &= ~other.mask;
524 flags |= (other.flags & other.mask);
525 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700526 }
527 if (other.what & eLayerStackChanged) {
528 what |= eLayerStackChanged;
529 layerStack = other.layerStack;
530 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700531 if (other.what & eCornerRadiusChanged) {
532 what |= eCornerRadiusChanged;
533 cornerRadius = other.cornerRadius;
534 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800535 if (other.what & eBackgroundBlurRadiusChanged) {
536 what |= eBackgroundBlurRadiusChanged;
537 backgroundBlurRadius = other.backgroundBlurRadius;
538 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700539 if (other.what & eBlurRegionsChanged) {
540 what |= eBlurRegionsChanged;
541 blurRegions = other.blurRegions;
542 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700543 if (other.what & eRelativeLayerChanged) {
544 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700545 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700546 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000547 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700548 }
549 if (other.what & eReparent) {
550 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000551 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700552 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000553 if (other.what & eBufferTransformChanged) {
554 what |= eBufferTransformChanged;
555 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700556 }
557 if (other.what & eTransformToDisplayInverseChanged) {
558 what |= eTransformToDisplayInverseChanged;
559 transformToDisplayInverse = other.transformToDisplayInverse;
560 }
561 if (other.what & eCropChanged) {
562 what |= eCropChanged;
563 crop = other.crop;
564 }
565 if (other.what & eBufferChanged) {
566 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500567 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700568 }
Chavi Weingarten076acac2023-01-19 17:20:43 +0000569 if (other.what & eTrustedPresentationInfoChanged) {
570 what |= eTrustedPresentationInfoChanged;
571 trustedPresentationListener = other.trustedPresentationListener;
572 trustedPresentationThresholds = other.trustedPresentationThresholds;
573 }
Marissa Wall61c58622018-07-18 10:12:20 -0700574 if (other.what & eDataspaceChanged) {
575 what |= eDataspaceChanged;
576 dataspace = other.dataspace;
577 }
John Reck68796592023-01-25 13:47:12 -0500578 if (other.what & eExtendedRangeBrightnessChanged) {
579 what |= eExtendedRangeBrightnessChanged;
580 desiredSdrHdrRatio = other.desiredSdrHdrRatio;
581 currentSdrHdrRatio = other.currentSdrHdrRatio;
582 }
Marissa Wall61c58622018-07-18 10:12:20 -0700583 if (other.what & eHdrMetadataChanged) {
584 what |= eHdrMetadataChanged;
585 hdrMetadata = other.hdrMetadata;
586 }
587 if (other.what & eSurfaceDamageRegionChanged) {
588 what |= eSurfaceDamageRegionChanged;
589 surfaceDamageRegion = other.surfaceDamageRegion;
590 }
591 if (other.what & eApiChanged) {
592 what |= eApiChanged;
593 api = other.api;
594 }
595 if (other.what & eSidebandStreamChanged) {
596 what |= eSidebandStreamChanged;
597 sidebandStream = other.sidebandStream;
598 }
Peiyong Lind3788632018-09-18 16:01:31 -0700599 if (other.what & eColorTransformChanged) {
600 what |= eColorTransformChanged;
601 colorTransform = other.colorTransform;
602 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700603 if (other.what & eHasListenerCallbacksChanged) {
604 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700605 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700606 if (other.what & eInputInfoChanged) {
607 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500608 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700609 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800610 if (other.what & eBackgroundColorChanged) {
611 what |= eBackgroundColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000612 color.rgb = other.color.rgb;
Valerie Haudd0b7572019-01-29 14:59:27 -0800613 bgColorAlpha = other.bgColorAlpha;
614 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800615 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800616 if (other.what & eMetadataChanged) {
617 what |= eMetadataChanged;
618 metadata.merge(other.metadata);
619 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700620 if (other.what & eShadowRadiusChanged) {
621 what |= eShadowRadiusChanged;
622 shadowRadius = other.shadowRadius;
623 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000624 if (other.what & eRenderBorderChanged) {
625 what |= eRenderBorderChanged;
626 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000627 borderWidth = other.borderWidth;
628 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000629 }
Andy Labrada096227e2022-06-15 16:58:11 +0000630 if (other.what & eDefaultFrameRateCompatibilityChanged) {
631 what |= eDefaultFrameRateCompatibilityChanged;
632 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
633 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100634 if (other.what & eFrameRateSelectionPriority) {
635 what |= eFrameRateSelectionPriority;
636 frameRateSelectionPriority = other.frameRateSelectionPriority;
637 }
Steven Thomas3172e202020-01-06 19:25:30 -0800638 if (other.what & eFrameRateChanged) {
639 what |= eFrameRateChanged;
640 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800641 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100642 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800643 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700644 if (other.what & eFixedTransformHintChanged) {
645 what |= eFixedTransformHintChanged;
646 fixedTransformHint = other.fixedTransformHint;
647 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800648 if (other.what & eAutoRefreshChanged) {
649 what |= eAutoRefreshChanged;
650 autoRefresh = other.autoRefresh;
651 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700652 if (other.what & eTrustedOverlayChanged) {
653 what |= eTrustedOverlayChanged;
654 isTrustedOverlay = other.isTrustedOverlay;
655 }
John Reckc00c6692021-02-16 11:37:33 -0500656 if (other.what & eStretchChanged) {
657 what |= eStretchChanged;
658 stretchEffect = other.stretchEffect;
659 }
chaviwf3f40fe2021-04-27 15:54:02 -0500660 if (other.what & eBufferCropChanged) {
661 what |= eBufferCropChanged;
662 bufferCrop = other.bufferCrop;
663 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700664 if (other.what & eDestinationFrameChanged) {
665 what |= eDestinationFrameChanged;
666 destinationFrame = other.destinationFrame;
667 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700668 if (other.what & eProducerDisconnect) {
669 what |= eProducerDisconnect;
670 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700671 if (other.what & eDropInputModeChanged) {
672 what |= eDropInputModeChanged;
673 dropInputMode = other.dropInputMode;
674 }
chaviw4c36cd82021-11-18 10:37:33 -0600675 if (other.what & eColorChanged) {
676 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000677 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600678 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800679 if (other.what & eColorSpaceAgnosticChanged) {
680 what |= eColorSpaceAgnosticChanged;
681 colorSpaceAgnostic = other.colorSpaceAgnostic;
682 }
Sally Qi81d95e62022-03-21 19:41:33 -0700683 if (other.what & eDimmingEnabledChanged) {
684 what |= eDimmingEnabledChanged;
685 dimmingEnabled = other.dimmingEnabled;
686 }
Pascal Muetschardb39918f2023-01-27 11:36:11 +0100687 if (other.what & eFlushJankData) {
688 what |= eFlushJankData;
689 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700690 if ((other.what & what) != other.what) {
691 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700692 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
693 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700694 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700695}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700696
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000697uint64_t layer_state_t::diff(const layer_state_t& other) const {
698 uint64_t diff = 0;
699 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
700 if (other.what & eLayerChanged) {
701 diff |= eLayerChanged;
702 diff &= ~eRelativeLayerChanged;
703 }
704 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
705 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
706 if (other.what & eTransparentRegionChanged &&
707 (!transparentRegion.hasSameRects(other.transparentRegion))) {
708 diff |= eTransparentRegionChanged;
709 }
710 if (other.what & eFlagsChanged) {
711 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
712 if (changedFlags) diff |= eFlagsChanged;
713 }
714 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
715 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
716 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
717 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
718 if (other.what & eRelativeLayerChanged) {
719 diff |= eRelativeLayerChanged;
720 diff &= ~eLayerChanged;
721 }
722 if (other.what & eReparent &&
723 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
724 other.parentSurfaceControlForChild)) {
725 diff |= eReparent;
726 }
727 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
728 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
729 CHECK_DIFF(diff, eCropChanged, other, crop);
730 if (other.what & eBufferChanged) diff |= eBufferChanged;
731 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
John Reck68796592023-01-25 13:47:12 -0500732 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentSdrHdrRatio,
733 desiredSdrHdrRatio);
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000734 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
735 if (other.what & eSurfaceDamageRegionChanged &&
736 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
737 diff |= eSurfaceDamageRegionChanged;
738 }
739 CHECK_DIFF(diff, eApiChanged, other, api);
740 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
741 CHECK_DIFF(diff, eApiChanged, other, api);
742 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
743 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
744 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
745 CHECK_DIFF3(diff, eBackgroundColorChanged, other, color.rgb, bgColorAlpha, bgColorDataspace);
746 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
747 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
748 CHECK_DIFF3(diff, eRenderBorderChanged, other, borderEnabled, borderWidth, borderColor);
749 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
750 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
751 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
752 changeFrameRateStrategy);
753 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
754 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
755 CHECK_DIFF(diff, eTrustedOverlayChanged, other, isTrustedOverlay);
756 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
757 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
758 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
759 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
760 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
761 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
762 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
763 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
764 return diff;
765}
766
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700767bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500768 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700769}
770
Ady Abraham6e8e3642021-07-08 19:44:07 -0700771bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700772 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700773}
774
chaviw308ddba2020-08-11 16:23:51 -0700775status_t layer_state_t::matrix22_t::write(Parcel& output) const {
776 SAFE_PARCEL(output.writeFloat, dsdx);
777 SAFE_PARCEL(output.writeFloat, dtdx);
778 SAFE_PARCEL(output.writeFloat, dtdy);
779 SAFE_PARCEL(output.writeFloat, dsdy);
780 return NO_ERROR;
781}
782
783status_t layer_state_t::matrix22_t::read(const Parcel& input) {
784 SAFE_PARCEL(input.readFloat, &dsdx);
785 SAFE_PARCEL(input.readFloat, &dtdx);
786 SAFE_PARCEL(input.readFloat, &dtdy);
787 SAFE_PARCEL(input.readFloat, &dsdy);
788 return NO_ERROR;
789}
790
chaviw273171b2018-12-26 11:46:30 -0800791// ------------------------------- InputWindowCommands ----------------------------------------
792
Vishnu Naire798b472020-07-23 13:52:21 -0700793bool InputWindowCommands::merge(const InputWindowCommands& other) {
794 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700795 changes |= !other.focusRequests.empty();
796 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
797 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000798 changes |= !other.windowInfosReportedListeners.empty();
799 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
800 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700801 return changes;
chaviw273171b2018-12-26 11:46:30 -0800802}
803
Vishnu Nair958da932020-08-21 17:12:37 -0700804bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000805 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700806}
807
chaviw273171b2018-12-26 11:46:30 -0800808void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700809 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000810 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800811}
812
chaviw308ddba2020-08-11 16:23:51 -0700813status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700814 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000815
816 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
817 for (const auto& listener : windowInfosReportedListeners) {
818 SAFE_PARCEL(output.writeStrongBinder, listener);
819 }
820
chaviw308ddba2020-08-11 16:23:51 -0700821 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800822}
823
chaviw308ddba2020-08-11 16:23:51 -0700824status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700825 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000826
827 int listenerSize = 0;
828 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
829 windowInfosReportedListeners.reserve(listenerSize);
830 for (int i = 0; i < listenerSize; i++) {
831 sp<gui::IWindowInfosReportedListener> listener;
832 SAFE_PARCEL(input.readStrongBinder, &listener);
833 windowInfosReportedListeners.insert(listener);
834 }
835
chaviw308ddba2020-08-11 16:23:51 -0700836 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800837}
838
Marin Shalamanovc5986772021-03-16 16:09:49 +0100839bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
840 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800841 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
842 int floatClassification = std::fpclassify(frameRate);
843 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
844 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
845 return false;
846 }
847
848 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800849 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700850 (!privileged ||
851 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
852 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800853 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
854 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800855 return false;
856 }
857
Marin Shalamanovc5986772021-03-16 16:09:49 +0100858 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
859 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
860 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
861 changeFrameRateStrategy);
862 }
863
Steven Thomas62a4cf82020-01-31 12:04:03 -0800864 return true;
865}
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);
chaviw308ddba2020-08-11 16:23:51 -0700881 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700882}
883
Huihong Luo9e84f332021-12-16 14:33:46 -0800884status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700885 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800886 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700887 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800888 SAFE_PARCEL(input->read, sourceCrop);
889 SAFE_PARCEL(input->readFloat, &frameScaleX);
890 SAFE_PARCEL(input->readFloat, &frameScaleY);
891 SAFE_PARCEL(input->readBool, &captureSecureLayers);
892 SAFE_PARCEL(input->readInt32, &uid);
893 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700894 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800895 SAFE_PARCEL(input->readBool, &allowProtected);
896 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700897 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700898}
899
Huihong Luo9e84f332021-12-16 14:33:46 -0800900status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
901 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700902
Huihong Luo9e84f332021-12-16 14:33:46 -0800903 SAFE_PARCEL(output->writeStrongBinder, displayToken);
904 SAFE_PARCEL(output->writeUint32, width);
905 SAFE_PARCEL(output->writeUint32, height);
906 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700907 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700908}
909
Huihong Luo9e84f332021-12-16 14:33:46 -0800910status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
911 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700912
Huihong Luo9e84f332021-12-16 14:33:46 -0800913 SAFE_PARCEL(input->readStrongBinder, &displayToken);
914 SAFE_PARCEL(input->readUint32, &width);
915 SAFE_PARCEL(input->readUint32, &height);
916 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700917 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700918}
919
Huihong Luo9e84f332021-12-16 14:33:46 -0800920status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
921 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700922
Huihong Luo9e84f332021-12-16 14:33:46 -0800923 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
924 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700925 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800926 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700927 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800928 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700929 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700930}
931
Huihong Luo9e84f332021-12-16 14:33:46 -0800932status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
933 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700934
Huihong Luo9e84f332021-12-16 14:33:46 -0800935 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700936
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700937 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800938 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700939 excludeHandles.reserve(numExcludeHandles);
940 for (int i = 0; i < numExcludeHandles; i++) {
941 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800942 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700943 excludeHandles.emplace(binder);
944 }
945
Huihong Luo9e84f332021-12-16 14:33:46 -0800946 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700947 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700948}
949
Huihong Luo9e84f332021-12-16 14:33:46 -0800950}; // namespace gui
951
chaviw8dd181f2022-01-05 18:36:46 -0600952ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500953 uint64_t bufferId;
954 if (buffer) {
955 bufferId = buffer->getId();
956 } else {
957 bufferId = cachedBuffer.id;
958 }
959 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600960}
961
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800962status_t BufferData::writeToParcel(Parcel* output) const {
963 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500964
965 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800966 SAFE_PARCEL(output->writeBool, true);
967 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500968 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800969 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500970 }
971
972 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800973 SAFE_PARCEL(output->writeBool, true);
974 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500975 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800976 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500977 }
978
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800979 SAFE_PARCEL(output->writeUint64, frameNumber);
980 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
981 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500982
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800983 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
984 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800985 SAFE_PARCEL(output->writeBool, hasBarrier);
986 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500987
988 return NO_ERROR;
989}
990
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800991status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500992 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800993 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700994 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500995
996 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800997 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500998 if (tmpBool) {
999 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001000 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -05001001 }
1002
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001003 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -05001004 if (tmpBool) {
1005 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001006 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -05001007 }
1008
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001009 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -05001010
1011 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001012 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001013 if (tmpBinder) {
1014 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1015 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001016 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -05001017
1018 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001019 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -05001020 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -08001021 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -05001022
Robert Carr79dc06a2022-02-22 15:28:59 -08001023 SAFE_PARCEL(input->readBool, &hasBarrier);
1024 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
1025
chaviwba4320c2021-09-15 15:20:53 -05001026 return NO_ERROR;
1027}
1028
Chavi Weingarten076acac2023-01-19 17:20:43 +00001029status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1030 SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1031 SAFE_PARCEL(parcel->writeInt32, callbackId);
1032 return NO_ERROR;
1033}
1034
1035status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1036 sp<IBinder> tmpBinder = nullptr;
1037 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1038 if (tmpBinder) {
1039 callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1040 }
1041 SAFE_PARCEL(parcel->readInt32, &callbackId);
1042 return NO_ERROR;
1043}
1044
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001045}; // namespace android