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