Loading services/surfaceflinger/RegionSamplingThread.cpp +15 −4 Original line number Diff line number Diff line Loading @@ -377,10 +377,15 @@ void RegionSamplingThread::captureSample() { mFlinger.traverseLayersInDisplay(device, filterVisitor); }; sp<GraphicBuffer> buffer = nullptr; if (mCachedBuffer && mCachedBuffer->getWidth() == sampledArea.getWidth() && mCachedBuffer->getHeight() == sampledArea.getHeight()) { buffer = mCachedBuffer; } else { const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_RENDER; sp<GraphicBuffer> buffer = new GraphicBuffer(sampledArea.getWidth(), sampledArea.getHeight(), buffer = new GraphicBuffer(sampledArea.getWidth(), sampledArea.getHeight(), PIXEL_FORMAT_RGBA_8888, 1, usage, "RegionSamplingThread"); } // When calling into SF, we post a message into the SF message queue (so the // screen capture runs on the main thread). This message blocks until the Loading Loading @@ -415,6 +420,12 @@ void RegionSamplingThread::captureSample() { for (size_t d = 0; d < activeDescriptors.size(); ++d) { activeDescriptors[d].listener->onSampleCollected(lumas[d]); } // Extend the lifetime of mCachedBuffer from the previous frame to here to ensure that: // 1) The region sampling thread is the last owner of the buffer, and the freeing of the buffer // happens in this thread, as opposed to the main thread. // 2) The listener(s) receive their notifications prior to freeing the buffer. mCachedBuffer = buffer; ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::noWorkNeeded)); } Loading services/surfaceflinger/RegionSamplingThread.h +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -121,6 +121,8 @@ private: 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 Loading
services/surfaceflinger/RegionSamplingThread.cpp +15 −4 Original line number Diff line number Diff line Loading @@ -377,10 +377,15 @@ void RegionSamplingThread::captureSample() { mFlinger.traverseLayersInDisplay(device, filterVisitor); }; sp<GraphicBuffer> buffer = nullptr; if (mCachedBuffer && mCachedBuffer->getWidth() == sampledArea.getWidth() && mCachedBuffer->getHeight() == sampledArea.getHeight()) { buffer = mCachedBuffer; } else { const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_HW_RENDER; sp<GraphicBuffer> buffer = new GraphicBuffer(sampledArea.getWidth(), sampledArea.getHeight(), buffer = new GraphicBuffer(sampledArea.getWidth(), sampledArea.getHeight(), PIXEL_FORMAT_RGBA_8888, 1, usage, "RegionSamplingThread"); } // When calling into SF, we post a message into the SF message queue (so the // screen capture runs on the main thread). This message blocks until the Loading Loading @@ -415,6 +420,12 @@ void RegionSamplingThread::captureSample() { for (size_t d = 0; d < activeDescriptors.size(); ++d) { activeDescriptors[d].listener->onSampleCollected(lumas[d]); } // Extend the lifetime of mCachedBuffer from the previous frame to here to ensure that: // 1) The region sampling thread is the last owner of the buffer, and the freeing of the buffer // happens in this thread, as opposed to the main thread. // 2) The listener(s) receive their notifications prior to freeing the buffer. mCachedBuffer = buffer; ATRACE_INT(lumaSamplingStepTag, static_cast<int>(samplingStep::noWorkNeeded)); } Loading
services/surfaceflinger/RegionSamplingThread.h +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -121,6 +121,8 @@ private: 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