Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1740)

Unified Diff: cc/tiles/picture_layer_tiling_unittest.cc

Issue 2175553002: Raster PictureLayerTiling with fractional translation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: combined Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/tiles/picture_layer_tiling_set_unittest.cc ('k') | cc/tiles/tile.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/tiles/picture_layer_tiling_unittest.cc
diff --git a/cc/tiles/picture_layer_tiling_unittest.cc b/cc/tiles/picture_layer_tiling_unittest.cc
index fdafb2dea3c340444b320cd173ee95cf1c5bbfb9..ba3e809c0cc53f3fd7997d36a69a439be1b6ccbf 100644
--- a/cc/tiles/picture_layer_tiling_unittest.cc
+++ b/cc/tiles/picture_layer_tiling_unittest.cc
@@ -47,12 +47,12 @@ class TestablePictureLayerTiling : public PictureLayerTiling {
static std::unique_ptr<TestablePictureLayerTiling> Create(
WhichTree tree,
- float contents_scale,
+ const ScaleTranslate2d& raster_transform,
scoped_refptr<RasterSource> raster_source,
PictureLayerTilingClient* client,
const LayerTreeSettings& settings) {
return base::WrapUnique(new TestablePictureLayerTiling(
- tree, contents_scale, raster_source, client,
+ tree, raster_transform, raster_source, client,
settings.tiling_interest_area_padding,
settings.skewport_target_time_in_seconds,
settings.skewport_extrapolation_limit_in_screen_pixels,
@@ -71,7 +71,7 @@ class TestablePictureLayerTiling : public PictureLayerTiling {
protected:
TestablePictureLayerTiling(WhichTree tree,
- float contents_scale,
+ const ScaleTranslate2d& raster_transform,
scoped_refptr<RasterSource> raster_source,
PictureLayerTilingClient* client,
size_t tiling_interest_area_padding,
@@ -80,7 +80,7 @@ class TestablePictureLayerTiling : public PictureLayerTiling {
float min_preraster_distance,
float max_preraster_distance)
: PictureLayerTiling(tree,
- contents_scale,
+ raster_transform,
raster_source,
client,
min_preraster_distance,
@@ -98,7 +98,19 @@ class PictureLayerTilingIteratorTest : public testing::Test {
client_.SetTileSize(tile_size);
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(layer_bounds);
- tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, contents_scale,
+ tiling_ = TestablePictureLayerTiling::Create(
+ PENDING_TREE, ScaleTranslate2d(contents_scale, gfx::Vector2dF()),
+ raster_source, &client_, LayerTreeSettings());
+ tiling_->set_resolution(HIGH_RESOLUTION);
+ }
+
+ void InitializeWithTranslation(const gfx::Size& tile_size,
+ const ScaleTranslate2d& raster_transform,
+ const gfx::Size& layer_bounds) {
+ client_.SetTileSize(tile_size);
+ scoped_refptr<FakeRasterSource> raster_source =
+ FakeRasterSource::CreateFilled(layer_bounds);
+ tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, raster_transform,
raster_source, &client_,
LayerTreeSettings());
tiling_->set_resolution(HIGH_RESOLUTION);
@@ -110,9 +122,9 @@ class PictureLayerTilingIteratorTest : public testing::Test {
client_.SetTileSize(tile_size);
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(layer_bounds);
- tiling_ = TestablePictureLayerTiling::Create(ACTIVE_TREE, contents_scale,
- raster_source, &client_,
- LayerTreeSettings());
+ tiling_ = TestablePictureLayerTiling::Create(
+ ACTIVE_TREE, ScaleTranslate2d(contents_scale, gfx::Vector2dF()),
+ raster_source, &client_, LayerTreeSettings());
tiling_->set_resolution(HIGH_RESOLUTION);
}
@@ -137,7 +149,7 @@ class PictureLayerTilingIteratorTest : public testing::Test {
// tiling scale. This is because coverage computation is done in integer
// grids in the dest space, and the overlap between tiles may not guarantee
// to enclose an integer grid line to round to if scaled down.
- ASSERT_GE(rect_scale, tiling_->contents_scale());
+ ASSERT_GE(rect_scale, tiling_->contents_scale_key());
Region remaining = expect_rect;
for (PictureLayerTiling::CoverageIterator
@@ -205,7 +217,7 @@ class PictureLayerTilingIteratorTest : public testing::Test {
void VerifyTilesCoverNonContainedRect(float rect_scale,
const gfx::Rect& dest_rect) {
- float dest_to_contents_scale = tiling_->contents_scale() / rect_scale;
+ float dest_to_contents_scale = tiling_->contents_scale_key() / rect_scale;
gfx::Rect clamped_rect = gfx::ScaleToEnclosingRect(
gfx::Rect(tiling_->tiling_size()), 1.f / dest_to_contents_scale);
clamped_rect.Intersect(dest_rect);
@@ -498,9 +510,9 @@ TEST_F(PictureLayerTilingIteratorTest, CreateTileJustCoverBorderUp) {
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(layer_size);
std::unique_ptr<TestablePictureLayerTiling> active_tiling =
- TestablePictureLayerTiling::Create(ACTIVE_TREE, content_scale,
- raster_source, &active_client,
- LayerTreeSettings());
+ TestablePictureLayerTiling::Create(
+ ACTIVE_TREE, ScaleTranslate2d(content_scale, gfx::Vector2dF()),
+ raster_source, &active_client, LayerTreeSettings());
active_tiling->set_resolution(HIGH_RESOLUTION);
gfx::Rect invalid_rect(0, 750, 220, 100);
@@ -715,8 +727,8 @@ TEST_F(PictureLayerTilingIteratorTest,
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(layer_bounds);
- tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, 1.f, raster_source,
- &client_, settings);
+ tiling_ = TestablePictureLayerTiling::Create(
+ PENDING_TREE, ScaleTranslate2d(), raster_source, &client_, settings);
tiling_->set_resolution(HIGH_RESOLUTION);
VerifyTilesExactlyCoverRect(1.f, gfx::Rect(layer_bounds));
VerifyTiles(1.f, gfx::Rect(layer_bounds), base::Bind(&TileExists, false));
@@ -753,8 +765,9 @@ TEST(ComputeTilePriorityRectsTest, VisibleTiles) {
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(current_layer_bounds);
std::unique_ptr<TestablePictureLayerTiling> tiling =
- TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, raster_source,
- &client, LayerTreeSettings());
+ TestablePictureLayerTiling::Create(ACTIVE_TREE, ScaleTranslate2d(),
+ raster_source, &client,
+ LayerTreeSettings());
tiling->set_resolution(HIGH_RESOLUTION);
LayerTreeSettings settings;
@@ -811,8 +824,9 @@ TEST(ComputeTilePriorityRectsTest, OffscreenTiles) {
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(current_layer_bounds);
std::unique_ptr<TestablePictureLayerTiling> tiling =
- TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, raster_source,
- &client, LayerTreeSettings());
+ TestablePictureLayerTiling::Create(ACTIVE_TREE, ScaleTranslate2d(),
+ raster_source, &client,
+ LayerTreeSettings());
tiling->set_resolution(HIGH_RESOLUTION);
LayerTreeSettings settings;
@@ -879,8 +893,9 @@ TEST(ComputeTilePriorityRectsTest, PartiallyOffscreenLayer) {
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(current_layer_bounds);
std::unique_ptr<TestablePictureLayerTiling> tiling =
- TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, raster_source,
- &client, LayerTreeSettings());
+ TestablePictureLayerTiling::Create(ACTIVE_TREE, ScaleTranslate2d(),
+ raster_source, &client,
+ LayerTreeSettings());
tiling->set_resolution(HIGH_RESOLUTION);
LayerTreeSettings settings;
@@ -921,8 +936,9 @@ TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) {
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(gfx::Size(100, 100));
std::unique_ptr<TestablePictureLayerTiling> active_tiling =
- TestablePictureLayerTiling::Create(ACTIVE_TREE, 1.0f, raster_source,
- &active_client, LayerTreeSettings());
+ TestablePictureLayerTiling::Create(ACTIVE_TREE, ScaleTranslate2d(),
+ raster_source, &active_client,
+ LayerTreeSettings());
active_tiling->set_resolution(HIGH_RESOLUTION);
// Create all tiles on this tiling.
gfx::Rect visible_rect = gfx::Rect(0, 0, 100, 100);
@@ -937,8 +953,9 @@ TEST(PictureLayerTilingTest, RecycledTilesClearedOnReset) {
raster_source = FakeRasterSource::CreateFilled(gfx::Size(100, 100));
std::unique_ptr<TestablePictureLayerTiling> recycle_tiling =
- TestablePictureLayerTiling::Create(PENDING_TREE, 1.0f, raster_source,
- &recycle_client, settings);
+ TestablePictureLayerTiling::Create(PENDING_TREE, ScaleTranslate2d(),
+ raster_source, &recycle_client,
+ settings);
recycle_tiling->set_resolution(HIGH_RESOLUTION);
// Create all tiles on the recycle tiling.
@@ -966,8 +983,9 @@ TEST(PictureLayerTilingTest, EdgeCaseTileNowAndRequired) {
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(gfx::Size(500, 500));
std::unique_ptr<TestablePictureLayerTiling> pending_tiling =
- TestablePictureLayerTiling::Create(PENDING_TREE, 1.0f, raster_source,
- &pending_client, LayerTreeSettings());
+ TestablePictureLayerTiling::Create(PENDING_TREE, ScaleTranslate2d(),
+ raster_source, &pending_client,
+ LayerTreeSettings());
pending_tiling->set_resolution(HIGH_RESOLUTION);
pending_tiling->set_can_require_tiles_for_activation(true);
@@ -1038,9 +1056,9 @@ TEST_F(PictureLayerTilingIteratorTest, GiantRect) {
client_.SetTileSize(tile_size);
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateEmpty(layer_size);
- tiling_ = TestablePictureLayerTiling::Create(PENDING_TREE, contents_scale,
- raster_source, &client_,
- LayerTreeSettings());
+ tiling_ = TestablePictureLayerTiling::Create(
+ PENDING_TREE, ScaleTranslate2d(contents_scale, gfx::Vector2dF()),
+ raster_source, &client_, LayerTreeSettings());
gfx::Rect content_rect(25554432, 25554432, 950, 860);
VerifyTilesExactlyCoverRect(contents_scale, content_rect);
@@ -1126,7 +1144,8 @@ TEST_F(PictureLayerTilingIteratorTest, TilesStoreTilings) {
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilled(bounds);
auto active_tiling = TestablePictureLayerTiling::Create(
- ACTIVE_TREE, 1.f, raster_source, &client_, LayerTreeSettings());
+ ACTIVE_TREE, ScaleTranslate2d(), raster_source, &client_,
+ LayerTreeSettings());
active_tiling->set_resolution(HIGH_RESOLUTION);
active_tiling->TakeTilesAndPropertiesFrom(tiling_.get(),
@@ -1136,5 +1155,106 @@ TEST_F(PictureLayerTilingIteratorTest, TilesStoreTilings) {
}
}
+TEST_F(PictureLayerTilingIteratorTest, FractionalTranslatedTiling) {
+ InitializeWithTranslation(
+ gfx::Size(256, 256),
+ ScaleTranslate2d(1.f, gfx::Vector2dF(0.125f, 0.125f)),
+ gfx::Size(1000, 1));
+ EXPECT_EQ(tiling_->tiling_size(), gfx::Size(1001, 2));
+ SetLiveRectAndVerifyTiles(gfx::Rect(1000, 1));
+
+ // Verifies the texture coordinate is correctly translated.
+ for (PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.f,
+ gfx::Rect(1000, 1));
+ iter; ++iter) {
+ gfx::Rect geometry_rect = iter.geometry_rect();
+ gfx::RectF texture_rect = iter.texture_rect();
+ if (geometry_rect == gfx::Rect(0, 0, 255, 1)) {
+ EXPECT_EQ(gfx::RectF(0.125f, 0.125f, 255.f, 1.f), texture_rect);
+ } else if (geometry_rect == gfx::Rect(255, 0, 254, 1)) {
+ EXPECT_EQ(gfx::RectF(1.125f, 0.125f, 254.f, 1.f), texture_rect);
+ } else if (geometry_rect == gfx::Rect(509, 0, 254, 1)) {
+ EXPECT_EQ(gfx::RectF(1.125f, 0.125f, 254.f, 1.f), texture_rect);
+ } else {
+ EXPECT_EQ(gfx::Rect(763, 0, 237, 1), geometry_rect);
+ EXPECT_EQ(gfx::RectF(1.125f, 0.125f, 237.f, 1.f), texture_rect);
+ }
+ }
+
+ // Similar to above, with a different coverage scale.
+ for (PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.375f,
+ gfx::Rect(1375, 2));
+ iter; ++iter) {
+ gfx::Rect geometry_rect = iter.geometry_rect();
+ gfx::RectF texture_rect = iter.texture_rect();
+ if (geometry_rect == gfx::Rect(0, 0, 351, 2)) {
+ gfx::RectF expectation(geometry_rect);
+ expectation.Scale(1.f / 1.375f);
+ expectation.Offset(0.125f, 0.125f);
+ EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x());
+ EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y());
+ EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width());
+ EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height());
+ } else if (geometry_rect == gfx::Rect(351, 0, 349, 2)) {
+ gfx::RectF expectation(geometry_rect);
+ expectation.Scale(1.f / 1.375f);
+ expectation.Offset(0.125f - 254.f, 0.125f);
+ EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x());
+ EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y());
+ EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width());
+ EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height());
+ } else if (geometry_rect == gfx::Rect(700, 0, 349, 2)) {
+ gfx::RectF expectation(geometry_rect);
+ expectation.Scale(1.f / 1.375f);
+ expectation.Offset(0.125f - 254.f * 2.f, 0.125f);
+ EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x());
+ EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y());
+ EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width());
+ EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height());
+ } else {
+ EXPECT_EQ(gfx::Rect(1049, 0, 326, 2), geometry_rect);
+ gfx::RectF expectation(geometry_rect);
+ expectation.Scale(1.f / 1.375f);
+ expectation.Offset(0.125f - 254.f * 3.f, 0.125f);
+ EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x());
+ EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y());
+ EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width());
+ EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height());
+ }
+ }
+}
+
+TEST_F(PictureLayerTilingIteratorTest, FractionalTranslatedTilingOverflow) {
+ // This tests a corner case where the coverage rect is slightly greater
+ // than the layer rect due to rounding up, and the bottom right edge of
+ // the tiling coincide with actual layer bound. That is, the requested
+ // coverage rect slightly exceed the valid extent, but we still return
+ // full coverage as a special case for external edges.
+
+ // The layer bounds is (9, 9), which after scale and translation
+ // becomes (l=0.5, t=0.5, r=14, b=14) in the contents space.
+ InitializeWithTranslation(gfx::Size(256, 256),
+ ScaleTranslate2d(1.5f, gfx::Vector2dF(0.5f, 0.5f)),
+ gfx::Size(9, 9));
+ EXPECT_EQ(tiling_->tiling_size(), gfx::Size(14, 14));
+ SetLiveRectAndVerifyTiles(gfx::Rect(9, 9));
+
+ PictureLayerTiling::CoverageIterator iter(tiling_.get(), 1.56f,
+ gfx::Rect(15, 15));
+ ASSERT_TRUE(iter);
+ gfx::Rect geometry_rect = iter.geometry_rect();
+ gfx::RectF texture_rect = iter.texture_rect();
+ EXPECT_EQ(gfx::Rect(0, 0, 15, 15), geometry_rect);
+ gfx::RectF expectation(geometry_rect);
+ expectation.Scale(1.5f / 1.56f);
+ expectation.Offset(0.5f, 0.5f);
+ EXPECT_FLOAT_EQ(expectation.x(), texture_rect.x());
+ EXPECT_FLOAT_EQ(expectation.y(), texture_rect.y());
+ EXPECT_FLOAT_EQ(expectation.width(), texture_rect.width());
+ EXPECT_FLOAT_EQ(expectation.height(), texture_rect.height());
+
+ EXPECT_FALSE(++iter);
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/tiles/picture_layer_tiling_set_unittest.cc ('k') | cc/tiles/tile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698