summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h
blob: 649f4ddd77c1d7319326ab6c5b52b2aa4efc01af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 * Copyright (C) 2011 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef CCLayerImpl_h
#define CCLayerImpl_h

#include "Color.h"
#include "FloatRect.h"
#include "IntRect.h"
#include "TextStream.h"
#include "TransformationMatrix.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>

namespace WebCore {

class LayerChromium;
class LayerRendererChromium;
class RenderSurfaceChromium;

class CCLayerImpl : public RefCounted<CCLayerImpl> {
public:
    static PassRefPtr<CCLayerImpl> create(LayerChromium* owner)
    {
        return adoptRef(new CCLayerImpl(owner));
    }
    // When this class gets subclasses, remember to add 'virtual' here.
    virtual ~CCLayerImpl();
    void resetOwner() { m_owner = 0; }

#ifndef NDEBUG
    int debugID() const { return m_debugID; }
#endif

    CCLayerImpl* superlayer() const;
    CCLayerImpl* maskLayer() const;
    CCLayerImpl* replicaLayer() const;

    virtual void draw(const IntRect& contentRect);
    virtual void updateCompositorResources();
    void unreserveContentsTexture();
    void bindContentsTexture();

    // Returns true if this layer has content to draw.
    virtual bool drawsContent() const;

    // Returns true if any of the layer's descendants has content to draw.
    bool descendantsDrawsContent();

    void cleanupResources();

    void setAnchorPoint(const FloatPoint& anchorPoint) { m_anchorPoint = anchorPoint; }
    const FloatPoint& anchorPoint() const { return m_anchorPoint; }

    void setAnchorPointZ(float anchorPointZ) { m_anchorPointZ = anchorPointZ; }
    float anchorPointZ() const { return m_anchorPointZ; }

    void setMasksToBounds(bool masksToBounds) { m_masksToBounds = masksToBounds; }
    bool masksToBounds() const { return m_masksToBounds; }

    void setOpacity(float opacity) { m_opacity = opacity; }
    float opacity() const { return m_opacity; }

    void setPosition(const FloatPoint& position) { m_position = position; }
    const FloatPoint& position() const { return m_position; }

    void setPreserves3D(bool preserves3D) { m_preserves3D = preserves3D; }
    bool preserves3D() const { return m_preserves3D; }

    void setSublayerTransform(const TransformationMatrix& sublayerTransform) { m_sublayerTransform = sublayerTransform; }
    const TransformationMatrix& sublayerTransform() const { return m_sublayerTransform; }

    void setTransform(const TransformationMatrix& transform) { m_transform = transform; }
    const TransformationMatrix& transform() const { return m_transform; }

    void setName(const String& name) { m_name = name; }
    const String& name() const { return m_name; }

    // Debug layer border - visual effect only, do not change geometry/clipping/etc.
    void setDebugBorderColor(Color c) { m_debugBorderColor = c; }
    Color debugBorderColor() const { return m_debugBorderColor; }
    void setDebugBorderWidth(float width) { m_debugBorderWidth = width; }
    float debugBorderWidth() const { return m_debugBorderWidth; }

    void drawDebugBorder();

    void setLayerRenderer(LayerRendererChromium*);
    LayerRendererChromium* layerRenderer() const { return m_layerRenderer.get(); }

    RenderSurfaceChromium* createRenderSurface();

    RenderSurfaceChromium* renderSurface() const { return m_renderSurface.get(); }
    void clearRenderSurface() { m_renderSurface.clear(); }
    float drawDepth() const { return m_drawDepth; }
    void setDrawDepth(float depth) { m_drawDepth = depth; }
    float drawOpacity() const { return m_drawOpacity; }
    void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
    const IntRect& scissorRect() const { return m_scissorRect; }
    void setScissorRect(const IntRect& rect) { m_scissorRect = rect; }
    RenderSurfaceChromium* targetRenderSurface() const { return m_targetRenderSurface; }
    void setTargetRenderSurface(RenderSurfaceChromium* surface) { m_targetRenderSurface = surface; }

    bool doubleSided() const { return m_doubleSided; }
    void setDoubleSided(bool doubleSided) { m_doubleSided = doubleSided; }
    const IntSize& bounds() const { return m_bounds; }
    void setBounds(const IntSize& bounds) { m_bounds = bounds; }

    // Returns the rect containtaining this layer in the current view's coordinate system.
    const IntRect getDrawRect() const;

    const TransformationMatrix& drawTransform() const { return m_drawTransform; }
    void setDrawTransform(const TransformationMatrix& matrix) { m_drawTransform = matrix; }
    const IntRect& drawableContentRect() const { return m_drawableContentRect; }
    void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = rect; }

    virtual void dumpLayerProperties(TextStream&, int indent) const;

protected:
    // For now, CCLayers are owned directly by a LayerChromium.
    LayerChromium* m_owner;
    explicit CCLayerImpl(LayerChromium*);

    static void writeIndent(TextStream&, int indent);

private:
    // Properties synchronized from the associated LayerChromium.
    FloatPoint m_anchorPoint;
    float m_anchorPointZ;
    IntSize m_bounds;

    // Whether the "back" of this layer should draw.
    bool m_doubleSided;

    bool m_masksToBounds;
    float m_opacity;
    FloatPoint m_position;
    bool m_preserves3D;
    TransformationMatrix m_sublayerTransform;
    TransformationMatrix m_transform;

    // Properties owned exclusively by this CCLayerImpl.
    // Debugging.
#ifndef NDEBUG
    int m_debugID;
#endif

    String m_name;

    // Render surface this layer draws into. This is a surface that can belong
    // either to this layer (if m_targetRenderSurface == m_renderSurface) or
    // to an ancestor of this layer. The target render surface determines the
    // coordinate system the layer's transforms are relative to.
    RenderSurfaceChromium* m_targetRenderSurface;

    // The global depth value of the center of the layer. This value is used
    // to sort layers from back to front.
    float m_drawDepth;
    float m_drawOpacity;

    // Debug borders.
    Color m_debugBorderColor;
    float m_debugBorderWidth;

    TransformationMatrix m_drawTransform;

    // The scissor rectangle that should be used when this layer is drawn.
    // Inherited by the parent layer and further restricted if this layer masks
    // to bounds.
    IntRect m_scissorRect;

    // Render surface associated with this layer. The layer and its descendants
    // will render to this surface.
    OwnPtr<RenderSurfaceChromium> m_renderSurface;

    // Hierarchical bounding rect containing the layer and its descendants.
    IntRect m_drawableContentRect;

    // Points to the layer renderer that updates and draws this layer.
    RefPtr<LayerRendererChromium> m_layerRenderer;
};

}

#endif // CCLayerImpl_h