summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cc/cc_tests.gyp3
-rw-r--r--cc/layers/picture_layer_impl_unittest.cc154
-rw-r--r--cc/resources/picture_pile_impl.cc11
-rw-r--r--cc/resources/picture_pile_impl.h4
-rw-r--r--cc/resources/picture_pile_impl_unittest.cc139
-rw-r--r--cc/test/fake_content_layer_client.cc14
-rw-r--r--cc/test/fake_content_layer_client.h10
-rw-r--r--cc/test/fake_picture_pile_impl.cc76
-rw-r--r--cc/test/fake_picture_pile_impl.h52
9 files changed, 335 insertions, 128 deletions
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp
index 0406810..144cfb5 100644
--- a/cc/cc_tests.gyp
+++ b/cc/cc_tests.gyp
@@ -50,6 +50,7 @@
'layers/picture_layer_impl_unittest.cc',
'resources/picture_layer_tiling_set_unittest.cc',
'resources/picture_layer_tiling_unittest.cc',
+ 'resources/picture_pile_impl_unittest.cc',
'resources/prioritized_resource_unittest.cc',
'trees/quad_culler_unittest.cc',
'base/region_unittest.cc',
@@ -104,6 +105,8 @@
'test/fake_layer_tree_host_impl.h',
'test/fake_picture_layer_tiling_client.cc',
'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.h',
'test/fake_rendering_stats_instrumentation.h',
diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc
index 4f00ed7..2dc4788 100644
--- a/cc/layers/picture_layer_impl_unittest.cc
+++ b/cc/layers/picture_layer_impl_unittest.cc
@@ -11,6 +11,7 @@
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.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/trees/layer_tree_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -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 {
public:
explicit MockCanvas(SkDevice* device) : SkCanvas(device) {}
@@ -217,10 +145,10 @@ class PictureLayerImplTest : public testing::Test {
settings.default_tile_size.width() * 7 / 2,
settings.default_tile_size.height() * 7 / 2);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateFilledPile(layer_size, layer_size);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateFilledPile(layer_size, layer_size);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateFilledPile(layer_size, layer_size);
SetupTrees(pending_pile, active_pile);
@@ -290,10 +218,10 @@ TEST_F(PictureLayerImplTest, CloneNoInvalidation) {
gfx::Size tile_size(100, 100);
gfx::Size layer_bounds(400, 400);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
SetupTrees(pending_pile, active_pile);
@@ -314,10 +242,10 @@ TEST_F(PictureLayerImplTest, ClonePartialInvalidation) {
gfx::Size layer_bounds(400, 400);
gfx::Rect layer_invalidation(150, 200, 30, 180);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
SetupTrees(pending_pile, active_pile);
@@ -351,10 +279,10 @@ TEST_F(PictureLayerImplTest, CloneFullInvalidation) {
gfx::Size tile_size(90, 80);
gfx::Size layer_bounds(300, 500);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
SetupTrees(pending_pile, active_pile);
@@ -375,11 +303,11 @@ TEST_F(PictureLayerImplTest, NoInvalidationBoundsChange) {
gfx::Size active_layer_bounds(300, 500);
gfx::Size pending_layer_bounds(400, 800);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size,
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size,
pending_layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, active_layer_bounds);
SetupTrees(pending_pile, active_pile);
@@ -415,10 +343,10 @@ TEST_F(PictureLayerImplTest, AddTilesFromNewRecording) {
gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
// Fill in some of active pile, but more of pending pile.
int hole_count = 0;
@@ -473,10 +401,10 @@ TEST_F(PictureLayerImplTest, ManageTilingsWithNoRecording) {
gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateEmptyPile(tile_size, layer_bounds);
float result_scale_x, result_scale_y;
gfx::Size result_bounds;
@@ -497,10 +425,10 @@ TEST_F(PictureLayerImplTest, ManageTilingsCreatesTilings) {
gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
float result_scale_x, result_scale_y;
gfx::Size result_bounds;
@@ -583,10 +511,10 @@ TEST_F(PictureLayerImplTest, CleanUpTilings) {
gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
float result_scale_x, result_scale_y;
gfx::Size result_bounds;
@@ -696,10 +624,10 @@ TEST_F(PictureLayerImplTest, DidLoseOutputSurface) {
gfx::Size tile_size(400, 400);
gfx::Size layer_bounds(1300, 1900);
- scoped_refptr<TestablePicturePileImpl> pending_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
- scoped_refptr<TestablePicturePileImpl> active_pile =
- TestablePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> pending_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
+ scoped_refptr<FakePicturePileImpl> active_pile =
+ FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
float result_scale_x, result_scale_y;
gfx::Size result_bounds;
diff --git a/cc/resources/picture_pile_impl.cc b/cc/resources/picture_pile_impl.cc
index 397d64c..dd30ede 100644
--- a/cc/resources/picture_pile_impl.cc
+++ b/cc/resources/picture_pile_impl.cc
@@ -242,18 +242,19 @@ skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() {
return picture;
}
-void PicturePileImpl::AnalyzeInRect(const gfx::Rect& content_rect,
+void PicturePileImpl::AnalyzeInRect(gfx::Rect content_rect,
float contents_scale,
PicturePileImpl::Analysis* analysis) {
DCHECK(analysis);
TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect");
- gfx::Rect layer_rect = gfx::ToEnclosingRect(
- gfx::ScaleRect(content_rect, 1.f / contents_scale));
+ content_rect.Intersect(gfx::Rect(gfx::ToCeiledSize(
+ gfx::ScaleSize(tiling_.total_size(), contents_scale))));
SkBitmap empty_bitmap;
- empty_bitmap.setConfig(SkBitmap::kNo_Config, content_rect.width(),
- content_rect.height());
+ empty_bitmap.setConfig(SkBitmap::kNo_Config,
+ content_rect.width(),
+ content_rect.height());
skia::AnalysisDevice device(empty_bitmap);
skia::AnalysisCanvas canvas(&device);
diff --git a/cc/resources/picture_pile_impl.h b/cc/resources/picture_pile_impl.h
index 9b49ed9..352772d 100644
--- a/cc/resources/picture_pile_impl.h
+++ b/cc/resources/picture_pile_impl.h
@@ -44,7 +44,7 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase {
skia::RefPtr<SkPicture> GetFlattenedPicture();
- struct Analysis {
+ struct CC_EXPORT Analysis {
Analysis();
~Analysis();
@@ -57,7 +57,7 @@ class CC_EXPORT PicturePileImpl : public PicturePileBase {
skia::AnalysisCanvas::LazyPixelRefList lazy_pixel_refs;
};
- void AnalyzeInRect(const gfx::Rect& content_rect,
+ void AnalyzeInRect(gfx::Rect content_rect,
float contents_scale,
Analysis* analysis);
diff --git a/cc/resources/picture_pile_impl_unittest.cc b/cc/resources/picture_pile_impl_unittest.cc
new file mode 100644
index 0000000..13a24fd
--- /dev/null
+++ b/cc/resources/picture_pile_impl_unittest.cc
@@ -0,0 +1,139 @@
+// 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
diff --git a/cc/test/fake_content_layer_client.cc b/cc/test/fake_content_layer_client.cc
index cf82de6..7153766 100644
--- a/cc/test/fake_content_layer_client.cc
+++ b/cc/test/fake_content_layer_client.cc
@@ -20,11 +20,15 @@ void FakeContentLayerClient::PaintContents(SkCanvas* canvas,
if (paint_all_opaque_)
*opaque_rect = rect;
- SkPaint paint;
- for (RectVector::const_iterator rect_it = draw_rects_.begin();
- rect_it < draw_rects_.end(); rect_it++) {
- SkRect draw_rect = SkRect::MakeXYWH(rect_it->x(), rect_it->y(),
- rect_it->width(), rect_it->height());
+ for (RectPaintVector::const_iterator it = draw_rects_.begin();
+ it < draw_rects_.end(); ++it) {
+ gfx::Rect rect = it->first;
+ SkPaint paint = it->second;
+ SkRect draw_rect = SkRect::MakeXYWH(
+ rect.x(),
+ rect.y(),
+ rect.width(),
+ rect.height());
canvas->drawRect(draw_rect, paint);
}
}
diff --git a/cc/test/fake_content_layer_client.h b/cc/test/fake_content_layer_client.h
index 462fa47..e987b11 100644
--- a/cc/test/fake_content_layer_client.h
+++ b/cc/test/fake_content_layer_client.h
@@ -5,10 +5,12 @@
#ifndef CC_TEST_FAKE_CONTENT_LAYER_CLIENT_H_
#define CC_TEST_FAKE_CONTENT_LAYER_CLIENT_H_
+#include <utility>
#include <vector>
#include "base/compiler_specific.h"
#include "cc/layers/content_layer_client.h"
+#include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/rect.h"
namespace cc {
@@ -25,13 +27,15 @@ class FakeContentLayerClient : public cc::ContentLayerClient {
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:
- typedef std::vector<gfx::Rect> RectVector;
+ typedef std::vector<std::pair<gfx::Rect, SkPaint> > RectPaintVector;
bool paint_all_opaque_;
- RectVector draw_rects_;
+ RectPaintVector draw_rects_;
};
} // namespace cc
diff --git a/cc/test/fake_picture_pile_impl.cc b/cc/test/fake_picture_pile_impl.cc
new file mode 100644
index 0000000..70d0a8d
--- /dev/null
+++ b/cc/test/fake_picture_pile_impl.cc
@@ -0,0 +1,76 @@
+// 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
diff --git a/cc/test/fake_picture_pile_impl.h b/cc/test/fake_picture_pile_impl.h
new file mode 100644
index 0000000..f3bde7b
--- /dev/null
+++ b/cc/test/fake_picture_pile_impl.h
@@ -0,0 +1,52 @@
+// 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_