blob: 304fc17e07dd9b78c3efa32434250310c6ea3f05 [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);
Sally Qi81d95e62022-03-21 19:41:33 -0700137 SAFE_PARCEL(output.writeBool, dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700138
139 SAFE_PARCEL(output.writeUint32, blurRegions.size());
140 for (auto region : blurRegions) {
141 SAFE_PARCEL(output.writeUint32, region.blurRadius);
142 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
143 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
144 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
145 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
146 SAFE_PARCEL(output.writeFloat, region.alpha);
147 SAFE_PARCEL(output.writeInt32, region.left);
148 SAFE_PARCEL(output.writeInt32, region.top);
149 SAFE_PARCEL(output.writeInt32, region.right);
150 SAFE_PARCEL(output.writeInt32, region.bottom);
151 }
John Reckcdb4ed72021-02-04 13:39:33 -0500152
153 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500154 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700155 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700156 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500157
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700158 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
Vishnu Nair685cfef2022-02-02 10:01:25 -0800159
160 const bool hasBufferData = (bufferData != nullptr);
161 SAFE_PARCEL(output.writeBool, hasBufferData);
162 if (hasBufferData) {
163 SAFE_PARCEL(output.writeParcelable, *bufferData);
164 }
Mathias Agopianac9fa422013-02-11 16:40:36 -0800165 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166}
167
168status_t layer_state_t::read(const Parcel& input)
169{
chaviw308ddba2020-08-11 16:23:51 -0700170 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000171 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700172 SAFE_PARCEL(input.readUint64, &what);
173 SAFE_PARCEL(input.readFloat, &x);
174 SAFE_PARCEL(input.readFloat, &y);
175 SAFE_PARCEL(input.readInt32, &z);
176 SAFE_PARCEL(input.readUint32, &w);
177 SAFE_PARCEL(input.readUint32, &h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700178 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700179 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700180
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800181 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700182
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800183 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700184
185 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800186 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000187 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700188
Pablo Gamito11dcc222020-09-12 15:49:39 +0000189 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
190 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
191
chaviw308ddba2020-08-11 16:23:51 -0700192 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700193 SAFE_PARCEL(input.readFloat, &tmpFloat);
194 color.r = tmpFloat;
195 SAFE_PARCEL(input.readFloat, &tmpFloat);
196 color.g = tmpFloat;
197 SAFE_PARCEL(input.readFloat, &tmpFloat);
198 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500199 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700200
chaviw308ddba2020-08-11 16:23:51 -0700201 SAFE_PARCEL(input.read, transparentRegion);
202 SAFE_PARCEL(input.readUint32, &transform);
203 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700204
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800205 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700206 SAFE_PARCEL(input.readUint32, &tmpUint32);
207 dataspace = static_cast<ui::Dataspace>(tmpUint32);
208
209 SAFE_PARCEL(input.read, hdrMetadata);
210 SAFE_PARCEL(input.read, surfaceDamageRegion);
211 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500212
213 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700214 SAFE_PARCEL(input.readBool, &tmpBool);
215 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700216 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
217 }
218
chaviw308ddba2020-08-11 16:23:51 -0700219 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
220 SAFE_PARCEL(input.readFloat, &cornerRadius);
221 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700222 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800223
chaviw308ddba2020-08-11 16:23:51 -0700224 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
225 SAFE_PARCEL(input.readUint32, &tmpUint32);
226 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
227 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800228
chaviw308ddba2020-08-11 16:23:51 -0700229 int32_t numListeners = 0;
230 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700231 listeners.clear();
232 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700233 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700234 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700235 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700236 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700237 listeners.emplace_back(listener, callbackIds);
238 }
chaviw308ddba2020-08-11 16:23:51 -0700239 SAFE_PARCEL(input.readFloat, &shadowRadius);
240 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
241 SAFE_PARCEL(input.readFloat, &frameRate);
242 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100243 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700244 SAFE_PARCEL(input.readUint32, &tmpUint32);
245 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800246 SAFE_PARCEL(input.readBool, &autoRefresh);
Sally Qi81d95e62022-03-21 19:41:33 -0700247 SAFE_PARCEL(input.readBool, &dimmingEnabled);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700248
249 uint32_t numRegions = 0;
250 SAFE_PARCEL(input.readUint32, &numRegions);
251 blurRegions.clear();
252 for (uint32_t i = 0; i < numRegions; i++) {
253 BlurRegion region;
254 SAFE_PARCEL(input.readUint32, &region.blurRadius);
255 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
256 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
257 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
258 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
259 SAFE_PARCEL(input.readFloat, &region.alpha);
260 SAFE_PARCEL(input.readInt32, &region.left);
261 SAFE_PARCEL(input.readInt32, &region.top);
262 SAFE_PARCEL(input.readInt32, &region.right);
263 SAFE_PARCEL(input.readInt32, &region.bottom);
264 blurRegions.push_back(region);
265 }
John Reckcdb4ed72021-02-04 13:39:33 -0500266
267 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500268 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700269 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700270 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500271
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700272 uint32_t mode;
273 SAFE_PARCEL(input.readUint32, &mode);
274 dropInputMode = static_cast<gui::DropInputMode>(mode);
Vishnu Nair685cfef2022-02-02 10:01:25 -0800275
276 bool hasBufferData;
277 SAFE_PARCEL(input.readBool, &hasBufferData);
278 if (hasBufferData) {
279 bufferData = std::make_shared<BufferData>();
280 SAFE_PARCEL(input.readParcelable, bufferData.get());
281 } else {
282 bufferData = nullptr;
283 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800284 return NO_ERROR;
285}
286
Mathias Agopian698c0872011-06-28 19:09:31 -0700287status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700288 return state.write(output);
289}
290
291status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700292 return state.read(input);
293}
294
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700295DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700296
Mathias Agopian8b33f032012-07-24 20:43:54 -0700297status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700298 SAFE_PARCEL(output.writeStrongBinder, token);
299 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
300 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700301 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700302 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700303 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
304 SAFE_PARCEL(output.write, layerStackSpaceRect);
305 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
306 SAFE_PARCEL(output.writeUint32, width);
307 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700308 return NO_ERROR;
309}
310
311status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700312 SAFE_PARCEL(input.readStrongBinder, &token);
313 sp<IBinder> tmpBinder;
314 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
315 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
316
317 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700318 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700319 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700320 uint32_t tmpUint = 0;
321 SAFE_PARCEL(input.readUint32, &tmpUint);
322 orientation = ui::toRotation(tmpUint);
323
324 SAFE_PARCEL(input.read, layerStackSpaceRect);
325 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
326 SAFE_PARCEL(input.readUint32, &width);
327 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700328 return NO_ERROR;
329}
330
Robert Carr2c5f6d22017-09-26 12:30:35 -0700331void DisplayState::merge(const DisplayState& other) {
332 if (other.what & eSurfaceChanged) {
333 what |= eSurfaceChanged;
334 surface = other.surface;
335 }
336 if (other.what & eLayerStackChanged) {
337 what |= eLayerStackChanged;
338 layerStack = other.layerStack;
339 }
Evan Rosky2239b372021-05-20 13:43:47 -0700340 if (other.what & eFlagsChanged) {
341 what |= eFlagsChanged;
342 flags = other.flags;
343 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700344 if (other.what & eDisplayProjectionChanged) {
345 what |= eDisplayProjectionChanged;
346 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200347 layerStackSpaceRect = other.layerStackSpaceRect;
348 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700349 }
350 if (other.what & eDisplaySizeChanged) {
351 what |= eDisplaySizeChanged;
352 width = other.width;
353 height = other.height;
354 }
355}
356
Robert Carrde6d7b42022-01-07 18:23:06 -0800357void layer_state_t::sanitize(int32_t permissions) {
358 // TODO: b/109894387
359 //
360 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
361 // rotation. To see the problem observe that if we have a square parent, and a child
362 // of the same size, then we rotate the child 45 degrees around its center, the child
363 // must now be cropped to a non rectangular 8 sided region.
364 //
365 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
366 // private API, and arbitrary rotation is used in limited use cases, for instance:
367 // - WindowManager only uses rotation in one case, which is on a top level layer in which
368 // cropping is not an issue.
369 // - Launcher, as a privileged app, uses this to transition an application to PiP
370 // (picture-in-picture) mode.
371 //
372 // However given that abuse of rotation matrices could lead to surfaces extending outside
373 // of cropped areas, we need to prevent non-root clients without permission
374 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
375 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
376 // preserving transformations.
377 if (what & eMatrixChanged) {
378 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
379 ui::Transform t;
380 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
381 if (!t.preserveRects()) {
382 what &= ~eMatrixChanged;
383 ALOGE("Stripped non rect preserving matrix in sanitize");
384 }
385 }
386 }
387
388 if (what & eFlagsChanged) {
389 if ((flags & eLayerIsDisplayDecoration) &&
390 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
391 flags &= ~eLayerIsDisplayDecoration;
392 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
393 }
394 }
395
396 if (what & layer_state_t::eInputInfoChanged) {
397 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
398 what &= ~eInputInfoChanged;
399 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
400 }
401 }
402 if (what & layer_state_t::eTrustedOverlayChanged) {
403 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
404 what &= ~eTrustedOverlayChanged;
405 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
406 }
407 }
408 if (what & layer_state_t::eDropInputModeChanged) {
409 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
410 what &= ~eDropInputModeChanged;
411 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
412 }
413 }
414 if (what & layer_state_t::eFrameRateSelectionPriority) {
415 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
416 what &= ~eFrameRateSelectionPriority;
417 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
418 }
419 }
420 if (what & layer_state_t::eFrameRateChanged) {
421 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
422 changeFrameRateStrategy,
423 "layer_state_t::sanitize",
424 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
425 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
426 }
427 }
428}
429
Robert Carr2c5f6d22017-09-26 12:30:35 -0700430void layer_state_t::merge(const layer_state_t& other) {
431 if (other.what & ePositionChanged) {
432 what |= ePositionChanged;
433 x = other.x;
434 y = other.y;
435 }
436 if (other.what & eLayerChanged) {
437 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700438 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700439 z = other.z;
440 }
441 if (other.what & eSizeChanged) {
442 what |= eSizeChanged;
443 w = other.w;
444 h = other.h;
445 }
446 if (other.what & eAlphaChanged) {
447 what |= eAlphaChanged;
448 alpha = other.alpha;
449 }
450 if (other.what & eMatrixChanged) {
451 what |= eMatrixChanged;
452 matrix = other.matrix;
453 }
454 if (other.what & eTransparentRegionChanged) {
455 what |= eTransparentRegionChanged;
456 transparentRegion = other.transparentRegion;
457 }
458 if (other.what & eFlagsChanged) {
459 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700460 flags &= ~other.mask;
461 flags |= (other.flags & other.mask);
462 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700463 }
464 if (other.what & eLayerStackChanged) {
465 what |= eLayerStackChanged;
466 layerStack = other.layerStack;
467 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700468 if (other.what & eCornerRadiusChanged) {
469 what |= eCornerRadiusChanged;
470 cornerRadius = other.cornerRadius;
471 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800472 if (other.what & eBackgroundBlurRadiusChanged) {
473 what |= eBackgroundBlurRadiusChanged;
474 backgroundBlurRadius = other.backgroundBlurRadius;
475 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700476 if (other.what & eBlurRegionsChanged) {
477 what |= eBlurRegionsChanged;
478 blurRegions = other.blurRegions;
479 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700480 if (other.what & eRelativeLayerChanged) {
481 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700482 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700483 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000484 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700485 }
486 if (other.what & eReparent) {
487 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000488 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700489 }
chaviwca27f252018-02-06 16:46:39 -0800490 if (other.what & eDestroySurface) {
491 what |= eDestroySurface;
492 }
Marissa Wall61c58622018-07-18 10:12:20 -0700493 if (other.what & eTransformChanged) {
494 what |= eTransformChanged;
495 transform = other.transform;
496 }
497 if (other.what & eTransformToDisplayInverseChanged) {
498 what |= eTransformToDisplayInverseChanged;
499 transformToDisplayInverse = other.transformToDisplayInverse;
500 }
501 if (other.what & eCropChanged) {
502 what |= eCropChanged;
503 crop = other.crop;
504 }
505 if (other.what & eBufferChanged) {
506 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500507 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700508 }
509 if (other.what & eDataspaceChanged) {
510 what |= eDataspaceChanged;
511 dataspace = other.dataspace;
512 }
513 if (other.what & eHdrMetadataChanged) {
514 what |= eHdrMetadataChanged;
515 hdrMetadata = other.hdrMetadata;
516 }
517 if (other.what & eSurfaceDamageRegionChanged) {
518 what |= eSurfaceDamageRegionChanged;
519 surfaceDamageRegion = other.surfaceDamageRegion;
520 }
521 if (other.what & eApiChanged) {
522 what |= eApiChanged;
523 api = other.api;
524 }
525 if (other.what & eSidebandStreamChanged) {
526 what |= eSidebandStreamChanged;
527 sidebandStream = other.sidebandStream;
528 }
Peiyong Lind3788632018-09-18 16:01:31 -0700529 if (other.what & eColorTransformChanged) {
530 what |= eColorTransformChanged;
531 colorTransform = other.colorTransform;
532 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700533 if (other.what & eHasListenerCallbacksChanged) {
534 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700535 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700536 if (other.what & eInputInfoChanged) {
537 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500538 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700539 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800540 if (other.what & eBackgroundColorChanged) {
541 what |= eBackgroundColorChanged;
542 color = other.color;
543 bgColorAlpha = other.bgColorAlpha;
544 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800545 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800546 if (other.what & eMetadataChanged) {
547 what |= eMetadataChanged;
548 metadata.merge(other.metadata);
549 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700550 if (other.what & eShadowRadiusChanged) {
551 what |= eShadowRadiusChanged;
552 shadowRadius = other.shadowRadius;
553 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100554 if (other.what & eFrameRateSelectionPriority) {
555 what |= eFrameRateSelectionPriority;
556 frameRateSelectionPriority = other.frameRateSelectionPriority;
557 }
Steven Thomas3172e202020-01-06 19:25:30 -0800558 if (other.what & eFrameRateChanged) {
559 what |= eFrameRateChanged;
560 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800561 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100562 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800563 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700564 if (other.what & eFixedTransformHintChanged) {
565 what |= eFixedTransformHintChanged;
566 fixedTransformHint = other.fixedTransformHint;
567 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800568 if (other.what & eAutoRefreshChanged) {
569 what |= eAutoRefreshChanged;
570 autoRefresh = other.autoRefresh;
571 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700572 if (other.what & eTrustedOverlayChanged) {
573 what |= eTrustedOverlayChanged;
574 isTrustedOverlay = other.isTrustedOverlay;
575 }
John Reckc00c6692021-02-16 11:37:33 -0500576 if (other.what & eStretchChanged) {
577 what |= eStretchChanged;
578 stretchEffect = other.stretchEffect;
579 }
chaviwf3f40fe2021-04-27 15:54:02 -0500580 if (other.what & eBufferCropChanged) {
581 what |= eBufferCropChanged;
582 bufferCrop = other.bufferCrop;
583 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700584 if (other.what & eDestinationFrameChanged) {
585 what |= eDestinationFrameChanged;
586 destinationFrame = other.destinationFrame;
587 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700588 if (other.what & eProducerDisconnect) {
589 what |= eProducerDisconnect;
590 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700591 if (other.what & eDropInputModeChanged) {
592 what |= eDropInputModeChanged;
593 dropInputMode = other.dropInputMode;
594 }
chaviw4c36cd82021-11-18 10:37:33 -0600595 if (other.what & eColorChanged) {
596 what |= eColorChanged;
597 color = other.color;
598 }
Arthur Hung91b346a2022-03-14 21:36:22 +0800599 if (other.what & eColorSpaceAgnosticChanged) {
600 what |= eColorSpaceAgnosticChanged;
601 colorSpaceAgnostic = other.colorSpaceAgnostic;
602 }
Sally Qi81d95e62022-03-21 19:41:33 -0700603 if (other.what & eDimmingEnabledChanged) {
604 what |= eDimmingEnabledChanged;
605 dimmingEnabled = other.dimmingEnabled;
606 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700607 if ((other.what & what) != other.what) {
608 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700609 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
610 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700611 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700612}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700613
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700614bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500615 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700616}
617
Ady Abraham6e8e3642021-07-08 19:44:07 -0700618bool layer_state_t::hasValidBuffer() const {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800619 return bufferData && (bufferData->buffer || bufferData->cachedBuffer.isValid());
Ady Abraham6e8e3642021-07-08 19:44:07 -0700620}
621
chaviw308ddba2020-08-11 16:23:51 -0700622status_t layer_state_t::matrix22_t::write(Parcel& output) const {
623 SAFE_PARCEL(output.writeFloat, dsdx);
624 SAFE_PARCEL(output.writeFloat, dtdx);
625 SAFE_PARCEL(output.writeFloat, dtdy);
626 SAFE_PARCEL(output.writeFloat, dsdy);
627 return NO_ERROR;
628}
629
630status_t layer_state_t::matrix22_t::read(const Parcel& input) {
631 SAFE_PARCEL(input.readFloat, &dsdx);
632 SAFE_PARCEL(input.readFloat, &dtdx);
633 SAFE_PARCEL(input.readFloat, &dtdy);
634 SAFE_PARCEL(input.readFloat, &dsdy);
635 return NO_ERROR;
636}
637
chaviw273171b2018-12-26 11:46:30 -0800638// ------------------------------- InputWindowCommands ----------------------------------------
639
Vishnu Naire798b472020-07-23 13:52:21 -0700640bool InputWindowCommands::merge(const InputWindowCommands& other) {
641 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700642 changes |= !other.focusRequests.empty();
643 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
644 std::make_move_iterator(other.focusRequests.end()));
Vishnu Naire798b472020-07-23 13:52:21 -0700645 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800646 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700647 return changes;
chaviw273171b2018-12-26 11:46:30 -0800648}
649
Vishnu Nair958da932020-08-21 17:12:37 -0700650bool InputWindowCommands::empty() const {
Vishnu Nair03ccbd62021-12-01 17:21:16 -0800651 return focusRequests.empty() && !syncInputWindows;
Vishnu Nair958da932020-08-21 17:12:37 -0700652}
653
chaviw273171b2018-12-26 11:46:30 -0800654void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700655 focusRequests.clear();
chaviwa911b102019-02-14 10:18:33 -0800656 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800657}
658
chaviw308ddba2020-08-11 16:23:51 -0700659status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700660 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700661 SAFE_PARCEL(output.writeBool, syncInputWindows);
662 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800663}
664
chaviw308ddba2020-08-11 16:23:51 -0700665status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700666 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700667 SAFE_PARCEL(input.readBool, &syncInputWindows);
668 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800669}
670
Marin Shalamanovc5986772021-03-16 16:09:49 +0100671bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
672 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800673 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
674 int floatClassification = std::fpclassify(frameRate);
675 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
676 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
677 return false;
678 }
679
680 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800681 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
682 (!privileged || compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT)) {
683 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
684 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800685 return false;
686 }
687
Marin Shalamanovc5986772021-03-16 16:09:49 +0100688 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
689 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
690 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
691 changeFrameRateStrategy);
692 }
693
Steven Thomas62a4cf82020-01-31 12:04:03 -0800694 return true;
695}
696
chaviw618c42d2020-07-24 15:25:08 -0700697// ----------------------------------------------------------------------------
698
Huihong Luo9e84f332021-12-16 14:33:46 -0800699namespace gui {
700
701status_t CaptureArgs::writeToParcel(Parcel* output) const {
702 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
703 SAFE_PARCEL(output->write, sourceCrop);
704 SAFE_PARCEL(output->writeFloat, frameScaleX);
705 SAFE_PARCEL(output->writeFloat, frameScaleY);
706 SAFE_PARCEL(output->writeBool, captureSecureLayers);
707 SAFE_PARCEL(output->writeInt32, uid);
708 SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
709 SAFE_PARCEL(output->writeBool, allowProtected);
710 SAFE_PARCEL(output->writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700711 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700712}
713
Huihong Luo9e84f332021-12-16 14:33:46 -0800714status_t CaptureArgs::readFromParcel(const Parcel* input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700715 int32_t value = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800716 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700717 pixelFormat = static_cast<ui::PixelFormat>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800718 SAFE_PARCEL(input->read, sourceCrop);
719 SAFE_PARCEL(input->readFloat, &frameScaleX);
720 SAFE_PARCEL(input->readFloat, &frameScaleY);
721 SAFE_PARCEL(input->readBool, &captureSecureLayers);
722 SAFE_PARCEL(input->readInt32, &uid);
723 SAFE_PARCEL(input->readInt32, &value);
Peiyong Lincd261472020-10-06 18:05:25 -0700724 dataspace = static_cast<ui::Dataspace>(value);
Huihong Luo9e84f332021-12-16 14:33:46 -0800725 SAFE_PARCEL(input->readBool, &allowProtected);
726 SAFE_PARCEL(input->readBool, &grayscale);
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::writeToParcel(Parcel* output) const {
731 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700732
Huihong Luo9e84f332021-12-16 14:33:46 -0800733 SAFE_PARCEL(output->writeStrongBinder, displayToken);
734 SAFE_PARCEL(output->writeUint32, width);
735 SAFE_PARCEL(output->writeUint32, height);
736 SAFE_PARCEL(output->writeBool, 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 DisplayCaptureArgs::readFromParcel(const Parcel* input) {
741 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700742
Huihong Luo9e84f332021-12-16 14:33:46 -0800743 SAFE_PARCEL(input->readStrongBinder, &displayToken);
744 SAFE_PARCEL(input->readUint32, &width);
745 SAFE_PARCEL(input->readUint32, &height);
746 SAFE_PARCEL(input->readBool, &useIdentityTransform);
chaviw308ddba2020-08-11 16:23:51 -0700747 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700748}
749
Huihong Luo9e84f332021-12-16 14:33:46 -0800750status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
751 SAFE_PARCEL(CaptureArgs::writeToParcel, output);
chaviw618c42d2020-07-24 15:25:08 -0700752
Huihong Luo9e84f332021-12-16 14:33:46 -0800753 SAFE_PARCEL(output->writeStrongBinder, layerHandle);
754 SAFE_PARCEL(output->writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700755 for (auto el : excludeHandles) {
Huihong Luo9e84f332021-12-16 14:33:46 -0800756 SAFE_PARCEL(output->writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700757 }
Huihong Luo9e84f332021-12-16 14:33:46 -0800758 SAFE_PARCEL(output->writeBool, childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700759 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700760}
761
Huihong Luo9e84f332021-12-16 14:33:46 -0800762status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
763 SAFE_PARCEL(CaptureArgs::readFromParcel, input);
chaviw618c42d2020-07-24 15:25:08 -0700764
Huihong Luo9e84f332021-12-16 14:33:46 -0800765 SAFE_PARCEL(input->readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700766
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700767 int32_t numExcludeHandles = 0;
Huihong Luo9e84f332021-12-16 14:33:46 -0800768 SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700769 excludeHandles.reserve(numExcludeHandles);
770 for (int i = 0; i < numExcludeHandles; i++) {
771 sp<IBinder> binder;
Huihong Luo9e84f332021-12-16 14:33:46 -0800772 SAFE_PARCEL(input->readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700773 excludeHandles.emplace(binder);
774 }
775
Huihong Luo9e84f332021-12-16 14:33:46 -0800776 SAFE_PARCEL(input->readBool, &childrenOnly);
chaviw308ddba2020-08-11 16:23:51 -0700777 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700778}
779
Huihong Luo9e84f332021-12-16 14:33:46 -0800780}; // namespace gui
781
chaviw8dd181f2022-01-05 18:36:46 -0600782ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
chaviwdcba9e02022-03-21 17:54:23 -0500783 uint64_t bufferId;
784 if (buffer) {
785 bufferId = buffer->getId();
786 } else {
787 bufferId = cachedBuffer.id;
788 }
789 return {bufferId, frameNumber};
chaviw8dd181f2022-01-05 18:36:46 -0600790}
791
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800792status_t BufferData::writeToParcel(Parcel* output) const {
793 SAFE_PARCEL(output->writeInt32, flags.get());
chaviwba4320c2021-09-15 15:20:53 -0500794
795 if (buffer) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800796 SAFE_PARCEL(output->writeBool, true);
797 SAFE_PARCEL(output->write, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500798 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800799 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500800 }
801
802 if (acquireFence) {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800803 SAFE_PARCEL(output->writeBool, true);
804 SAFE_PARCEL(output->write, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500805 } else {
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800806 SAFE_PARCEL(output->writeBool, false);
chaviwba4320c2021-09-15 15:20:53 -0500807 }
808
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800809 SAFE_PARCEL(output->writeUint64, frameNumber);
810 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
811 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500812
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800813 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
814 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
Robert Carr79dc06a2022-02-22 15:28:59 -0800815 SAFE_PARCEL(output->writeBool, hasBarrier);
816 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500817
818 return NO_ERROR;
819}
820
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800821status_t BufferData::readFromParcel(const Parcel* input) {
chaviwba4320c2021-09-15 15:20:53 -0500822 int32_t tmpInt32;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800823 SAFE_PARCEL(input->readInt32, &tmpInt32);
chaviwba4320c2021-09-15 15:20:53 -0500824 flags = Flags<BufferDataChange>(tmpInt32);
825
826 bool tmpBool = false;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800827 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500828 if (tmpBool) {
829 buffer = new GraphicBuffer();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800830 SAFE_PARCEL(input->read, *buffer);
chaviwba4320c2021-09-15 15:20:53 -0500831 }
832
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800833 SAFE_PARCEL(input->readBool, &tmpBool);
chaviwba4320c2021-09-15 15:20:53 -0500834 if (tmpBool) {
835 acquireFence = new Fence();
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800836 SAFE_PARCEL(input->read, *acquireFence);
chaviwba4320c2021-09-15 15:20:53 -0500837 }
838
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800839 SAFE_PARCEL(input->readUint64, &frameNumber);
chaviwba4320c2021-09-15 15:20:53 -0500840
841 sp<IBinder> tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800842 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500843 if (tmpBinder) {
844 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
845 }
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800846 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
chaviwba4320c2021-09-15 15:20:53 -0500847
848 tmpBinder = nullptr;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800849 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
chaviwba4320c2021-09-15 15:20:53 -0500850 cachedBuffer.token = tmpBinder;
Vishnu Nair9f0835e2022-01-07 09:33:19 -0800851 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
chaviwba4320c2021-09-15 15:20:53 -0500852
Robert Carr79dc06a2022-02-22 15:28:59 -0800853 SAFE_PARCEL(input->readBool, &hasBarrier);
854 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
855
chaviwba4320c2021-09-15 15:20:53 -0500856 return NO_ERROR;
857}
858
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800859}; // namespace android