1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "CCLayerTilingData.h"
using namespace std;
namespace cc {
PassOwnPtr<CCLayerTilingData> CCLayerTilingData::create(const IntSize& tileSize, BorderTexelOption border)
{
return adoptPtr(new CCLayerTilingData(tileSize, border));
}
CCLayerTilingData::CCLayerTilingData(const IntSize& tileSize, BorderTexelOption border)
: m_tilingData(tileSize, IntSize(), border == HasBorderTexels)
{
setTileSize(tileSize);
}
void CCLayerTilingData::setTileSize(const IntSize& size)
{
if (tileSize() == size)
return;
reset();
m_tilingData.setMaxTextureSize(size);
}
IntSize CCLayerTilingData::tileSize() const
{
return m_tilingData.maxTextureSize();
}
void CCLayerTilingData::setBorderTexelOption(BorderTexelOption borderTexelOption)
{
bool borderTexels = borderTexelOption == HasBorderTexels;
if (hasBorderTexels() == borderTexels)
return;
reset();
m_tilingData.setHasBorderTexels(borderTexels);
}
const CCLayerTilingData& CCLayerTilingData::operator=(const CCLayerTilingData& tiler)
{
m_tilingData = tiler.m_tilingData;
return *this;
}
void CCLayerTilingData::addTile(PassOwnPtr<Tile> tile, int i, int j)
{
ASSERT(!tileAt(i, j));
tile->moveTo(i, j);
m_tiles.add(make_pair(i, j), tile);
}
PassOwnPtr<CCLayerTilingData::Tile> CCLayerTilingData::takeTile(int i, int j)
{
return m_tiles.take(make_pair(i, j));
}
CCLayerTilingData::Tile* CCLayerTilingData::tileAt(int i, int j) const
{
return m_tiles.get(make_pair(i, j));
}
void CCLayerTilingData::reset()
{
m_tiles.clear();
}
void CCLayerTilingData::contentRectToTileIndices(const IntRect& contentRect, int& left, int& top, int& right, int& bottom) const
{
// An empty rect doesn't result in an empty set of tiles, so don't pass an empty rect.
// FIXME: Possibly we should fill a vector of tiles instead,
// since the normal use of this function is to enumerate some tiles.
ASSERT(!contentRect.isEmpty());
left = m_tilingData.tileXIndexFromSrcCoord(contentRect.x());
top = m_tilingData.tileYIndexFromSrcCoord(contentRect.y());
right = m_tilingData.tileXIndexFromSrcCoord(contentRect.maxX() - 1);
bottom = m_tilingData.tileYIndexFromSrcCoord(contentRect.maxY() - 1);
}
IntRect CCLayerTilingData::tileRect(const Tile* tile) const
{
IntRect tileRect = m_tilingData.tileBoundsWithBorder(tile->i(), tile->j());
tileRect.setSize(tileSize());
return tileRect;
}
Region CCLayerTilingData::opaqueRegionInContentRect(const IntRect& contentRect) const
{
if (contentRect.isEmpty())
return Region();
Region opaqueRegion;
int left, top, right, bottom;
contentRectToTileIndices(contentRect, left, top, right, bottom);
for (int j = top; j <= bottom; ++j) {
for (int i = left; i <= right; ++i) {
Tile* tile = tileAt(i, j);
if (!tile)
continue;
IntRect tileOpaqueRect = intersection(contentRect, tile->opaqueRect());
opaqueRegion.unite(tileOpaqueRect);
}
}
return opaqueRegion;
}
void CCLayerTilingData::setBounds(const IntSize& size)
{
m_tilingData.setTotalSize(size);
if (size.isEmpty()) {
m_tiles.clear();
return;
}
// Any tiles completely outside our new bounds are invalid and should be dropped.
int left, top, right, bottom;
contentRectToTileIndices(IntRect(IntPoint(), size), left, top, right, bottom);
Vector<TileMapKey> invalidTileKeys;
for (TileMap::const_iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) {
#if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
if (it->key.first > right || it->key.second > bottom)
invalidTileKeys.append(it->key);
#else
if (it->first.first > right || it->first.second > bottom)
invalidTileKeys.append(it->first);
#endif
}
for (size_t i = 0; i < invalidTileKeys.size(); ++i)
m_tiles.remove(invalidTileKeys[i]);
}
IntSize CCLayerTilingData::bounds() const
{
return m_tilingData.totalSize();
}
} // namespace cc
#endif // USE(ACCELERATED_COMPOSITING)
|