Bug 1444449 - Do not return raw pointers to window targets from compositors r=bas
authorBarret Rennie <barret@brennie.ca>
Tue, 12 Feb 2019 18:53:10 +0000
changeset 459344 6c289d94dcca88ecfe3893633a31370119c061c7
parent 459343 847aa80e92e872bbbfb986c0fd0645efff5b3ae4
child 459345 5f30ff27430670b51e526c12023ea1236efdf8c4
push id35559
push userrmaries@mozilla.com
push dateFri, 15 Feb 2019 09:55:16 +0000
treeherdermozilla-central@fc01e86f7e80 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1444449
milestone67.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 1444449 - Do not return raw pointers to window targets from compositors r=bas Differential Revision: https://phabricator.services.mozilla.com/D18598
gfx/layers/Compositor.cpp
gfx/layers/Compositor.h
gfx/layers/basic/BasicCompositor.h
gfx/layers/composite/ContainerLayerComposite.cpp
gfx/layers/d3d11/CompositorD3D11.h
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/CompositorOGL.h
--- a/gfx/layers/Compositor.cpp
+++ b/gfx/layers/Compositor.cpp
@@ -498,18 +498,20 @@ size_t DecomposeIntoNoRepeatRects(const 
   return 4;
 }
 
 gfx::IntRect Compositor::ComputeBackdropCopyRect(
     const gfx::Rect& aRect, const gfx::IntRect& aClipRect,
     const gfx::Matrix4x4& aTransform, gfx::Matrix4x4* aOutTransform,
     gfx::Rect* aOutLayerQuad) {
   // Compute the clip.
-  gfx::IntPoint rtOffset = GetCurrentRenderTarget()->GetOrigin();
-  gfx::IntSize rtSize = GetCurrentRenderTarget()->GetSize();
+  RefPtr<CompositingRenderTarget> currentRenderTarget =
+      GetCurrentRenderTarget();
+  gfx::IntPoint rtOffset = currentRenderTarget->GetOrigin();
+  gfx::IntSize rtSize = currentRenderTarget->GetSize();
 
   return layers::ComputeBackdropCopyRect(aRect, aClipRect, aTransform,
                                          gfx::IntRect(rtOffset, rtSize),
                                          aOutTransform, aOutLayerQuad);
 }
 
 gfx::IntRect Compositor::ComputeBackdropCopyRect(
     const gfx::Triangle& aTriangle, const gfx::IntRect& aClipRect,
--- a/gfx/layers/Compositor.h
+++ b/gfx/layers/Compositor.h
@@ -287,25 +287,27 @@ class Compositor : public TextureSourceP
    * Passing null as aSurface sets the screen as the target.
    */
   virtual void SetRenderTarget(CompositingRenderTarget* aSurface) = 0;
 
   /**
    * Returns the current target for rendering. Will return null if we are
    * rendering to the screen.
    */
-  virtual CompositingRenderTarget* GetCurrentRenderTarget() const = 0;
+  virtual already_AddRefed<CompositingRenderTarget> GetCurrentRenderTarget()
+      const = 0;
 
   /**
    * Returns a render target which contains the entire window's drawing.
    * On platforms where no such render target is used during compositing (e.g.
    * with buffered BasicCompositor, where only the invalid area is drawn to a
    * render target), this will return null.
    */
-  virtual CompositingRenderTarget* GetWindowRenderTarget() const {
+  virtual already_AddRefed<CompositingRenderTarget> GetWindowRenderTarget()
+      const {
     return nullptr;
   }
 
   /**
    * Mostly the compositor will pull the size from a widget and this method will
    * be ignored, but compositor implementations are free to use it if they like.
    */
   virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) = 0;
--- a/gfx/layers/basic/BasicCompositor.h
+++ b/gfx/layers/basic/BasicCompositor.h
@@ -93,22 +93,24 @@ class BasicCompositor : public Composito
                                 const gfx::IntSize& aSourceSize,
                                 const gfx::IntSize& aDestSize) override;
 
   virtual void SetRenderTarget(CompositingRenderTarget* aSource) override {
     mRenderTarget = static_cast<BasicCompositingRenderTarget*>(aSource);
     mRenderTarget->BindRenderTarget();
   }
 
-  virtual CompositingRenderTarget* GetWindowRenderTarget() const override {
-    return mFullWindowRenderTarget;
+  virtual already_AddRefed<CompositingRenderTarget> GetWindowRenderTarget()
+      const override {
+    return do_AddRef(mFullWindowRenderTarget);
   }
 
-  virtual CompositingRenderTarget* GetCurrentRenderTarget() const override {
-    return mRenderTarget;
+  virtual already_AddRefed<CompositingRenderTarget> GetCurrentRenderTarget()
+      const override {
+    return do_AddRef(mRenderTarget);
   }
 
   virtual void DrawQuad(const gfx::Rect& aRect, const gfx::IntRect& aClipRect,
                         const EffectChain& aEffectChain, gfx::Float aOpacity,
                         const gfx::Matrix4x4& aTransform,
                         const gfx::Rect& aVisibleRect) override;
 
   virtual void ClearRect(const gfx::Rect& aRect) override;
--- a/gfx/layers/composite/ContainerLayerComposite.cpp
+++ b/gfx/layers/composite/ContainerLayerComposite.cpp
@@ -560,17 +560,17 @@ RefPtr<CompositingRenderTarget> CreateTe
   gfx::IntPoint sourcePoint = gfx::IntPoint(visibleRect.X(), visibleRect.Y());
 
   gfx::Matrix4x4 transform = aContainer->GetEffectiveTransform();
   DebugOnly<gfx::Matrix> transform2d;
   MOZ_ASSERT(transform.Is2D(&transform2d) &&
              !gfx::ThebesMatrix(transform2d).HasNonIntegerTranslation());
   sourcePoint += gfx::IntPoint::Truncate(transform._41, transform._42);
 
-  sourcePoint -= compositor->GetCurrentRenderTarget()->GetOrigin();
+  sourcePoint -= previousTarget->GetOrigin();
 
   return compositor->CreateRenderTargetFromSource(surfaceRect, previousTarget,
                                                   sourcePoint);
 }
 
 template <class ContainerT>
 void RenderIntermediate(ContainerT* aContainer, LayerManagerComposite* aManager,
                         const gfx::IntRect& aClipRect,
--- a/gfx/layers/d3d11/CompositorD3D11.h
+++ b/gfx/layers/d3d11/CompositorD3D11.h
@@ -49,18 +49,19 @@ class CompositorD3D11 : public Composito
       const gfx::IntRect& aRect, SurfaceInitMode aInit) override;
 
   virtual already_AddRefed<CompositingRenderTarget>
   CreateRenderTargetFromSource(const gfx::IntRect& aRect,
                                const CompositingRenderTarget* aSource,
                                const gfx::IntPoint& aSourcePoint) override;
 
   virtual void SetRenderTarget(CompositingRenderTarget* aSurface) override;
-  virtual CompositingRenderTarget* GetCurrentRenderTarget() const override {
-    return mCurrentRT;
+  virtual already_AddRefed<CompositingRenderTarget> GetCurrentRenderTarget()
+      const override {
+    return do_AddRef(mCurrentRT);
   }
 
   virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) override {}
 
   /**
    * Declare an offset to use when rendering layers. This will be ignored when
    * rendering to a target instead of the screen.
    */
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -651,22 +651,24 @@ void CompositorOGL::SetRenderTarget(Comp
   if (mCurrentRenderTarget != surface) {
     mCurrentRenderTarget = surface;
     surface->BindRenderTarget();
   }
 
   PrepareViewport(mCurrentRenderTarget);
 }
 
-CompositingRenderTarget* CompositorOGL::GetCurrentRenderTarget() const {
-  return mCurrentRenderTarget;
+already_AddRefed<CompositingRenderTarget>
+CompositorOGL::GetCurrentRenderTarget() const {
+  return do_AddRef(mCurrentRenderTarget);
 }
 
-CompositingRenderTarget* CompositorOGL::GetWindowRenderTarget() const {
-  return mWindowRenderTarget;
+already_AddRefed<CompositingRenderTarget> CompositorOGL::GetWindowRenderTarget()
+    const {
+  return do_AddRef(mWindowRenderTarget);
 }
 
 already_AddRefed<AsyncReadbackBuffer> CompositorOGL::CreateAsyncReadbackBuffer(
     const IntSize& aSize) {
   return MakeAndAddRef<AsyncReadbackBufferOGL>(mGLContext, aSize);
 }
 
 bool CompositorOGL::ReadbackRenderTarget(CompositingRenderTarget* aSource,
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -150,18 +150,20 @@ class CompositorOGL final : public Compo
       const gfx::IntRect& aRect, SurfaceInitMode aInit) override;
 
   virtual already_AddRefed<CompositingRenderTarget>
   CreateRenderTargetFromSource(const gfx::IntRect& aRect,
                                const CompositingRenderTarget* aSource,
                                const gfx::IntPoint& aSourcePoint) override;
 
   virtual void SetRenderTarget(CompositingRenderTarget* aSurface) override;
-  virtual CompositingRenderTarget* GetCurrentRenderTarget() const override;
-  virtual CompositingRenderTarget* GetWindowRenderTarget() const override;
+  virtual already_AddRefed<CompositingRenderTarget> GetCurrentRenderTarget()
+      const override;
+  virtual already_AddRefed<CompositingRenderTarget> GetWindowRenderTarget()
+      const override;
 
   virtual bool ReadbackRenderTarget(CompositingRenderTarget* aSource,
                                     AsyncReadbackBuffer* aDest) override;
 
   virtual already_AddRefed<AsyncReadbackBuffer> CreateAsyncReadbackBuffer(
       const gfx::IntSize& aSize) override;
 
   virtual bool BlitRenderTarget(CompositingRenderTarget* aSource,