blob: 59b62fe58cadd41b02c2485b277124fa471c5f55 [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 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800188 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800189}
190
191status_t layer_state_t::read(const Parcel& input)
192{
chaviw308ddba2020-08-11 16:23:51 -0700193 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000194 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700195 SAFE_PARCEL(input.readUint64, &what);
196 SAFE_PARCEL(input.readFloat, &x);
197 SAFE_PARCEL(input.readFloat, &y);
198 SAFE_PARCEL(input.readInt32, &z);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700199 SAFE_PARCEL(input.readUint32, &layerStack.id);
Robert Carr2c358bf2018-08-08 15:58:15 -0700200
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800201 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700202
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800203 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700204
205 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800206 SAFE_PARCEL(input.read, crop);
chaviw308ddba2020-08-11 16:23:51 -0700207
Pablo Gamito11dcc222020-09-12 15:49:39 +0000208 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
209 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
210
chaviw308ddba2020-08-11 16:23:51 -0700211 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700212 SAFE_PARCEL(input.readFloat, &tmpFloat);
213 color.r = tmpFloat;
214 SAFE_PARCEL(input.readFloat, &tmpFloat);
215 color.g = tmpFloat;
216 SAFE_PARCEL(input.readFloat, &tmpFloat);
217 color.b = tmpFloat;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000218 SAFE_PARCEL(input.readFloat, &tmpFloat);
219 color.a = tmpFloat;
220
chaviw98318de2021-05-19 16:45:23 -0500221 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700222
chaviw308ddba2020-08-11 16:23:51 -0700223 SAFE_PARCEL(input.read, transparentRegion);
Vishnu Nairbbceb462022-10-10 04:52:13 +0000224 SAFE_PARCEL(input.readUint32, &bufferTransform);
chaviw308ddba2020-08-11 16:23:51 -0700225 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
Tianhao Yao67dd7122022-02-22 17:48:33 +0000226 SAFE_PARCEL(input.readBool, &borderEnabled);
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000227 SAFE_PARCEL(input.readFloat, &tmpFloat);
228 borderWidth = tmpFloat;
229 SAFE_PARCEL(input.readFloat, &tmpFloat);
230 borderColor.r = tmpFloat;
231 SAFE_PARCEL(input.readFloat, &tmpFloat);
232 borderColor.g = tmpFloat;
233 SAFE_PARCEL(input.readFloat, &tmpFloat);
234 borderColor.b = tmpFloat;
235 SAFE_PARCEL(input.readFloat, &tmpFloat);
236 borderColor.a = tmpFloat;
chaviw308ddba2020-08-11 16:23:51 -0700237
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800238 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700239 SAFE_PARCEL(input.readUint32, &tmpUint32);
240 dataspace = static_cast<ui::Dataspace>(tmpUint32);
241
242 SAFE_PARCEL(input.read, hdrMetadata);
243 SAFE_PARCEL(input.read, surfaceDamageRegion);
244 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500245
246 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700247 SAFE_PARCEL(input.readBool, &tmpBool);
248 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700249 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
250 }
251
chaviw308ddba2020-08-11 16:23:51 -0700252 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
253 SAFE_PARCEL(input.readFloat, &cornerRadius);
254 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700255 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800256
chaviw308ddba2020-08-11 16:23:51 -0700257 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
258 SAFE_PARCEL(input.readUint32, &tmpUint32);
259 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
260 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800261
chaviw308ddba2020-08-11 16:23:51 -0700262 int32_t numListeners = 0;
263 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700264 listeners.clear();
265 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700266 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700267 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700268 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700269 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700270 listeners.emplace_back(listener, callbackIds);
271 }
chaviw308ddba2020-08-11 16:23:51 -0700272 SAFE_PARCEL(input.readFloat, &shadowRadius);
273 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
274 SAFE_PARCEL(input.readFloat, &frameRate);
275 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100276 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
Andy Labrada096227e2022-06-15 16:58:11 +0000277 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
chaviw308ddba2020-08-11 16:23:51 -0700278 SAFE_PARCEL(input.readUint32, &tmpUint32);
279 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800280 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700281 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700282
283 uint32_t numRegions = 0;
284 SAFE_PARCEL(input.readUint32, &numRegions);
285 blurRegions.clear();
286 for (uint32_t i = 0; i < numRegions; i++) {
287 BlurRegion region;
288 SAFE_PARCEL(input.readUint32, &region.blurRadius);
289 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
290 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
291 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
292 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
293 SAFE_PARCEL(input.readFloat, &region.alpha);
294 SAFE_PARCEL(input.readInt32, &region.left);
295 SAFE_PARCEL(input.readInt32, &region.top);
296 SAFE_PARCEL(input.readInt32, &region.right);
297 SAFE_PARCEL(input.readInt32, &region.bottom);
298 blurRegions.push_back(region);
299 }
John Reckcdb4ed72021-02-04 13:39:33 -0500300
301 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500302 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700303 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700304 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500305
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700306 uint32_t mode;
307 SAFE_PARCEL(input.readUint32, &mode);
308 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800309
310 bool hasBufferData;
311 SAFE_PARCEL(input.readBool, &hasBufferData);
312 if (hasBufferData) {
313 bufferData = std::make_shared<BufferData>();
314 SAFE_PARCEL(input.readParcelable, bufferData.get());
315 } else {
316 bufferData = nullptr;
317 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800318 return NO_ERROR;
319}
320
Mathias Agopian698c0872011-06-28 19:09:31 -0700321status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700322 return state.write(output);
323}
324
325status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700326 return state.read(input);
327}
328
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700329DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700330
Mathias Agopian8b33f032012-07-24 20:43:54 -0700331status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700332 SAFE_PARCEL(output.writeStrongBinder, token);
333 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
334 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700335 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700336 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700337 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
338 SAFE_PARCEL(output.write, layerStackSpaceRect);
339 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
340 SAFE_PARCEL(output.writeUint32, width);
341 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700342 return NO_ERROR;
343}
344
345status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700346 SAFE_PARCEL(input.readStrongBinder, &token);
347 sp<IBinder> tmpBinder;
348 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
349 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
350
351 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700352 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700353 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700354 uint32_t tmpUint = 0;
355 SAFE_PARCEL(input.readUint32, &tmpUint);
356 orientation = ui::toRotation(tmpUint);
357
358 SAFE_PARCEL(input.read, layerStackSpaceRect);
359 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
360 SAFE_PARCEL(input.readUint32, &width);
361 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700362 return NO_ERROR;
363}
364
Robert Carr2c5f6d22017-09-26 12:30:35 -0700365void DisplayState::merge(const DisplayState& other) {
366 if (other.what & eSurfaceChanged) {
367 what |= eSurfaceChanged;
368 surface = other.surface;
369 }
370 if (other.what & eLayerStackChanged) {
371 what |= eLayerStackChanged;
372 layerStack = other.layerStack;
373 }
Evan Rosky2239b372021-05-20 13:43:47 -0700374 if (other.what & eFlagsChanged) {
375 what |= eFlagsChanged;
376 flags = other.flags;
377 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700378 if (other.what & eDisplayProjectionChanged) {
379 what |= eDisplayProjectionChanged;
380 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200381 layerStackSpaceRect = other.layerStackSpaceRect;
382 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700383 }
384 if (other.what & eDisplaySizeChanged) {
385 what |= eDisplaySizeChanged;
386 width = other.width;
387 height = other.height;
388 }
389}
390
Sally Qi6bb12822022-10-05 11:42:30 -0700391void DisplayState::sanitize(int32_t permissions) {
392 if (what & DisplayState::eLayerStackChanged) {
393 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
394 what &= ~DisplayState::eLayerStackChanged;
395 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
396 }
397 }
398 if (what & DisplayState::eDisplayProjectionChanged) {
399 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
400 what &= ~DisplayState::eDisplayProjectionChanged;
401 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
402 }
403 }
404 if (what & DisplayState::eSurfaceChanged) {
405 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
406 what &= ~DisplayState::eSurfaceChanged;
407 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
408 }
409 }
410}
411
Robert Carrde6d7b42022-01-07 18:23:06 -0800412void layer_state_t::sanitize(int32_t permissions) {
413 // TODO: b/109894387
414 //
415 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
416 // rotation. To see the problem observe that if we have a square parent, and a child
417 // of the same size, then we rotate the child 45 degrees around its center, the child
418 // must now be cropped to a non rectangular 8 sided region.
419 //
420 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
421 // private API, and arbitrary rotation is used in limited use cases, for instance:
422 // - WindowManager only uses rotation in one case, which is on a top level layer in which
423 // cropping is not an issue.
424 // - Launcher, as a privileged app, uses this to transition an application to PiP
425 // (picture-in-picture) mode.
426 //
427 // However given that abuse of rotation matrices could lead to surfaces extending outside
428 // of cropped areas, we need to prevent non-root clients without permission
429 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
430 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
431 // preserving transformations.
432 if (what & eMatrixChanged) {
433 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
434 ui::Transform t;
435 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
436 if (!t.preserveRects()) {
437 what &= ~eMatrixChanged;
438 ALOGE("Stripped non rect preserving matrix in sanitize");
439 }
440 }
441 }
442
443 if (what & eFlagsChanged) {
444 if ((flags & eLayerIsDisplayDecoration) &&
445 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
446 flags &= ~eLayerIsDisplayDecoration;
447 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
448 }
449 }
450
451 if (what & layer_state_t::eInputInfoChanged) {
452 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
453 what &= ~eInputInfoChanged;
454 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
455 }
456 }
457 if (what & layer_state_t::eTrustedOverlayChanged) {
458 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
459 what &= ~eTrustedOverlayChanged;
460 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
461 }
462 }
463 if (what & layer_state_t::eDropInputModeChanged) {
464 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
465 what &= ~eDropInputModeChanged;
466 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
467 }
468 }
469 if (what & layer_state_t::eFrameRateSelectionPriority) {
470 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
471 what &= ~eFrameRateSelectionPriority;
472 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
473 }
474 }
475 if (what & layer_state_t::eFrameRateChanged) {
476 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
477 changeFrameRateStrategy,
478 "layer_state_t::sanitize",
479 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
480 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
481 }
482 }
483}
484
Robert Carr2c5f6d22017-09-26 12:30:35 -0700485void layer_state_t::merge(const layer_state_t& other) {
486 if (other.what & ePositionChanged) {
487 what |= ePositionChanged;
488 x = other.x;
489 y = other.y;
490 }
491 if (other.what & eLayerChanged) {
492 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700493 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700494 z = other.z;
495 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700496 if (other.what & eAlphaChanged) {
497 what |= eAlphaChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000498 color.a = other.color.a;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700499 }
500 if (other.what & eMatrixChanged) {
501 what |= eMatrixChanged;
502 matrix = other.matrix;
503 }
504 if (other.what & eTransparentRegionChanged) {
505 what |= eTransparentRegionChanged;
506 transparentRegion = other.transparentRegion;
507 }
508 if (other.what & eFlagsChanged) {
509 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700510 flags &= ~other.mask;
511 flags |= (other.flags & other.mask);
512 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700513 }
514 if (other.what & eLayerStackChanged) {
515 what |= eLayerStackChanged;
516 layerStack = other.layerStack;
517 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700518 if (other.what & eCornerRadiusChanged) {
519 what |= eCornerRadiusChanged;
520 cornerRadius = other.cornerRadius;
521 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800522 if (other.what & eBackgroundBlurRadiusChanged) {
523 what |= eBackgroundBlurRadiusChanged;
524 backgroundBlurRadius = other.backgroundBlurRadius;
525 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700526 if (other.what & eBlurRegionsChanged) {
527 what |= eBlurRegionsChanged;
528 blurRegions = other.blurRegions;
529 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700530 if (other.what & eRelativeLayerChanged) {
531 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700532 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700533 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000534 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700535 }
536 if (other.what & eReparent) {
537 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000538 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700539 }
Vishnu Nairbbceb462022-10-10 04:52:13 +0000540 if (other.what & eBufferTransformChanged) {
541 what |= eBufferTransformChanged;
542 bufferTransform = other.bufferTransform;
Marissa Wall61c58622018-07-18 10:12:20 -0700543 }
544 if (other.what & eTransformToDisplayInverseChanged) {
545 what |= eTransformToDisplayInverseChanged;
546 transformToDisplayInverse = other.transformToDisplayInverse;
547 }
548 if (other.what & eCropChanged) {
549 what |= eCropChanged;
550 crop = other.crop;
551 }
552 if (other.what & eBufferChanged) {
553 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500554 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700555 }
556 if (other.what & eDataspaceChanged) {
557 what |= eDataspaceChanged;
558 dataspace = other.dataspace;
559 }
560 if (other.what & eHdrMetadataChanged) {
561 what |= eHdrMetadataChanged;
562 hdrMetadata = other.hdrMetadata;
563 }
564 if (other.what & eSurfaceDamageRegionChanged) {
565 what |= eSurfaceDamageRegionChanged;
566 surfaceDamageRegion = other.surfaceDamageRegion;
567 }
568 if (other.what & eApiChanged) {
569 what |= eApiChanged;
570 api = other.api;
571 }
572 if (other.what & eSidebandStreamChanged) {
573 what |= eSidebandStreamChanged;
574 sidebandStream = other.sidebandStream;
575 }
Peiyong Lind3788632018-09-18 16:01:31 -0700576 if (other.what & eColorTransformChanged) {
577 what |= eColorTransformChanged;
578 colorTransform = other.colorTransform;
579 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700580 if (other.what & eHasListenerCallbacksChanged) {
581 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700582 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700583 if (other.what & eInputInfoChanged) {
584 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500585 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700586 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800587 if (other.what & eBackgroundColorChanged) {
588 what |= eBackgroundColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000589 color.rgb = other.color.rgb;
Valerie Haudd0b7572019-01-29 14:59:27 -0800590 bgColorAlpha = other.bgColorAlpha;
591 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800592 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800593 if (other.what & eMetadataChanged) {
594 what |= eMetadataChanged;
595 metadata.merge(other.metadata);
596 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700597 if (other.what & eShadowRadiusChanged) {
598 what |= eShadowRadiusChanged;
599 shadowRadius = other.shadowRadius;
600 }
Tianhao Yao67dd7122022-02-22 17:48:33 +0000601 if (other.what & eRenderBorderChanged) {
602 what |= eRenderBorderChanged;
603 borderEnabled = other.borderEnabled;
Tianhao Yao10cea3c2022-03-30 01:37:22 +0000604 borderWidth = other.borderWidth;
605 borderColor = other.borderColor;
Tianhao Yao67dd7122022-02-22 17:48:33 +0000606 }
Andy Labrada096227e2022-06-15 16:58:11 +0000607 if (other.what & eDefaultFrameRateCompatibilityChanged) {
608 what |= eDefaultFrameRateCompatibilityChanged;
609 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
610 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100611 if (other.what & eFrameRateSelectionPriority) {
612 what |= eFrameRateSelectionPriority;
613 frameRateSelectionPriority = other.frameRateSelectionPriority;
614 }
Steven Thomas3172e202020-01-06 19:25:30 -0800615 if (other.what & eFrameRateChanged) {
616 what |= eFrameRateChanged;
617 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800618 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100619 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800620 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700621 if (other.what & eFixedTransformHintChanged) {
622 what |= eFixedTransformHintChanged;
623 fixedTransformHint = other.fixedTransformHint;
624 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800625 if (other.what & eAutoRefreshChanged) {
626 what |= eAutoRefreshChanged;
627 autoRefresh = other.autoRefresh;
628 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700629 if (other.what & eTrustedOverlayChanged) {
630 what |= eTrustedOverlayChanged;
631 isTrustedOverlay = other.isTrustedOverlay;
632 }
John Reckc00c6692021-02-16 11:37:33 -0500633 if (other.what & eStretchChanged) {
634 what |= eStretchChanged;
635 stretchEffect = other.stretchEffect;
636 }
chaviwf3f40fe2021-04-27 15:54:02 -0500637 if (other.what & eBufferCropChanged) {
638 what |= eBufferCropChanged;
639 bufferCrop = other.bufferCrop;
640 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700641 if (other.what & eDestinationFrameChanged) {
642 what |= eDestinationFrameChanged;
643 destinationFrame = other.destinationFrame;
644 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700645 if (other.what & eProducerDisconnect) {
646 what |= eProducerDisconnect;
647 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700648 if (other.what & eDropInputModeChanged) {
649 what |= eDropInputModeChanged;
650 dropInputMode = other.dropInputMode;
651 }
chaviw4c36cd82021-11-18 10:37:33 -0600652 if (other.what & eColorChanged) {
653 what |= eColorChanged;
Vishnu Nairbbceb462022-10-10 04:52:13 +0000654 color.rgb = other.color.rgb;
chaviw4c36cd82021-11-18 10:37:33 -0600655 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800656 if (other.what & eColorSpaceAgnosticChanged) {
657 what |= eColorSpaceAgnosticChanged;
658 colorSpaceAgnostic = other.colorSpaceAgnostic;
659 }
Sally Qi81d95e62022-03-21 19:41:33 -0700660 if (other.what & eDimmingEnabledChanged) {
661 what |= eDimmingEnabledChanged;
662 dimmingEnabled = other.dimmingEnabled;
663 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700664 if ((other.what & what) != other.what) {
665 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700666 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
667 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700668 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700669}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700670
Vishnu Nairaa799bd2022-11-16 23:09:09 +0000671uint64_t layer_state_t::diff(const layer_state_t& other) const {
672 uint64_t diff = 0;
673 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
674 if (other.what & eLayerChanged) {
675 diff |= eLayerChanged;
676 diff &= ~eRelativeLayerChanged;
677 }
678 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
679 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
680 if (other.what & eTransparentRegionChanged &&
681 (!transparentRegion.hasSameRects(other.transparentRegion))) {
682 diff |= eTransparentRegionChanged;
683 }
684 if (other.what & eFlagsChanged) {
685 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
686 if (changedFlags) diff |= eFlagsChanged;
687 }
688 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
689 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
690 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
691 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
692 if (other.what & eRelativeLayerChanged) {
693 diff |= eRelativeLayerChanged;
694 diff &= ~eLayerChanged;
695 }
696 if (other.what & eReparent &&
697 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
698 other.parentSurfaceControlForChild)) {
699 diff |= eReparent;
700 }
701 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
702 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
703 CHECK_DIFF(diff, eCropChanged, other, crop);
704 if (other.what & eBufferChanged) diff |= eBufferChanged;
705 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
706 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
707 if (other.what & eSurfaceDamageRegionChanged &&
708 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
709 diff |= eSurfaceDamageRegionChanged;
710 }
711 CHECK_DIFF(diff, eApiChanged, other, api);
712 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
713 CHECK_DIFF(diff, eApiChanged, other, api);
714 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
715 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
716 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
717 CHECK_DIFF3(diff, eBackgroundColorChanged, other, color.rgb, bgColorAlpha, bgColorDataspace);
718 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
719 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
720 CHECK_DIFF3(diff, eRenderBorderChanged, other, borderEnabled, borderWidth, borderColor);
721 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
722 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
723 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
724 changeFrameRateStrategy);
725 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
726 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
727 CHECK_DIFF(diff, eTrustedOverlayChanged, other, isTrustedOverlay);
728 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
729 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
730 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
731 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
732 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
733 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
734 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
735 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
736 return diff;
737}
738
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700739bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500740 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700741}
742
Ady Abraham6e8e3642021-07-08 19:44:07 -0700743bool layer_state_t::hasValidBuffer() const {
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700744 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700745}
746
chaviw308ddba2020-08-11 16:23:51 -0700747status_t layer_state_t::matrix22_t::write(Parcel& output) const {
748 SAFE_PARCEL(output.writeFloat, dsdx);
749 SAFE_PARCEL(output.writeFloat, dtdx);
750 SAFE_PARCEL(output.writeFloat, dtdy);
751 SAFE_PARCEL(output.writeFloat, dsdy);
752 return NO_ERROR;
753}
754
755status_t layer_state_t::matrix22_t::read(const Parcel& input) {
756 SAFE_PARCEL(input.readFloat, &dsdx);
757 SAFE_PARCEL(input.readFloat, &dtdx);
758 SAFE_PARCEL(input.readFloat, &dtdy);
759 SAFE_PARCEL(input.readFloat, &dsdy);
760 return NO_ERROR;
761}
762
chaviw273171b2018-12-26 11:46:30 -0800763// ------------------------------- InputWindowCommands ----------------------------------------
764
Vishnu Naire798b472020-07-23 13:52:21 -0700765bool InputWindowCommands::merge(const InputWindowCommands& other) {
766 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700767 changes |= !other.focusRequests.empty();
768 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
769 std::make_move_iterator(other.focusRequests.end()));
Patrick Williams641f7f22022-06-22 19:25:35 +0000770 changes |= !other.windowInfosReportedListeners.empty();
771 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
772 other.windowInfosReportedListeners.end());
Vishnu Naire798b472020-07-23 13:52:21 -0700773 return changes;
chaviw273171b2018-12-26 11:46:30 -0800774}
775
Vishnu Nair958da932020-08-21 17:12:37 -0700776bool InputWindowCommands::empty() const {
Patrick Williams641f7f22022-06-22 19:25:35 +0000777 return focusRequests.empty() && windowInfosReportedListeners.empty();
Vishnu Nair958da932020-08-21 17:12:37 -0700778}
779
chaviw273171b2018-12-26 11:46:30 -0800780void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700781 focusRequests.clear();
Patrick Williams641f7f22022-06-22 19:25:35 +0000782 windowInfosReportedListeners.clear();
chaviw273171b2018-12-26 11:46:30 -0800783}
784
chaviw308ddba2020-08-11 16:23:51 -0700785status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700786 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000787
788 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
789 for (const auto& listener : windowInfosReportedListeners) {
790 SAFE_PARCEL(output.writeStrongBinder, listener);
791 }
792
chaviw308ddba2020-08-11 16:23:51 -0700793 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800794}
795
chaviw308ddba2020-08-11 16:23:51 -0700796status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700797 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
Patrick Williams641f7f22022-06-22 19:25:35 +0000798
799 int listenerSize = 0;
800 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
801 windowInfosReportedListeners.reserve(listenerSize);
802 for (int i = 0; i < listenerSize; i++) {
803 sp<gui::IWindowInfosReportedListener> listener;
804 SAFE_PARCEL(input.readStrongBinder, &listener);
805 windowInfosReportedListeners.insert(listener);
806 }
807
chaviw308ddba2020-08-11 16:23:51 -0700808 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800809}
810
Marin Shalamanovc5986772021-03-16 16:09:49 +0100811bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
812 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800813 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
814 int floatClassification = std::fpclassify(frameRate);
815 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
816 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
817 return false;
818 }
819
820 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800821 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700822 (!privileged ||
823 (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
824 compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800825 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
826 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800827 return false;
828 }
829
Marin Shalamanovc5986772021-03-16 16:09:49 +0100830 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
831 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
832 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
833 changeFrameRateStrategy);
834 }
835
Steven Thomas62a4cf82020-01-31 12:04:03 -0800836 return true;
837}
838
chaviw618c42d2020-07-24 15:25:08 -0700839// ----------------------------------------------------------------------------
840
Huihong Luo9e84f332021-12-16 14:33:46 -0800841namespace gui {
842
843status_t CaptureArgs::writeToParcel(Parcel* output) const {
844 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
845 SAFE_PARCEL(output->write, sourceCrop);
846 SAFE_PARCEL(output->writeFloat, frameScaleX);
847 SAFE_PARCEL(output->writeFloat, frameScaleY);
848 SAFE_PARCEL(output->writeBool, captureSecureLayers);
849 SAFE_PARCEL(output->writeInt32, uid);
850 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
851 SAFE_PARCEL(output->writeBool, allowProtected);
852 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700853 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700854}
855
Huihong Luo9e84f332021-12-16 14:33:46 -0800856status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700857 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800858 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700859 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800860 SAFE_PARCEL(input->read, sourceCrop);
861 SAFE_PARCEL(input->readFloat, &frameScaleX);
862 SAFE_PARCEL(input->readFloat, &frameScaleY);
863 SAFE_PARCEL(input->readBool, &captureSecureLayers);
864 SAFE_PARCEL(input->readInt32, &uid);
865 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700866 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800867 SAFE_PARCEL(input->readBool, &allowProtected);
868 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700869 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700870}
871
Huihong Luo9e84f332021-12-16 14:33:46 -0800872status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
873 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700874
Huihong Luo9e84f332021-12-16 14:33:46 -0800875 SAFE_PARCEL(output->writeStrongBinder, displayToken);
876 SAFE_PARCEL(output->writeUint32, width);
877 SAFE_PARCEL(output->writeUint32, height);
878 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700879 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700880}
881
Huihong Luo9e84f332021-12-16 14:33:46 -0800882status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
883 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700884
Huihong Luo9e84f332021-12-16 14:33:46 -0800885 SAFE_PARCEL(input->readStrongBinder, &displayToken);
886 SAFE_PARCEL(input->readUint32, &width);
887 SAFE_PARCEL(input->readUint32, &height);
888 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700889 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700890}
891
Huihong Luo9e84f332021-12-16 14:33:46 -0800892status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
893 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700894
Huihong Luo9e84f332021-12-16 14:33:46 -0800895 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
896 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700897 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800898 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700899 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800900 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700901 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700902}
903
Huihong Luo9e84f332021-12-16 14:33:46 -0800904status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
905 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700906
Huihong Luo9e84f332021-12-16 14:33:46 -0800907 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700908
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700909 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800910 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700911 excludeHandles.reserve(numExcludeHandles);
912 for (int i = 0; i < numExcludeHandles; i++) {
913 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800914 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700915 excludeHandles.emplace(binder);
916 }
917
Huihong Luo9e84f332021-12-16 14:33:46 -0800918 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700919 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700920}
921
Huihong Luo9e84f332021-12-16 14:33:46 -0800922}; // namespace gui
923
chaviw8dd181f2022-01-05 18:36:46 -0600924ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500925 uint64_t bufferId;
926 if (buffer) {
927 bufferId = buffer->getId();
928 } else {
929 bufferId = cachedBuffer.id;
930 }
931 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600932}
933
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800934status_t BufferData::writeToParcel(Parcel* output) const {
935 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500936
937 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800938 SAFE_PARCEL(output->writeBool, true);
939 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500940 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800941 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500942 }
943
944 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800945 SAFE_PARCEL(output->writeBool, true);
946 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500947 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800948 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500949 }
950
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800951 SAFE_PARCEL(output->writeUint64, frameNumber);
952 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
953 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500954
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800955 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
956 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800957 SAFE_PARCEL(output->writeBool, hasBarrier);
958 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500959
960 return NO_ERROR;
961}
962
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800963status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500964 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800965 SAFE_PARCEL(input->readInt32, &tmpInt32);
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700966 flags = ftl::Flags<BufferDataChange>(tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500967
968 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800969 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500970 if (tmpBool) {
971 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800972 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500973 }
974
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800975 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500976 if (tmpBool) {
977 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800978 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500979 }
980
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800981 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500982
983 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800984 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500985 if (tmpBinder) {
986 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
987 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800988 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500989
990 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800991 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500992 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800993 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500994
Robert Carr79dc06a2022-02-22 15:28:59 -0800995 SAFE_PARCEL(input->readBool, &hasBarrier);
996 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
997
chaviwba4320c2021-09-15 15:20:53 -0500998 return NO_ERROR;
999}
1000
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001001}; // namespace android