From 57f748c78d326521fc50d2336373117bb819764b Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 17 Mar 2022 17:23:49 -0400 Subject: Support setBuffer w/ release callback Allow setBuffer to take a release callback without passing a frame number. A fallback frame number on the target SurfaceControl is used instead. Bug: 220897032 Test: SurfaceControlTest CTS Change-Id: Ib110755e2887396d41a5d52af1305ccc2bf0e9bd --- libs/gui/SurfaceControl.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libs/gui/SurfaceControl.cpp') diff --git a/libs/gui/SurfaceControl.cpp b/libs/gui/SurfaceControl.cpp index 6529a4e51c..063dda5153 100644 --- a/libs/gui/SurfaceControl.cpp +++ b/libs/gui/SurfaceControl.cpp @@ -280,5 +280,18 @@ sp SurfaceControl::getParentingLayer() { return this; } +uint64_t SurfaceControl::resolveFrameNumber(const std::optional& frameNumber) { + if (frameNumber.has_value()) { + auto ret = frameNumber.value(); + // Set the fallback to something far enough ahead that in the unlikely event of mixed + // "real" frame numbers and fallback frame numbers, we still won't collide in any + // meaningful capacity + mFallbackFrameNumber = ret + 100; + return ret; + } else { + return mFallbackFrameNumber++; + } +} + // ---------------------------------------------------------------------------- }; // namespace android -- cgit v1.2.3-59-g8ed1b From c2cf02c17af0d7e5f58b8a17ecb9cfcc91a4d2eb Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Tue, 22 Mar 2022 15:25:54 -0700 Subject: SurfaceControl: Ensure unused fields are zeroed Otherwise we could leak uninitialized memory to an untrusted process. Bug: 214999987 Test: Existing tests pass Change-Id: I87993fbb920b3af938a311e6afc15383d571823a --- libs/gui/SurfaceControl.cpp | 1 + libs/gui/include/gui/SurfaceControl.h | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'libs/gui/SurfaceControl.cpp') diff --git a/libs/gui/SurfaceControl.cpp b/libs/gui/SurfaceControl.cpp index 063dda5153..654fb336fe 100644 --- a/libs/gui/SurfaceControl.cpp +++ b/libs/gui/SurfaceControl.cpp @@ -70,6 +70,7 @@ SurfaceControl::SurfaceControl(const sp& other) { mLayerId = other->mLayerId; mWidth = other->mWidth; mHeight = other->mHeight; + mFormat = other->mFormat; mCreateFlags = other->mCreateFlags; } diff --git a/libs/gui/include/gui/SurfaceControl.h b/libs/gui/include/gui/SurfaceControl.h index 1690e44ecc..b72cf8390e 100644 --- a/libs/gui/include/gui/SurfaceControl.h +++ b/libs/gui/include/gui/SurfaceControl.h @@ -121,12 +121,12 @@ private: mutable sp mSurfaceData; mutable sp mBbq; mutable sp mBbqChild; - int32_t mLayerId; - uint32_t mTransformHint; - uint32_t mWidth; - uint32_t mHeight; - PixelFormat mFormat; - uint32_t mCreateFlags; + int32_t mLayerId = 0; + uint32_t mTransformHint = 0; + uint32_t mWidth = 0; + uint32_t mHeight = 0; + PixelFormat mFormat = PIXEL_FORMAT_NONE; + uint32_t mCreateFlags = 0; uint64_t mFallbackFrameNumber = 100; }; -- cgit v1.2.3-59-g8ed1b