• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "FloatSize.h"
26 #include "IntPoint.h"
27 #include "IntRect.h"
28 #include "Tile.h"
29 #include "Timer.h"
30 #include <wtf/Assertions.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/RefPtr.h>
33 
34 namespace WebCore {
35 
36 class GraphicsContext;
37 class TiledBackingStoreClient;
38 
39 class TiledBackingStore {
40     WTF_MAKE_NONCOPYABLE(TiledBackingStore); WTF_MAKE_FAST_ALLOCATED;
41 public:
42     TiledBackingStore(TiledBackingStoreClient*);
43     ~TiledBackingStore();
44 
45     void adjustVisibleRect();
46 
contentsScale()47     float contentsScale() { return m_contentsScale; }
48     void setContentsScale(float);
49 
contentsFrozen()50     bool contentsFrozen() const { return m_contentsFrozen; }
51     void setContentsFrozen(bool);
52 
53     void invalidate(const IntRect& dirtyRect);
54     void paint(GraphicsContext*, const IntRect&);
55 
tileSize()56     IntSize tileSize() { return m_tileSize; }
57     void setTileSize(const IntSize&);
58 
tileCreationDelay()59     double tileCreationDelay() const { return m_tileCreationDelay; }
60     void setTileCreationDelay(double delay);
61 
62     // Tiled are dropped outside the keep area, and created for cover area. The values a relative to the viewport size.
getKeepAndCoverAreaMultipliers(FloatSize & keepMultiplier,FloatSize & coverMultiplier)63     void getKeepAndCoverAreaMultipliers(FloatSize& keepMultiplier, FloatSize& coverMultiplier)
64     {
65         keepMultiplier = m_keepAreaMultiplier;
66         coverMultiplier = m_coverAreaMultiplier;
67     }
68     void setKeepAndCoverAreaMultipliers(const FloatSize& keepMultiplier, const FloatSize& coverMultiplier);
69 
70 private:
71     void startTileBufferUpdateTimer();
72     void startTileCreationTimer();
73 
74     typedef Timer<TiledBackingStore> TileTimer;
75 
76     void tileBufferUpdateTimerFired(TileTimer*);
77     void tileCreationTimerFired(TileTimer*);
78 
79     void updateTileBuffers();
80     void createTiles();
81 
82     void commitScaleChange();
83 
84     void dropOverhangingTiles();
85     void dropTilesOutsideRect(const IntRect&);
86 
87     PassRefPtr<Tile> tileAt(const Tile::Coordinate&) const;
88     void setTile(const Tile::Coordinate& coordinate, PassRefPtr<Tile> tile);
89     void removeTile(const Tile::Coordinate& coordinate);
90 
91     IntRect mapToContents(const IntRect&) const;
92     IntRect mapFromContents(const IntRect&) const;
93 
94     IntRect contentsRect() const;
95 
96     IntRect tileRectForCoordinate(const Tile::Coordinate&) const;
97     Tile::Coordinate tileCoordinateForPoint(const IntPoint&) const;
98     double tileDistance(const IntRect& viewport, const Tile::Coordinate&);
99 
100     void paintCheckerPattern(GraphicsContext*, const IntRect&, const Tile::Coordinate&);
101 
102 private:
103     TiledBackingStoreClient* m_client;
104 
105     typedef HashMap<Tile::Coordinate, RefPtr<Tile> > TileMap;
106     TileMap m_tiles;
107 
108     TileTimer* m_tileBufferUpdateTimer;
109     TileTimer* m_tileCreationTimer;
110 
111     IntSize m_tileSize;
112     double m_tileCreationDelay;
113     FloatSize m_keepAreaMultiplier;
114     FloatSize m_coverAreaMultiplier;
115 
116     IntRect m_previousVisibleRect;
117     float m_contentsScale;
118     float m_pendingScale;
119 
120     bool m_contentsFrozen;
121 
122     friend class Tile;
123 };
124 
125 }
126 
127 #endif
128 #endif
129