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" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "cc/hash_pair.h" | 11 #include "cc/hash_pair.h" |
12 #include "cc/scoped_ptr_hash_map.h" | 12 #include "cc/scoped_ptr_hash_map.h" |
| 13 #include "ui/gfx/rect.h" |
13 #include "IntRect.h" | 14 #include "IntRect.h" |
14 #include "Region.h" | 15 #include "Region.h" |
15 #include "TilingData.h" | 16 #include "TilingData.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 | 19 |
19 class LayerTilingData { | 20 class LayerTilingData { |
20 public: | 21 public: |
21 enum BorderTexelOption { HasBorderTexels, NoBorderTexels }; | 22 enum BorderTexelOption { HasBorderTexels, NoBorderTexels }; |
22 | 23 |
23 ~LayerTilingData(); | 24 ~LayerTilingData(); |
24 | 25 |
25 static scoped_ptr<LayerTilingData> create(const IntSize& tileSize, BorderTex
elOption); | 26 static scoped_ptr<LayerTilingData> create(const gfx::Size& tileSize, BorderT
exelOption); |
26 | 27 |
27 bool hasEmptyBounds() const { return m_tilingData.hasEmptyBounds(); } | 28 bool hasEmptyBounds() const { return m_tilingData.hasEmptyBounds(); } |
28 int numTilesX() const { return m_tilingData.numTilesX(); } | 29 int numTilesX() const { return m_tilingData.numTilesX(); } |
29 int numTilesY() const { return m_tilingData.numTilesY(); } | 30 int numTilesY() const { return m_tilingData.numTilesY(); } |
30 IntRect tileBounds(int i, int j) const { return m_tilingData.tileBounds(i, j
); } | 31 gfx::Rect tileBounds(int i, int j) const { return cc::IntRect(m_tilingData.t
ileBounds(i, j)); } |
31 IntPoint textureOffset(int xIndex, int yIndex) const { return m_tilingData.t
extureOffset(xIndex, yIndex); } | 32 gfx::Vector2d textureOffset(int xIndex, int yIndex) const { |
| 33 cc::IntPoint p(m_tilingData.textureOffset(xIndex, yIndex)); |
| 34 return gfx::Vector2d(p.x(), p.y()); |
| 35 } |
32 | 36 |
33 // Change the tile size. This may invalidate all the existing tiles. | 37 // Change the tile size. This may invalidate all the existing tiles. |
34 void setTileSize(const IntSize&); | 38 void setTileSize(const gfx::Size&); |
35 IntSize tileSize() const; | 39 gfx::Size tileSize() const; |
36 // Change the border texel setting. This may invalidate all existing tiles. | 40 // Change the border texel setting. This may invalidate all existing tiles. |
37 void setBorderTexelOption(BorderTexelOption); | 41 void setBorderTexelOption(BorderTexelOption); |
38 bool hasBorderTexels() const { return m_tilingData.borderTexels(); } | 42 bool hasBorderTexels() const { return m_tilingData.borderTexels(); } |
39 | 43 |
40 bool isEmpty() const { return hasEmptyBounds() || !tiles().size(); } | 44 bool isEmpty() const { return hasEmptyBounds() || !tiles().size(); } |
41 | 45 |
42 const LayerTilingData& operator=(const LayerTilingData&); | 46 const LayerTilingData& operator=(const LayerTilingData&); |
43 | 47 |
44 class Tile { | 48 class Tile { |
45 public: | 49 public: |
46 Tile() : m_i(-1), m_j(-1) { } | 50 Tile() : m_i(-1), m_j(-1) { } |
47 virtual ~Tile() { } | 51 virtual ~Tile() { } |
48 | 52 |
49 int i() const { return m_i; } | 53 int i() const { return m_i; } |
50 int j() const { return m_j; } | 54 int j() const { return m_j; } |
51 void moveTo(int i, int j) { m_i = i; m_j = j; } | 55 void moveTo(int i, int j) { m_i = i; m_j = j; } |
52 | 56 |
53 const IntRect& opaqueRect() const { return m_opaqueRect; } | 57 const gfx::Rect& opaqueRect() const { return m_opaqueRect; } |
54 void setOpaqueRect(const IntRect& opaqueRect) { m_opaqueRect = opaqueRec
t; } | 58 void setOpaqueRect(const gfx::Rect& opaqueRect) { m_opaqueRect = opaqueR
ect; } |
55 private: | 59 private: |
56 int m_i; | 60 int m_i; |
57 int m_j; | 61 int m_j; |
58 IntRect m_opaqueRect; | 62 gfx::Rect m_opaqueRect; |
59 DISALLOW_COPY_AND_ASSIGN(Tile); | 63 DISALLOW_COPY_AND_ASSIGN(Tile); |
60 }; | 64 }; |
61 typedef std::pair<int, int> TileMapKey; | 65 typedef std::pair<int, int> TileMapKey; |
62 typedef ScopedPtrHashMap<TileMapKey, Tile> TileMap; | 66 typedef ScopedPtrHashMap<TileMapKey, Tile> TileMap; |
63 | 67 |
64 void addTile(scoped_ptr<Tile>, int, int); | 68 void addTile(scoped_ptr<Tile>, int, int); |
65 scoped_ptr<Tile> takeTile(int, int); | 69 scoped_ptr<Tile> takeTile(int, int); |
66 Tile* tileAt(int, int) const; | 70 Tile* tileAt(int, int) const; |
67 const TileMap& tiles() const { return m_tiles; } | 71 const TileMap& tiles() const { return m_tiles; } |
68 | 72 |
69 void setBounds(const IntSize&); | 73 void setBounds(const gfx::Size&); |
70 IntSize bounds() const; | 74 gfx::Size bounds() const; |
71 | 75 |
72 void contentRectToTileIndices(const IntRect&, int &left, int &top, int &righ
t, int &bottom) const; | 76 void contentRectToTileIndices(const gfx::Rect&, int &left, int &top, int &ri
ght, int &bottom) const; |
73 IntRect tileRect(const Tile*) const; | 77 gfx::Rect tileRect(const Tile*) const; |
74 | 78 |
75 Region opaqueRegionInContentRect(const IntRect&) const; | 79 Region opaqueRegionInContentRect(const gfx::Rect&) const; |
76 | 80 |
77 void reset(); | 81 void reset(); |
78 | 82 |
79 protected: | 83 protected: |
80 LayerTilingData(const IntSize& tileSize, BorderTexelOption); | 84 LayerTilingData(const gfx::Size& tileSize, BorderTexelOption); |
81 | 85 |
82 TileMap m_tiles; | 86 TileMap m_tiles; |
83 TilingData m_tilingData; | 87 TilingData m_tilingData; |
84 }; | 88 }; |
85 | 89 |
86 } | 90 } |
87 | 91 |
88 #endif | 92 #endif |
OLD | NEW |