rework how we take screenshots for a CPU consumer
We're not using IMemoryHeap as a transport anymore,
instead we're providing a CpuConsumer and use the
IGraphicBufferProducer version of the screenshot API.
However, some GPU drivers don't support properly
a GPU to CPU path, to work around this, we use a
temporary BufferQueue on the server side for the
GL rendering, and we use glReadPixels into the
CpuConsumer (we're now using a CPU to CPU path
which is always supported).
Currently this "wrapping" is always performed,
but it can be bypassed on devices that support
the GPU to CPU path.
This also addresses a DoS attack vector on
SurfaceFlinger, where an application could
consume all of SF's filedescriptors by creating
a lot of screenshots in a row.
Bug: 8390553
Change-Id: I9e81514c2a7711b9bb393f74305be7d2abe08f1c
diff --git a/include/gui/SurfaceComposerClient.h b/include/gui/SurfaceComposerClient.h
index 38c931d..23655c7 100644
--- a/include/gui/SurfaceComposerClient.h
+++ b/include/gui/SurfaceComposerClient.h
@@ -30,6 +30,7 @@
#include <ui/PixelFormat.h>
+#include <gui/CpuConsumer.h>
#include <gui/SurfaceControl.h>
namespace android {
@@ -38,7 +39,6 @@
class DisplayInfo;
class Composer;
-class IMemoryHeap;
class ISurfaceComposerClient;
class IGraphicBufferProducer;
class Region;
@@ -164,10 +164,9 @@
uint32_t minLayerZ, uint32_t maxLayerZ);
private:
- sp<IMemoryHeap> mHeap;
- uint32_t mWidth;
- uint32_t mHeight;
- PixelFormat mFormat;
+ mutable sp<CpuConsumer> mCpuConsumer;
+ CpuConsumer::LockedBuffer mBuffer;
+ bool mHaveBuffer;
public:
ScreenshotClient();
@@ -180,6 +179,8 @@
uint32_t reqWidth, uint32_t reqHeight,
uint32_t minLayerZ, uint32_t maxLayerZ);
+ sp<CpuConsumer> getCpuConsumer() const;
+
// release memory occupied by the screenshot
void release();