Backed out changeset 48667a14f94d (bug 1092360) for test bustage / crashes on a CLOSED TREE
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Fri, 14 Nov 2014 08:14:22 +0100
changeset 240031 1f809f55b139534f9627591d0aca55b9768be7d4
parent 240030 c98cb03a84755209e20208c800eef4457e31a510
child 240032 536546ad1bd91914744fcd7a7986cea606cb6057
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1092360
milestone36.0a1
backs out48667a14f94dcc46be8bb69cea1b7020eece58a3
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
Backed out changeset 48667a14f94d (bug 1092360) for test bustage / crashes on a CLOSED TREE
gfx/layers/Compositor.cpp
gfx/layers/Compositor.h
gfx/layers/basic/BasicCompositor.cpp
gfx/layers/basic/BasicCompositor.h
gfx/layers/composite/ContainerLayerComposite.cpp
gfx/layers/composite/ContainerLayerComposite.h
gfx/layers/composite/LayerManagerComposite.cpp
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.cpp
+++ b/gfx/layers/Compositor.cpp
@@ -12,28 +12,16 @@
 
 namespace mozilla {
 namespace gfx {
 class Matrix4x4;
 }
 
 namespace layers {
 
-Compositor::Compositor(PCompositorParent* aParent)
-  : mCompositorID(0)
-  , mDiagnosticTypes(DiagnosticTypes::NO_DIAGNOSTIC)
-  , mParent(aParent)
-  , mScreenRotation(ROTATION_0)
-{
-}
-
-Compositor::~Compositor()
-{
-}
-
 /* static */ LayersBackend Compositor::sBackend = LayersBackend::LAYERS_NONE;
 /* static */ LayersBackend
 Compositor::GetBackend()
 {
   AssertOnCompositorThread();
   return sBackend;
 }
 
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -177,22 +177,28 @@ enum SurfaceInitMode
  * by CreateRenderTarget or CreateRenderTargetFromSource.
  *
  * The target and viewport methods can be called before any DrawQuad call and
  * affect any subsequent DrawQuad calls.
  */
 class Compositor
 {
 protected:
-  virtual ~Compositor();
+  virtual ~Compositor() {}
 
 public:
   NS_INLINE_DECL_REFCOUNTING(Compositor)
 
-  explicit Compositor(PCompositorParent* aParent = nullptr);
+  explicit Compositor(PCompositorParent* aParent = nullptr)
+    : mCompositorID(0)
+    , mDiagnosticTypes(DiagnosticTypes::NO_DIAGNOSTIC)
+    , mParent(aParent)
+    , mScreenRotation(ROTATION_0)
+  {
+  }
 
   virtual TemporaryRef<DataTextureSource> CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) = 0;
   virtual bool Initialize() = 0;
   virtual void Destroy() = 0;
 
   /**
    * Return true if the effect type is supported.
    *
@@ -467,22 +473,16 @@ public:
   ScreenRotation GetScreenRotation() const {
     return mScreenRotation;
   }
 
   void SetScreenRotation(ScreenRotation aRotation) {
     mScreenRotation = aRotation;
   }
 
-  /**
-   * This is called to set the composition target (the screen or an offscreen target)
-   * after we've ran the prepare phase. This must be called after BeginFrame.
-   */
-  virtual void SetFinalDestinationTarget() = 0;
-
 protected:
   void DrawDiagnosticsInternal(DiagnosticFlags aFlags,
                                const gfx::Rect& aVisibleRect,
                                const gfx::Rect& aClipRect,
                                const gfx::Matrix4x4& transform,
                                uint32_t aFlashCounter);
 
   bool ShouldDrawDiagnostics(DiagnosticFlags);
@@ -505,17 +505,16 @@ protected:
   size_t mPixelsFilled;
 
   ScreenRotation mScreenRotation;
 
   virtual gfx::IntSize GetWidgetSize() const = 0;
 
   RefPtr<gfx::DrawTarget> mTarget;
   nsIntRect mTargetBounds;
-  RefPtr<CompositingRenderTarget> mFinalDestinationTarget;
 
 private:
   static LayersBackend sBackend;
 
 };
 
 // Returns the number of rects. (Up to 4)
 typedef gfx::Rect decomposedRectArrayT[4];
--- a/gfx/layers/basic/BasicCompositor.cpp
+++ b/gfx/layers/basic/BasicCompositor.cpp
@@ -80,26 +80,23 @@ void BasicCompositor::Destroy()
 {
   mWidget->CleanupRemoteDrawing();
   mWidget = nullptr;
 }
 
 TemporaryRef<CompositingRenderTarget>
 BasicCompositor::CreateRenderTarget(const IntRect& aRect, SurfaceInitMode aInit)
 {
-  MOZ_ASSERT(aRect.width != 0 && aRect.height != 0,
-             "Trying to create a render target of invalid size");
+  MOZ_ASSERT(aRect.width != 0 && aRect.height != 0, "Trying to create a render target of invalid size");
 
   if (aRect.width * aRect.height == 0) {
     return nullptr;
   }
 
-  RefPtr<DrawTarget> target =
-    static_cast<BasicCompositingRenderTarget*>(mFinalDestinationTarget.get())->mDrawTarget->
-      CreateSimilarDrawTarget(aRect.Size(), SurfaceFormat::B8G8R8A8);
+  RefPtr<DrawTarget> target = mDrawTarget->CreateSimilarDrawTarget(aRect.Size(), SurfaceFormat::B8G8R8A8);
 
   if (!target) {
     return nullptr;
   }
 
   RefPtr<BasicCompositingRenderTarget> rt = new BasicCompositingRenderTarget(target, aRect);
 
   return rt.forget();
@@ -438,33 +435,33 @@ BasicCompositor::BeginFrame(const nsIntR
   // copy this into mDrawTarget (the widget), and/or mTarget in EndFrame()
   RefPtr<CompositingRenderTarget> target = CreateRenderTarget(mInvalidRect, INIT_MODE_CLEAR);
   if (!target) {
     if (!mTarget) {
       mWidget->EndRemoteDrawing();
     }
     return;
   }
-  mFinalDestinationTarget = target;
+  SetRenderTarget(target);
 
   // We only allocate a surface sized to the invalidated region, so we need to
   // translate future coordinates.
   mRenderTarget->mDrawTarget->SetTransform(Matrix::Translation(-invalidRect.x,
                                                                -invalidRect.y));
 
   gfxUtils::ClipToRegion(mRenderTarget->mDrawTarget, invalidRegionSafe);
 
   if (aRenderBoundsOut) {
     *aRenderBoundsOut = rect;
   }
 
   if (aClipRectIn) {
-    mDrawTarget->PushClipRect(*aClipRectIn);
+    mRenderTarget->mDrawTarget->PushClipRect(*aClipRectIn);
   } else {
-    mDrawTarget->PushClipRect(rect);
+    mRenderTarget->mDrawTarget->PushClipRect(rect);
     if (aClipRectOut) {
       *aClipRectOut = rect;
     }
   }
 }
 
 void
 BasicCompositor::EndFrame()
@@ -501,23 +498,21 @@ BasicCompositor::EndFrame()
                       IntPoint(r->x - offset.x, r->y - offset.y));
   }
   if (!mTarget) {
     mWidget->EndRemoteDrawing();
   }
 
   mDrawTarget = nullptr;
   mRenderTarget = nullptr;
-  mFinalDestinationTarget = nullptr;
 }
 
 void
 BasicCompositor::AbortFrame()
 {
   mRenderTarget->mDrawTarget->PopClip();
   mRenderTarget->mDrawTarget->PopClip();
   mDrawTarget = nullptr;
   mRenderTarget = nullptr;
-  mFinalDestinationTarget = nullptr;
 }
 
 }
 }
--- a/gfx/layers/basic/BasicCompositor.h
+++ b/gfx/layers/basic/BasicCompositor.h
@@ -116,20 +116,16 @@ public:
   virtual LayersBackend GetBackendType() const MOZ_OVERRIDE {
     return LayersBackend::LAYERS_BASIC;
   }
 
   virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; }
 
   gfx::DrawTarget *GetDrawTarget() { return mDrawTarget; }
 
-  virtual void SetFinalDestinationTarget() MOZ_OVERRIDE {
-    MOZ_ASSERT(mFinalDestinationTarget);
-    SetRenderTarget(mFinalDestinationTarget);
-  }
 private:
 
   virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return mWidgetSize; }
 
   // Widget associated with this compositor
   nsIWidget *mWidget;
   gfx::IntSize mWidgetSize;
 
--- a/gfx/layers/composite/ContainerLayerComposite.cpp
+++ b/gfx/layers/composite/ContainerLayerComposite.cpp
@@ -133,18 +133,16 @@ struct PreparedData
 };
 
 // ContainerPrepare is shared between RefLayer and ContainerLayer
 template<class ContainerT> void
 ContainerPrepare(ContainerT* aContainer,
                  LayerManagerComposite* aManager,
                  const RenderTargetIntRect& aClipRect)
 {
-  Compositor* compositor = aManager->GetCompositor();
-
   aContainer->mPrepared = MakeUnique<PreparedData>();
   aContainer->mPrepared->mNeedsSurfaceCopy = false;
 
   /**
    * Determine which layers to draw.
    */
   nsAutoTArray<Layer*, 12> children;
   aContainer->SortChildrenBy3DZOrder(children);
@@ -181,22 +179,17 @@ ContainerPrepare(ContainerT* aContainer,
   // DefaultComputeSupportsComponentAlphaChildren can mutate aContainer so call it unconditionally
   aContainer->DefaultComputeSupportsComponentAlphaChildren(&surfaceCopyNeeded);
   if (aContainer->UseIntermediateSurface()) {
     MOZ_PERFORMANCE_WARNING("gfx", "[%p] Container layer requires intermediate surface\n", aContainer);
     if (!surfaceCopyNeeded) {
       // If we don't need a copy we can render to the intermediate now to avoid
       // unecessary render target switching. This brings a big perf boost on mobile gpus.
       RefPtr<CompositingRenderTarget> surface = CreateTemporaryTarget(aContainer, aManager);
-
-      if (surface) {
-        compositor->SetRenderTarget(surface);
-        RenderLayers(aContainer, aManager, aClipRect);
-      }
-
+      RenderIntermediate(aContainer, aManager, RenderTargetPixel::ToUntyped(aClipRect), surface);
       aContainer->mPrepared->mTmpTarget = surface;
     } else {
       aContainer->mPrepared->mNeedsSurfaceCopy = true;
     }
   }
 }
 
 template<class ContainerT> void
@@ -307,50 +300,64 @@ CreateTemporaryTargetAndCopyFromBackgrou
   sourcePoint += gfx::IntPoint(transform._41, transform._42);
 
   sourcePoint -= compositor->GetCurrentRenderTarget()->GetOrigin();
 
   return compositor->CreateRenderTargetFromSource(surfaceRect, previousTarget, sourcePoint);
 }
 
 template<class ContainerT> void
+RenderIntermediate(ContainerT* aContainer,
+                   LayerManagerComposite* aManager,
+                   const nsIntRect& aClipRect,
+                   RefPtr<CompositingRenderTarget> surface)
+{
+  Compositor* compositor = aManager->GetCompositor();
+  RefPtr<CompositingRenderTarget> previousTarget = compositor->GetCurrentRenderTarget();
+
+  if (!surface) {
+    return;
+  }
+
+  compositor->SetRenderTarget(surface);
+  // pre-render all of the layers into our temporary
+  RenderLayers(aContainer, aManager, RenderTargetPixel::FromUntyped(aClipRect));
+  // Unbind the current surface and rebind the previous one.
+  compositor->SetRenderTarget(previousTarget);
+}
+
+template<class ContainerT> void
 ContainerRender(ContainerT* aContainer,
                  LayerManagerComposite* aManager,
                  const nsIntRect& aClipRect)
 {
-  Compositor* compositor = aManager->GetCompositor();
-
   MOZ_ASSERT(aContainer->mPrepared);
   if (aContainer->UseIntermediateSurface()) {
     RefPtr<CompositingRenderTarget> surface;
 
     if (aContainer->mPrepared->mNeedsSurfaceCopy) {
-      RefPtr<CompositingRenderTarget> previousTarget = compositor->GetCurrentRenderTarget();
       // we needed to copy the background so we waited until now to render the intermediate
       surface = CreateTemporaryTargetAndCopyFromBackground(aContainer, aManager);
-      compositor->SetRenderTarget(surface);
-      if (surface) {
-        RenderLayers(aContainer, aManager, RenderTargetPixel::FromUntyped(aClipRect));
-      }
-      compositor->SetRenderTarget(previousTarget);
+      RenderIntermediate(aContainer, aManager,
+                         aClipRect, surface);
     } else {
       surface = aContainer->mPrepared->mTmpTarget;
     }
 
     if (!surface) {
       aContainer->mPrepared = nullptr;
       return;
     }
 
     float opacity = aContainer->GetEffectiveOpacity();
 
     nsIntRect visibleRect = aContainer->GetEffectiveVisibleRegion().GetBounds();
 #ifdef MOZ_DUMP_PAINTING
     if (gfxUtils::sDumpPainting) {
-      RefPtr<gfx::DataSourceSurface> surf = surface->Dump(compositor);
+      RefPtr<gfx::DataSourceSurface> surf = surface->Dump(aManager->GetCompositor());
       if (surf) {
         WriteSnapshotToDumpFile(aContainer, surf);
       }
     }
 #endif
 
     EffectChain effectChain(aContainer);
     LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(aContainer->GetMaskLayer(),
--- a/gfx/layers/composite/ContainerLayerComposite.h
+++ b/gfx/layers/composite/ContainerLayerComposite.h
@@ -32,16 +32,21 @@ class ContainerLayerComposite : public C
   friend void ContainerRender(ContainerT* aContainer,
                               LayerManagerComposite* aManager,
                               const RenderTargetIntRect& aClipRect);
   template<class ContainerT>
   friend void RenderLayers(ContainerT* aContainer,
                            LayerManagerComposite* aManager,
                            const RenderTargetIntRect& aClipRect);
   template<class ContainerT>
+  friend void RenderIntermediate(ContainerT* aContainer,
+                   LayerManagerComposite* aManager,
+                   const nsIntRect& aClipRect,
+                   RefPtr<CompositingRenderTarget> surface);
+  template<class ContainerT>
   friend RefPtr<CompositingRenderTarget>
   CreateTemporaryTargetAndCopyFromBackground(ContainerT* aContainer,
                                              LayerManagerComposite* aManager,
                                              const RenderTargetIntRect& aClipRect);
   template<class ContainerT>
   friend RefPtr<CompositingRenderTarget>
   CreateTemporaryTarget(ContainerT* aContainer,
                         LayerManagerComposite* aManager,
@@ -102,16 +107,21 @@ class RefLayerComposite : public RefLaye
   friend void ContainerRender(ContainerT* aContainer,
                               LayerManagerComposite* aManager,
                               const nsIntRect& aClipRect);
   template<class ContainerT>
   friend void RenderLayers(ContainerT* aContainer,
                            LayerManagerComposite* aManager,
                            const nsIntRect& aClipRect);
   template<class ContainerT>
+  friend void RenderIntermediate(ContainerT* aContainer,
+                   LayerManagerComposite* aManager,
+                   const nsIntRect& aClipRect,
+                   RefPtr<CompositingRenderTarget> surface);
+  template<class ContainerT>
   friend RefPtr<CompositingRenderTarget>
   CreateTemporaryTargetAndCopyFromBackground(ContainerT* aContainer,
                                              LayerManagerComposite* aManager,
                                              const nsIntRect& aClipRect);
   template<class ContainerT>
   friend RefPtr<CompositingRenderTarget>
   CreateTemporaryTarget(ContainerT* aContainer,
                         LayerManagerComposite* aManager,
--- a/gfx/layers/composite/LayerManagerComposite.cpp
+++ b/gfx/layers/composite/LayerManagerComposite.cpp
@@ -699,40 +699,35 @@ LayerManagerComposite::Render()
     mCompositor->BeginFrame(invalid, &rect, bounds, nullptr, &actualBounds);
   } else {
     gfx::Rect rect;
     mCompositor->BeginFrame(invalid, nullptr, bounds, &rect, &actualBounds);
     clipRect = nsIntRect(rect.x, rect.y, rect.width, rect.height);
   }
 
   if (actualBounds.IsEmpty()) {
-    mCompositor->SetFinalDestinationTarget();
     mCompositor->GetWidget()->PostRender(this);
     return;
   }
 
-  // Prepare our intermediate surface to minimize render target switches.
-  RootLayer()->Prepare(RenderTargetPixel::FromUntyped(clipRect));
-
-  mCompositor->SetFinalDestinationTarget();
-
   // Allow widget to render a custom background.
   mCompositor->GetWidget()->DrawWindowUnderlay(this, nsIntRect(actualBounds.x,
                                                                actualBounds.y,
                                                                actualBounds.width,
                                                                actualBounds.height));
 
   RefPtr<CompositingRenderTarget> previousTarget;
   if (haveLayerEffects) {
     previousTarget = PushGroupForLayerEffects();
   } else {
     mTwoPassTmpTarget = nullptr;
   }
 
   // Render our layers.
+  RootLayer()->Prepare(RenderTargetPixel::FromUntyped(clipRect));
   RootLayer()->RenderLayer(clipRect);
 
   if (!mRegionToClear.IsEmpty()) {
     nsIntRegionRectIterator iter(mRegionToClear);
     const nsIntRect *r;
     while ((r = iter.Next())) {
       mCompositor->ClearRect(Rect(r->x, r->y, r->width, r->height));
     }
--- a/gfx/layers/d3d11/CompositorD3D11.cpp
+++ b/gfx/layers/d3d11/CompositorD3D11.cpp
@@ -864,17 +864,17 @@ CompositorD3D11::BeginFrame(const nsIntR
   mContext->RSSetScissorRects(1, &scissor);
 
   FLOAT black[] = { 0, 0, 0, 0 };
   mContext->ClearRenderTargetView(mDefaultRT->mRTView, black);
 
   mContext->OMSetBlendState(mAttachments->mPremulBlendState, sBlendFactor, 0xFFFFFFFF);
   mContext->RSSetState(mAttachments->mRasterizerState);
 
-  mFinalDestinationTarget = mDefaultRT;
+  SetRenderTarget(mDefaultRT);
 }
 
 void
 CompositorD3D11::EndFrame()
 {
   mContext->Flush();
 
   nsIntSize oldSize = mSize;
@@ -883,17 +883,16 @@ CompositorD3D11::EndFrame()
     mSwapChain->Present(0, mDisableSequenceForNextFrame ? DXGI_PRESENT_DO_NOT_SEQUENCE : 0);
     mDisableSequenceForNextFrame = false;
     if (mTarget) {
       PaintToTarget();
     }
   }
 
   mCurrentRT = nullptr;
-  mFinalDestinationTarget = nullptr;
 }
 
 void
 CompositorD3D11::PrepareViewport(const gfx::IntSize& aSize)
 {
   D3D11_VIEWPORT viewport;
   viewport.MaxDepth = 1.0f;
   viewport.MinDepth = 0;
--- a/gfx/layers/d3d11/CompositorD3D11.h
+++ b/gfx/layers/d3d11/CompositorD3D11.h
@@ -137,20 +137,16 @@ public:
   }
 
   virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; }
 
   ID3D11Device* GetDevice() { return mDevice; }
 
   ID3D11DeviceContext* GetDC() { return mContext; }
 
-  virtual void SetFinalDestinationTarget() MOZ_OVERRIDE {
-    MOZ_ASSERT(mFinalDestinationTarget);
-    SetRenderTarget(mFinalDestinationTarget);
-  }
 private:
   enum Severity {
     Recoverable,
     DebugAssert,
     Critical,
   };
 
   void HandleError(HRESULT hr, Severity aSeverity = DebugAssert);
--- a/gfx/layers/d3d9/CompositorD3D9.cpp
+++ b/gfx/layers/d3d9/CompositorD3D9.cpp
@@ -587,17 +587,17 @@ CompositorD3D9::Ready()
       // called by mSwapChain->PrepareForRendering() via EnsureSwapChain().
 
       CheckResetCount();
       return true;
     }
     return false;
   }
 
-  NS_ASSERTION(!mCurrentRT && !mFinalDestinationTarget,
+  NS_ASSERTION(!mCurrentRT && !mDefaultRT,
                "Shouldn't have any render targets around, they must be released before our device");
   mSwapChain = nullptr;
 
   mDeviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
   if (!mDeviceManager) {
     mParent->SendInvalidateAll();
     return false;
   }
@@ -640,19 +640,20 @@ CompositorD3D9::BeginFrame(const nsIntRe
   } else {
     r.left = r.top = 0;
     r.right = mSize.width;
     r.bottom = mSize.height;
   }
   device()->SetScissorRect(&r);
 
   nsRefPtr<IDirect3DSurface9> backBuffer = mSwapChain->GetBackBuffer();
-  mFinalDestinationTarget = new CompositingRenderTargetD3D9(backBuffer,
-                                                       INIT_MODE_CLEAR,
-                                                       IntRect(0, 0, mSize.width, mSize.height));
+  mDefaultRT = new CompositingRenderTargetD3D9(backBuffer,
+                                               INIT_MODE_CLEAR,
+                                               IntRect(0, 0, mSize.width, mSize.height));
+  SetRenderTarget(mDefaultRT);
 }
 
 void
 CompositorD3D9::EndFrame()
 {
   if (mDeviceManager) {
     device()->EndScene();
 
@@ -663,17 +664,17 @@ CompositorD3D9::EndFrame()
         PaintToTarget();
       } else {
         mSwapChain->Present();
       }
     }
   }
 
   mCurrentRT = nullptr;
-  mFinalDestinationTarget = nullptr;
+  mDefaultRT = nullptr;
 }
 
 void
 CompositorD3D9::PrepareViewport(const gfx::IntSize& aSize)
 {
   Matrix4x4 viewMatrix;
   /*
    * Matrix to transform to viewport space ( <-1.0, 1.0> topleft,
--- a/gfx/layers/d3d9/CompositorD3D9.h
+++ b/gfx/layers/d3d9/CompositorD3D9.h
@@ -115,21 +115,16 @@ public:
     if (aOffset.x || aOffset.y) {
       NS_RUNTIMEABORT("SetScreenRenderOffset not supported by CompositorD3D9.");
     }
     // If the offset is 0, 0 that's okay.
   }
 
   virtual TemporaryRef<DataTextureSource>
     CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) MOZ_OVERRIDE;
-
-  virtual void SetFinalDestinationTarget() MOZ_OVERRIDE {
-    MOZ_ASSERT(mFinalDestinationTarget);
-    SetRenderTarget(mFinalDestinationTarget);
-  }
 private:
   // ensure mSize is up to date with respect to mWidget
   void EnsureSize();
   void SetSamplerForFilter(gfx::Filter aFilter);
   void PaintToTarget();
   void SetMask(const EffectChain &aEffectChain, uint32_t aMaskTexture);
   /**
    * Ensure we have a swap chain and it is ready for rendering.
@@ -164,16 +159,17 @@ private:
   nsRefPtr<DeviceManagerD3D9> mDeviceManager;
 
   /* Swap chain associated with this compositor */
   nsRefPtr<SwapChainD3D9> mSwapChain;
 
   /* Widget associated with this layer manager */
   nsIWidget *mWidget;
 
+  RefPtr<CompositingRenderTargetD3D9> mDefaultRT;
   RefPtr<CompositingRenderTargetD3D9> mCurrentRT;
 
   nsIntSize mSize;
 
   uint32_t mDeviceResetCount;
 };
 
 }
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -443,31 +443,16 @@ CompositorOGL::PrepareViewport(const gfx
   }
 
   Matrix4x4 matrix3d = Matrix4x4::From2D(viewMatrix);
   matrix3d._33 = 0.0f;
 
   mProjMatrix = matrix3d;
 }
 
-void
-CompositorOGL::SetFinalDestinationTarget() {
-  MOZ_ASSERT(mFinalDestinationTarget);
-  SetRenderTarget(mFinalDestinationTarget);
-
-  // If the Android compositor is being used, this clear will be done in
-  // DrawWindowUnderlay. Make sure the bits used here match up with those used
-  // in mobile/android/base/gfx/LayerRenderer.java
-#ifndef MOZ_WIDGET_ANDROID
-  mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0);
-  mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT);
-#endif
-}
-
-
 TemporaryRef<CompositingRenderTarget>
 CompositorOGL::CreateRenderTarget(const IntRect &aRect, SurfaceInitMode aInit)
 {
   MOZ_ASSERT(aRect.width != 0 && aRect.height != 0, "Trying to create a render target of invalid size");
 
   if (aRect.width * aRect.height == 0) {
     return nullptr;
   }
@@ -618,31 +603,44 @@ CompositorOGL::BeginFrame(const nsIntReg
 
   mPixelsPerFrame = width * height;
   mPixelsFilled = 0;
 
 #if MOZ_WIDGET_ANDROID
   TexturePoolOGL::Fill(gl());
 #endif
 
-  mFinalDestinationTarget =
+  mCurrentRenderTarget =
     CompositingRenderTargetOGL::RenderTargetForWindow(this,
                                                       IntSize(width, height));
+  mCurrentRenderTarget->BindRenderTarget();
+
   mContextStateTracker.PushOGLSection(gl(), "Frame");
+#ifdef DEBUG
+  mWindowRenderTarget = mCurrentRenderTarget;
+#endif
 
   // Default blend function implements "OVER"
   mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA,
                                  LOCAL_GL_ONE, LOCAL_GL_ONE);
   mGLContext->fEnable(LOCAL_GL_BLEND);
 
   mGLContext->fEnable(LOCAL_GL_SCISSOR_TEST);
 
   if (aClipRectOut && !aClipRectIn) {
     aClipRectOut->SetRect(0, 0, width, height);
   }
+
+  // If the Android compositor is being used, this clear will be done in
+  // DrawWindowUnderlay. Make sure the bits used here match up with those used
+  // in mobile/android/base/gfx/LayerRenderer.java
+#ifndef MOZ_WIDGET_ANDROID
+  mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0);
+  mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT);
+#endif
 }
 
 void
 CompositorOGL::CreateFBOWithTexture(const IntRect& aRect, bool aCopyFromSource,
                                     GLuint aSourceFrameBuffer,
                                     GLuint *aFBO, GLuint *aTexture)
 {
   // we're about to create a framebuffer backed by textures to use as an intermediate
@@ -1172,18 +1170,17 @@ CompositorOGL::DrawQuad(const Rect& aRec
 }
 
 void
 CompositorOGL::EndFrame()
 {
   PROFILER_LABEL("CompositorOGL", "EndFrame",
     js::ProfileEntry::Category::GRAPHICS);
 
-  MOZ_ASSERT(mCurrentRenderTarget == mFinalDestinationTarget,
-             "Rendering target not properly restored");
+  MOZ_ASSERT(mCurrentRenderTarget == mWindowRenderTarget, "Rendering target not properly restored");
 
 #ifdef MOZ_DUMP_PAINTING
   if (gfxUtils::sDumpPainting) {
     nsIntRect rect;
     if (mUseExternalSurfaceSize) {
       rect = nsIntRect(0, 0, mSurfaceSize.width, mSurfaceSize.height);
     } else {
       mWidget->GetBounds(rect);
@@ -1202,17 +1199,16 @@ CompositorOGL::EndFrame()
   if (mTarget) {
     CopyToTarget(mTarget, mTargetBounds.TopLeft(), Matrix());
     mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
     mCurrentRenderTarget = nullptr;
     return;
   }
 
   mCurrentRenderTarget = nullptr;
-  mFinalDestinationTarget = nullptr;
 
   if (mTexturePool) {
     mTexturePool->EndFrame();
   }
 
   mGLContext->SwapBuffers();
   mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
 
@@ -1295,17 +1291,16 @@ CompositorOGL::EndFrameForExternalCompos
 }
 
 void
 CompositorOGL::AbortFrame()
 {
   mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
   mFrameInProgress = false;
   mCurrentRenderTarget = nullptr;
-  mFinalDestinationTarget = nullptr;
 
   if (mTexturePool) {
     mTexturePool->EndFrame();
   }
 }
 
 void
 CompositorOGL::SetDestinationSurfaceSize(const gfx::IntSize& aSize)
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -267,18 +267,16 @@ public:
    * Doing so lets us use gralloc the way it has been designed to be used
    * (see https://wiki.mozilla.org/Platform/GFX/Gralloc)
    */
   GLuint GetTemporaryTexture(GLenum aTarget, GLenum aUnit);
 
   const gfx::Matrix4x4& GetProjMatrix() const {
     return mProjMatrix;
   }
-
-  virtual void SetFinalDestinationTarget() MOZ_OVERRIDE;
 private:
   virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE
   {
     return gfx::ToIntSize(mWidgetSize);
   }
 
   /** Widget associated with this compositor */
   nsIWidget *mWidget;
@@ -294,16 +292,19 @@ private:
 
   already_AddRefed<mozilla::gl::GLContext> CreateContext();
 
   /** Texture target to use for FBOs */
   GLenum mFBOTextureTarget;
 
   /** Currently bound render target */
   RefPtr<CompositingRenderTargetOGL> mCurrentRenderTarget;
+#ifdef DEBUG
+  CompositingRenderTargetOGL* mWindowRenderTarget;
+#endif
 
   /**
    * VBO that has some basics in it for a textured quad, including vertex
    * coords and texcoords.
    */
   GLuint mQuadVBO;
 
   bool mHasBGRA;