This source file includes following definitions.
- picture_map
- recorded_viewport
- CanRasterLayerRect
- contents_opaque_
- layer_rect
- Update
- UpdateWholeLayer
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include <map>
#include <utility>
#include "cc/resources/picture_pile.h"
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/fake_rendering_stats_instrumentation.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/size_conversions.h"
namespace cc {
namespace {
class TestPicturePile : public PicturePile {
public:
using PicturePile::buffer_pixels;
using PicturePile::CanRasterSlowTileCheck;
using PicturePile::Clear;
PictureMap& picture_map() { return picture_map_; }
const gfx::Rect& recorded_viewport() const { return recorded_viewport_; }
bool CanRasterLayerRect(const gfx::Rect& layer_rect) {
return CanRaster(1.f, layer_rect);
}
typedef PicturePile::PictureInfo PictureInfo;
typedef PicturePile::PictureMapKey PictureMapKey;
typedef PicturePile::PictureMap PictureMap;
protected:
virtual ~TestPicturePile() {}
};
class PicturePileTest : public testing::Test {
public:
PicturePileTest()
: pile_(new TestPicturePile()),
background_color_(SK_ColorBLUE),
min_scale_(0.125),
frame_number_(0),
contents_opaque_(false) {
pile_->Resize(pile_->tiling().max_texture_size());
pile_->SetTileGridSize(gfx::Size(1000, 1000));
pile_->SetMinContentsScale(min_scale_);
}
gfx::Rect layer_rect() const { return gfx::Rect(pile_->size()); }
bool Update(const Region& invalidation, const gfx::Rect& visible_layer_rect) {
frame_number_++;
return pile_->Update(&client_,
background_color_,
contents_opaque_,
false,
invalidation,
visible_layer_rect,
frame_number_,
&stats_instrumentation_);
}
bool UpdateWholeLayer() { return Update(layer_rect(), layer_rect()); }
FakeContentLayerClient client_;
FakeRenderingStatsInstrumentation stats_instrumentation_;
scoped_refptr<TestPicturePile> pile_;
SkColor background_color_;
float min_scale_;
int frame_number_;
bool contents_opaque_;
};
TEST_F(PicturePileTest, SmallInvalidateInflated) {
UpdateWholeLayer();
gfx::Rect invalidate_rect(50, 50, 1, 1);
Update(invalidate_rect, layer_rect());
EXPECT_EQ(1, pile_->tiling().num_tiles_x());
EXPECT_EQ(1, pile_->tiling().num_tiles_y());
TestPicturePile::PictureInfo& picture_info =
pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second;
EXPECT_TRUE(!!picture_info.GetPicture());
gfx::Rect picture_rect = gfx::ScaleToEnclosedRect(
picture_info.GetPicture()->LayerRect(), min_scale_);
EXPECT_FALSE(picture_rect.IsEmpty()) << "Picture rect " <<
picture_rect.ToString();
}
TEST_F(PicturePileTest, LargeInvalidateInflated) {
UpdateWholeLayer();
gfx::Rect invalidate_rect(50, 50, 100, 100);
Update(invalidate_rect, layer_rect());
EXPECT_EQ(1, pile_->tiling().num_tiles_x());
EXPECT_EQ(1, pile_->tiling().num_tiles_y());
TestPicturePile::PictureInfo& picture_info =
pile_->picture_map().find(TestPicturePile::PictureMapKey(0, 0))->second;
EXPECT_TRUE(!!picture_info.GetPicture());
int expected_inflation = pile_->buffer_pixels();
Picture* base_picture = picture_info.GetPicture();
gfx::Rect base_picture_rect(pile_->size());
base_picture_rect.Inset(-expected_inflation, -expected_inflation);
EXPECT_EQ(base_picture_rect.ToString(),
base_picture->LayerRect().ToString());
}
TEST_F(PicturePileTest, InvalidateOnTileBoundaryInflated) {
gfx::Size layer_size = gfx::ToFlooredSize(gfx::ScaleSize(pile_->size(), 2.f));
pile_->Resize(layer_size);
EXPECT_EQ(3, pile_->tiling().num_tiles_x());
EXPECT_EQ(3, pile_->tiling().num_tiles_y());
EXPECT_EQ(7, pile_->buffer_pixels());
EXPECT_EQ(7, pile_->tiling().border_texels());
UpdateWholeLayer();
UpdateWholeLayer();
gfx::Rect invalidate_rect(
pile_->tiling().TileBoundsWithBorder(0, 0).right(),
pile_->tiling().TileBoundsWithBorder(0, 0).bottom() - 1,
50,
50);
Update(invalidate_rect, layer_rect());
for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) {
for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) {
TestPicturePile::PictureInfo& picture_info =
pile_->picture_map()
.find(TestPicturePile::PictureMapKey(i, j))
->second;
if (i == 1 && (j == 0 || j == 1)) {
EXPECT_FLOAT_EQ(
2.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED,
picture_info.GetInvalidationFrequencyForTesting());
} else {
EXPECT_FLOAT_EQ(
1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED,
picture_info.GetInvalidationFrequencyForTesting());
}
}
}
}
TEST_F(PicturePileTest, StopRecordingOffscreenInvalidations) {
gfx::Size layer_size = gfx::ToFlooredSize(gfx::ScaleSize(pile_->size(), 4.f));
pile_->Resize(layer_size);
gfx::Rect viewport(0, 0, layer_size.width(), 1);
for (int frame = 0; frame < 33; ++frame) {
UpdateWholeLayer();
}
for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) {
for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) {
TestPicturePile::PictureInfo& picture_info =
pile_->picture_map()
.find(TestPicturePile::PictureMapKey(i, j))
->second;
EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting())
<< "i " << i << " j " << j;
}
}
Update(layer_rect(), viewport);
for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) {
for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) {
TestPicturePile::PictureInfo& picture_info =
pile_->picture_map()
.find(TestPicturePile::PictureMapKey(i, j))
->second;
EXPECT_FLOAT_EQ(1.0f, picture_info.GetInvalidationFrequencyForTesting());
if (j >= 2)
EXPECT_FALSE(picture_info.GetPicture()) << "i " << i << " j " << j;
else
EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j;
}
}
Update(gfx::Rect(), layer_rect());
for (int i = 0; i < pile_->tiling().num_tiles_x(); ++i) {
for (int j = 0; j < pile_->tiling().num_tiles_y(); ++j) {
TestPicturePile::PictureInfo& picture_info =
pile_->picture_map()
.find(TestPicturePile::PictureMapKey(i, j))
->second;
float expected_frequency =
1.0f -
1.0f / TestPicturePile::PictureInfo::INVALIDATION_FRAMES_TRACKED;
EXPECT_FLOAT_EQ(expected_frequency,
picture_info.GetInvalidationFrequencyForTesting());
EXPECT_TRUE(picture_info.GetPicture()) << "i " << i << " j " << j;
}
}
}
TEST_F(PicturePileTest, ClearingInvalidatesRecordedRect) {
UpdateWholeLayer();
gfx::Rect rect(0, 0, 5, 5);
EXPECT_TRUE(pile_->CanRasterLayerRect(rect));
EXPECT_TRUE(pile_->CanRasterSlowTileCheck(rect));
pile_->Clear();
EXPECT_FALSE(pile_->CanRasterLayerRect(rect));
EXPECT_FALSE(pile_->CanRasterSlowTileCheck(rect));
}
TEST_F(PicturePileTest, FrequentInvalidationCanRaster) {
gfx::Size layer_size = gfx::ToFlooredSize(gfx::ScaleSize(pile_->size(), 4.f));
pile_->Resize(layer_size);
gfx::Rect tile01_borders = pile_->tiling().TileBoundsWithBorder(0, 1);
gfx::Rect tile02_borders = pile_->tiling().TileBoundsWithBorder(0, 2);
gfx::Rect tile01_noborders = pile_->tiling().TileBounds(0, 1);
gfx::Rect tile02_noborders = pile_->tiling().TileBounds(0, 2);
EXPECT_TRUE(tile01_borders.Intersects(tile02_borders));
EXPECT_FALSE(tile01_noborders.Intersects(tile02_noborders));
UpdateWholeLayer();
EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders));
EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders));
EXPECT_TRUE(pile_->CanRasterLayerRect(tile02_noborders));
EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile02_noborders));
EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
for (int frame = 0; frame < 33; ++frame) {
UpdateWholeLayer();
}
gfx::Rect viewport(0, 0, layer_size.width(), 1);
Update(layer_rect(), viewport);
EXPECT_TRUE(pile_->picture_map()
.find(TestPicturePile::PictureMapKey(0, 1))
->second.GetPicture());
EXPECT_FALSE(pile_->picture_map()
.find(TestPicturePile::PictureMapKey(0, 2))
->second.GetPicture());
EXPECT_TRUE(pile_->CanRasterLayerRect(tile01_noborders));
EXPECT_TRUE(pile_->CanRasterSlowTileCheck(tile01_noborders));
EXPECT_FALSE(pile_->CanRasterLayerRect(tile02_noborders));
EXPECT_FALSE(pile_->CanRasterSlowTileCheck(tile02_noborders));
}
TEST_F(PicturePileTest, NoInvalidationValidViewport) {
UpdateWholeLayer();
EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
Update(gfx::Rect(), layer_rect());
EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
Update(gfx::Rect(gfx::Rect(0, 0, 1, 1)), layer_rect());
EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
Update(gfx::Rect(), gfx::Rect(5, 5, 5, 5));
EXPECT_TRUE(!pile_->recorded_viewport().IsEmpty());
}
}
}