blob: 338ff1114fa734e90c4715bb80d23db07451f3c5 [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
Ady Abrahamdd5bfa92021-01-07 17:56:08 -080019#include <apex/window.h>
Garfield Tan8a3083e2018-12-03 13:21:07 -080020#include <inttypes.h>
21
Marin Shalamanovc5986772021-03-16 16:09:49 +010022#include <android/native_window.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080024#include <gui/IGraphicBufferProducer.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000025#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070026#include <gui/LayerState.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010027#include <private/gui/ParcelUtils.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000028#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029
Steven Thomas62a4cf82020-01-31 12:04:03 -080030#include <cmath>
31
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032namespace android {
33
chaviw98318de2021-05-19 16:45:23 -050034using gui::FocusRequest;
35using gui::WindowInfoHandle;
36
Pablo Gamito11dcc222020-09-12 15:49:39 +000037layer_state_t::layer_state_t()
Vishnu Nair685cfef2022-02-02 10:01:25 -080038 : surface(nullptr),
39 layerId(-1),
40 what(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000041 x(0),
42 y(0),
43 z(0),
44 w(0),
45 h(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000046 alpha(0),
47 flags(0),
48 mask(0),
49 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000050 cornerRadius(0.0f),
51 backgroundBlurRadius(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000052 transform(0),
53 transformToDisplayInverse(false),
54 crop(Rect::INVALID_RECT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000055 dataspace(ui::Dataspace::UNKNOWN),
56 surfaceDamageRegion(),
57 api(-1),
58 colorTransform(mat4()),
59 bgColorAlpha(0),
60 bgColorDataspace(ui::Dataspace::UNKNOWN),
61 colorSpaceAgnostic(false),
62 shadowRadius(0.0f),
63 frameRateSelectionPriority(-1),
64 frameRate(0.0f),
65 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010066 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Pablo Gamito11dcc222020-09-12 15:49:39 +000067 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080068 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070069 isTrustedOverlay(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070070 bufferCrop(Rect::INVALID_RECT),
71 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070072 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000073 matrix.dsdx = matrix.dtdy = 1.0f;
74 matrix.dsdy = matrix.dtdx = 0.0f;
75 hdrMetadata.validTypes = 0;
76}
77
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078status_t layer_state_t::write(Parcel& output) const
79{
chaviw308ddba2020-08-11 16:23:51 -070080 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +000081 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -070082 SAFE_PARCEL(output.writeUint64, what);
83 SAFE_PARCEL(output.writeFloat, x);
84 SAFE_PARCEL(output.writeFloat, y);
85 SAFE_PARCEL(output.writeInt32, z);
86 SAFE_PARCEL(output.writeUint32, w);
87 SAFE_PARCEL(output.writeUint32, h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -070088 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -070089 SAFE_PARCEL(output.writeFloat, alpha);
90 SAFE_PARCEL(output.writeUint32, flags);
91 SAFE_PARCEL(output.writeUint32, mask);
92 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080093 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000094 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
Pablo Gamito11dcc222020-09-12 15:49:39 +000095 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
96 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070097 SAFE_PARCEL(output.writeFloat, color.r);
98 SAFE_PARCEL(output.writeFloat, color.g);
99 SAFE_PARCEL(output.writeFloat, color.b);
chaviw98318de2021-05-19 16:45:23 -0500100 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -0700101 SAFE_PARCEL(output.write, transparentRegion);
102 SAFE_PARCEL(output.writeUint32, transform);
103 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700104
chaviw308ddba2020-08-11 16:23:51 -0700105 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
106 SAFE_PARCEL(output.write, hdrMetadata);
107 SAFE_PARCEL(output.write, surfaceDamageRegion);
108 SAFE_PARCEL(output.writeInt32, api);
109
Marissa Wall61c58622018-07-18 10:12:20 -0700110 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700111 SAFE_PARCEL(output.writeBool, true);
112 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700113 } else {
chaviw308ddba2020-08-11 16:23:51 -0700114 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700115 }
116
chaviw308ddba2020-08-11 16:23:51 -0700117 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
118 SAFE_PARCEL(output.writeFloat, cornerRadius);
119 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700120 SAFE_PARCEL(output.writeParcelable, metadata);
121 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
122 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
123 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
124 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700125
126 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700127 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700128 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700129 }
chaviw308ddba2020-08-11 16:23:51 -0700130 SAFE_PARCEL(output.writeFloat, shadowRadius);
131 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
132 SAFE_PARCEL(output.writeFloat, frameRate);
133 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100134 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700135 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800136 SAFE_PARCEL(output.writeBool, autoRefresh);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700137
138 SAFE_PARCEL(output.writeUint32, blurRegions.size());
139 for (auto region : blurRegions) {
140 SAFE_PARCEL(output.writeUint32, region.blurRadius);
141 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
142 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
143 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
144 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
145 SAFE_PARCEL(output.writeFloat, region.alpha);
146 SAFE_PARCEL(output.writeInt32, region.left);
147 SAFE_PARCEL(output.writeInt32, region.top);
148 SAFE_PARCEL(output.writeInt32, region.right);
149 SAFE_PARCEL(output.writeInt32, region.bottom);
150 }
John Reckcdb4ed72021-02-04 13:39:33 -0500151
152 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500153 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700154 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700155 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500156
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700157 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800158
159 const bool hasBufferData = (bufferData != nullptr);
160 SAFE_PARCEL(output.writeBool, hasBufferData);
161 if (hasBufferData) {
162 SAFE_PARCEL(output.writeParcelable, *bufferData);
163 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800164 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165}
166
167status_t layer_state_t::read(const Parcel& input)
168{
chaviw308ddba2020-08-11 16:23:51 -0700169 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000170 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700171 SAFE_PARCEL(input.readUint64, &what);
172 SAFE_PARCEL(input.readFloat, &x);
173 SAFE_PARCEL(input.readFloat, &y);
174 SAFE_PARCEL(input.readInt32, &z);
175 SAFE_PARCEL(input.readUint32, &w);
176 SAFE_PARCEL(input.readUint32, &h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700177 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700178 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700179
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800180 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700181
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800182 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700183
184 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800185 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000186 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700187
Pablo Gamito11dcc222020-09-12 15:49:39 +0000188 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
189 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
190
chaviw308ddba2020-08-11 16:23:51 -0700191 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700192 SAFE_PARCEL(input.readFloat, &tmpFloat);
193 color.r = tmpFloat;
194 SAFE_PARCEL(input.readFloat, &tmpFloat);
195 color.g = tmpFloat;
196 SAFE_PARCEL(input.readFloat, &tmpFloat);
197 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500198 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700199
chaviw308ddba2020-08-11 16:23:51 -0700200 SAFE_PARCEL(input.read, transparentRegion);
201 SAFE_PARCEL(input.readUint32, &transform);
202 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700203
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800204 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700205 SAFE_PARCEL(input.readUint32, &tmpUint32);
206 dataspace = static_cast<ui::Dataspace>(tmpUint32);
207
208 SAFE_PARCEL(input.read, hdrMetadata);
209 SAFE_PARCEL(input.read, surfaceDamageRegion);
210 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500211
212 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700213 SAFE_PARCEL(input.readBool, &tmpBool);
214 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700215 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
216 }
217
chaviw308ddba2020-08-11 16:23:51 -0700218 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
219 SAFE_PARCEL(input.readFloat, &cornerRadius);
220 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700221 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800222
chaviw308ddba2020-08-11 16:23:51 -0700223 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
224 SAFE_PARCEL(input.readUint32, &tmpUint32);
225 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
226 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800227
chaviw308ddba2020-08-11 16:23:51 -0700228 int32_t numListeners = 0;
229 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700230 listeners.clear();
231 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700232 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700233 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700234 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700235 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700236 listeners.emplace_back(listener, callbackIds);
237 }
chaviw308ddba2020-08-11 16:23:51 -0700238 SAFE_PARCEL(input.readFloat, &shadowRadius);
239 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
240 SAFE_PARCEL(input.readFloat, &frameRate);
241 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100242 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700243 SAFE_PARCEL(input.readUint32, &tmpUint32);
244 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800245 SAFE_PARCEL(input.readBool, &autoRefresh);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700246
247 uint32_t numRegions = 0;
248 SAFE_PARCEL(input.readUint32, &numRegions);
249 blurRegions.clear();
250 for (uint32_t i = 0; i < numRegions; i++) {
251 BlurRegion region;
252 SAFE_PARCEL(input.readUint32, &region.blurRadius);
253 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
254 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
255 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
256 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
257 SAFE_PARCEL(input.readFloat, &region.alpha);
258 SAFE_PARCEL(input.readInt32, &region.left);
259 SAFE_PARCEL(input.readInt32, &region.top);
260 SAFE_PARCEL(input.readInt32, &region.right);
261 SAFE_PARCEL(input.readInt32, &region.bottom);
262 blurRegions.push_back(region);
263 }
John Reckcdb4ed72021-02-04 13:39:33 -0500264
265 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500266 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700267 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700268 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500269
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700270 uint32_t mode;
271 SAFE_PARCEL(input.readUint32, &mode);
272 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800273
274 bool hasBufferData;
275 SAFE_PARCEL(input.readBool, &hasBufferData);
276 if (hasBufferData) {
277 bufferData = std::make_shared<BufferData>();
278 SAFE_PARCEL(input.readParcelable, bufferData.get());
279 } else {
280 bufferData = nullptr;
281 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800282 return NO_ERROR;
283}
284
Mathias Agopian698c0872011-06-28 19:09:31 -0700285status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700286 return state.write(output);
287}
288
289status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700290 return state.read(input);
291}
292
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700293DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700294
Mathias Agopian8b33f032012-07-24 20:43:54 -0700295status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700296 SAFE_PARCEL(output.writeStrongBinder, token);
297 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
298 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700299 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700300 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700301 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
302 SAFE_PARCEL(output.write, layerStackSpaceRect);
303 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
304 SAFE_PARCEL(output.writeUint32, width);
305 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700306 return NO_ERROR;
307}
308
309status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700310 SAFE_PARCEL(input.readStrongBinder, &token);
311 sp<IBinder> tmpBinder;
312 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
313 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
314
315 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700316 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700317 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700318 uint32_t tmpUint = 0;
319 SAFE_PARCEL(input.readUint32, &tmpUint);
320 orientation = ui::toRotation(tmpUint);
321
322 SAFE_PARCEL(input.read, layerStackSpaceRect);
323 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
324 SAFE_PARCEL(input.readUint32, &width);
325 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700326 return NO_ERROR;
327}
328
Robert Carr2c5f6d22017-09-26 12:30:35 -0700329void DisplayState::merge(const DisplayState& other) {
330 if (other.what & eSurfaceChanged) {
331 what |= eSurfaceChanged;
332 surface = other.surface;
333 }
334 if (other.what & eLayerStackChanged) {
335 what |= eLayerStackChanged;
336 layerStack = other.layerStack;
337 }
Evan Rosky2239b372021-05-20 13:43:47 -0700338 if (other.what & eFlagsChanged) {
339 what |= eFlagsChanged;
340 flags = other.flags;
341 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700342 if (other.what & eDisplayProjectionChanged) {
343 what |= eDisplayProjectionChanged;
344 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200345 layerStackSpaceRect = other.layerStackSpaceRect;
346 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700347 }
348 if (other.what & eDisplaySizeChanged) {
349 what |= eDisplaySizeChanged;
350 width = other.width;
351 height = other.height;
352 }
353}
354
Robert Carrde6d7b42022-01-07 18:23:06 -0800355void layer_state_t::sanitize(int32_t permissions) {
356 // TODO: b/109894387
357 //
358 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
359 // rotation. To see the problem observe that if we have a square parent, and a child
360 // of the same size, then we rotate the child 45 degrees around its center, the child
361 // must now be cropped to a non rectangular 8 sided region.
362 //
363 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
364 // private API, and arbitrary rotation is used in limited use cases, for instance:
365 // - WindowManager only uses rotation in one case, which is on a top level layer in which
366 // cropping is not an issue.
367 // - Launcher, as a privileged app, uses this to transition an application to PiP
368 // (picture-in-picture) mode.
369 //
370 // However given that abuse of rotation matrices could lead to surfaces extending outside
371 // of cropped areas, we need to prevent non-root clients without permission
372 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
373 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
374 // preserving transformations.
375 if (what & eMatrixChanged) {
376 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
377 ui::Transform t;
378 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
379 if (!t.preserveRects()) {
380 what &= ~eMatrixChanged;
381 ALOGE("Stripped non rect preserving matrix in sanitize");
382 }
383 }
384 }
385
386 if (what & eFlagsChanged) {
387 if ((flags & eLayerIsDisplayDecoration) &&
388 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
389 flags &= ~eLayerIsDisplayDecoration;
390 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
391 }
392 }
393
394 if (what & layer_state_t::eInputInfoChanged) {
395 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
396 what &= ~eInputInfoChanged;
397 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
398 }
399 }
400 if (what & layer_state_t::eTrustedOverlayChanged) {
401 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
402 what &= ~eTrustedOverlayChanged;
403 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
404 }
405 }
406 if (what & layer_state_t::eDropInputModeChanged) {
407 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
408 what &= ~eDropInputModeChanged;
409 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
410 }
411 }
412 if (what & layer_state_t::eFrameRateSelectionPriority) {
413 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
414 what &= ~eFrameRateSelectionPriority;
415 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
416 }
417 }
418 if (what & layer_state_t::eFrameRateChanged) {
419 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
420 changeFrameRateStrategy,
421 "layer_state_t::sanitize",
422 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
423 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
424 }
425 }
426}
427
Robert Carr2c5f6d22017-09-26 12:30:35 -0700428void layer_state_t::merge(const layer_state_t& other) {
429 if (other.what & ePositionChanged) {
430 what |= ePositionChanged;
431 x = other.x;
432 y = other.y;
433 }
434 if (other.what & eLayerChanged) {
435 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700436 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700437 z = other.z;
438 }
439 if (other.what & eSizeChanged) {
440 what |= eSizeChanged;
441 w = other.w;
442 h = other.h;
443 }
444 if (other.what & eAlphaChanged) {
445 what |= eAlphaChanged;
446 alpha = other.alpha;
447 }
448 if (other.what & eMatrixChanged) {
449 what |= eMatrixChanged;
450 matrix = other.matrix;
451 }
452 if (other.what & eTransparentRegionChanged) {
453 what |= eTransparentRegionChanged;
454 transparentRegion = other.transparentRegion;
455 }
456 if (other.what & eFlagsChanged) {
457 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700458 flags &= ~other.mask;
459 flags |= (other.flags & other.mask);
460 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700461 }
462 if (other.what & eLayerStackChanged) {
463 what |= eLayerStackChanged;
464 layerStack = other.layerStack;
465 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700466 if (other.what & eCornerRadiusChanged) {
467 what |= eCornerRadiusChanged;
468 cornerRadius = other.cornerRadius;
469 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800470 if (other.what & eBackgroundBlurRadiusChanged) {
471 what |= eBackgroundBlurRadiusChanged;
472 backgroundBlurRadius = other.backgroundBlurRadius;
473 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700474 if (other.what & eBlurRegionsChanged) {
475 what |= eBlurRegionsChanged;
476 blurRegions = other.blurRegions;
477 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700478 if (other.what & eRelativeLayerChanged) {
479 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700480 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700481 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000482 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700483 }
484 if (other.what & eReparent) {
485 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000486 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700487 }
chaviwca27f252018-02-06 16:46:39 -0800488 if (other.what & eDestroySurface) {
489 what |= eDestroySurface;
490 }
Marissa Wall61c58622018-07-18 10:12:20 -0700491 if (other.what & eTransformChanged) {
492 what |= eTransformChanged;
493 transform = other.transform;
494 }
495 if (other.what & eTransformToDisplayInverseChanged) {
496 what |= eTransformToDisplayInverseChanged;
497 transformToDisplayInverse = other.transformToDisplayInverse;
498 }
499 if (other.what & eCropChanged) {
500 what |= eCropChanged;
501 crop = other.crop;
502 }
503 if (other.what & eBufferChanged) {
504 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500505 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700506 }
507 if (other.what & eDataspaceChanged) {
508 what |= eDataspaceChanged;
509 dataspace = other.dataspace;
510 }
511 if (other.what & eHdrMetadataChanged) {
512 what |= eHdrMetadataChanged;
513 hdrMetadata = other.hdrMetadata;
514 }
515 if (other.what & eSurfaceDamageRegionChanged) {
516 what |= eSurfaceDamageRegionChanged;
517 surfaceDamageRegion = other.surfaceDamageRegion;
518 }
519 if (other.what & eApiChanged) {
520 what |= eApiChanged;
521 api = other.api;
522 }
523 if (other.what & eSidebandStreamChanged) {
524 what |= eSidebandStreamChanged;
525 sidebandStream = other.sidebandStream;
526 }
Peiyong Lind3788632018-09-18 16:01:31 -0700527 if (other.what & eColorTransformChanged) {
528 what |= eColorTransformChanged;
529 colorTransform = other.colorTransform;
530 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700531 if (other.what & eHasListenerCallbacksChanged) {
532 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700533 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700534 if (other.what & eInputInfoChanged) {
535 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500536 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700537 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800538 if (other.what & eBackgroundColorChanged) {
539 what |= eBackgroundColorChanged;
540 color = other.color;
541 bgColorAlpha = other.bgColorAlpha;
542 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800543 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800544 if (other.what & eMetadataChanged) {
545 what |= eMetadataChanged;
546 metadata.merge(other.metadata);
547 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700548 if (other.what & eShadowRadiusChanged) {
549 what |= eShadowRadiusChanged;
550 shadowRadius = other.shadowRadius;
551 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100552 if (other.what & eFrameRateSelectionPriority) {
553 what |= eFrameRateSelectionPriority;
554 frameRateSelectionPriority = other.frameRateSelectionPriority;
555 }
Steven Thomas3172e202020-01-06 19:25:30 -0800556 if (other.what & eFrameRateChanged) {
557 what |= eFrameRateChanged;
558 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800559 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100560 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800561 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700562 if (other.what & eFixedTransformHintChanged) {
563 what |= eFixedTransformHintChanged;
564 fixedTransformHint = other.fixedTransformHint;
565 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800566 if (other.what & eAutoRefreshChanged) {
567 what |= eAutoRefreshChanged;
568 autoRefresh = other.autoRefresh;
569 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700570 if (other.what & eTrustedOverlayChanged) {
571 what |= eTrustedOverlayChanged;
572 isTrustedOverlay = other.isTrustedOverlay;
573 }
John Reckc00c6692021-02-16 11:37:33 -0500574 if (other.what & eStretchChanged) {
575 what |= eStretchChanged;
576 stretchEffect = other.stretchEffect;
577 }
chaviwf3f40fe2021-04-27 15:54:02 -0500578 if (other.what & eBufferCropChanged) {
579 what |= eBufferCropChanged;
580 bufferCrop = other.bufferCrop;
581 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700582 if (other.what & eDestinationFrameChanged) {
583 what |= eDestinationFrameChanged;
584 destinationFrame = other.destinationFrame;
585 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700586 if (other.what & eProducerDisconnect) {
587 what |= eProducerDisconnect;
588 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700589 if (other.what & eDropInputModeChanged) {
590 what |= eDropInputModeChanged;
591 dropInputMode = other.dropInputMode;
592 }
chaviw4c36cd82021-11-18 10:37:33 -0600593 if (other.what & eColorChanged) {
594 what |= eColorChanged;
595 color = other.color;
596 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700597 if ((other.what & what) != other.what) {
598 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700599 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
600 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700601 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700602}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700603
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700604bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500605 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700606}
607
Ady Abraham6e8e3642021-07-08 19:44:07 -0700608bool layer_state_t::hasValidBuffer() const {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800609 return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700610}
611
chaviw308ddba2020-08-11 16:23:51 -0700612status_t layer_state_t::matrix22_t::write(Parcel& output) const {
613 SAFE_PARCEL(output.writeFloat, dsdx);
614 SAFE_PARCEL(output.writeFloat, dtdx);
615 SAFE_PARCEL(output.writeFloat, dtdy);
616 SAFE_PARCEL(output.writeFloat, dsdy);
617 return NO_ERROR;
618}
619
620status_t layer_state_t::matrix22_t::read(const Parcel& input) {
621 SAFE_PARCEL(input.readFloat, &dsdx);
622 SAFE_PARCEL(input.readFloat, &dtdx);
623 SAFE_PARCEL(input.readFloat, &dtdy);
624 SAFE_PARCEL(input.readFloat, &dsdy);
625 return NO_ERROR;
626}
627
chaviw273171b2018-12-26 11:46:30 -0800628// ------------------------------- InputWindowCommands ----------------------------------------
629
Vishnu Naire798b472020-07-23 13:52:21 -0700630bool InputWindowCommands::merge(const InputWindowCommands& other) {
631 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700632 changes |= !other.focusRequests.empty();
633 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
634 std::make_move_iterator(other.focusRequests.end()));
Vishnu Naire798b472020-07-23 13:52:21 -0700635 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800636 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700637 return changes;
chaviw273171b2018-12-26 11:46:30 -0800638}
639
Vishnu Nair958da932020-08-21 17:12:37 -0700640bool InputWindowCommands::empty() const {
Vishnu Nair03ccbd62021-12-01 17:21:16 -0800641 return focusRequests.empty() && !syncInputWindows;
Vishnu Nair958da932020-08-21 17:12:37 -0700642}
643
chaviw273171b2018-12-26 11:46:30 -0800644void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700645 focusRequests.clear();
chaviwa911b102019-02-14 10:18:33 -0800646 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800647}
648
chaviw308ddba2020-08-11 16:23:51 -0700649status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700650 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700651 SAFE_PARCEL(output.writeBool, syncInputWindows);
652 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800653}
654
chaviw308ddba2020-08-11 16:23:51 -0700655status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700656 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700657 SAFE_PARCEL(input.readBool, &syncInputWindows);
658 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800659}
660
Marin Shalamanovc5986772021-03-16 16:09:49 +0100661bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
662 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800663 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
664 int floatClassification = std::fpclassify(frameRate);
665 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
666 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
667 return false;
668 }
669
670 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800671 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
672 (!privileged || compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT)) {
673 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
674 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800675 return false;
676 }
677
Marin Shalamanovc5986772021-03-16 16:09:49 +0100678 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
679 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
680 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
681 changeFrameRateStrategy);
682 }
683
Steven Thomas62a4cf82020-01-31 12:04:03 -0800684 return true;
685}
686
chaviw618c42d2020-07-24 15:25:08 -0700687// ----------------------------------------------------------------------------
688
Huihong Luo9e84f332021-12-16 14:33:46 -0800689namespace gui {
690
691status_t CaptureArgs::writeToParcel(Parcel* output) const {
692 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
693 SAFE_PARCEL(output->write, sourceCrop);
694 SAFE_PARCEL(output->writeFloat, frameScaleX);
695 SAFE_PARCEL(output->writeFloat, frameScaleY);
696 SAFE_PARCEL(output->writeBool, captureSecureLayers);
697 SAFE_PARCEL(output->writeInt32, uid);
698 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
699 SAFE_PARCEL(output->writeBool, allowProtected);
700 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700701 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700702}
703
Huihong Luo9e84f332021-12-16 14:33:46 -0800704status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700705 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800706 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700707 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800708 SAFE_PARCEL(input->read, sourceCrop);
709 SAFE_PARCEL(input->readFloat, &frameScaleX);
710 SAFE_PARCEL(input->readFloat, &frameScaleY);
711 SAFE_PARCEL(input->readBool, &captureSecureLayers);
712 SAFE_PARCEL(input->readInt32, &uid);
713 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700714 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800715 SAFE_PARCEL(input->readBool, &allowProtected);
716 SAFE_PARCEL(input->readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700717 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700718}
719
Huihong Luo9e84f332021-12-16 14:33:46 -0800720status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
721 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700722
Huihong Luo9e84f332021-12-16 14:33:46 -0800723 SAFE_PARCEL(output->writeStrongBinder, displayToken);
724 SAFE_PARCEL(output->writeUint32, width);
725 SAFE_PARCEL(output->writeUint32, height);
726 SAFE_PARCEL(output->writeBool, useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700727 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700728}
729
Huihong Luo9e84f332021-12-16 14:33:46 -0800730status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
731 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700732
Huihong Luo9e84f332021-12-16 14:33:46 -0800733 SAFE_PARCEL(input->readStrongBinder, &displayToken);
734 SAFE_PARCEL(input->readUint32, &width);
735 SAFE_PARCEL(input->readUint32, &height);
736 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700737 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700738}
739
Huihong Luo9e84f332021-12-16 14:33:46 -0800740status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
741 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700742
Huihong Luo9e84f332021-12-16 14:33:46 -0800743 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
744 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700745 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800746 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700747 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800748 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700749 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700750}
751
Huihong Luo9e84f332021-12-16 14:33:46 -0800752status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
753 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700754
Huihong Luo9e84f332021-12-16 14:33:46 -0800755 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700756
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700757 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800758 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700759 excludeHandles.reserve(numExcludeHandles);
760 for (int i = 0; i < numExcludeHandles; i++) {
761 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800762 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700763 excludeHandles.emplace(binder);
764 }
765
Huihong Luo9e84f332021-12-16 14:33:46 -0800766 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700767 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700768}
769
Huihong Luo9e84f332021-12-16 14:33:46 -0800770}; // namespace gui
771
chaviw8dd181f2022-01-05 18:36:46 -0600772ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
773 return {buffer->getId(), frameNumber};
774}
775
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800776status_t BufferData::writeToParcel(Parcel* output) const {
777 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500778
779 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800780 SAFE_PARCEL(output->writeBool, true);
781 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500782 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800783 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500784 }
785
786 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800787 SAFE_PARCEL(output->writeBool, true);
788 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500789 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800790 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500791 }
792
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800793 SAFE_PARCEL(output->writeUint64, frameNumber);
794 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
795 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500796
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800797 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
798 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800799 SAFE_PARCEL(output->writeBool, hasBarrier);
800 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500801
802 return NO_ERROR;
803}
804
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800805status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500806 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800807 SAFE_PARCEL(input->readInt32, &tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500808 flags = Flags<BufferDataChange>(tmpInt32);
809
810 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800811 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500812 if (tmpBool) {
813 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800814 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500815 }
816
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800817 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500818 if (tmpBool) {
819 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800820 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500821 }
822
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800823 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500824
825 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800826 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500827 if (tmpBinder) {
828 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
829 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800830 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500831
832 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800833 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500834 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800835 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500836
Robert Carr79dc06a2022-02-22 15:28:59 -0800837 SAFE_PARCEL(input->readBool, &hasBarrier);
838 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
839
chaviwba4320c2021-09-15 15:20:53 -0500840 return NO_ERROR;
841}
842
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800843}; // namespace android