OSDN Git Service

Fix the flickering bug. We return any previous textures used by the
authorNicolas Roard <nicolas@android.com>
Wed, 26 Jan 2011 22:46:30 +0000 (14:46 -0800)
committerNicolas Roard <nicolas@android.com>
Wed, 26 Jan 2011 22:46:30 +0000 (14:46 -0800)
layer until we get the new one ready.

bug:3391157 bug:3393571
Change-Id: I81dce23f79be788c3c0bfb0ccfd54d08156dfe3f

WebCore/platform/graphics/android/LayerAndroid.cpp
WebCore/platform/graphics/android/LayerTexture.h
WebCore/platform/graphics/android/TilesManager.cpp
WebCore/platform/graphics/android/TilesManager.h

index 03bb11d..77a948a 100644 (file)
@@ -77,7 +77,7 @@ LayerAndroid::LayerAndroid(bool isRootLayer) : SkLayer(),
     m_uniqueId(++gUniqueId),
     m_drawingTexture(0),
     m_reservedTexture(0),
-    m_pictureUsed(-1),
+    m_pictureUsed(0),
     m_requestSent(false),
     m_scale(1)
 {
@@ -594,12 +594,20 @@ void LayerAndroid::reserveGLTextures()
         IntRect cr = TilesManager::instance()->shader()->clippedRectWithViewport(tr);
         m_layerTextureRect = drawTransform().inverse().mapRect(cr);
 
-        reservedTexture = TilesManager::instance()->getExistingTextureForLayer(this, m_layerTextureRect);
+        reservedTexture = TilesManager::instance()->getExistingTextureForLayer(
+            this, m_layerTextureRect);
 
         // If we do not have a drawing texture (i.e. new LayerAndroid tree),
         // we get any one available.
-        if (!m_drawingTexture)
-            m_drawingTexture = TilesManager::instance()->getExistingTextureForLayer(this, m_layerTextureRect, true);
+        if (!m_drawingTexture) {
+            LayerTexture* texture = reservedTexture;
+            m_drawingTexture =
+                TilesManager::instance()->getExistingTextureForLayer(
+                    this, m_layerTextureRect, true, texture);
+
+            if (!m_drawingTexture)
+                m_drawingTexture = reservedTexture;
+        }
     }
 
     // SMP flush
@@ -636,6 +644,7 @@ void LayerAndroid::createGLTextures()
     m_atomicSync.unlock();
 
     if (reservedTexture &&
+        reservedTexture->ready() &&
         (reservedTexture != m_drawingTexture)) {
         if (m_drawingTexture) {
             TilesManager::instance()->removeOperationsForTexture(m_drawingTexture);
@@ -668,13 +677,10 @@ bool LayerAndroid::needsScheduleRepaint(LayerTexture* texture)
     if (!texture)
         return false;
 
-    if (m_pictureUsed == -1 ||
-        texture->pictureUsed() == -1 ||
+    if (!texture->ready() ||
         texture->pictureUsed() != m_pictureUsed) {
         XLOG("We mark layer %d (%x) as dirty because: m_pictureUsed(%d == 0?), texture picture used %x",
              uniqueId(), this, m_pictureUsed, texture->pictureUsed());
-        if (m_pictureUsed == -1)
-            m_pictureUsed = 0;
         m_dirty = true;
     }
 
@@ -705,8 +711,10 @@ bool LayerAndroid::drawGL(SkMatrix& matrix)
             // move the drawing depending on where the texture is on the layer
             TransformationMatrix m = drawTransform();
             m.translate(textureRect.x(), textureRect.y());
-            XLOG("LayerAndroid %d %x (%.2f, %.2f) drawGL (texture %x, %d, %d, %d, %d)", uniqueId(), this, getWidth(), getHeight(),
-                 m_drawingTexture, textureRect.x(), textureRect.y(), textureRect.width(), textureRect.height());
+            XLOG("LayerAndroid %d %x (%.2f, %.2f) drawGL (texture %x, %d, %d, %d, %d)",
+                 uniqueId(), this, getWidth(), getHeight(),
+                 m_drawingTexture, textureRect.x(), textureRect.y(),
+                 textureRect.width(), textureRect.height());
             TilesManager::instance()->shader()->drawLayerQuad(m, bounds,
                                                               textureInfo->m_textureId,
                                                               m_drawOpacity);
@@ -768,7 +776,7 @@ void LayerAndroid::paintBitmapGL()
         return;
     }
 
-    XLOG("LayerAndroid paintBitmapGL (layer %d), texture used %x (%d, %d)", uniqueId(), texture,
+    XLOG("LayerAndroid %d paintBitmapGL, texture used %x (%d, %d)", uniqueId(), texture,
          texture->rect().width(), texture->rect().height());
 
     // We need to mark the texture as busy before relinquishing the lock
@@ -805,12 +813,13 @@ void LayerAndroid::paintBitmapGL()
     m_atomicSync.lock();
     m_dirty = false;
     m_requestSent = false;
-    texture->setPictureUsed(m_pictureUsed);
-    m_atomicSync.unlock();
 
     XLOG("LayerAndroid %d paintBitmapGL PAINTING DONE, updating the texture", uniqueId());
     texture->producerUpdate(textureInfo);
 
+    texture->setPictureUsed(m_pictureUsed);
+    m_atomicSync.unlock();
+
     XLOG("LayerAndroid %d paintBitmapGL UPDATING DONE", uniqueId());
 }
 
index fb1b9fb..042422d 100644 (file)
@@ -38,15 +38,22 @@ class LayerTexture : public BackedDoubleBufferedTexture {
         : BackedDoubleBufferedTexture(w, h, config)
         , m_id(0)
         , m_scale(1)
-        , m_pictureUsed(-1)
+        , m_pictureUsed(0)
+        , m_ready(false)
     {}
     virtual ~LayerTexture() {};
 
     int id() { return m_id; }
     void setId(int id) { m_id = id; }
+    bool ready() { return m_ready; }
 
     unsigned int pictureUsed() { return m_pictureUsed; }
-    void setPictureUsed(unsigned pictureUsed) { m_pictureUsed = pictureUsed; }
+    void setPictureUsed(unsigned pictureUsed)
+    {
+          if (!m_ready)
+              m_ready = true;
+          m_pictureUsed = pictureUsed;
+    }
     void setRect(const IntRect& r) { m_rect = r; }
     IntRect& rect() { return m_rect; }
     float scale() { return m_scale; }
@@ -58,6 +65,7 @@ class LayerTexture : public BackedDoubleBufferedTexture {
     IntRect m_rect;
     float m_scale;
     unsigned int m_pictureUsed;
+    bool m_ready;
 };
 
 } // namespace WebCore
index 1655016..16282c4 100644 (file)
@@ -80,7 +80,7 @@ TilesManager::TilesManager()
         m_textures.append(reinterpret_cast<BackedDoubleBufferedTexture*>(
             android_atomic_acquire_load(reinterpret_cast<int32_t*>(&texture))));
     }
-    XLOG("TilesManager ctor");
+    XLOG("TilesManager ctor - init textures done");
 
     m_pixmapsGenerationThread = new TexturesGenerator();
     m_pixmapsGenerationThread->run("TexturesGenerator");
@@ -232,7 +232,8 @@ BackedDoubleBufferedTexture* TilesManager::getAvailableTexture(BaseTile* owner)
 
 LayerTexture* TilesManager::getExistingTextureForLayer(LayerAndroid* layer,
                                                        const IntRect& rect,
-                                                       bool any)
+                                                       bool any,
+                                                       LayerTexture* texture)
 {
     android::Mutex::Autolock lock(m_texturesLock);
     for (unsigned int i = 0; i< m_layersTextures.size(); i++) {
@@ -242,6 +243,8 @@ LayerTexture* TilesManager::getExistingTextureForLayer(LayerAndroid* layer,
             continue;
         if (!any && layer->getScale() != m_layersTextures[i]->scale())
             continue;
+        if (any && texture == m_layersTextures[i])
+            continue;
 
         XLOG("return layer %d (%x) for tile %d (%x)",
              i, m_layersTextures[i],
index c09a388..0338ece 100644 (file)
@@ -72,7 +72,7 @@ public:
     void printLayersTextures(const char* s);
     void cleanupLayersTextures(LayerAndroid* layer, bool forceCleanup = false);
     LayerTexture* getExistingTextureForLayer(LayerAndroid* layer, const IntRect& rect,
-                                             bool any = false);
+                                             bool any = false, LayerTexture* texture = 0);
     LayerTexture* createTextureForLayer(LayerAndroid* layer, const IntRect& rect);
 
     void markGeneratorAsReady()