blob: 0d1a69b898e7caf2aba8c94f91c77f830ae3e24c [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
Huihong Luoc50b4982021-11-24 12:34:52 -080054using gui::CallbackId;
chaviw98318de2021-05-19 16:45:23 -050055using gui::FocusRequest;
56using gui::WindowInfoHandle;
57
Pablo Gamito11dcc222020-09-12 15:49:39 +000058layer_state_t::layer_state_t()
Vishnu Nair685cfef2022-02-02 10:01:25 -080059 : surface(nullptr),
60 layerId(-1),
61 what(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000062 x(0),
63 y(0),
64 z(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000065 flags(0),
66 mask(0),
67 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000068 cornerRadius(0.0f),
69 backgroundBlurRadius(0),
Vishnu Nairbbceb462022-10-10 04:52:13 +000070 color(0),
71 bufferTransform(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000072 transformToDisplayInverse(false),
73 crop(Rect::INVALID_RECT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000074 dataspace(ui::Dataspace::UNKNOWN),
75 surfaceDamageRegion(),
76 api(-1),
77 colorTransform(mat4()),
78 bgColorAlpha(0),
79 bgColorDataspace(ui::Dataspace::UNKNOWN),
80 colorSpaceAgnostic(false),
81 shadowRadius(0.0f),
82 frameRateSelectionPriority(-1),
83 frameRate(0.0f),
84 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010085 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Andy Labrada096227e2022-06-15 16:58:11 +000086 defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000087 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080088 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070089 isTrustedOverlay(false),
Tianhao Yao67dd7122022-02-22 17:48:33 +000090 borderEnabled(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070091 bufferCrop(Rect::INVALID_RECT),
92 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070093 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000094 matrix.dsdx = matrix.dtdy = 1.0f;
95 matrix.dsdy = matrix.dtdx = 0.0f;
96 hdrMetadata.validTypes = 0;
97}
98
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099status_t layer_state_t::write(Parcel& output) const
100{
chaviw308ddba2020-08-11 16:23:51 -0700101 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000102 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -0700103 SAFE_PARCEL(output.writeUint64, what);
104 SAFE_PARCEL(output.writeFloat, x);
105 SAFE_PARCEL(output.writeFloat, y);
106 SAFE_PARCEL(output.writeInt32, z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700107 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700108 SAFE_PARCEL(output.writeUint32, flags);
109 SAFE_PARCEL(output.writeUint32, mask);
110 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -0800111 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000112 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
113 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -0700114 SAFE_PARCEL(output.writeFloat, color.r);
115 SAFE_PARCEL(output.writeFloat, color.g);
116 SAFE_PARCEL(output.writeFloat, color.b);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000117 SAFE_PARCEL(output.writeFloat, color.a);
chaviw98318de2021-05-19 16:45:23 -0500118 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700119 SAFE_PARCEL(output.write, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000120 SAFE_PARCEL(output.writeUint32, bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700121 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000122 SAFE_PARCEL(output.writeBool, borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000123 SAFE_PARCEL(output.writeFloat, borderWidth);
124 SAFE_PARCEL(output.writeFloat, borderColor.r);
125 SAFE_PARCEL(output.writeFloat, borderColor.g);
126 SAFE_PARCEL(output.writeFloat, borderColor.b);
127 SAFE_PARCEL(output.writeFloat, borderColor.a);
chaviw308ddba2020-08-11 16:23:51 -0700128 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
129 SAFE_PARCEL(output.write, hdrMetadata);
130 SAFE_PARCEL(output.write, surfaceDamageRegion);
131 SAFE_PARCEL(output.writeInt32, api);
132
Marissa Wall61c58622018-07-18 10:12:20 -0700133 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700134 SAFE_PARCEL(output.writeBool, true);
135 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700136 } else {
chaviw308ddba2020-08-11 16:23:51 -0700137 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700138 }
139
chaviw308ddba2020-08-11 16:23:51 -0700140 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
141 SAFE_PARCEL(output.writeFloat, cornerRadius);
142 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700143 SAFE_PARCEL(output.writeParcelable, metadata);
144 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
145 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
146 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
147 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700148
149 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700150 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700151 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700152 }
chaviw308ddba2020-08-11 16:23:51 -0700153 SAFE_PARCEL(output.writeFloat, shadowRadius);
154 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
155 SAFE_PARCEL(output.writeFloat, frameRate);
156 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100157 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000158 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700159 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800160 SAFE_PARCEL(output.writeBool, autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700161 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700162
163 SAFE_PARCEL(output.writeUint32, blurRegions.size());
164 for (auto region : blurRegions) {
165 SAFE_PARCEL(output.writeUint32, region.blurRadius);
166 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
167 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
168 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
169 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
170 SAFE_PARCEL(output.writeFloat, region.alpha);
171 SAFE_PARCEL(output.writeInt32, region.left);
172 SAFE_PARCEL(output.writeInt32, region.top);
173 SAFE_PARCEL(output.writeInt32, region.right);
174 SAFE_PARCEL(output.writeInt32, region.bottom);
175 }
John Reckcdb4ed72021-02-04 13:39:33 -0500176
177 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500178 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700179 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700180 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500181
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700182 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800183
184 const bool hasBufferData = (bufferData != nullptr);
185 SAFE_PARCEL(output.writeBool, hasBufferData);
186 if (hasBufferData) {
187 SAFE_PARCEL(output.writeParcelable, *bufferData);
188 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800189 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800190}
191
192status_t layer_state_t::read(const Parcel& input)
193{
chaviw308ddba2020-08-11 16:23:51 -0700194 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000195 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700196 SAFE_PARCEL(input.readUint64, &what);
197 SAFE_PARCEL(input.readFloat, &x);
198 SAFE_PARCEL(input.readFloat, &y);
199 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700200 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700201
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800202 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700203
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800204 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700205
206 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800207 SAFE_PARCEL(input.read, crop);
chaviw308ddba2020-08-11 16:23:51 -0700208
Pablo Gamito11dcc222020-09-12 15:49:39 +0000209 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
210 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
211
chaviw308ddba2020-08-11 16:23:51 -0700212 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700213 SAFE_PARCEL(input.readFloat, &tmpFloat);
214 color.r = tmpFloat;
215 SAFE_PARCEL(input.readFloat, &tmpFloat);
216 color.g = tmpFloat;
217 SAFE_PARCEL(input.readFloat, &tmpFloat);
218 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000219 SAFE_PARCEL(input.readFloat, &tmpFloat);
220 color.a = tmpFloat;
221
chaviw98318de2021-05-19 16:45:23 -0500222 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700223
chaviw308ddba2020-08-11 16:23:51 -0700224 SAFE_PARCEL(input.read, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000225 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700226 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000227 SAFE_PARCEL(input.readBool, &borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000228 SAFE_PARCEL(input.readFloat, &tmpFloat);
229 borderWidth = tmpFloat;
230 SAFE_PARCEL(input.readFloat, &tmpFloat);
231 borderColor.r = tmpFloat;
232 SAFE_PARCEL(input.readFloat, &tmpFloat);
233 borderColor.g = tmpFloat;
234 SAFE_PARCEL(input.readFloat, &tmpFloat);
235 borderColor.b = tmpFloat;
236 SAFE_PARCEL(input.readFloat, &tmpFloat);
237 borderColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700238
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800239 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700240 SAFE_PARCEL(input.readUint32, &tmpUint32);
241 dataspace = static_cast<ui::Dataspace>(tmpUint32);
242
243 SAFE_PARCEL(input.read, hdrMetadata);
244 SAFE_PARCEL(input.read, surfaceDamageRegion);
245 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500246
247 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700248 SAFE_PARCEL(input.readBool, &tmpBool);
249 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700250 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
251 }
252
chaviw308ddba2020-08-11 16:23:51 -0700253 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
254 SAFE_PARCEL(input.readFloat, &cornerRadius);
255 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700256 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800257
chaviw308ddba2020-08-11 16:23:51 -0700258 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
259 SAFE_PARCEL(input.readUint32, &tmpUint32);
260 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
261 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800262
chaviw308ddba2020-08-11 16:23:51 -0700263 int32_t numListeners = 0;
264 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700265 listeners.clear();
266 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700267 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700268 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700269 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700270 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700271 listeners.emplace_back(listener, callbackIds);
272 }
chaviw308ddba2020-08-11 16:23:51 -0700273 SAFE_PARCEL(input.readFloat, &shadowRadius);
274 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
275 SAFE_PARCEL(input.readFloat, &frameRate);
276 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100277 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000278 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700279 SAFE_PARCEL(input.readUint32, &tmpUint32);
280 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800281 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700282 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700283
284 uint32_t numRegions = 0;
285 SAFE_PARCEL(input.readUint32, &numRegions);
286 blurRegions.clear();
287 for (uint32_t i = 0; i < numRegions; i++) {
288 BlurRegion region;
289 SAFE_PARCEL(input.readUint32, &region.blurRadius);
290 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
291 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
292 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
293 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
294 SAFE_PARCEL(input.readFloat, &region.alpha);
295 SAFE_PARCEL(input.readInt32, &region.left);
296 SAFE_PARCEL(input.readInt32, &region.top);
297 SAFE_PARCEL(input.readInt32, &region.right);
298 SAFE_PARCEL(input.readInt32, &region.bottom);
299 blurRegions.push_back(region);
300 }
John Reckcdb4ed72021-02-04 13:39:33 -0500301
302 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500303 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700304 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700305 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500306
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700307 uint32_t mode;
308 SAFE_PARCEL(input.readUint32, &mode);
309 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800310
311 bool hasBufferData;
312 SAFE_PARCEL(input.readBool, &hasBufferData);
313 if (hasBufferData) {
314 bufferData = std::make_shared<BufferData>();
315 SAFE_PARCEL(input.readParcelable, bufferData.get());
316 } else {
317 bufferData = nullptr;
318 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800319 return NO_ERROR;
320}
321
Mathias Agopian698c0872011-06-28 19:09:31 -0700322status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700323 return state.write(output);
324}
325
326status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700327 return state.read(input);
328}
329
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700330DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700331
Mathias Agopian8b33f032012-07-24 20:43:54 -0700332status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700333 SAFE_PARCEL(output.writeStrongBinder, token);
334 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
335 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700336 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700337 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700338 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
339 SAFE_PARCEL(output.write, layerStackSpaceRect);
340 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
341 SAFE_PARCEL(output.writeUint32, width);
342 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700343 return NO_ERROR;
344}
345
346status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700347 SAFE_PARCEL(input.readStrongBinder, &token);
348 sp<IBinder> tmpBinder;
349 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
350 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
351
352 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700353 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700354 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700355 uint32_t tmpUint = 0;
356 SAFE_PARCEL(input.readUint32, &tmpUint);
357 orientation = ui::toRotation(tmpUint);
358
359 SAFE_PARCEL(input.read, layerStackSpaceRect);
360 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
361 SAFE_PARCEL(input.readUint32, &width);
362 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700363 return NO_ERROR;
364}
365
Robert Carr2c5f6d22017-09-26 12:30:35 -0700366void DisplayState::merge(const DisplayState& other) {
367 if (other.what & eSurfaceChanged) {
368 what |= eSurfaceChanged;
369 surface = other.surface;
370 }
371 if (other.what & eLayerStackChanged) {
372 what |= eLayerStackChanged;
373 layerStack = other.layerStack;
374 }
Evan Rosky2239b372021-05-20 13:43:47 -0700375 if (other.what & eFlagsChanged) {
376 what |= eFlagsChanged;
377 flags = other.flags;
378 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700379 if (other.what & eDisplayProjectionChanged) {
380 what |= eDisplayProjectionChanged;
381 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200382 layerStackSpaceRect = other.layerStackSpaceRect;
383 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700384 }
385 if (other.what & eDisplaySizeChanged) {
386 what |= eDisplaySizeChanged;
387 width = other.width;
388 height = other.height;
389 }
390}
391
Sally Qi6bb12822022-10-05 11:42:30 -0700392void DisplayState::sanitize(int32_t permissions) {
393 if (what & DisplayState::eLayerStackChanged) {
394 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
395 what &= ~DisplayState::eLayerStackChanged;
396 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
397 }
398 }
399 if (what & DisplayState::eDisplayProjectionChanged) {
400 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
401 what &= ~DisplayState::eDisplayProjectionChanged;
402 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
403 }
404 }
405 if (what & DisplayState::eSurfaceChanged) {
406 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
407 what &= ~DisplayState::eSurfaceChanged;
408 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
409 }
410 }
411}
412
Robert Carrde6d7b42022-01-07 18:23:06 -0800413void layer_state_t::sanitize(int32_t permissions) {
414 // TODO: b/109894387
415 //
416 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
417 // rotation. To see the problem observe that if we have a square parent, and a child
418 // of the same size, then we rotate the child 45 degrees around its center, the child
419 // must now be cropped to a non rectangular 8 sided region.
420 //
421 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
422 // private API, and arbitrary rotation is used in limited use cases, for instance:
423 // - WindowManager only uses rotation in one case, which is on a top level layer in which
424 // cropping is not an issue.
425 // - Launcher, as a privileged app, uses this to transition an application to PiP
426 // (picture-in-picture) mode.
427 //
428 // However given that abuse of rotation matrices could lead to surfaces extending outside
429 // of cropped areas, we need to prevent non-root clients without permission
430 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
431 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
432 // preserving transformations.
433 if (what & eMatrixChanged) {
434 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
435 ui::Transform t;
436 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
437 if (!t.preserveRects()) {
438 what &= ~eMatrixChanged;
439 ALOGE("Stripped non rect preserving matrix in sanitize");
440 }
441 }
442 }
443
444 if (what & eFlagsChanged) {
445 if ((flags & eLayerIsDisplayDecoration) &&
446 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
447 flags &= ~eLayerIsDisplayDecoration;
448 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
449 }
450 }
451
452 if (what & layer_state_t::eInputInfoChanged) {
453 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
454 what &= ~eInputInfoChanged;
455 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
456 }
457 }
458 if (what & layer_state_t::eTrustedOverlayChanged) {
459 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
460 what &= ~eTrustedOverlayChanged;
461 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
462 }
463 }
464 if (what & layer_state_t::eDropInputModeChanged) {
465 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
466 what &= ~eDropInputModeChanged;
467 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
468 }
469 }
470 if (what & layer_state_t::eFrameRateSelectionPriority) {
471 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
472 what &= ~eFrameRateSelectionPriority;
473 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
474 }
475 }
476 if (what & layer_state_t::eFrameRateChanged) {
477 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
478 changeFrameRateStrategy,
479 "layer_state_t::sanitize",
480 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
481 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
482 }
483 }
484}
485
Robert Carr2c5f6d22017-09-26 12:30:35 -0700486void layer_state_t::merge(const layer_state_t& other) {
487 if (other.what & ePositionChanged) {
488 what |= ePositionChanged;
489 x = other.x;
490 y = other.y;
491 }
492 if (other.what & eLayerChanged) {
493 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700494 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700495 z = other.z;
496 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700497 if (other.what & eAlphaChanged) {
498 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000499 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700500 }
501 if (other.what & eMatrixChanged) {
502 what |= eMatrixChanged;
503 matrix = other.matrix;
504 }
505 if (other.what & eTransparentRegionChanged) {
506 what |= eTransparentRegionChanged;
507 transparentRegion = other.transparentRegion;
508 }
509 if (other.what & eFlagsChanged) {
510 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700511 flags &= ~other.mask;
512 flags |= (other.flags & other.mask);
513 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700514 }
515 if (other.what & eLayerStackChanged) {
516 what |= eLayerStackChanged;
517 layerStack = other.layerStack;
518 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700519 if (other.what & eCornerRadiusChanged) {
520 what |= eCornerRadiusChanged;
521 cornerRadius = other.cornerRadius;
522 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800523 if (other.what & eBackgroundBlurRadiusChanged) {
524 what |= eBackgroundBlurRadiusChanged;
525 backgroundBlurRadius = other.backgroundBlurRadius;
526 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700527 if (other.what & eBlurRegionsChanged) {
528 what |= eBlurRegionsChanged;
529 blurRegions = other.blurRegions;
530 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700531 if (other.what & eRelativeLayerChanged) {
532 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700533 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700534 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000535 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700536 }
537 if (other.what & eReparent) {
538 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000539 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700540 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000541 if (other.what & eBufferTransformChanged) {
542 what |= eBufferTransformChanged;
543 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700544 }
545 if (other.what & eTransformToDisplayInverseChanged) {
546 what |= eTransformToDisplayInverseChanged;
547 transformToDisplayInverse = other.transformToDisplayInverse;
548 }
549 if (other.what & eCropChanged) {
550 what |= eCropChanged;
551 crop = other.crop;
552 }
553 if (other.what & eBufferChanged) {
554 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500555 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700556 }
557 if (other.what & eDataspaceChanged) {
558 what |= eDataspaceChanged;
559 dataspace = other.dataspace;
560 }
561 if (other.what & eHdrMetadataChanged) {
562 what |= eHdrMetadataChanged;
563 hdrMetadata = other.hdrMetadata;
564 }
565 if (other.what & eSurfaceDamageRegionChanged) {
566 what |= eSurfaceDamageRegionChanged;
567 surfaceDamageRegion = other.surfaceDamageRegion;
568 }
569 if (other.what & eApiChanged) {
570 what |= eApiChanged;
571 api = other.api;
572 }
573 if (other.what & eSidebandStreamChanged) {
574 what |= eSidebandStreamChanged;
575 sidebandStream = other.sidebandStream;
576 }
Peiyong Lind3788632018-09-18 16:01:31 -0700577 if (other.what & eColorTransformChanged) {
578 what |= eColorTransformChanged;
579 colorTransform = other.colorTransform;
580 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700581 if (other.what & eHasListenerCallbacksChanged) {
582 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700583 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700584 if (other.what & eInputInfoChanged) {
585 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500586 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700587 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800588 if (other.what & eBackgroundColorChanged) {
589 what |= eBackgroundColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000590 color.rgb = other.color.rgb;
Valerie Haudd0b7572019-01-29 14:59:27 -0800591 bgColorAlpha = other.bgColorAlpha;
592 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800593 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800594 if (other.what & eMetadataChanged) {
595 what |= eMetadataChanged;
596 metadata.merge(other.metadata);
597 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700598 if (other.what & eShadowRadiusChanged) {
599 what |= eShadowRadiusChanged;
600 shadowRadius = other.shadowRadius;
601 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000602 if (other.what & eRenderBorderChanged) {
603 what |= eRenderBorderChanged;
604 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000605 borderWidth = other.borderWidth;
606 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000607 }
Andy Labrada096227e2022-06-15 16:58:11 +0000608 if (other.what & eDefaultFrameRateCompatibilityChanged) {
609 what |= eDefaultFrameRateCompatibilityChanged;
610 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
611 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100612 if (other.what & eFrameRateSelectionPriority) {
613 what |= eFrameRateSelectionPriority;
614 frameRateSelectionPriority = other.frameRateSelectionPriority;
615 }
Steven Thomas3172e202020-01-06 19:25:30 -0800616 if (other.what & eFrameRateChanged) {
617 what |= eFrameRateChanged;
618 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800619 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100620 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800621 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700622 if (other.what & eFixedTransformHintChanged) {
623 what |= eFixedTransformHintChanged;
624 fixedTransformHint = other.fixedTransformHint;
625 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800626 if (other.what & eAutoRefreshChanged) {
627 what |= eAutoRefreshChanged;
628 autoRefresh = other.autoRefresh;
629 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700630 if (other.what & eTrustedOverlayChanged) {
631 what |= eTrustedOverlayChanged;
632 isTrustedOverlay = other.isTrustedOverlay;
633 }
John Reckc00c6692021-02-16 11:37:33 -0500634 if (other.what & eStretchChanged) {
635 what |= eStretchChanged;
636 stretchEffect = other.stretchEffect;
637 }
chaviwf3f40fe2021-04-27 15:54:02 -0500638 if (other.what & eBufferCropChanged) {
639 what |= eBufferCropChanged;
640 bufferCrop = other.bufferCrop;
641 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700642 if (other.what & eDestinationFrameChanged) {
643 what |= eDestinationFrameChanged;
644 destinationFrame = other.destinationFrame;
645 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700646 if (other.what & eProducerDisconnect) {
647 what |= eProducerDisconnect;
648 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700649 if (other.what & eDropInputModeChanged) {
650 what |= eDropInputModeChanged;
651 dropInputMode = other.dropInputMode;
652 }
chaviw4c36cd82021-11-18 10:37:33 -0600653 if (other.what & eColorChanged) {
654 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000655 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600656 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800657 if (other.what & eColorSpaceAgnosticChanged) {
658 what |= eColorSpaceAgnosticChanged;
659 colorSpaceAgnostic = other.colorSpaceAgnostic;
660 }
Sally Qi81d95e62022-03-21 19:41:33 -0700661 if (other.what & eDimmingEnabledChanged) {
662 what |= eDimmingEnabledChanged;
663 dimmingEnabled = other.dimmingEnabled;
664 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700665 if ((other.what & what) != other.what) {
666 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700667 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
668 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700669 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700670}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700671
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000672uint64_t layer_state_t::diff(const layer_state_t& other) const {
673 uint64_t diff = 0;
674 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
675 if (other.what & eLayerChanged) {
676 diff |= eLayerChanged;
677 diff &= ~eRelativeLayerChanged;
678 }
679 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
680 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
681 if (other.what & eTransparentRegionChanged &&
682 (!transparentRegion.hasSameRects(other.transparentRegion))) {
683 diff |= eTransparentRegionChanged;
684 }
685 if (other.what & eFlagsChanged) {
686 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
687 if (changedFlags) diff |= eFlagsChanged;
688 }
689 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
690 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
691 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
692 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
693 if (other.what & eRelativeLayerChanged) {
694 diff |= eRelativeLayerChanged;
695 diff &= ~eLayerChanged;
696 }
697 if (other.what & eReparent &&
698 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
699 other.parentSurfaceControlForChild)) {
700 diff |= eReparent;
701 }
702 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
703 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
704 CHECK_DIFF(diff, eCropChanged, other, crop);
705 if (other.what & eBufferChanged) diff |= eBufferChanged;
706 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
707 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
708 if (other.what & eSurfaceDamageRegionChanged &&
709 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
710 diff |= eSurfaceDamageRegionChanged;
711 }
712 CHECK_DIFF(diff, eApiChanged, other, api);
713 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
714 CHECK_DIFF(diff, eApiChanged, other, api);
715 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
716 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
717 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
718 CHECK_DIFF3(diff, eBackgroundColorChanged, other, color.rgb, bgColorAlpha, bgColorDataspace);
719 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
720 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
721 CHECK_DIFF3(diff, eRenderBorderChanged, other, borderEnabled, borderWidth, borderColor);
722 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
723 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
724 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
725 changeFrameRateStrategy);
726 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
727 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
728 CHECK_DIFF(diff, eTrustedOverlayChanged, other, isTrustedOverlay);
729 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
730 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
731 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
732 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
733 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
734 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
735 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
736 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
737 return diff;
738}
739
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700740bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500741 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700742}
743
Ady Abraham6e8e3642021-07-08 19:44:07 -0700744bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700745 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700746}
747
chaviw308ddba2020-08-11 16:23:51 -0700748status_t layer_state_t::matrix22_t::write(Parcel& output) const {
749 SAFE_PARCEL(output.writeFloat, dsdx);
750 SAFE_PARCEL(output.writeFloat, dtdx);
751 SAFE_PARCEL(output.writeFloat, dtdy);
752 SAFE_PARCEL(output.writeFloat, dsdy);
753 return NO_ERROR;
754}
755
756status_t layer_state_t::matrix22_t::read(const Parcel& input) {
757 SAFE_PARCEL(input.readFloat, &dsdx);
758 SAFE_PARCEL(input.readFloat, &dtdx);
759 SAFE_PARCEL(input.readFloat, &dtdy);
760 SAFE_PARCEL(input.readFloat, &dsdy);
761 return NO_ERROR;
762}
763
chaviw273171b2018-12-26 11:46:30 -0800764// ------------------------------- InputWindowCommands ----------------------------------------
765
Vishnu Naire798b472020-07-23 13:52:21 -0700766bool InputWindowCommands::merge(const InputWindowCommands& other) {
767 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700768 changes |= !other.focusRequests.empty();
769 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
770 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000771 changes |= !other.windowInfosReportedListeners.empty();
772 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
773 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700774 return changes;
chaviw273171b2018-12-26 11:46:30 -0800775}
776
Vishnu Nair958da932020-08-21 17:12:37 -0700777bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000778 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700779}
780
chaviw273171b2018-12-26 11:46:30 -0800781void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700782 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000783 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800784}
785
chaviw308ddba2020-08-11 16:23:51 -0700786status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700787 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000788
789 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
790 for (const auto& listener : windowInfosReportedListeners) {
791 SAFE_PARCEL(output.writeStrongBinder, listener);
792 }
793
chaviw308ddba2020-08-11 16:23:51 -0700794 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800795}
796
chaviw308ddba2020-08-11 16:23:51 -0700797status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700798 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000799
800 int listenerSize = 0;
801 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
802 windowInfosReportedListeners.reserve(listenerSize);
803 for (int i = 0; i < listenerSize; i++) {
804 sp<gui::IWindowInfosReportedListener> listener;
805 SAFE_PARCEL(input.readStrongBinder, &listener);
806 windowInfosReportedListeners.insert(listener);
807 }
808
chaviw308ddba2020-08-11 16:23:51 -0700809 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800810}
811
Marin Shalamanovc5986772021-03-16 16:09:49 +0100812bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
813 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800814 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
815 int floatClassification = std::fpclassify(frameRate);
816 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
817 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
818 return false;
819 }
820
821 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800822 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700823 (!privileged ||
824 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
825 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800826 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
827 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800828 return false;
829 }
830
Marin Shalamanovc5986772021-03-16 16:09:49 +0100831 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
832 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
833 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
834 changeFrameRateStrategy);
835 }
836
Steven Thomas62a4cf82020-01-31 12:04:03 -0800837 return true;
838}
839
chaviw618c42d2020-07-24 15:25:08 -0700840// ----------------------------------------------------------------------------
841
Huihong Luo9e84f332021-12-16 14:33:46 -0800842namespace gui {
843
844status_t CaptureArgs::writeToParcel(Parcel* output) const {
845 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
846 SAFE_PARCEL(output->write, sourceCrop);
847 SAFE_PARCEL(output->writeFloat, frameScaleX);
848 SAFE_PARCEL(output->writeFloat, frameScaleY);
849 SAFE_PARCEL(output->writeBool, captureSecureLayers);
850 SAFE_PARCEL(output->writeInt32, uid);
851 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
852 SAFE_PARCEL(output->writeBool, allowProtected);
853 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700854 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700855}
856
Huihong Luo9e84f332021-12-16 14:33:46 -0800857status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700858 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800859 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700860 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800861 SAFE_PARCEL(input->read, sourceCrop);
862 SAFE_PARCEL(input->readFloat, &frameScaleX);
863 SAFE_PARCEL(input->readFloat, &frameScaleY);
864 SAFE_PARCEL(input->readBool, &captureSecureLayers);
865 SAFE_PARCEL(input->readInt32, &uid);
866 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700867 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800868 SAFE_PARCEL(input->readBool, &allowProtected);
869 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700870 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700871}
872
Huihong Luo9e84f332021-12-16 14:33:46 -0800873status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
874 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700875
Huihong Luo9e84f332021-12-16 14:33:46 -0800876 SAFE_PARCEL(output->writeStrongBinder, displayToken);
877 SAFE_PARCEL(output->writeUint32, width);
878 SAFE_PARCEL(output->writeUint32, height);
879 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700880 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700881}
882
Huihong Luo9e84f332021-12-16 14:33:46 -0800883status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
884 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700885
Huihong Luo9e84f332021-12-16 14:33:46 -0800886 SAFE_PARCEL(input->readStrongBinder, &displayToken);
887 SAFE_PARCEL(input->readUint32, &width);
888 SAFE_PARCEL(input->readUint32, &height);
889 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700890 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700891}
892
Huihong Luo9e84f332021-12-16 14:33:46 -0800893status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
894 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700895
Huihong Luo9e84f332021-12-16 14:33:46 -0800896 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
897 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700898 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800899 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700900 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800901 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700902 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700903}
904
Huihong Luo9e84f332021-12-16 14:33:46 -0800905status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
906 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700907
Huihong Luo9e84f332021-12-16 14:33:46 -0800908 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700909
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700910 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800911 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700912 excludeHandles.reserve(numExcludeHandles);
913 for (int i = 0; i < numExcludeHandles; i++) {
914 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800915 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700916 excludeHandles.emplace(binder);
917 }
918
Huihong Luo9e84f332021-12-16 14:33:46 -0800919 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700920 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700921}
922
Huihong Luo9e84f332021-12-16 14:33:46 -0800923}; // namespace gui
924
chaviw8dd181f2022-01-05 18:36:46 -0600925ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500926 uint64_t bufferId;
927 if (buffer) {
928 bufferId = buffer->getId();
929 } else {
930 bufferId = cachedBuffer.id;
931 }
932 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600933}
934
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800935status_t BufferData::writeToParcel(Parcel* output) const {
936 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500937
938 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800939 SAFE_PARCEL(output->writeBool, true);
940 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500941 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800942 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500943 }
944
945 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800946 SAFE_PARCEL(output->writeBool, true);
947 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500948 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800949 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500950 }
951
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800952 SAFE_PARCEL(output->writeUint64, frameNumber);
953 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
954 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500955
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800956 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
957 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800958 SAFE_PARCEL(output->writeBool, hasBarrier);
959 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500960
961 return NO_ERROR;
962}
963
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800964status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500965 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800966 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700967 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500968
969 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800970 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500971 if (tmpBool) {
972 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800973 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500974 }
975
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800976 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500977 if (tmpBool) {
978 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800979 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500980 }
981
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800982 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500983
984 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800985 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500986 if (tmpBinder) {
987 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
988 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800989 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500990
991 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800992 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500993 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800994 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500995
Robert Carr79dc06a2022-02-22 15:28:59 -0800996 SAFE_PARCEL(input->readBool, &hasBarrier);
997 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
998
chaviwba4320c2021-09-15 15:20:53 -0500999 return NO_ERROR;
1000}
1001
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001002}; // namespace android