summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2011-01-13 12:57:21 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-13 12:57:21 -0800
commit3defffe06e6989506698ecdce1be3149a33774c1 (patch)
tree34bff5e8ee751dd2ceba4d399bce65b32a0c77cd /services
parent57ce3909fc05b06585bf11b14a704340a0763401 (diff)
parentf7acf162f8d682c6ebc9af41ca76795b79509193 (diff)
downloadframeworks_base-3defffe06e6989506698ecdce1be3149a33774c1.zip
frameworks_base-3defffe06e6989506698ecdce1be3149a33774c1.tar.gz
frameworks_base-3defffe06e6989506698ecdce1be3149a33774c1.tar.bz2
Merge "Fix remote GraphicBuffer allocation in SurfaceFlinger." into honeycomb
Diffstat (limited to 'services')
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp57
-rw-r--r--services/surfaceflinger/SurfaceFlinger.h19
2 files changed, 55 insertions, 21 deletions
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index c982ea5..967ff1a 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -144,6 +144,11 @@ sp<ISurfaceComposerClient> SurfaceFlinger::createClientConnection()
return bclient;
}
+sp<IGraphicBufferAlloc> SurfaceFlinger::createGraphicBufferAlloc()
+{
+ sp<GraphicBufferAlloc> gba(new GraphicBufferAlloc());
+ return gba;
+}
const GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) const
{
@@ -2267,25 +2272,6 @@ sp<Layer> SurfaceFlinger::getLayer(const sp<ISurface>& sur) const
// ---------------------------------------------------------------------------
-sp<GraphicBuffer> SurfaceFlinger::createGraphicBuffer(uint32_t w, uint32_t h,
- PixelFormat format, uint32_t usage) const {
- // XXX: HACK HACK HACK!!! This should NOT be static, but it is to fix a
- // race between SurfaceFlinger unref'ing the buffer and the client ref'ing
- // it.
- static sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(w, h, format, usage));
- status_t err = graphicBuffer->initCheck();
- if (err != 0) {
- LOGE("createGraphicBuffer: init check failed: %d", err);
- return 0;
- } else if (graphicBuffer->handle == 0) {
- LOGE("createGraphicBuffer: unable to create GraphicBuffer");
- return 0;
- }
- return graphicBuffer;
-}
-
-// ---------------------------------------------------------------------------
-
Client::Client(const sp<SurfaceFlinger>& flinger)
: mFlinger(flinger), mNameGenerator(1)
{
@@ -2465,6 +2451,39 @@ status_t UserClient::setState(int32_t count, const layer_state_t* states) {
// ---------------------------------------------------------------------------
+GraphicBufferAlloc::GraphicBufferAlloc() {}
+
+GraphicBufferAlloc::~GraphicBufferAlloc() {}
+
+sp<GraphicBuffer> GraphicBufferAlloc::createGraphicBuffer(uint32_t w, uint32_t h,
+ PixelFormat format, uint32_t usage) {
+ sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(w, h, format, usage));
+ status_t err = graphicBuffer->initCheck();
+ if (err != 0) {
+ LOGE("createGraphicBuffer: init check failed: %d", err);
+ return 0;
+ } else if (graphicBuffer->handle == 0) {
+ LOGE("createGraphicBuffer: unable to create GraphicBuffer");
+ return 0;
+ }
+ Mutex::Autolock _l(mLock);
+ mBuffers.add(graphicBuffer);
+ return graphicBuffer;
+}
+
+void GraphicBufferAlloc::freeAllGraphicBuffersExcept(int bufIdx) {
+ Mutex::Autolock _l(mLock);
+ if (0 <= bufIdx && bufIdx < mBuffers.size()) {
+ sp<GraphicBuffer> b(mBuffers[bufIdx]);
+ mBuffers.clear();
+ mBuffers.add(b);
+ } else {
+ mBuffers.clear();
+ }
+}
+
+// ---------------------------------------------------------------------------
+
GraphicPlane::GraphicPlane()
: mHw(0)
{
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 48642d4..2f2977a 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -34,6 +34,7 @@
#include <ui/PixelFormat.h>
#include <surfaceflinger/ISurfaceComposer.h>
#include <surfaceflinger/ISurfaceComposerClient.h>
+#include <surfaceflinger/IGraphicBufferAlloc.h>
#include "Barrier.h"
#include "Layer.h"
@@ -119,6 +120,21 @@ private:
sp<SurfaceFlinger> mFlinger;
};
+class GraphicBufferAlloc : public BnGraphicBufferAlloc
+{
+public:
+ GraphicBufferAlloc();
+ virtual ~GraphicBufferAlloc();
+
+ virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
+ PixelFormat format, uint32_t usage);
+ virtual void freeAllGraphicBuffersExcept(int bufIdx);
+
+private:
+ Vector<sp<GraphicBuffer> > mBuffers;
+ Mutex mLock;
+};
+
// ---------------------------------------------------------------------------
class GraphicPlane
@@ -184,6 +200,7 @@ public:
// ISurfaceComposer interface
virtual sp<ISurfaceComposerClient> createConnection();
virtual sp<ISurfaceComposerClient> createClientConnection();
+ virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc();
virtual sp<IMemoryHeap> getCblk() const;
virtual void bootFinished();
virtual void openGlobalTransaction();
@@ -322,8 +339,6 @@ private:
status_t electronBeamOnAnimationImplLocked();
status_t renderScreenToTextureLocked(DisplayID dpy,
GLuint* textureName, GLfloat* uOut, GLfloat* vOut);
- sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h,
- PixelFormat format, uint32_t usage) const;
friend class FreezeLock;
sp<FreezeLock> getFreezeLock() const;