Bug 1060085 - Add thread-local Fence/Poll/Wait to Basic ShSurf. - r=kamidphish
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 02 Sep 2014 15:16:02 -0700
changeset 203122 9d4fc9f2d5d177b10bc0426b5f21a3fa4fae3d5c
parent 203121 d1bc9a5c17ffa24e12bba028a6e17d0936637a50
child 203123 26c4989e824cd238b0f52b6d9d8e3c9759f80e86
push id48569
push userjgilbert@mozilla.com
push dateTue, 02 Sep 2014 22:16:15 +0000
treeherdermozilla-inbound@9d4fc9f2d5d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1060085
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1060085 - Add thread-local Fence/Poll/Wait to Basic ShSurf. - r=kamidphish
gfx/gl/SharedSurfaceGL.cpp
gfx/gl/SharedSurfaceGL.h
--- a/gfx/gl/SharedSurfaceGL.cpp
+++ b/gfx/gl/SharedSurfaceGL.cpp
@@ -1,20 +1,20 @@
 /* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SharedSurfaceGL.h"
 
+#include "GLBlitHelper.h"
 #include "GLContext.h"
-#include "GLBlitHelper.h"
+#include "GLReadTexImageHelper.h"
+#include "mozilla/gfx/2D.h"
 #include "ScopedGLHelpers.h"
-#include "mozilla/gfx/2D.h"
-#include "GLReadTexImageHelper.h"
 
 namespace mozilla {
 namespace gl {
 
 using gfx::IntSize;
 using gfx::SurfaceFormat;
 
 /*static*/ UniquePtr<SharedSurface_Basic>
@@ -65,16 +65,17 @@ SharedSurface_Basic::SharedSurface_Basic
                                          GLuint tex)
     : SharedSurface(SharedSurfaceType::Basic,
                     AttachmentType::GLTexture,
                     gl,
                     size,
                     hasAlpha)
     , mTex(tex)
     , mFB(0)
+    , mIsDataCurrent(false)
 {
     mGL->MakeCurrent();
     mGL->fGenFramebuffers(1, &mFB);
 
     ScopedBindFramebuffer autoFB(mGL, mFB);
     mGL->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
                               LOCAL_GL_COLOR_ATTACHMENT0,
                               LOCAL_GL_TEXTURE_2D,
@@ -110,16 +111,61 @@ SharedSurface_Basic::Fence()
     // The constructor can fail to get us mData, we should deal with it:
     if (NS_WARN_IF(!mData)) {
         return;
     }
 
     mGL->MakeCurrent();
     ScopedBindFramebuffer autoFB(mGL, mFB);
     ReadPixelsIntoDataSurface(mGL, mData);
+    mIsDataCurrent = true;
+}
+
+bool
+SharedSurface_Basic::WaitSync()
+{
+    MOZ_ASSERT(mIsDataCurrent);
+    return true;
+}
+
+bool
+SharedSurface_Basic::PollSync()
+{
+    MOZ_ASSERT(mIsDataCurrent);
+    return true;
+}
+
+void
+SharedSurface_Basic::Fence_ContentThread_Impl()
+{
+    mIsDataCurrent = false;
+}
+
+bool
+SharedSurface_Basic::WaitSync_ContentThread_Impl()
+{
+    if (!mIsDataCurrent) {
+        mGL->MakeCurrent();
+        ScopedBindFramebuffer autoFB(mGL, mFB);
+        ReadPixelsIntoDataSurface(mGL, mData);
+        mIsDataCurrent = true;
+    }
+    return true;
+}
+
+bool
+SharedSurface_Basic::PollSync_ContentThread_Impl()
+{
+    if (!mIsDataCurrent) {
+        mGL->MakeCurrent();
+        ScopedBindFramebuffer autoFB(mGL, mFB);
+        ReadPixelsIntoDataSurface(mGL, mData);
+        mIsDataCurrent = true;
+    }
+    return true;
 }
 
 ////////////////////////////////////////////////////////////////////////
 // SharedSurface_GLTexture
 
 /*static*/ UniquePtr<SharedSurface_GLTexture>
 SharedSurface_GLTexture::Create(GLContext* prodGL,
                                 GLContext* consGL,
--- a/gfx/gl/SharedSurfaceGL.h
+++ b/gfx/gl/SharedSurfaceGL.h
@@ -11,17 +11,16 @@
 #include "SurfaceTypes.h"
 #include "GLContextTypes.h"
 #include "nsAutoPtr.h"
 #include "gfxTypes.h"
 #include "mozilla/Mutex.h"
 
 #include <queue>
 
-// Forwards:
 namespace mozilla {
     namespace gl {
         class GLContext;
     }
     namespace gfx {
         class DataSourceSurface;
     }
 }
@@ -43,39 +42,39 @@ public:
         MOZ_ASSERT(surf->mType == SharedSurfaceType::Basic);
 
         return (SharedSurface_Basic*)surf;
     }
 
 protected:
     const GLuint mTex;
     GLuint mFB;
-
     RefPtr<gfx::DataSourceSurface> mData;
+    bool mIsDataCurrent;
 
     SharedSurface_Basic(GLContext* gl,
                         const gfx::IntSize& size,
                         bool hasAlpha,
                         gfx::SurfaceFormat format,
                         GLuint tex);
 
 public:
     virtual ~SharedSurface_Basic();
 
     virtual void LockProdImpl() MOZ_OVERRIDE {}
     virtual void UnlockProdImpl() MOZ_OVERRIDE {}
 
 
     virtual void Fence() MOZ_OVERRIDE;
+    virtual bool WaitSync() MOZ_OVERRIDE;
+    virtual bool PollSync() MOZ_OVERRIDE;
 
-    virtual bool WaitSync() MOZ_OVERRIDE {
-        // Since we already store the data in Fence, we're always done already.
-        return true;
-    }
-    virtual bool PollSync() MOZ_OVERRIDE { return true; }
+    virtual void Fence_ContentThread_Impl() MOZ_OVERRIDE;
+    virtual bool WaitSync_ContentThread_Impl() MOZ_OVERRIDE;
+    virtual bool PollSync_ContentThread_Impl() MOZ_OVERRIDE;
 
     virtual GLuint ProdTexture() MOZ_OVERRIDE {
         return mTex;
     }
 
     // Implementation-specific functions below:
     gfx::DataSourceSurface* GetData() {
         return mData;