Backed out changesets 7caa8e80b06a, 1509f8be5df3, a249bd79e71a, and 9cc4a77561e8...
[gecko.git] / gfx / layers / client / ClientContainerLayer.h
blob20df9320f5fef8a469c193c72e265f66bb57ee1a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_CLIENTCONTAINERLAYER_H
7 #define GFX_CLIENTCONTAINERLAYER_H
9 #include <stdint.h> // for uint32_t
10 #include "ClientLayerManager.h" // for ClientLayerManager, etc
11 #include "Layers.h" // for Layer, ContainerLayer, etc
12 #include "gfx3DMatrix.h" // for gfx3DMatrix
13 #include "gfxMatrix.h" // for gfxMatrix
14 #include "gfxPlatform.h" // for gfxPlatform
15 #include "nsDebug.h" // for NS_ASSERTION
16 #include "nsISupportsUtils.h" // for NS_ADDREF, NS_RELEASE
17 #include "nsRegion.h" // for nsIntRegion
18 #include "nsTArray.h" // for nsAutoTArray
19 #include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc
21 namespace mozilla {
22 namespace layers {
24 class ShadowableLayer;
26 class ClientContainerLayer : public ContainerLayer,
27 public ClientLayer
29 public:
30 ClientContainerLayer(ClientLayerManager* aManager) :
31 ContainerLayer(aManager,
32 static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
34 MOZ_COUNT_CTOR(ClientContainerLayer);
35 mSupportsComponentAlphaChildren = true;
37 virtual ~ClientContainerLayer()
39 while (mFirstChild) {
40 ContainerLayer::RemoveChild(mFirstChild);
43 MOZ_COUNT_DTOR(ClientContainerLayer);
46 virtual void RenderLayer()
48 if (GetMaskLayer()) {
49 ToClientLayer(GetMaskLayer())->RenderLayer();
52 // Setup mSupportsComponentAlphaChildren in the same way
53 // that ContainerLayerComposite will do.
54 if (UseIntermediateSurface()) {
55 if (GetEffectiveVisibleRegion().GetNumRects() != 1 ||
56 !(GetContentFlags() & Layer::CONTENT_OPAQUE))
58 const gfx3DMatrix& transform3D = GetEffectiveTransform();
59 gfxMatrix transform;
60 if (HasOpaqueAncestorLayer(this) &&
61 transform3D.Is2D(&transform) &&
62 !transform.HasNonIntegerTranslation()) {
63 SetSupportsComponentAlphaChildren(
64 gfxPlatform::ComponentAlphaEnabled());
67 } else {
68 SetSupportsComponentAlphaChildren(
69 (GetContentFlags() & Layer::CONTENT_OPAQUE) ||
70 (GetParent() && GetParent()->SupportsComponentAlphaChildren()));
73 nsAutoTArray<Layer*, 12> children;
74 SortChildrenBy3DZOrder(children);
76 for (uint32_t i = 0; i < children.Length(); i++) {
77 if (children.ElementAt(i)->GetEffectiveVisibleRegion().IsEmpty()) {
78 continue;
81 ToClientLayer(children.ElementAt(i))->RenderLayer();
85 virtual void SetVisibleRegion(const nsIntRegion& aRegion)
87 NS_ASSERTION(ClientManager()->InConstruction(),
88 "Can only set properties in construction phase");
89 ContainerLayer::SetVisibleRegion(aRegion);
91 virtual void InsertAfter(Layer* aChild, Layer* aAfter) MOZ_OVERRIDE
93 NS_ASSERTION(ClientManager()->InConstruction(),
94 "Can only set properties in construction phase");
95 ClientManager()->InsertAfter(ClientManager()->Hold(this),
96 ClientManager()->Hold(aChild),
97 aAfter ? ClientManager()->Hold(aAfter) : nullptr);
98 ContainerLayer::InsertAfter(aChild, aAfter);
101 virtual void RemoveChild(Layer* aChild) MOZ_OVERRIDE
103 NS_ASSERTION(ClientManager()->InConstruction(),
104 "Can only set properties in construction phase");
105 ClientManager()->RemoveChild(ClientManager()->Hold(this),
106 ClientManager()->Hold(aChild));
107 ContainerLayer::RemoveChild(aChild);
110 virtual void RepositionChild(Layer* aChild, Layer* aAfter) MOZ_OVERRIDE
112 NS_ASSERTION(ClientManager()->InConstruction(),
113 "Can only set properties in construction phase");
114 ClientManager()->RepositionChild(ClientManager()->Hold(this),
115 ClientManager()->Hold(aChild),
116 aAfter ? ClientManager()->Hold(aAfter) : nullptr);
117 ContainerLayer::RepositionChild(aChild, aAfter);
120 virtual Layer* AsLayer() { return this; }
121 virtual ShadowableLayer* AsShadowableLayer() { return this; }
123 virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
125 DefaultComputeEffectiveTransforms(aTransformToSurface);
128 void ForceIntermediateSurface() { mUseIntermediateSurface = true; }
130 void SetSupportsComponentAlphaChildren(bool aSupports) { mSupportsComponentAlphaChildren = aSupports; }
132 protected:
133 ClientLayerManager* ClientManager()
135 return static_cast<ClientLayerManager*>(mManager);
139 class ClientRefLayer : public RefLayer,
140 public ClientLayer {
141 public:
142 ClientRefLayer(ClientLayerManager* aManager) :
143 RefLayer(aManager,
144 static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
146 MOZ_COUNT_CTOR(ClientRefLayer);
148 virtual ~ClientRefLayer()
150 MOZ_COUNT_DTOR(ClientRefLayer);
153 virtual Layer* AsLayer() { return this; }
154 virtual ShadowableLayer* AsShadowableLayer() { return this; }
156 virtual void Disconnect()
158 ClientLayer::Disconnect();
161 virtual void RenderLayer() { }
163 virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
165 DefaultComputeEffectiveTransforms(aTransformToSurface);
168 private:
169 ClientLayerManager* ClientManager()
171 return static_cast<ClientLayerManager*>(mManager);
178 #endif