gfx/layers/client/ClientContainerLayer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/client/ClientContainerLayer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,199 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef GFX_CLIENTCONTAINERLAYER_H
    1.10 +#define GFX_CLIENTCONTAINERLAYER_H
    1.11 +
    1.12 +#include <stdint.h>                     // for uint32_t
    1.13 +#include "ClientLayerManager.h"         // for ClientLayerManager, etc
    1.14 +#include "Layers.h"                     // for Layer, ContainerLayer, etc
    1.15 +#include "gfxPrefs.h"                   // for gfxPrefs
    1.16 +#include "nsDebug.h"                    // for NS_ASSERTION
    1.17 +#include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
    1.18 +#include "nsISupportsUtils.h"           // for NS_ADDREF, NS_RELEASE
    1.19 +#include "nsRegion.h"                   // for nsIntRegion
    1.20 +#include "nsTArray.h"                   // for nsAutoTArray
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace layers {
    1.24 +
    1.25 +class ShadowableLayer;
    1.26 +
    1.27 +class ClientContainerLayer : public ContainerLayer,
    1.28 +                             public ClientLayer
    1.29 +{
    1.30 +public:
    1.31 +  ClientContainerLayer(ClientLayerManager* aManager) :
    1.32 +    ContainerLayer(aManager,
    1.33 +                   static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
    1.34 +  {
    1.35 +    MOZ_COUNT_CTOR(ClientContainerLayer);
    1.36 +    mSupportsComponentAlphaChildren = true;
    1.37 +  }
    1.38 +  virtual ~ClientContainerLayer()
    1.39 +  {
    1.40 +    while (mFirstChild) {
    1.41 +      ContainerLayer::RemoveChild(mFirstChild);
    1.42 +    }
    1.43 +
    1.44 +    MOZ_COUNT_DTOR(ClientContainerLayer);
    1.45 +  }
    1.46 +
    1.47 +  virtual void RenderLayer()
    1.48 +  {
    1.49 +    if (GetMaskLayer()) {
    1.50 +      ToClientLayer(GetMaskLayer())->RenderLayer();
    1.51 +    }
    1.52 +    
    1.53 +    // Setup mSupportsComponentAlphaChildren in the same way 
    1.54 +    // that ContainerLayerComposite will do.
    1.55 +    if (UseIntermediateSurface()) {
    1.56 +      if (GetEffectiveVisibleRegion().GetNumRects() != 1 ||
    1.57 +          !(GetContentFlags() & Layer::CONTENT_OPAQUE))
    1.58 +      {
    1.59 +        gfx::Matrix transform;
    1.60 +        if (HasOpaqueAncestorLayer(this) &&
    1.61 +            GetEffectiveTransform().Is2D(&transform) &&
    1.62 +            !gfx::ThebesMatrix(transform).HasNonIntegerTranslation()) {
    1.63 +          SetSupportsComponentAlphaChildren(
    1.64 +            gfxPrefs::ComponentAlphaEnabled());
    1.65 +        }
    1.66 +      }
    1.67 +    } else {
    1.68 +      SetSupportsComponentAlphaChildren(
    1.69 +        (GetContentFlags() & Layer::CONTENT_OPAQUE) ||
    1.70 +        (GetParent() && GetParent()->SupportsComponentAlphaChildren()));
    1.71 +    }
    1.72 +
    1.73 +    nsAutoTArray<Layer*, 12> children;
    1.74 +    SortChildrenBy3DZOrder(children);
    1.75 +
    1.76 +    for (uint32_t i = 0; i < children.Length(); i++) {
    1.77 +      Layer* child = children.ElementAt(i);
    1.78 +      if (child->GetEffectiveVisibleRegion().IsEmpty()) {
    1.79 +        continue;
    1.80 +      }
    1.81 +
    1.82 +      ToClientLayer(child)->RenderLayer();
    1.83 +
    1.84 +      if (!ClientManager()->GetRepeatTransaction() &&
    1.85 +          !child->GetInvalidRegion().IsEmpty()) {
    1.86 +        child->Mutated();
    1.87 +      }
    1.88 +    }
    1.89 +  }
    1.90 +
    1.91 +  virtual void SetVisibleRegion(const nsIntRegion& aRegion)
    1.92 +  {
    1.93 +    NS_ASSERTION(ClientManager()->InConstruction(),
    1.94 +                 "Can only set properties in construction phase");
    1.95 +    ContainerLayer::SetVisibleRegion(aRegion);
    1.96 +  }
    1.97 +  virtual bool InsertAfter(Layer* aChild, Layer* aAfter) MOZ_OVERRIDE
    1.98 +  {
    1.99 +    if(!ClientManager()->InConstruction()) {
   1.100 +      NS_ERROR("Can only set properties in construction phase");
   1.101 +      return false;
   1.102 +    }
   1.103 +
   1.104 +    if (!ContainerLayer::InsertAfter(aChild, aAfter)) {
   1.105 +      return false;
   1.106 +    }
   1.107 +
   1.108 +    ClientManager()->AsShadowForwarder()->InsertAfter(ClientManager()->Hold(this),
   1.109 +                                                      ClientManager()->Hold(aChild),
   1.110 +                                                      aAfter ? ClientManager()->Hold(aAfter) : nullptr);
   1.111 +    return true;
   1.112 +  }
   1.113 +
   1.114 +  virtual bool RemoveChild(Layer* aChild) MOZ_OVERRIDE
   1.115 +  {
   1.116 +    if (!ClientManager()->InConstruction()) {
   1.117 +      NS_ERROR("Can only set properties in construction phase");
   1.118 +      return false;
   1.119 +    }
   1.120 +    // hold on to aChild before we remove it!
   1.121 +    ShadowableLayer *heldChild = ClientManager()->Hold(aChild);
   1.122 +    if (!ContainerLayer::RemoveChild(aChild)) {
   1.123 +      return false;
   1.124 +    }
   1.125 +    ClientManager()->AsShadowForwarder()->RemoveChild(ClientManager()->Hold(this), heldChild);
   1.126 +    return true;
   1.127 +  }
   1.128 +
   1.129 +  virtual bool RepositionChild(Layer* aChild, Layer* aAfter) MOZ_OVERRIDE
   1.130 +  {
   1.131 +    if (!ClientManager()->InConstruction()) {
   1.132 +      NS_ERROR("Can only set properties in construction phase");
   1.133 +      return false;
   1.134 +    }
   1.135 +    if (!ContainerLayer::RepositionChild(aChild, aAfter)) {
   1.136 +      return false;
   1.137 +    }
   1.138 +    ClientManager()->AsShadowForwarder()->RepositionChild(ClientManager()->Hold(this),
   1.139 +                                                          ClientManager()->Hold(aChild),
   1.140 +                                                          aAfter ? ClientManager()->Hold(aAfter) : nullptr);
   1.141 +    return true;
   1.142 +  }
   1.143 +
   1.144 +  virtual Layer* AsLayer() { return this; }
   1.145 +  virtual ShadowableLayer* AsShadowableLayer() { return this; }
   1.146 +
   1.147 +  virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
   1.148 +  {
   1.149 +    DefaultComputeEffectiveTransforms(aTransformToSurface);
   1.150 +  }
   1.151 +
   1.152 +  void ForceIntermediateSurface() { mUseIntermediateSurface = true; }
   1.153 +
   1.154 +  void SetSupportsComponentAlphaChildren(bool aSupports) { mSupportsComponentAlphaChildren = aSupports; }
   1.155 +
   1.156 +protected:
   1.157 +  ClientLayerManager* ClientManager()
   1.158 +  {
   1.159 +    return static_cast<ClientLayerManager*>(mManager);
   1.160 +  }
   1.161 +};
   1.162 +
   1.163 +class ClientRefLayer : public RefLayer,
   1.164 +                       public ClientLayer {
   1.165 +public:
   1.166 +  ClientRefLayer(ClientLayerManager* aManager) :
   1.167 +    RefLayer(aManager,
   1.168 +             static_cast<ClientLayer*>(MOZ_THIS_IN_INITIALIZER_LIST()))
   1.169 +  {
   1.170 +    MOZ_COUNT_CTOR(ClientRefLayer);
   1.171 +  }
   1.172 +  virtual ~ClientRefLayer()
   1.173 +  {
   1.174 +    MOZ_COUNT_DTOR(ClientRefLayer);
   1.175 +  }
   1.176 +
   1.177 +  virtual Layer* AsLayer() { return this; }
   1.178 +  virtual ShadowableLayer* AsShadowableLayer() { return this; }
   1.179 +
   1.180 +  virtual void Disconnect()
   1.181 +  {
   1.182 +    ClientLayer::Disconnect();
   1.183 +  }
   1.184 +
   1.185 +  virtual void RenderLayer() { }
   1.186 +
   1.187 +  virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
   1.188 +  {
   1.189 +    DefaultComputeEffectiveTransforms(aTransformToSurface);
   1.190 +  }
   1.191 +
   1.192 +private:
   1.193 +  ClientLayerManager* ClientManager()
   1.194 +  {
   1.195 +    return static_cast<ClientLayerManager*>(mManager);
   1.196 +  }
   1.197 +};
   1.198 +
   1.199 +}
   1.200 +}
   1.201 +
   1.202 +#endif

mercurial