private void setKeepRect(final Rect keepRect) { // Drop tiles outside the new keepRect. RectF keepRectF = keepRect.toRectF(); List<Coordinate> toRemove = new ArrayList<Coordinate>(); ; Iterator<Entry<Coordinate, ITile>> it = mMainTiles.iterator(); while (it.hasNext()) { Entry<Coordinate, ITile> entry = it.next(); Coordinate coordinate = entry.getValue().coordinate(); RectF tileRect = entry.getValue().rect().toRectF(); if (!tileRect.intersectsWith(keepRectF)) toRemove.add(coordinate); } int removeCount = toRemove.size(); for (int n = 0; n < removeCount; ++n) removeTile(toRemove.get(n)); keepRect.copyTo(mKeepRect); }
private boolean resizeEdgeTiles() { boolean wasResized = false; List<Coordinate> tilesToRemove = new ArrayList<Coordinate>(); Iterator<Entry<Coordinate, ITile>> it = mMainTiles.iterator(); while (it.hasNext()) { Entry<Coordinate, ITile> entry = it.next(); Coordinate tileCoordinate = entry.getValue().coordinate(); Rect tileRect = entry.getValue().rect(); Rect expectedTileRect = tileRectForCoordinate(tileCoordinate); if (expectedTileRect.isEmpty()) tilesToRemove.add(tileCoordinate); else if (!expectedTileRect.equals(tileRect)) { entry.getValue().resize(expectedTileRect.getWidth(), expectedTileRect.getHeight()); wasResized = true; } } int removeCount = tilesToRemove.size(); for (int n = 0; n < removeCount; ++n) removeTile(tilesToRemove.get(n)); return wasResized; }
private void updateTileBuffers(BSTimerTask task) { if (mContentsFrozen) return; mUpdateFlowBreaked = false; mClient.tbsPaintBegin(); List<Rect> paintedArea = new ArrayList<Rect>(); List<ITile> dirtyTiles = new ArrayList<ITile>(); Iterator<Entry<Coordinate, ITile>> it = mMainTiles.iterator(); while (it.hasNext()) { Entry<Coordinate, ITile> entry = it.next(); if (!entry.getValue().isDirty()) continue; dirtyTiles.add(entry.getValue()); } if (dirtyTiles.isEmpty()) { mClient.tbsPaintEnd(paintedArea); return; } // FIXME: In single threaded case, tile back buffers could be updated asynchronously // one by one and then swapped to front in one go. This would minimize the time spent // blocking on tile updates. int size = dirtyTiles.size(); for (int n = 0; n < size; ++n) { Collection<Rect> paintedRects = dirtyTiles.get(n).updateBackBuffer(); paintedArea.addAll(paintedRects); dirtyTiles.get(n).swapBackBufferToFront(); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } if (task != null && task.cancelled()) { mUpdateFlowBreaked = true; break; } } mClient.tbsPaintEnd(paintedArea); }
public void paint(GLCanvas canvas, int offsetX, int offsetY, final Rect rect) { synchronized (mScaleBufferTiles) { Iterator<Entry<Coordinate, ITile>> it = mScaleBufferTiles.iterator(); while (it.hasNext()) { Entry<Coordinate, ITile> entry = it.next(); ITile currentTile = entry.getValue(); if (currentTile != null && currentTile.isReadyToPaint()) { float scale = mPendingScale == 0 ? mContentsScale : mPendingScale; currentTile.paint(canvas, offsetX, offsetY, null, scale / mScaleBufferTiles.getScale()); } } } Rect dirtyRect = mapFromContents(rect, mScaleBufferTiles.getScale()); Coordinate topLeft = tileCoordinateForPoint(dirtyRect.getLeft(), dirtyRect.getTop()); Coordinate bottomRight = tileCoordinateForPoint(dirtyRect.getRight(), dirtyRect.getBottom()); // for (int yCoordinate = topLeft.getY(); yCoordinate <= bottomRight.getY(); // ++yCoordinate) { // for (int xCoordinate = topLeft.getX(); xCoordinate <= bottomRight.getX(); // ++xCoordinate) { // Coordinate currentCoordinate = new Coordinate(xCoordinate, yCoordinate); // ITile currentTile = mScaleBufferTiles.get(currentCoordinate); // if (currentTile != null && currentTile.isReadyToPaint()) { // currentTile.paint(canvas, offsetX, offsetY, dirtyRect, mPendingScale / // mScaleBufferTiles.getScale()); // } else { // Rect tileRect = tileRectForCoordinate(currentCoordinate); // Rect target = Rect.intersect(tileRect, dirtyRect); // if (target == null || target.isEmpty()) // continue; // //// float scaleFactor = mOldScale == 0 ? 1 : mContentsScale / mOldScale; //// float left = offsetX + target.getLeft() * scaleFactor; //// float top = offsetY + target.getTop() * scaleFactor; //// float width = target.getWidth() * scaleFactor; //// float height = target.getHeight() * scaleFactor; // // canvas.drawTexture(mTextureBuffer.getCheckerTextureID(canvas.getGL(), // (int)width, (int)height), left, top, width, height); // } // // } // } dirtyRect = mapFromContents(rect); topLeft = tileCoordinateForPoint(dirtyRect.getLeft(), dirtyRect.getTop()); bottomRight = tileCoordinateForPoint(dirtyRect.getRight(), dirtyRect.getBottom()); for (int yCoordinate = topLeft.getY(); yCoordinate <= bottomRight.getY(); ++yCoordinate) { for (int xCoordinate = topLeft.getX(); xCoordinate <= bottomRight.getX(); ++xCoordinate) { Coordinate currentCoordinate = new Coordinate(xCoordinate, yCoordinate); ITile currentTile = mMainTiles.get(currentCoordinate); if (currentTile != null && currentTile.isReadyToPaint()) { float scaleFactor = mPendingScale == 0 ? 1 : mPendingScale / mContentsScale; currentTile.paint(canvas, offsetX, offsetY, dirtyRect, scaleFactor); } else { Rect tileRect = tileRectForCoordinate(currentCoordinate); Rect target = Rect.intersect(tileRect, dirtyRect); if (target == null || target.isEmpty()) continue; float scaleFactor = mPendingScale == 0 ? 1 : mPendingScale / mContentsScale; float left = offsetX + target.getLeft() * scaleFactor; float top = offsetY + target.getTop() * scaleFactor; float width = target.getWidth() * scaleFactor; float height = target.getHeight() * scaleFactor; // // canvas.drawTexture(mTextureBuffer.getCheckerTextureID(canvas.getGL(), (int)width, // (int)height), left, top, width, height); } } } }