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.h" | 7 #include "cc/tiled_layer.h" |
8 | 8 |
9 #include "Region.h" | 9 #include "Region.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 , m_updaterResource(updaterResource.Pass()) | 77 , m_updaterResource(updaterResource.Pass()) |
78 { | 78 { |
79 } | 79 } |
80 | 80 |
81 scoped_ptr<LayerUpdater::Resource> m_updaterResource; | 81 scoped_ptr<LayerUpdater::Resource> m_updaterResource; |
82 | 82 |
83 DISALLOW_COPY_AND_ASSIGN(UpdatableTile); | 83 DISALLOW_COPY_AND_ASSIGN(UpdatableTile); |
84 }; | 84 }; |
85 | 85 |
86 TiledLayer::TiledLayer() | 86 TiledLayer::TiledLayer() |
87 : Layer() | 87 : ContentsScalingLayer() |
88 , m_textureFormat(GL_INVALID_ENUM) | 88 , m_textureFormat(GL_INVALID_ENUM) |
89 , m_skipsDraw(false) | 89 , m_skipsDraw(false) |
90 , m_failedUpdate(false) | 90 , m_failedUpdate(false) |
91 , m_tilingOption(AutoTile) | 91 , m_tilingOption(AutoTile) |
92 { | 92 { |
93 m_tiler = LayerTilingData::create(IntSize(), LayerTilingData::HasBorderTexel s); | 93 m_tiler = LayerTilingData::create(IntSize(), LayerTilingData::HasBorderTexel s); |
94 } | 94 } |
95 | 95 |
96 TiledLayer::~TiledLayer() | 96 TiledLayer::~TiledLayer() |
97 { | 97 { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 m_tiler->setTileSize(size); | 159 m_tiler->setTileSize(size); |
160 } | 160 } |
161 | 161 |
162 void TiledLayer::setBorderTexelOption(LayerTilingData::BorderTexelOption borderT exelOption) | 162 void TiledLayer::setBorderTexelOption(LayerTilingData::BorderTexelOption borderT exelOption) |
163 { | 163 { |
164 m_tiler->setBorderTexelOption(borderTexelOption); | 164 m_tiler->setBorderTexelOption(borderTexelOption); |
165 } | 165 } |
166 | 166 |
167 bool TiledLayer::drawsContent() const | 167 bool TiledLayer::drawsContent() const |
168 { | 168 { |
169 if (!Layer::drawsContent()) | 169 if (!ContentsScalingLayer::drawsContent()) |
170 return false; | 170 return false; |
171 | 171 |
172 bool hasMoreThanOneTile = m_tiler->numTilesX() > 1 || m_tiler->numTilesY() > 1; | 172 bool hasMoreThanOneTile = m_tiler->numTilesX() > 1 || m_tiler->numTilesY() > 1; |
173 if (m_tilingOption == NeverTile && hasMoreThanOneTile) | 173 if (m_tilingOption == NeverTile && hasMoreThanOneTile) |
174 return false; | 174 return false; |
175 | 175 |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 bool TiledLayer::needsContentsScale() const | |
180 { | |
181 return true; | |
182 } | |
183 | |
184 IntSize TiledLayer::contentBounds() const | |
185 { | |
186 return IntSize(lroundf(bounds().width() * contentsScale()), lroundf(bounds() .height() * contentsScale())); | |
187 } | |
188 | |
189 void TiledLayer::setTilingOption(TilingOption tilingOption) | 179 void TiledLayer::setTilingOption(TilingOption tilingOption) |
190 { | 180 { |
191 m_tilingOption = tilingOption; | 181 m_tilingOption = tilingOption; |
192 } | 182 } |
193 | 183 |
194 void TiledLayer::setIsMask(bool isMask) | 184 void TiledLayer::setIsMask(bool isMask) |
195 { | 185 { |
196 setTilingOption(isMask ? NeverTile : AutoTile); | 186 setTilingOption(isMask ? NeverTile : AutoTile); |
197 } | 187 } |
198 | 188 |
199 void TiledLayer::pushPropertiesTo(LayerImpl* layer) | 189 void TiledLayer::pushPropertiesTo(LayerImpl* layer) |
200 { | 190 { |
201 Layer::pushPropertiesTo(layer); | 191 ContentsScalingLayer::pushPropertiesTo(layer); |
202 | 192 |
203 TiledLayerImpl* tiledLayer = static_cast<TiledLayerImpl*>(layer); | 193 TiledLayerImpl* tiledLayer = static_cast<TiledLayerImpl*>(layer); |
204 | 194 |
205 tiledLayer->setSkipsDraw(m_skipsDraw); | 195 tiledLayer->setSkipsDraw(m_skipsDraw); |
206 tiledLayer->setTilingData(*m_tiler); | 196 tiledLayer->setTilingData(*m_tiler); |
207 Vector<UpdatableTile*> invalidTiles; | 197 Vector<UpdatableTile*> invalidTiles; |
208 | 198 |
209 for (LayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begin( ); iter != m_tiler->tiles().end(); ++iter) { | 199 for (LayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begin( ); iter != m_tiler->tiles().end(); ++iter) { |
210 int i = iter->first.first; | 200 int i = iter->first.first; |
211 int j = iter->first.second; | 201 int j = iter->first.second; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 { | 233 { |
244 if (host && host != layerTreeHost()) { | 234 if (host && host != layerTreeHost()) { |
245 for (LayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().be gin(); iter != m_tiler->tiles().end(); ++iter) { | 235 for (LayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().be gin(); iter != m_tiler->tiles().end(); ++iter) { |
246 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second); | 236 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second); |
247 // FIXME: This should not ever be null. | 237 // FIXME: This should not ever be null. |
248 if (!tile) | 238 if (!tile) |
249 continue; | 239 continue; |
250 tile->managedTexture()->setTextureManager(host->contentsTextureManag er()); | 240 tile->managedTexture()->setTextureManager(host->contentsTextureManag er()); |
251 } | 241 } |
252 } | 242 } |
253 Layer::setLayerTreeHost(host); | 243 ContentsScalingLayer::setLayerTreeHost(host); |
254 } | 244 } |
255 | 245 |
256 UpdatableTile* TiledLayer::tileAt(int i, int j) const | 246 UpdatableTile* TiledLayer::tileAt(int i, int j) const |
257 { | 247 { |
258 return static_cast<UpdatableTile*>(m_tiler->tileAt(i, j)); | 248 return static_cast<UpdatableTile*>(m_tiler->tileAt(i, j)); |
259 } | 249 } |
260 | 250 |
261 UpdatableTile* TiledLayer::createTile(int i, int j) | 251 UpdatableTile* TiledLayer::createTile(int i, int j) |
262 { | 252 { |
263 createUpdaterIfNeeded(); | 253 createUpdaterIfNeeded(); |
(...skipping 10 matching lines...) Expand all Loading... | |
274 if (!addedTile) | 264 if (!addedTile) |
275 CRASH(); | 265 CRASH(); |
276 if (!tileAt(i, j)) | 266 if (!tileAt(i, j)) |
277 CRASH(); | 267 CRASH(); |
278 | 268 |
279 return addedTile; | 269 return addedTile; |
280 } | 270 } |
281 | 271 |
282 void TiledLayer::setNeedsDisplayRect(const FloatRect& dirtyRect) | 272 void TiledLayer::setNeedsDisplayRect(const FloatRect& dirtyRect) |
283 { | 273 { |
284 float contentsWidthScale = static_cast<float>(contentBounds().width()) / bou nds().width(); | |
285 float contentsHeightScale = static_cast<float>(contentBounds().height()) / b ounds().height(); | |
286 FloatRect scaledDirtyRect(dirtyRect); | 274 FloatRect scaledDirtyRect(dirtyRect); |
287 scaledDirtyRect.scale(contentsWidthScale, contentsHeightScale); | 275 scaledDirtyRect.scale(contentsScaleX(), contentsScaleY()); |
288 IntRect dirty = enclosingIntRect(scaledDirtyRect); | 276 IntRect dirty = enclosingIntRect(scaledDirtyRect); |
danakj
2012/10/29 20:06:51
Can you use Layer::layerRectToContentRect() here a
wangxianzhu
2012/10/30 02:14:21
Done.
| |
289 invalidateContentRect(dirty); | 277 invalidateContentRect(dirty); |
290 Layer::setNeedsDisplayRect(dirtyRect); | 278 ContentsScalingLayer::setNeedsDisplayRect(dirtyRect); |
291 } | 279 } |
292 | 280 |
293 void TiledLayer::setUseLCDText(bool useLCDText) | 281 void TiledLayer::setUseLCDText(bool useLCDText) |
294 { | 282 { |
295 Layer::setUseLCDText(useLCDText); | 283 ContentsScalingLayer::setUseLCDText(useLCDText); |
296 | 284 |
297 LayerTilingData::BorderTexelOption borderTexelOption; | 285 LayerTilingData::BorderTexelOption borderTexelOption; |
298 #if OS(ANDROID) | 286 #if OS(ANDROID) |
299 // Always want border texels and GL_LINEAR due to pinch zoom. | 287 // Always want border texels and GL_LINEAR due to pinch zoom. |
300 borderTexelOption = LayerTilingData::HasBorderTexels; | 288 borderTexelOption = LayerTilingData::HasBorderTexels; |
301 #else | 289 #else |
302 borderTexelOption = useLCDText ? LayerTilingData::NoBorderTexels : LayerTili ngData::HasBorderTexels; | 290 borderTexelOption = useLCDText ? LayerTilingData::NoBorderTexels : LayerTili ngData::HasBorderTexels; |
303 #endif | 291 #endif |
304 setBorderTexelOption(borderTexelOption); | 292 setBorderTexelOption(borderTexelOption); |
305 } | 293 } |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 IntRect prepaintRect = visibleContentRect(); | 780 IntRect prepaintRect = visibleContentRect(); |
793 prepaintRect.inflateX(m_tiler->tileSize().width() * prepaintColumns); | 781 prepaintRect.inflateX(m_tiler->tileSize().width() * prepaintColumns); |
794 prepaintRect.inflateY(m_tiler->tileSize().height() * prepaintRows); | 782 prepaintRect.inflateY(m_tiler->tileSize().height() * prepaintRows); |
795 IntRect contentRect(IntPoint::zero(), contentBounds()); | 783 IntRect contentRect(IntPoint::zero(), contentBounds()); |
796 prepaintRect.intersect(contentRect); | 784 prepaintRect.intersect(contentRect); |
797 | 785 |
798 return prepaintRect; | 786 return prepaintRect; |
799 } | 787 } |
800 | 788 |
801 } | 789 } |
OLD | NEW |