1package org.mozilla.gecko.gfx;
3import android.content.ComponentCallbacks2;
4import android.content.Context;
5import android.content.res.Configuration;
6import android.graphics.RectF;
7import android.graphics.Region;
8import android.util.Log;
14import java.util.ArrayList;
15import java.util.Iterator;
17import java.util.concurrent.locks.Lock;
18import java.util.concurrent.locks.ReadWriteLock;
19import java.util.concurrent.locks.ReentrantReadWriteLock;
24 protected final List<SubTile>
tiles =
new ArrayList<SubTile>();
38 context.registerComponentCallbacks(
this);
39 this.tileSize =
new IntSize(256, 256);
47 return new RectF(minX, minY, maxX, maxY);
51 RectF newRect =
new RectF(rect);
52 newRect.left -= inflateSize.
width;
53 newRect.left = newRect.left < 0.0f ? 0.0f : newRect.left;
55 newRect.top -= inflateSize.
height;
56 newRect.top = newRect.top < 0.0f ? 0.0f : newRect.top;
58 newRect.right += inflateSize.
width;
59 newRect.bottom += inflateSize.
height;
64 protected static RectF
normalizeRect(RectF rect,
float sourceFactor,
float targetFactor) {
66 (rect.left / sourceFactor) * targetFactor,
67 (rect.top / sourceFactor) * targetFactor,
68 (rect.right / sourceFactor) * targetFactor,
69 (rect.bottom / sourceFactor) * targetFactor);
82 super.beginTransaction();
85 tile.beginTransaction();
94 tile.endTransaction();
97 super.endTransaction();
104 if (RectF.intersects(tile.getBounds(context), context.
viewport)) {
113 super.performUpdates(context);
117 tile.beginTransaction();
118 tile.refreshTileMetrics();
119 tile.endTransaction();
120 tile.performUpdates(context);
127 Region validRegion =
new Region();
130 validRegion.op(tile.getValidRegion(context), Region.Op.UNION);
138 super.setResolution(newResolution);
141 tile.setResolution(newResolution);
148 float newZoom =
getZoom(viewportMetrics);
151 if (newZoom <= 0.0 ||
Float.isNaN(newZoom)) {
159 long currentReevaluationNanoTime =
System.nanoTime();
183 if (tile.id.x ==
x && tile.id.y ==
y && tile.id.zoom ==
currentZoom) {
213 Iterator<SubTile> iterator =
tiles.iterator();
214 while (iterator.hasNext()) {
215 SubTile tile = iterator.next();
228 RectF tileRect = tile.id.getRectF();
230 tile.markForRemoval();
233 tile.markForRemoval();
266 if (!tile.markedForRemoval && RectF.intersects(zoomedRect, tile.id.getRectF())) {
267 tilesToInvalidate.add(tile);
285 Log.i(
LOGTAG,
"Trimming memory - TRIM_MEMORY_RUNNING_CRITICAL");
286 }
else if (level >= 10 ) {
287 Log.i(
LOGTAG,
"Trimming memory - TRIM_MEMORY_RUNNING_LOW");
Common static LOKit functions, functions to send events.
static void sendTileReevaluationRequest(ComposedTileLayer composedTileLayer)
Send tile reevaluation to LOKitThread.
Identifies the tile by its position (x and y coordinate on the document), zoom and tile size (current...
RectF getRectF()
Returns a rectangle of the tiles position in scaled coordinates.
void beginTransaction()
Call this before modifying the layer.
final Lock tilesWriteLock
static RectF roundToTileSize(RectF input, IntSize tileSize)
final List< SubTile > tiles
void reevaluateTiles(ImmutableViewportMetrics viewportMetrics, DisplayPortMetrics mDisplayPort)
boolean isStillValid(TileIdentifier tileId)
boolean containsTilesMatching(float x, float y, float currentZoom)
static RectF normalizeRect(RectF rect, float sourceFactor, float targetFactor)
void setResolution(float newResolution)
Sets the layer resolution.
ComposedTileLayer(Context context)
void onConfigurationChanged(Configuration newConfig)
final ReadWriteLock tilesReadWriteLock
void addNewTiles(List< SubTile > newTiles)
Region getValidRegion(RenderContext context)
Returns the region of the layer that is considered valid.
void endTransaction()
Call this when you're done modifying the layer.
static final String LOGTAG
void draw(RenderContext context)
Subclasses override this function to draw the layer.
void invalidateTiles(List< SubTile > tilesToInvalidate, RectF cssRect)
Invalidate tiles which intersect the input rect.
abstract int getTilePriority()
void onTrimMemory(int level)
SubTile createNewTile(TileIdentifier tileId)
static RectF inflate(RectF rect, IntSize inflateSize)
abstract float getZoom(ImmutableViewportMetrics viewportMetrics)
abstract RectF getViewPort(ImmutableViewportMetrics viewportMetrics)
long reevaluationNanoTime
void performUpdates(RenderContext context)
Subclasses may override this method to perform custom layer updates.
ImmutableViewportMetrics are used to store the viewport metrics in way that we can access a version o...
void beginTransaction()
Call this before modifying the layer.
static RectF scale(RectF rect, float scale)
static boolean fuzzyEquals(float a, float b)
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int