Fix remote GraphicBuffer allocation in SurfaceFlinger.
This change fixes a horrible hack that I did to allow application
processes to create GraphicBuffer objects by making a binder call to
SurfaceFlinger. This change introduces a new binder interface
specifically for doing this, and does it in such a way that
SurfaceFlinger will maintain a reference to the buffers until the app is
done with them.
Change-Id: Icb240397c6c206d7f69124c1497a829f051cb49b
diff --git a/include/gui/SurfaceTexture.h b/include/gui/SurfaceTexture.h
index 09cf2a2..002e48b 100644
--- a/include/gui/SurfaceTexture.h
+++ b/include/gui/SurfaceTexture.h
@@ -26,12 +26,15 @@
#include <ui/GraphicBuffer.h>
#include <utils/threads.h>
+#include <utils/Vector.h>
#define ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID "mSurfaceTexture"
namespace android {
// ----------------------------------------------------------------------------
+class IGraphicBufferAlloc;
+
class SurfaceTexture : public BnSurfaceTexture {
public:
enum { MIN_BUFFER_SLOTS = 3 };
@@ -140,6 +143,12 @@
// reset mCurrentTexture to INVALID_BUFFER_SLOT.
int mCurrentTexture;
+ // mCurrentTextureBuf is the graphic buffer of the current texture. It's
+ // possible that this buffer is not associated with any buffer slot, so we
+ // must track it separately in order to properly use
+ // IGraphicBufferAlloc::freeAllGraphicBuffersExcept.
+ sp<GraphicBuffer> mCurrentTextureBuf;
+
// mCurrentCrop is the crop rectangle that applies to the current texture.
// It gets set to mLastQueuedCrop each time updateTexImage is called.
Rect mCurrentCrop;
@@ -176,6 +185,16 @@
// changed with a call to setTexName.
const GLuint mTexName;
+ // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
+ // allocate new GraphicBuffer objects.
+ sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
+
+ // mAllocdBuffers is mirror of the list of buffers that SurfaceFlinger is
+ // referencing. This is kept so that gralloc implementations do not need to
+ // properly handle the case where SurfaceFlinger no longer holds a reference
+ // to a buffer, but other processes do.
+ Vector<sp<GraphicBuffer> > mAllocdBuffers;
+
// mMutex is the mutex used to prevent concurrent access to the member
// variables of SurfaceTexture objects. It must be locked whenever the
// member variables are accessed.