bitmap.compress(outputStream); try { lock.writeLock().lock();
@Override protected boolean removeEldestEntry(Map.Entry<Job, TileBitmap> eldest) { if (size() > this.capacity) { TileBitmap bitmap = eldest.getValue(); if (bitmap != null) { bitmap.decrementRefCount(); } return true; } return false; }
/** * Whether the tile is stale and should be refreshed. * <p/> * This method is called from {@link #draw(BoundingBox, byte, Canvas, Point)} to determine whether the tile needs to * be refreshed. * <p/> * A tile is considered stale if one or more of the following two conditions apply: * <ul> * <li>The {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#isExpired()} method returns {@code True}.</li> * <li>The layer has a time-to-live (TTL) set ({@link #getCacheTimeToLive()} returns a nonzero value) and the sum of * the {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#getTimestamp()} and TTL is less than current * time (as returned by {@link java.lang.System#currentTimeMillis()}).</li> * </ul> * <p/> * When a tile has become stale, the layer will first display the tile referenced by {@code bitmap} and attempt to * obtain a fresh copy in the background. When a fresh copy becomes available, the layer will replace it and update * the cache. If a fresh copy cannot be obtained (e.g. because the tile is obtained from an online source which * cannot be reached), the stale tile will continue to be used until another * {@code #draw(BoundingBox, byte, Canvas, Point)} operation requests it again. * * @param tile A tile. This parameter is not used for a {@code TileDownloadLayer} and can be null. * @param bitmap The bitmap for {@code tile} currently held in the layer's cache. */ @Override protected boolean isTileStale(Tile tile, TileBitmap bitmap) { if (bitmap.isExpired()) return true; return cacheTimeToLive != 0 && ((bitmap.getTimestamp() + cacheTimeToLive) < System.currentTimeMillis()); }
@Override public synchronized void put(Job key, TileBitmap bitmap) { if (key == null) { throw new IllegalArgumentException("key must not be null"); } else if (bitmap == null) { throw new IllegalArgumentException("bitmap must not be null"); } TileBitmap old = this.lruCache.get(key); if (old != null) { old.decrementRefCount(); } if (this.lruCache.put(key, bitmap) != null) { LOGGER.warning("overwriting cached entry: " + key); } bitmap.incrementRefCount(); this.observable.notifyObservers(); }
inputStream = new FileInputStream(file); TileBitmap result = this.graphicFactory.createTileBitmap(inputStream, key.tile.tileSize, key.hasAlpha); result.setTimestamp(file.lastModified()); return result; } catch (CorruptedInputStreamException e) {
@Override public synchronized TileBitmap get(Job key) { TileBitmap bitmap = this.lruCache.get(key); if (bitmap != null) { bitmap.incrementRefCount(); } return bitmap; }
private void downloadTile(DownloadJob downloadJob) throws IOException { TileDownloader tileDownloader = new TileDownloader(downloadJob, this.graphicFactory); TileBitmap bitmap = tileDownloader.downloadImage(); if (!isInterrupted() && bitmap != null) { bitmap.scaleTo(this.displayModel.getTileSize(), this.displayModel.getTileSize()); this.tileCache.put(downloadJob, bitmap); this.layer.requestRedraw(); } } }
/** * Whether the tile is stale and should be refreshed. * <p/> * This method is called from {@link #draw(org.mapsforge.core.model.BoundingBox, byte, org.mapsforge.core.graphics.Canvas, org.mapsforge.core.model.Point)} to determine whether the tile needs to * be refreshed. * <p/> * A tile is considered stale if the timestamp of the layer's {@link #mapDataStore} is more recent than the * {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#getTimestamp()}. * <p/> * When a tile has become stale, the layer will first display the tile referenced by {@code bitmap} and attempt to * obtain a fresh copy in the background. When a fresh copy becomes available, the layer will replace is and update * the cache. If a fresh copy cannot be obtained for whatever reason, the stale tile will continue to be used until * another {@code #draw(BoundingBox, byte, Canvas, Point)} operation requests it again. * * @param tile A tile. * @param bitmap The bitmap for {@code tile} currently held in the layer's cache. */ @Override protected boolean isTileStale(Tile tile, TileBitmap bitmap) { return this.mapDataStore.getDataTimestamp(tile) > bitmap.getTimestamp(); }
TileBitmap result = this.graphicFactory.createTileBitmap(inputStream, this.downloadJob.tile.tileSize, this.downloadJob.hasAlpha); result.setExpiration(urlConnection.getExpiration()); return result; } catch (CorruptedInputStreamException e) {
@Override public synchronized void put(Job key, TileBitmap bitmap) { if (key == null) { throw new IllegalArgumentException("key must not be null"); } else if (bitmap == null) { throw new IllegalArgumentException("bitmap must not be null"); } TileBitmap old = this.lruCache.get(key); if (old != null) { old.decrementRefCount(); } if (this.lruCache.put(key, bitmap) != null) { LOGGER.warning("overwriting cached entry: " + key); } bitmap.incrementRefCount(); this.observable.notifyObservers(); }
renderContext.renderTheme.matchHillShadings(this, renderContext); bitmap = this.graphicFactory.createTileBitmap(rendererJob.tile.tileSize, rendererJob.hasAlpha); bitmap.setTimestamp(rendererJob.mapDataStore.getDataTimestamp(rendererJob.tile)); renderContext.canvasRasterer.setCanvasBitmap(bitmap); if (!rendererJob.hasAlpha && rendererJob.displayModel.getBackgroundColor() != renderContext.renderTheme.getMapBackground()) {
@Override public synchronized TileBitmap get(Job key) { TileBitmap bitmap = this.lruCache.get(key); if (bitmap != null) { bitmap.incrementRefCount(); } return bitmap; }
private void downloadTile(DownloadJob downloadJob) throws IOException { TileDownloader tileDownloader = new TileDownloader(downloadJob, this.graphicFactory); TileBitmap bitmap = tileDownloader.downloadImage(); if (!isInterrupted() && bitmap != null) { bitmap.scaleTo(this.displayModel.getTileSize(), this.displayModel.getTileSize()); this.tileCache.put(downloadJob, bitmap); this.layer.requestRedraw(); } } }
/** * Whether the tile is stale and should be refreshed. * <p/> * This method is called from {@link #draw(org.mapsforge.core.model.BoundingBox, byte, org.mapsforge.core.graphics.Canvas, org.mapsforge.core.model.Point)} to determine whether the tile needs to * be refreshed. * <p/> * A tile is considered stale if the timestamp of the layer's {@link #mapDataStore} is more recent than the * {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#getTimestamp()}. * <p/> * When a tile has become stale, the layer will first display the tile referenced by {@code bitmap} and attempt to * obtain a fresh copy in the background. When a fresh copy becomes available, the layer will replace is and update * the cache. If a fresh copy cannot be obtained for whatever reason, the stale tile will continue to be used until * another {@code #draw(BoundingBox, byte, Canvas, Point)} operation requests it again. * * @param tile A tile. * @param bitmap The bitmap for {@code tile} currently held in the layer's cache. */ @Override protected boolean isTileStale(Tile tile, TileBitmap bitmap) { return this.mapDataStore.getDataTimestamp(tile) > bitmap.getTimestamp(); }
TileBitmap result = this.graphicFactory.createTileBitmap(inputStream, this.downloadJob.tile.tileSize, this.downloadJob.hasAlpha); result.setExpiration(urlConnection.getExpiration()); return result; } catch (CorruptedInputStreamException e) {
@Override public void purge() { for (TileBitmap bitmap : this.lruCache.values()) { bitmap.decrementRefCount(); } this.lruCache.clear(); }
/** * Whether the tile is stale and should be refreshed. * <p/> * This method is called from {@link #draw(BoundingBox, byte, Canvas, Point)} to determine whether the tile needs to * be refreshed. * <p/> * A tile is considered stale if one or more of the following two conditions apply: * <ul> * <li>The {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#isExpired()} method returns {@code True}.</li> * <li>The layer has a time-to-live (TTL) set ({@link #getCacheTimeToLive()} returns a nonzero value) and the sum of * the {@code bitmap}'s {@link org.mapsforge.core.graphics.TileBitmap#getTimestamp()} and TTL is less than current * time (as returned by {@link java.lang.System#currentTimeMillis()}).</li> * </ul> * <p/> * When a tile has become stale, the layer will first display the tile referenced by {@code bitmap} and attempt to * obtain a fresh copy in the background. When a fresh copy becomes available, the layer will replace it and update * the cache. If a fresh copy cannot be obtained (e.g. because the tile is obtained from an online source which * cannot be reached), the stale tile will continue to be used until another * {@code #draw(BoundingBox, byte, Canvas, Point)} operation requests it again. * * @param tile A tile. This parameter is not used for a {@code TileDownloadLayer} and can be null. * @param bitmap The bitmap for {@code tile} currently held in the layer's cache. */ @Override protected boolean isTileStale(Tile tile, TileBitmap bitmap) { if (bitmap.isExpired()) return true; return cacheTimeToLive != 0 && ((bitmap.getTimestamp() + cacheTimeToLive) < System.currentTimeMillis()); }
renderContext.renderTheme.matchHillShadings(this, renderContext); bitmap = this.graphicFactory.createTileBitmap(rendererJob.tile.tileSize, rendererJob.hasAlpha); bitmap.setTimestamp(rendererJob.mapDataStore.getDataTimestamp(rendererJob.tile)); renderContext.canvasRasterer.setCanvasBitmap(bitmap); if (!rendererJob.hasAlpha && rendererJob.displayModel.getBackgroundColor() != renderContext.renderTheme.getMapBackground()) {
bitmap.compress(outputStream); try { lock.writeLock().lock();
jobQueue.remove(rendererJob); if (bitmap != null) { bitmap.decrementRefCount();