2013-08-11 23:17:23 +00:00
|
|
|
/* -*- 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_CLIENTCONTAINERLAYER_H
|
|
|
|
#define GFX_CLIENTCONTAINERLAYER_H
|
|
|
|
|
|
|
|
#include <stdint.h> // for uint32_t
|
|
|
|
#include "ClientLayerManager.h" // for ClientLayerManager, etc
|
|
|
|
#include "Layers.h" // for Layer, ContainerLayer, etc
|
2014-02-27 02:53:27 +00:00
|
|
|
#include "gfxPrefs.h" // for gfxPrefs
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
2014-02-26 21:36:35 +00:00
|
|
|
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
|
2013-08-11 23:17:23 +00:00
|
|
|
#include "nsISupportsUtils.h" // for NS_ADDREF, NS_RELEASE
|
|
|
|
#include "nsRegion.h" // for nsIntRegion
|
|
|
|
#include "nsTArray.h" // for nsAutoTArray
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class ShadowableLayer;
|
2013-05-01 05:03:25 +00:00
|
|
|
|
|
|
|
class ClientContainerLayer : public ContainerLayer,
|
|
|
|
public ClientLayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ClientContainerLayer(ClientLayerManager* aManager) :
|
2013-08-16 13:18:36 +00:00
|
|
|
ContainerLayer(aManager,
|
|
|
|
static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
|
2013-05-01 05:03:25 +00:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ClientContainerLayer);
|
|
|
|
mSupportsComponentAlphaChildren = true;
|
|
|
|
}
|
|
|
|
virtual ~ClientContainerLayer()
|
|
|
|
{
|
|
|
|
while (mFirstChild) {
|
2013-09-01 22:19:18 +00:00
|
|
|
ContainerLayer::RemoveChild(mFirstChild);
|
2013-05-01 05:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(ClientContainerLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void RenderLayer()
|
|
|
|
{
|
2013-06-13 23:34:15 +00:00
|
|
|
if (GetMaskLayer()) {
|
|
|
|
ToClientLayer(GetMaskLayer())->RenderLayer();
|
|
|
|
}
|
|
|
|
|
2013-05-01 05:03:25 +00:00
|
|
|
// Setup mSupportsComponentAlphaChildren in the same way
|
|
|
|
// that ContainerLayerComposite will do.
|
|
|
|
if (UseIntermediateSurface()) {
|
|
|
|
if (GetEffectiveVisibleRegion().GetNumRects() != 1 ||
|
|
|
|
!(GetContentFlags() & Layer::CONTENT_OPAQUE))
|
|
|
|
{
|
2014-01-27 20:25:19 +00:00
|
|
|
gfx::Matrix transform;
|
2013-05-01 05:03:25 +00:00
|
|
|
if (HasOpaqueAncestorLayer(this) &&
|
2014-01-27 20:25:19 +00:00
|
|
|
GetEffectiveTransform().Is2D(&transform) &&
|
|
|
|
!gfx::ThebesMatrix(transform).HasNonIntegerTranslation()) {
|
2013-05-01 05:03:25 +00:00
|
|
|
SetSupportsComponentAlphaChildren(
|
2014-02-27 02:53:27 +00:00
|
|
|
gfxPrefs::ComponentAlphaEnabled());
|
2013-05-01 05:03:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SetSupportsComponentAlphaChildren(
|
|
|
|
(GetContentFlags() & Layer::CONTENT_OPAQUE) ||
|
|
|
|
(GetParent() && GetParent()->SupportsComponentAlphaChildren()));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<Layer*, 12> children;
|
|
|
|
SortChildrenBy3DZOrder(children);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < children.Length(); i++) {
|
2014-02-11 04:01:49 +00:00
|
|
|
Layer* child = children.ElementAt(i);
|
|
|
|
if (child->GetEffectiveVisibleRegion().IsEmpty()) {
|
2013-05-01 05:03:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-03-17 09:54:24 +00:00
|
|
|
ToClientLayer(child)->RenderLayer();
|
|
|
|
|
|
|
|
if (!ClientManager()->GetRepeatTransaction() &&
|
|
|
|
!child->GetInvalidRegion().IsEmpty()) {
|
2014-02-11 04:01:49 +00:00
|
|
|
child->Mutated();
|
|
|
|
}
|
2013-05-01 05:03:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetVisibleRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(ClientManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
|
|
|
ContainerLayer::SetVisibleRegion(aRegion);
|
|
|
|
}
|
2014-02-21 21:50:25 +00:00
|
|
|
virtual bool InsertAfter(Layer* aChild, Layer* aAfter) MOZ_OVERRIDE
|
2013-05-01 05:03:25 +00:00
|
|
|
{
|
2014-02-21 21:50:25 +00:00
|
|
|
if(!ClientManager()->InConstruction()) {
|
|
|
|
NS_ERROR("Can only set properties in construction phase");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ContainerLayer::InsertAfter(aChild, aAfter)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-27 15:19:34 +00:00
|
|
|
ClientManager()->AsShadowForwarder()->InsertAfter(ClientManager()->Hold(this),
|
|
|
|
ClientManager()->Hold(aChild),
|
|
|
|
aAfter ? ClientManager()->Hold(aAfter) : nullptr);
|
2014-02-21 21:50:25 +00:00
|
|
|
return true;
|
2013-05-01 05:03:25 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 21:50:25 +00:00
|
|
|
virtual bool RemoveChild(Layer* aChild) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
if (!ClientManager()->InConstruction()) {
|
|
|
|
NS_ERROR("Can only set properties in construction phase");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// hold on to aChild before we remove it!
|
|
|
|
ShadowableLayer *heldChild = ClientManager()->Hold(aChild);
|
|
|
|
if (!ContainerLayer::RemoveChild(aChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ClientManager()->AsShadowForwarder()->RemoveChild(ClientManager()->Hold(this), heldChild);
|
|
|
|
return true;
|
2013-05-01 05:03:25 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 21:50:25 +00:00
|
|
|
virtual bool RepositionChild(Layer* aChild, Layer* aAfter) MOZ_OVERRIDE
|
2013-05-01 05:03:25 +00:00
|
|
|
{
|
2014-02-21 21:50:25 +00:00
|
|
|
if (!ClientManager()->InConstruction()) {
|
|
|
|
NS_ERROR("Can only set properties in construction phase");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!ContainerLayer::RepositionChild(aChild, aAfter)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-27 15:19:34 +00:00
|
|
|
ClientManager()->AsShadowForwarder()->RepositionChild(ClientManager()->Hold(this),
|
|
|
|
ClientManager()->Hold(aChild),
|
|
|
|
aAfter ? ClientManager()->Hold(aAfter) : nullptr);
|
2014-02-21 21:50:25 +00:00
|
|
|
return true;
|
2013-05-01 05:03:25 +00:00
|
|
|
}
|
2014-01-27 20:25:19 +00:00
|
|
|
|
2013-05-01 05:03:25 +00:00
|
|
|
virtual Layer* AsLayer() { return this; }
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return this; }
|
|
|
|
|
2014-01-27 15:28:04 +00:00
|
|
|
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
|
2013-05-01 05:03:25 +00:00
|
|
|
{
|
|
|
|
DefaultComputeEffectiveTransforms(aTransformToSurface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ForceIntermediateSurface() { mUseIntermediateSurface = true; }
|
|
|
|
|
|
|
|
void SetSupportsComponentAlphaChildren(bool aSupports) { mSupportsComponentAlphaChildren = aSupports; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ClientLayerManager* ClientManager()
|
|
|
|
{
|
|
|
|
return static_cast<ClientLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClientRefLayer : public RefLayer,
|
|
|
|
public ClientLayer {
|
|
|
|
public:
|
|
|
|
ClientRefLayer(ClientLayerManager* aManager) :
|
2013-08-16 13:18:36 +00:00
|
|
|
RefLayer(aManager,
|
|
|
|
static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
|
2013-05-01 05:03:25 +00:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ClientRefLayer);
|
|
|
|
}
|
|
|
|
virtual ~ClientRefLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ClientRefLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Layer* AsLayer() { return this; }
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return this; }
|
|
|
|
|
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
ClientLayer::Disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void RenderLayer() { }
|
|
|
|
|
2014-01-27 15:28:04 +00:00
|
|
|
virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
|
2013-05-01 05:03:25 +00:00
|
|
|
{
|
|
|
|
DefaultComputeEffectiveTransforms(aTransformToSurface);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ClientLayerManager* ClientManager()
|
|
|
|
{
|
|
|
|
return static_cast<ClientLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
};
|
2013-08-11 23:17:23 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|