Chromium Code Reviews| Index: cc/resources/picture_pile_impl_unittest.cc |
| diff --git a/cc/resources/picture_pile_impl_unittest.cc b/cc/resources/picture_pile_impl_unittest.cc |
| index 13a24fd9b0fe4c3de80215bca1ccd835e6e659fd..7fdb6447f0c9375245b66cd35f2e4721b9bd91df 100644 |
| --- a/cc/resources/picture_pile_impl_unittest.cc |
| +++ b/cc/resources/picture_pile_impl_unittest.cc |
| @@ -2,13 +2,61 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/memory/scoped_ptr.h" |
| #include "cc/test/fake_picture_pile_impl.h" |
| +#include "skia/ext/lazy_pixel_ref.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/skia/include/core/SkPixelRef.h" |
| +#include "third_party/skia/include/core/SkShader.h" |
| #include "ui/gfx/rect.h" |
| namespace cc { |
| namespace { |
| +class TestPixelRef : public SkPixelRef { |
| + public: |
| + // Pure virtual implementation. |
| + TestPixelRef(int width, int height) |
| + : pixels_(new char[4 * width * height]) {} |
| + virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; } |
| + virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE { |
| + return pixels_.get(); |
| + } |
| + virtual void onUnlockPixels() OVERRIDE {} |
| + virtual SkPixelRef* deepCopy( |
| + SkBitmap::Config config, |
| + const SkIRect* subset) OVERRIDE { |
| + this->ref(); |
| + return this; |
| + } |
| + private: |
| + scoped_ptr<char[]> pixels_; |
| +}; |
| + |
| +class TestLazyPixelRef : public skia::LazyPixelRef { |
| + public: |
| + // Pure virtual implementation. |
| + TestLazyPixelRef(int width, int height) |
| + : pixels_(new char[4 * width * height]) {} |
| + virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; } |
| + virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE { |
| + return pixels_.get(); |
| + } |
| + virtual void onUnlockPixels() OVERRIDE {} |
| + virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE { |
| + return true; |
| + } |
| + virtual SkPixelRef* deepCopy( |
| + SkBitmap::Config config, |
| + const SkIRect* subset) OVERRIDE { |
| + this->ref(); |
| + return this; |
| + } |
| + virtual void Decode() OVERRIDE {} |
| + private: |
| + scoped_ptr<char[]> pixels_; |
| +}; |
| + |
| 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) { |
| @@ -134,6 +182,471 @@ TEST(PicturePileImplTest, AnalyzeIsSolidScaled) { |
| EXPECT_EQ(analysis.solid_color, solid_color); |
| } |
| +TEST(PicturePileImplTest, LazyPixelRefIteratorEmpty) { |
| + gfx::Size tile_size(128, 128); |
| + gfx::Size layer_bounds(256, 256); |
| + |
| + // Create a filled pile with no recording. |
| + scoped_refptr<FakePicturePileImpl> pile = |
| + FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| + |
| + // Tile sized iterators. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 128, 128), |
| + 1.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 256, 256), |
| + 2.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 64, 64), |
| + 0.5, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + // Shifted tile sized iterators. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(140, 140, 128, 128), |
| + 1.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(280, 280, 256, 256), |
| + 2.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(70, 70, 64, 64), |
| + 0.5, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + // Layer sized iterators. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 256, 256), |
| + 1.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 512, 512), |
| + 2.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 128, 128), |
| + 0.5, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| +} |
| + |
| +TEST(PicturePileImplTest, LazyPixelRefIteratorNoLazyRefs) { |
| + gfx::Size tile_size(128, 128); |
| + gfx::Size layer_bounds(256, 256); |
| + |
| + scoped_refptr<FakePicturePileImpl> pile = |
| + FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| + |
| + SkPaint simple_paint; |
| + simple_paint.setColor(SkColorSetARGB(255, 12, 23, 34)); |
| + |
| + SkAutoTUnref<TestPixelRef> non_lazy_pixel_ref; |
| + non_lazy_pixel_ref.reset(new TestPixelRef(128, 128)); |
| + non_lazy_pixel_ref->setURI("notlazy"); |
| + |
| + SkBitmap non_lazy_bitmap; |
| + non_lazy_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 128, 128); |
| + non_lazy_bitmap.setPixelRef(non_lazy_pixel_ref); |
| + |
| + pile->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), simple_paint); |
| + pile->add_draw_rect_with_paint(gfx::Rect(128, 128, 512, 512), simple_paint); |
| + pile->add_draw_rect_with_paint(gfx::Rect(512, 0, 256, 256), simple_paint); |
| + pile->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), simple_paint); |
| + pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(128, 0)); |
| + pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(0, 128)); |
| + pile->add_draw_bitmap(non_lazy_bitmap, gfx::Point(150, 150)); |
| + |
| + RerecordPile(pile); |
| + |
| + // Tile sized iterators. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 128, 128), |
| + 1.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 256, 256), |
| + 2.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 64, 64), |
| + 0.5, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + // Shifted tile sized iterators. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(140, 140, 128, 128), |
| + 1.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(280, 280, 256, 256), |
| + 2.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(70, 70, 64, 64), |
| + 0.5, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + // Layer sized iterators. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 256, 256), |
| + 1.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 512, 512), |
| + 2.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 128, 128), |
| + 0.5, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + } |
| +} |
| + |
| +TEST(PicturePileImplTest, LazyPixelRefIteratorLazyRefs) { |
| + gfx::Size tile_size(128, 128); |
| + gfx::Size layer_bounds(256, 256); |
| + |
| + scoped_refptr<FakePicturePileImpl> pile = |
| + FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| + |
| + SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref; |
| + lazy_pixel_ref.reset(new TestLazyPixelRef(32, 32)); |
| + lazy_pixel_ref->setURI("lazy"); |
| + |
| + SkBitmap lazy_bitmap; |
| + lazy_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32, 32); |
| + lazy_bitmap.setPixelRef(lazy_pixel_ref); |
| + |
| + // Lazy pixel refs are found in the following cells: |
|
enne (OOO)
2013/04/22 19:10:56
Can you use different bitmaps per cell?
vmpstr
2013/04/22 22:38:16
Done.
|
| + // |---|---| |
| + // | x | | |
| + // |---|---| |
| + // | x | x | |
| + // |---|---| |
| + pile->add_draw_bitmap(lazy_bitmap, gfx::Point(140, 140)); |
| + pile->add_draw_bitmap(lazy_bitmap, gfx::Point(0, 0)); |
| + pile->add_draw_bitmap(lazy_bitmap, gfx::Point(0, 130)); |
| + |
| + RerecordPile(pile); |
| + |
| + // Tile sized iterators. These should find only one pixel ref. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 128, 128), |
| + 1.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 256, 256), |
| + 2.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 64, 64), |
| + 0.5, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + // Shifted tile sized iterators. These should find only one pixel ref. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(140, 140, 128, 128), |
| + 1.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(280, 280, 256, 256), |
| + 2.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(70, 70, 64, 64), |
| + 0.5, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + // Ensure there's no lazy pixel refs in the empty cell |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(140, 0, 128, 128), |
| + 1.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + // Ensure we can increment the iterator with no change |
| + EXPECT_FALSE(++iterator); |
| + EXPECT_FALSE(++iterator); |
| + EXPECT_FALSE(++iterator); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + // Layer sized iterators. These should find all 3 pixel refs. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 256, 256), |
| + 1.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 512, 512), |
| + 2.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 128, 128), |
| + 0.5, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| +} |
| + |
| +TEST(PicturePileImplTest, LazyPixelRefIteratorLazyRefsOneTile) { |
| + gfx::Size tile_size(512, 512); |
| + gfx::Size layer_bounds(1024, 1024); |
| + |
| + scoped_refptr<FakePicturePileImpl> pile = |
| + FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| + |
| + SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref; |
| + lazy_pixel_ref.reset(new TestLazyPixelRef(256, 256)); |
| + lazy_pixel_ref->setURI("lazy"); |
| + |
| + SkBitmap lazy_bitmap; |
|
enne (OOO)
2013/04/22 19:10:56
You do this a bunch. Maybe you could wrap the boi
vmpstr
2013/04/22 22:38:16
Done.
|
| + lazy_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); |
| + lazy_bitmap.setPixelRef(lazy_pixel_ref); |
| + |
| + // Lazy pixel refs are found in the following cells: |
| + // |---|---| |
| + // | x | x | |
| + // |---|---| |
| + // | | x | |
| + // |---|---| |
| + pile->add_draw_bitmap(lazy_bitmap, gfx::Point(0, 0)); |
| + pile->add_draw_bitmap(lazy_bitmap, gfx::Point(520, 520)); |
| + pile->add_draw_bitmap(lazy_bitmap, gfx::Point(520, 0)); |
| + |
| + RerecordPile(pile); |
| + |
| + // Tile sized iterators. These should find only one pixel ref. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 512, 512), |
| + 1.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 1024, 1024), |
| + 2.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 256, 256), |
| + 0.5, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + // Shifted tile sized iterators. These should find only one pixel ref. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(530, 530, 512, 512), |
| + 1.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(1060, 1060, 1024, 1024), |
| + 2.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(275, 275, 256, 256), |
| + 0.5, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + // Ensure there's no lazy pixel refs in the empty cell |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 512, 512, 512), |
| + 1.0, |
| + pile); |
| + EXPECT_FALSE(iterator); |
| + // Ensure we can increment the iterator with no change |
| + EXPECT_FALSE(++iterator); |
| + EXPECT_FALSE(++iterator); |
| + EXPECT_FALSE(++iterator); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + // Tile sized iterators. These should find only one pixel ref. |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 1024, 1024), |
| + 1.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 2048, 2048), |
| + 2.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + { |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 512, 512), |
| + 0.5, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_TRUE(*iterator == lazy_pixel_ref.get()); |
| + EXPECT_FALSE(++iterator); |
| + } |
| + |
| + // Copy test. |
| + PicturePileImpl::LazyPixelRefIterator iterator( |
| + gfx::Rect(0, 0, 1024, 1024), |
| + 1.0, |
| + pile); |
| + EXPECT_TRUE(iterator); |
| + EXPECT_TRUE(++iterator); |
| + |
| + // copy now points to the same spot as iterator, |
| + // but both can be incremented independently. |
| + PicturePileImpl::LazyPixelRefIterator copy = iterator; |
| + EXPECT_TRUE(++iterator); |
| + EXPECT_FALSE(++iterator); |
| + |
| + EXPECT_TRUE(copy); |
| + EXPECT_TRUE(++copy); |
| + EXPECT_FALSE(++copy); |
| +} |
| } // namespace |
| } // namespace cc |