1/*
2 * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *     * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32
33#ifndef LayerData_h
34#define LayerData_h
35
36#include "Color.h"
37#include "FilterOperations.h"
38#include "FloatPoint.h"
39#include "FloatRect.h"
40#include "IntRect.h"
41#include "TransformationMatrix.h"
42#include <wtf/HashMap.h>
43#include <wtf/text/WTFString.h>
44
45#if USE(ACCELERATED_COMPOSITING)
46
47namespace WebCore {
48
49class HTMLCanvasElement;
50class PluginView;
51#if ENABLE(VIDEO)
52class MediaPlayer;
53#endif
54
55class LayerData {
56public:
57    enum LayerType { Layer, TransformLayer, WebGLLayer, CanvasLayer, CustomLayer };
58    enum FilterType { Linear, Nearest, Trilinear, Lanczos };
59    enum LayerProgram {
60        LayerProgramRGBA = 0,
61        LayerProgramBGRA,
62        NumberOfLayerPrograms
63    };
64
65#if ENABLE(CSS_FILTERS)
66    enum CSSFilterShaders {
67        CSSFilterShaderGrayscale = 0,
68        CSSFilterShaderSepia,
69        CSSFilterShaderSaturate,
70        CSSFilterShaderHueRotate,
71        CSSFilterShaderInvert,
72        CSSFilterShaderBrightness,
73        CSSFilterShaderContrast,
74        CSSFilterShaderOpacity,
75        CSSFilterShaderBlurY,
76        CSSFilterShaderBlurX,
77        CSSFilterShaderShadow,
78        CSSFilterShaderPassthrough,
79#if ENABLE(CSS_SHADERS)
80        CSSFilterShaderCustom,
81#endif
82        NumberOfCSSFilterShaders
83    };
84#endif
85
86    LayerData(LayerType type)
87        : m_layerType(type)
88        , m_anchorPoint(0.5, 0.5)
89        , m_backgroundColor(0, 0, 0, 0)
90        , m_borderColor(0, 0, 0, 0)
91        , m_opacity(1.0)
92        , m_anchorPointZ(0.0)
93        , m_borderWidth(0.0)
94        , m_layerProgram(LayerProgramBGRA)
95        , m_pluginView(0)
96#if ENABLE(VIDEO)
97        , m_mediaPlayer(0)
98#endif
99        , m_suspendTime(0)
100        , m_contentsScale(1.0)
101        , m_doubleSided(true)
102        , m_masksToBounds(false)
103        , m_isOpaque(false)
104        , m_preserves3D(false)
105        , m_needsDisplayOnBoundsChange(false)
106        , m_needsTexture(false)
107        , m_isFixedPosition(false)
108        , m_hasFixedContainer(false)
109        , m_hasFixedAncestorInDOMTree(false)
110        , m_isContainerForFixedPositionLayers(false)
111        , m_sizeIsScaleInvariant(false)
112        , m_contentsResolutionIndependent(false)
113        , m_isVisible(true)
114    {
115    }
116
117    virtual ~LayerData()
118    {
119    }
120
121    FloatPoint anchorPoint() const { return m_anchorPoint; }
122
123    float anchorPointZ() const { return m_anchorPointZ; }
124
125    Color backgroundColor() const { return m_backgroundColor; }
126
127    Color borderColor() const { return m_borderColor; }
128
129    float borderWidth() const { return m_borderWidth; }
130
131    IntSize bounds() const { return m_bounds; }
132
133    bool sizeIsScaleInvariant() const { return m_sizeIsScaleInvariant; }
134
135    bool contentsResolutionIndependent() const { return m_contentsResolutionIndependent; }
136
137    bool doubleSided() const { return m_doubleSided; }
138
139    FloatRect frame() const { return m_frame; }
140
141    bool masksToBounds() const { return m_masksToBounds; }
142
143    float opacity() const { return m_opacity; }
144
145#if ENABLE(CSS_FILTERS)
146    FilterOperations filters() const { return m_filters; }
147#endif
148
149    bool isOpaque() const { return m_isOpaque; }
150
151    FloatPoint position() const { return m_position; }
152
153    // This is currently only used for perspective transform, see GraphicsLayer::setChildrenTransform()
154    const TransformationMatrix& sublayerTransform() const { return m_sublayerTransform; }
155
156    const TransformationMatrix& transform() const { return m_transform; }
157
158    bool preserves3D() const { return m_preserves3D; }
159
160    bool needsTexture() const { return m_layerType == WebGLLayer || m_layerType == CanvasLayer || m_needsTexture; }
161
162    LayerProgram layerProgram() const { return m_layerProgram; }
163
164    bool isFixedPosition() const { return m_isFixedPosition; }
165    bool hasFixedContainer() const { return m_hasFixedContainer; }
166    bool hasFixedAncestorInDOMTree() const { return m_hasFixedAncestorInDOMTree; }
167    bool isContainerForFixedPositionLayers() const { return m_isContainerForFixedPositionLayers; }
168    bool isFixedToTop() const { return m_isFixedToTop; }
169    bool isFixedToLeft() const { return m_isFixedToLeft; }
170
171    IntRect frameVisibleRect() const { return m_frameVisibleRect; }
172    IntSize frameContentsSize() const { return m_frameContentsSize; }
173
174    PluginView* pluginView() const { return m_pluginView; }
175
176    IntRect holePunchRect() const { return m_holePunchRect; }
177    bool hasHolePunchRect() const { return !m_holePunchRect.isEmpty(); }
178
179    double contentsScale() const { return m_contentsScale; }
180
181#if ENABLE(VIDEO)
182    MediaPlayer* mediaPlayer() const { return m_mediaPlayer; }
183#endif
184
185    void replicate(LayerData *to) const { *to = *this; }
186
187    LayerType layerType() const { return m_layerType; }
188
189    bool includeVisibility() const
190    {
191        if (pluginView())
192            return true;
193
194#if ENABLE(VIDEO)
195        if (mediaPlayer())
196            return true;
197#endif
198
199        return false;
200    }
201
202protected:
203    LayerType m_layerType;
204
205    IntSize m_bounds;
206    FloatPoint m_position;
207    FloatPoint m_anchorPoint;
208    Color m_backgroundColor;
209    Color m_borderColor;
210
211    FloatRect m_frame;
212    TransformationMatrix m_transform;
213    TransformationMatrix m_sublayerTransform;
214
215    float m_opacity;
216#if ENABLE(CSS_FILTERS)
217    FilterOperations m_filters;
218#endif
219    float m_anchorPointZ;
220    float m_borderWidth;
221
222    LayerProgram m_layerProgram;
223
224    PluginView* m_pluginView;
225#if ENABLE(VIDEO)
226    MediaPlayer* m_mediaPlayer;
227#endif
228    IntRect m_holePunchRect;
229
230    IntRect m_frameVisibleRect;
231    IntSize m_frameContentsSize;
232
233    double m_suspendTime;
234    double m_contentsScale;
235
236    unsigned m_doubleSided : 1;
237    unsigned m_masksToBounds : 1;
238    unsigned m_isOpaque : 1;
239    unsigned m_preserves3D : 1;
240    unsigned m_needsDisplayOnBoundsChange : 1;
241
242    unsigned m_needsTexture : 1;
243    unsigned m_isFixedPosition : 1;
244    unsigned m_hasFixedContainer : 1;
245    unsigned m_hasFixedAncestorInDOMTree : 1;
246    unsigned m_isContainerForFixedPositionLayers: 1;
247    unsigned m_isFixedToTop : 1;
248    unsigned m_isFixedToLeft : 1;
249
250    unsigned m_sizeIsScaleInvariant : 1;
251    unsigned m_contentsResolutionIndependent : 1;
252
253    // The following is only available for media (video) and plugin layers.
254    unsigned m_isVisible : 1;
255
256    // CAUTION: all the data members are copied from one instance to another
257    // i.e. from one thread to another in the replicate method.
258    // Beware of adding any member data e.g. of type String whose default
259    // assignment operator doesn't behave properly if the two String instances
260    // are owned by different threads.
261};
262
263} // namespace WebCore
264
265#endif // USE(ACCELERATED_COMPOSITING)
266
267#endif // LayerData_h
268