LCOV - code coverage report
Current view: top level - gfx/layers/client - ClientContainerLayer.h (source / functions) Hit Total Coverage
Test: output.info Lines: 56 75 74.7 %
Date: 2017-07-14 16:53:18 Functions: 16 19 84.2 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       5             : 
       6             : #ifndef GFX_CLIENTCONTAINERLAYER_H
       7             : #define GFX_CLIENTCONTAINERLAYER_H
       8             : 
       9             : #include <stdint.h>                     // for uint32_t
      10             : #include "ClientLayerManager.h"         // for ClientLayerManager, etc
      11             : #include "Layers.h"                     // for Layer, ContainerLayer, etc
      12             : #include "nsDebug.h"                    // for NS_ASSERTION
      13             : #include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
      14             : #include "nsISupportsUtils.h"           // for NS_ADDREF, NS_RELEASE
      15             : #include "nsRegion.h"                   // for nsIntRegion
      16             : #include "nsTArray.h"                   // for AutoTArray
      17             : #include "ReadbackProcessor.h"
      18             : #include "ClientPaintedLayer.h"
      19             : 
      20             : namespace mozilla {
      21             : namespace layers {
      22             : 
      23             : class ShadowableLayer;
      24             : 
      25             : class ClientContainerLayer : public ContainerLayer,
      26             :                              public ClientLayer
      27             : {
      28             : public:
      29           4 :   explicit ClientContainerLayer(ClientLayerManager* aManager) :
      30           4 :     ContainerLayer(aManager, static_cast<ClientLayer*>(this))
      31             :   {
      32           4 :     MOZ_COUNT_CTOR(ClientContainerLayer);
      33           4 :     mSupportsComponentAlphaChildren = true;
      34           4 :   }
      35             : 
      36             : protected:
      37           4 :   virtual ~ClientContainerLayer()
      38           4 :   {
      39           2 :     ContainerLayer::RemoveAllChildren();
      40           2 :     MOZ_COUNT_DTOR(ClientContainerLayer);
      41           6 :   }
      42             : 
      43             : public:
      44          57 :   virtual void RenderLayer() override
      45             :   {
      46          57 :     RenderMaskLayers(this);
      47             : 
      48          57 :     DefaultComputeSupportsComponentAlphaChildren();
      49             : 
      50         114 :     ReadbackProcessor readback;
      51          57 :     readback.BuildUpdates(this);
      52             : 
      53         114 :     nsTArray<Layer*> children = CollectChildren();
      54         192 :     for (uint32_t i = 0; i < children.Length(); i++) {
      55         135 :       Layer* child = children.ElementAt(i);
      56             : 
      57         135 :       ToClientLayer(child)->RenderLayerWithReadback(&readback);
      58             : 
      59         270 :       if (!ClientManager()->GetRepeatTransaction() &&
      60         135 :           !child->GetInvalidRegion().IsEmpty()) {
      61          46 :         child->Mutated();
      62             :       }
      63             :     }
      64          57 :   }
      65             : 
      66          54 :   virtual void SetVisibleRegion(const LayerIntRegion& aRegion) override
      67             :   {
      68          54 :     NS_ASSERTION(ClientManager()->InConstruction(),
      69             :                  "Can only set properties in construction phase");
      70          54 :     ContainerLayer::SetVisibleRegion(aRegion);
      71          54 :   }
      72          27 :   virtual bool InsertAfter(Layer* aChild, Layer* aAfter) override
      73             :   {
      74          27 :     if(!ClientManager()->InConstruction()) {
      75           0 :       NS_ERROR("Can only set properties in construction phase");
      76           0 :       return false;
      77             :     }
      78             : 
      79          27 :     if (!ContainerLayer::InsertAfter(aChild, aAfter)) {
      80           0 :       return false;
      81             :     }
      82             : 
      83          50 :     ClientManager()->AsShadowForwarder()->InsertAfter(ClientManager()->Hold(this),
      84             :                                                       ClientManager()->Hold(aChild),
      85          50 :                                                       aAfter ? ClientManager()->Hold(aAfter) : nullptr);
      86          27 :     return true;
      87             :   }
      88             : 
      89          20 :   virtual bool RemoveChild(Layer* aChild) override
      90             :   {
      91          20 :     if (!ClientManager()->InConstruction()) {
      92           0 :       NS_ERROR("Can only set properties in construction phase");
      93           0 :       return false;
      94             :     }
      95             :     // hold on to aChild before we remove it!
      96          20 :     ShadowableLayer *heldChild = ClientManager()->Hold(aChild);
      97          20 :     if (!ContainerLayer::RemoveChild(aChild)) {
      98           0 :       return false;
      99             :     }
     100          20 :     ClientManager()->AsShadowForwarder()->RemoveChild(ClientManager()->Hold(this), heldChild);
     101          20 :     return true;
     102             :   }
     103             : 
     104           0 :   virtual bool RepositionChild(Layer* aChild, Layer* aAfter) override
     105             :   {
     106           0 :     if (!ClientManager()->InConstruction()) {
     107           0 :       NS_ERROR("Can only set properties in construction phase");
     108           0 :       return false;
     109             :     }
     110           0 :     if (!ContainerLayer::RepositionChild(aChild, aAfter)) {
     111           0 :       return false;
     112             :     }
     113           0 :     ClientManager()->AsShadowForwarder()->RepositionChild(ClientManager()->Hold(this),
     114             :                                                           ClientManager()->Hold(aChild),
     115           0 :                                                           aAfter ? ClientManager()->Hold(aAfter) : nullptr);
     116           0 :     return true;
     117             :   }
     118             : 
     119          49 :   virtual Layer* AsLayer() override { return this; }
     120          87 :   virtual ShadowableLayer* AsShadowableLayer() override { return this; }
     121             : 
     122          57 :   virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override
     123             :   {
     124          57 :     DefaultComputeEffectiveTransforms(aTransformToSurface);
     125          57 :   }
     126             : 
     127             :   void ForceIntermediateSurface() { mUseIntermediateSurface = true; }
     128             : 
     129             :   void SetSupportsComponentAlphaChildren(bool aSupports) { mSupportsComponentAlphaChildren = aSupports; }
     130             : 
     131             : protected:
     132         400 :   ClientLayerManager* ClientManager()
     133             :   {
     134         400 :     return static_cast<ClientLayerManager*>(mManager);
     135             :   }
     136             : };
     137             : 
     138             : class ClientRefLayer : public RefLayer,
     139             :                        public ClientLayer {
     140             : public:
     141           1 :   explicit ClientRefLayer(ClientLayerManager* aManager) :
     142           1 :     RefLayer(aManager, static_cast<ClientLayer*>(this))
     143             :   {
     144           1 :     MOZ_COUNT_CTOR(ClientRefLayer);
     145           1 :   }
     146             : 
     147             : protected:
     148           0 :   virtual ~ClientRefLayer()
     149           0 :   {
     150           0 :     MOZ_COUNT_DTOR(ClientRefLayer);
     151           0 :   }
     152             : 
     153             : public:
     154          26 :   virtual Layer* AsLayer() { return this; }
     155          51 :   virtual ShadowableLayer* AsShadowableLayer() { return this; }
     156             : 
     157          25 :   virtual void RenderLayer() { }
     158             : 
     159          25 :   virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
     160             :   {
     161          25 :     DefaultComputeEffectiveTransforms(aTransformToSurface);
     162          25 :   }
     163             : 
     164             : private:
     165             :   ClientLayerManager* ClientManager()
     166             :   {
     167             :     return static_cast<ClientLayerManager*>(mManager);
     168             :   }
     169             : };
     170             : 
     171             : } // namespace layers
     172             : } // namespace mozilla
     173             : 
     174             : #endif

Generated by: LCOV version 1.13