Commit ab5843bd authored by enne@google.com's avatar enne@google.com

2011-03-10 Adrienne Walker <enne@google.com>

        Reviewed by Kenneth Russell.

        [chromium] Make tiled compositor data structure more efficient.
        https://bugs.webkit.org/show_bug.cgi?id=54133

        Previously, the compositor had a sparse 2D array of tiles for the
        whole page, most of which were null.  The tiles were implicitly
        located based on their position in the array. This was inefficient
        when the page grew (e.g. infinite scrolling) and caused some bugs
        (e.g. width * height > MAX_INT).  This change modifies tiles to have
        explicit positions so they can be stored in a hash map.

        Tests: LayoutTests/compositing/

        * platform/graphics/chromium/LayerTilerChromium.cpp:
        (WebCore::LayerTilerChromium::reset):
        (WebCore::LayerTilerChromium::createTile):
        (WebCore::LayerTilerChromium::invalidateTiles):
        (WebCore::LayerTilerChromium::contentRectToTileIndices):
        (WebCore::LayerTilerChromium::tileAt):
        (WebCore::LayerTilerChromium::tileContentRect):
        (WebCore::LayerTilerChromium::tileLayerRect):
        (WebCore::LayerTilerChromium::invalidateRect):
        (WebCore::LayerTilerChromium::invalidateEntireLayer):
        (WebCore::LayerTilerChromium::update):
        (WebCore::LayerTilerChromium::updateFromPixels):
        (WebCore::LayerTilerChromium::draw):
        (WebCore::LayerTilerChromium::growLayerToContain):
        * platform/graphics/chromium/LayerTilerChromium.h:
        (WebCore::LayerTilerChromium::Tile::Tile):
        (WebCore::LayerTilerChromium::Tile::i):
        (WebCore::LayerTilerChromium::Tile::j):
        (WebCore::LayerTilerChromium::Tile::moveTo):
        (WebCore::LayerTilerChromium::TileMapKeyTraits::emptyValue):
        (WebCore::LayerTilerChromium::TileMapKeyTraits::constructDeletedValue):
        (WebCore::LayerTilerChromium::TileMapKeyTraits::isDeletedValue):

git-svn-id: svn://svn.chromium.org/blink/trunk@80767 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 969f1d55
2011-03-10 Adrienne Walker <enne@google.com>
Reviewed by Kenneth Russell.
[chromium] Make tiled compositor data structure more efficient.
https://bugs.webkit.org/show_bug.cgi?id=54133
Previously, the compositor had a sparse 2D array of tiles for the
whole page, most of which were null. The tiles were implicitly
located based on their position in the array. This was inefficient
when the page grew (e.g. infinite scrolling) and caused some bugs
(e.g. width * height > MAX_INT). This change modifies tiles to have
explicit positions so they can be stored in a hash map.
Tests: LayoutTests/compositing/
* platform/graphics/chromium/LayerTilerChromium.cpp:
(WebCore::LayerTilerChromium::reset):
(WebCore::LayerTilerChromium::createTile):
(WebCore::LayerTilerChromium::invalidateTiles):
(WebCore::LayerTilerChromium::contentRectToTileIndices):
(WebCore::LayerTilerChromium::tileAt):
(WebCore::LayerTilerChromium::tileContentRect):
(WebCore::LayerTilerChromium::tileLayerRect):
(WebCore::LayerTilerChromium::invalidateRect):
(WebCore::LayerTilerChromium::invalidateEntireLayer):
(WebCore::LayerTilerChromium::update):
(WebCore::LayerTilerChromium::updateFromPixels):
(WebCore::LayerTilerChromium::draw):
(WebCore::LayerTilerChromium::growLayerToContain):
* platform/graphics/chromium/LayerTilerChromium.h:
(WebCore::LayerTilerChromium::Tile::Tile):
(WebCore::LayerTilerChromium::Tile::i):
(WebCore::LayerTilerChromium::Tile::j):
(WebCore::LayerTilerChromium::Tile::moveTo):
(WebCore::LayerTilerChromium::TileMapKeyTraits::emptyValue):
(WebCore::LayerTilerChromium::TileMapKeyTraits::constructDeletedValue):
(WebCore::LayerTilerChromium::TileMapKeyTraits::isDeletedValue):
2011-03-10 Ryosuke Niwa <rniwa@webkit.org>
Unreviewed build fix for r80752; Negated the boolean logic.
......
......@@ -33,7 +33,9 @@
#include "LayerTexture.h"
#include "PlatformCanvas.h"
#include "TilingData.h"
#include <wtf/HashTraits.h>
#include <wtf/OwnArrayPtr.h>
#include <wtf/RefCounted.h>
namespace WebCore {
......@@ -70,20 +72,26 @@ public:
private:
LayerTilerChromium(LayerRendererChromium*, const IntSize& tileSize, BorderTexelOption);
class Tile {
class Tile : public RefCounted<Tile> {
WTF_MAKE_NONCOPYABLE(Tile);
public:
explicit Tile(PassOwnPtr<LayerTexture> tex) : m_tex(tex) {}
explicit Tile(PassOwnPtr<LayerTexture> tex) : m_tex(tex), m_i(-1), m_j(-1) {}
LayerTexture* texture() { return m_tex.get(); }
bool dirty() const { return !m_dirtyLayerRect.isEmpty(); }
void clearDirty() { m_dirtyLayerRect = IntRect(); }
int i() const { return m_i; }
int j() const { return m_j; }
void moveTo(int i, int j) { m_i = i; m_j = j; }
// Layer-space dirty rectangle that needs to be repainted.
IntRect m_dirtyLayerRect;
private:
OwnPtr<LayerTexture> m_tex;
int m_i;
int m_j;
};
void drawTexturedQuad(GraphicsContext3D*, const TransformationMatrix& projectionMatrix, const TransformationMatrix& drawMatrix,
......@@ -92,40 +100,45 @@ private:
float texScaleX, float texScaleY,
const LayerTilerChromium::Program*);
void resizeLayer(const IntSize& size);
// Grow layer size to contain this rectangle.
void growLayerToContain(const IntRect& contentRect);
LayerRendererChromium* layerRenderer() const { return m_layerRenderer; }
GraphicsContext3D* layerRendererContext() const;
Tile* createTile(int i, int j);
// Invalidate any tiles which do not intersect with the newLayerRect.
void invalidateTiles(const IntRect& oldLayerRect, const IntRect& newLayerRect);
// Invalidate any tiles which do not intersect with the contentRect
void invalidateTiles(const IntRect& contentRect);
void reset();
void contentRectToTileIndices(const IntRect& contentRect, int &left, int &top, int &right, int &bottom) const;
IntRect contentRectToLayerRect(const IntRect& contentRect) const;
IntRect layerRectToContentRect(const IntRect& layerRect) const;
// Returns the index into m_tiles for a given tile location.
int tileIndex(int i, int j) const;
// Returns the bounds in content space for a given tile location.
IntRect tileContentRect(int i, int j) const;
// Returns the bounds in layer space for a given tile location.
IntRect tileLayerRect(int i, int j) const;
IntSize layerSize() const;
IntSize layerTileSize() const;
Tile* tileAt(int, int) const;
IntRect tileContentRect(const Tile*) const;
IntRect tileLayerRect(const Tile*) const;
IntSize m_tileSize;
IntRect m_lastUpdateLayerRect;
IntPoint m_layerPosition;
bool m_skipsDraw;
// Logical 2D array of tiles (dimensions of m_layerTileSize)
Vector<OwnPtr<Tile> > m_tiles;
// Linear array of unused tiles.
Vector<OwnPtr<Tile> > m_unusedTiles;
// Default hash key traits for integers disallow 0 and -1 as a key, so
// use a custom hash trait which disallows -1 and -2 instead.
typedef std::pair<int, int> TileMapKey;
struct TileMapKeyTraits : HashTraits<TileMapKey> {
static const bool emptyValueIsZero = false;
static const bool needsDestruction = false;
static TileMapKey emptyValue() { return std::make_pair(-1, -1); }
static void constructDeletedValue(TileMapKey& slot) { slot = std::make_pair(-2, -2); }
static bool isDeletedValue(TileMapKey value) { return value.first == -2 && value.second == -2; }
};
// FIXME: The mapped value in TileMap should really be an OwnPtr, as the
// refcount of a Tile should never be more than 1. However, HashMap
// doesn't easily support OwnPtr as a value.
typedef HashMap<TileMapKey, RefPtr<Tile>, DefaultHash<TileMapKey>::Hash, TileMapKeyTraits> TileMap;
TileMap m_tiles;
// Tightly packed set of unused tiles.
Vector<RefPtr<Tile> > m_unusedTiles;
PlatformCanvas m_canvas;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment