Bug 1049957 - Use RefPtr for SurfaceStream. - r=kamidphish
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 15 Aug 2014 17:38:07 -0700
changeset 199930 2055bb42b4e5a25d15cbbb529c24ea6836b4105c
parent 199929 0c2662b805d2230716216777e6730527e8cf1ec0
child 199931 57a7fffebc80722f508398b8fda26c759f255ba2
push id9784
push userryanvm@gmail.com
push dateSat, 16 Aug 2014 21:45:40 +0000
treeherderb2g-inbound@94ba78a42305 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1049957
milestone34.0a1
Bug 1049957 - Use RefPtr for SurfaceStream. - r=kamidphish
gfx/gl/GLScreenBuffer.cpp
gfx/gl/GLScreenBuffer.h
gfx/gl/SurfaceStream.cpp
gfx/gl/SurfaceStream.h
--- a/gfx/gl/GLScreenBuffer.cpp
+++ b/gfx/gl/GLScreenBuffer.cpp
@@ -53,21 +53,20 @@ GLScreenBuffer::Create(GLContext* gl,
     if (!factory) {
         factory = SurfaceFactory_IOSurface::Create(gl, caps);
     }
 #endif
 
     if (!factory)
         factory = new SurfaceFactory_Basic(gl, caps);
 
-    SurfaceStream* stream = SurfaceStream::CreateForType(
-        SurfaceStream::ChooseGLStreamType(SurfaceStream::MainThread,
-                                          caps.preserve),
-        gl,
-        nullptr);
+    auto streamType = SurfaceStream::ChooseGLStreamType(SurfaceStream::MainThread,
+                                                        caps.preserve);
+    RefPtr<SurfaceStream> stream;
+    stream = SurfaceStream::CreateForType(streamType, gl, nullptr);
 
     UniquePtr<GLScreenBuffer> ret( new GLScreenBuffer(gl, caps,
                                                       Move(factory),
                                                       stream) );
     return Move(ret);
 }
 
 GLScreenBuffer::~GLScreenBuffer()
@@ -382,20 +381,18 @@ GLScreenBuffer::Morph(SurfaceFactory* ne
     if (newFactory) {
         delete mFactory;
         mFactory = newFactory;
     }
 
     if (mStream->mType == streamType)
         return;
 
-    SurfaceStream* newStream = SurfaceStream::CreateForType(streamType, mGL, mStream);
-    MOZ_ASSERT(newStream);
-
-    mStream = newStream;
+    mStream = SurfaceStream::CreateForType(streamType, mGL, mStream);
+    MOZ_ASSERT(mStream);
 }
 
 bool
 GLScreenBuffer::Attach(SharedSurface* surf, const gfx::IntSize& size)
 {
     ScopedBindFramebuffer autoFB(mGL);
 
     if (mRead && SharedSurf())
--- a/gfx/gl/GLScreenBuffer.h
+++ b/gfx/gl/GLScreenBuffer.h
@@ -144,17 +144,17 @@ protected:
 #ifdef DEBUG
     bool mInInternalMode_DrawFB;
     bool mInInternalMode_ReadFB;
 #endif
 
     GLScreenBuffer(GLContext* gl,
                    const SurfaceCaps& caps,
                    SurfaceFactory* factory,
-                   SurfaceStream* stream)
+                   const RefPtr<SurfaceStream>& stream)
         : mGL(gl)
         , mCaps(caps)
         , mFactory(factory)
         , mStream(stream)
         , mDraw(nullptr)
         , mRead(nullptr)
         , mNeedsBlit(true)
         , mUserDrawFB(0)
--- a/gfx/gl/SurfaceStream.cpp
+++ b/gfx/gl/SurfaceStream.cpp
@@ -25,20 +25,20 @@ SurfaceStream::ChooseGLStreamType(Surfac
     } else {
         if (preserveBuffer)
             return SurfaceStreamType::SingleBuffer;
         else
             return SurfaceStreamType::TripleBuffer;
     }
 }
 
-SurfaceStream*
+TemporaryRef<SurfaceStream>
 SurfaceStream::CreateForType(SurfaceStreamType type, mozilla::gl::GLContext* glContext, SurfaceStream* prevStream)
 {
-    SurfaceStream* result = nullptr;
+    RefPtr<SurfaceStream> result;
 
     switch (type) {
         case SurfaceStreamType::SingleBuffer:
             result = new SurfaceStream_SingleBuffer(prevStream);
             break;
         case SurfaceStreamType::TripleBuffer_Copy:
             result = new SurfaceStream_TripleBuffer_Copy(prevStream);
             break;
@@ -48,17 +48,18 @@ SurfaceStream::CreateForType(SurfaceStre
         case SurfaceStreamType::TripleBuffer:
             result = new SurfaceStream_TripleBuffer(prevStream);
             break;
         default:
             MOZ_CRASH("Invalid Type.");
     }
 
     result->mGLContext = glContext;
-    return result;
+
+    return result.forget();
 }
 
 bool
 SurfaceStream_TripleBuffer::CopySurfaceToProducer(SharedSurface* src, SurfaceFactory* factory)
 {
     if (!mProducer) {
         New(factory, src->mSize, mProducer);
         if (!mProducer) {
--- a/gfx/gl/SurfaceStream.h
+++ b/gfx/gl/SurfaceStream.h
@@ -29,19 +29,19 @@ public:
     typedef enum {
         MainThread,
         OffMainThread
     } OMTC;
 
     static SurfaceStreamType ChooseGLStreamType(OMTC omtc,
                                                 bool preserveBuffer);
 
-    static SurfaceStream* CreateForType(SurfaceStreamType type,
-                                        mozilla::gl::GLContext* glContext,
-                                        SurfaceStream* prevStream = nullptr);
+    static TemporaryRef<SurfaceStream> CreateForType(SurfaceStreamType type,
+                                                     mozilla::gl::GLContext* glContext,
+                                                     SurfaceStream* prevStream = nullptr);
 
     const SurfaceStreamType mType;
 
     mozilla::gl::GLContext* GLContext() const { return mGLContext; }
 
 
 protected:
     // |mProd| is owned by us, but can be ripped away when