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.
This commit is contained in:
Chris Lord 2012-01-20 17:35:14 +00:00
Родитель c38b23d383
Коммит 8308adeb13
1 изменённых файлов: 26 добавлений и 29 удалений

Просмотреть файл

@ -59,7 +59,7 @@ public class MultiTileLayer extends Layer {
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();
@ -67,33 +67,26 @@ public class MultiTileLayer extends Layer {
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();
}
@ -148,7 +141,7 @@ public class MultiTileLayer extends Layer {
}
};
mTiles.add(new SingleTileLayer(subImage));
mTiles.add(new SubTile(subImage, x, y));
offset += layerSize.getArea() * bpp;
}
}
@ -168,8 +161,8 @@ public class MultiTileLayer extends Layer {
// 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();
@ -216,25 +209,18 @@ public class MultiTileLayer extends Layer {
}
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;
}
}
}
@ -254,13 +240,13 @@ public class MultiTileLayer extends Layer {
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();
@ -268,7 +254,7 @@ public class MultiTileLayer extends Layer {
@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())
@ -280,5 +266,16 @@ public class MultiTileLayer extends Layer {
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;
}
}
}