1 /*
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
17 #define LOG_TAG "LayerState"
18
19 #include <cinttypes>
20
21 #include <android/gui/ISurfaceComposerClient.h>
22 #include <android/native_window.h>
23 #include <binder/Parcel.h>
24 #include <com_android_graphics_libgui_flags.h>
25 #include <gui/FrameRateUtils.h>
26 #include <gui/IGraphicBufferProducer.h>
27 #include <gui/LayerState.h>
28 #include <gui/SurfaceControl.h>
29 #include <private/gui/ParcelUtils.h>
30 #include <system/window.h>
31 #include <utils/Errors.h>
32
33 #define CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD) \
34 { \
35 if ((OTHER.what & CHANGE_FLAG) && (FIELD != OTHER.FIELD)) { \
36 DIFF_RESULT |= CHANGE_FLAG; \
37 } \
38 }
39
40 #define CHECK_DIFF2(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2) \
41 { \
42 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1) \
43 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2) \
44 }
45
46 #define CHECK_DIFF3(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2, FIELD3) \
47 { \
48 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1) \
49 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2) \
50 CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD3) \
51 }
52
53 namespace android {
54
55 using gui::FocusRequest;
56 using gui::WindowInfoHandle;
57
layer_state_t()58 layer_state_t::layer_state_t()
59 : surface(nullptr),
60 layerId(-1),
61 what(0),
62 x(0),
63 y(0),
64 z(0),
65 flags(0),
66 mask(0),
67 reserved(0),
68 cornerRadius(0.0f),
69 backgroundBlurRadius(0),
70 color(0),
71 bufferTransform(0),
72 transformToDisplayInverse(false),
73 crop({0, 0, -1, -1}),
74 dataspace(ui::Dataspace::UNKNOWN),
75 surfaceDamageRegion(),
76 api(-1),
77 colorTransform(mat4()),
78 bgColor(0),
79 bgColorDataspace(ui::Dataspace::UNKNOWN),
80 colorSpaceAgnostic(false),
81 shadowRadius(0.0f),
82 frameRateSelectionPriority(-1),
83 frameRate(0.0f),
84 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
85 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
86 defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
87 frameRateCategory(ANATIVEWINDOW_FRAME_RATE_CATEGORY_DEFAULT),
88 frameRateCategorySmoothSwitchOnly(false),
89 frameRateSelectionStrategy(ANATIVEWINDOW_FRAME_RATE_SELECTION_STRATEGY_PROPAGATE),
90 fixedTransformHint(ui::Transform::ROT_INVALID),
91 autoRefresh(false),
92 trustedOverlay(gui::TrustedOverlay::UNSET),
93 bufferCrop(Rect::INVALID_RECT),
94 destinationFrame(Rect::INVALID_RECT),
95 dropInputMode(gui::DropInputMode::NONE),
96 pictureProfileHandle(PictureProfileHandle::NONE),
97 appContentPriority(0) {
98 matrix.dsdx = matrix.dtdy = 1.0f;
99 matrix.dsdy = matrix.dtdx = 0.0f;
100 hdrMetadata.validTypes = 0;
101 }
102
write(Parcel & output) const103 status_t layer_state_t::write(Parcel& output) const
104 {
105 SAFE_PARCEL(output.writeStrongBinder, surface);
106 SAFE_PARCEL(output.writeInt32, layerId);
107 SAFE_PARCEL(output.writeUint64, what);
108 SAFE_PARCEL(output.writeFloat, x);
109 SAFE_PARCEL(output.writeFloat, y);
110 SAFE_PARCEL(output.writeInt32, z);
111 SAFE_PARCEL(output.writeUint32, layerStack.id);
112 SAFE_PARCEL(output.writeUint32, flags);
113 SAFE_PARCEL(output.writeUint32, mask);
114 SAFE_PARCEL(matrix.write, output);
115 SAFE_PARCEL(output.writeFloat, crop.top);
116 SAFE_PARCEL(output.writeFloat, crop.left);
117 SAFE_PARCEL(output.writeFloat, crop.bottom);
118 SAFE_PARCEL(output.writeFloat, crop.right);
119 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
120 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
121 SAFE_PARCEL(output.writeFloat, color.r);
122 SAFE_PARCEL(output.writeFloat, color.g);
123 SAFE_PARCEL(output.writeFloat, color.b);
124 SAFE_PARCEL(output.writeFloat, color.a);
125 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
126 SAFE_PARCEL(output.write, transparentRegion);
127 SAFE_PARCEL(output.writeUint32, bufferTransform);
128 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
129 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
130 SAFE_PARCEL(output.write, hdrMetadata);
131 SAFE_PARCEL(output.write, surfaceDamageRegion);
132 SAFE_PARCEL(output.writeInt32, api);
133
134 if (sidebandStream) {
135 SAFE_PARCEL(output.writeBool, true);
136 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
137 } else {
138 SAFE_PARCEL(output.writeBool, false);
139 }
140
141 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
142 SAFE_PARCEL(output.writeFloat, cornerRadius);
143 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
144 SAFE_PARCEL(output.writeParcelable, metadata);
145 SAFE_PARCEL(output.writeFloat, bgColor.r);
146 SAFE_PARCEL(output.writeFloat, bgColor.g);
147 SAFE_PARCEL(output.writeFloat, bgColor.b);
148 SAFE_PARCEL(output.writeFloat, bgColor.a);
149 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
150 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
151 SAFE_PARCEL(output.writeVectorSize, listeners);
152
153 for (auto listener : listeners) {
154 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
155 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
156 }
157 SAFE_PARCEL(output.writeFloat, shadowRadius);
158 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
159 SAFE_PARCEL(output.writeFloat, frameRate);
160 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
161 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
162 SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
163 SAFE_PARCEL(output.writeByte, frameRateCategory);
164 SAFE_PARCEL(output.writeBool, frameRateCategorySmoothSwitchOnly);
165 SAFE_PARCEL(output.writeByte, frameRateSelectionStrategy);
166 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
167 SAFE_PARCEL(output.writeBool, autoRefresh);
168 SAFE_PARCEL(output.writeBool, dimmingEnabled);
169
170 SAFE_PARCEL(output.writeUint32, blurRegions.size());
171 for (auto region : blurRegions) {
172 SAFE_PARCEL(output.writeUint32, region.blurRadius);
173 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
174 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
175 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
176 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
177 SAFE_PARCEL(output.writeFloat, region.alpha);
178 SAFE_PARCEL(output.writeInt32, region.left);
179 SAFE_PARCEL(output.writeInt32, region.top);
180 SAFE_PARCEL(output.writeInt32, region.right);
181 SAFE_PARCEL(output.writeInt32, region.bottom);
182 }
183
184 SAFE_PARCEL(output.write, stretchEffect);
185 SAFE_PARCEL(output.writeParcelable, edgeExtensionParameters);
186 SAFE_PARCEL(output.write, bufferCrop);
187 SAFE_PARCEL(output.write, destinationFrame);
188 SAFE_PARCEL(output.writeInt32, static_cast<uint32_t>(trustedOverlay));
189
190 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
191
192 const bool hasBufferData = (bufferData != nullptr);
193 SAFE_PARCEL(output.writeBool, hasBufferData);
194 if (hasBufferData) {
195 SAFE_PARCEL(output.writeParcelable, *bufferData);
196 }
197 SAFE_PARCEL(output.writeParcelable, trustedPresentationThresholds);
198 SAFE_PARCEL(output.writeParcelable, trustedPresentationListener);
199 SAFE_PARCEL(output.writeFloat, currentHdrSdrRatio);
200 SAFE_PARCEL(output.writeFloat, desiredHdrSdrRatio);
201 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(cachingHint));
202
203 const bool hasBufferReleaseChannel = (bufferReleaseChannel != nullptr);
204 SAFE_PARCEL(output.writeBool, hasBufferReleaseChannel);
205 if (hasBufferReleaseChannel) {
206 SAFE_PARCEL(output.writeParcelable, *bufferReleaseChannel);
207 }
208 #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
209 SAFE_PARCEL(output.writeInt64, pictureProfileHandle.getId());
210 SAFE_PARCEL(output.writeInt32, appContentPriority);
211 #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
212
213 const bool hasLuts = (luts != nullptr);
214 SAFE_PARCEL(output.writeBool, hasLuts);
215 if (hasLuts) {
216 SAFE_PARCEL(output.writeParcelable, *luts);
217 }
218
219 return NO_ERROR;
220 }
221
read(const Parcel & input)222 status_t layer_state_t::read(const Parcel& input)
223 {
224 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
225 SAFE_PARCEL(input.readInt32, &layerId);
226 SAFE_PARCEL(input.readUint64, &what);
227 SAFE_PARCEL(input.readFloat, &x);
228 SAFE_PARCEL(input.readFloat, &y);
229 SAFE_PARCEL(input.readInt32, &z);
230 SAFE_PARCEL(input.readUint32, &layerStack.id);
231
232 SAFE_PARCEL(input.readUint32, &flags);
233
234 SAFE_PARCEL(input.readUint32, &mask);
235
236 SAFE_PARCEL(matrix.read, input);
237 SAFE_PARCEL(input.readFloat, &crop.top);
238 SAFE_PARCEL(input.readFloat, &crop.left);
239 SAFE_PARCEL(input.readFloat, &crop.bottom);
240 SAFE_PARCEL(input.readFloat, &crop.right);
241
242 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
243 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
244
245 float tmpFloat = 0;
246 SAFE_PARCEL(input.readFloat, &tmpFloat);
247 color.r = tmpFloat;
248 SAFE_PARCEL(input.readFloat, &tmpFloat);
249 color.g = tmpFloat;
250 SAFE_PARCEL(input.readFloat, &tmpFloat);
251 color.b = tmpFloat;
252 SAFE_PARCEL(input.readFloat, &tmpFloat);
253 color.a = tmpFloat;
254
255 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
256
257 SAFE_PARCEL(input.read, transparentRegion);
258 SAFE_PARCEL(input.readUint32, &bufferTransform);
259 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
260
261 uint32_t tmpUint32 = 0;
262 SAFE_PARCEL(input.readUint32, &tmpUint32);
263 dataspace = static_cast<ui::Dataspace>(tmpUint32);
264
265 SAFE_PARCEL(input.read, hdrMetadata);
266 SAFE_PARCEL(input.read, surfaceDamageRegion);
267 SAFE_PARCEL(input.readInt32, &api);
268
269 bool tmpBool = false;
270 SAFE_PARCEL(input.readBool, &tmpBool);
271 if (tmpBool) {
272 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
273 }
274
275 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
276 SAFE_PARCEL(input.readFloat, &cornerRadius);
277 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
278 SAFE_PARCEL(input.readParcelable, &metadata);
279
280 SAFE_PARCEL(input.readFloat, &tmpFloat);
281 bgColor.r = tmpFloat;
282 SAFE_PARCEL(input.readFloat, &tmpFloat);
283 bgColor.g = tmpFloat;
284 SAFE_PARCEL(input.readFloat, &tmpFloat);
285 bgColor.b = tmpFloat;
286 SAFE_PARCEL(input.readFloat, &tmpFloat);
287 bgColor.a = tmpFloat;
288 SAFE_PARCEL(input.readUint32, &tmpUint32);
289 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
290 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
291
292 int32_t numListeners = 0;
293 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
294 listeners.clear();
295 for (int i = 0; i < numListeners; i++) {
296 sp<IBinder> listener;
297 std::vector<CallbackId> callbackIds;
298 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
299 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
300 listeners.emplace_back(listener, callbackIds);
301 }
302 SAFE_PARCEL(input.readFloat, &shadowRadius);
303 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
304 SAFE_PARCEL(input.readFloat, &frameRate);
305 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
306 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
307 SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
308 SAFE_PARCEL(input.readByte, &frameRateCategory);
309 SAFE_PARCEL(input.readBool, &frameRateCategorySmoothSwitchOnly);
310 SAFE_PARCEL(input.readByte, &frameRateSelectionStrategy);
311 SAFE_PARCEL(input.readUint32, &tmpUint32);
312 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
313 SAFE_PARCEL(input.readBool, &autoRefresh);
314 SAFE_PARCEL(input.readBool, &dimmingEnabled);
315
316 uint32_t numRegions = 0;
317 SAFE_PARCEL(input.readUint32, &numRegions);
318 blurRegions.clear();
319 for (uint32_t i = 0; i < numRegions; i++) {
320 BlurRegion region;
321 SAFE_PARCEL(input.readUint32, ®ion.blurRadius);
322 SAFE_PARCEL(input.readFloat, ®ion.cornerRadiusTL);
323 SAFE_PARCEL(input.readFloat, ®ion.cornerRadiusTR);
324 SAFE_PARCEL(input.readFloat, ®ion.cornerRadiusBL);
325 SAFE_PARCEL(input.readFloat, ®ion.cornerRadiusBR);
326 SAFE_PARCEL(input.readFloat, ®ion.alpha);
327 SAFE_PARCEL(input.readInt32, ®ion.left);
328 SAFE_PARCEL(input.readInt32, ®ion.top);
329 SAFE_PARCEL(input.readInt32, ®ion.right);
330 SAFE_PARCEL(input.readInt32, ®ion.bottom);
331 blurRegions.push_back(region);
332 }
333
334 SAFE_PARCEL(input.read, stretchEffect);
335 SAFE_PARCEL(input.readParcelable, &edgeExtensionParameters);
336 SAFE_PARCEL(input.read, bufferCrop);
337 SAFE_PARCEL(input.read, destinationFrame);
338 uint32_t trustedOverlayInt;
339 SAFE_PARCEL(input.readUint32, &trustedOverlayInt);
340 trustedOverlay = static_cast<gui::TrustedOverlay>(trustedOverlayInt);
341
342 uint32_t mode;
343 SAFE_PARCEL(input.readUint32, &mode);
344 dropInputMode = static_cast<gui::DropInputMode>(mode);
345
346 bool hasBufferData;
347 SAFE_PARCEL(input.readBool, &hasBufferData);
348 if (hasBufferData) {
349 bufferData = std::make_shared<BufferData>();
350 SAFE_PARCEL(input.readParcelable, bufferData.get());
351 } else {
352 bufferData = nullptr;
353 }
354
355 SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
356 SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
357
358 SAFE_PARCEL(input.readFloat, &tmpFloat);
359 currentHdrSdrRatio = tmpFloat;
360 SAFE_PARCEL(input.readFloat, &tmpFloat);
361 desiredHdrSdrRatio = tmpFloat;
362
363 int32_t tmpInt32;
364 SAFE_PARCEL(input.readInt32, &tmpInt32);
365 cachingHint = static_cast<gui::CachingHint>(tmpInt32);
366
367 bool hasBufferReleaseChannel;
368 SAFE_PARCEL(input.readBool, &hasBufferReleaseChannel);
369 if (hasBufferReleaseChannel) {
370 bufferReleaseChannel = std::make_shared<gui::BufferReleaseChannel::ProducerEndpoint>();
371 SAFE_PARCEL(input.readParcelable, bufferReleaseChannel.get());
372 }
373 #if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
374 int64_t pictureProfileId;
375 SAFE_PARCEL(input.readInt64, &pictureProfileId);
376 pictureProfileHandle = PictureProfileHandle(pictureProfileId);
377 SAFE_PARCEL(input.readInt32, &appContentPriority);
378 #endif // COM_ANDROID_GRAPHICS_LIBGUI_FLAGS_APPLY_PICTURE_PROFILES
379
380 bool hasLuts;
381 SAFE_PARCEL(input.readBool, &hasLuts);
382 if (hasLuts) {
383 luts = std::make_shared<gui::DisplayLuts>();
384 SAFE_PARCEL(input.readParcelable, luts.get());
385 } else {
386 luts = nullptr;
387 }
388
389 return NO_ERROR;
390 }
391
write(Parcel & output) const392 status_t ComposerState::write(Parcel& output) const {
393 return state.write(output);
394 }
395
read(const Parcel & input)396 status_t ComposerState::read(const Parcel& input) {
397 return state.read(input);
398 }
399
400 DisplayState::DisplayState() = default;
401
write(Parcel & output) const402 status_t DisplayState::write(Parcel& output) const {
403 SAFE_PARCEL(output.writeStrongBinder, token);
404 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
405 SAFE_PARCEL(output.writeUint32, what);
406 SAFE_PARCEL(output.writeUint32, flags);
407 SAFE_PARCEL(output.writeUint32, layerStack.id);
408 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
409 SAFE_PARCEL(output.write, layerStackSpaceRect);
410 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
411 SAFE_PARCEL(output.writeUint32, width);
412 SAFE_PARCEL(output.writeUint32, height);
413 return NO_ERROR;
414 }
415
read(const Parcel & input)416 status_t DisplayState::read(const Parcel& input) {
417 SAFE_PARCEL(input.readStrongBinder, &token);
418 sp<IBinder> tmpBinder;
419 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
420 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
421
422 SAFE_PARCEL(input.readUint32, &what);
423 SAFE_PARCEL(input.readUint32, &flags);
424 SAFE_PARCEL(input.readUint32, &layerStack.id);
425 uint32_t tmpUint = 0;
426 SAFE_PARCEL(input.readUint32, &tmpUint);
427 orientation = ui::toRotation(tmpUint);
428
429 SAFE_PARCEL(input.read, layerStackSpaceRect);
430 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
431 SAFE_PARCEL(input.readUint32, &width);
432 SAFE_PARCEL(input.readUint32, &height);
433 return NO_ERROR;
434 }
435
merge(const DisplayState & other)436 void DisplayState::merge(const DisplayState& other) {
437 if (other.what & eSurfaceChanged) {
438 what |= eSurfaceChanged;
439 surface = other.surface;
440 }
441 if (other.what & eLayerStackChanged) {
442 what |= eLayerStackChanged;
443 layerStack = other.layerStack;
444 }
445 if (other.what & eFlagsChanged) {
446 what |= eFlagsChanged;
447 flags = other.flags;
448 }
449 if (other.what & eDisplayProjectionChanged) {
450 what |= eDisplayProjectionChanged;
451 orientation = other.orientation;
452 layerStackSpaceRect = other.layerStackSpaceRect;
453 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
454 }
455 if (other.what & eDisplaySizeChanged) {
456 what |= eDisplaySizeChanged;
457 width = other.width;
458 height = other.height;
459 }
460 }
461
sanitize(int32_t permissions)462 void DisplayState::sanitize(int32_t permissions) {
463 if (what & DisplayState::eLayerStackChanged) {
464 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
465 what &= ~DisplayState::eLayerStackChanged;
466 ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
467 }
468 }
469 if (what & DisplayState::eDisplayProjectionChanged) {
470 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
471 what &= ~DisplayState::eDisplayProjectionChanged;
472 ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
473 }
474 }
475 if (what & DisplayState::eSurfaceChanged) {
476 if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
477 what &= ~DisplayState::eSurfaceChanged;
478 ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
479 }
480 }
481 }
482
sanitize(int32_t permissions)483 void layer_state_t::sanitize(int32_t permissions) {
484 // TODO: b/109894387
485 //
486 // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
487 // rotation. To see the problem observe that if we have a square parent, and a child
488 // of the same size, then we rotate the child 45 degrees around its center, the child
489 // must now be cropped to a non rectangular 8 sided region.
490 //
491 // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
492 // private API, and arbitrary rotation is used in limited use cases, for instance:
493 // - WindowManager only uses rotation in one case, which is on a top level layer in which
494 // cropping is not an issue.
495 // - Launcher, as a privileged app, uses this to transition an application to PiP
496 // (picture-in-picture) mode.
497 //
498 // However given that abuse of rotation matrices could lead to surfaces extending outside
499 // of cropped areas, we need to prevent non-root clients without permission
500 // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
501 // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
502 // preserving transformations.
503 if (what & eMatrixChanged) {
504 if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
505 ui::Transform t;
506 t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
507 if (!t.preserveRects()) {
508 what &= ~eMatrixChanged;
509 ALOGE("Stripped non rect preserving matrix in sanitize");
510 }
511 }
512 }
513
514 if (what & eFlagsChanged) {
515 if ((flags & eLayerIsDisplayDecoration) &&
516 !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
517 flags &= ~eLayerIsDisplayDecoration;
518 ALOGE("Stripped attempt to set LayerIsDisplayDecoration in sanitize");
519 }
520 if ((mask & eCanOccludePresentation) &&
521 !(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
522 flags &= ~eCanOccludePresentation;
523 mask &= ~eCanOccludePresentation;
524 ALOGE("Stripped attempt to set eCanOccludePresentation in sanitize");
525 }
526 }
527
528 if (what & layer_state_t::eInputInfoChanged) {
529 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
530 what &= ~eInputInfoChanged;
531 ALOGE("Stripped attempt to set eInputInfoChanged in sanitize");
532 }
533 }
534 if (what & layer_state_t::eTrustedOverlayChanged) {
535 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
536 what &= ~eTrustedOverlayChanged;
537 ALOGE("Stripped attempt to set eTrustedOverlay in sanitize");
538 }
539 }
540 if (what & layer_state_t::eDropInputModeChanged) {
541 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
542 what &= ~eDropInputModeChanged;
543 ALOGE("Stripped attempt to set eDropInputModeChanged in sanitize");
544 }
545 }
546 if (what & layer_state_t::eFrameRateSelectionPriority) {
547 if (!(permissions & Permission::ACCESS_SURFACE_FLINGER)) {
548 what &= ~eFrameRateSelectionPriority;
549 ALOGE("Stripped attempt to set eFrameRateSelectionPriority in sanitize");
550 }
551 }
552 if (what & layer_state_t::eFrameRateChanged) {
553 if (!ValidateFrameRate(frameRate, frameRateCompatibility,
554 changeFrameRateStrategy,
555 "layer_state_t::sanitize",
556 permissions & Permission::ACCESS_SURFACE_FLINGER)) {
557 what &= ~eFrameRateChanged; // logged in ValidateFrameRate
558 }
559 }
560 }
561
merge(const layer_state_t & other)562 void layer_state_t::merge(const layer_state_t& other) {
563 if (other.what & ePositionChanged) {
564 what |= ePositionChanged;
565 x = other.x;
566 y = other.y;
567 }
568 if (other.what & eLayerChanged) {
569 what |= eLayerChanged;
570 what &= ~eRelativeLayerChanged;
571 z = other.z;
572 }
573 if (other.what & eAlphaChanged) {
574 what |= eAlphaChanged;
575 color.a = other.color.a;
576 }
577 if (other.what & eMatrixChanged) {
578 what |= eMatrixChanged;
579 matrix = other.matrix;
580 }
581 if (other.what & eTransparentRegionChanged) {
582 what |= eTransparentRegionChanged;
583 transparentRegion = other.transparentRegion;
584 }
585 if (other.what & eFlagsChanged) {
586 what |= eFlagsChanged;
587 flags &= ~other.mask;
588 flags |= (other.flags & other.mask);
589 mask |= other.mask;
590 }
591 if (other.what & eLayerStackChanged) {
592 what |= eLayerStackChanged;
593 layerStack = other.layerStack;
594 }
595 if (other.what & eCornerRadiusChanged) {
596 what |= eCornerRadiusChanged;
597 cornerRadius = other.cornerRadius;
598 }
599 if (other.what & eBackgroundBlurRadiusChanged) {
600 what |= eBackgroundBlurRadiusChanged;
601 backgroundBlurRadius = other.backgroundBlurRadius;
602 }
603 if (other.what & eBlurRegionsChanged) {
604 what |= eBlurRegionsChanged;
605 blurRegions = other.blurRegions;
606 }
607 if (other.what & eRelativeLayerChanged) {
608 what |= eRelativeLayerChanged;
609 what &= ~eLayerChanged;
610 z = other.z;
611 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
612 }
613 if (other.what & eReparent) {
614 what |= eReparent;
615 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
616 }
617 if (other.what & eBufferTransformChanged) {
618 what |= eBufferTransformChanged;
619 bufferTransform = other.bufferTransform;
620 }
621 if (other.what & eTransformToDisplayInverseChanged) {
622 what |= eTransformToDisplayInverseChanged;
623 transformToDisplayInverse = other.transformToDisplayInverse;
624 }
625 if (other.what & eCropChanged) {
626 what |= eCropChanged;
627 crop = other.crop;
628 }
629 if (other.what & eBufferChanged) {
630 what |= eBufferChanged;
631 bufferData = other.bufferData;
632 }
633 if (other.what & eTrustedPresentationInfoChanged) {
634 what |= eTrustedPresentationInfoChanged;
635 trustedPresentationListener = other.trustedPresentationListener;
636 trustedPresentationThresholds = other.trustedPresentationThresholds;
637 }
638 if (other.what & eDataspaceChanged) {
639 what |= eDataspaceChanged;
640 dataspace = other.dataspace;
641 }
642 if (other.what & eExtendedRangeBrightnessChanged) {
643 what |= eExtendedRangeBrightnessChanged;
644 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
645 currentHdrSdrRatio = other.currentHdrSdrRatio;
646 }
647 if (other.what & eDesiredHdrHeadroomChanged) {
648 what |= eDesiredHdrHeadroomChanged;
649 desiredHdrSdrRatio = other.desiredHdrSdrRatio;
650 }
651 if (other.what & eCachingHintChanged) {
652 what |= eCachingHintChanged;
653 cachingHint = other.cachingHint;
654 }
655 if (other.what & eHdrMetadataChanged) {
656 what |= eHdrMetadataChanged;
657 hdrMetadata = other.hdrMetadata;
658 }
659 if (other.what & eSurfaceDamageRegionChanged) {
660 what |= eSurfaceDamageRegionChanged;
661 surfaceDamageRegion = other.surfaceDamageRegion;
662 }
663 if (other.what & eApiChanged) {
664 what |= eApiChanged;
665 api = other.api;
666 }
667 if (other.what & eSidebandStreamChanged) {
668 what |= eSidebandStreamChanged;
669 sidebandStream = other.sidebandStream;
670 }
671 if (other.what & eColorTransformChanged) {
672 what |= eColorTransformChanged;
673 colorTransform = other.colorTransform;
674 }
675 if (other.what & eHasListenerCallbacksChanged) {
676 what |= eHasListenerCallbacksChanged;
677 }
678 if (other.what & eInputInfoChanged) {
679 what |= eInputInfoChanged;
680 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
681 }
682 if (other.what & eBackgroundColorChanged) {
683 what |= eBackgroundColorChanged;
684 bgColor = other.bgColor;
685 bgColorDataspace = other.bgColorDataspace;
686 }
687 if (other.what & eMetadataChanged) {
688 what |= eMetadataChanged;
689 metadata.merge(other.metadata);
690 }
691 if (other.what & eShadowRadiusChanged) {
692 what |= eShadowRadiusChanged;
693 shadowRadius = other.shadowRadius;
694 }
695 if (other.what & eLutsChanged) {
696 what |= eLutsChanged;
697 luts = other.luts;
698 }
699 if (other.what & eDefaultFrameRateCompatibilityChanged) {
700 what |= eDefaultFrameRateCompatibilityChanged;
701 defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
702 }
703 if (other.what & eFrameRateSelectionPriority) {
704 what |= eFrameRateSelectionPriority;
705 frameRateSelectionPriority = other.frameRateSelectionPriority;
706 }
707 if (other.what & eFrameRateChanged) {
708 what |= eFrameRateChanged;
709 frameRate = other.frameRate;
710 frameRateCompatibility = other.frameRateCompatibility;
711 changeFrameRateStrategy = other.changeFrameRateStrategy;
712 }
713 if (other.what & eFrameRateCategoryChanged) {
714 what |= eFrameRateCategoryChanged;
715 frameRateCategory = other.frameRateCategory;
716 frameRateCategorySmoothSwitchOnly = other.frameRateCategorySmoothSwitchOnly;
717 }
718 if (other.what & eFrameRateSelectionStrategyChanged) {
719 what |= eFrameRateSelectionStrategyChanged;
720 frameRateSelectionStrategy = other.frameRateSelectionStrategy;
721 }
722 if (other.what & eFixedTransformHintChanged) {
723 what |= eFixedTransformHintChanged;
724 fixedTransformHint = other.fixedTransformHint;
725 }
726 if (other.what & eAutoRefreshChanged) {
727 what |= eAutoRefreshChanged;
728 autoRefresh = other.autoRefresh;
729 }
730 if (other.what & eTrustedOverlayChanged) {
731 what |= eTrustedOverlayChanged;
732 trustedOverlay = other.trustedOverlay;
733 }
734 if (other.what & eStretchChanged) {
735 what |= eStretchChanged;
736 stretchEffect = other.stretchEffect;
737 }
738 if (other.what & eEdgeExtensionChanged) {
739 what |= eEdgeExtensionChanged;
740 edgeExtensionParameters = other.edgeExtensionParameters;
741 }
742 if (other.what & eBufferCropChanged) {
743 what |= eBufferCropChanged;
744 bufferCrop = other.bufferCrop;
745 }
746 if (other.what & eDestinationFrameChanged) {
747 what |= eDestinationFrameChanged;
748 destinationFrame = other.destinationFrame;
749 }
750 if (other.what & eProducerDisconnect) {
751 what |= eProducerDisconnect;
752 }
753 if (other.what & eDropInputModeChanged) {
754 what |= eDropInputModeChanged;
755 dropInputMode = other.dropInputMode;
756 }
757 if (other.what & eColorChanged) {
758 what |= eColorChanged;
759 color.rgb = other.color.rgb;
760 }
761 if (other.what & eColorSpaceAgnosticChanged) {
762 what |= eColorSpaceAgnosticChanged;
763 colorSpaceAgnostic = other.colorSpaceAgnostic;
764 }
765 if (other.what & eDimmingEnabledChanged) {
766 what |= eDimmingEnabledChanged;
767 dimmingEnabled = other.dimmingEnabled;
768 }
769 if (other.what & eFlushJankData) {
770 what |= eFlushJankData;
771 }
772 if (other.what & eBufferReleaseChannelChanged) {
773 what |= eBufferReleaseChannelChanged;
774 bufferReleaseChannel = other.bufferReleaseChannel;
775 }
776 if (com_android_graphics_libgui_flags_apply_picture_profiles()) {
777 if (other.what & ePictureProfileHandleChanged) {
778 what |= ePictureProfileHandleChanged;
779 pictureProfileHandle = other.pictureProfileHandle;
780 }
781 if (other.what & eAppContentPriorityChanged) {
782 what |= eAppContentPriorityChanged;
783 appContentPriority = other.appContentPriority;
784 }
785 }
786 if ((other.what & what) != other.what) {
787 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
788 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
789 other.what, what, (other.what & what) ^ other.what);
790 }
791 }
792
diff(const layer_state_t & other) const793 uint64_t layer_state_t::diff(const layer_state_t& other) const {
794 uint64_t diff = 0;
795 CHECK_DIFF2(diff, ePositionChanged, other, x, y);
796 if (other.what & eLayerChanged) {
797 diff |= eLayerChanged;
798 diff &= ~eRelativeLayerChanged;
799 }
800 CHECK_DIFF(diff, eAlphaChanged, other, color.a);
801 CHECK_DIFF(diff, eMatrixChanged, other, matrix);
802 if (other.what & eTransparentRegionChanged &&
803 (!transparentRegion.hasSameRects(other.transparentRegion))) {
804 diff |= eTransparentRegionChanged;
805 }
806 if (other.what & eFlagsChanged) {
807 uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
808 if (changedFlags) diff |= eFlagsChanged;
809 }
810 CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
811 CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
812 CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
813 if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
814 if (other.what & eRelativeLayerChanged) {
815 diff |= eRelativeLayerChanged;
816 diff &= ~eLayerChanged;
817 }
818 if (other.what & eReparent &&
819 !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
820 other.parentSurfaceControlForChild)) {
821 diff |= eReparent;
822 }
823 CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
824 CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
825 CHECK_DIFF(diff, eCropChanged, other, crop);
826 if (other.what & eBufferChanged) diff |= eBufferChanged;
827 CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
828 CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio,
829 desiredHdrSdrRatio);
830 CHECK_DIFF(diff, eDesiredHdrHeadroomChanged, other, desiredHdrSdrRatio);
831 CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
832 CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
833 if (other.what & eSurfaceDamageRegionChanged &&
834 (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
835 diff |= eSurfaceDamageRegionChanged;
836 }
837 CHECK_DIFF(diff, eApiChanged, other, api);
838 if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
839 CHECK_DIFF(diff, eApiChanged, other, api);
840 CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
841 if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
842 if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
843 CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
844 if (other.what & eMetadataChanged) diff |= eMetadataChanged;
845 CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
846 CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
847 CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
848 CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
849 changeFrameRateStrategy);
850 CHECK_DIFF2(diff, eFrameRateCategoryChanged, other, frameRateCategory,
851 frameRateCategorySmoothSwitchOnly);
852 CHECK_DIFF(diff, eFrameRateSelectionStrategyChanged, other, frameRateSelectionStrategy);
853 CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
854 CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
855 CHECK_DIFF(diff, eTrustedOverlayChanged, other, trustedOverlay);
856 CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
857 CHECK_DIFF(diff, eEdgeExtensionChanged, other, edgeExtensionParameters);
858 CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
859 CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
860 if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
861 CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
862 CHECK_DIFF(diff, eColorChanged, other, color.rgb);
863 CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
864 CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
865 if (other.what & eBufferReleaseChannelChanged) diff |= eBufferReleaseChannelChanged;
866 if (other.what & eLutsChanged) diff |= eLutsChanged;
867 CHECK_DIFF(diff, ePictureProfileHandleChanged, other, pictureProfileHandle);
868 CHECK_DIFF(diff, eAppContentPriorityChanged, other, appContentPriority);
869
870 return diff;
871 }
872
hasBufferChanges() const873 bool layer_state_t::hasBufferChanges() const {
874 return what & layer_state_t::eBufferChanged;
875 }
876
hasValidBuffer() const877 bool layer_state_t::hasValidBuffer() const {
878 return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
879 }
880
write(Parcel & output) const881 status_t layer_state_t::matrix22_t::write(Parcel& output) const {
882 SAFE_PARCEL(output.writeFloat, dsdx);
883 SAFE_PARCEL(output.writeFloat, dtdx);
884 SAFE_PARCEL(output.writeFloat, dtdy);
885 SAFE_PARCEL(output.writeFloat, dsdy);
886 return NO_ERROR;
887 }
888
read(const Parcel & input)889 status_t layer_state_t::matrix22_t::read(const Parcel& input) {
890 SAFE_PARCEL(input.readFloat, &dsdx);
891 SAFE_PARCEL(input.readFloat, &dtdx);
892 SAFE_PARCEL(input.readFloat, &dtdy);
893 SAFE_PARCEL(input.readFloat, &dsdy);
894 return NO_ERROR;
895 }
896
897 // ------------------------------- InputWindowCommands ----------------------------------------
898
merge(const InputWindowCommands & other)899 bool InputWindowCommands::merge(const InputWindowCommands& other) {
900 bool changes = false;
901 changes |= !other.focusRequests.empty();
902 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
903 std::make_move_iterator(other.focusRequests.end()));
904 changes |= !other.windowInfosReportedListeners.empty();
905 windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
906 other.windowInfosReportedListeners.end());
907 return changes;
908 }
909
empty() const910 bool InputWindowCommands::empty() const {
911 return focusRequests.empty() && windowInfosReportedListeners.empty();
912 }
913
clear()914 void InputWindowCommands::clear() {
915 focusRequests.clear();
916 windowInfosReportedListeners.clear();
917 }
918
write(Parcel & output) const919 status_t InputWindowCommands::write(Parcel& output) const {
920 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
921
922 SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
923 for (const auto& listener : windowInfosReportedListeners) {
924 SAFE_PARCEL(output.writeStrongBinder, listener);
925 }
926
927 return NO_ERROR;
928 }
929
read(const Parcel & input)930 status_t InputWindowCommands::read(const Parcel& input) {
931 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
932
933 int listenerSize = 0;
934 SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
935 windowInfosReportedListeners.reserve(listenerSize);
936 for (int i = 0; i < listenerSize; i++) {
937 sp<gui::IWindowInfosReportedListener> listener;
938 SAFE_PARCEL(input.readStrongBinder, &listener);
939 windowInfosReportedListeners.insert(listener);
940 }
941
942 return NO_ERROR;
943 }
944
945 // ----------------------------------------------------------------------------
946
generateReleaseCallbackId() const947 ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
948 uint64_t bufferId;
949 if (buffer) {
950 bufferId = buffer->getId();
951 } else {
952 bufferId = cachedBuffer.id;
953 }
954 return {bufferId, frameNumber};
955 }
956
writeToParcel(Parcel * output) const957 status_t BufferData::writeToParcel(Parcel* output) const {
958 SAFE_PARCEL(output->writeInt32, flags.get());
959
960 if (buffer) {
961 SAFE_PARCEL(output->writeBool, true);
962 SAFE_PARCEL(output->write, *buffer);
963 } else {
964 SAFE_PARCEL(output->writeBool, false);
965 }
966
967 if (acquireFence) {
968 SAFE_PARCEL(output->writeBool, true);
969 SAFE_PARCEL(output->write, *acquireFence);
970 } else {
971 SAFE_PARCEL(output->writeBool, false);
972 }
973
974 SAFE_PARCEL(output->writeUint64, frameNumber);
975 SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
976 SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
977
978 SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
979 SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
980 SAFE_PARCEL(output->writeBool, hasBarrier);
981 SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
982 SAFE_PARCEL(output->writeUint32, producerId);
983 SAFE_PARCEL(output->writeInt64, dequeueTime);
984
985 return NO_ERROR;
986 }
987
readFromParcel(const Parcel * input)988 status_t BufferData::readFromParcel(const Parcel* input) {
989 int32_t tmpInt32;
990 SAFE_PARCEL(input->readInt32, &tmpInt32);
991 flags = ftl::Flags<BufferDataChange>(tmpInt32);
992
993 bool tmpBool = false;
994 SAFE_PARCEL(input->readBool, &tmpBool);
995 if (tmpBool) {
996 buffer = new GraphicBuffer();
997 SAFE_PARCEL(input->read, *buffer);
998 }
999
1000 SAFE_PARCEL(input->readBool, &tmpBool);
1001 if (tmpBool) {
1002 acquireFence = new Fence();
1003 SAFE_PARCEL(input->read, *acquireFence);
1004 }
1005
1006 SAFE_PARCEL(input->readUint64, &frameNumber);
1007
1008 sp<IBinder> tmpBinder = nullptr;
1009 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
1010 if (tmpBinder) {
1011 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1012 }
1013 SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
1014
1015 tmpBinder = nullptr;
1016 SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
1017 cachedBuffer.token = tmpBinder;
1018 SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
1019
1020 SAFE_PARCEL(input->readBool, &hasBarrier);
1021 SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
1022 SAFE_PARCEL(input->readUint32, &producerId);
1023 SAFE_PARCEL(input->readInt64, &dequeueTime);
1024
1025 return NO_ERROR;
1026 }
1027
writeToParcel(Parcel * parcel) const1028 status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1029 SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1030 SAFE_PARCEL(parcel->writeInt32, callbackId);
1031 return NO_ERROR;
1032 }
1033
readFromParcel(const Parcel * parcel)1034 status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1035 sp<IBinder> tmpBinder = nullptr;
1036 SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1037 if (tmpBinder) {
1038 callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1039 }
1040 SAFE_PARCEL(parcel->readInt32, &callbackId);
1041 return NO_ERROR;
1042 }
1043
1044 }; // namespace android
1045