From ec182c75fb35d955a9115fbaf516f648a48ed0e1 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Tue, 28 Jun 2011 09:33:24 -0400 Subject: Cleanup Skia related rendering code for raster rendering. In the existing code we created a sharedBitmap for BaseTiles and never used it instead opting for createing bitmaps on the stack to enable partial invalidation. This CL removes the sharedBitmap concept and instead creates all bitmaps on the stack. This means that BackedDoubleBufferedTexture no longer needs to have a bitmap member, but instead simply takes the bitmap from the caller and uploads it to the appropriate texture. To make this upload clean we now pass the bitmap via const references instead of pointers. Change-Id: Ie218c4b4564e5574ca6e404d4857904ab41a3a5c --- .../android/BackedDoubleBufferedTexture.cpp | 274 --------------------- .../graphics/android/BackedDoubleBufferedTexture.h | 145 ----------- .../WebCore/platform/graphics/android/BaseTile.cpp | 9 +- .../WebCore/platform/graphics/android/BaseTile.h | 10 +- .../platform/graphics/android/BaseTileTexture.cpp | 237 ++++++++++++++++++ .../platform/graphics/android/BaseTileTexture.h | 137 +++++++++++ .../WebCore/platform/graphics/android/GLUtils.cpp | 51 ++-- Source/WebCore/platform/graphics/android/GLUtils.h | 13 +- .../platform/graphics/android/LayerAndroid.cpp | 21 +- .../platform/graphics/android/LayerAndroid.h | 4 +- .../platform/graphics/android/LayerTexture.h | 9 +- .../platform/graphics/android/RasterRenderer.cpp | 6 +- .../platform/graphics/android/RasterRenderer.h | 6 +- .../platform/graphics/android/TextureOwner.h | 4 +- .../platform/graphics/android/TilesManager.cpp | 24 +- .../platform/graphics/android/TilesManager.h | 7 +- 16 files changed, 452 insertions(+), 505 deletions(-) delete mode 100644 Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp delete mode 100644 Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h create mode 100644 Source/WebCore/platform/graphics/android/BaseTileTexture.cpp create mode 100644 Source/WebCore/platform/graphics/android/BaseTileTexture.h (limited to 'Source/WebCore/platform') diff --git a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp b/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp deleted file mode 100644 index 0e22103..0000000 --- a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright 2010, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "BackedDoubleBufferedTexture.h" - -#include "BaseTile.h" -#include "ClassTracker.h" -#include "DeleteTextureOperation.h" -#include "GLUtils.h" -#include "TilesManager.h" - -#define LOG_NDEBUG 1 -#define LOG_TAG "BackedDoubleBufferedTexture.cpp" -#include - -namespace WebCore { - -BackedDoubleBufferedTexture::BackedDoubleBufferedTexture(uint32_t w, uint32_t h, - SkBitmap* bitmap, - SkBitmap::Config config) - : DoubleBufferedTexture(eglGetCurrentContext(), SurfaceTextureMode) - , m_usedLevel(-1) - , m_config(config) - , m_owner(0) - , m_delayedReleaseOwner(0) - , m_delayedRelease(false) - , m_busy(false) -{ - m_size.set(w, h); - if (bitmap) { - m_bitmap = bitmap; - m_sharedBitmap = true; - m_canvas = new SkCanvas(*m_bitmap); - } else { - m_bitmap = 0; - m_sharedBitmap = false; - m_canvas = 0; - } - -#ifdef DEBUG_COUNT - ClassTracker::instance()->increment("BackedDoubleBufferedTexture"); -#endif -} - -SkCanvas* BackedDoubleBufferedTexture::canvas() -{ - if (!m_bitmap && !m_sharedBitmap) { - m_bitmap = new SkBitmap(); - m_bitmap->setConfig(m_config, m_size.width(), m_size.height()); - m_bitmap->allocPixels(); - m_bitmap->eraseColor(0); - m_canvas = new SkCanvas(*m_bitmap); - } - return m_canvas; -} - -BackedDoubleBufferedTexture::~BackedDoubleBufferedTexture() -{ - if (!m_sharedBitmap) - delete m_bitmap; - delete m_canvas; - if (m_sharedTextureMode == EglImageMode) { - SharedTexture* textures[3] = { m_textureA, m_textureB, 0 }; - destroyTextures(textures); - } -#ifdef DEBUG_COUNT - ClassTracker::instance()->decrement("BackedDoubleBufferedTexture"); -#endif -} - -void BackedDoubleBufferedTexture::destroyTextures(SharedTexture** textures) -{ - int x = 0; - while (textures[x]) { - // We need to delete the source texture and EGLImage in the texture - // generation thread. In theory we should be able to delete the EGLImage - // from either thread, but it currently throws an error if not deleted - // in the same EGLContext from which it was created. - textures[x]->lock(); - DeleteTextureOperation* operation = new DeleteTextureOperation( - textures[x]->getSourceTextureId(), textures[x]->getEGLImage()); - textures[x]->unlock(); - TilesManager::instance()->scheduleOperation(operation); - x++; - } -} - -TextureInfo* BackedDoubleBufferedTexture::producerLock() -{ - m_busyLock.lock(); - m_busy = true; - m_busyLock.unlock(); - return DoubleBufferedTexture::producerLock(); -} - -void BackedDoubleBufferedTexture::producerRelease() -{ - DoubleBufferedTexture::producerRelease(); - setNotBusy(); -} - -void BackedDoubleBufferedTexture::producerReleaseAndSwap() -{ - DoubleBufferedTexture::producerReleaseAndSwap(); - setNotBusy(); -} - -void BackedDoubleBufferedTexture::setNotBusy() -{ - android::Mutex::Autolock lock(m_busyLock); - m_busy = false; - if (m_delayedRelease) { - if (m_owner == m_delayedReleaseOwner) - m_owner = 0; - - m_delayedRelease = false; - m_delayedReleaseOwner = 0; - } - m_busyCond.signal(); -} - -bool BackedDoubleBufferedTexture::busy() -{ - android::Mutex::Autolock lock(m_busyLock); - return m_busy; -} - -void BackedDoubleBufferedTexture::producerUpdate(TextureInfo* textureInfo) -{ - if (!m_bitmap) - return; - - // no need to upload a texture since the bitmap is empty - if (!m_bitmap->width() && !m_bitmap->height()) { - producerRelease(); - return; - } - - GLUtils::paintTextureWithBitmap(textureInfo, m_bitmap, 0, 0, this); - - if (!m_sharedBitmap) { - delete m_bitmap; - delete m_canvas; - m_bitmap = 0; - m_canvas = 0; - } - - producerReleaseAndSwap(); -} - -bool BackedDoubleBufferedTexture::acquire(TextureOwner* owner, bool force) -{ - if (m_owner == owner) { - if (m_delayedRelease) { - m_delayedRelease = false; - m_delayedReleaseOwner = 0; - } - return true; - } - - return setOwner(owner, force); -} - -bool BackedDoubleBufferedTexture::tryAcquire(TextureOwner* owner, TiledPage* currentPage, TiledPage* nextPage) -{ - m_busyLock.lock(); - if (!m_busy - && m_owner - && m_owner->page() != currentPage - && m_owner->page() != nextPage) { - m_busyLock.unlock(); - return this->acquire(owner); - } - m_busyLock.unlock(); - return false; -} - -bool BackedDoubleBufferedTexture::setOwner(TextureOwner* owner, bool force) -{ - // if the writable texture is busy (i.e. currently being written to) then we - // can't change the owner out from underneath that texture - m_busyLock.lock(); - while (m_busy && force) - m_busyCond.wait(m_busyLock); - bool busy = m_busy; - m_busyLock.unlock(); - - if (!busy) { - // if we are not busy we can try to remove the texture from the layer; - // LayerAndroid::removeTexture() is protected by the same lock as - // LayerAndroid::paintBitmapGL(), so either we execute removeTexture() - // first and paintBitmapGL() will bail out, or we execute it after, - // and paintBitmapGL() will mark the texture as busy before - // relinquishing the lock. LayerAndroid::removeTexture() will call - // BackedDoubleBufferedTexture::release(), which will then do nothing - // if the texture is busy and we then don't return true. - bool proceed = true; - if (m_owner && m_owner != owner) - proceed = m_owner->removeTexture(this); - - if (proceed) { - m_owner = owner; - return true; - } - } - return false; -} - -bool BackedDoubleBufferedTexture::release(TextureOwner* owner) -{ - android::Mutex::Autolock lock(m_busyLock); - if (m_owner != owner) - return false; - - if (!m_busy) { - m_owner = 0; - } else { - m_delayedRelease = true; - m_delayedReleaseOwner = owner; - } - return true; -} - -void BackedDoubleBufferedTexture::setTile(TextureInfo* info, int x, int y, - float scale, unsigned int pictureCount) -{ - TextureTileInfo* textureInfo = m_texturesInfo.get(getWriteableTexture()); - if (!textureInfo) { - textureInfo = new TextureTileInfo(); - } - textureInfo->m_x = x; - textureInfo->m_y = y; - textureInfo->m_scale = scale; - textureInfo->m_picture = pictureCount; - m_texturesInfo.set(getWriteableTexture(), textureInfo); -} - -bool BackedDoubleBufferedTexture::readyFor(BaseTile* baseTile) -{ - TextureTileInfo* info = m_texturesInfo.get(getReadableTexture()); - if (info && - (info->m_x == baseTile->x()) && - (info->m_y == baseTile->y()) && - (info->m_scale == baseTile->scale()) && - (info->m_picture == baseTile->lastPaintedPicture())) { - return true; - } - return false; -} - -} // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h b/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h deleted file mode 100644 index 89ea771..0000000 --- a/Source/WebCore/platform/graphics/android/BackedDoubleBufferedTexture.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2010, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef BackedDoubleBufferedTexture_h -#define BackedDoubleBufferedTexture_h - -#include "DoubleBufferedTexture.h" -#include "GLWebViewState.h" -#include "TextureOwner.h" -#include - -class SkCanvas; - -namespace WebCore { - -class BaseTile; - -class TextureTileInfo { - public: - TextureTileInfo() - : m_x(-1) - , m_y(-1) - , m_layerId(-1) - , m_scale(0) - , m_texture(0) - , m_picture(0) - { - } - int m_x; - int m_y; - int m_layerId; - float m_scale; - TextureInfo* m_texture; - unsigned int m_picture; -}; - -// DoubleBufferedTexture using a SkBitmap as backing mechanism -class BackedDoubleBufferedTexture : public DoubleBufferedTexture { -public: - // This object is to be constructed on the consumer's thread and must have - // a width and height greater than 0. - BackedDoubleBufferedTexture(uint32_t w, uint32_t h, - SkBitmap* bitmap = 0, - SkBitmap::Config config = SkBitmap::kARGB_8888_Config); - virtual ~BackedDoubleBufferedTexture(); - - // these functions override their parent - virtual TextureInfo* producerLock(); - virtual void producerRelease(); - virtual void producerReleaseAndSwap(); - - // updates the texture with current bitmap and releases (and if needed also - // swaps) the texture. - virtual void producerUpdate(TextureInfo* textureInfo); - void producerUpdate(TextureInfo* textureInfo, SkBitmap* bitmap, SkIRect& rect); - - // The level can be one of the following values: - // * -1 for an unused texture. - // * 0 for the tiles intersecting with the viewport. - // * n where n > 0 for the distance between the viewport and the tile. - // We use this to prioritize the order in which we reclaim textures, see - // TilesManager::getAvailableTexture() for more information. - int usedLevel() { return m_usedLevel; } - void setUsedLevel(int used) { m_usedLevel = used; } - - // allows consumer thread to assign ownership of the texture to the tile. It - // returns false if ownership cannot be transferred because the tile is busy - bool acquire(TextureOwner* owner, bool force = false); - bool release(TextureOwner* owner); - bool tryAcquire(TextureOwner* owner, TiledPage* currentPage, TiledPage* nextPage); - - // set the texture owner if not busy. Return false if busy, true otherwise. - bool setOwner(TextureOwner* owner, bool force = false); - - // private member accessor functions - TextureOwner* owner() { return m_owner; } // only used by the consumer thread - TextureOwner* delayedReleaseOwner() { return m_delayedReleaseOwner; } - SkCanvas* canvas(); // only used by the producer thread - SkBitmap* bitmap() { return m_bitmap; } - - bool busy(); - void setNotBusy(); - - const SkSize& getSize() const { return m_size; } - - void setTile(TextureInfo* info, int x, int y, float scale, unsigned int pictureCount); - bool readyFor(BaseTile* baseTile); - -protected: - HashMap m_texturesInfo; - -private: - void destroyTextures(SharedTexture** textures); - - SkBitmap* m_bitmap; - bool m_sharedBitmap; - SkSize m_size; - SkCanvas* m_canvas; - int m_usedLevel; - SkBitmap::Config m_config; - TextureOwner* m_owner; - - // When trying to release a texture, we may delay this if the texture is - // currently used (busy being painted). We use the following two variables - // to do so in setNotBusy() - TextureOwner* m_delayedReleaseOwner; - bool m_delayedRelease; - - // This values signals that the texture is currently in use by the consumer. - // This allows us to prevent the owner of the texture from changing while the - // consumer is holding a lock on the texture. - bool m_busy; - // We mutex protect the reads/writes of m_busy to ensure that we are reading - // the most up-to-date value even across processors in an SMP system. - android::Mutex m_busyLock; - // We use this condition variable to signal that the texture - // is not busy anymore - android::Condition m_busyCond; -}; - -} // namespace WebCore - -#endif // BackedDoubleBufferedTexture_h diff --git a/Source/WebCore/platform/graphics/android/BaseTile.cpp b/Source/WebCore/platform/graphics/android/BaseTile.cpp index 4515083..7020208 100644 --- a/Source/WebCore/platform/graphics/android/BaseTile.cpp +++ b/Source/WebCore/platform/graphics/android/BaseTile.cpp @@ -95,7 +95,7 @@ void BaseTile::setContents(TiledPage* page, int x, int y) void BaseTile::reserveTexture() { - BackedDoubleBufferedTexture* texture = TilesManager::instance()->getAvailableTexture(this); + BaseTileTexture* texture = TilesManager::instance()->getAvailableTexture(this); android::AutoMutex lock(m_atomicSync); if (texture && m_texture != texture) { @@ -105,7 +105,7 @@ void BaseTile::reserveTexture() } } -bool BaseTile::removeTexture(BackedDoubleBufferedTexture* texture) +bool BaseTile::removeTexture(BaseTileTexture* texture) { XLOG("%x removeTexture res: %x... page %x", this, m_texture, m_page); // We update atomically, so paintBitmap() can see the correct value @@ -254,7 +254,7 @@ void BaseTile::paintBitmap() // can be updated by other threads without consequence. m_atomicSync.lock(); bool dirty = m_dirty; - BackedDoubleBufferedTexture* texture = m_texture; + BaseTileTexture* texture = m_texture; SkRegion dirtyArea = *m_currentDirtyArea; float scale = m_scale; const int x = m_x; @@ -289,7 +289,8 @@ void BaseTile::paintBitmap() // TODO: Implement the partial invalidate in Surface Texture Mode if (((m_currentDirtyArea == &m_dirtyAreaA) && m_fullRepaintA) || ((m_currentDirtyArea == &m_dirtyAreaB) && m_fullRepaintB) - || !GLUtils::textureExist(textureInfo, texture->bitmap()) + || textureInfo->m_width != tileWidth + || textureInfo->m_height != tileHeight || textureInfo->getSharedTextureMode() == SurfaceTextureMode) { fullRepaint = true; } diff --git a/Source/WebCore/platform/graphics/android/BaseTile.h b/Source/WebCore/platform/graphics/android/BaseTile.h index f58a598..cddaa60 100644 --- a/Source/WebCore/platform/graphics/android/BaseTile.h +++ b/Source/WebCore/platform/graphics/android/BaseTile.h @@ -39,7 +39,7 @@ namespace WebCore { class TextureInfo; class TiledPage; -class BackedDoubleBufferedTexture; +class BaseTileTexture; /** * An individual tile that is used to construct part of a webpage's BaseLayer of @@ -74,7 +74,7 @@ public: // the only thread-safe function called by the background thread void paintBitmap(); int paintPartialBitmap(SkIRect rect, float tx, float ty, - float scale, BackedDoubleBufferedTexture* texture, + float scale, BaseTileTexture* texture, TextureInfo* textureInfo, TiledPage* tiledPage, bool fullRepaint = false); @@ -92,10 +92,10 @@ public: int x() const { return m_x; } int y() const { return m_y; } unsigned int lastPaintedPicture() const { return m_lastPaintedPicture; } - BackedDoubleBufferedTexture* texture() { return m_texture; } + BaseTileTexture* texture() { return m_texture; } // TextureOwner implementation - virtual bool removeTexture(BackedDoubleBufferedTexture* texture); + virtual bool removeTexture(BaseTileTexture* texture); virtual TiledPage* page() { return m_page; } private: @@ -105,7 +105,7 @@ private: int m_y; // The remaining variables can be updated throughout the lifetime of the object - BackedDoubleBufferedTexture* m_texture; + BaseTileTexture* m_texture; float m_scale; // used to signal that the that the tile is out-of-date and needs to be redrawn bool m_dirty; diff --git a/Source/WebCore/platform/graphics/android/BaseTileTexture.cpp b/Source/WebCore/platform/graphics/android/BaseTileTexture.cpp new file mode 100644 index 0000000..ee8cebf --- /dev/null +++ b/Source/WebCore/platform/graphics/android/BaseTileTexture.cpp @@ -0,0 +1,237 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "BaseTileTexture.h" + +#include "BaseTile.h" +#include "ClassTracker.h" +#include "DeleteTextureOperation.h" +#include "GLUtils.h" +#include "TilesManager.h" + +#define LOG_NDEBUG 1 +#define LOG_TAG "BaseTileTexture.cpp" +#include + +namespace WebCore { + +BaseTileTexture::BaseTileTexture(uint32_t w, uint32_t h) + : DoubleBufferedTexture(eglGetCurrentContext(), SurfaceTextureMode) + , m_usedLevel(-1) + , m_owner(0) + , m_delayedReleaseOwner(0) + , m_delayedRelease(false) + , m_busy(false) +{ + m_size.set(w, h); + +#ifdef DEBUG_COUNT + ClassTracker::instance()->increment("BaseTileTexture"); +#endif +} + +BaseTileTexture::~BaseTileTexture() +{ + if (m_sharedTextureMode == EglImageMode) { + SharedTexture* textures[3] = { m_textureA, m_textureB, 0 }; + destroyTextures(textures); + } +#ifdef DEBUG_COUNT + ClassTracker::instance()->decrement("BaseTileTexture"); +#endif +} + +void BaseTileTexture::destroyTextures(SharedTexture** textures) +{ + int x = 0; + while (textures[x]) { + // We need to delete the source texture and EGLImage in the texture + // generation thread. In theory we should be able to delete the EGLImage + // from either thread, but it currently throws an error if not deleted + // in the same EGLContext from which it was created. + textures[x]->lock(); + DeleteTextureOperation* operation = new DeleteTextureOperation( + textures[x]->getSourceTextureId(), textures[x]->getEGLImage()); + textures[x]->unlock(); + TilesManager::instance()->scheduleOperation(operation); + x++; + } +} + +TextureInfo* BaseTileTexture::producerLock() +{ + m_busyLock.lock(); + m_busy = true; + m_busyLock.unlock(); + return DoubleBufferedTexture::producerLock(); +} + +void BaseTileTexture::producerRelease() +{ + DoubleBufferedTexture::producerRelease(); + setNotBusy(); +} + +void BaseTileTexture::producerReleaseAndSwap() +{ + DoubleBufferedTexture::producerReleaseAndSwap(); + setNotBusy(); +} + +void BaseTileTexture::setNotBusy() +{ + android::Mutex::Autolock lock(m_busyLock); + m_busy = false; + if (m_delayedRelease) { + if (m_owner == m_delayedReleaseOwner) + m_owner = 0; + + m_delayedRelease = false; + m_delayedReleaseOwner = 0; + } + m_busyCond.signal(); +} + +bool BaseTileTexture::busy() +{ + android::Mutex::Autolock lock(m_busyLock); + return m_busy; +} + +void BaseTileTexture::producerUpdate(TextureInfo* textureInfo, const SkBitmap& bitmap) +{ + // no need to upload a texture since the bitmap is empty + if (!bitmap.width() && !bitmap.height()) { + producerRelease(); + return; + } + + GLUtils::paintTextureWithBitmap(textureInfo, m_size, bitmap, 0, 0); + + producerReleaseAndSwap(); +} + +bool BaseTileTexture::acquire(TextureOwner* owner, bool force) +{ + if (m_owner == owner) { + if (m_delayedRelease) { + m_delayedRelease = false; + m_delayedReleaseOwner = 0; + } + return true; + } + + return setOwner(owner, force); +} + +bool BaseTileTexture::tryAcquire(TextureOwner* owner, TiledPage* currentPage, TiledPage* nextPage) +{ + m_busyLock.lock(); + if (!m_busy + && m_owner + && m_owner->page() != currentPage + && m_owner->page() != nextPage) { + m_busyLock.unlock(); + return this->acquire(owner); + } + m_busyLock.unlock(); + return false; +} + +bool BaseTileTexture::setOwner(TextureOwner* owner, bool force) +{ + // if the writable texture is busy (i.e. currently being written to) then we + // can't change the owner out from underneath that texture + m_busyLock.lock(); + while (m_busy && force) + m_busyCond.wait(m_busyLock); + bool busy = m_busy; + m_busyLock.unlock(); + + if (!busy) { + // if we are not busy we can try to remove the texture from the layer; + // LayerAndroid::removeTexture() is protected by the same lock as + // LayerAndroid::paintBitmapGL(), so either we execute removeTexture() + // first and paintBitmapGL() will bail out, or we execute it after, + // and paintBitmapGL() will mark the texture as busy before + // relinquishing the lock. LayerAndroid::removeTexture() will call + // BaseTileTexture::release(), which will then do nothing + // if the texture is busy and we then don't return true. + bool proceed = true; + if (m_owner && m_owner != owner) + proceed = m_owner->removeTexture(this); + + if (proceed) { + m_owner = owner; + return true; + } + } + return false; +} + +bool BaseTileTexture::release(TextureOwner* owner) +{ + android::Mutex::Autolock lock(m_busyLock); + if (m_owner != owner) + return false; + + if (!m_busy) { + m_owner = 0; + } else { + m_delayedRelease = true; + m_delayedReleaseOwner = owner; + } + return true; +} + +void BaseTileTexture::setTile(TextureInfo* info, int x, int y, + float scale, unsigned int pictureCount) +{ + TextureTileInfo* textureInfo = m_texturesInfo.get(getWriteableTexture()); + if (!textureInfo) { + textureInfo = new TextureTileInfo(); + } + textureInfo->m_x = x; + textureInfo->m_y = y; + textureInfo->m_scale = scale; + textureInfo->m_picture = pictureCount; + m_texturesInfo.set(getWriteableTexture(), textureInfo); +} + +bool BaseTileTexture::readyFor(BaseTile* baseTile) +{ + TextureTileInfo* info = m_texturesInfo.get(getReadableTexture()); + if (info && + (info->m_x == baseTile->x()) && + (info->m_y == baseTile->y()) && + (info->m_scale == baseTile->scale()) && + (info->m_picture == baseTile->lastPaintedPicture())) { + return true; + } + return false; +} + +} // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/BaseTileTexture.h b/Source/WebCore/platform/graphics/android/BaseTileTexture.h new file mode 100644 index 0000000..0a7534a --- /dev/null +++ b/Source/WebCore/platform/graphics/android/BaseTileTexture.h @@ -0,0 +1,137 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef BaseTileTexture_h +#define BaseTileTexture_h + +#include "DoubleBufferedTexture.h" +#include "GLWebViewState.h" +#include "TextureOwner.h" +#include + +class SkCanvas; + +namespace WebCore { + +class BaseTile; + +class TextureTileInfo { + public: + TextureTileInfo() + : m_x(-1) + , m_y(-1) + , m_layerId(-1) + , m_scale(0) + , m_texture(0) + , m_picture(0) + { + } + int m_x; + int m_y; + int m_layerId; + float m_scale; + TextureInfo* m_texture; + unsigned int m_picture; +}; + +// DoubleBufferedTexture using a SkBitmap as backing mechanism +class BaseTileTexture : public DoubleBufferedTexture { +public: + // This object is to be constructed on the consumer's thread and must have + // a width and height greater than 0. + BaseTileTexture(uint32_t w, uint32_t h); + virtual ~BaseTileTexture(); + + // these functions override their parent + virtual TextureInfo* producerLock(); + virtual void producerRelease(); + virtual void producerReleaseAndSwap(); + + // updates the texture with current bitmap and releases (and if needed also + // swaps) the texture. + virtual void producerUpdate(TextureInfo* textureInfo, const SkBitmap& bitmap); + + // The level can be one of the following values: + // * -1 for an unused texture. + // * 0 for the tiles intersecting with the viewport. + // * n where n > 0 for the distance between the viewport and the tile. + // We use this to prioritize the order in which we reclaim textures, see + // TilesManager::getAvailableTexture() for more information. + int usedLevel() { return m_usedLevel; } + void setUsedLevel(int used) { m_usedLevel = used; } + + // allows consumer thread to assign ownership of the texture to the tile. It + // returns false if ownership cannot be transferred because the tile is busy + bool acquire(TextureOwner* owner, bool force = false); + bool release(TextureOwner* owner); + bool tryAcquire(TextureOwner* owner, TiledPage* currentPage, TiledPage* nextPage); + + // set the texture owner if not busy. Return false if busy, true otherwise. + bool setOwner(TextureOwner* owner, bool force = false); + + // private member accessor functions + TextureOwner* owner() { return m_owner; } // only used by the consumer thread + TextureOwner* delayedReleaseOwner() { return m_delayedReleaseOwner; } + + bool busy(); + void setNotBusy(); + + const SkSize& getSize() const { return m_size; } + + void setTile(TextureInfo* info, int x, int y, float scale, unsigned int pictureCount); + bool readyFor(BaseTile* baseTile); + +protected: + HashMap m_texturesInfo; + +private: + void destroyTextures(SharedTexture** textures); + + SkSize m_size; + int m_usedLevel; + SkBitmap::Config m_config; + TextureOwner* m_owner; + + // When trying to release a texture, we may delay this if the texture is + // currently used (busy being painted). We use the following two variables + // to do so in setNotBusy() + TextureOwner* m_delayedReleaseOwner; + bool m_delayedRelease; + + // This values signals that the texture is currently in use by the consumer. + // This allows us to prevent the owner of the texture from changing while the + // consumer is holding a lock on the texture. + bool m_busy; + // We mutex protect the reads/writes of m_busy to ensure that we are reading + // the most up-to-date value even across processors in an SMP system. + android::Mutex m_busyLock; + // We use this condition variable to signal that the texture + // is not busy anymore + android::Condition m_busyCond; +}; + +} // namespace WebCore + +#endif // BaseTileTexture_h diff --git a/Source/WebCore/platform/graphics/android/GLUtils.cpp b/Source/WebCore/platform/graphics/android/GLUtils.cpp index 29608cf..e32f1e9 100644 --- a/Source/WebCore/platform/graphics/android/GLUtils.cpp +++ b/Source/WebCore/platform/graphics/android/GLUtils.cpp @@ -336,45 +336,36 @@ GLuint GLUtils::createSampleTexture() return texture; } -bool GLUtils::textureExist(TextureInfo* textureInfo, const SkBitmap* bitmap) -{ - if (!bitmap) - return false; - - if (!bitmap->width() || !bitmap->height()) - return false; - - if (textureInfo->m_width == bitmap->width() - && textureInfo->m_height == bitmap->height()) - return true; - - return false; -} - void GLUtils::paintTextureWithBitmap(TextureInfo* textureInfo, - SkBitmap* bitmap, - int x, - int y, - BackedDoubleBufferedTexture* texture) + const SkSize& requiredSize, + const SkBitmap& bitmap, + int x, int y) { SharedTextureMode mode = textureInfo->getSharedTextureMode(); - if (textureExist(textureInfo, texture->bitmap())) { + if (requiredSize.equals(textureInfo->m_width, textureInfo->m_height)) { if (mode == EglImageMode) - GLUtils::updateTextureWithBitmap(textureInfo->m_textureId, x, y, *bitmap); + GLUtils::updateTextureWithBitmap(textureInfo->m_textureId, x, y, bitmap); else if (mode == SurfaceTextureMode) - GLUtils::updateSurfaceTextureWithBitmap(textureInfo, x, y, *bitmap); + GLUtils::updateSurfaceTextureWithBitmap(textureInfo, x, y, bitmap); } else { + + if (!requiredSize.equals(bitmap.width(), bitmap.height())) { + XLOG("The bitmap size (%d,%d) does not equal the texture size (%d,%d)", + bitmap.width(), bitmap.height(), + requiredSize.width(), requiredSize.height()); + } + if (mode == EglImageMode) - GLUtils::createTextureWithBitmap(textureInfo->m_textureId, *bitmap); + GLUtils::createTextureWithBitmap(textureInfo->m_textureId, bitmap); else if (mode == SurfaceTextureMode) - GLUtils::createSurfaceTextureWithBitmap(textureInfo, *bitmap); + GLUtils::createSurfaceTextureWithBitmap(textureInfo, bitmap); - textureInfo->m_width = bitmap->width(); - textureInfo->m_height = bitmap->height(); + textureInfo->m_width = bitmap.width(); + textureInfo->m_height = bitmap.height(); } } -void GLUtils::createSurfaceTextureWithBitmap(TextureInfo* texture, SkBitmap& bitmap, GLint filter) +void GLUtils::createSurfaceTextureWithBitmap(TextureInfo* texture, const SkBitmap& bitmap, GLint filter) { sp surfaceTexture = texture->m_surfaceTexture; sp ANW = texture->m_ANW; @@ -394,7 +385,7 @@ void GLUtils::createSurfaceTextureWithBitmap(TextureInfo* texture, SkBitmap& bit updateSurfaceTextureWithBitmap(texture, 0, 0, bitmap, filter); } -void GLUtils::updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, SkBitmap& bitmap, GLint filter) +void GLUtils::updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, const SkBitmap& bitmap, GLint filter) { sp surfaceTexture = texture->m_surfaceTexture; sp ANW = texture->m_ANW; @@ -431,7 +422,7 @@ void GLUtils::updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, checkSurfaceTextureError("queueBuffer", status); } -void GLUtils::createTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint filter) +void GLUtils::createTextureWithBitmap(GLuint texture, const SkBitmap& bitmap, GLint filter) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, texture); @@ -462,7 +453,7 @@ void GLUtils::createTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint fi glDeleteFramebuffers(1, &fboID); } -void GLUtils::updateTextureWithBitmap(GLuint texture, int x, int y, SkBitmap& bitmap, GLint filter) +void GLUtils::updateTextureWithBitmap(GLuint texture, int x, int y, const SkBitmap& bitmap, GLint filter) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, texture); diff --git a/Source/WebCore/platform/graphics/android/GLUtils.h b/Source/WebCore/platform/graphics/android/GLUtils.h index 85656f1..a015136 100644 --- a/Source/WebCore/platform/graphics/android/GLUtils.h +++ b/Source/WebCore/platform/graphics/android/GLUtils.h @@ -28,9 +28,9 @@ #if USE(ACCELERATED_COMPOSITING) -#include "BackedDoubleBufferedTexture.h" #include "SkBitmap.h" #include "SkMatrix.h" +#include "SkSize.h" #include "TextureInfo.h" #include "TransformationMatrix.h" #include @@ -64,16 +64,15 @@ public: static void deleteTexture(GLuint* texture); static GLuint createSampleColorTexture(int r, int g, int b); static GLuint createSampleTexture(); - static void createTextureWithBitmap(GLuint texture, SkBitmap& bitmap, GLint filter = GL_LINEAR); - static void updateTextureWithBitmap(GLuint texture, int x, int y, SkBitmap& bitmap, GLint filter = GL_LINEAR); + static void createTextureWithBitmap(GLuint texture, const SkBitmap& bitmap, GLint filter = GL_LINEAR); + static void updateTextureWithBitmap(GLuint texture, int x, int y, const SkBitmap& bitmap, GLint filter = GL_LINEAR); static void createEGLImageFromTexture(GLuint texture, EGLImageKHR* image); static void createTextureFromEGLImage(GLuint texture, EGLImageKHR image, GLint filter = GL_LINEAR); - static bool textureExist(TextureInfo* textureInfo, const SkBitmap* bitmap); - static void paintTextureWithBitmap(TextureInfo* textureInfo, SkBitmap* bitmap, int x, int y, BackedDoubleBufferedTexture* texture); + static void paintTextureWithBitmap(TextureInfo* textureInfo, const SkSize& requiredSize, const SkBitmap& bitmap, int x, int y); - static void createSurfaceTextureWithBitmap(TextureInfo* texture, SkBitmap& bitmap, GLint filter = GL_LINEAR); - static void updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, SkBitmap& bitmap, GLint filter = GL_LINEAR); + static void createSurfaceTextureWithBitmap(TextureInfo* texture, const SkBitmap& bitmap, GLint filter = GL_LINEAR); + static void updateSurfaceTextureWithBitmap(TextureInfo* texture, int x, int y, const SkBitmap& bitmap, GLint filter = GL_LINEAR); }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp index 74b246f..e90829a 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -163,7 +163,7 @@ LayerAndroid::LayerAndroid(SkPicture* picture) : SkLayer(), #endif } -bool LayerAndroid::removeTexture(BackedDoubleBufferedTexture* aTexture) +bool LayerAndroid::removeTexture(BaseTileTexture* aTexture) { LayerTexture* texture = static_cast(aTexture); android::AutoMutex lock(m_atomicSync); @@ -1051,14 +1051,21 @@ void LayerAndroid::paintBitmapGL() } XLOG("LayerAndroid %d %x (%.2f, %.2f) paintBitmapGL WE ARE PAINTING", uniqueId(), this, getWidth(), getHeight()); - SkCanvas* canvas = texture->canvas(); + + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, texture->getSize().width(), texture->getSize().height()); + bitmap.allocPixels(); + + SkCanvas canvas(bitmap); + canvas.drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode); + float scale = texture->scale(); IntRect textureRect = texture->rect(); - canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode); + if (m_contentsImage) { - contentDraw(canvas); + contentDraw(&canvas); } else { SkPicture picture; SkCanvas* nCanvas = picture.beginRecording(textureRect.width(), @@ -1067,9 +1074,9 @@ void LayerAndroid::paintBitmapGL() nCanvas->translate(-textureRect.x(), -textureRect.y()); contentDraw(nCanvas); picture.endRecording(); - picture.draw(canvas); + picture.draw(&canvas); } - extraDraw(canvas); + extraDraw(&canvas); m_atomicSync.lock(); texture->setTextureInfoFor(this); @@ -1078,7 +1085,7 @@ void LayerAndroid::paintBitmapGL() m_requestSent = false; XLOG("LayerAndroid %d paintBitmapGL PAINTING DONE, updating the texture", uniqueId()); - texture->producerUpdate(textureInfo); + texture->producerUpdate(textureInfo, bitmap); m_atomicSync.unlock(); diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.h b/Source/WebCore/platform/graphics/android/LayerAndroid.h index fe41e35..551e020 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.h @@ -84,7 +84,7 @@ struct SkLength { namespace WebCore { class AndroidAnimation; -class BackedDoubleBufferedTexture; +class BaseTileTexture; class LayerAndroidFindState; class RenderLayer; class TiledPage; @@ -98,7 +98,7 @@ public: virtual ~LayerAndroid(); // TextureOwner methods - virtual bool removeTexture(BackedDoubleBufferedTexture* texture); + virtual bool removeTexture(BaseTileTexture* texture); LayerTexture* texture() { return m_reservedTexture; } virtual TiledPage* page() { return 0; } diff --git a/Source/WebCore/platform/graphics/android/LayerTexture.h b/Source/WebCore/platform/graphics/android/LayerTexture.h index be3594f..7a6c369 100644 --- a/Source/WebCore/platform/graphics/android/LayerTexture.h +++ b/Source/WebCore/platform/graphics/android/LayerTexture.h @@ -26,17 +26,16 @@ #ifndef LayerTexture_h #define LayerTexture_h -#include "BackedDoubleBufferedTexture.h" +#include "BaseTileTexture.h" #include "ClassTracker.h" #include "IntRect.h" namespace WebCore { -class LayerTexture : public BackedDoubleBufferedTexture { +class LayerTexture : public BaseTileTexture { public: - LayerTexture(uint32_t w, uint32_t h, - SkBitmap::Config config = SkBitmap::kARGB_8888_Config) - : BackedDoubleBufferedTexture(w, h, 0, config) + LayerTexture(uint32_t w, uint32_t h) + : BaseTileTexture(w, h) , m_layerId(0) , m_scale(1) , m_ready(false) diff --git a/Source/WebCore/platform/graphics/android/RasterRenderer.cpp b/Source/WebCore/platform/graphics/android/RasterRenderer.cpp index 04eae7c..c1fcbcb 100644 --- a/Source/WebCore/platform/graphics/android/RasterRenderer.cpp +++ b/Source/WebCore/platform/graphics/android/RasterRenderer.cpp @@ -87,7 +87,7 @@ RasterRenderer::~RasterRenderer() } void RasterRenderer::drawTileInfo(SkCanvas* canvas, - BackedDoubleBufferedTexture* texture, + BaseTileTexture* texture, TiledPage* tiledPage, int x, int y, float scale, int pictureCount) @@ -120,7 +120,7 @@ void RasterRenderer::drawTileInfo(SkCanvas* canvas, } int RasterRenderer::renderContent(int x, int y, SkIRect rect, float tx, float ty, - float scale, BackedDoubleBufferedTexture* texture, + float scale, BaseTileTexture* texture, TextureInfo* textureInfo, TiledPage* tiledPage, bool fullRepaint) { @@ -177,7 +177,7 @@ int RasterRenderer::renderContent(int x, int y, SkIRect rect, float tx, float ty if (measurePerf) m_perfMon.start(TAG_UPDATE_TEXTURE); - GLUtils::paintTextureWithBitmap(textureInfo, &bitmap, rect.fLeft, rect.fTop, texture); + GLUtils::paintTextureWithBitmap(textureInfo, texture->getSize(), bitmap, rect.fLeft, rect.fTop); if (measurePerf) m_perfMon.stop(TAG_UPDATE_TEXTURE); diff --git a/Source/WebCore/platform/graphics/android/RasterRenderer.h b/Source/WebCore/platform/graphics/android/RasterRenderer.h index 88832f6..efe1bd8 100644 --- a/Source/WebCore/platform/graphics/android/RasterRenderer.h +++ b/Source/WebCore/platform/graphics/android/RasterRenderer.h @@ -35,7 +35,7 @@ class SkCanvas; namespace WebCore { -class BackedDoubleBufferedTexture; +class BaseTileTexture; class TextureInfo; class TiledPage; @@ -48,12 +48,12 @@ public: ~RasterRenderer(); void drawTileInfo(SkCanvas* canvas, - BackedDoubleBufferedTexture* texture, + BaseTileTexture* texture, TiledPage* tiledPage, int x, int y, float scale, int pictureCount); int renderContent(int x, int y, SkIRect rect, float tx, float ty, - float scale, BackedDoubleBufferedTexture* texture, + float scale, BaseTileTexture* texture, TextureInfo* textureInfo, TiledPage* tiledPage, bool fullRepaint); diff --git a/Source/WebCore/platform/graphics/android/TextureOwner.h b/Source/WebCore/platform/graphics/android/TextureOwner.h index aebbf90..bd3a291 100644 --- a/Source/WebCore/platform/graphics/android/TextureOwner.h +++ b/Source/WebCore/platform/graphics/android/TextureOwner.h @@ -29,12 +29,12 @@ namespace WebCore { class TiledPage; -class BackedDoubleBufferedTexture; +class BaseTileTexture; class TextureOwner { public: virtual ~TextureOwner() { } - virtual bool removeTexture(BackedDoubleBufferedTexture* texture) = 0; + virtual bool removeTexture(BaseTileTexture* texture) = 0; virtual TiledPage* page() = 0; }; diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp index 0e91dc7..b4df0a1 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.cpp +++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp @@ -96,10 +96,6 @@ TilesManager::TilesManager() { XLOG("TilesManager ctor"); m_textures.reserveCapacity(MAX_TEXTURE_ALLOCATION); - m_tilesBitmap = new SkBitmap(); - m_tilesBitmap->setConfig(SkBitmap::kARGB_8888_Config, tileWidth(), tileHeight()); - m_tilesBitmap->allocPixels(); - m_tilesBitmap->eraseColor(0); m_pixmapsGenerationThread = new TexturesGenerator(); m_pixmapsGenerationThread->run("TexturesGenerator"); } @@ -110,12 +106,12 @@ void TilesManager::allocateTiles() 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); + BaseTileTexture* texture = new BaseTileTexture( + tileWidth(), tileHeight()); // 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( + BaseTileTexture* loadedTexture = + reinterpret_cast( android_atomic_acquire_load(reinterpret_cast(&texture))); m_textures.append(loadedTexture); nbTexturesAllocated++; @@ -128,7 +124,7 @@ void TilesManager::printTextures() #ifdef DEBUG XLOG("++++++"); for (unsigned int i = 0; i < m_textures.size(); i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; + BaseTileTexture* texture = m_textures[i]; BaseTile* o = 0; if (texture->owner()) o = (BaseTile*) texture->owner(); @@ -150,7 +146,7 @@ void TilesManager::resetTextureUsage(TiledPage* page) { android::Mutex::Autolock lock(m_texturesLock); for (unsigned int i = 0; i < m_textures.size(); i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; + BaseTileTexture* texture = m_textures[i]; TextureOwner* owner = texture->owner(); if (owner) { if (owner->page() == page) @@ -159,7 +155,7 @@ void TilesManager::resetTextureUsage(TiledPage* page) } } -BackedDoubleBufferedTexture* TilesManager::getAvailableTexture(BaseTile* owner) +BaseTileTexture* TilesManager::getAvailableTexture(BaseTile* owner) { android::Mutex::Autolock lock(m_texturesLock); @@ -177,11 +173,11 @@ BackedDoubleBufferedTexture* TilesManager::getAvailableTexture(BaseTile* owner) // 3. return any texture not used by the tile's page or the page's sibiling // // The texture level indicates a tiles closeness to the current viewport - BackedDoubleBufferedTexture* farthestTexture = 0; + BaseTileTexture* farthestTexture = 0; int farthestTextureLevel = 0; const unsigned int max = m_textures.size(); for (unsigned int i = 0; i < max; i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; + BaseTileTexture* texture = m_textures[i]; if (texture->usedLevel() == -1) { // found an unused texture, grab it farthestTexture = texture; break; @@ -204,7 +200,7 @@ BackedDoubleBufferedTexture* TilesManager::getAvailableTexture(BaseTile* owner) TiledPage* currentPage = owner->page(); TiledPage* nextPage = currentPage->sibling(); for (unsigned int i = 0; i < max; i++) { - BackedDoubleBufferedTexture* texture = m_textures[i]; + BaseTileTexture* texture = m_textures[i]; if (texture->tryAcquire(owner, currentPage, nextPage)) { XLOG("grab a texture that wasn't ours, (%x != %x) at %d => texture %x", owner->page(), texture->owner()->page(), i, texture); diff --git a/Source/WebCore/platform/graphics/android/TilesManager.h b/Source/WebCore/platform/graphics/android/TilesManager.h index e43afed..5237c14 100644 --- a/Source/WebCore/platform/graphics/android/TilesManager.h +++ b/Source/WebCore/platform/graphics/android/TilesManager.h @@ -28,8 +28,8 @@ #if USE(ACCELERATED_COMPOSITING) -#include "BackedDoubleBufferedTexture.h" #include "BaseTile.h" +#include "BaseTileTexture.h" #include "LayerAndroid.h" #include "LayerTexture.h" #include "ShaderProgram.h" @@ -79,7 +79,7 @@ public: ShaderProgram* shader() { return &m_shader; } VideoLayerManager* videoLayerManager() { return &m_videoLayerManager; } - BackedDoubleBufferedTexture* getAvailableTexture(BaseTile* owner); + BaseTileTexture* getAvailableTexture(BaseTile* owner); void printLayersTextures(const char* s); void cleanupLayersTextures(LayerAndroid* layer, bool forceCleanup = false); @@ -134,7 +134,7 @@ private: m_generatorReadyCond.wait(m_generatorLock); } - Vector m_textures; + Vector m_textures; Vector m_layersTextures; unsigned int m_layersMemoryUsage; @@ -156,7 +156,6 @@ private: ShaderProgram m_shader; VideoLayerManager m_videoLayerManager; - SkBitmap* m_tilesBitmap; }; } // namespace WebCore -- cgit v1.1