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
3 // found in the LICENSE file.
6 #ifndef CCLayerTilingData_h
7 #define CCLayerTilingData_h
9 #if USE(ACCELERATED_COMPOSITING)
11 #include "base/basictypes.h"
14 #include "TilingData.h"
15 #include <wtf/HashMap.h>
16 #include <wtf/HashTraits.h>
17 #include <wtf/PassOwnPtr.h>
21 class CCLayerTilingData
{
23 enum BorderTexelOption
{ HasBorderTexels
, NoBorderTexels
};
27 static PassOwnPtr
<CCLayerTilingData
> create(const IntSize
& tileSize
, BorderTexelOption
);
29 bool hasEmptyBounds() const { return m_tilingData
.hasEmptyBounds(); }
30 int numTilesX() const { return m_tilingData
.numTilesX(); }
31 int numTilesY() const { return m_tilingData
.numTilesY(); }
32 IntRect
tileBounds(int i
, int j
) const { return m_tilingData
.tileBounds(i
, j
); }
33 IntPoint
textureOffset(int xIndex
, int yIndex
) const { return m_tilingData
.textureOffset(xIndex
, yIndex
); }
35 // Change the tile size. This may invalidate all the existing tiles.
36 void setTileSize(const IntSize
&);
37 IntSize
tileSize() const;
38 // Change the border texel setting. This may invalidate all existing tiles.
39 void setBorderTexelOption(BorderTexelOption
);
40 bool hasBorderTexels() const { return m_tilingData
.borderTexels(); }
42 bool isEmpty() const { return hasEmptyBounds() || !tiles().size(); }
44 const CCLayerTilingData
& operator=(const CCLayerTilingData
&);
48 Tile() : m_i(-1), m_j(-1) { }
51 int i() const { return m_i
; }
52 int j() const { return m_j
; }
53 void moveTo(int i
, int j
) { m_i
= i
; m_j
= j
; }
55 const IntRect
& opaqueRect() const { return m_opaqueRect
; }
56 void setOpaqueRect(const IntRect
& opaqueRect
) { m_opaqueRect
= opaqueRect
; }
61 DISALLOW_COPY_AND_ASSIGN(Tile
);
63 // Default hash key traits for integers disallow 0 and -1 as a key, so
64 // use a custom hash trait which disallows -1 and -2 instead.
65 typedef std::pair
<int, int> TileMapKey
;
66 struct TileMapKeyTraits
: HashTraits
<TileMapKey
> {
67 static const bool emptyValueIsZero
= false;
68 static const bool needsDestruction
= false;
69 static TileMapKey
emptyValue() { return std::make_pair(-1, -1); }
70 static void constructDeletedValue(TileMapKey
& slot
) { slot
= std::make_pair(-2, -2); }
71 static bool isDeletedValue(TileMapKey value
) { return value
.first
== -2 && value
.second
== -2; }
73 typedef HashMap
<TileMapKey
, OwnPtr
<Tile
>, DefaultHash
<TileMapKey
>::Hash
, TileMapKeyTraits
> TileMap
;
75 void addTile(PassOwnPtr
<Tile
>, int, int);
76 PassOwnPtr
<Tile
> takeTile(int, int);
77 Tile
* tileAt(int, int) const;
78 const TileMap
& tiles() const { return m_tiles
; }
80 void setBounds(const IntSize
&);
81 IntSize
bounds() const;
83 void contentRectToTileIndices(const IntRect
&, int &left
, int &top
, int &right
, int &bottom
) const;
84 IntRect
tileRect(const Tile
*) const;
86 Region
opaqueRegionInContentRect(const IntRect
&) const;
91 CCLayerTilingData(const IntSize
& tileSize
, BorderTexelOption
);
94 TilingData m_tilingData
;
99 #endif // USE(ACCELERATED_COMPOSITING)