Commit c410a989 authored by vmpstr@chromium.org's avatar vmpstr@chromium.org

cc: Only consider layer clipped content rect for analysis

This fixes a problem in which tiles that are on the right and bottom edges of the viewport are not considered solid, even when the visible part of them is solid.

BUG=230875

Review URL: https://chromiumcodereview.appspot.com/14205005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195103 0039d316-1c4b-4281-b951-d872f2087c98
parent d5f4177d
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
'layers/picture_layer_impl_unittest.cc', 'layers/picture_layer_impl_unittest.cc',
'resources/picture_layer_tiling_set_unittest.cc', 'resources/picture_layer_tiling_set_unittest.cc',
'resources/picture_layer_tiling_unittest.cc', 'resources/picture_layer_tiling_unittest.cc',
'resources/picture_pile_impl_unittest.cc',
'resources/prioritized_resource_unittest.cc', 'resources/prioritized_resource_unittest.cc',
'trees/quad_culler_unittest.cc', 'trees/quad_culler_unittest.cc',
'base/region_unittest.cc', 'base/region_unittest.cc',
...@@ -104,6 +105,8 @@ ...@@ -104,6 +105,8 @@
'test/fake_layer_tree_host_impl.h', 'test/fake_layer_tree_host_impl.h',
'test/fake_picture_layer_tiling_client.cc', 'test/fake_picture_layer_tiling_client.cc',
'test/fake_picture_layer_tiling_client.h', 'test/fake_picture_layer_tiling_client.h',
'test/fake_picture_pile_impl.cc',
'test/fake_picture_pile_impl.h',
'test/fake_proxy.cc', 'test/fake_proxy.cc',
'test/fake_proxy.h', 'test/fake_proxy.h',
'test/fake_rendering_stats_instrumentation.h', 'test/fake_rendering_stats_instrumentation.h',
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "cc/test/fake_impl_proxy.h" #include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h" #include "cc/test/fake_output_surface.h"
#include "cc/test/fake_picture_pile_impl.h"
#include "cc/test/impl_side_painting_settings.h" #include "cc/test/impl_side_painting_settings.h"
#include "cc/trees/layer_tree_impl.h" #include "cc/trees/layer_tree_impl.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -55,79 +56,6 @@ class TestablePictureLayerImpl : public PictureLayerImpl { ...@@ -55,79 +56,6 @@ class TestablePictureLayerImpl : public PictureLayerImpl {
} }
}; };
class TestablePicturePileImpl : public PicturePileImpl {
public:
static scoped_refptr<TestablePicturePileImpl> CreateFilledPile(
gfx::Size tile_size,
gfx::Size layer_bounds) {
scoped_refptr<TestablePicturePileImpl> pile(new TestablePicturePileImpl());
pile->tiling().SetTotalSize(layer_bounds);
pile->tiling().SetMaxTextureSize(tile_size);
pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) {
for (int y = 0; y < pile->tiling().num_tiles_y(); ++y)
pile->AddRecordingAt(x, y);
}
pile->UpdateRecordedRegion();
return pile;
}
static scoped_refptr<TestablePicturePileImpl> CreateEmptyPile(
gfx::Size tile_size,
gfx::Size layer_bounds) {
scoped_refptr<TestablePicturePileImpl> pile(new TestablePicturePileImpl());
pile->tiling().SetTotalSize(layer_bounds);
pile->tiling().SetMaxTextureSize(tile_size);
pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
pile->UpdateRecordedRegion();
return pile;
}
TilingData& tiling() { return tiling_; }
void AddRecordingAt(int x, int y) {
EXPECT_GE(x, 0);
EXPECT_GE(y, 0);
EXPECT_LT(x, tiling_.num_tiles_x());
EXPECT_LT(y, tiling_.num_tiles_y());
if (HasRecordingAt(x, y))
return;
gfx::Rect bounds(tiling().TileBounds(x, y));
scoped_refptr<Picture> picture(Picture::Create(bounds));
picture->Record(&client_, NULL, tile_grid_info_);
picture_list_map_[std::pair<int, int>(x, y)].push_back(picture);
EXPECT_TRUE(HasRecordingAt(x, y));
UpdateRecordedRegion();
}
void RemoveRecordingAt(int x, int y) {
EXPECT_GE(x, 0);
EXPECT_GE(y, 0);
EXPECT_LT(x, tiling_.num_tiles_x());
EXPECT_LT(y, tiling_.num_tiles_y());
if (!HasRecordingAt(x, y))
return;
picture_list_map_.erase(std::pair<int, int>(x, y));
EXPECT_FALSE(HasRecordingAt(x, y));
UpdateRecordedRegion();
}
void add_draw_rect(const gfx::Rect& rect) {
client_.add_draw_rect(rect);
}
protected:
TestablePicturePileImpl() : PicturePileImpl(false) {}
virtual ~TestablePicturePileImpl() {}
FakeContentLayerClient client_;
};
class MockCanvas : public SkCanvas { class MockCanvas : public SkCanvas {
public: public:
explicit MockCanvas(SkDevice* device) : SkCanvas(device) {} explicit MockCanvas(SkDevice* device) : SkCanvas(device) {}
...@@ -217,10 +145,10 @@ class PictureLayerImplTest : public testing::Test { ...@@ -217,10 +145,10 @@ class PictureLayerImplTest : public testing::Test {
settings.default_tile_size.width() * 7 / 2, settings.default_tile_size.width() * 7 / 2,
settings.default_tile_size.height() * 7 / 2); settings.default_tile_size.height() * 7 / 2);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateFilledPile(layer_size, layer_size); FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateFilledPile(layer_size, layer_size); FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
SetupTrees(pending_pile, active_pile); SetupTrees(pending_pile, active_pile);
...@@ -290,10 +218,10 @@ TEST_F(PictureLayerImplTest, CloneNoInvalidation) { ...@@ -290,10 +218,10 @@ TEST_F(PictureLayerImplTest, CloneNoInvalidation) {
gfx::Size tile_size(100, 100); gfx::Size tile_size(100, 100);
gfx::Size layer_bounds(400, 400); gfx::Size layer_bounds(400, 400);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
SetupTrees(pending_pile, active_pile); SetupTrees(pending_pile, active_pile);
...@@ -314,10 +242,10 @@ TEST_F(PictureLayerImplTest, ClonePartialInvalidation) { ...@@ -314,10 +242,10 @@ TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
gfx::Size layer_bounds(400, 400); gfx::Size layer_bounds(400, 400);
gfx::Rect layer_invalidation(150, 200, 30, 180); gfx::Rect layer_invalidation(150, 200, 30, 180);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
SetupTrees(pending_pile, active_pile); SetupTrees(pending_pile, active_pile);
...@@ -351,10 +279,10 @@ TEST_F(PictureLayerImplTest, CloneFullInvalidation) { ...@@ -351,10 +279,10 @@ TEST_F(PictureLayerImplTest, CloneFullInvalidation) {
gfx::Size tile_size(90, 80); gfx::Size tile_size(90, 80);
gfx::Size layer_bounds(300, 500); gfx::Size layer_bounds(300, 500);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
SetupTrees(pending_pile, active_pile); SetupTrees(pending_pile, active_pile);
...@@ -375,11 +303,11 @@ TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) { ...@@ -375,11 +303,11 @@ TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) {
gfx::Size active_layer_bounds(300, 500); gfx::Size active_layer_bounds(300, 500);
gfx::Size pending_layer_bounds(400, 800); gfx::Size pending_layer_bounds(400, 800);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, FakePicturePileImpl::CreateFilledPile(tile_size,
pending_layer_bounds); pending_layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
SetupTrees(pending_pile, active_pile); SetupTrees(pending_pile, active_pile);
...@@ -415,10 +343,10 @@ TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) { ...@@ -415,10 +343,10 @@ TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) {
gfx::Size tile_size(400, 400); gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900); gfx::Size layer_bounds(1300, 1900);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
// Fill in some of active pile, but more of pending pile. // Fill in some of active pile, but more of pending pile.
int hole_count = 0; int hole_count = 0;
...@@ -473,10 +401,10 @@ TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) { ...@@ -473,10 +401,10 @@ TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) {
gfx::Size tile_size(400, 400); gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900); gfx::Size layer_bounds(1300, 1900);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds); FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
float result_scale_x, result_scale_y; float result_scale_x, result_scale_y;
gfx::Size result_bounds; gfx::Size result_bounds;
...@@ -497,10 +425,10 @@ TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) { ...@@ -497,10 +425,10 @@ TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) {
gfx::Size tile_size(400, 400); gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900); gfx::Size layer_bounds(1300, 1900);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
float result_scale_x, result_scale_y; float result_scale_x, result_scale_y;
gfx::Size result_bounds; gfx::Size result_bounds;
...@@ -583,10 +511,10 @@ TEST_F(PictureLayerImplTest, CleanUpTilings) { ...@@ -583,10 +511,10 @@ TEST_F(PictureLayerImplTest, CleanUpTilings) {
gfx::Size tile_size(400, 400); gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900); gfx::Size layer_bounds(1300, 1900);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
float result_scale_x, result_scale_y; float result_scale_x, result_scale_y;
gfx::Size result_bounds; gfx::Size result_bounds;
...@@ -696,10 +624,10 @@ TEST_F(PictureLayerImplTest, DidLoseOutputSurface) { ...@@ -696,10 +624,10 @@ TEST_F(PictureLayerImplTest, DidLoseOutputSurface) {
gfx::Size tile_size(400, 400); gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900); gfx::Size layer_bounds(1300, 1900);
scoped_refptr<TestablePicturePileImpl> pending_pile = scoped_refptr<FakePicturePileImpl> pending_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
scoped_refptr<TestablePicturePileImpl> active_pile = scoped_refptr<FakePicturePileImpl> active_pile =
TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
float result_scale_x, result_scale_y; float result_scale_x, result_scale_y;
gfx::Size result_bounds; gfx::Size result_bounds;
......
...@@ -242,18 +242,19 @@ skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { ...@@ -242,18 +242,19 @@ skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() {
return picture; return picture;
} }
void PicturePileImpl::AnalyzeInRect(const gfx::Rect& content_rect, void PicturePileImpl::AnalyzeInRect(gfx::Rect content_rect,
float contents_scale, float contents_scale,
PicturePileImpl::Analysis* analysis) { PicturePileImpl::Analysis* analysis) {
DCHECK(analysis); DCHECK(analysis);
TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect");
gfx::Rect layer_rect = gfx::ToEnclosingRect( content_rect.Intersect(gfx::Rect(gfx::ToCeiledSize(
gfx::ScaleRect(content_rect, 1.f / contents_scale)); gfx::ScaleSize(tiling_.total_size(), contents_scale))));
SkBitmap empty_bitmap; SkBitmap empty_bitmap;
empty_bitmap.setConfig(SkBitmap::kNo_Config, content_rect.width(), empty_bitmap.setConfig(SkBitmap::kNo_Config,
content_rect.height()); content_rect.width(),
content_rect.height());
skia::AnalysisDevice device(empty_bitmap); skia::AnalysisDevice device(empty_bitmap);
skia::AnalysisCanvas canvas(&device); skia::AnalysisCanvas canvas(&device);
......
...@@ -44,7 +44,7 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase { ...@@ -44,7 +44,7 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase {
skia::RefPtr<SkPicture> GetFlattenedPicture(); skia::RefPtr<SkPicture> GetFlattenedPicture();
struct Analysis { struct CC_EXPORT Analysis {
Analysis(); Analysis();
~Analysis(); ~Analysis();
...@@ -57,7 +57,7 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase { ...@@ -57,7 +57,7 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase {
skia::AnalysisCanvas::LazyPixelRefList lazy_pixel_refs; skia::AnalysisCanvas::LazyPixelRefList lazy_pixel_refs;
}; };
void AnalyzeInRect(const gfx::Rect& content_rect, void AnalyzeInRect(gfx::Rect content_rect,
float contents_scale, float contents_scale,
Analysis* analysis); Analysis* analysis);
......
// Copyright 2013 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.
#include "cc/test/fake_picture_pile_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/rect.h"
namespace cc {
namespace {
void RerecordPile(scoped_refptr<FakePicturePileImpl> pile) {
for (int y = 0; y < pile->num_tiles_y(); ++y) {
for (int x = 0; x < pile->num_tiles_x(); ++x) {
pile->RemoveRecordingAt(x, y);
pile->AddRecordingAt(x, y);
}
}
}
TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) {
gfx::Size tile_size(100, 100);
gfx::Size layer_bounds(400, 400);
scoped_refptr<FakePicturePileImpl> pile =
FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
SkPaint solid_paint;
solid_paint.setColor(solid_color);
SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
SkPaint non_solid_paint;
non_solid_paint.setColor(non_solid_color);
pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint);
RerecordPile(pile);
// Ensure everything is solid
for (int y = 0; y <= 300; y += 100) {
for (int x = 0; x <= 300; x += 100) {
PicturePileImpl::Analysis analysis;
gfx::Rect rect(x, y, 100, 100);
pile->AnalyzeInRect(rect, 1.0, &analysis);
EXPECT_TRUE(analysis.is_solid_color) << rect.ToString();
EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString();
}
}
// One pixel non solid
pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint);
RerecordPile(pile);
PicturePileImpl::Analysis analysis;
pile->AnalyzeInRect(gfx::Rect(0, 0, 100, 100), 1.0, &analysis);
EXPECT_FALSE(analysis.is_solid_color);
pile->AnalyzeInRect(gfx::Rect(100, 0, 100, 100), 1.0, &analysis);
EXPECT_TRUE(analysis.is_solid_color);
EXPECT_EQ(analysis.solid_color, solid_color);
// Boundaries should be clipped
analysis.is_solid_color = false;
pile->AnalyzeInRect(gfx::Rect(350, 0, 100, 100), 1.0, &analysis);
EXPECT_TRUE(analysis.is_solid_color);
EXPECT_EQ(analysis.solid_color, solid_color);
analysis.is_solid_color = false;
pile->AnalyzeInRect(gfx::Rect(0, 350, 100, 100), 1.0, &analysis);
EXPECT_TRUE(analysis.is_solid_color);
EXPECT_EQ(analysis.solid_color, solid_color);
analysis.is_solid_color = false;
pile->AnalyzeInRect(gfx::Rect(350, 350, 100, 100), 1.0, &analysis);
EXPECT_TRUE(analysis.is_solid_color);
EXPECT_EQ(analysis.solid_color, solid_color);
}
TEST(PicturePileImplTest, AnalyzeIsSolidScaled) {
gfx::Size tile_size(100, 100);
gfx::Size layer_bounds(400, 400);
scoped_refptr<FakePicturePileImpl> pile =
FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
SkPaint solid_paint;
solid_paint.setColor(solid_color);
SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
SkPaint non_solid_paint;
non_solid_paint.setColor(non_solid_color);
pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), solid_paint);
RerecordPile(pile);
// Ensure everything is solid
for (int y = 0; y <= 30; y += 10) {
for (int x = 0; x <= 30; x += 10) {
PicturePileImpl::Analysis analysis;
gfx::Rect rect(x, y, 10, 10);
pile->AnalyzeInRect(rect, 0.1f, &analysis);
EXPECT_TRUE(analysis.is_solid_color) << rect.ToString();
EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString();
}
}
// One pixel non solid
pile->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), non_solid_paint);
RerecordPile(pile);
PicturePileImpl::Analysis analysis;
pile->AnalyzeInRect(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis);
EXPECT_FALSE(analysis.is_solid_color);
pile->AnalyzeInRect(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis);
EXPECT_TRUE(analysis.is_solid_color);
EXPECT_EQ(analysis.solid_color, solid_color);
// Boundaries should be clipped
analysis.is_solid_color = false;
pile->AnalyzeInRect(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis);
EXPECT_TRUE(analysis.is_solid_color);
EXPECT_EQ(analysis.solid_color, solid_color);
analysis.is_solid_color = false;
pile->AnalyzeInRect(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis);
EXPECT_TRUE(analysis.is_solid_color);
EXPECT_EQ(analysis.solid_color, solid_color);
analysis.is_solid_color = false;
pile->AnalyzeInRect(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis);
EXPECT_TRUE(analysis.is_solid_color);
EXPECT_EQ(analysis.solid_color, solid_color);
}
} // namespace
} // namespace cc
...@@ -20,11 +20,15 @@ void FakeContentLayerClient::PaintContents(SkCanvas* canvas, ...@@ -20,11 +20,15 @@ void FakeContentLayerClient::PaintContents(SkCanvas* canvas,
if (paint_all_opaque_) if (paint_all_opaque_)
*opaque_rect = rect; *opaque_rect = rect;
SkPaint paint; for (RectPaintVector::const_iterator it = draw_rects_.begin();
for (RectVector::const_iterator rect_it = draw_rects_.begin(); it < draw_rects_.end(); ++it) {
rect_it < draw_rects_.end(); rect_it++) { gfx::Rect rect = it->first;
SkRect draw_rect = SkRect::MakeXYWH(rect_it->x(), rect_it->y(), SkPaint paint = it->second;
rect_it->width(), rect_it->height()); SkRect draw_rect = SkRect::MakeXYWH(
rect.x(),
rect.y(),
rect.width(),
rect.height());
canvas->drawRect(draw_rect, paint); canvas->drawRect(draw_rect, paint);
} }
} }
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#ifndef CC_TEST_FAKE_CONTENT_LAYER_CLIENT_H_ #ifndef CC_TEST_FAKE_CONTENT_LAYER_CLIENT_H_
#define CC_TEST_FAKE_CONTENT_LAYER_CLIENT_H_ #define CC_TEST_FAKE_CONTENT_LAYER_CLIENT_H_
#include <utility>
#include <vector> #include <vector>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "cc/layers/content_layer_client.h" #include "cc/layers/content_layer_client.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
namespace cc { namespace cc {
...@@ -25,13 +27,15 @@ class FakeContentLayerClient : public cc::ContentLayerClient { ...@@ -25,13 +27,15 @@ class FakeContentLayerClient : public cc::ContentLayerClient {
void set_paint_all_opaque(bool opaque) { paint_all_opaque_ = opaque; } void set_paint_all_opaque(bool opaque) { paint_all_opaque_ = opaque; }
void add_draw_rect(const gfx::Rect& rect) { draw_rects_.push_back(rect); } void add_draw_rect(const gfx::Rect& rect, const SkPaint& paint) {
draw_rects_.push_back(std::make_pair(rect, paint));
}
private: private:
typedef std::vector<gfx::Rect> RectVector; typedef std::vector<std::pair<gfx::Rect, SkPaint> > RectPaintVector;
bool paint_all_opaque_; bool paint_all_opaque_;
RectVector draw_rects_; RectPaintVector draw_rects_;
}; };
} // namespace cc } // namespace cc
......
// Copyright 2013 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.
#include "cc/test/fake_picture_pile_impl.h"
#include <utility>
#include "cc/test/impl_side_painting_settings.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
FakePicturePileImpl::FakePicturePileImpl()
: PicturePileImpl(false) {}
FakePicturePileImpl::~FakePicturePileImpl() {}
scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateFilledPile(
gfx::Size tile_size,
gfx::Size layer_bounds) {
scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
pile->tiling().SetTotalSize(layer_bounds);
pile->tiling().SetMaxTextureSize(tile_size);
pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
for (int x = 0; x < pile->tiling().num_tiles_x(); ++x) {
for (int y = 0; y < pile->tiling().num_tiles_y(); ++y)
pile->AddRecordingAt(x, y);
}
pile->UpdateRecordedRegion();
return pile;
}
scoped_refptr<FakePicturePileImpl> FakePicturePileImpl::CreateEmptyPile(
gfx::Size tile_size,
gfx::Size layer_bounds) {
scoped_refptr<FakePicturePileImpl> pile(new FakePicturePileImpl());
pile->tiling().SetTotalSize(layer_bounds);
pile->tiling().SetMaxTextureSize(tile_size);
pile->SetTileGridSize(ImplSidePaintingSettings().default_tile_size);
pile->UpdateRecordedRegion();
return pile;
}
void FakePicturePileImpl::AddRecordingAt(int x, int y) {
EXPECT_GE(x, 0);
EXPECT_GE(y, 0);
EXPECT_LT(x, tiling_.num_tiles_x());
EXPECT_LT(y, tiling_.num_tiles_y());
if (HasRecordingAt(x, y))
return;
gfx::Rect bounds(tiling().TileBounds(x, y));
scoped_refptr<Picture> picture(Picture::Create(bounds));
picture->Record(&client_, NULL, tile_grid_info_);
picture_list_map_[std::pair<int, int>(x, y)].push_back(picture);
EXPECT_TRUE(HasRecordingAt(x, y));
UpdateRecordedRegion();
}
void FakePicturePileImpl::RemoveRecordingAt(int x, int y) {
EXPECT_GE(x, 0);
EXPECT_GE(y, 0);
EXPECT_LT(x, tiling_.num_tiles_x());
EXPECT_LT(y, tiling_.num_tiles_y());
if (!HasRecordingAt(x, y))
return;
picture_list_map_.erase(std::pair<int, int>(x, y));
EXPECT_FALSE(HasRecordingAt(x, y));
UpdateRecordedRegion();
}
} // namespace cc
// Copyright 2013 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.
#ifndef CC_TEST_FAKE_PICTURE_PILE_IMPL_H_
#define CC_TEST_FAKE_PICTURE_PILE_IMPL_H_
#include "base/memory/ref_counted.h"
#include "cc/resources/picture_pile_impl.h"
#include "cc/test/fake_content_layer_client.h"
namespace cc {
class FakePicturePileImpl : public PicturePileImpl {
public:
static scoped_refptr<FakePicturePileImpl> CreateFilledPile(
gfx::Size tile_size,
gfx::Size layer_bounds);
static scoped_refptr<FakePicturePileImpl> CreateEmptyPile(
gfx::Size tile_size,
gfx::Size layer_bounds);
TilingData& tiling() { return tiling_; }
void AddRecordingAt(int x, int y);
void RemoveRecordingAt(int x, int y);
void add_draw_rect(const gfx::Rect& rect) {
client_.add_draw_rect(rect, default_paint_);
}
void add_draw_rect_with_paint(gfx::Rect rect, const SkPaint& paint) {
client_.add_draw_rect(rect, paint);
}
void set_default_paint(const SkPaint& paint) {
default_paint_ = paint;
}
protected:
FakePicturePileImpl();
virtual ~FakePicturePileImpl();
FakeContentLayerClient client_;
SkPaint default_paint_;
};
} // namespace cc
#endif // CC_TEST_FAKE_PICTURE_PILE_IMPL_H_
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