sf: reuse luma sampling buffer when available
Reuse the luma sampling buffer when available, saving a frequent buffer
reallocation. Depending on driver refcounting behavior, this could have
resulted in the buffer free on the SF main thread (and typically did on
referenced device, costing about ~500us @10hz).
Test: verify luma sampling work reduces from ~2ms -> 1.5ms
Test: RegionSamplingTest in libgui
Fixes: 131416627
Change-Id: I8e6d57ae25bd37ceec828c82796f0f4f8f45636e
diff --git a/services/surfaceflinger/RegionSamplingThread.h b/services/surfaceflinger/RegionSamplingThread.h
index 9796429..72b2042 100644
--- a/services/surfaceflinger/RegionSamplingThread.h
+++ b/services/surfaceflinger/RegionSamplingThread.h
@@ -24,13 +24,13 @@
#include <android-base/thread_annotations.h>
#include <binder/IBinder.h>
+#include <ui/GraphicBuffer.h>
#include <ui/Rect.h>
#include <utils/StrongPointer.h>
#include "Scheduler/IdleTimer.h"
namespace android {
-class GraphicBuffer;
class IRegionSamplingListener;
class Layer;
class Scheduler;
@@ -121,6 +121,8 @@
std::unordered_map<wp<IBinder>, Descriptor, WpHash> mDescriptors GUARDED_BY(mMutex);
std::chrono::nanoseconds lastSampleTime GUARDED_BY(mMutex);
bool mDiscardedFrames GUARDED_BY(mMutex) = false;
+
+ sp<GraphicBuffer> mCachedBuffer GUARDED_BY(mMutex) = nullptr;
};
} // namespace android