diff options
author | Nicolas Roard <nicolasroard@google.com> | 2011-10-14 14:36:56 -0700 |
---|---|---|
committer | Nicolas Roard <nicolasroard@google.com> | 2011-10-14 15:16:33 -0700 |
commit | 7eb15a6b569f79bfddb934615640fd6275218377 (patch) | |
tree | 24fe93822190ec16b84a6c5dd689012b6a6706bc | |
parent | 4520f40c217eca38e19654c0d5e7c987ab07bb9a (diff) | |
download | external_webkit-7eb15a6b569f79bfddb934615640fd6275218377.zip external_webkit-7eb15a6b569f79bfddb934615640fd6275218377.tar.gz external_webkit-7eb15a6b569f79bfddb934615640fd6275218377.tar.bz2 |
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
8 files changed, 58 insertions, 10 deletions
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<SkBitmapRef*, ImageTexture*> m_images; + Vector<ImageTexture*> 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<RenderStyle> 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; } |