Back out d5496f32f2e4 for mochitest failures
authorBenoit Girard <b56girard@gmail.com>
Mon, 15 Oct 2012 16:57:06 -0400
changeset 110462 ae9e70b44f368defa198f4ba6a1712abd458b206
parent 110461 b80e81edc9f15fe93c4bdd4f4d0e93103c51400a
child 110463 2d10007609f1bcc9b8250aaebafe6997d01ed062
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
milestone19.0a1
backs outd5496f32f2e40ebf34298af22bf326d2e1c163c2
Back out d5496f32f2e4 for mochitest failures
gfx/layers/basic/BasicTiledThebesLayer.cpp
gfx/layers/opengl/ReusableTileStoreOGL.cpp
--- a/gfx/layers/basic/BasicTiledThebesLayer.cpp
+++ b/gfx/layers/basic/BasicTiledThebesLayer.cpp
@@ -258,22 +258,16 @@ BasicTiledThebesLayer::PaintThebes(gfxCo
 
   gfxSize resolution(1, 1);
   for (ContainerLayer* parent = GetParent(); parent; parent = parent->GetParent()) {
     const FrameMetrics& metrics = parent->GetFrameMetrics();
     resolution.width *= metrics.mResolution.width;
     resolution.height *= metrics.mResolution.height;
   }
 
-  // If the resolution has changed, discard all the old tiles.
-  // They will end up being retained on the shadow side by ReusableTileStoreOGL
-  if (mTiledBuffer.GetResolution() != resolution) {
-    mValidRegion = nsIntRegion();
-  }
-
   // Calculate the scroll offset since the last transaction. Progressive tile
   // painting is only used when scrolling.
   gfx::Point scrollOffset(0, 0);
   Layer* primaryScrollable = BasicManager()->GetPrimaryScrollableLayer();
   if (primaryScrollable) {
     const FrameMetrics& metrics = primaryScrollable->AsContainerLayer()->GetFrameMetrics();
     scrollOffset = metrics.mScrollOffset;
   }
--- a/gfx/layers/opengl/ReusableTileStoreOGL.cpp
+++ b/gfx/layers/opengl/ReusableTileStoreOGL.cpp
@@ -54,29 +54,43 @@ ReusableTileStoreOGL::InvalidateTiles(Ti
 
   // Iterate over existing harvested tiles and release any that are contained
   // within the new valid region, the display-port or the widget area. The
   // assumption is that anything within this area should be valid, so there's
   // no need to keep invalid tiles there.
   mContext->MakeCurrent();
   for (uint32_t i = 0; i < mTiles.Length();) {
     ReusableTiledTextureOGL* tile = mTiles[i];
+
+    // Check if the tile region is contained within the new valid region.
+    nsIntRect tileRect;
     bool release = false;
-
-    nsIntRect tileRect = tile->mTileRegion.GetBounds();
-    if (tile->mResolution != aResolution) {
+    if (tile->mResolution == aResolution) {
+      if (aValidRegion.Contains(tile->mTileRegion)) {
+        release = true;
+      } else {
+        tileRect = tile->mTileRegion.GetBounds();
+      }
+    } else {
       nsIntRegion transformedTileRegion(tile->mTileRegion);
       transformedTileRegion.ScaleRoundOut(tile->mResolution.width / aResolution.width,
                                           tile->mResolution.height / aResolution.height);
-      tileRect = transformedTileRegion.GetBounds();
+      if (aValidRegion.Contains(transformedTileRegion))
+        release = true;
+      else
+        tileRect = transformedTileRegion.GetBounds();
     }
 
-    // Check if the tile region is contained within the new valid region.
-    if (aValidRegion.Contains(tileRect)) {
-      release = true;
+    // If the tile region wasn't contained within the valid region, check if
+    // it intersects with the currently rendered region.
+    if (!release) {
+      // Transform the tile region to see if it falls inside the rendered bounds
+      gfxRect tileBounds = aLayer->GetEffectiveTransform().TransformBounds(gfxRect(tileRect));
+      if (renderBounds.Contains(tileBounds))
+        release = true;
     }
 
     if (release) {
 #ifdef GFX_TILEDLAYER_PREF_WARNINGS
       nsIntRect tileBounds = tile->mTileRegion.GetBounds();
       printf_stderr("Releasing obsolete reused tile at %d,%d, x%f\n",
                     tileBounds.x, tileBounds.y, tile->mResolution.width);
 #endif
@@ -115,30 +129,26 @@ ReusableTileStoreOGL::HarvestTiles(Tiled
   for (int x = validBounds.x; x < validBounds.XMost();) {
     int w = tileSize - aVideoMemoryTiledBuffer->GetTileStart(x);
     if (x + w > validBounds.x + validBounds.width)
       w = validBounds.x + validBounds.width - x;
 
     // A tile will consume 256^2 of memory, don't retain small tile trims.
     // This works around the display port sometimes creating a small 1 pixel wide
     // tile because of rounding error.
-    if (w < 16) {
-      x += w;
+    if (w < 16)
       continue;
-    }
 
     for (int y = validBounds.y; y < validBounds.YMost();) {
       int h = tileSize - aVideoMemoryTiledBuffer->GetTileStart(y);
       if (y + h > validBounds.y + validBounds.height)
         h = validBounds.y + validBounds.height - y;
 
-      if (h < 16) {
-        y += h;
+      if (h < 16)
         continue;
-      }
 
       // If the new valid region doesn't contain this tile region,
       // harvest the tile.
       nsIntRegion tileRegion;
       tileRegion.And(aOldValidRegion, nsIntRect(x, y, w, h));
 
       nsIntRegion intersectingRegion;
       bool retainTile = false;
@@ -151,50 +161,40 @@ ReusableTileStoreOGL::HarvestTiles(Tiled
         transformedTileRegion.ScaleRoundOut(scaleFactor.width, scaleFactor.height);
         if (!aNewValidRegion.Contains(transformedTileRegion))
           retainTile = true;
       } else if (intersectingRegion.And(tileRegion, aNewValidRegion).IsEmpty()) {
         retainTile = true;
       }
 
       if (retainTile) {
+#ifdef GFX_TILEDLAYER_PREF_WARNINGS
+        printf_stderr("Retaining tile at %d,%d, x%f for reuse\n", x, y, aOldResolution.width);
+#endif
         TiledTexture removedTile;
         if (aVideoMemoryTiledBuffer->RemoveTile(nsIntPoint(x, y), removedTile)) {
           ReusableTiledTextureOGL* reusedTile =
             new ReusableTiledTextureOGL(removedTile, nsIntPoint(x, y), tileRegion,
                                         tileSize, aOldResolution);
           mTiles.AppendElement(reusedTile);
 
-#ifdef GFX_TILEDLAYER_PREF_WARNINGS
-          bool replacedATile = false;
-#endif
           // Remove any tile that is superseded by this new tile.
           // (same resolution, same area)
           for (int i = 0; i < mTiles.Length() - 1; i++) {
             // XXX Perhaps we should check the region instead of the origin
             //     so a partial tile doesn't replace a full older tile?
             if (aVideoMemoryTiledBuffer->RoundDownToTileEdge(mTiles[i]->mTileOrigin.x) == aVideoMemoryTiledBuffer->RoundDownToTileEdge(x) &&
                 aVideoMemoryTiledBuffer->RoundDownToTileEdge(mTiles[i]->mTileOrigin.y) == aVideoMemoryTiledBuffer->RoundDownToTileEdge(y) &&
                 mTiles[i]->mResolution == aOldResolution) {
               mContext->fDeleteTextures(1, &mTiles[i]->mTexture.mTextureHandle);
               mTiles.RemoveElementAt(i);
-#ifdef GFX_TILEDLAYER_PREF_WARNINGS
-              replacedATile = true;
-#endif
               // There should only be one similar tile
               break;
             }
           }
-#ifdef GFX_TILEDLAYER_PREF_WARNINGS
-          if (replacedATile) {
-            printf_stderr("Replaced tile at %d,%d, x%f for reuse\n", x, y, aOldResolution.width);
-          } else {
-            printf_stderr("New tile at %d,%d, x%f for reuse\n", x, y, aOldResolution.width);
-          }
-#endif
         }
 #ifdef GFX_TILEDLAYER_PREF_WARNINGS
         else
           printf_stderr("Failed to retain tile for reuse\n");
 #endif
       }
 
       y += h;
@@ -213,17 +213,16 @@ ReusableTileStoreOGL::HarvestTiles(Tiled
     printf_stderr("Releasing old reused tile at %d,%d, x%f\n",
                   tileBounds.x, tileBounds.y, mTiles[0]->mResolution.width);
 #endif
     mContext->fDeleteTextures(1, &mTiles[0]->mTexture.mTextureHandle);
     mTiles.RemoveElementAt(0);
   }
 
 #ifdef GFX_TILEDLAYER_PREF_WARNINGS
-  printf_stderr("Retained tile limit: %f\n", aVideoMemoryTiledBuffer->GetTileCount() * mSizeLimit);
   printf_stderr("Retained %d tiles\n", mTiles.Length());
 #endif
 }
 
 void
 ReusableTileStoreOGL::DrawTiles(TiledThebesLayerOGL* aLayer,
                                 const nsIntRegion& aValidRegion,
                                 const gfxSize& aResolution,
@@ -270,17 +269,16 @@ ReusableTileStoreOGL::DrawTiles(TiledThe
                                   aResolution.height / tile->mResolution.height);
 
     // Reconcile the resolution difference by adjusting the transform.
     gfx3DMatrix transform = aTransform;
     if (aResolution != tile->mResolution)
       transform.Scale(scaleFactor.width, scaleFactor.height, 1);
 
     // Subtract the layer's valid region from the tile region.
-    // This region will be drawn by the layer itself.
     nsIntRegion transformedValidRegion(aValidRegion);
     if (aResolution != tile->mResolution)
       transformedValidRegion.ScaleRoundOut(1.0f/scaleFactor.width,
                                            1.0f/scaleFactor.height);
     nsIntRegion tileRegion;
     tileRegion.Sub(tile->mTileRegion, transformedValidRegion);
 
     // Subtract the display-port from the tile region.