diff options
Diffstat (limited to 'WebCore/platform')
10 files changed, 102 insertions, 72 deletions
diff --git a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp index fdc6860..77f673a 100644 --- a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp +++ b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp @@ -42,6 +42,8 @@ BackedDoubleBufferedTexture::BackedDoubleBufferedTexture(uint32_t w, uint32_t h, SkBitmap* bitmap, SkBitmap::Config config) : DoubleBufferedTexture(eglGetCurrentContext()) + , m_x(-1) + , m_y(-1) , m_usedLevel(-1) , m_config(config) , m_owner(0) diff --git a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h index eea5807..1c50d87 100644 --- a/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h +++ b/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h @@ -81,9 +81,15 @@ public: const SkSize& getSize() const { return m_size; } + int x() { return m_x; } + int y() { return m_y; } + void setTile(int x, int y) { m_x = x; m_y = y; } + private: void destroyTextures(SharedTexture** textures); + int m_x; + int m_y; SkBitmap* m_bitmap; bool m_sharedBitmap; SkSize m_size; diff --git a/WebCore/platform/graphics/android/BaseTile.cpp b/WebCore/platform/graphics/android/BaseTile.cpp index 2753fb2..960d073 100644 --- a/WebCore/platform/graphics/android/BaseTile.cpp +++ b/WebCore/platform/graphics/android/BaseTile.cpp @@ -174,6 +174,9 @@ void BaseTile::draw(float transparency, SkRect& rect) return; } + if (m_texture->x() != m_x || m_texture->y() != m_y) + return; + TextureInfo* textureInfo = m_texture->consumerLock(); if (!textureInfo) { XLOG("%x (%d, %d) trying to draw, but no textureInfo!", this, x(), y()); @@ -198,6 +201,20 @@ bool BaseTile::isTileReady() return !m_dirty; } +void BaseTile::drawTileInfo(SkCanvas* canvas, + BackedDoubleBufferedTexture* texture, + int x, int y, float scale) +{ + SkPaint paint; + char str[256]; + snprintf(str, 256, "(%d,%d) %.2f, tile %x, texture: %x", + x, y, scale, this, texture); + paint.setARGB(255, 0, 0, 0); + canvas->drawText(str, strlen(str), 50, 100, paint); + paint.setARGB(255, 255, 0, 0); + canvas->drawText(str, strlen(str), 51, 101, paint); +} + // This is called from the texture generation thread void BaseTile::paintBitmap() { @@ -218,6 +235,7 @@ void BaseTile::paintBitmap() const int y = m_y; TiledPage* tiledPage = m_page; + texture->producerAcquireContext(); TextureInfo* textureInfo = texture->producerLock(); // at this point we can safely check the ownership (if the texture got @@ -227,8 +245,9 @@ void BaseTile::paintBitmap() return; } - float tileWidth = textureInfo->m_width; - float tileHeight = textureInfo->m_height; + SkSize size = texture->getSize(); + float tileWidth = size.width(); + float tileHeight = size.height(); const float invScale = 1 / scale; float w = tileWidth * invScale; @@ -255,8 +274,10 @@ void BaseTile::paintBitmap() paint.setARGB(128, 0, 0, 255); canvas->drawLine(0, 0, tileWidth, 0, paint); canvas->drawLine(tileWidth, 0, tileWidth, tileHeight, paint); + drawTileInfo(canvas, texture, x, y, scale); #endif + texture->setTile(x, y); texture->producerUpdate(textureInfo); m_atomicSync.lock(); diff --git a/WebCore/platform/graphics/android/BaseTile.h b/WebCore/platform/graphics/android/BaseTile.h index d22849d..0527fcd 100644 --- a/WebCore/platform/graphics/android/BaseTile.h +++ b/WebCore/platform/graphics/android/BaseTile.h @@ -75,6 +75,9 @@ public: // the only thread-safe function called by the background thread void paintBitmap(); + void drawTileInfo(SkCanvas* canvas, + BackedDoubleBufferedTexture* texture, + int x, int y, float scale); void markAsDirty(const unsigned int pictureCount); bool isDirty(); diff --git a/WebCore/platform/graphics/android/GLWebViewState.cpp b/WebCore/platform/graphics/android/GLWebViewState.cpp index 3c1d40a..63fe730 100644 --- a/WebCore/platform/graphics/android/GLWebViewState.cpp +++ b/WebCore/platform/graphics/android/GLWebViewState.cpp @@ -287,6 +287,11 @@ void GLWebViewState::setViewport(SkRect& viewport, float scale) static_cast<int>(floorf(viewport.fTop * invTileContentHeight)), static_cast<int>(ceilf(viewport.fRight * invTileContentWidth)), static_cast<int>(ceilf(viewport.fBottom * invTileContentHeight))); + + int maxTextureCount = (m_viewportTileBounds.width()+1)*(m_viewportTileBounds.height()+1)*2; + TilesManager::instance()->setMaxTextureCount(maxTextureCount); + m_tiledPageA->updateBaseTileSize(); + m_tiledPageB->updateBaseTileSize(); } } // namespace WebCore diff --git a/WebCore/platform/graphics/android/TexturesGenerator.cpp b/WebCore/platform/graphics/android/TexturesGenerator.cpp index cdf4b5a..5b9c809 100644 --- a/WebCore/platform/graphics/android/TexturesGenerator.cpp +++ b/WebCore/platform/graphics/android/TexturesGenerator.cpp @@ -126,10 +126,6 @@ void TexturesGenerator::removeOperationsForFilter(OperationFilter* filter) status_t TexturesGenerator::readyToRun() { - TilesManager::instance()->enableTextures(); - XLOG("Textures enabled (context acquired...)"); - TilesManager::instance()->paintTexturesDefault(); - XLOG("Textures painted"); TilesManager::instance()->markGeneratorAsReady(); XLOG("Thread ready to run"); return NO_ERROR; diff --git a/WebCore/platform/graphics/android/TiledPage.cpp b/WebCore/platform/graphics/android/TiledPage.cpp index 68f38ab..b6d2205 100644 --- a/WebCore/platform/graphics/android/TiledPage.cpp +++ b/WebCore/platform/graphics/android/TiledPage.cpp @@ -49,18 +49,30 @@ #endif // DEBUG +#define MAX_TILES 256 + namespace WebCore { using namespace android; TiledPage::TiledPage(int id, GLWebViewState* state) - : m_id(id) + : m_baseTiles(0) + , m_baseTileSize(0) + , m_id(id) , m_scale(1) , m_invScale(1) , m_glWebViewState(state) , m_latestPictureInval(0) , m_prepare(false) { + m_baseTiles = new BaseTile[MAX_TILES]; +#ifdef DEBUG_COUNT + ClassTracker::instance()->increment("TiledPage"); +#endif +} + +void TiledPage::updateBaseTileSize() +{ // This value must be at least 1 greater than the max number of allowed // textures. This is because prepare() asks for a tile before it reserves // a texture for that tile. If all textures are currently in use by the @@ -69,12 +81,10 @@ TiledPage::TiledPage(int id, GLWebViewState* state) // to reserveTexture() will cause some other tile in the page to lose it's // texture and become available, thus ensuring that we always have at least // one tile that is available. - m_baseTileSize = TilesManager::maxTextureCount() + 1; - m_baseTiles = new BaseTile[m_baseTileSize]; - -#ifdef DEBUG_COUNT - ClassTracker::instance()->increment("TiledPage"); -#endif + int baseTileSize = TilesManager::instance()->maxTextureCount() + 1; + if (baseTileSize > m_baseTileSize) + m_baseTileSize = baseTileSize; + XLOG("Allocate %d tiles", m_baseTileSize); } TiledPage::~TiledPage() @@ -154,18 +164,20 @@ void TiledPage::prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y availableTile = &tile; } - if (!currentTile) { + if (!currentTile && availableTile) { currentTile = availableTile; currentTile->setContents(this, x, y); } - currentTile->setScale(m_scale); + if (currentTile) { + currentTile->setScale(m_scale); - // ensure there is a texture associated with the tile and then check to - // see if the texture is dirty and in need of repainting - currentTile->reserveTexture(); - if (currentTile->isDirty()) - set->add(currentTile); + // ensure there is a texture associated with the tile and then check to + // see if the texture is dirty and in need of repainting + currentTile->reserveTexture(); + if (currentTile->isDirty()) + set->add(currentTile); + } } } @@ -210,7 +222,6 @@ void TiledPage::updateTileState(const SkIRect& tileBounds) int d = std::max(dx, dy); - XLOG("setTileLevel tile: %x, fxy(%d, %d), level: %d", tile, tileBounds.fLeft, tileBounds.fTop, d); tile.setUsedLevel(d); } diff --git a/WebCore/platform/graphics/android/TiledPage.h b/WebCore/platform/graphics/android/TiledPage.h index 6424f34..e449107 100644 --- a/WebCore/platform/graphics/android/TiledPage.h +++ b/WebCore/platform/graphics/android/TiledPage.h @@ -73,6 +73,8 @@ public: void invalidateRect(const IntRect& invalRect, const unsigned int pictureCount); void setUsable(bool usable); + void updateBaseTileSize(); + private: void updateTileState(const SkIRect& tileBounds); void prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y, TileSet* set); diff --git a/WebCore/platform/graphics/android/TilesManager.cpp b/WebCore/platform/graphics/android/TilesManager.cpp index 4b53a54..81b0404 100644 --- a/WebCore/platform/graphics/android/TilesManager.cpp +++ b/WebCore/platform/graphics/android/TilesManager.cpp @@ -68,6 +68,7 @@ namespace WebCore { TilesManager::TilesManager() : m_layersMemoryUsage(0) + , m_maxTextureCount(0) , m_generatorReady(false) { XLOG("TilesManager ctor"); @@ -76,16 +77,6 @@ TilesManager::TilesManager() m_tilesBitmap->setConfig(SkBitmap::kARGB_8888_Config, tileWidth(), tileHeight()); m_tilesBitmap->allocPixels(); m_tilesBitmap->eraseColor(0); - for (int i = 0; i < MAX_TEXTURE_ALLOCATION; i++) { - BackedDoubleBufferedTexture* texture = new BackedDoubleBufferedTexture( - tileWidth(), tileHeight(), m_tilesBitmap); - // the atomic load ensures that the texture has been fully initialized - // before we pass a pointer for other threads to operate on - m_textures.append(reinterpret_cast<BackedDoubleBufferedTexture*>( - android_atomic_acquire_load(reinterpret_cast<int32_t*>(&texture)))); - } - XLOG("TilesManager ctor - init textures done"); - m_pixmapsGenerationThread = new TexturesGenerator(); m_pixmapsGenerationThread->run("TexturesGenerator"); @@ -94,15 +85,23 @@ TilesManager::TilesManager() XLOG("Max texture size %d", m_maxTextureSize); } -// Has to be run on the texture generation threads -void TilesManager::enableTextures() +void TilesManager::allocateTiles() { - android::Mutex::Autolock lock(m_texturesLock); - for (unsigned int i = 0; i < m_textures.size(); i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; - texture->producerAcquireContext(); + int nbTexturesToAllocate = m_maxTextureCount - m_textures.size(); + XLOG("%d tiles to allocate (%d textures planned)", nbTexturesToAllocate, m_maxTextureCount); + int nbTexturesAllocated = 0; + for (int i = 0; i < nbTexturesToAllocate; i++) { + BackedDoubleBufferedTexture* texture = new BackedDoubleBufferedTexture( + tileWidth(), tileHeight(), m_tilesBitmap); + // the atomic load ensures that the texture has been fully initialized + // before we pass a pointer for other threads to operate on + BackedDoubleBufferedTexture* loadedTexture = + reinterpret_cast<BackedDoubleBufferedTexture*>( + android_atomic_acquire_load(reinterpret_cast<int32_t*>(&texture))); + m_textures.append(loadedTexture); + nbTexturesAllocated++; } - XLOG("enableTextures"); + XLOG("allocated %d textures", nbTexturesAllocated); } void TilesManager::printTextures() @@ -128,36 +127,6 @@ void TilesManager::printTextures() #endif // DEBUG } -void TilesManager::paintTexturesDefault() -{ - android::Mutex::Autolock lock(m_texturesLock); - for (unsigned int i = 0; i < m_textures.size(); i++) { - for (int j = 0; j < 2; j++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; - TextureInfo* textureInfo = texture->producerLock(); - SkCanvas* canvas = texture->canvas(); -#ifdef DEBUG - if (j) - canvas->drawARGB(255, 0, 0, 255); - else - canvas->drawARGB(255, 255, 0, 255); - SkPaint paint; - paint.setARGB(128, 255, 0, 0); - paint.setStrokeWidth(3); - canvas->drawLine(0, 0, tileWidth(), tileHeight(), paint); - paint.setARGB(128, 0, 255, 0); - canvas->drawLine(0, tileHeight(), tileWidth(), 0, paint); - paint.setARGB(128, 0, 0, 255); - canvas->drawLine(0, 0, tileWidth(), 0, paint); - canvas->drawLine(tileWidth(), 0, tileWidth(), tileHeight(), paint); -#else - canvas->drawARGB(255, 255, 255, 255); -#endif // DEBUG - texture->producerUpdate(textureInfo); - } - } -} - void TilesManager::resetTextureUsage(TiledPage* page) { android::Mutex::Autolock lock(m_texturesLock); @@ -372,7 +341,19 @@ LayerTexture* TilesManager::createTextureForLayer(LayerAndroid* layer, const Int int TilesManager::maxTextureCount() { - return MAX_TEXTURE_ALLOCATION; + android::Mutex::Autolock lock(m_texturesLock); + return m_maxTextureCount; +} + +void TilesManager::setMaxTextureCount(int max) +{ + XLOG("setMaxTextureCount: %d", max); + if (m_maxTextureCount >= max && m_maxTextureCount) + return; + + android::Mutex::Autolock lock(m_texturesLock); + m_maxTextureCount = max; + allocateTiles(); } float TilesManager::tileWidth() diff --git a/WebCore/platform/graphics/android/TilesManager.h b/WebCore/platform/graphics/android/TilesManager.h index 6cd8bcd..92306b5 100644 --- a/WebCore/platform/graphics/android/TilesManager.h +++ b/WebCore/platform/graphics/android/TilesManager.h @@ -83,15 +83,16 @@ public: } void printTextures(); - void enableTextures(); void resetTextureUsage(TiledPage* page); - void paintTexturesDefault(); - static int maxTextureCount(); + int maxTextureCount(); + void setMaxTextureCount(int max); static float tileWidth(); static float tileHeight(); + void allocateTiles(); + private: TilesManager(); @@ -110,6 +111,8 @@ private: GLint m_maxTextureSize; unsigned int m_totalMaxTextureSize; + int m_maxTextureCount; + bool m_generatorReady; sp<TexturesGenerator> m_pixmapsGenerationThread; |