Coverage Report

Created: 2018-09-25 14:53

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