Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: cc/tiled_layer.cc

Issue 11144023: cc: Store tiles, painters, tiling data in scoped_ptr (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/tiled_layer.h ('k') | cc/tiled_layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "TiledLayerChromium.h" 7 #include "TiledLayerChromium.h"
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "CCLayerImpl.h" 10 #include "CCLayerImpl.h"
11 #include "CCLayerTreeHost.h" 11 #include "CCLayerTreeHost.h"
12 #include "CCOverdrawMetrics.h" 12 #include "CCOverdrawMetrics.h"
13 #include "CCTextureUpdateQueue.h" 13 #include "CCTextureUpdateQueue.h"
14 #include "CCTiledLayerImpl.h" 14 #include "CCTiledLayerImpl.h"
15 #include "GraphicsContext3D.h"
16 #include "Region.h" 15 #include "Region.h"
17 #include <wtf/CurrentTime.h>
18 #include <wtf/MathExtras.h>
19 16
20 using namespace std; 17 using namespace std;
21 using WebKit::WebTransformationMatrix; 18 using WebKit::WebTransformationMatrix;
22 19
23 namespace cc { 20 namespace cc {
24 21
25 class UpdatableTile : public CCLayerTilingData::Tile { 22 class UpdatableTile : public CCLayerTilingData::Tile {
26 public: 23 public:
27 static PassOwnPtr<UpdatableTile> create(PassOwnPtr<LayerTextureUpdater::Text ure> texture) 24 static scoped_ptr<UpdatableTile> create(PassOwnPtr<LayerTextureUpdater::Text ure> texture)
28 { 25 {
29 return adoptPtr(new UpdatableTile(texture)); 26 return make_scoped_ptr(new UpdatableTile(texture));
30 } 27 }
31 28
32 LayerTextureUpdater::Texture* texture() { return m_texture.get(); } 29 LayerTextureUpdater::Texture* texture() { return m_texture.get(); }
33 CCPrioritizedTexture* managedTexture() { return m_texture->texture(); } 30 CCPrioritizedTexture* managedTexture() { return m_texture->texture(); }
34 31
35 bool isDirty() const { return !dirtyRect.isEmpty(); } 32 bool isDirty() const { return !dirtyRect.isEmpty(); }
36 33
37 // Reset update state for the current frame. This should occur before painti ng 34 // Reset update state for the current frame. This should occur before painti ng
38 // for all layers. Since painting one layer can invalidate another layer 35 // for all layers. Since painting one layer can invalidate another layer
39 // after it has already painted, mark all non-dirty tiles as valid before pa inting 36 // after it has already painted, mark all non-dirty tiles as valid before pa inting
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 LayerChromium::pushPropertiesTo(layer); 193 LayerChromium::pushPropertiesTo(layer);
197 194
198 CCTiledLayerImpl* tiledLayer = static_cast<CCTiledLayerImpl*>(layer); 195 CCTiledLayerImpl* tiledLayer = static_cast<CCTiledLayerImpl*>(layer);
199 196
200 tiledLayer->setSkipsDraw(m_skipsDraw); 197 tiledLayer->setSkipsDraw(m_skipsDraw);
201 tiledLayer->setContentsSwizzled(m_sampledTexelFormat != LayerTextureUpdater: :SampledTexelFormatRGBA); 198 tiledLayer->setContentsSwizzled(m_sampledTexelFormat != LayerTextureUpdater: :SampledTexelFormatRGBA);
202 tiledLayer->setTilingData(*m_tiler); 199 tiledLayer->setTilingData(*m_tiler);
203 Vector<UpdatableTile*> invalidTiles; 200 Vector<UpdatableTile*> invalidTiles;
204 201
205 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begi n(); iter != m_tiler->tiles().end(); ++iter) { 202 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begi n(); iter != m_tiler->tiles().end(); ++iter) {
206 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
207 int i = iter->key.first;
208 int j = iter->key.second;
209 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->value.get());
210 #else
211 int i = iter->first.first; 203 int i = iter->first.first;
212 int j = iter->first.second; 204 int j = iter->first.second;
213 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second.get()); 205 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second);
214 #endif
215 // FIXME: This should not ever be null. 206 // FIXME: This should not ever be null.
216 if (!tile) 207 if (!tile)
217 continue; 208 continue;
218 209
219 tile->isInUseOnImpl = false; 210 tile->isInUseOnImpl = false;
220 211
221 if (!tile->managedTexture()->haveBackingTexture()) { 212 if (!tile->managedTexture()->haveBackingTexture()) {
222 // Evicted tiles get deleted from both layers 213 // Evicted tiles get deleted from both layers
223 invalidTiles.append(tile); 214 invalidTiles.append(tile);
224 continue; 215 continue;
(...skipping 16 matching lines...) Expand all
241 { 232 {
242 if (!layerTreeHost()) 233 if (!layerTreeHost())
243 return 0; 234 return 0;
244 return layerTreeHost()->contentsTextureManager(); 235 return layerTreeHost()->contentsTextureManager();
245 } 236 }
246 237
247 void TiledLayerChromium::setLayerTreeHost(CCLayerTreeHost* host) 238 void TiledLayerChromium::setLayerTreeHost(CCLayerTreeHost* host)
248 { 239 {
249 if (host && host != layerTreeHost()) { 240 if (host && host != layerTreeHost()) {
250 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles(). begin(); iter != m_tiler->tiles().end(); ++iter) { 241 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles(). begin(); iter != m_tiler->tiles().end(); ++iter) {
251 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 242 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second);
252 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->value.get()) ;
253 #else
254 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second.get() );
255 #endif
256 // FIXME: This should not ever be null. 243 // FIXME: This should not ever be null.
257 if (!tile) 244 if (!tile)
258 continue; 245 continue;
259 tile->managedTexture()->setTextureManager(host->contentsTextureManag er()); 246 tile->managedTexture()->setTextureManager(host->contentsTextureManag er());
260 } 247 }
261 } 248 }
262 LayerChromium::setLayerTreeHost(host); 249 LayerChromium::setLayerTreeHost(host);
263 } 250 }
264 251
265 UpdatableTile* TiledLayerChromium::tileAt(int i, int j) const 252 UpdatableTile* TiledLayerChromium::tileAt(int i, int j) const
266 { 253 {
267 return static_cast<UpdatableTile*>(m_tiler->tileAt(i, j)); 254 return static_cast<UpdatableTile*>(m_tiler->tileAt(i, j));
268 } 255 }
269 256
270 UpdatableTile* TiledLayerChromium::createTile(int i, int j) 257 UpdatableTile* TiledLayerChromium::createTile(int i, int j)
271 { 258 {
272 createTextureUpdaterIfNeeded(); 259 createTextureUpdaterIfNeeded();
273 260
274 OwnPtr<UpdatableTile> tile(UpdatableTile::create(textureUpdater()->createTex ture(textureManager()))); 261 scoped_ptr<UpdatableTile> tile(UpdatableTile::create(textureUpdater()->creat eTexture(textureManager())));
275 tile->managedTexture()->setDimensions(m_tiler->tileSize(), m_textureFormat); 262 tile->managedTexture()->setDimensions(m_tiler->tileSize(), m_textureFormat);
276 263
277 UpdatableTile* addedTile = tile.get(); 264 UpdatableTile* addedTile = tile.get();
278 m_tiler->addTile(tile.release(), i, j); 265 m_tiler->addTile(tile.PassAs<CCLayerTilingData::Tile>(), i, j);
279 266
280 addedTile->dirtyRect = m_tiler->tileRect(addedTile); 267 addedTile->dirtyRect = m_tiler->tileRect(addedTile);
281 268
282 // Temporary diagnostic crash. 269 // Temporary diagnostic crash.
283 if (!addedTile) 270 if (!addedTile)
284 CRASH(); 271 CRASH();
285 if (!tileAt(i, j)) 272 if (!tileAt(i, j))
286 CRASH(); 273 CRASH();
287 274
288 return addedTile; 275 return addedTile;
(...skipping 24 matching lines...) Expand all
313 setBorderTexelOption(borderTexelOption); 300 setBorderTexelOption(borderTexelOption);
314 } 301 }
315 302
316 void TiledLayerChromium::invalidateContentRect(const IntRect& contentRect) 303 void TiledLayerChromium::invalidateContentRect(const IntRect& contentRect)
317 { 304 {
318 updateBounds(); 305 updateBounds();
319 if (m_tiler->isEmpty() || contentRect.isEmpty() || m_skipsDraw) 306 if (m_tiler->isEmpty() || contentRect.isEmpty() || m_skipsDraw)
320 return; 307 return;
321 308
322 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begi n(); iter != m_tiler->tiles().end(); ++iter) { 309 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begi n(); iter != m_tiler->tiles().end(); ++iter) {
323 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 310 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second);
324 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->value.get());
325 #else
326 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second.get());
327 #endif
328 ASSERT(tile); 311 ASSERT(tile);
329 // FIXME: This should not ever be null. 312 // FIXME: This should not ever be null.
330 if (!tile) 313 if (!tile)
331 continue; 314 continue;
332 IntRect bound = m_tiler->tileRect(tile); 315 IntRect bound = m_tiler->tileRect(tile);
333 bound.intersect(contentRect); 316 bound.intersect(contentRect);
334 tile->dirtyRect.unite(bound); 317 tile->dirtyRect.unite(bound);
335 } 318 }
336 } 319 }
337 320
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 backBuffer->texture()->format()); 624 backBuffer->texture()->format());
642 // Swap backBuffer into frontBuffer and add it to delete after c ommit queue. 625 // Swap backBuffer into frontBuffer and add it to delete after c ommit queue.
643 backBuffer->swapTextureWith(frontBuffer); 626 backBuffer->swapTextureWith(frontBuffer);
644 layerTreeHost()->deleteTextureAfterCommit(frontBuffer.Pass()); 627 layerTreeHost()->deleteTextureAfterCommit(frontBuffer.Pass());
645 } 628 }
646 } 629 }
647 } 630 }
648 631
649 // Now update priorities on all tiles we have in the layer, no matter where they are. 632 // Now update priorities on all tiles we have in the layer, no matter where they are.
650 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begi n(); iter != m_tiler->tiles().end(); ++iter) { 633 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begi n(); iter != m_tiler->tiles().end(); ++iter) {
651 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 634 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second);
652 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->value.get());
653 #else
654 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second.get());
655 #endif
656 // FIXME: This should not ever be null. 635 // FIXME: This should not ever be null.
657 if (!tile) 636 if (!tile)
658 continue; 637 continue;
659 IntRect tileRect = m_tiler->tileRect(tile); 638 IntRect tileRect = m_tiler->tileRect(tile);
660 setPriorityForTexture(visibleContentRect(), tileRect, drawsToRoot, small AnimatedLayer, tile->managedTexture()); 639 setPriorityForTexture(visibleContentRect(), tileRect, drawsToRoot, small AnimatedLayer, tile->managedTexture());
661 } 640 }
662 } 641 }
663 642
664 Region TiledLayerChromium::visibleContentOpaqueRegion() const 643 Region TiledLayerChromium::visibleContentOpaqueRegion() const
665 { 644 {
666 if (m_skipsDraw) 645 if (m_skipsDraw)
667 return Region(); 646 return Region();
668 if (contentsOpaque()) 647 if (contentsOpaque())
669 return visibleContentRect(); 648 return visibleContentRect();
670 return m_tiler->opaqueRegionInContentRect(visibleContentRect()); 649 return m_tiler->opaqueRegionInContentRect(visibleContentRect());
671 } 650 }
672 651
673 void TiledLayerChromium::resetUpdateState() 652 void TiledLayerChromium::resetUpdateState()
674 { 653 {
675 m_skipsDraw = false; 654 m_skipsDraw = false;
676 m_failedUpdate = false; 655 m_failedUpdate = false;
677 656
678 CCLayerTilingData::TileMap::const_iterator end = m_tiler->tiles().end(); 657 CCLayerTilingData::TileMap::const_iterator end = m_tiler->tiles().end();
679 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begi n(); iter != end; ++iter) { 658 for (CCLayerTilingData::TileMap::const_iterator iter = m_tiler->tiles().begi n(); iter != end; ++iter) {
680 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE 659 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second);
681 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->value.get());
682 #else
683 UpdatableTile* tile = static_cast<UpdatableTile*>(iter->second.get());
684 #endif
685 // FIXME: This should not ever be null. 660 // FIXME: This should not ever be null.
686 if (!tile) 661 if (!tile)
687 continue; 662 continue;
688 tile->resetUpdateState(); 663 tile->resetUpdateState();
689 } 664 }
690 } 665 }
691 666
692 void TiledLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTr acker* occlusion, CCRenderingStats& stats) 667 void TiledLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTr acker* occlusion, CCRenderingStats& stats)
693 { 668 {
694 ASSERT(!m_skipsDraw && !m_failedUpdate); // Did resetUpdateState get skipped ? 669 ASSERT(!m_skipsDraw && !m_failedUpdate); // Did resetUpdateState get skipped ?
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 IntRect prepaintRect = visibleContentRect(); 778 IntRect prepaintRect = visibleContentRect();
804 prepaintRect.inflateX(m_tiler->tileSize().width()); 779 prepaintRect.inflateX(m_tiler->tileSize().width());
805 prepaintRect.inflateY(m_tiler->tileSize().height() * 2); 780 prepaintRect.inflateY(m_tiler->tileSize().height() * 2);
806 IntRect contentRect(IntPoint::zero(), contentBounds()); 781 IntRect contentRect(IntPoint::zero(), contentBounds());
807 prepaintRect.intersect(contentRect); 782 prepaintRect.intersect(contentRect);
808 783
809 return prepaintRect; 784 return prepaintRect;
810 } 785 }
811 786
812 } 787 }
OLDNEW
« no previous file with comments | « cc/tiled_layer.h ('k') | cc/tiled_layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698