Implement LayerMLGPU::SetLayerManager. (bug 1375759, r=mattwoodrow)
☠☠ backed out by 7da6c9907099 ☠ ☠
authorDavid Anderson <danderson@mozilla.com>
Tue, 27 Jun 2017 11:31:37 -0700
changeset 366158 9db369ba372ccc31274de3ecd6598e6a16ca1995
parent 366157 f165f830468d42546e03a1770286db0ef561ff1e
child 366159 8d9b536289c2ddec604ea8e2f305a007ec840612
push id91900
push userdanderson@mozilla.com
push dateTue, 27 Jun 2017 18:33:12 +0000
treeherdermozilla-inbound@9db369ba372c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1375759
milestone56.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
Implement LayerMLGPU::SetLayerManager. (bug 1375759, r=mattwoodrow)
gfx/layers/Layers.cpp
gfx/layers/Layers.h
gfx/layers/mlgpu/ContainerLayerMLGPU.cpp
gfx/layers/mlgpu/ContainerLayerMLGPU.h
gfx/layers/mlgpu/LayerMLGPU.cpp
gfx/layers/mlgpu/LayerMLGPU.h
gfx/layers/mlgpu/LayerManagerMLGPU.cpp
gfx/layers/mlgpu/LayerManagerMLGPU.h
gfx/layers/mlgpu/PaintedLayerMLGPU.h
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -2098,16 +2098,25 @@ Layer::IsBackfaceHidden()
 UniquePtr<LayerUserData>
 Layer::RemoveUserData(void* aKey)
 {
   UniquePtr<LayerUserData> d(static_cast<LayerUserData*>(mUserData.Remove(static_cast<gfx::UserDataKey*>(aKey))));
   return d;
 }
 
 void
+Layer::SetManager(LayerManager* aManager, HostLayer* aSelf)
+{
+  // No one should be calling this for weird reasons.
+  MOZ_ASSERT(aSelf);
+  MOZ_ASSERT(aSelf->GetLayer() == this);
+  mManager = aManager;
+}
+
+void
 PaintedLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix)
 {
   Layer::PrintInfo(aStream, aPrefix);
   nsIntRegion validRegion = GetValidRegion();
   if (!validRegion.IsEmpty()) {
     AppendToString(aStream, validRegion, " [valid=", "]");
   }
 }
--- a/gfx/layers/Layers.h
+++ b/gfx/layers/Layers.h
@@ -839,16 +839,21 @@ public:
 
   /**
    * Returns the LayerManager this Layer belongs to. Note that the layer
    * manager might be in a destroyed state, at which point it's only
    * valid to set/get user data from it.
    */
   LayerManager* Manager() { return mManager; }
 
+  /**
+   * This should only be called when changing layer managers from HostLayers.
+   */
+  void SetManager(LayerManager* aManager, HostLayer* aSelf);
+
   enum {
     /**
      * If this is set, the caller is promising that by the end of this
      * transaction the entire visible region (as specified by
      * SetVisibleRegion) will be filled with opaque content.
      */
     CONTENT_OPAQUE = 0x01,
     /**
--- a/gfx/layers/mlgpu/ContainerLayerMLGPU.cpp
+++ b/gfx/layers/mlgpu/ContainerLayerMLGPU.cpp
@@ -44,16 +44,22 @@ ContainerLayerMLGPU::OnPrepareToRender(F
     mInvalidRect = viewport;
   } else {
     // Clamp the invalid rect to the viewport.
     mInvalidRect = mInvalidRect.Intersect(viewport);
   }
   return true;
 }
 
+void
+ContainerLayerMLGPU::OnLayerManagerChange(LayerManagerMLGPU* aManager)
+{
+  ClearCachedResources();
+}
+
 RefPtr<MLGRenderTarget>
 ContainerLayerMLGPU::UpdateRenderTarget(MLGDevice* aDevice, MLGRenderTargetFlags aFlags)
 {
   if (mRenderTarget) {
     return mRenderTarget;
   }
 
   mRenderTarget = aDevice->CreateRenderTarget(mTargetSize, aFlags);
--- a/gfx/layers/mlgpu/ContainerLayerMLGPU.h
+++ b/gfx/layers/mlgpu/ContainerLayerMLGPU.h
@@ -48,16 +48,17 @@ public:
   }
   void ClearInvalidRect() {
     mInvalidRect.SetEmpty();
   }
   bool IsContentOpaque() override;
 
 protected:
   bool OnPrepareToRender(FrameBuilder* aBuilder) override;
+  void OnLayerManagerChange(LayerManagerMLGPU* aManager) override;
 
 private:
   RefPtr<MLGRenderTarget> mRenderTarget;
 
   // We cache these since occlusion culling can change the visible region.
   gfx::IntPoint mTargetOffset;
   gfx::IntSize mTargetSize;
 
--- a/gfx/layers/mlgpu/LayerMLGPU.cpp
+++ b/gfx/layers/mlgpu/LayerMLGPU.cpp
@@ -120,16 +120,32 @@ LayerMLGPU::IsContentOpaque()
 }
 
 void
 LayerMLGPU::SetRegionToRender(LayerIntRegion&& aRegion)
 {
   SetShadowVisibleRegion(Move(aRegion));
 }
 
+void
+LayerMLGPU::SetLayerManager(HostLayerManager* aManager)
+{
+  LayerManagerMLGPU* manager = aManager->AsLayerManagerMLGPU();
+  MOZ_RELEASE_ASSERT(manager);
+
+  HostLayer::SetLayerManager(aManager);
+  GetLayer()->SetManager(manager, this);
+
+  if (CompositableHost* host = GetCompositableHost()) {
+    host->SetTextureSourceProvider(manager->GetTextureSourceProvider());
+  }
+
+  OnLayerManagerChange(manager);
+}
+
 RefLayerMLGPU::RefLayerMLGPU(LayerManagerMLGPU* aManager)
   : RefLayer(aManager, static_cast<HostLayer*>(this))
   , LayerMLGPU(aManager)
 {
 }
 
 RefLayerMLGPU::~RefLayerMLGPU()
 {
--- a/gfx/layers/mlgpu/LayerMLGPU.h
+++ b/gfx/layers/mlgpu/LayerMLGPU.h
@@ -100,16 +100,21 @@ protected:
   LayerManagerMLGPU* GetManager();
 
   void AddBoundsToView(FrameBuilder* aBuilder,
                        RenderViewMLGPU* aView,
                        Maybe<gfx::Polygon>&& aGeometry);
 
   void MarkPrepared();
 
+  // We don't want derivative layers overriding this directly - we provide a
+  // callback instead.
+  void SetLayerManager(HostLayerManager* aManager) override;
+  virtual void OnLayerManagerChange(LayerManagerMLGPU* aManager) {}
+
 private:
   // This is a monotonic counter used to check whether a layer appears twice
   // when 3d sorting.
   static uint64_t sFrameKey;
 
 protected:
   // These are set during PrepareToRender.
   RenderTargetIntRect mComputedClipRect;
--- a/gfx/layers/mlgpu/LayerManagerMLGPU.cpp
+++ b/gfx/layers/mlgpu/LayerManagerMLGPU.cpp
@@ -188,16 +188,22 @@ LayerManagerMLGPU::GetTextureFactoryIden
 }
 
 LayersBackend
 LayerManagerMLGPU::GetBackendType()
 {
   return mDevice ? mDevice->GetLayersBackend() : LayersBackend::LAYERS_NONE;
 }
 
+void
+LayerManagerMLGPU::SetRoot(Layer* aLayer)
+{
+  mRoot = aLayer;
+}
+
 bool
 LayerManagerMLGPU::BeginTransaction()
 {
   MOZ_ASSERT(!mTarget);
   return true;
 }
 
 void
--- a/gfx/layers/mlgpu/LayerManagerMLGPU.h
+++ b/gfx/layers/mlgpu/LayerManagerMLGPU.h
@@ -33,17 +33,17 @@ public:
   ~LayerManagerMLGPU();
 
   bool Initialize();
   void Destroy() override;
 
   // LayerManager methods
   bool BeginTransaction() override;
   void BeginTransactionWithDrawTarget(gfx::DrawTarget* aTarget, const gfx::IntRect& aRect) override;
-  void SetRoot(Layer* aLayer) override { mRoot = aLayer; }
+  void SetRoot(Layer* aLayer) override;
   already_AddRefed<PaintedLayer> CreatePaintedLayer() override;
   already_AddRefed<ContainerLayer> CreateContainerLayer() override;
   already_AddRefed<ImageLayer> CreateImageLayer() override;
   already_AddRefed<ColorLayer> CreateColorLayer() override;
   already_AddRefed<TextLayer> CreateTextLayer() override;
   already_AddRefed<CanvasLayer> CreateCanvasLayer() override;
   already_AddRefed<RefLayer> CreateRefLayer() override;
   already_AddRefed<BorderLayer> CreateBorderLayer() override;
--- a/gfx/layers/mlgpu/PaintedLayerMLGPU.h
+++ b/gfx/layers/mlgpu/PaintedLayerMLGPU.h
@@ -59,17 +59,16 @@ public:
 
   MOZ_LAYER_DECL_NAME("PaintedLayerMLGPU", TYPE_PAINTED)
 
   void CleanupCachedResources();
 
 protected:
   void PrintInfo(std::stringstream& aStream, const char* aPrefix) override;
   bool OnPrepareToRender(FrameBuilder* aBuilder) override;
-  void ComputeDrawRegion();
 
   void CleanupResources();
 
 private:
   RefPtr<ContentHostTexture> mHost;
   RefPtr<TextureSource> mTexture;
   RefPtr<TextureSource> mTextureOnWhite;
   gfx::IntRegion mLocalDrawRegion;