OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #ifndef CCLayerTilingData_h | 6 #ifndef CCLayerTilingData_h |
7 #define CCLayerTilingData_h | 7 #define CCLayerTilingData_h |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "cc/hash_pair.h" |
| 12 #include "cc/scoped_ptr_hash_map.h" |
10 #include "IntRect.h" | 13 #include "IntRect.h" |
11 #include "Region.h" | 14 #include "Region.h" |
12 #include "TilingData.h" | 15 #include "TilingData.h" |
13 #include <wtf/HashMap.h> | |
14 #include <wtf/HashTraits.h> | |
15 #include <wtf/PassOwnPtr.h> | |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 class CCLayerTilingData { | 19 class CCLayerTilingData { |
20 public: | 20 public: |
21 enum BorderTexelOption { HasBorderTexels, NoBorderTexels }; | 21 enum BorderTexelOption { HasBorderTexels, NoBorderTexels }; |
22 | 22 |
23 ~CCLayerTilingData(); | 23 ~CCLayerTilingData(); |
24 | 24 |
25 static PassOwnPtr<CCLayerTilingData> create(const IntSize& tileSize, BorderT
exelOption); | 25 static scoped_ptr<CCLayerTilingData> create(const IntSize& tileSize, BorderT
exelOption); |
26 | 26 |
27 bool hasEmptyBounds() const { return m_tilingData.hasEmptyBounds(); } | 27 bool hasEmptyBounds() const { return m_tilingData.hasEmptyBounds(); } |
28 int numTilesX() const { return m_tilingData.numTilesX(); } | 28 int numTilesX() const { return m_tilingData.numTilesX(); } |
29 int numTilesY() const { return m_tilingData.numTilesY(); } | 29 int numTilesY() const { return m_tilingData.numTilesY(); } |
30 IntRect tileBounds(int i, int j) const { return m_tilingData.tileBounds(i, j
); } | 30 IntRect tileBounds(int i, int j) const { return m_tilingData.tileBounds(i, j
); } |
31 IntPoint textureOffset(int xIndex, int yIndex) const { return m_tilingData.t
extureOffset(xIndex, yIndex); } | 31 IntPoint textureOffset(int xIndex, int yIndex) const { return m_tilingData.t
extureOffset(xIndex, yIndex); } |
32 | 32 |
33 // Change the tile size. This may invalidate all the existing tiles. | 33 // Change the tile size. This may invalidate all the existing tiles. |
34 void setTileSize(const IntSize&); | 34 void setTileSize(const IntSize&); |
35 IntSize tileSize() const; | 35 IntSize tileSize() const; |
(...skipping 15 matching lines...) Expand all Loading... |
51 void moveTo(int i, int j) { m_i = i; m_j = j; } | 51 void moveTo(int i, int j) { m_i = i; m_j = j; } |
52 | 52 |
53 const IntRect& opaqueRect() const { return m_opaqueRect; } | 53 const IntRect& opaqueRect() const { return m_opaqueRect; } |
54 void setOpaqueRect(const IntRect& opaqueRect) { m_opaqueRect = opaqueRec
t; } | 54 void setOpaqueRect(const IntRect& opaqueRect) { m_opaqueRect = opaqueRec
t; } |
55 private: | 55 private: |
56 int m_i; | 56 int m_i; |
57 int m_j; | 57 int m_j; |
58 IntRect m_opaqueRect; | 58 IntRect m_opaqueRect; |
59 DISALLOW_COPY_AND_ASSIGN(Tile); | 59 DISALLOW_COPY_AND_ASSIGN(Tile); |
60 }; | 60 }; |
61 // Default hash key traits for integers disallow 0 and -1 as a key, so | |
62 // use a custom hash trait which disallows -1 and -2 instead. | |
63 typedef std::pair<int, int> TileMapKey; | 61 typedef std::pair<int, int> TileMapKey; |
64 struct TileMapKeyTraits : HashTraits<TileMapKey> { | 62 typedef ScopedPtrHashMap<TileMapKey, Tile> TileMap; |
65 static const bool emptyValueIsZero = false; | |
66 static const bool needsDestruction = false; | |
67 static TileMapKey emptyValue() { return std::make_pair(-1, -1); } | |
68 static void constructDeletedValue(TileMapKey& slot) { slot = std::make_p
air(-2, -2); } | |
69 static bool isDeletedValue(TileMapKey value) { return value.first == -2
&& value.second == -2; } | |
70 }; | |
71 typedef HashMap<TileMapKey, OwnPtr<Tile>, DefaultHash<TileMapKey>::Hash, Til
eMapKeyTraits> TileMap; | |
72 | 63 |
73 void addTile(PassOwnPtr<Tile>, int, int); | 64 void addTile(scoped_ptr<Tile>, int, int); |
74 PassOwnPtr<Tile> takeTile(int, int); | 65 scoped_ptr<Tile> takeTile(int, int); |
75 Tile* tileAt(int, int) const; | 66 Tile* tileAt(int, int) const; |
76 const TileMap& tiles() const { return m_tiles; } | 67 const TileMap& tiles() const { return m_tiles; } |
77 | 68 |
78 void setBounds(const IntSize&); | 69 void setBounds(const IntSize&); |
79 IntSize bounds() const; | 70 IntSize bounds() const; |
80 | 71 |
81 void contentRectToTileIndices(const IntRect&, int &left, int &top, int &righ
t, int &bottom) const; | 72 void contentRectToTileIndices(const IntRect&, int &left, int &top, int &righ
t, int &bottom) const; |
82 IntRect tileRect(const Tile*) const; | 73 IntRect tileRect(const Tile*) const; |
83 | 74 |
84 Region opaqueRegionInContentRect(const IntRect&) const; | 75 Region opaqueRegionInContentRect(const IntRect&) const; |
85 | 76 |
86 void reset(); | 77 void reset(); |
87 | 78 |
88 protected: | 79 protected: |
89 CCLayerTilingData(const IntSize& tileSize, BorderTexelOption); | 80 CCLayerTilingData(const IntSize& tileSize, BorderTexelOption); |
90 | 81 |
91 TileMap m_tiles; | 82 TileMap m_tiles; |
92 TilingData m_tilingData; | 83 TilingData m_tilingData; |
93 }; | 84 }; |
94 | 85 |
95 } | 86 } |
96 | 87 |
97 #endif | 88 #endif |
OLD | NEW |