Commit cc270077 authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] BitmapState

This CL moves bitmap request logic from PlayerFrameMediator to
PlayerFrameBitmapState. This is mostly a mechanical change just moving
code.

Bug: 1099722
Change-Id: Iddedf83510bd715b18f3b5e393099721db33b69e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2292895
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Reviewed-by: default avatarFred Mello <fredmello@chromium.org>
Reviewed-by: default avatarMehran Mahmoudi <mahmoudi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787827}
parent 5cbbc35e
...@@ -55,6 +55,7 @@ android_library("java") { ...@@ -55,6 +55,7 @@ android_library("java") {
"java/src/org/chromium/components/paintpreview/player/PlayerManager.java", "java/src/org/chromium/components/paintpreview/player/PlayerManager.java",
"java/src/org/chromium/components/paintpreview/player/PlayerSwipeRefreshHandler.java", "java/src/org/chromium/components/paintpreview/player/PlayerSwipeRefreshHandler.java",
"java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameBitmapPainter.java", "java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameBitmapPainter.java",
"java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameBitmapState.java",
"java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameCoordinator.java", "java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameCoordinator.java",
"java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameGestureDetector.java", "java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameGestureDetector.java",
"java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameMediator.java", "java/src/org/chromium/components/paintpreview/player/frame/PlayerFrameMediator.java",
......
...@@ -7,6 +7,7 @@ package org.chromium.components.paintpreview.player.frame; ...@@ -7,6 +7,7 @@ package org.chromium.components.paintpreview.player.frame;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Size;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
...@@ -15,8 +16,7 @@ import javax.annotation.Nonnull; ...@@ -15,8 +16,7 @@ import javax.annotation.Nonnull;
* on a {@link Canvas}. * on a {@link Canvas}.
*/ */
class PlayerFrameBitmapPainter { class PlayerFrameBitmapPainter {
private int mTileWidth; private Size mTileSize;
private int mTileHeight;
private Bitmap[][] mBitmapMatrix; private Bitmap[][] mBitmapMatrix;
private Rect mViewPort = new Rect(); private Rect mViewPort = new Rect();
private Rect mDrawBitmapSrc = new Rect(); private Rect mDrawBitmapSrc = new Rect();
...@@ -27,9 +27,8 @@ class PlayerFrameBitmapPainter { ...@@ -27,9 +27,8 @@ class PlayerFrameBitmapPainter {
mInvalidateCallback = invalidateCallback; mInvalidateCallback = invalidateCallback;
} }
void updateTileDimensions(int[] tileDimensions) { void updateTileDimensions(Size tileDimensions) {
mTileWidth = tileDimensions[0]; mTileSize = tileDimensions;
mTileHeight = tileDimensions[1];
} }
void updateViewPort(int left, int top, int right, int bottom) { void updateViewPort(int left, int top, int right, int bottom) {
...@@ -50,12 +49,12 @@ class PlayerFrameBitmapPainter { ...@@ -50,12 +49,12 @@ class PlayerFrameBitmapPainter {
if (mViewPort.isEmpty()) return; if (mViewPort.isEmpty()) return;
if (mTileWidth <= 0 || mTileHeight <= 0) return; if (mTileSize.getWidth() <= 0 || mTileSize.getHeight() <= 0) return;
final int rowStart = mViewPort.top / mTileHeight; final int rowStart = mViewPort.top / mTileSize.getHeight();
final int rowEnd = (int) Math.ceil((double) mViewPort.bottom / mTileHeight); final int rowEnd = (int) Math.ceil((double) mViewPort.bottom / mTileSize.getHeight());
final int colStart = mViewPort.left / mTileWidth; final int colStart = mViewPort.left / mTileSize.getWidth();
final int colEnd = (int) Math.ceil((double) mViewPort.right / mTileWidth); final int colEnd = (int) Math.ceil((double) mViewPort.right / mTileSize.getWidth());
if (rowEnd > mBitmapMatrix.length || colEnd > mBitmapMatrix[rowEnd - 1].length) { if (rowEnd > mBitmapMatrix.length || colEnd > mBitmapMatrix[rowEnd - 1].length) {
return; return;
} }
...@@ -68,17 +67,17 @@ class PlayerFrameBitmapPainter { ...@@ -68,17 +67,17 @@ class PlayerFrameBitmapPainter {
} }
// Calculate the portion of this tileBitmap that is visible in mViewPort. // Calculate the portion of this tileBitmap that is visible in mViewPort.
int bitmapLeft = Math.max(mViewPort.left - (col * mTileWidth), 0); int bitmapLeft = Math.max(mViewPort.left - (col * mTileSize.getWidth()), 0);
int bitmapTop = Math.max(mViewPort.top - (row * mTileHeight), 0); int bitmapTop = Math.max(mViewPort.top - (row * mTileSize.getHeight()), 0);
int bitmapRight = int bitmapRight = Math.min(mTileSize.getWidth(),
Math.min(mTileWidth, bitmapLeft + mViewPort.right - (col * mTileWidth)); bitmapLeft + mViewPort.right - (col * mTileSize.getWidth()));
int bitmapBottom = int bitmapBottom = Math.min(mTileSize.getHeight(),
Math.min(mTileHeight, bitmapTop + mViewPort.bottom - (row * mTileHeight)); bitmapTop + mViewPort.bottom - (row * mTileSize.getHeight()));
mDrawBitmapSrc.set(bitmapLeft, bitmapTop, bitmapRight, bitmapBottom); mDrawBitmapSrc.set(bitmapLeft, bitmapTop, bitmapRight, bitmapBottom);
// Calculate the portion of the canvas that tileBitmap is gonna be drawn on. // Calculate the portion of the canvas that tileBitmap is gonna be drawn on.
int canvasLeft = Math.max((col * mTileWidth) - mViewPort.left, 0); int canvasLeft = Math.max((col * mTileSize.getWidth()) - mViewPort.left, 0);
int canvasTop = Math.max((row * mTileHeight) - mViewPort.top, 0); int canvasTop = Math.max((row * mTileSize.getHeight()) - mViewPort.top, 0);
int canvasRight = canvasLeft + mDrawBitmapSrc.width(); int canvasRight = canvasLeft + mDrawBitmapSrc.width();
int canvasBottom = canvasTop + mDrawBitmapSrc.height(); int canvasBottom = canvasTop + mDrawBitmapSrc.height();
mDrawBitmapDst.set(canvasLeft, canvasTop, canvasRight, canvasBottom); mDrawBitmapDst.set(canvasLeft, canvasTop, canvasRight, canvasBottom);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.paintpreview.player.frame;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.Size;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.Callback;
import org.chromium.base.UnguessableToken;
import org.chromium.components.paintpreview.player.PlayerCompositorDelegate;
/**
* Manages the bitmaps shown in the PlayerFrameView at a given scale factor.
*/
public class PlayerFrameBitmapState {
private final UnguessableToken mGuid;
/** Dimension of tiles. */
private final Size mTileSize;
/** The scale factor of bitmaps. */
private float mScaleFactor;
/** Bitmaps that make up the contents. */
private Bitmap[][] mBitmapMatrix;
/** Whether a request for a bitmap tile is pending. */
private boolean[][] mPendingBitmapRequests;
/**
* Whether we currently need a bitmap tile. This is used for deleting bitmaps that we don't
* need and freeing up memory.
*/
@VisibleForTesting
boolean[][] mRequiredBitmaps;
/** Delegate for accessing native to request bitmaps. */
private final PlayerCompositorDelegate mCompositorDelegate;
private final PlayerFrameMediatorDelegate mMediatorDelegate;
PlayerFrameBitmapState(UnguessableToken guid, int tileWidth, int tileHeight, float scaleFactor,
Size contentSize, PlayerCompositorDelegate compositorDelegate,
PlayerFrameMediatorDelegate mediatorDelegate) {
mGuid = guid;
mTileSize = new Size(tileWidth, tileHeight);
mScaleFactor = scaleFactor;
mCompositorDelegate = compositorDelegate;
mMediatorDelegate = mediatorDelegate;
// Each tile is as big as the initial view port. Here we determine the number of
// columns and rows for the current scale factor.
int rows = (int) Math.ceil((contentSize.getHeight() * scaleFactor) / tileHeight);
int cols = (int) Math.ceil((contentSize.getWidth() * scaleFactor) / tileWidth);
mBitmapMatrix = new Bitmap[rows][cols];
mPendingBitmapRequests = new boolean[rows][cols];
mRequiredBitmaps = new boolean[rows][cols];
}
Bitmap[][] getMatrix() {
return mBitmapMatrix;
}
Size getTileDimensions() {
return mTileSize;
}
/**
* Clears state so in-flight requests abort upon return.
*/
void clear() {
mBitmapMatrix = null;
mRequiredBitmaps = null;
mPendingBitmapRequests = null;
}
/**
* Clears all the required bitmaps before they are re-set in {@link #requestBitmapForRect()}
*/
void clearRequiredBitmaps() {
if (mRequiredBitmaps == null) return;
for (int row = 0; row < mRequiredBitmaps.length; row++) {
for (int col = 0; col < mRequiredBitmaps[row].length; col++) {
mRequiredBitmaps[row][col] = false;
}
}
}
/**
* Requests bitmaps for tiles that overlap with the provided rect. Also requests bitmaps for
* adjacent tiles.
* @param viewportRect The rect of the viewport for which bitmaps are needed.
*/
void requestBitmapForRect(Rect viewportRect) {
if (mRequiredBitmaps == null) return;
final int rowStart =
Math.max(0, (int) Math.floor((double) viewportRect.top / mTileSize.getHeight()));
final int rowEnd = Math.min(mRequiredBitmaps.length,
(int) Math.ceil((double) viewportRect.bottom / mTileSize.getHeight()));
final int colStart =
Math.max(0, (int) Math.floor((double) viewportRect.left / mTileSize.getWidth()));
final int colEnd = Math.min(mRequiredBitmaps[0].length,
(int) Math.ceil((double) viewportRect.right / mTileSize.getWidth()));
for (int col = colStart; col < colEnd; col++) {
for (int row = rowStart; row < rowEnd; row++) {
requestBitmapForTile(row, col);
}
}
// Request bitmaps for adjacent tiles that are not currently in the view port. The reason
// that we do this in a separate loop is to make sure bitmaps for tiles inside the view port
// are fetched first.
for (int col = colStart; col < colEnd; col++) {
for (int row = rowStart; row < rowEnd; row++) {
requestBitmapForAdjacentTiles(row, col);
}
}
}
private void requestBitmapForAdjacentTiles(int row, int col) {
if (mBitmapMatrix == null) return;
if (row > 0) {
requestBitmapForTile(row - 1, col);
}
if (row < mBitmapMatrix.length - 1) {
requestBitmapForTile(row + 1, col);
}
if (col > 0) {
requestBitmapForTile(row, col - 1);
}
if (col < mBitmapMatrix[row].length - 1) {
requestBitmapForTile(row, col + 1);
}
}
private void requestBitmapForTile(int row, int col) {
if (mRequiredBitmaps == null) return;
mRequiredBitmaps[row][col] = true;
if (mBitmapMatrix == null || mPendingBitmapRequests == null
|| mBitmapMatrix[row][col] != null || mPendingBitmapRequests[row][col]) {
return;
}
final int y = row * mTileSize.getHeight();
final int x = col * mTileSize.getWidth();
BitmapRequestHandler bitmapRequestHandler =
new BitmapRequestHandler(row, col, mScaleFactor);
mPendingBitmapRequests[row][col] = true;
mCompositorDelegate.requestBitmap(mGuid,
new Rect(x, y, x + mTileSize.getWidth(), y + mTileSize.getHeight()), mScaleFactor,
bitmapRequestHandler, bitmapRequestHandler::onError);
}
/**
* Remove previously fetched bitmaps that are no longer required according to
* {@link #mRequiredBitmaps}.
*/
private void deleteUnrequiredBitmaps() {
if (mBitmapMatrix == null) return;
for (int row = 0; row < mBitmapMatrix.length; row++) {
for (int col = 0; col < mBitmapMatrix[row].length; col++) {
Bitmap bitmap = mBitmapMatrix[row][col];
if (!mRequiredBitmaps[row][col] && bitmap != null) {
bitmap.recycle();
mBitmapMatrix[row][col] = null;
}
}
}
}
/**
* Used as the callback for bitmap requests from the Paint Preview compositor.
*/
private class BitmapRequestHandler implements Callback<Bitmap> {
int mRequestRow;
int mRequestCol;
float mRequestScaleFactor;
private BitmapRequestHandler(int requestRow, int requestCol, float requestScaleFactor) {
mRequestRow = requestRow;
mRequestCol = requestCol;
mRequestScaleFactor = requestScaleFactor;
}
/**
* Called when bitmap is successfully composited.
* @param result
*/
@Override
public void onResult(Bitmap result) {
if (result == null) {
onError();
return;
}
if (mBitmapMatrix == null || !mPendingBitmapRequests[mRequestRow][mRequestCol]
|| !mRequiredBitmaps[mRequestRow][mRequestCol]) {
result.recycle();
deleteUnrequiredBitmaps();
return;
}
mPendingBitmapRequests[mRequestRow][mRequestCol] = false;
mBitmapMatrix[mRequestRow][mRequestCol] = result;
mMediatorDelegate.updateBitmapMatrix(mBitmapMatrix);
deleteUnrequiredBitmaps();
}
/**
* Called when there was an error compositing the bitmap.
*/
public void onError() {
if (mPendingBitmapRequests == null) return;
// TODO(crbug.com/1021590): Handle errors.
assert mBitmapMatrix != null;
assert mBitmapMatrix[mRequestRow][mRequestCol] == null;
assert mPendingBitmapRequests[mRequestRow][mRequestCol];
mPendingBitmapRequests[mRequestRow][mRequestCol] = false;
}
}
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
package org.chromium.components.paintpreview.player.frame; package org.chromium.components.paintpreview.player.frame;
import android.graphics.Bitmap;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Rect; import android.graphics.Rect;
...@@ -46,4 +47,9 @@ public interface PlayerFrameMediatorDelegate { ...@@ -46,4 +47,9 @@ public interface PlayerFrameMediatorDelegate {
* redraw when scaling is finished if its layout size didn't change. * redraw when scaling is finished if its layout size didn't change.
*/ */
void forceRedrawVisibleSubframes(); void forceRedrawVisibleSubframes();
/**
* Updates the bitmap matrix in the model.
*/
void updateBitmapMatrix(Bitmap[][] bitmapMatrix);
} }
...@@ -7,6 +7,7 @@ package org.chromium.components.paintpreview.player.frame; ...@@ -7,6 +7,7 @@ package org.chromium.components.paintpreview.player.frame;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Size;
import android.view.View; import android.view.View;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
...@@ -22,7 +23,7 @@ class PlayerFrameProperties { ...@@ -22,7 +23,7 @@ class PlayerFrameProperties {
static final PropertyModel.WritableObjectPropertyKey<Bitmap[][]> BITMAP_MATRIX = static final PropertyModel.WritableObjectPropertyKey<Bitmap[][]> BITMAP_MATRIX =
new PropertyModel.WritableObjectPropertyKey<>(true); new PropertyModel.WritableObjectPropertyKey<>(true);
/** The dimensions of each bitmap tile in the current bitmap matrix. */ /** The dimensions of each bitmap tile in the current bitmap matrix. */
static final PropertyModel.WritableObjectPropertyKey<int[]> TILE_DIMENSIONS = static final PropertyModel.WritableObjectPropertyKey<Size> TILE_DIMENSIONS =
new PropertyModel.WritableObjectPropertyKey<>(); new PropertyModel.WritableObjectPropertyKey<>();
/** /**
* Contains the current user-visible content window. The view should use this to draw the * Contains the current user-visible content window. The view should use this to draw the
......
...@@ -9,6 +9,7 @@ import android.graphics.Bitmap; ...@@ -9,6 +9,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Size;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
...@@ -80,7 +81,7 @@ class PlayerFrameView extends FrameLayout { ...@@ -80,7 +81,7 @@ class PlayerFrameView extends FrameLayout {
mBitmapPainter.updateBitmapMatrix(bitmapMatrix); mBitmapPainter.updateBitmapMatrix(bitmapMatrix);
} }
void updateTileDimensions(int[] tileDimensions) { void updateTileDimensions(Size tileDimensions) {
mBitmapPainter.updateTileDimensions(tileDimensions); mBitmapPainter.updateTileDimensions(tileDimensions);
} }
......
...@@ -8,6 +8,7 @@ import android.graphics.Bitmap; ...@@ -8,6 +8,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Size;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -99,7 +100,7 @@ public class PlayerFrameBitmapPainterTest { ...@@ -99,7 +100,7 @@ public class PlayerFrameBitmapPainterTest {
PlayerFrameBitmapPainter painter = PlayerFrameBitmapPainter painter =
new PlayerFrameBitmapPainter(Mockito.mock(Runnable.class)); new PlayerFrameBitmapPainter(Mockito.mock(Runnable.class));
painter.updateBitmapMatrix(generateMockBitmapMatrix(2, 3)); painter.updateBitmapMatrix(generateMockBitmapMatrix(2, 3));
painter.updateTileDimensions(new int[] {10, -5}); painter.updateTileDimensions(new Size(10, -5));
painter.updateViewPort(0, 5, 10, -10); painter.updateViewPort(0, 5, 10, -10);
MockCanvas canvas = new MockCanvas(); MockCanvas canvas = new MockCanvas();
...@@ -107,7 +108,7 @@ public class PlayerFrameBitmapPainterTest { ...@@ -107,7 +108,7 @@ public class PlayerFrameBitmapPainterTest {
canvas.assertNumberOfBitmapDraws(0); canvas.assertNumberOfBitmapDraws(0);
// Update the view port so it is covered by 2 bitmap tiles. // Update the view port so it is covered by 2 bitmap tiles.
painter.updateTileDimensions(new int[] {10, 10}); painter.updateTileDimensions(new Size(10, 10));
painter.updateViewPort(0, 5, 10, 15); painter.updateViewPort(0, 5, 10, 15);
painter.onDraw(canvas); painter.onDraw(canvas);
canvas.assertNumberOfBitmapDraws(2); canvas.assertNumberOfBitmapDraws(2);
...@@ -123,7 +124,7 @@ public class PlayerFrameBitmapPainterTest { ...@@ -123,7 +124,7 @@ public class PlayerFrameBitmapPainterTest {
painter.updateBitmapMatrix(new Bitmap[0][0]); painter.updateBitmapMatrix(new Bitmap[0][0]);
// This view port is covered by 2 bitmap tiles, so there should be 2 draw operations on // This view port is covered by 2 bitmap tiles, so there should be 2 draw operations on
// the canvas. // the canvas.
painter.updateTileDimensions(new int[] {10, 10}); painter.updateTileDimensions(new Size(10, 10));
painter.updateViewPort(0, 5, 10, 15); painter.updateViewPort(0, 5, 10, 15);
MockCanvas canvas = new MockCanvas(); MockCanvas canvas = new MockCanvas();
...@@ -156,7 +157,7 @@ public class PlayerFrameBitmapPainterTest { ...@@ -156,7 +157,7 @@ public class PlayerFrameBitmapPainterTest {
bitmaps[1][1] = bitmap11; bitmaps[1][1] = bitmap11;
painter.updateBitmapMatrix(bitmaps); painter.updateBitmapMatrix(bitmaps);
painter.updateTileDimensions(new int[] {10, 15}); painter.updateTileDimensions(new Size(10, 15));
painter.updateViewPort(5, 10, 15, 25); painter.updateViewPort(5, 10, 15, 25);
// Make sure the invalidator was called after updating the bitmap matrix and the view port. // Make sure the invalidator was called after updating the bitmap matrix and the view port.
......
...@@ -400,7 +400,8 @@ public class PlayerFrameMediatorTest { ...@@ -400,7 +400,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
mMediator.scrollBy(10, 15); mMediator.scrollBy(10, 15);
// The current viewport covers portions of the 4 top left bitmap tiles. // The current viewport covers portions of the 4 top left bitmap tiles.
...@@ -421,7 +422,8 @@ public class PlayerFrameMediatorTest { ...@@ -421,7 +422,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[1][2] = true; expectedRequiredBitmaps[1][2] = true;
expectedRequiredBitmaps[2][0] = true; expectedRequiredBitmaps[2][0] = true;
expectedRequiredBitmaps[2][1] = true; expectedRequiredBitmaps[2][1] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
mMediator.scrollBy(200, 400); mMediator.scrollBy(200, 400);
// The current view port contains portions of the middle 4 tiles. // The current view port contains portions of the middle 4 tiles.
...@@ -454,7 +456,8 @@ public class PlayerFrameMediatorTest { ...@@ -454,7 +456,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[3][4] = true; expectedRequiredBitmaps[3][4] = true;
expectedRequiredBitmaps[4][2] = true; expectedRequiredBitmaps[4][2] = true;
expectedRequiredBitmaps[4][3] = true; expectedRequiredBitmaps[4][3] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
mMediator.scrollBy(200, 400); mMediator.scrollBy(200, 400);
// The current view port contains portions of the 4 bottom right tiles. // The current view port contains portions of the 4 bottom right tiles.
...@@ -488,7 +491,8 @@ public class PlayerFrameMediatorTest { ...@@ -488,7 +491,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[5][3] = true; expectedRequiredBitmaps[5][3] = true;
expectedRequiredBitmaps[5][4] = true; expectedRequiredBitmaps[5][4] = true;
expectedRequiredBitmaps[5][5] = true; expectedRequiredBitmaps[5][5] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
} }
/** /**
...@@ -811,7 +815,8 @@ public class PlayerFrameMediatorTest { ...@@ -811,7 +815,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
// Now a scale factor of 2 will be applied. This will happen at a focal point of 0, 0. // Now a scale factor of 2 will be applied. This will happen at a focal point of 0, 0.
// The same bitmaps will be required but the grid will be double the size. // The same bitmaps will be required but the grid will be double the size.
...@@ -822,7 +827,8 @@ public class PlayerFrameMediatorTest { ...@@ -822,7 +827,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
// Reduce the scale factor by 0.5 returning to a scale of 1. // Reduce the scale factor by 0.5 returning to a scale of 1.
Assert.assertTrue(mMediator.scaleBy(0.5f, 0, 0)); Assert.assertTrue(mMediator.scaleBy(0.5f, 0, 0));
...@@ -832,7 +838,8 @@ public class PlayerFrameMediatorTest { ...@@ -832,7 +838,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
// Increase the scale factor to 6 which is above the maximum limit returning to a scale // Increase the scale factor to 6 which is above the maximum limit returning to a scale
// of 5. Note that the grid is smaller than 30x30 as the viewport is not a multiple of the // of 5. Note that the grid is smaller than 30x30 as the viewport is not a multiple of the
...@@ -844,7 +851,8 @@ public class PlayerFrameMediatorTest { ...@@ -844,7 +851,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
// Reduce the scale factor back to 1. // Reduce the scale factor back to 1.
Assert.assertTrue(mMediator.scaleBy(0.2f, 0, 0)); Assert.assertTrue(mMediator.scaleBy(0.2f, 0, 0));
...@@ -854,7 +862,8 @@ public class PlayerFrameMediatorTest { ...@@ -854,7 +862,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
// We now reduce the scale factor to less than mInitialScaleFactor; however, the maximum // We now reduce the scale factor to less than mInitialScaleFactor; however, the maximum
// scale out is limited to mInitialScaleFactor. // scale out is limited to mInitialScaleFactor.
...@@ -866,7 +875,8 @@ public class PlayerFrameMediatorTest { ...@@ -866,7 +875,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps = new boolean[2][1]; expectedRequiredBitmaps = new boolean[2][1];
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
} }
/** /**
...@@ -910,7 +920,8 @@ public class PlayerFrameMediatorTest { ...@@ -910,7 +920,8 @@ public class PlayerFrameMediatorTest {
assertViewportStateIs(1f, 0f, 0f, mViewport); assertViewportStateIs(1f, 0f, 0f, mViewport);
Assert.assertTrue(mModel.get(PlayerFrameProperties.SCALE_MATRIX).isIdentity()); Assert.assertTrue(mModel.get(PlayerFrameProperties.SCALE_MATRIX).isIdentity());
// Ensure the correct bitmaps are required and requested. // Ensure the correct bitmaps are required and requested.
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
Assert.assertEquals(expectedRequestedBitmaps, mCompositorDelegate.mRequestedBitmap); Assert.assertEquals(expectedRequestedBitmaps, mCompositorDelegate.mRequestedBitmap);
// STEP 2: Scroll slightly. // STEP 2: Scroll slightly.
...@@ -933,7 +944,8 @@ public class PlayerFrameMediatorTest { ...@@ -933,7 +944,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[1][2] = true; expectedRequiredBitmaps[1][2] = true;
expectedRequiredBitmaps[2][0] = true; expectedRequiredBitmaps[2][0] = true;
expectedRequiredBitmaps[2][1] = true; expectedRequiredBitmaps[2][1] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
expectedRequestedBitmaps.add( expectedRequestedBitmaps.add(
new RequestedBitmap(mFrameGuid, getRectForTile(100, 200, 1, 1), 1f)); new RequestedBitmap(mFrameGuid, getRectForTile(100, 200, 1, 1), 1f));
...@@ -985,7 +997,8 @@ public class PlayerFrameMediatorTest { ...@@ -985,7 +997,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[1][2] = true; expectedRequiredBitmaps[1][2] = true;
expectedRequiredBitmaps[2][0] = true; expectedRequiredBitmaps[2][0] = true;
expectedRequiredBitmaps[2][1] = true; expectedRequiredBitmaps[2][1] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
expectedRequestedBitmaps.add( expectedRequestedBitmaps.add(
new RequestedBitmap(mFrameGuid, getRectForTile(100, 200, 0, 0), 2f)); new RequestedBitmap(mFrameGuid, getRectForTile(100, 200, 0, 0), 2f));
...@@ -1035,7 +1048,8 @@ public class PlayerFrameMediatorTest { ...@@ -1035,7 +1048,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[1][2] = true; expectedRequiredBitmaps[1][2] = true;
expectedRequiredBitmaps[2][0] = true; expectedRequiredBitmaps[2][0] = true;
expectedRequiredBitmaps[2][1] = true; expectedRequiredBitmaps[2][1] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
expectedRequestedBitmaps.add( expectedRequestedBitmaps.add(
new RequestedBitmap(mFrameGuid, getRectForTile(100, 200, 0, 0), 1f)); new RequestedBitmap(mFrameGuid, getRectForTile(100, 200, 0, 0), 1f));
...@@ -1098,7 +1112,8 @@ public class PlayerFrameMediatorTest { ...@@ -1098,7 +1112,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[2][3] = true; expectedRequiredBitmaps[2][3] = true;
expectedRequiredBitmaps[3][1] = true; expectedRequiredBitmaps[3][1] = true;
expectedRequiredBitmaps[3][2] = true; expectedRequiredBitmaps[3][2] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
expectedRequestedBitmaps.add( expectedRequestedBitmaps.add(
new RequestedBitmap(mFrameGuid, getRectForTile(100, 200, 1, 1), 2f)); new RequestedBitmap(mFrameGuid, getRectForTile(100, 200, 1, 1), 2f));
...@@ -1249,7 +1264,8 @@ public class PlayerFrameMediatorTest { ...@@ -1249,7 +1264,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
// Now a scale factor of 2 will be applied. This will happen at a focal point of 0, 0. // Now a scale factor of 2 will be applied. This will happen at a focal point of 0, 0.
// The same bitmaps will be required but the grid will be double the size. // The same bitmaps will be required but the grid will be double the size.
...@@ -1267,7 +1283,8 @@ public class PlayerFrameMediatorTest { ...@@ -1267,7 +1283,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
// Reduce the scale factor by 0.5 returning to a scale of 1 but try to do so with a focal // Reduce the scale factor by 0.5 returning to a scale of 1 but try to do so with a focal
// point that causes translation outside the bounds. The focal point should be ignored. // point that causes translation outside the bounds. The focal point should be ignored.
...@@ -1284,7 +1301,8 @@ public class PlayerFrameMediatorTest { ...@@ -1284,7 +1301,8 @@ public class PlayerFrameMediatorTest {
expectedRequiredBitmaps[0][0] = true; expectedRequiredBitmaps[0][0] = true;
expectedRequiredBitmaps[0][1] = true; expectedRequiredBitmaps[0][1] = true;
expectedRequiredBitmaps[1][0] = true; expectedRequiredBitmaps[1][0] = true;
Assert.assertTrue(Arrays.deepEquals(expectedRequiredBitmaps, mMediator.mRequiredBitmaps)); Assert.assertTrue(Arrays.deepEquals(
expectedRequiredBitmaps, mMediator.mBitmapState.mRequiredBitmaps));
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment