gfx/layers/wr/WebRenderContainerLayer.h
author peter chang <pchang@mozilla.com>
Wed, 19 Apr 2017 17:54:11 +0800
changeset 405133 ccd2f70fc8d4848babf04e2b5a8c9ade7f1839ae
parent 403308 6b896b357ad2d1dcd504ea4f1127f6dc043435c5
child 405135 f877064cf25c2eafef32df87deb02f16107ce705
permissions -rw-r--r--
Bug 1357320 - Deal with the lifetime of compositor animations, r?kats First, hook the Layer's ClearAnimation API to delete unnecessary animations in next layer transaction. Second, add another async DeleteCompositorAnimations API to delete animations on the compositor, especially calling this API before WebRenderLayerManager got destroyed. MozReview-Commit-ID: 4mbj5IgsXYa

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * 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/. */

#ifndef GFX_WEBRENDERCONTAINERLAYER_H
#define GFX_WEBRENDERCONTAINERLAYER_H

#include "gfxPrefs.h"
#include "Layers.h"
#include "mozilla/layers/WebRenderLayer.h"
#include "mozilla/layers/WebRenderLayerManager.h"

namespace mozilla {
namespace layers {

class WebRenderContainerLayer : public WebRenderLayer,
                                public ContainerLayer
{
public:
  explicit WebRenderContainerLayer(WebRenderLayerManager* aManager)
    : ContainerLayer(aManager, static_cast<WebRenderLayer*>(this))
  {
    MOZ_COUNT_CTOR(WebRenderContainerLayer);
  }

protected:
  virtual ~WebRenderContainerLayer()
  {

    if (gfxPrefs::WebRenderOMTAEnabled() &&
        !GetAnimations().IsEmpty()) {
      mManager->AsWebRenderLayerManager()->
        AddCompositorAnimationsIdForDiscard(GetCompositorAnimationsId());
    }

    ContainerLayer::RemoveAllChildren();
    MOZ_COUNT_DTOR(WebRenderContainerLayer);
  }

public:
  Layer* GetLayer() override { return this; }
  void RenderLayer(wr::DisplayListBuilder& aBuilder) override;

  void ClearAnimations() override;
  virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override
  {
    DefaultComputeEffectiveTransforms(aTransformToSurface);
  }
};

class WebRenderRefLayer : public WebRenderLayer,
                          public RefLayer {
public:
  explicit WebRenderRefLayer(WebRenderLayerManager* aManager) :
    RefLayer(aManager, static_cast<WebRenderLayer*>(this))
  {
    MOZ_COUNT_CTOR(WebRenderRefLayer);
  }

protected:
  virtual ~WebRenderRefLayer()
  {
    MOZ_COUNT_DTOR(WebRenderRefLayer);
  }

public:
  Layer* GetLayer() override { return this; }
  void RenderLayer(wr::DisplayListBuilder& aBuilder) override;

  virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override
  {
    DefaultComputeEffectiveTransforms(aTransformToSurface);
  }
};

} // namespace layers
} // namespace mozilla

#endif // GFX_WEBRENDERCONTAINERLAYER_H