Bug 717283 - Store sub-tile metrics on the tile object. r=pcwalton
authorChris Lord <chrislord.net@gmail.com>
Tue, 24 Jan 2012 15:38:29 +0000
changeset 86461 2a9c391e2a8985057bb68b53a281ace0b46d67fc
parent 86460 dc059f35f32bfa25aa8f699f328926b0078721ca
child 86462 d8fc13006aa47bbf33c77905c4b0e9e354c7bc3f
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
bugs717283
milestone12.0a1
Bug 717283 - Store sub-tile metrics on the tile object. r=pcwalton Instead of deriving sub-tile metrics on each iteration, create a SingleTileLayer sub-class and store them there.
mobile/android/base/gfx/MultiTileLayer.java
--- a/mobile/android/base/gfx/MultiTileLayer.java
+++ b/mobile/android/base/gfx/MultiTileLayer.java
@@ -54,51 +54,44 @@ import javax.microedition.khronos.opengl
  * TODO: Support repeating.
  */
 public class MultiTileLayer extends Layer {
     private static final String LOGTAG = "GeckoMultiTileLayer";
 
     private final CairoImage mImage;
     private IntSize mTileSize;
     private IntSize mBufferSize;
-    private final ArrayList<SingleTileLayer> mTiles;
+    private final ArrayList<SubTile> mTiles;
 
     public MultiTileLayer(CairoImage image, IntSize tileSize) {
         super();
 
         mImage = image;
         mTileSize = tileSize;
         mBufferSize = new IntSize(0, 0);
-        mTiles = new ArrayList<SingleTileLayer>();
+        mTiles = new ArrayList<SubTile>();
     }
 
     public void invalidate(Rect dirtyRect) {
         if (!inTransaction())
             throw new RuntimeException("invalidate() is only valid inside a transaction");
 
-        int x = 0, y = 0;
-        IntSize size = getSize();
-        for (SingleTileLayer layer : mTiles) {
-            Rect tileRect = new Rect(x, y, x + mTileSize.width, y + mTileSize.height);
+        for (SubTile layer : mTiles) {
+            IntSize tileSize = layer.getSize();
+            Rect tileRect = new Rect(layer.x, layer.y, layer.x + tileSize.width, layer.y + tileSize.height);
 
             if (tileRect.intersect(dirtyRect)) {
-                tileRect.offset(-x, -y);
+                tileRect.offset(-layer.x, -layer.y);
                 layer.invalidate(tileRect);
             }
-
-            x += mTileSize.width;
-            if (x >= size.width) {
-                x = 0;
-                y += mTileSize.height;
-            }
         }
     }
 
     public void invalidate() {
-        for (SingleTileLayer layer : mTiles)
+        for (SubTile layer : mTiles)
             layer.invalidate();
     }
 
     @Override
     public IntSize getSize() {
         return mImage.getSize();
     }
 
@@ -143,17 +136,17 @@ public class MultiTileLayer extends Laye
                     }
 
                     @Override
                     public int getFormat() {
                         return format;
                     }
                 };
 
-                mTiles.add(new SingleTileLayer(subImage));
+                mTiles.add(new SubTile(subImage, x, y));
                 offset += layerSize.getArea() * bpp;
             }
         }
 
         // Set tile origins and resolution
         refreshTileMetrics(getOrigin(), getResolution(), false);
 
         mBufferSize = size;
@@ -163,18 +156,18 @@ public class MultiTileLayer extends Laye
     protected boolean performUpdates(GL10 gl, RenderContext context) {
         super.performUpdates(gl, context);
 
         validateTiles();
 
         // Iterate over the tiles and decide which ones we'll be drawing
         int dirtyTiles = 0;
         boolean screenUpdateDone = false;
-        SingleTileLayer firstDirtyTile = null;
-        for (SingleTileLayer layer : mTiles) {
+        SubTile firstDirtyTile = null;
+        for (SubTile layer : mTiles) {
             // First do a non-texture update to make sure coordinates are
             // up-to-date.
             boolean invalid = layer.getSkipTextureUpdate();
             layer.setSkipTextureUpdate(true);
             layer.performUpdates(gl, context);
 
             RectF layerBounds = layer.getBounds(context, new FloatSize(layer.getSize()));
             boolean isDirty = layer.isDirty();
@@ -211,35 +204,28 @@ public class MultiTileLayer extends Laye
             firstDirtyTile.performUpdates(gl, context);
             dirtyTiles --;
         }
 
         return (dirtyTiles == 0);
     }
 
     private void refreshTileMetrics(Point origin, float resolution, boolean inTransaction) {
-        int x = 0, y = 0;
         IntSize size = getSize();
-        for (SingleTileLayer layer : mTiles) {
+        for (SubTile layer : mTiles) {
             if (!inTransaction)
                 layer.beginTransaction(null);
 
             if (origin != null)
-                layer.setOrigin(new Point(origin.x + x, origin.y + y));
+                layer.setOrigin(new Point(origin.x + layer.x, origin.y + layer.y));
             if (resolution >= 0.0f)
                 layer.setResolution(resolution);
 
             if (!inTransaction)
                 layer.endTransaction();
-
-            x += mTileSize.width;
-            if (x >= size.width) {
-                x = 0;
-                y += mTileSize.height;
-            }
         }
     }
 
     @Override
     public void setOrigin(Point newOrigin) {
         super.setOrigin(newOrigin);
         refreshTileMetrics(newOrigin, -1, true);
     }
@@ -249,36 +235,47 @@ public class MultiTileLayer extends Laye
         super.setResolution(newResolution);
         refreshTileMetrics(null, newResolution, true);
     }
 
     @Override
     public void beginTransaction(LayerView aView) {
         super.beginTransaction(aView);
 
-        for (SingleTileLayer layer : mTiles)
+        for (SubTile layer : mTiles)
             layer.beginTransaction(aView);
     }
 
     @Override
     public void endTransaction() {
-        for (SingleTileLayer layer : mTiles)
+        for (SubTile layer : mTiles)
             layer.endTransaction();
 
         super.endTransaction();
     }
 
     @Override
     public void draw(RenderContext context) {
-        for (SingleTileLayer layer : mTiles) {
+        for (SubTile layer : mTiles) {
             // We use the SkipTextureUpdate flag as a validity flag. If it's false,
             // the contents of this tile are invalid and we shouldn't draw it.
             if (layer.getSkipTextureUpdate())
                 continue;
 
             // Avoid work, only draw tiles that intersect with the viewport
             RectF layerBounds = layer.getBounds(context, new FloatSize(layer.getSize()));
             if (RectF.intersects(layerBounds, context.viewport))
                 layer.draw(context);
         }
     }
+
+    class SubTile extends SingleTileLayer {
+        public int x;
+        public int y;
+
+        public SubTile(CairoImage mImage, int mX, int mY) {
+            super(mImage);
+            x = mX;
+            y = mY;
+        }
+    }
 }