Hoist mWidget into the Compositor base class. (bug 1264545 part 1, r=nical)
authorDavid Anderson <danderson@mozilla.com>
Fri, 29 Apr 2016 19:20:40 -0400
changeset 295587 25d57a3a2abd86b4283c84b8380b49dd5cda33cb
parent 295586 f8896b71e9bc4737ab067515d1bf03fe679398a6
child 295588 d1dad3cf31c1590d30af46c2a93e8fdbe6fe8019
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1264545
milestone49.0a1
Hoist mWidget into the Compositor base class. (bug 1264545 part 1, r=nical)
gfx/layers/Compositor.h
gfx/layers/basic/BasicCompositor.cpp
gfx/layers/basic/BasicCompositor.h
gfx/layers/d3d11/CompositorD3D11.cpp
gfx/layers/d3d11/CompositorD3D11.h
gfx/layers/d3d9/CompositorD3D9.cpp
gfx/layers/d3d9/CompositorD3D9.h
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/CompositorOGL.h
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -184,32 +184,34 @@ enum SurfaceInitMode
 class Compositor
 {
 protected:
   virtual ~Compositor() {}
 
 public:
   NS_INLINE_DECL_REFCOUNTING(Compositor)
 
-  explicit Compositor(CompositorBridgeParent* aParent = nullptr)
+  explicit Compositor(nsIWidget* aWidget, CompositorBridgeParent* aParent = nullptr)
     : mCompositorID(0)
     , mDiagnosticTypes(DiagnosticTypes::NO_DIAGNOSTIC)
     , mParent(aParent)
     , mScreenRotation(ROTATION_0)
+    , mWidget(aWidget)
   {
   }
 
   virtual already_AddRefed<DataTextureSource> CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) = 0;
 
   virtual already_AddRefed<DataTextureSource>
   CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface) { return nullptr; }
 
   virtual bool Initialize() = 0;
   virtual void Destroy() = 0;
-  virtual void DetachWidget() {}
+
+  virtual void DetachWidget() { mWidget = nullptr; }
 
   /**
    * Return true if the effect type is supported.
    *
    * By default Compositor implementations should support all effects but in
    * some rare cases it is not possible to support an effect efficiently.
    * This is the case for BasicCompositor with EffectYCbCr.
    */
@@ -467,19 +469,17 @@ public:
   /**
    * Call before rendering begins to ensure the compositor is ready to
    * composite. Returns false if rendering should be aborted.
    */
   virtual bool Ready() { return true; }
 
   virtual void ForcePresent() { }
 
-  // XXX I expect we will want to move mWidget into this class and implement
-  // these methods properly.
-  virtual nsIWidget* GetWidget() const { return nullptr; }
+  nsIWidget* GetWidget() const { return mWidget; }
 
   virtual bool HasImageHostOverlays() { return false; }
 
   virtual void AddImageHostOverlay(ImageHostOverlay* aOverlay) {}
 
   virtual void RemoveImageHostOverlay(ImageHostOverlay* aOverlay) {}
 
   /**
@@ -579,16 +579,18 @@ protected:
   size_t mPixelsPerFrame;
   size_t mPixelsFilled;
 
   ScreenRotation mScreenRotation;
 
   RefPtr<gfx::DrawTarget> mTarget;
   gfx::IntRect mTargetBounds;
 
+  nsIWidget* mWidget;
+
 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
   FenceHandle mReleaseFenceHandle;
 #endif
 
 private:
   static LayersBackend sBackend;
 
 };
--- a/gfx/layers/basic/BasicCompositor.cpp
+++ b/gfx/layers/basic/BasicCompositor.cpp
@@ -74,18 +74,17 @@ public:
   }
 
 public:
   RefPtr<gfx::DataSourceSurface> mSurface;
   bool mWrappingExistingData;
 };
 
 BasicCompositor::BasicCompositor(CompositorBridgeParent* aParent, nsIWidget *aWidget)
-  : Compositor(aParent)
-  , mWidget(aWidget)
+  : Compositor(aWidget, aParent)
   , mDidExternalComposition(false)
 {
   MOZ_COUNT_CTOR(BasicCompositor);
 
   mMaxTextureSize =
     Factory::GetMaxSurfaceSize(gfxPlatform::GetPlatform()->GetContentBackendFor(LayersBackend::LAYERS_BASIC));
 }
 
@@ -114,18 +113,18 @@ BasicCompositingRenderTarget::BindRender
     mClearOnBind = false;
   }
 }
 
 void BasicCompositor::DetachWidget()
 {
   if (mWidget) {
     mWidget->CleanupRemoteDrawing();
-    mWidget = nullptr;
   }
+  Compositor::DetachWidget();
 }
 
 TextureFactoryIdentifier
 BasicCompositor::GetTextureFactoryIdentifier()
 {
   TextureFactoryIdentifier ident(LayersBackend::LAYERS_BASIC,
                                  XRE_GetProcessType(),
                                  GetMaxTextureSize());
--- a/gfx/layers/basic/BasicCompositor.h
+++ b/gfx/layers/basic/BasicCompositor.h
@@ -121,25 +121,20 @@ public:
 #ifdef MOZ_DUMP_PAINTING
   virtual const char* Name() const override { return "Basic"; }
 #endif // MOZ_DUMP_PAINTING
 
   virtual LayersBackend GetBackendType() const override {
     return LayersBackend::LAYERS_BASIC;
   }
 
-  virtual nsIWidget* GetWidget() const override { return mWidget; }
-
   gfx::DrawTarget *GetDrawTarget() { return mDrawTarget; }
 
 private:
 
-  // Widget associated with this compositor
-  nsIWidget *mWidget;
-
   // The final destination surface
   RefPtr<gfx::DrawTarget> mDrawTarget;
   // The current render target for drawing
   RefPtr<BasicCompositingRenderTarget> mRenderTarget;
 
   LayoutDeviceIntRect mInvalidRect;
   LayoutDeviceIntRegion mInvalidRegion;
   bool mDidExternalComposition;
--- a/gfx/layers/d3d11/CompositorD3D11.cpp
+++ b/gfx/layers/d3d11/CompositorD3D11.cpp
@@ -155,19 +155,18 @@ private:
   }
 
   // Only used during initialization.
   RefPtr<ID3D11Device> mDevice;
   bool mInitOkay;
 };
 
 CompositorD3D11::CompositorD3D11(CompositorBridgeParent* aParent, nsIWidget* aWidget)
-  : Compositor(aParent)
+  : Compositor(aWidget, aParent)
   , mAttachments(nullptr)
-  , mWidget(aWidget)
   , mHwnd(nullptr)
   , mDisableSequenceForNextFrame(false)
   , mVerifyBuffersFailed(false)
 {
 }
 
 CompositorD3D11::~CompositorD3D11()
 {
--- a/gfx/layers/d3d11/CompositorD3D11.h
+++ b/gfx/layers/d3d11/CompositorD3D11.h
@@ -44,17 +44,16 @@ class CompositorD3D11 : public Composito
 public:
   CompositorD3D11(CompositorBridgeParent* aParent, nsIWidget* aWidget);
   ~CompositorD3D11();
 
   virtual CompositorD3D11* AsCompositorD3D11() override { return this; }
 
   virtual bool Initialize() override;
   virtual void Destroy() override {}
-  virtual void DetachWidget() override { mWidget = nullptr; }
 
   virtual TextureFactoryIdentifier
     GetTextureFactoryIdentifier() override;
 
   virtual already_AddRefed<DataTextureSource>
     CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) override;
 
   virtual bool CanUseCanvasLayerForSize(const gfx::IntSize& aSize) override;
@@ -144,18 +143,16 @@ public:
 #endif
 
   virtual LayersBackend GetBackendType() const override {
     return LayersBackend::LAYERS_D3D11;
   }
 
   virtual void ForcePresent();
 
-  virtual nsIWidget* GetWidget() const override { return mWidget; }
-
   ID3D11Device* GetDevice() { return mDevice; }
 
   ID3D11DeviceContext* GetDC() { return mContext; }
 
 private:
   enum Severity {
     Recoverable,
     DebugAssert,
@@ -186,18 +183,16 @@ private:
   RefPtr<ID3D11DeviceContext> mContext;
   RefPtr<ID3D11Device> mDevice;
   RefPtr<IDXGISwapChain> mSwapChain;
   RefPtr<CompositingRenderTargetD3D11> mDefaultRT;
   RefPtr<CompositingRenderTargetD3D11> mCurrentRT;
 
   DeviceAttachmentsD3D11* mAttachments;
 
-  nsIWidget* mWidget;
-
   LayoutDeviceIntSize mSize;
 
   HWND mHwnd;
 
   D3D_FEATURE_LEVEL mFeatureLevel;
 
   VertexShaderConstants mVSConstants;
   PixelShaderConstants mPSConstants;
--- a/gfx/layers/d3d9/CompositorD3D9.cpp
+++ b/gfx/layers/d3d9/CompositorD3D9.cpp
@@ -19,18 +19,17 @@
 #include "mozilla/layers/CompositorBridgeParent.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
 
 CompositorD3D9::CompositorD3D9(CompositorBridgeParent* aParent, nsIWidget *aWidget)
-  : Compositor(aParent)
-  , mWidget(aWidget)
+  : Compositor(aWidget, aParent)
   , mDeviceResetCount(0)
   , mFailedResetAttempts(0)
 {
 }
 
 CompositorD3D9::~CompositorD3D9()
 {
   mSwapChain = nullptr;
--- a/gfx/layers/d3d9/CompositorD3D9.h
+++ b/gfx/layers/d3d9/CompositorD3D9.h
@@ -23,17 +23,16 @@ class CompositorD3D9 : public Compositor
 public:
   CompositorD3D9(CompositorBridgeParent* aParent, nsIWidget *aWidget);
   ~CompositorD3D9();
 
   virtual CompositorD3D9* AsCompositorD3D9() override { return this; }
 
   virtual bool Initialize() override;
   virtual void Destroy() override {}
-  virtual void DetachWidget() override { mWidget = nullptr; }
 
   virtual TextureFactoryIdentifier
     GetTextureFactoryIdentifier() override;
 
   virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) override;
   virtual int32_t GetMaxTextureSize() const final;
 
   virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) override {}
@@ -82,18 +81,16 @@ public:
 #ifdef MOZ_DUMP_PAINTING
   virtual const char* Name() const override { return "Direct3D9"; }
 #endif
 
   virtual LayersBackend GetBackendType() const override {
     return LayersBackend::LAYERS_D3D9;
   }
 
-  virtual nsIWidget* GetWidget() const override { return mWidget; }
-
   IDirect3DDevice9* device() const
   {
     // If the reset counts don't match it means the device was lost and we are
     // in the process of recreating a new one or will be soon.
     // cf. comment in EnsureSwapChain.
     return mDeviceManager && mDeviceResetCount == mDeviceManager->GetDeviceResetCount()
            ? mDeviceManager->device()
            : nullptr;
@@ -171,19 +168,16 @@ private:
   void ReportFailure(const nsACString &aMsg, HRESULT aCode);
 
   /* Device manager instance for this compositor */
   RefPtr<DeviceManagerD3D9> mDeviceManager;
 
   /* Swap chain associated with this compositor */
   RefPtr<SwapChainD3D9> mSwapChain;
 
-  /* Widget associated with this layer manager */
-  nsIWidget *mWidget;
-
   RefPtr<CompositingRenderTargetD3D9> mDefaultRT;
   RefPtr<CompositingRenderTargetD3D9> mCurrentRT;
 
   LayoutDeviceIntSize mSize;
 
   uint32_t mDeviceResetCount;
   uint32_t mFailedResetAttempts;
 };
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -81,18 +81,17 @@ CompositorOGL::BindBackdrop(ShaderProgra
   mGLContext->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
   mGLContext->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
   aProgram->SetBackdropTextureUnit(aTexUnit - LOCAL_GL_TEXTURE0);
 }
 
 CompositorOGL::CompositorOGL(CompositorBridgeParent* aParent,
                              nsIWidget *aWidget, int aSurfaceWidth,
                              int aSurfaceHeight, bool aUseExternalSurfaceSize)
-  : Compositor(aParent)
-  , mWidget(aWidget)
+  : Compositor(aWidget, aParent)
   , mWidgetSize(-1, -1)
   , mSurfaceSize(aSurfaceWidth, aSurfaceHeight)
   , mHasBGRA(0)
   , mUseExternalSurfaceSize(aUseExternalSurfaceSize)
   , mFrameInProgress(false)
   , mDestroyed(false)
   , mViewportSize(0, 0)
   , mCurrentProgram(nullptr)
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -205,18 +205,16 @@ public:
 
   virtual already_AddRefed<DataTextureSource>
   CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) override;
 
   virtual bool Initialize() override;
 
   virtual void Destroy() override;
 
-  virtual void DetachWidget() override { mWidget = nullptr; }
-
   virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() override
   {
     TextureFactoryIdentifier result =
       TextureFactoryIdentifier(LayersBackend::LAYERS_OPENGL,
                                XRE_GetProcessType(),
                                GetMaxTextureSize(),
                                mFBOTextureTarget == LOCAL_GL_TEXTURE_2D,
                                SupportsPartialTextureUpdate());
@@ -274,18 +272,16 @@ public:
 
   virtual LayersBackend GetBackendType() const override {
     return LayersBackend::LAYERS_OPENGL;
   }
 
   virtual void Pause() override;
   virtual bool Resume() override;
 
-  virtual nsIWidget* GetWidget() const override { return mWidget; }
-
   virtual bool HasImageHostOverlays() override
   {
 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 21
     return mImageHostOverlays.Count() > 0;
 #else
     return false;
 #endif
   }
@@ -348,17 +344,16 @@ private:
                         const gfx::Rect& aClipRect,
                         const EffectChain& aEffectChain,
                         gfx::Float aOpacity,
                         const gfx::Matrix4x4& aTransform);
 
   void PrepareViewport(CompositingRenderTargetOGL *aRenderTarget);
 
   /** Widget associated with this compositor */
-  nsIWidget *mWidget;
   LayoutDeviceIntSize mWidgetSize;
   RefPtr<GLContext> mGLContext;
   UniquePtr<GLBlitTextureImageHelper> mBlitTextureImageHelper;
   gfx::Matrix4x4 mProjMatrix;
 
   /** The size of the surface we are rendering to */
   gfx::IntSize mSurfaceSize;