michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_CLIENTCONTAINERLAYER_H michael@0: #define GFX_CLIENTCONTAINERLAYER_H michael@0: michael@0: #include // for uint32_t michael@0: #include "ClientLayerManager.h" // for ClientLayerManager, etc michael@0: #include "Layers.h" // for Layer, ContainerLayer, etc michael@0: #include "gfxPrefs.h" // for gfxPrefs michael@0: #include "nsDebug.h" // for NS_ASSERTION michael@0: #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc michael@0: #include "nsISupportsUtils.h" // for NS_ADDREF, NS_RELEASE michael@0: #include "nsRegion.h" // for nsIntRegion michael@0: #include "nsTArray.h" // for nsAutoTArray michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class ShadowableLayer; michael@0: michael@0: class ClientContainerLayer : public ContainerLayer, michael@0: public ClientLayer michael@0: { michael@0: public: michael@0: ClientContainerLayer(ClientLayerManager* aManager) : michael@0: ContainerLayer(aManager, michael@0: static_cast(MOZ_THIS_IN_INITIALIZER_LIST())) michael@0: { michael@0: MOZ_COUNT_CTOR(ClientContainerLayer); michael@0: mSupportsComponentAlphaChildren = true; michael@0: } michael@0: virtual ~ClientContainerLayer() michael@0: { michael@0: while (mFirstChild) { michael@0: ContainerLayer::RemoveChild(mFirstChild); michael@0: } michael@0: michael@0: MOZ_COUNT_DTOR(ClientContainerLayer); michael@0: } michael@0: michael@0: virtual void RenderLayer() michael@0: { michael@0: if (GetMaskLayer()) { michael@0: ToClientLayer(GetMaskLayer())->RenderLayer(); michael@0: } michael@0: michael@0: // Setup mSupportsComponentAlphaChildren in the same way michael@0: // that ContainerLayerComposite will do. michael@0: if (UseIntermediateSurface()) { michael@0: if (GetEffectiveVisibleRegion().GetNumRects() != 1 || michael@0: !(GetContentFlags() & Layer::CONTENT_OPAQUE)) michael@0: { michael@0: gfx::Matrix transform; michael@0: if (HasOpaqueAncestorLayer(this) && michael@0: GetEffectiveTransform().Is2D(&transform) && michael@0: !gfx::ThebesMatrix(transform).HasNonIntegerTranslation()) { michael@0: SetSupportsComponentAlphaChildren( michael@0: gfxPrefs::ComponentAlphaEnabled()); michael@0: } michael@0: } michael@0: } else { michael@0: SetSupportsComponentAlphaChildren( michael@0: (GetContentFlags() & Layer::CONTENT_OPAQUE) || michael@0: (GetParent() && GetParent()->SupportsComponentAlphaChildren())); michael@0: } michael@0: michael@0: nsAutoTArray children; michael@0: SortChildrenBy3DZOrder(children); michael@0: michael@0: for (uint32_t i = 0; i < children.Length(); i++) { michael@0: Layer* child = children.ElementAt(i); michael@0: if (child->GetEffectiveVisibleRegion().IsEmpty()) { michael@0: continue; michael@0: } michael@0: michael@0: ToClientLayer(child)->RenderLayer(); michael@0: michael@0: if (!ClientManager()->GetRepeatTransaction() && michael@0: !child->GetInvalidRegion().IsEmpty()) { michael@0: child->Mutated(); michael@0: } michael@0: } michael@0: } michael@0: michael@0: virtual void SetVisibleRegion(const nsIntRegion& aRegion) michael@0: { michael@0: NS_ASSERTION(ClientManager()->InConstruction(), michael@0: "Can only set properties in construction phase"); michael@0: ContainerLayer::SetVisibleRegion(aRegion); michael@0: } michael@0: virtual bool InsertAfter(Layer* aChild, Layer* aAfter) MOZ_OVERRIDE michael@0: { michael@0: if(!ClientManager()->InConstruction()) { michael@0: NS_ERROR("Can only set properties in construction phase"); michael@0: return false; michael@0: } michael@0: michael@0: if (!ContainerLayer::InsertAfter(aChild, aAfter)) { michael@0: return false; michael@0: } michael@0: michael@0: ClientManager()->AsShadowForwarder()->InsertAfter(ClientManager()->Hold(this), michael@0: ClientManager()->Hold(aChild), michael@0: aAfter ? ClientManager()->Hold(aAfter) : nullptr); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool RemoveChild(Layer* aChild) MOZ_OVERRIDE michael@0: { michael@0: if (!ClientManager()->InConstruction()) { michael@0: NS_ERROR("Can only set properties in construction phase"); michael@0: return false; michael@0: } michael@0: // hold on to aChild before we remove it! michael@0: ShadowableLayer *heldChild = ClientManager()->Hold(aChild); michael@0: if (!ContainerLayer::RemoveChild(aChild)) { michael@0: return false; michael@0: } michael@0: ClientManager()->AsShadowForwarder()->RemoveChild(ClientManager()->Hold(this), heldChild); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool RepositionChild(Layer* aChild, Layer* aAfter) MOZ_OVERRIDE michael@0: { michael@0: if (!ClientManager()->InConstruction()) { michael@0: NS_ERROR("Can only set properties in construction phase"); michael@0: return false; michael@0: } michael@0: if (!ContainerLayer::RepositionChild(aChild, aAfter)) { michael@0: return false; michael@0: } michael@0: ClientManager()->AsShadowForwarder()->RepositionChild(ClientManager()->Hold(this), michael@0: ClientManager()->Hold(aChild), michael@0: aAfter ? ClientManager()->Hold(aAfter) : nullptr); michael@0: return true; michael@0: } michael@0: michael@0: virtual Layer* AsLayer() { return this; } michael@0: virtual ShadowableLayer* AsShadowableLayer() { return this; } michael@0: michael@0: virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) michael@0: { michael@0: DefaultComputeEffectiveTransforms(aTransformToSurface); michael@0: } michael@0: michael@0: void ForceIntermediateSurface() { mUseIntermediateSurface = true; } michael@0: michael@0: void SetSupportsComponentAlphaChildren(bool aSupports) { mSupportsComponentAlphaChildren = aSupports; } michael@0: michael@0: protected: michael@0: ClientLayerManager* ClientManager() michael@0: { michael@0: return static_cast(mManager); michael@0: } michael@0: }; michael@0: michael@0: class ClientRefLayer : public RefLayer, michael@0: public ClientLayer { michael@0: public: michael@0: ClientRefLayer(ClientLayerManager* aManager) : michael@0: RefLayer(aManager, michael@0: static_cast(MOZ_THIS_IN_INITIALIZER_LIST())) michael@0: { michael@0: MOZ_COUNT_CTOR(ClientRefLayer); michael@0: } michael@0: virtual ~ClientRefLayer() michael@0: { michael@0: MOZ_COUNT_DTOR(ClientRefLayer); michael@0: } michael@0: michael@0: virtual Layer* AsLayer() { return this; } michael@0: virtual ShadowableLayer* AsShadowableLayer() { return this; } michael@0: michael@0: virtual void Disconnect() michael@0: { michael@0: ClientLayer::Disconnect(); michael@0: } michael@0: michael@0: virtual void RenderLayer() { } michael@0: michael@0: virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) michael@0: { michael@0: DefaultComputeEffectiveTransforms(aTransformToSurface); michael@0: } michael@0: michael@0: private: michael@0: ClientLayerManager* ClientManager() michael@0: { michael@0: return static_cast(mManager); michael@0: } michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif