Bug 995065 - Backout bug 947227 on the release branches. r=jgilbert, a=sledru
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 16 Apr 2014 11:25:24 -0400
changeset 183782 cea0324a3ac6
parent 183781 51375c4deaf6
child 183783 92cae49290ae
push id3481
push userryanvm@gmail.com
push date2014-04-16 15:27 +0000
Treeherderresults
reviewersjgilbert, sledru
bugs995065, 947227
milestone29.0
Bug 995065 - Backout bug 947227 on the release branches. r=jgilbert, a=sledru
gfx/gl/SurfaceStream.cpp
gfx/gl/SurfaceStream.h
gfx/gl/SurfaceTypes.h
--- a/gfx/gl/SurfaceStream.cpp
+++ b/gfx/gl/SurfaceStream.cpp
@@ -16,17 +16,17 @@ namespace gfx {
 SurfaceStreamType
 SurfaceStream::ChooseGLStreamType(SurfaceStream::OMTC omtc,
                                   bool preserveBuffer)
 {
     if (omtc == SurfaceStream::OffMainThread) {
         if (preserveBuffer)
             return SurfaceStreamType::TripleBuffer_Copy;
         else
-            return SurfaceStreamType::TripleBuffer;
+            return SurfaceStreamType::TripleBuffer_Async;
     } else {
         if (preserveBuffer)
             return SurfaceStreamType::SingleBuffer;
         else
             return SurfaceStreamType::TripleBuffer;
     }
 }
 
@@ -37,16 +37,19 @@ SurfaceStream::CreateForType(SurfaceStre
 
     switch (type) {
         case SurfaceStreamType::SingleBuffer:
             result = new SurfaceStream_SingleBuffer(prevStream);
             break;
         case SurfaceStreamType::TripleBuffer_Copy:
             result = new SurfaceStream_TripleBuffer_Copy(prevStream);
             break;
+        case SurfaceStreamType::TripleBuffer_Async:
+            result = new SurfaceStream_TripleBuffer_Async(prevStream);
+            break;
         case SurfaceStreamType::TripleBuffer:
             result = new SurfaceStream_TripleBuffer(prevStream);
             break;
         default:
             MOZ_CRASH("Invalid Type.");
     }
 
     result->mGLContext = glContext;
@@ -407,17 +410,19 @@ SurfaceStream_TripleBuffer::SwapProducer
                                          const gfx::IntSize& size)
 {
     PROFILER_LABEL("SurfaceStream_TripleBuffer", "SwapProducer");
 
     MonitorAutoLock lock(mMonitor);
     if (mProducer) {
         RecycleScraps(factory);
 
-        if (mStaging)
+        // If WaitForCompositor succeeds, mStaging has moved to mConsumer.
+        // If it failed, we might have to scrap it.
+        if (mStaging && !WaitForCompositor())
             Scrap(mStaging);
 
         MOZ_ASSERT(!mStaging);
         Move(mProducer, mStaging);
         mStaging->Fence();
     }
 
     MOZ_ASSERT(!mProducer);
@@ -434,10 +439,31 @@ SurfaceStream_TripleBuffer::SwapConsumer
         Scrap(mConsumer);
         Move(mStaging, mConsumer);
         mMonitor.NotifyAll();
     }
 
     return mConsumer;
 }
 
+SurfaceStream_TripleBuffer_Async::SurfaceStream_TripleBuffer_Async(SurfaceStream* prevStream)
+    : SurfaceStream_TripleBuffer(SurfaceStreamType::TripleBuffer_Async, prevStream)
+{
+}
+
+SurfaceStream_TripleBuffer_Async::~SurfaceStream_TripleBuffer_Async()
+{
+}
+
+bool
+SurfaceStream_TripleBuffer_Async::WaitForCompositor()
+{
+    PROFILER_LABEL("SurfaceStream_TripleBuffer_Async", "WaitForCompositor");
+
+    // We are assumed to be locked
+    while (mStaging)
+        mMonitor.Wait();
+
+    return true;
+}
+
 } /* namespace gfx */
 } /* namespace mozilla */
--- a/gfx/gl/SurfaceStream.h
+++ b/gfx/gl/SurfaceStream.h
@@ -178,16 +178,19 @@ public:
 
 class SurfaceStream_TripleBuffer
     : public SurfaceStream
 {
 protected:
     SharedSurface* mStaging;
     SharedSurface* mConsumer;
 
+    // Returns true if we were able to wait, false if not
+    virtual bool WaitForCompositor() { return false; }
+
     // To support subclasses initializing the mType.
     SurfaceStream_TripleBuffer(SurfaceStreamType type, SurfaceStream* prevStream);
 
 public:
     SurfaceStream_TripleBuffer(SurfaceStream* prevStream);
     virtual ~SurfaceStream_TripleBuffer();
 
 private:
@@ -199,12 +202,24 @@ public:
     virtual SharedSurface* SwapProducer(SurfaceFactory* factory,
                                         const gfx::IntSize& size);
 
     virtual SharedSurface* SwapConsumer_NoWait();
 
     virtual void SurrenderSurfaces(SharedSurface*& producer, SharedSurface*& consumer);
 };
 
+class SurfaceStream_TripleBuffer_Async
+    : public SurfaceStream_TripleBuffer
+{
+protected:
+    virtual bool WaitForCompositor();
+
+public:
+    SurfaceStream_TripleBuffer_Async(SurfaceStream* prevStream);
+    virtual ~SurfaceStream_TripleBuffer_Async();
+};
+
+
 } /* namespace gfx */
 } /* namespace mozilla */
 
 #endif /* SURFACESTREAM_H_ */
--- a/gfx/gl/SurfaceTypes.h
+++ b/gfx/gl/SurfaceTypes.h
@@ -82,16 +82,17 @@ MOZ_BEGIN_ENUM_CLASS(SharedSurfaceType, 
 
     Max
 MOZ_END_ENUM_CLASS(SharedSurfaceType)
 
 
 MOZ_BEGIN_ENUM_CLASS(SurfaceStreamType, uint8_t)
     SingleBuffer,
     TripleBuffer_Copy,
+    TripleBuffer_Async,
     TripleBuffer,
     Max
 MOZ_END_ENUM_CLASS(SurfaceStreamType)
 
 
 MOZ_BEGIN_ENUM_CLASS(APITypeT, uint8_t)
     Generic = 0,