From 7eb15a6b569f79bfddb934615640fd6275218377 Mon Sep 17 00:00:00 2001 From: Nicolas Roard Date: Fri, 14 Oct 2011 14:36:56 -0700 Subject: Improve performances / fixes some glitches - no layout / bgd color check if no inval on the base layer - throttle the number of ImageTexture uploaded per draw call - disable fast layer position update for now bug:5297559 bug:5421309 bug:5218173 Change-Id: I9ff9867dd3cfc2e0805e378d75ea75667fef8673 --- .../platform/graphics/android/GLWebViewState.cpp | 8 +++++++- .../platform/graphics/android/ImageTexture.cpp | 9 +++++++++ .../platform/graphics/android/ImageTexture.h | 1 + .../platform/graphics/android/ImagesManager.cpp | 21 +++++++++++++++++++++ .../platform/graphics/android/ImagesManager.h | 4 ++++ .../platform/graphics/android/LayerAndroid.cpp | 5 +++++ Source/WebKit/android/jni/WebViewCore.cpp | 18 ++++++++++-------- Source/WebKit/android/jni/WebViewCore.h | 2 +- 8 files changed, 58 insertions(+), 10 deletions(-) (limited to 'Source') diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp index 66c0370..2d7b177 100644 --- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp +++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp @@ -31,6 +31,7 @@ #include "BaseLayerAndroid.h" #include "ClassTracker.h" #include "GLUtils.h" +#include "ImagesManager.h" #include "LayerAndroid.h" #include "SkPath.h" #include "TilesManager.h" @@ -447,6 +448,11 @@ bool GLWebViewState::drawGL(IntRect& rect, SkRect& viewport, IntRect* invalRect, // the BaseTiles' texture. TilesManager::instance()->transferQueue()->updateDirtyBaseTiles(); + // Upload any pending ImageTexture + // Return true if we still have some images to upload. + // TODO: upload as many textures as possible within a certain time limit + bool ret = ImagesManager::instance()->uploadTextures(); + if (scale < MIN_SCALE_WARNING || scale > MAX_SCALE_WARNING) XLOGC("WARNING, scale seems corrupted after update: %e", scale); @@ -459,7 +465,7 @@ bool GLWebViewState::drawGL(IntRect& rect, SkRect& viewport, IntRect* invalRect, // set up zoom manager, shaders, etc. m_backgroundColor = baseLayer->getBackgroundColor(); double currentTime = setupDrawing(rect, viewport, webViewRect, titleBarHeight, clip, scale); - bool ret = baseLayer->drawGL(currentTime, compositedRoot, rect, + ret |= baseLayer->drawGL(currentTime, compositedRoot, rect, viewport, scale, buffersSwappedPtr); m_glExtras.drawGL(webViewRect, viewport, titleBarHeight); diff --git a/Source/WebCore/platform/graphics/android/ImageTexture.cpp b/Source/WebCore/platform/graphics/android/ImageTexture.cpp index 814373c..96f7713 100644 --- a/Source/WebCore/platform/graphics/android/ImageTexture.cpp +++ b/Source/WebCore/platform/graphics/android/ImageTexture.cpp @@ -26,6 +26,7 @@ #include "config.h" #include "ImageTexture.h" +#include "ImagesManager.h" #include "SkDevice.h" #include "TilesManager.h" @@ -92,6 +93,14 @@ void ImageTexture::prepareGL() if (m_textureId) return; + ImagesManager::instance()->scheduleTextureUpload(this); +} + +void ImageTexture::uploadGLTexture() +{ + if (m_textureId) + return; + glGenTextures(1, &m_textureId); GLUtils::createTextureWithBitmap(m_textureId, *m_image); } diff --git a/Source/WebCore/platform/graphics/android/ImageTexture.h b/Source/WebCore/platform/graphics/android/ImageTexture.h index 18ff7ef..7f35f06 100644 --- a/Source/WebCore/platform/graphics/android/ImageTexture.h +++ b/Source/WebCore/platform/graphics/android/ImageTexture.h @@ -64,6 +64,7 @@ public: virtual ~ImageTexture(); void prepareGL(); + void uploadGLTexture(); void drawGL(LayerAndroid* painter); void drawCanvas(SkCanvas*, SkRect&); void retain() { m_refCount++; } diff --git a/Source/WebCore/platform/graphics/android/ImagesManager.cpp b/Source/WebCore/platform/graphics/android/ImagesManager.cpp index 3518832..21f9fe9 100644 --- a/Source/WebCore/platform/graphics/android/ImagesManager.cpp +++ b/Source/WebCore/platform/graphics/android/ImagesManager.cpp @@ -105,4 +105,25 @@ ImageTexture* ImagesManager::getTextureForImage(SkBitmapRef* img, bool retain) return image; } +void ImagesManager::scheduleTextureUpload(ImageTexture* texture) +{ + if (m_imagesToUpload.contains(texture)) + return; + + texture->retain(); + m_imagesToUpload.append(texture); +} + +bool ImagesManager::uploadTextures() +{ + // scheduleUpload and uploadTextures are called on the same thread + if (!m_imagesToUpload.size()) + return false; + ImageTexture* texture = m_imagesToUpload.last(); + texture->uploadGLTexture(); + m_imagesToUpload.removeLast(); + removeImage(texture->imageRef()); + return m_imagesToUpload.size(); +} + } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/ImagesManager.h b/Source/WebCore/platform/graphics/android/ImagesManager.h index 1b5d322..2fcb9fd 100644 --- a/Source/WebCore/platform/graphics/android/ImagesManager.h +++ b/Source/WebCore/platform/graphics/android/ImagesManager.h @@ -30,6 +30,7 @@ #include "SkBitmap.h" #include "SkBitmapRef.h" #include "SkRefCnt.h" +#include "Vector.h" namespace WebCore { @@ -43,6 +44,8 @@ public: void removeImage(SkBitmapRef* img); ImageTexture* getTextureForImage(SkBitmapRef* img, bool retain = true); void showImages(); + void scheduleTextureUpload(ImageTexture* texture); + bool uploadTextures(); private: ImagesManager() {} @@ -51,6 +54,7 @@ private: android::Mutex m_imagesLock; HashMap m_images; + Vector m_imagesToUpload; }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp index 4162e0b..4a0e2bb 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -768,6 +768,8 @@ void LayerAndroid::assignTextureTo(LayerAndroid* newTree) bool LayerAndroid::updateWithTree(LayerAndroid* newTree) { +// Disable fast update for now +#if (0) bool needsRepaint = false; int count = this->countChildren(); for (int i = 0; i < count; i++) @@ -778,6 +780,9 @@ bool LayerAndroid::updateWithTree(LayerAndroid* newTree) needsRepaint |= updateWithLayer(newLayer); } return needsRepaint; +#else + return true; +#endif } // Return true to indicate to WebViewCore that the updates diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index 134408a..f35f768 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -945,20 +945,22 @@ bool WebViewCore::updateLayers(LayerAndroid* layers) return true; } -BaseLayerAndroid* WebViewCore::createBaseLayer() +BaseLayerAndroid* WebViewCore::createBaseLayer(SkRegion* region) { BaseLayerAndroid* base = new BaseLayerAndroid(); base->setContent(m_content); - m_skipContentDraw = true; - bool layoutSucceeded = layoutIfNeededRecursive(m_mainFrame); - m_skipContentDraw = false; - // Layout only fails if called during a layout. - LOG_ASSERT(layoutSucceeded, "Can never be called recursively"); + if (!region->isEmpty()) { + m_skipContentDraw = true; + bool layoutSucceeded = layoutIfNeededRecursive(m_mainFrame); + m_skipContentDraw = false; + // Layout only fails if called during a layout. + LOG_ASSERT(layoutSucceeded, "Can never be called recursively"); + } #if USE(ACCELERATED_COMPOSITING) // We set the background color - if (m_mainFrame && m_mainFrame->document() + if (!region->isEmpty() && m_mainFrame && m_mainFrame->document() && m_mainFrame->document()->body()) { Document* document = m_mainFrame->document(); RefPtr style = document->styleForElementIgnoringPendingStylesheets(document->body()); @@ -1013,7 +1015,7 @@ BaseLayerAndroid* WebViewCore::recordContent(SkRegion* region, SkIPoint* point) region->getBounds().fBottom); DBG_SET_LOG("end"); - return createBaseLayer(); + return createBaseLayer(region); } void WebViewCore::splitContent(PictureSet* content) diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index 491a0ad..ea57c11 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -527,7 +527,7 @@ namespace android { // This creates a new BaseLayerAndroid by copying the current m_content // and doing a copy of the layers. The layers' content may be updated // as we are calling layersSync(). - BaseLayerAndroid* createBaseLayer(); + BaseLayerAndroid* createBaseLayer(SkRegion*); bool updateLayers(LayerAndroid*); int textWrapWidth() const { return m_textWrapWidth; } -- cgit v1.1