• Home
  • 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/IGraphicBufferProducer.h>
26 #include <gui/LayerState.h>
27 #include <gui/SurfaceControl.h>
28 #include <private/gui/ParcelUtils.h>
29 #include <system/window.h>
30 #include <utils/Errors.h>
31 
32 #define CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD)          \
33     {                                                               \
34         if ((OTHER.what & CHANGE_FLAG) && (FIELD != OTHER.FIELD)) { \
35             DIFF_RESULT |= CHANGE_FLAG;                             \
36         }                                                           \
37     }
38 
39 #define CHECK_DIFF2(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2) \
40     {                                                                \
41         CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1)          \
42         CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2)          \
43     }
44 
45 #define CHECK_DIFF3(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1, FIELD2, FIELD3) \
46     {                                                                        \
47         CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD1)                  \
48         CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD2)                  \
49         CHECK_DIFF(DIFF_RESULT, CHANGE_FLAG, OTHER, FIELD3)                  \
50     }
51 
52 namespace android {
53 
54 using gui::FocusRequest;
55 using gui::WindowInfoHandle;
56 
layer_state_t()57 layer_state_t::layer_state_t()
58       : surface(nullptr),
59         layerId(-1),
60         what(0),
61         x(0),
62         y(0),
63         z(0),
64         flags(0),
65         mask(0),
66         reserved(0),
67         cornerRadius(0.0f),
68         backgroundBlurRadius(0),
69         color(0),
70         bufferTransform(0),
71         transformToDisplayInverse(false),
72         crop(Rect::INVALID_RECT),
73         dataspace(ui::Dataspace::UNKNOWN),
74         surfaceDamageRegion(),
75         api(-1),
76         colorTransform(mat4()),
77         bgColor(0),
78         bgColorDataspace(ui::Dataspace::UNKNOWN),
79         colorSpaceAgnostic(false),
80         shadowRadius(0.0f),
81         frameRateSelectionPriority(-1),
82         frameRate(0.0f),
83         frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
84         changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
85         defaultFrameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
86         fixedTransformHint(ui::Transform::ROT_INVALID),
87         autoRefresh(false),
88         isTrustedOverlay(false),
89         borderEnabled(false),
90         bufferCrop(Rect::INVALID_RECT),
91         destinationFrame(Rect::INVALID_RECT),
92         dropInputMode(gui::DropInputMode::NONE) {
93     matrix.dsdx = matrix.dtdy = 1.0f;
94     matrix.dsdy = matrix.dtdx = 0.0f;
95     hdrMetadata.validTypes = 0;
96 }
97 
write(Parcel & output) const98 status_t layer_state_t::write(Parcel& output) const
99 {
100     SAFE_PARCEL(output.writeStrongBinder, surface);
101     SAFE_PARCEL(output.writeInt32, layerId);
102     SAFE_PARCEL(output.writeUint64, what);
103     SAFE_PARCEL(output.writeFloat, x);
104     SAFE_PARCEL(output.writeFloat, y);
105     SAFE_PARCEL(output.writeInt32, z);
106     SAFE_PARCEL(output.writeUint32, layerStack.id);
107     SAFE_PARCEL(output.writeUint32, flags);
108     SAFE_PARCEL(output.writeUint32, mask);
109     SAFE_PARCEL(matrix.write, output);
110     SAFE_PARCEL(output.write, crop);
111     SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
112     SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
113     SAFE_PARCEL(output.writeFloat, color.r);
114     SAFE_PARCEL(output.writeFloat, color.g);
115     SAFE_PARCEL(output.writeFloat, color.b);
116     SAFE_PARCEL(output.writeFloat, color.a);
117     SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
118     SAFE_PARCEL(output.write, transparentRegion);
119     SAFE_PARCEL(output.writeUint32, bufferTransform);
120     SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
121     SAFE_PARCEL(output.writeBool, borderEnabled);
122     SAFE_PARCEL(output.writeFloat, borderWidth);
123     SAFE_PARCEL(output.writeFloat, borderColor.r);
124     SAFE_PARCEL(output.writeFloat, borderColor.g);
125     SAFE_PARCEL(output.writeFloat, borderColor.b);
126     SAFE_PARCEL(output.writeFloat, borderColor.a);
127     SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
128     SAFE_PARCEL(output.write, hdrMetadata);
129     SAFE_PARCEL(output.write, surfaceDamageRegion);
130     SAFE_PARCEL(output.writeInt32, api);
131 
132     if (sidebandStream) {
133         SAFE_PARCEL(output.writeBool, true);
134         SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
135     } else {
136         SAFE_PARCEL(output.writeBool, false);
137     }
138 
139     SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
140     SAFE_PARCEL(output.writeFloat, cornerRadius);
141     SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
142     SAFE_PARCEL(output.writeParcelable, metadata);
143     SAFE_PARCEL(output.writeFloat, bgColor.r);
144     SAFE_PARCEL(output.writeFloat, bgColor.g);
145     SAFE_PARCEL(output.writeFloat, bgColor.b);
146     SAFE_PARCEL(output.writeFloat, bgColor.a);
147     SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
148     SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
149     SAFE_PARCEL(output.writeVectorSize, listeners);
150 
151     for (auto listener : listeners) {
152         SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
153         SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
154     }
155     SAFE_PARCEL(output.writeFloat, shadowRadius);
156     SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
157     SAFE_PARCEL(output.writeFloat, frameRate);
158     SAFE_PARCEL(output.writeByte, frameRateCompatibility);
159     SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
160     SAFE_PARCEL(output.writeByte, defaultFrameRateCompatibility);
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.writeBool, isTrustedOverlay);
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     SAFE_PARCEL(input.readBool, &borderEnabled);
235     SAFE_PARCEL(input.readFloat, &tmpFloat);
236     borderWidth = tmpFloat;
237     SAFE_PARCEL(input.readFloat, &tmpFloat);
238     borderColor.r = tmpFloat;
239     SAFE_PARCEL(input.readFloat, &tmpFloat);
240     borderColor.g = tmpFloat;
241     SAFE_PARCEL(input.readFloat, &tmpFloat);
242     borderColor.b = tmpFloat;
243     SAFE_PARCEL(input.readFloat, &tmpFloat);
244     borderColor.a = tmpFloat;
245 
246     uint32_t tmpUint32 = 0;
247     SAFE_PARCEL(input.readUint32, &tmpUint32);
248     dataspace = static_cast<ui::Dataspace>(tmpUint32);
249 
250     SAFE_PARCEL(input.read, hdrMetadata);
251     SAFE_PARCEL(input.read, surfaceDamageRegion);
252     SAFE_PARCEL(input.readInt32, &api);
253 
254     bool tmpBool = false;
255     SAFE_PARCEL(input.readBool, &tmpBool);
256     if (tmpBool) {
257         sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
258     }
259 
260     SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
261     SAFE_PARCEL(input.readFloat, &cornerRadius);
262     SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
263     SAFE_PARCEL(input.readParcelable, &metadata);
264 
265     SAFE_PARCEL(input.readFloat, &tmpFloat);
266     bgColor.r = tmpFloat;
267     SAFE_PARCEL(input.readFloat, &tmpFloat);
268     bgColor.g = tmpFloat;
269     SAFE_PARCEL(input.readFloat, &tmpFloat);
270     bgColor.b = tmpFloat;
271     SAFE_PARCEL(input.readFloat, &tmpFloat);
272     bgColor.a = tmpFloat;
273     SAFE_PARCEL(input.readUint32, &tmpUint32);
274     bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
275     SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
276 
277     int32_t numListeners = 0;
278     SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
279     listeners.clear();
280     for (int i = 0; i < numListeners; i++) {
281         sp<IBinder> listener;
282         std::vector<CallbackId> callbackIds;
283         SAFE_PARCEL(input.readNullableStrongBinder, &listener);
284         SAFE_PARCEL(input.readParcelableVector, &callbackIds);
285         listeners.emplace_back(listener, callbackIds);
286     }
287     SAFE_PARCEL(input.readFloat, &shadowRadius);
288     SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
289     SAFE_PARCEL(input.readFloat, &frameRate);
290     SAFE_PARCEL(input.readByte, &frameRateCompatibility);
291     SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
292     SAFE_PARCEL(input.readByte, &defaultFrameRateCompatibility);
293     SAFE_PARCEL(input.readUint32, &tmpUint32);
294     fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
295     SAFE_PARCEL(input.readBool, &autoRefresh);
296     SAFE_PARCEL(input.readBool, &dimmingEnabled);
297 
298     uint32_t numRegions = 0;
299     SAFE_PARCEL(input.readUint32, &numRegions);
300     blurRegions.clear();
301     for (uint32_t i = 0; i < numRegions; i++) {
302         BlurRegion region;
303         SAFE_PARCEL(input.readUint32, &region.blurRadius);
304         SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
305         SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
306         SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
307         SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
308         SAFE_PARCEL(input.readFloat, &region.alpha);
309         SAFE_PARCEL(input.readInt32, &region.left);
310         SAFE_PARCEL(input.readInt32, &region.top);
311         SAFE_PARCEL(input.readInt32, &region.right);
312         SAFE_PARCEL(input.readInt32, &region.bottom);
313         blurRegions.push_back(region);
314     }
315 
316     SAFE_PARCEL(input.read, stretchEffect);
317     SAFE_PARCEL(input.read, bufferCrop);
318     SAFE_PARCEL(input.read, destinationFrame);
319     SAFE_PARCEL(input.readBool, &isTrustedOverlay);
320 
321     uint32_t mode;
322     SAFE_PARCEL(input.readUint32, &mode);
323     dropInputMode = static_cast<gui::DropInputMode>(mode);
324 
325     bool hasBufferData;
326     SAFE_PARCEL(input.readBool, &hasBufferData);
327     if (hasBufferData) {
328         bufferData = std::make_shared<BufferData>();
329         SAFE_PARCEL(input.readParcelable, bufferData.get());
330     } else {
331         bufferData = nullptr;
332     }
333 
334     SAFE_PARCEL(input.readParcelable, &trustedPresentationThresholds);
335     SAFE_PARCEL(input.readParcelable, &trustedPresentationListener);
336 
337     SAFE_PARCEL(input.readFloat, &tmpFloat);
338     currentHdrSdrRatio = tmpFloat;
339     SAFE_PARCEL(input.readFloat, &tmpFloat);
340     desiredHdrSdrRatio = tmpFloat;
341 
342     int32_t tmpInt32;
343     SAFE_PARCEL(input.readInt32, &tmpInt32);
344     cachingHint = static_cast<gui::CachingHint>(tmpInt32);
345 
346     return NO_ERROR;
347 }
348 
write(Parcel & output) const349 status_t ComposerState::write(Parcel& output) const {
350     return state.write(output);
351 }
352 
read(const Parcel & input)353 status_t ComposerState::read(const Parcel& input) {
354     return state.read(input);
355 }
356 
357 DisplayState::DisplayState() = default;
358 
write(Parcel & output) const359 status_t DisplayState::write(Parcel& output) const {
360     SAFE_PARCEL(output.writeStrongBinder, token);
361     SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
362     SAFE_PARCEL(output.writeUint32, what);
363     SAFE_PARCEL(output.writeUint32, flags);
364     SAFE_PARCEL(output.writeUint32, layerStack.id);
365     SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
366     SAFE_PARCEL(output.write, layerStackSpaceRect);
367     SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
368     SAFE_PARCEL(output.writeUint32, width);
369     SAFE_PARCEL(output.writeUint32, height);
370     return NO_ERROR;
371 }
372 
read(const Parcel & input)373 status_t DisplayState::read(const Parcel& input) {
374     SAFE_PARCEL(input.readStrongBinder, &token);
375     sp<IBinder> tmpBinder;
376     SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
377     surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
378 
379     SAFE_PARCEL(input.readUint32, &what);
380     SAFE_PARCEL(input.readUint32, &flags);
381     SAFE_PARCEL(input.readUint32, &layerStack.id);
382     uint32_t tmpUint = 0;
383     SAFE_PARCEL(input.readUint32, &tmpUint);
384     orientation = ui::toRotation(tmpUint);
385 
386     SAFE_PARCEL(input.read, layerStackSpaceRect);
387     SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
388     SAFE_PARCEL(input.readUint32, &width);
389     SAFE_PARCEL(input.readUint32, &height);
390     return NO_ERROR;
391 }
392 
merge(const DisplayState & other)393 void DisplayState::merge(const DisplayState& other) {
394     if (other.what & eSurfaceChanged) {
395         what |= eSurfaceChanged;
396         surface = other.surface;
397     }
398     if (other.what & eLayerStackChanged) {
399         what |= eLayerStackChanged;
400         layerStack = other.layerStack;
401     }
402     if (other.what & eFlagsChanged) {
403         what |= eFlagsChanged;
404         flags = other.flags;
405     }
406     if (other.what & eDisplayProjectionChanged) {
407         what |= eDisplayProjectionChanged;
408         orientation = other.orientation;
409         layerStackSpaceRect = other.layerStackSpaceRect;
410         orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
411     }
412     if (other.what & eDisplaySizeChanged) {
413         what |= eDisplaySizeChanged;
414         width = other.width;
415         height = other.height;
416     }
417 }
418 
sanitize(int32_t permissions)419 void DisplayState::sanitize(int32_t permissions) {
420     if (what & DisplayState::eLayerStackChanged) {
421         if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
422             what &= ~DisplayState::eLayerStackChanged;
423             ALOGE("Stripped attempt to set eLayerStackChanged in sanitize");
424         }
425     }
426     if (what & DisplayState::eDisplayProjectionChanged) {
427         if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
428             what &= ~DisplayState::eDisplayProjectionChanged;
429             ALOGE("Stripped attempt to set eDisplayProjectionChanged in sanitize");
430         }
431     }
432     if (what & DisplayState::eSurfaceChanged) {
433         if (!(permissions & layer_state_t::Permission::ACCESS_SURFACE_FLINGER)) {
434             what &= ~DisplayState::eSurfaceChanged;
435             ALOGE("Stripped attempt to set eSurfaceChanged in sanitize");
436         }
437     }
438 }
439 
sanitize(int32_t permissions)440 void layer_state_t::sanitize(int32_t permissions) {
441     // TODO: b/109894387
442     //
443     // SurfaceFlinger's renderer is not prepared to handle cropping in the face of arbitrary
444     // rotation. To see the problem observe that if we have a square parent, and a child
445     // of the same size, then we rotate the child 45 degrees around its center, the child
446     // must now be cropped to a non rectangular 8 sided region.
447     //
448     // Of course we can fix this in the future. For now, we are lucky, SurfaceControl is
449     // private API, and arbitrary rotation is used in limited use cases, for instance:
450     // - WindowManager only uses rotation in one case, which is on a top level layer in which
451     //   cropping is not an issue.
452     // - Launcher, as a privileged app, uses this to transition an application to PiP
453     //   (picture-in-picture) mode.
454     //
455     // However given that abuse of rotation matrices could lead to surfaces extending outside
456     // of cropped areas, we need to prevent non-root clients without permission
457     // ACCESS_SURFACE_FLINGER nor ROTATE_SURFACE_FLINGER
458     // (a.k.a. everyone except WindowManager / tests / Launcher) from setting non rectangle
459     // preserving transformations.
460     if (what & eMatrixChanged) {
461         if (!(permissions & Permission::ROTATE_SURFACE_FLINGER)) {
462             ui::Transform t;
463             t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
464             if (!t.preserveRects()) {
465                 what &= ~eMatrixChanged;
466                 ALOGE("Stripped non rect preserving matrix in sanitize");
467             }
468         }
469     }
470 
471     if (what & eFlagsChanged) {
472         if ((flags & eLayerIsDisplayDecoration) &&
473             !(permissions & Permission::INTERNAL_SYSTEM_WINDOW)) {
474             flags &= ~eLayerIsDisplayDecoration;
475             ALOGE("Stripped attempt to set LayerIsDisplayDecoration 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 & eCachingHintChanged) {
599         what |= eCachingHintChanged;
600         cachingHint = other.cachingHint;
601     }
602     if (other.what & eHdrMetadataChanged) {
603         what |= eHdrMetadataChanged;
604         hdrMetadata = other.hdrMetadata;
605     }
606     if (other.what & eSurfaceDamageRegionChanged) {
607         what |= eSurfaceDamageRegionChanged;
608         surfaceDamageRegion = other.surfaceDamageRegion;
609     }
610     if (other.what & eApiChanged) {
611         what |= eApiChanged;
612         api = other.api;
613     }
614     if (other.what & eSidebandStreamChanged) {
615         what |= eSidebandStreamChanged;
616         sidebandStream = other.sidebandStream;
617     }
618     if (other.what & eColorTransformChanged) {
619         what |= eColorTransformChanged;
620         colorTransform = other.colorTransform;
621     }
622     if (other.what & eHasListenerCallbacksChanged) {
623         what |= eHasListenerCallbacksChanged;
624     }
625     if (other.what & eInputInfoChanged) {
626         what |= eInputInfoChanged;
627         windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
628     }
629     if (other.what & eBackgroundColorChanged) {
630         what |= eBackgroundColorChanged;
631         bgColor = other.bgColor;
632         bgColorDataspace = other.bgColorDataspace;
633     }
634     if (other.what & eMetadataChanged) {
635         what |= eMetadataChanged;
636         metadata.merge(other.metadata);
637     }
638     if (other.what & eShadowRadiusChanged) {
639         what |= eShadowRadiusChanged;
640         shadowRadius = other.shadowRadius;
641     }
642     if (other.what & eRenderBorderChanged) {
643         what |= eRenderBorderChanged;
644         borderEnabled = other.borderEnabled;
645         borderWidth = other.borderWidth;
646         borderColor = other.borderColor;
647     }
648     if (other.what & eDefaultFrameRateCompatibilityChanged) {
649         what |= eDefaultFrameRateCompatibilityChanged;
650         defaultFrameRateCompatibility = other.defaultFrameRateCompatibility;
651     }
652     if (other.what & eFrameRateSelectionPriority) {
653         what |= eFrameRateSelectionPriority;
654         frameRateSelectionPriority = other.frameRateSelectionPriority;
655     }
656     if (other.what & eFrameRateChanged) {
657         what |= eFrameRateChanged;
658         frameRate = other.frameRate;
659         frameRateCompatibility = other.frameRateCompatibility;
660         changeFrameRateStrategy = other.changeFrameRateStrategy;
661     }
662     if (other.what & eFixedTransformHintChanged) {
663         what |= eFixedTransformHintChanged;
664         fixedTransformHint = other.fixedTransformHint;
665     }
666     if (other.what & eAutoRefreshChanged) {
667         what |= eAutoRefreshChanged;
668         autoRefresh = other.autoRefresh;
669     }
670     if (other.what & eTrustedOverlayChanged) {
671         what |= eTrustedOverlayChanged;
672         isTrustedOverlay = other.isTrustedOverlay;
673     }
674     if (other.what & eStretchChanged) {
675         what |= eStretchChanged;
676         stretchEffect = other.stretchEffect;
677     }
678     if (other.what & eBufferCropChanged) {
679         what |= eBufferCropChanged;
680         bufferCrop = other.bufferCrop;
681     }
682     if (other.what & eDestinationFrameChanged) {
683         what |= eDestinationFrameChanged;
684         destinationFrame = other.destinationFrame;
685     }
686     if (other.what & eProducerDisconnect) {
687         what |= eProducerDisconnect;
688     }
689     if (other.what & eDropInputModeChanged) {
690         what |= eDropInputModeChanged;
691         dropInputMode = other.dropInputMode;
692     }
693     if (other.what & eColorChanged) {
694         what |= eColorChanged;
695         color.rgb = other.color.rgb;
696     }
697     if (other.what & eColorSpaceAgnosticChanged) {
698         what |= eColorSpaceAgnosticChanged;
699         colorSpaceAgnostic = other.colorSpaceAgnostic;
700     }
701     if (other.what & eDimmingEnabledChanged) {
702         what |= eDimmingEnabledChanged;
703         dimmingEnabled = other.dimmingEnabled;
704     }
705     if (other.what & eFlushJankData) {
706         what |= eFlushJankData;
707     }
708     if ((other.what & what) != other.what) {
709         ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
710               "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
711               other.what, what, (other.what & what) ^ other.what);
712     }
713 }
714 
diff(const layer_state_t & other) const715 uint64_t layer_state_t::diff(const layer_state_t& other) const {
716     uint64_t diff = 0;
717     CHECK_DIFF2(diff, ePositionChanged, other, x, y);
718     if (other.what & eLayerChanged) {
719         diff |= eLayerChanged;
720         diff &= ~eRelativeLayerChanged;
721     }
722     CHECK_DIFF(diff, eAlphaChanged, other, color.a);
723     CHECK_DIFF(diff, eMatrixChanged, other, matrix);
724     if (other.what & eTransparentRegionChanged &&
725         (!transparentRegion.hasSameRects(other.transparentRegion))) {
726         diff |= eTransparentRegionChanged;
727     }
728     if (other.what & eFlagsChanged) {
729         uint64_t changedFlags = (flags & other.mask) ^ (other.flags & other.mask);
730         if (changedFlags) diff |= eFlagsChanged;
731     }
732     CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
733     CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
734     CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
735     if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
736     if (other.what & eRelativeLayerChanged) {
737         diff |= eRelativeLayerChanged;
738         diff &= ~eLayerChanged;
739     }
740     if (other.what & eReparent &&
741         !SurfaceControl::isSameSurface(parentSurfaceControlForChild,
742                                        other.parentSurfaceControlForChild)) {
743         diff |= eReparent;
744     }
745     CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
746     CHECK_DIFF(diff, eTransformToDisplayInverseChanged, other, transformToDisplayInverse);
747     CHECK_DIFF(diff, eCropChanged, other, crop);
748     if (other.what & eBufferChanged) diff |= eBufferChanged;
749     CHECK_DIFF(diff, eDataspaceChanged, other, dataspace);
750     CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio,
751                 desiredHdrSdrRatio);
752     CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
753     CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
754     if (other.what & eSurfaceDamageRegionChanged &&
755         (!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
756         diff |= eSurfaceDamageRegionChanged;
757     }
758     CHECK_DIFF(diff, eApiChanged, other, api);
759     if (other.what & eSidebandStreamChanged) diff |= eSidebandStreamChanged;
760     CHECK_DIFF(diff, eApiChanged, other, api);
761     CHECK_DIFF(diff, eColorTransformChanged, other, colorTransform);
762     if (other.what & eHasListenerCallbacksChanged) diff |= eHasListenerCallbacksChanged;
763     if (other.what & eInputInfoChanged) diff |= eInputInfoChanged;
764     CHECK_DIFF2(diff, eBackgroundColorChanged, other, bgColor, bgColorDataspace);
765     if (other.what & eMetadataChanged) diff |= eMetadataChanged;
766     CHECK_DIFF(diff, eShadowRadiusChanged, other, shadowRadius);
767     CHECK_DIFF3(diff, eRenderBorderChanged, other, borderEnabled, borderWidth, borderColor);
768     CHECK_DIFF(diff, eDefaultFrameRateCompatibilityChanged, other, defaultFrameRateCompatibility);
769     CHECK_DIFF(diff, eFrameRateSelectionPriority, other, frameRateSelectionPriority);
770     CHECK_DIFF3(diff, eFrameRateChanged, other, frameRate, frameRateCompatibility,
771                 changeFrameRateStrategy);
772     CHECK_DIFF(diff, eFixedTransformHintChanged, other, fixedTransformHint);
773     CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
774     CHECK_DIFF(diff, eTrustedOverlayChanged, other, isTrustedOverlay);
775     CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
776     CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
777     CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
778     if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
779     CHECK_DIFF(diff, eDropInputModeChanged, other, dropInputMode);
780     CHECK_DIFF(diff, eColorChanged, other, color.rgb);
781     CHECK_DIFF(diff, eColorSpaceAgnosticChanged, other, colorSpaceAgnostic);
782     CHECK_DIFF(diff, eDimmingEnabledChanged, other, dimmingEnabled);
783     return diff;
784 }
785 
hasBufferChanges() const786 bool layer_state_t::hasBufferChanges() const {
787     return what & layer_state_t::eBufferChanged;
788 }
789 
hasValidBuffer() const790 bool layer_state_t::hasValidBuffer() const {
791     return bufferData && (bufferData->hasBuffer() || bufferData->cachedBuffer.isValid());
792 }
793 
write(Parcel & output) const794 status_t layer_state_t::matrix22_t::write(Parcel& output) const {
795     SAFE_PARCEL(output.writeFloat, dsdx);
796     SAFE_PARCEL(output.writeFloat, dtdx);
797     SAFE_PARCEL(output.writeFloat, dtdy);
798     SAFE_PARCEL(output.writeFloat, dsdy);
799     return NO_ERROR;
800 }
801 
read(const Parcel & input)802 status_t layer_state_t::matrix22_t::read(const Parcel& input) {
803     SAFE_PARCEL(input.readFloat, &dsdx);
804     SAFE_PARCEL(input.readFloat, &dtdx);
805     SAFE_PARCEL(input.readFloat, &dtdy);
806     SAFE_PARCEL(input.readFloat, &dsdy);
807     return NO_ERROR;
808 }
809 
810 // ------------------------------- InputWindowCommands ----------------------------------------
811 
merge(const InputWindowCommands & other)812 bool InputWindowCommands::merge(const InputWindowCommands& other) {
813     bool changes = false;
814     changes |= !other.focusRequests.empty();
815     focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
816                          std::make_move_iterator(other.focusRequests.end()));
817     changes |= !other.windowInfosReportedListeners.empty();
818     windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
819                                         other.windowInfosReportedListeners.end());
820     return changes;
821 }
822 
empty() const823 bool InputWindowCommands::empty() const {
824     return focusRequests.empty() && windowInfosReportedListeners.empty();
825 }
826 
clear()827 void InputWindowCommands::clear() {
828     focusRequests.clear();
829     windowInfosReportedListeners.clear();
830 }
831 
write(Parcel & output) const832 status_t InputWindowCommands::write(Parcel& output) const {
833     SAFE_PARCEL(output.writeParcelableVector, focusRequests);
834 
835     SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
836     for (const auto& listener : windowInfosReportedListeners) {
837         SAFE_PARCEL(output.writeStrongBinder, listener);
838     }
839 
840     return NO_ERROR;
841 }
842 
read(const Parcel & input)843 status_t InputWindowCommands::read(const Parcel& input) {
844     SAFE_PARCEL(input.readParcelableVector, &focusRequests);
845 
846     int listenerSize = 0;
847     SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
848     windowInfosReportedListeners.reserve(listenerSize);
849     for (int i = 0; i < listenerSize; i++) {
850         sp<gui::IWindowInfosReportedListener> listener;
851         SAFE_PARCEL(input.readStrongBinder, &listener);
852         windowInfosReportedListeners.insert(listener);
853     }
854 
855     return NO_ERROR;
856 }
857 
ValidateFrameRate(float frameRate,int8_t compatibility,int8_t changeFrameRateStrategy,const char * inFunctionName,bool privileged)858 bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
859                        const char* inFunctionName, bool privileged) {
860     const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
861     int floatClassification = std::fpclassify(frameRate);
862     if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
863         ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
864         return false;
865     }
866 
867     if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
868         compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
869         (!privileged ||
870          (compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT &&
871           compatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE))) {
872         ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
873               compatibility, privileged ? "yes" : "no");
874         return false;
875     }
876 
877     if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
878         changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
879         ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
880               changeFrameRateStrategy);
881     }
882 
883     return true;
884 }
885 
886 // ----------------------------------------------------------------------------
887 
888 namespace gui {
889 
writeToParcel(Parcel * output) const890 status_t CaptureArgs::writeToParcel(Parcel* output) const {
891     SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(pixelFormat));
892     SAFE_PARCEL(output->write, sourceCrop);
893     SAFE_PARCEL(output->writeFloat, frameScaleX);
894     SAFE_PARCEL(output->writeFloat, frameScaleY);
895     SAFE_PARCEL(output->writeBool, captureSecureLayers);
896     SAFE_PARCEL(output->writeInt32, uid);
897     SAFE_PARCEL(output->writeInt32, static_cast<int32_t>(dataspace));
898     SAFE_PARCEL(output->writeBool, allowProtected);
899     SAFE_PARCEL(output->writeBool, grayscale);
900     SAFE_PARCEL(output->writeInt32, excludeHandles.size());
901     for (auto& excludeHandle : excludeHandles) {
902         SAFE_PARCEL(output->writeStrongBinder, excludeHandle);
903     }
904     SAFE_PARCEL(output->writeBool, hintForSeamlessTransition);
905     return NO_ERROR;
906 }
907 
readFromParcel(const Parcel * input)908 status_t CaptureArgs::readFromParcel(const Parcel* input) {
909     int32_t value = 0;
910     SAFE_PARCEL(input->readInt32, &value);
911     pixelFormat = static_cast<ui::PixelFormat>(value);
912     SAFE_PARCEL(input->read, sourceCrop);
913     SAFE_PARCEL(input->readFloat, &frameScaleX);
914     SAFE_PARCEL(input->readFloat, &frameScaleY);
915     SAFE_PARCEL(input->readBool, &captureSecureLayers);
916     SAFE_PARCEL(input->readInt32, &uid);
917     SAFE_PARCEL(input->readInt32, &value);
918     dataspace = static_cast<ui::Dataspace>(value);
919     SAFE_PARCEL(input->readBool, &allowProtected);
920     SAFE_PARCEL(input->readBool, &grayscale);
921     int32_t numExcludeHandles = 0;
922     SAFE_PARCEL_READ_SIZE(input->readInt32, &numExcludeHandles, input->dataSize());
923     excludeHandles.reserve(numExcludeHandles);
924     for (int i = 0; i < numExcludeHandles; i++) {
925         sp<IBinder> binder;
926         SAFE_PARCEL(input->readStrongBinder, &binder);
927         excludeHandles.emplace(binder);
928     }
929     SAFE_PARCEL(input->readBool, &hintForSeamlessTransition);
930     return NO_ERROR;
931 }
932 
writeToParcel(Parcel * output) const933 status_t DisplayCaptureArgs::writeToParcel(Parcel* output) const {
934     SAFE_PARCEL(CaptureArgs::writeToParcel, output);
935 
936     SAFE_PARCEL(output->writeStrongBinder, displayToken);
937     SAFE_PARCEL(output->writeUint32, width);
938     SAFE_PARCEL(output->writeUint32, height);
939     SAFE_PARCEL(output->writeBool, useIdentityTransform);
940     return NO_ERROR;
941 }
942 
readFromParcel(const Parcel * input)943 status_t DisplayCaptureArgs::readFromParcel(const Parcel* input) {
944     SAFE_PARCEL(CaptureArgs::readFromParcel, input);
945 
946     SAFE_PARCEL(input->readStrongBinder, &displayToken);
947     SAFE_PARCEL(input->readUint32, &width);
948     SAFE_PARCEL(input->readUint32, &height);
949     SAFE_PARCEL(input->readBool, &useIdentityTransform);
950     return NO_ERROR;
951 }
952 
writeToParcel(Parcel * output) const953 status_t LayerCaptureArgs::writeToParcel(Parcel* output) const {
954     SAFE_PARCEL(CaptureArgs::writeToParcel, output);
955 
956     SAFE_PARCEL(output->writeStrongBinder, layerHandle);
957     SAFE_PARCEL(output->writeBool, childrenOnly);
958     return NO_ERROR;
959 }
960 
readFromParcel(const Parcel * input)961 status_t LayerCaptureArgs::readFromParcel(const Parcel* input) {
962     SAFE_PARCEL(CaptureArgs::readFromParcel, input);
963 
964     SAFE_PARCEL(input->readStrongBinder, &layerHandle);
965 
966     SAFE_PARCEL(input->readBool, &childrenOnly);
967     return NO_ERROR;
968 }
969 
970 }; // namespace gui
971 
generateReleaseCallbackId() const972 ReleaseCallbackId BufferData::generateReleaseCallbackId() const {
973     uint64_t bufferId;
974     if (buffer) {
975         bufferId = buffer->getId();
976     } else {
977         bufferId = cachedBuffer.id;
978     }
979     return {bufferId, frameNumber};
980 }
981 
writeToParcel(Parcel * output) const982 status_t BufferData::writeToParcel(Parcel* output) const {
983     SAFE_PARCEL(output->writeInt32, flags.get());
984 
985     if (buffer) {
986         SAFE_PARCEL(output->writeBool, true);
987         SAFE_PARCEL(output->write, *buffer);
988     } else {
989         SAFE_PARCEL(output->writeBool, false);
990     }
991 
992     if (acquireFence) {
993         SAFE_PARCEL(output->writeBool, true);
994         SAFE_PARCEL(output->write, *acquireFence);
995     } else {
996         SAFE_PARCEL(output->writeBool, false);
997     }
998 
999     SAFE_PARCEL(output->writeUint64, frameNumber);
1000     SAFE_PARCEL(output->writeStrongBinder, IInterface::asBinder(releaseBufferListener));
1001     SAFE_PARCEL(output->writeStrongBinder, releaseBufferEndpoint);
1002 
1003     SAFE_PARCEL(output->writeStrongBinder, cachedBuffer.token.promote());
1004     SAFE_PARCEL(output->writeUint64, cachedBuffer.id);
1005     SAFE_PARCEL(output->writeBool, hasBarrier);
1006     SAFE_PARCEL(output->writeUint64, barrierFrameNumber);
1007     SAFE_PARCEL(output->writeUint32, producerId);
1008 
1009     return NO_ERROR;
1010 }
1011 
readFromParcel(const Parcel * input)1012 status_t BufferData::readFromParcel(const Parcel* input) {
1013     int32_t tmpInt32;
1014     SAFE_PARCEL(input->readInt32, &tmpInt32);
1015     flags = ftl::Flags<BufferDataChange>(tmpInt32);
1016 
1017     bool tmpBool = false;
1018     SAFE_PARCEL(input->readBool, &tmpBool);
1019     if (tmpBool) {
1020         buffer = new GraphicBuffer();
1021         SAFE_PARCEL(input->read, *buffer);
1022     }
1023 
1024     SAFE_PARCEL(input->readBool, &tmpBool);
1025     if (tmpBool) {
1026         acquireFence = new Fence();
1027         SAFE_PARCEL(input->read, *acquireFence);
1028     }
1029 
1030     SAFE_PARCEL(input->readUint64, &frameNumber);
1031 
1032     sp<IBinder> tmpBinder = nullptr;
1033     SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
1034     if (tmpBinder) {
1035         releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1036     }
1037     SAFE_PARCEL(input->readNullableStrongBinder, &releaseBufferEndpoint);
1038 
1039     tmpBinder = nullptr;
1040     SAFE_PARCEL(input->readNullableStrongBinder, &tmpBinder);
1041     cachedBuffer.token = tmpBinder;
1042     SAFE_PARCEL(input->readUint64, &cachedBuffer.id);
1043 
1044     SAFE_PARCEL(input->readBool, &hasBarrier);
1045     SAFE_PARCEL(input->readUint64, &barrierFrameNumber);
1046     SAFE_PARCEL(input->readUint32, &producerId);
1047 
1048     return NO_ERROR;
1049 }
1050 
writeToParcel(Parcel * parcel) const1051 status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1052     SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1053     SAFE_PARCEL(parcel->writeInt32, callbackId);
1054     return NO_ERROR;
1055 }
1056 
readFromParcel(const Parcel * parcel)1057 status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
1058     sp<IBinder> tmpBinder = nullptr;
1059     SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
1060     if (tmpBinder) {
1061         callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1062     }
1063     SAFE_PARCEL(parcel->readInt32, &callbackId);
1064     return NO_ERROR;
1065 }
1066 
1067 }; // namespace android
1068