1 | /* |
2 | Copyright (C) 2010-2012 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 USE(COORDINATED_GRAPHICS) |
24 | |
25 | #include "FloatPoint.h" |
26 | #include "IntPoint.h" |
27 | #include "IntRect.h" |
28 | #include "Tile.h" |
29 | #include <wtf/Assertions.h> |
30 | #include <wtf/HashMap.h> |
31 | |
32 | namespace WebCore { |
33 | |
34 | class GraphicsContext; |
35 | class TiledBackingStoreClient; |
36 | |
37 | class TiledBackingStore { |
38 | WTF_MAKE_NONCOPYABLE(TiledBackingStore); WTF_MAKE_FAST_ALLOCATED; |
39 | public: |
40 | TiledBackingStore(TiledBackingStoreClient&, float contentsScale = 1.f); |
41 | ~TiledBackingStore(); |
42 | |
43 | TiledBackingStoreClient& client() { return m_client; } |
44 | |
45 | void setTrajectoryVector(const FloatPoint&); |
46 | void createTilesIfNeeded(const IntRect& unscaledVisibleRect, const IntRect& contentsRect); |
47 | |
48 | float contentsScale() { return m_contentsScale; } |
49 | |
50 | Vector<std::reference_wrapper<Tile>> dirtyTiles(); |
51 | |
52 | void invalidate(const IntRect& dirtyRect); |
53 | |
54 | WEBCORE_EXPORT IntRect mapToContents(const IntRect&) const; |
55 | IntRect mapFromContents(const IntRect&) const; |
56 | |
57 | IntRect tileRectForCoordinate(const Tile::Coordinate&) const; |
58 | Tile::Coordinate tileCoordinateForPoint(const IntPoint&) const; |
59 | double tileDistance(const IntRect& viewport, const Tile::Coordinate&) const; |
60 | |
61 | IntRect coverRect() const { return m_coverRect; } |
62 | bool visibleAreaIsCovered() const; |
63 | void removeAllNonVisibleTiles(const IntRect& unscaledVisibleRect, const IntRect& contentsRect); |
64 | |
65 | private: |
66 | void createTiles(const IntRect& visibleRect, const IntRect& scaledContentsRect, float coverAreaMultiplier); |
67 | void computeCoverAndKeepRect(const IntRect& visibleRect, IntRect& coverRect, IntRect& keepRect) const; |
68 | |
69 | void resizeEdgeTiles(); |
70 | void setCoverRect(const IntRect& rect) { m_coverRect = rect; } |
71 | void setKeepRect(const IntRect&); |
72 | |
73 | float coverageRatio(const IntRect&) const; |
74 | void adjustForContentsRect(IntRect&) const; |
75 | |
76 | void paintCheckerPattern(GraphicsContext*, const IntRect&, const Tile::Coordinate&); |
77 | |
78 | private: |
79 | TiledBackingStoreClient& m_client; |
80 | |
81 | typedef HashMap<Tile::Coordinate, std::unique_ptr<Tile>> TileMap; |
82 | TileMap m_tiles; |
83 | |
84 | IntSize m_tileSize; |
85 | float m_coverAreaMultiplier; |
86 | |
87 | FloatPoint m_trajectoryVector; |
88 | FloatPoint m_pendingTrajectoryVector; |
89 | IntRect m_visibleRect; |
90 | |
91 | IntRect m_coverRect; |
92 | IntRect m_keepRect; |
93 | IntRect m_rect; |
94 | IntRect m_previousRect; |
95 | |
96 | float m_contentsScale; |
97 | |
98 | bool m_pendingTileCreation; |
99 | |
100 | friend class Tile; |
101 | }; |
102 | |
103 | } |
104 | |
105 | #endif |
106 | #endif |
107 | |