1/*
2 * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies)
3 * Copyright (C) 2013 Company 100, 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
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef CoordinatedGraphicsState_h
28#define CoordinatedGraphicsState_h
29
30#if USE(COORDINATED_GRAPHICS)
31
32#include "Color.h"
33#include "FloatRect.h"
34#include "FloatSize.h"
35#include "GraphicsLayerAnimation.h"
36#include "IntRect.h"
37#include "IntSize.h"
38#include "SurfaceUpdateInfo.h"
39#include "TransformationMatrix.h"
40
41#if ENABLE(CSS_FILTERS)
42#include "FilterOperations.h"
43#endif
44
45#if ENABLE(CSS_FILTERS)
46#include "CustomFilterProgramInfo.h"
47#endif
48
49#if USE(GRAPHICS_SURFACE)
50#include "GraphicsSurface.h"
51#include "GraphicsSurfaceToken.h"
52#endif
53
54namespace WebCore {
55
56class CoordinatedSurface;
57
58typedef uint32_t CoordinatedLayerID;
59enum { InvalidCoordinatedLayerID = 0 };
60
61typedef uint64_t CoordinatedImageBackingID;
62enum { InvalidCoordinatedImageBackingID = 0 };
63
64struct TileUpdateInfo {
65    uint32_t tileID;
66    IntRect tileRect;
67    WebCore::SurfaceUpdateInfo updateInfo;
68};
69
70struct TileCreationInfo {
71    uint32_t tileID;
72    float scale;
73};
74
75struct CoordinatedGraphicsLayerState {
76    union {
77        struct {
78            bool positionChanged: 1;
79            bool anchorPointChanged: 1;
80            bool sizeChanged: 1;
81            bool transformChanged: 1;
82            bool childrenTransformChanged: 1;
83            bool contentsRectChanged: 1;
84            bool opacityChanged: 1;
85            bool solidColorChanged: 1;
86            bool debugBorderColorChanged: 1;
87            bool debugBorderWidthChanged: 1;
88            bool replicaChanged: 1;
89            bool maskChanged: 1;
90            bool imageChanged: 1;
91            bool flagsChanged: 1;
92            bool animationsChanged: 1;
93            bool filtersChanged: 1;
94            bool childrenChanged: 1;
95            bool repaintCountChanged : 1;
96            bool canvasChanged: 1;
97            bool canvasShouldSwapBuffers: 1;
98            bool isScrollableChanged: 1;
99            bool committedScrollOffsetChanged: 1;
100            bool contentsTilingChanged: 1;
101        };
102        unsigned changeMask;
103    };
104    union {
105        struct {
106            bool contentsOpaque : 1;
107            bool drawsContent : 1;
108            bool contentsVisible : 1;
109            bool backfaceVisible : 1;
110            bool masksToBounds : 1;
111            bool preserves3D : 1;
112            bool fixedToViewport : 1;
113            bool showDebugBorders : 1;
114            bool showRepaintCounter : 1;
115            bool isScrollable: 1;
116        };
117        unsigned flags;
118    };
119
120    CoordinatedGraphicsLayerState()
121        : changeMask(0)
122        , contentsOpaque(false)
123        , drawsContent(false)
124        , contentsVisible(true)
125        , backfaceVisible(true)
126        , masksToBounds(false)
127        , preserves3D(false)
128        , fixedToViewport(false)
129        , showDebugBorders(false)
130        , showRepaintCounter(false)
131        , isScrollable(false)
132        , opacity(0)
133        , debugBorderWidth(0)
134        , replica(InvalidCoordinatedLayerID)
135        , mask(InvalidCoordinatedLayerID)
136        , imageID(InvalidCoordinatedImageBackingID)
137#if USE(GRAPHICS_SURFACE)
138        , canvasFrontBuffer(0)
139#endif
140    {
141    }
142
143    FloatPoint pos;
144    FloatPoint3D anchorPoint;
145    FloatSize size;
146    TransformationMatrix transform;
147    TransformationMatrix childrenTransform;
148    IntRect contentsRect;
149    IntPoint contentsTilePhase;
150    IntSize contentsTileSize;
151    float opacity;
152    Color solidColor;
153    Color debugBorderColor;
154    float debugBorderWidth;
155#if ENABLE(CSS_FILTERS)
156    FilterOperations filters;
157#endif
158    GraphicsLayerAnimations animations;
159    Vector<uint32_t> children;
160    Vector<TileCreationInfo> tilesToCreate;
161    Vector<uint32_t> tilesToRemove;
162    CoordinatedLayerID replica;
163    CoordinatedLayerID mask;
164    CoordinatedImageBackingID imageID;
165
166    unsigned repaintCount;
167    Vector<TileUpdateInfo> tilesToUpdate;
168
169#if USE(GRAPHICS_SURFACE)
170    IntSize canvasSize;
171    GraphicsSurfaceToken canvasToken;
172    uint32_t canvasFrontBuffer;
173    GraphicsSurface::Flags canvasSurfaceFlags;
174#endif
175
176    IntSize committedScrollOffset;
177
178    bool hasPendingChanges() const
179    {
180        return changeMask || tilesToUpdate.size() || tilesToRemove.size() || tilesToCreate.size();
181    }
182};
183
184struct CoordinatedGraphicsState {
185    uint32_t rootCompositingLayer;
186    FloatPoint scrollPosition;
187    IntSize contentsSize;
188    IntRect coveredRect;
189
190    Vector<CoordinatedLayerID> layersToCreate;
191    Vector<std::pair<CoordinatedLayerID, CoordinatedGraphicsLayerState> > layersToUpdate;
192    Vector<CoordinatedLayerID> layersToRemove;
193
194    Vector<CoordinatedImageBackingID> imagesToCreate;
195    Vector<CoordinatedImageBackingID> imagesToRemove;
196    Vector<std::pair<CoordinatedImageBackingID, RefPtr<CoordinatedSurface> > > imagesToUpdate;
197    Vector<CoordinatedImageBackingID> imagesToClear;
198
199    Vector<std::pair<uint32_t /* atlasID */, RefPtr<CoordinatedSurface> > > updateAtlasesToCreate;
200    Vector<uint32_t /* atlasID */> updateAtlasesToRemove;
201
202#if ENABLE(CSS_SHADERS)
203    Vector<std::pair<uint32_t /* FilterID */, CustomFilterProgramInfo> > customFiltersToCreate;
204    Vector<uint32_t> customFiltersToRemove;
205#endif
206};
207
208} // namespace WebCore
209
210#endif // USE(COORDINATED_GRAPHICS)
211
212#endif // CoordinatedGraphicsState_h
213