OSDN Git Service

Improve performances / fixes some glitches
authorNicolas Roard <nicolasroard@google.com>
Fri, 14 Oct 2011 21:36:56 +0000 (14:36 -0700)
committerNicolas Roard <nicolasroard@google.com>
Fri, 14 Oct 2011 22:16:33 +0000 (15:16 -0700)
- 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

Source/WebCore/platform/graphics/android/GLWebViewState.cpp
Source/WebCore/platform/graphics/android/ImageTexture.cpp
Source/WebCore/platform/graphics/android/ImageTexture.h
Source/WebCore/platform/graphics/android/ImagesManager.cpp
Source/WebCore/platform/graphics/android/ImagesManager.h
Source/WebCore/platform/graphics/android/LayerAndroid.cpp
Source/WebKit/android/jni/WebViewCore.cpp
Source/WebKit/android/jni/WebViewCore.h

index 66c0370..2d7b177 100644 (file)
@@ -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);
 
index 814373c..96f7713 100644 (file)
@@ -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);
 }
index 18ff7ef..7f35f06 100644 (file)
@@ -64,6 +64,7 @@ public:
     virtual ~ImageTexture();
 
     void prepareGL();
+    void uploadGLTexture();
     void drawGL(LayerAndroid* painter);
     void drawCanvas(SkCanvas*, SkRect&);
     void retain() { m_refCount++; }
index 3518832..21f9fe9 100644 (file)
@@ -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
index 1b5d322..2fcb9fd 100644 (file)
@@ -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
index 4162e0b..4a0e2bb 100644 (file)
@@ -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
index 134408a..f35f768 100644 (file)
@@ -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)
index 491a0ad..ea57c11 100644 (file)
@@ -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; }