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 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/tiled_layer_impl.h" | 7 #include "cc/tiled_layer_impl.h" |
8 | 8 |
9 #include "FloatQuad.h" | 9 #include "FloatQuad.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 DrawableTile* TiledLayerImpl::createTile(int i, int j) | 111 DrawableTile* TiledLayerImpl::createTile(int i, int j) |
112 { | 112 { |
113 scoped_ptr<DrawableTile> tile(DrawableTile::create()); | 113 scoped_ptr<DrawableTile> tile(DrawableTile::create()); |
114 DrawableTile* addedTile = tile.get(); | 114 DrawableTile* addedTile = tile.get(); |
115 m_tiler->addTile(tile.PassAs<LayerTilingData::Tile>(), i, j); | 115 m_tiler->addTile(tile.PassAs<LayerTilingData::Tile>(), i, j); |
116 return addedTile; | 116 return addedTile; |
117 } | 117 } |
118 | 118 |
119 void TiledLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad
sData) | 119 void TiledLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad
sData) |
120 { | 120 { |
121 const IntRect& contentRect = visibleContentRect(); | 121 const gfx::Rect& contentRect = visibleContentRect(); |
122 | 122 |
123 if (!m_tiler || m_tiler->hasEmptyBounds() || contentRect.isEmpty()) | 123 if (!m_tiler || m_tiler->hasEmptyBounds() || contentRect.IsEmpty()) |
124 return; | 124 return; |
125 | 125 |
126 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ
uadState()); | 126 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ
uadState()); |
127 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); | 127 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); |
128 | 128 |
129 int left, top, right, bottom; | 129 int left, top, right, bottom; |
130 m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom); | 130 m_tiler->contentRectToTileIndices(contentRect, left, top, right, bottom); |
131 | 131 |
132 if (hasDebugBorders()) { | 132 if (hasDebugBorders()) { |
133 for (int j = top; j <= bottom; ++j) { | 133 for (int j = top; j <= bottom; ++j) { |
134 for (int i = left; i <= right; ++i) { | 134 for (int i = left; i <= right; ++i) { |
135 DrawableTile* tile = tileAt(i, j); | 135 DrawableTile* tile = tileAt(i, j); |
136 IntRect tileRect = m_tiler->tileBounds(i, j); | 136 gfx::Rect tileRect = m_tiler->tileBounds(i, j); |
137 SkColor borderColor; | 137 SkColor borderColor; |
138 | 138 |
139 if (m_skipsDraw || !tile || !tile->resourceId()) | 139 if (m_skipsDraw || !tile || !tile->resourceId()) |
140 borderColor = SkColorSetARGB(debugTileBorderAlpha, debugTile
BorderMissingTileColorRed, debugTileBorderMissingTileColorGreen, debugTileBorder
MissingTileColorBlue); | 140 borderColor = SkColorSetARGB(debugTileBorderAlpha, debugTile
BorderMissingTileColorRed, debugTileBorderMissingTileColorGreen, debugTileBorder
MissingTileColorBlue); |
141 else | 141 else |
142 borderColor = SkColorSetARGB(debugTileBorderAlpha, debugTile
BorderColorRed, debugTileBorderColorGreen, debugTileBorderColorBlue); | 142 borderColor = SkColorSetARGB(debugTileBorderAlpha, debugTile
BorderColorRed, debugTileBorderColorGreen, debugTileBorderColorBlue); |
143 quadSink.append(DebugBorderDrawQuad::create(sharedQuadState, til
eRect, borderColor, debugTileBorderWidth).PassAs<DrawQuad>(), appendQuadsData); | 143 quadSink.append(DebugBorderDrawQuad::create(sharedQuadState, til
eRect, borderColor, debugTileBorderWidth).PassAs<DrawQuad>(), appendQuadsData); |
144 } | 144 } |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 if (m_skipsDraw) | 148 if (m_skipsDraw) |
149 return; | 149 return; |
150 | 150 |
151 for (int j = top; j <= bottom; ++j) { | 151 for (int j = top; j <= bottom; ++j) { |
152 for (int i = left; i <= right; ++i) { | 152 for (int i = left; i <= right; ++i) { |
153 DrawableTile* tile = tileAt(i, j); | 153 DrawableTile* tile = tileAt(i, j); |
154 IntRect tileRect = m_tiler->tileBounds(i, j); | 154 gfx::Rect tileRect = m_tiler->tileBounds(i, j); |
155 IntRect displayRect = tileRect; | 155 gfx::Rect displayRect = tileRect; |
156 tileRect.intersect(contentRect); | 156 tileRect.Intersect(contentRect); |
157 | 157 |
158 // Skip empty tiles. | 158 // Skip empty tiles. |
159 if (tileRect.isEmpty()) | 159 if (tileRect.IsEmpty()) |
160 continue; | 160 continue; |
161 | 161 |
162 if (!tile || !tile->resourceId()) { | 162 if (!tile || !tile->resourceId()) { |
163 if (drawCheckerboardForMissingTiles()) { | 163 if (drawCheckerboardForMissingTiles()) { |
164 SkColor defaultColor = SkColorSetRGB(defaultCheckerboardColo
rRed, defaultCheckerboardColorGreen, defaultCheckerboardColorBlue); | 164 SkColor defaultColor = SkColorSetRGB(defaultCheckerboardColo
rRed, defaultCheckerboardColorGreen, defaultCheckerboardColorBlue); |
165 SkColor evictedColor = SkColorSetRGB(debugTileEvictedChecker
boardColorRed, debugTileEvictedCheckerboardColorGreen, debugTileEvictedCheckerbo
ardColorBlue); | 165 SkColor evictedColor = SkColorSetRGB(debugTileEvictedChecker
boardColorRed, debugTileEvictedCheckerboardColorGreen, debugTileEvictedCheckerbo
ardColorBlue); |
166 SkColor invalidatedColor = SkColorSetRGB(debugTileInvalidate
dCheckerboardColorRed, debugTileEvictedCheckerboardColorGreen, debugTileEvictedC
heckerboardColorBlue); | 166 SkColor invalidatedColor = SkColorSetRGB(debugTileInvalidate
dCheckerboardColorRed, debugTileEvictedCheckerboardColorGreen, debugTileEvictedC
heckerboardColorBlue); |
167 | 167 |
168 SkColor checkerColor; | 168 SkColor checkerColor; |
169 if (hasDebugBorders()) | 169 if (hasDebugBorders()) |
170 checkerColor = tile ? invalidatedColor : evictedColor; | 170 checkerColor = tile ? invalidatedColor : evictedColor; |
171 else | 171 else |
172 checkerColor = defaultColor; | 172 checkerColor = defaultColor; |
173 | 173 |
174 appendQuadsData.hadMissingTiles |= quadSink.append(Checkerbo
ardDrawQuad::create(sharedQuadState, tileRect, checkerColor).PassAs<DrawQuad>(),
appendQuadsData); | 174 appendQuadsData.hadMissingTiles |= quadSink.append(Checkerbo
ardDrawQuad::create(sharedQuadState, tileRect, checkerColor).PassAs<DrawQuad>(),
appendQuadsData); |
175 } else | 175 } else |
176 appendQuadsData.hadMissingTiles |= quadSink.append(SolidColo
rDrawQuad::create(sharedQuadState, tileRect, backgroundColor()).PassAs<DrawQuad>
(), appendQuadsData); | 176 appendQuadsData.hadMissingTiles |= quadSink.append(SolidColo
rDrawQuad::create(sharedQuadState, tileRect, backgroundColor()).PassAs<DrawQuad>
(), appendQuadsData); |
177 continue; | 177 continue; |
178 } | 178 } |
179 | 179 |
180 IntRect tileOpaqueRect = tile->opaqueRect(); | 180 gfx::Rect tileOpaqueRect = tile->opaqueRect(); |
181 tileOpaqueRect.intersect(contentRect); | 181 tileOpaqueRect.Intersect(contentRect); |
182 | 182 |
183 // Keep track of how the top left has moved, so the texture can be | 183 // Keep track of how the top left has moved, so the texture can be |
184 // offset the same amount. | 184 // offset the same amount. |
185 IntSize displayOffset = tileRect.minXMinYCorner() - displayRect.minX
MinYCorner(); | 185 gfx::Vector2d displayOffset = tileRect.origin() - displayRect.origin
(); |
186 IntPoint textureOffset = m_tiler->textureOffset(i, j) + displayOffse
t; | 186 gfx::Vector2d textureOffset = m_tiler->textureOffset(i, j) + display
Offset; |
187 float tileWidth = static_cast<float>(m_tiler->tileSize().width()); | 187 float tileWidth = static_cast<float>(m_tiler->tileSize().width()); |
188 float tileHeight = static_cast<float>(m_tiler->tileSize().height()); | 188 float tileHeight = static_cast<float>(m_tiler->tileSize().height()); |
189 IntSize textureSize(tileWidth, tileHeight); | 189 gfx::Size textureSize(tileWidth, tileHeight); |
190 | 190 |
191 bool clipped = false; | 191 bool clipped = false; |
192 FloatQuad visibleContentInTargetQuad = MathUtil::mapQuad(drawTransfo
rm(), FloatQuad(visibleContentRect()), clipped); | 192 FloatQuad visibleContentInTargetQuad = MathUtil::mapQuad(drawTransfo
rm(), FloatQuad(visibleContentRect()), clipped); |
193 bool isAxisAlignedInTarget = !clipped && visibleContentInTargetQuad.
isRectilinear(); | 193 bool isAxisAlignedInTarget = !clipped && visibleContentInTargetQuad.
isRectilinear(); |
194 bool useAA = m_tiler->hasBorderTexels() && !isAxisAlignedInTarget; | 194 bool useAA = m_tiler->hasBorderTexels() && !isAxisAlignedInTarget; |
195 | 195 |
196 bool leftEdgeAA = !i && useAA; | 196 bool leftEdgeAA = !i && useAA; |
197 bool topEdgeAA = !j && useAA; | 197 bool topEdgeAA = !j && useAA; |
198 bool rightEdgeAA = i == m_tiler->numTilesX() - 1 && useAA; | 198 bool rightEdgeAA = i == m_tiler->numTilesX() - 1 && useAA; |
199 bool bottomEdgeAA = j == m_tiler->numTilesY() - 1 && useAA; | 199 bool bottomEdgeAA = j == m_tiler->numTilesY() - 1 && useAA; |
200 | 200 |
201 const GLint textureFilter = m_tiler->hasBorderTexels() ? GL_LINEAR :
GL_NEAREST; | 201 const GLint textureFilter = m_tiler->hasBorderTexels() ? GL_LINEAR :
GL_NEAREST; |
202 quadSink.append(TileDrawQuad::create(sharedQuadState, tileRect, tile
OpaqueRect, tile->resourceId(), textureOffset, textureSize, textureFilter, tile-
>contentsSwizzled(), leftEdgeAA, topEdgeAA, rightEdgeAA, bottomEdgeAA).PassAs<Dr
awQuad>(), appendQuadsData); | 202 quadSink.append(TileDrawQuad::create(sharedQuadState, tileRect, tile
OpaqueRect, tile->resourceId(), textureOffset, textureSize, textureFilter, tile-
>contentsSwizzled(), leftEdgeAA, topEdgeAA, rightEdgeAA, bottomEdgeAA).PassAs<Dr
awQuad>(), appendQuadsData); |
203 } | 203 } |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 void TiledLayerImpl::setTilingData(const LayerTilingData& tiler) | 207 void TiledLayerImpl::setTilingData(const LayerTilingData& tiler) |
208 { | 208 { |
209 if (m_tiler) | 209 if (m_tiler) |
210 m_tiler->reset(); | 210 m_tiler->reset(); |
211 else | 211 else |
212 m_tiler = LayerTilingData::create(tiler.tileSize(), tiler.hasBorderTexel
s() ? LayerTilingData::HasBorderTexels : LayerTilingData::NoBorderTexels); | 212 m_tiler = LayerTilingData::create(tiler.tileSize(), tiler.hasBorderTexel
s() ? LayerTilingData::HasBorderTexels : LayerTilingData::NoBorderTexels); |
213 *m_tiler = tiler; | 213 *m_tiler = tiler; |
214 } | 214 } |
215 | 215 |
216 void TiledLayerImpl::pushTileProperties(int i, int j, ResourceProvider::Resource
Id resourceId, const IntRect& opaqueRect, bool contentsSwizzled) | 216 void TiledLayerImpl::pushTileProperties(int i, int j, ResourceProvider::Resource
Id resourceId, const gfx::Rect& opaqueRect, bool contentsSwizzled) |
217 { | 217 { |
218 DrawableTile* tile = tileAt(i, j); | 218 DrawableTile* tile = tileAt(i, j); |
219 if (!tile) | 219 if (!tile) |
220 tile = createTile(i, j); | 220 tile = createTile(i, j); |
221 tile->setResourceId(resourceId); | 221 tile->setResourceId(resourceId); |
222 tile->setOpaqueRect(opaqueRect); | 222 tile->setOpaqueRect(opaqueRect); |
223 tile->setContentsSwizzled(contentsSwizzled); | 223 tile->setContentsSwizzled(contentsSwizzled); |
224 } | 224 } |
225 | 225 |
226 void TiledLayerImpl::pushInvalidTile(int i, int j) | 226 void TiledLayerImpl::pushInvalidTile(int i, int j) |
227 { | 227 { |
228 DrawableTile* tile = tileAt(i, j); | 228 DrawableTile* tile = tileAt(i, j); |
229 if (!tile) | 229 if (!tile) |
230 tile = createTile(i, j); | 230 tile = createTile(i, j); |
231 tile->setResourceId(0); | 231 tile->setResourceId(0); |
232 tile->setOpaqueRect(IntRect()); | 232 tile->setOpaqueRect(gfx::Rect()); |
233 tile->setContentsSwizzled(false); | 233 tile->setContentsSwizzled(false); |
234 } | 234 } |
235 | 235 |
236 Region TiledLayerImpl::visibleContentOpaqueRegion() const | 236 Region TiledLayerImpl::visibleContentOpaqueRegion() const |
237 { | 237 { |
238 if (m_skipsDraw) | 238 if (m_skipsDraw) |
239 return Region(); | 239 return Region(); |
240 if (contentsOpaque()) | 240 if (contentsOpaque()) |
241 return visibleContentRect(); | 241 return cc::IntRect(visibleContentRect()); |
242 return m_tiler->opaqueRegionInContentRect(visibleContentRect()); | 242 return m_tiler->opaqueRegionInContentRect(visibleContentRect()); |
243 } | 243 } |
244 | 244 |
245 void TiledLayerImpl::didLoseContext() | 245 void TiledLayerImpl::didLoseContext() |
246 { | 246 { |
247 m_tiler->reset(); | 247 m_tiler->reset(); |
248 } | 248 } |
249 | 249 |
250 const char* TiledLayerImpl::layerTypeAsString() const | 250 const char* TiledLayerImpl::layerTypeAsString() const |
251 { | 251 { |
252 return "ContentLayer"; | 252 return "ContentLayer"; |
253 } | 253 } |
254 | 254 |
255 } // namespace cc | 255 } // namespace cc |
OLD | NEW |