initial import
[vuplus_webkit] / Source / WebCore / platform / graphics / TiledBackingStore.h
1 /*
2  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3  
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8  
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  Library General Public License for more details.
13  
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB.  If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef TiledBackingStore_h
21 #define TiledBackingStore_h
22
23 #if ENABLE(TILED_BACKING_STORE)
24
25 #include "FloatPoint.h"
26 #include "IntPoint.h"
27 #include "IntRect.h"
28 #include "Tile.h"
29 #include "TiledBackingStoreBackend.h"
30 #include "Timer.h"
31 #include <wtf/Assertions.h>
32 #include <wtf/HashMap.h>
33 #include <wtf/RefPtr.h>
34
35 namespace WebCore {
36
37 class GraphicsContext;
38 class TiledBackingStore;
39 class TiledBackingStoreClient;
40
41 class TiledBackingStore {
42     WTF_MAKE_NONCOPYABLE(TiledBackingStore); WTF_MAKE_FAST_ALLOCATED;
43 public:
44     TiledBackingStore(TiledBackingStoreClient*, PassOwnPtr<TiledBackingStoreBackend> = TiledBackingStoreBackend::create());
45     ~TiledBackingStore();
46
47     void adjustVisibleRect();
48     
49     TiledBackingStoreClient* client() { return m_client; }
50     float contentsScale() { return m_contentsScale; }
51     void setContentsScale(float);
52     
53     bool contentsFrozen() const { return m_contentsFrozen; }
54     void setContentsFrozen(bool);
55     void updateTileBuffers();
56
57     void invalidate(const IntRect& dirtyRect);
58     void paint(GraphicsContext*, const IntRect&);
59     
60     IntSize tileSize() { return m_tileSize; }
61     void setTileSize(const IntSize&);
62     
63     double tileCreationDelay() const { return m_tileCreationDelay; }
64     void setTileCreationDelay(double delay);
65     
66     // Tiled are dropped outside the keep area, and created for cover area. The values a relative to the viewport size.
67     void getKeepAndCoverAreaMultipliers(float& keepMultiplier, float& coverMultiplier)
68     {
69         keepMultiplier = m_keepAreaMultiplier;
70         coverMultiplier = m_coverAreaMultiplier;
71     }
72     void setKeepAndCoverAreaMultipliers(float keepMultiplier, float coverMultiplier);
73     void setVisibleRectTrajectoryVector(const FloatPoint&);
74
75     IntRect mapToContents(const IntRect&) const;
76     IntRect mapFromContents(const IntRect&) const;
77
78     IntRect tileRectForCoordinate(const Tile::Coordinate&) const;
79     Tile::Coordinate tileCoordinateForPoint(const IntPoint&) const;
80     double tileDistance(const IntRect& viewport, const Tile::Coordinate&) const;
81     float coverageRatio(const WebCore::IntRect& contentsRect);
82
83 private:
84     void startTileBufferUpdateTimer();
85     void startTileCreationTimer();
86     
87     typedef Timer<TiledBackingStore> TileTimer;
88
89     void tileBufferUpdateTimerFired(TileTimer*);
90     void tileCreationTimerFired(TileTimer*);
91     
92     void createTiles();
93     IntRect computeKeepRect(const IntRect& visibleRect) const;
94     IntRect computeCoverRect(const IntRect& visibleRect) const;
95     
96     void commitScaleChange();
97
98     bool resizeEdgeTiles();
99     void dropTilesOutsideRect(const IntRect&);
100     
101     PassRefPtr<Tile> tileAt(const Tile::Coordinate&) const;
102     void setTile(const Tile::Coordinate& coordinate, PassRefPtr<Tile> tile);
103     void removeTile(const Tile::Coordinate& coordinate);
104
105     IntRect contentsRect() const;
106     
107     void paintCheckerPattern(GraphicsContext*, const IntRect&, const Tile::Coordinate&);
108
109 private:
110     TiledBackingStoreClient* m_client;
111     OwnPtr<TiledBackingStoreBackend> m_backend;
112
113     typedef HashMap<Tile::Coordinate, RefPtr<Tile> > TileMap;
114     TileMap m_tiles;
115
116     TileTimer* m_tileBufferUpdateTimer;
117     TileTimer* m_tileCreationTimer;
118
119     IntSize m_tileSize;
120     double m_tileCreationDelay;
121     float m_keepAreaMultiplier;
122     float m_coverAreaMultiplier;
123     FloatPoint m_visibleRectTrajectoryVector;
124     
125     IntRect m_previousVisibleRect;
126     float m_contentsScale;
127     float m_pendingScale;
128
129     bool m_contentsFrozen;
130
131     friend class Tile;
132 };
133
134 }
135
136 #endif
137 #endif