Title: [177442] trunk/Source/WebCore
Revision
177442
Author
zandober...@gmail.com
Date
2014-12-17 03:44:49 -0800 (Wed, 17 Dec 2014)

Log Message

[TexMap] Sprinkle range-based for-loops where still possible
https://bugs.webkit.org/show_bug.cgi?id=138752

Reviewed by Chris Dumez.

Apply range-based for-loops where possible in the TextureMapper,
TextureMapperGL and TextureMapperTiledBackingStore classes.

Also prettify the loop in SharedGLData destructor and return
nullptr instead of explicitly constructing the empty PassRefPtr
object in TextureMapperTiledBackingStore::texture().

* platform/graphics/texmap/TextureMapper.cpp:
(WebCore::BitmapTexturePool::acquireTexture):
* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGLData::SharedGLData::~SharedGLData):
(WebCore::TextureMapperGLData::~TextureMapperGLData):
* platform/graphics/texmap/TextureMapperTiledBackingStore.cpp:
(WebCore::TextureMapperTiledBackingStore::paintToTextureMapper):
(WebCore::TextureMapperTiledBackingStore::drawBorder):
(WebCore::TextureMapperTiledBackingStore::drawRepaintCounter):
(WebCore::TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded):
(WebCore::TextureMapperTiledBackingStore::updateContents):
(WebCore::TextureMapperTiledBackingStore::texture):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (177441 => 177442)


--- trunk/Source/WebCore/ChangeLog	2014-12-17 10:14:32 UTC (rev 177441)
+++ trunk/Source/WebCore/ChangeLog	2014-12-17 11:44:49 UTC (rev 177442)
@@ -1,3 +1,30 @@
+2014-12-17  Zan Dobersek  <zdober...@igalia.com>
+
+        [TexMap] Sprinkle range-based for-loops where still possible
+        https://bugs.webkit.org/show_bug.cgi?id=138752
+
+        Reviewed by Chris Dumez.
+
+        Apply range-based for-loops where possible in the TextureMapper,
+        TextureMapperGL and TextureMapperTiledBackingStore classes.
+
+        Also prettify the loop in SharedGLData destructor and return
+        nullptr instead of explicitly constructing the empty PassRefPtr
+        object in TextureMapperTiledBackingStore::texture().
+
+        * platform/graphics/texmap/TextureMapper.cpp:
+        (WebCore::BitmapTexturePool::acquireTexture):
+        * platform/graphics/texmap/TextureMapperGL.cpp:
+        (WebCore::TextureMapperGLData::SharedGLData::~SharedGLData):
+        (WebCore::TextureMapperGLData::~TextureMapperGLData):
+        * platform/graphics/texmap/TextureMapperTiledBackingStore.cpp:
+        (WebCore::TextureMapperTiledBackingStore::paintToTextureMapper):
+        (WebCore::TextureMapperTiledBackingStore::drawBorder):
+        (WebCore::TextureMapperTiledBackingStore::drawRepaintCounter):
+        (WebCore::TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded):
+        (WebCore::TextureMapperTiledBackingStore::updateContents):
+        (WebCore::TextureMapperTiledBackingStore::texture):
+
 2014-12-17  Radu Stavila  <stav...@adobe.com>
 
         The SVGDocument of an SVGImage should not perform any additional actions when the SVGImage is being destroyed

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp (177441 => 177442)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp	2014-12-17 10:14:32 UTC (rev 177441)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp	2014-12-17 11:44:49 UTC (rev 177442)
@@ -98,15 +98,13 @@
 PassRefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size, TextureMapper* textureMapper)
 {
     BitmapTexturePoolEntry* selectedEntry = 0;
-    for (size_t i = 0; i < m_textures.size(); ++i) {
-        BitmapTexturePoolEntry* entry = &m_textures[i];
-
+    for (auto& entry : m_textures) {
         // If the surface has only one reference (the one in m_textures), we can safely reuse it.
-        if (entry->m_texture->refCount() > 1)
+        if (entry.m_texture->refCount() > 1)
             continue;
 
-        if (entry->m_texture->canReuseWith(size)) {
-            selectedEntry = entry;
+        if (entry.m_texture->canReuseWith(size)) {
+            selectedEntry = &entry;
             break;
         }
     }

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp (177441 => 177442)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2014-12-17 10:14:32 UTC (rev 177441)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp	2014-12-17 11:44:49 UTC (rev 177442)
@@ -94,15 +94,14 @@
 
         ~SharedGLData()
         {
-            GLContextDataMap::const_iterator end = glContextDataMap().end();
-            GLContextDataMap::iterator it;
-            for (it = glContextDataMap().begin(); it != end; ++it) {
-                if (it->value == this)
-                    break;
+            for (auto it = glContextDataMap().begin(), end = glContextDataMap().end(); it != end; ++it) {
+                if (it->value == this) {
+                    glContextDataMap().remove(it);
+                    return;
+                }
             }
 
-            ASSERT(it != end);
-            glContextDataMap().remove(it);
+            ASSERT_NOT_REACHED();
         }
     };
 
@@ -159,9 +158,8 @@
 
 TextureMapperGLData::~TextureMapperGLData()
 {
-    HashMap<const void*, Platform3DObject>::iterator end = vbos.end();
-    for (HashMap<const void*, Platform3DObject>::iterator it = vbos.begin(); it != end; ++it)
-        context->deleteBuffer(it->value);
+    for (auto& entry : vbos)
+        context->deleteBuffer(entry.value);
 }
 
 void TextureMapperGL::ClipStack::reset(const IntRect& rect, TextureMapperGL::ClipStack::YAxisMode mode)

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp (177441 => 177442)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp	2014-12-17 10:14:32 UTC (rev 177441)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp	2014-12-17 11:44:49 UTC (rev 177442)
@@ -51,22 +51,22 @@
 {
     updateContentsFromImageIfNeeded(textureMapper);
     TransformationMatrix adjustedTransform = transform * adjustedTransformForRect(targetRect);
-    for (size_t i = 0; i < m_tiles.size(); ++i)
-        m_tiles[i].paint(textureMapper, adjustedTransform, opacity, calculateExposedTileEdges(rect(), m_tiles[i].rect()));
+    for (auto& tile : m_tiles)
+        tile.paint(textureMapper, adjustedTransform, opacity, calculateExposedTileEdges(rect(), tile.rect()));
 }
 
 void TextureMapperTiledBackingStore::drawBorder(TextureMapper* textureMapper, const Color& borderColor, float borderWidth, const FloatRect& targetRect, const TransformationMatrix& transform)
 {
     TransformationMatrix adjustedTransform = transform * adjustedTransformForRect(targetRect);
-    for (size_t i = 0; i < m_tiles.size(); ++i)
-        textureMapper->drawBorder(borderColor, borderWidth, m_tiles[i].rect(), adjustedTransform);
+    for (auto& tile : m_tiles)
+        textureMapper->drawBorder(borderColor, borderWidth, tile.rect(), adjustedTransform);
 }
 
 void TextureMapperTiledBackingStore::drawRepaintCounter(TextureMapper* textureMapper, int repaintCount, const Color& borderColor, const FloatRect& targetRect, const TransformationMatrix& transform)
 {
     TransformationMatrix adjustedTransform = transform * adjustedTransformForRect(targetRect);
-    for (size_t i = 0; i < m_tiles.size(); ++i)
-        textureMapper->drawNumber(repaintCount, borderColor, m_tiles[i].rect().location(), adjustedTransform);
+    for (auto& tile : m_tiles)
+        textureMapper->drawNumber(repaintCount, borderColor, tile.rect().location(), adjustedTransform);
 }
 
 void TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded(const FloatSize& size, const IntSize& tileSize, bool hasAlpha)
@@ -112,50 +112,52 @@
     }
 
     // Recycle removable tiles to be used for newly requested tiles.
-    for (size_t i = 0; i < tileRectsToAdd.size(); ++i) {
+    for (auto& rect : tileRectsToAdd) {
         if (!tileIndicesToRemove.isEmpty()) {
             // We recycle an existing tile for usage with a new tile rect.
             TextureMapperTile& tile = m_tiles[tileIndicesToRemove.last()];
             tileIndicesToRemove.removeLast();
-            tile.setRect(tileRectsToAdd[i]);
+            tile.setRect(rect);
 
             if (tile.texture())
                 tile.texture()->reset(enclosingIntRect(tile.rect()).size(), hasAlpha ? BitmapTexture::SupportsAlpha : 0);
             continue;
         }
 
-        m_tiles.append(TextureMapperTile(tileRectsToAdd[i]));
+        m_tiles.append(TextureMapperTile(rect));
     }
 
     // Remove unnecessary tiles, if they weren't recycled.
     // We use a threshold to make sure we don't create/destroy tiles too eagerly.
-    for (size_t i = 0; i < tileIndicesToRemove.size() && m_tiles.size() > TileEraseThreshold; ++i)
-        m_tiles.remove(tileIndicesToRemove[i]);
+    for (auto& index : tileIndicesToRemove) {
+        if (m_tiles.size() <= TileEraseThreshold)
+            break;
+        m_tiles.remove(index);
+    }
 }
 
 void TextureMapperTiledBackingStore::updateContents(TextureMapper* textureMapper, Image* image, const FloatSize& totalSize, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag)
 {
     createOrDestroyTilesIfNeeded(totalSize, textureMapper->maxTextureSize(), !image->currentFrameKnownToBeOpaque());
-    for (size_t i = 0; i < m_tiles.size(); ++i)
-        m_tiles[i].updateContents(textureMapper, image, dirtyRect, updateContentsFlag);
+    for (auto& tile : m_tiles)
+        tile.updateContents(textureMapper, image, dirtyRect, updateContentsFlag);
 }
 
 void TextureMapperTiledBackingStore::updateContents(TextureMapper* textureMapper, GraphicsLayer* sourceLayer, const FloatSize& totalSize, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag)
 {
     createOrDestroyTilesIfNeeded(totalSize, textureMapper->maxTextureSize(), true);
-    for (size_t i = 0; i < m_tiles.size(); ++i)
-        m_tiles[i].updateContents(textureMapper, sourceLayer, dirtyRect, updateContentsFlag);
+    for (auto& tile : m_tiles)
+        tile.updateContents(textureMapper, sourceLayer, dirtyRect, updateContentsFlag);
 }
 
 PassRefPtr<BitmapTexture> TextureMapperTiledBackingStore::texture() const
 {
-    for (size_t i = 0; i < m_tiles.size(); ++i) {
-        RefPtr<BitmapTexture> texture = m_tiles[i].texture();
-        if (texture)
+    for (const auto& tile : m_tiles) {
+        if (auto texture = tile.texture())
             return texture;
     }
 
-    return PassRefPtr<BitmapTexture>();
+    return nullptr;
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to