| Index: cc/resources/picture_unittest.cc
|
| diff --git a/cc/resources/picture_unittest.cc b/cc/resources/picture_unittest.cc
|
| index f20c5476b9107f2f5651f57f97f7a77306667b74..a418f101c9f7a8367185632724c3fdac81eb31da 100644
|
| --- a/cc/resources/picture_unittest.cc
|
| +++ b/cc/resources/picture_unittest.cc
|
| @@ -5,11 +5,13 @@
|
| #include "cc/resources/picture.h"
|
|
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "cc/test/fake_content_layer_client.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| #include "third_party/skia/include/core/SkDevice.h"
|
| #include "third_party/skia/include/core/SkGraphics.h"
|
| +#include "third_party/skia/include/core/SkPixelRef.h"
|
| #include "third_party/skia/include/core/SkTileGridPicture.h"
|
| #include "ui/gfx/rect.h"
|
| #include "ui/gfx/skia_util.h"
|
| @@ -17,6 +19,30 @@
|
| namespace cc {
|
| namespace {
|
|
|
| +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 DrawPicture(unsigned char* buffer,
|
| gfx::Rect layer_rect,
|
| scoped_refptr<Picture> picture) {
|
| @@ -120,5 +146,101 @@ TEST(PictureTest, AsBase64String) {
|
| memcmp(two_rect_buffer, two_rect_buffer_check, 4 * 100 * 100) == 0);
|
| }
|
|
|
| +TEST(PictureTest, LazyPixelRefIterator) {
|
| + gfx::Rect layer_rect(2048, 2048);
|
| +
|
| + SkTileGridPicture::TileGridInfo tile_grid_info;
|
| + tile_grid_info.fTileInterval = SkISize::Make(100, 100);
|
| + tile_grid_info.fMargin.setEmpty();
|
| + tile_grid_info.fOffset.setZero();
|
| +
|
| + FakeContentLayerClient content_layer_client;
|
| +
|
| + 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, 500, 500);
|
| + lazy_bitmap.setPixelRef(lazy_pixel_ref);
|
| +
|
| + // Lazy pixel refs are found in the following grids:
|
| + // |---|---|---|---|
|
| + // | | x | | x |
|
| + // |---|---|---|---|
|
| + // | x | | x | |
|
| + // |---|---|---|---|
|
| + // | | x | | x |
|
| + // |---|---|---|---|
|
| + // | x | | x | |
|
| + // |---|---|---|---|
|
| + for (int y = 0; y < 4; ++y) {
|
| + for (int x = 0; x < 4; ++x) {
|
| + if ((x + y) & 1) {
|
| + content_layer_client.add_draw_bitmap(
|
| + lazy_bitmap,
|
| + gfx::Point(x * 512 + 6, y * 512 + 6));
|
| + }
|
| + }
|
| + }
|
| +
|
| + scoped_refptr<Picture> picture = Picture::Create(layer_rect);
|
| + picture->Record(&content_layer_client, NULL, tile_grid_info);
|
| +
|
| + // Default iterator does not have any pixel refs
|
| + {
|
| + Picture::LazyPixelRefIterator iterator;
|
| + EXPECT_FALSE(iterator);
|
| + // Incrementing an invalid iterator does not do anything.
|
| + EXPECT_FALSE(++iterator);
|
| + EXPECT_FALSE(++iterator);
|
| + EXPECT_FALSE(++iterator);
|
| + EXPECT_FALSE(++iterator);
|
| + }
|
| + for (int y = 0; y < 4; ++y) {
|
| + for (int x = 0; x < 4; ++x) {
|
| + Picture::LazyPixelRefIterator iterator(
|
| + gfx::Rect(x * 512, y * 512, 500, 500),
|
| + picture);
|
| + if ((x + y) & 1) {
|
| + EXPECT_TRUE(iterator) << x << " " << y;
|
| + EXPECT_FALSE(++iterator) << x << " " << y;
|
| + } else {
|
| + EXPECT_FALSE(iterator) << x << " " << y;
|
| + }
|
| + }
|
| + }
|
| + // Capture 4 pixel refs.
|
| + {
|
| + Picture::LazyPixelRefIterator iterator(
|
| + gfx::Rect(512, 512, 2048, 2048),
|
| + picture);
|
| + EXPECT_TRUE(iterator);
|
| + EXPECT_TRUE(++iterator);
|
| + EXPECT_TRUE(++iterator);
|
| + EXPECT_TRUE(++iterator);
|
| + EXPECT_FALSE(++iterator);
|
| + }
|
| +
|
| + // Copy test.
|
| + Picture::LazyPixelRefIterator iterator(
|
| + gfx::Rect(512, 512, 2048, 2048),
|
| + picture);
|
| + EXPECT_TRUE(iterator);
|
| + EXPECT_TRUE(++iterator);
|
| +
|
| + // copy now points to the same spot as iterator,
|
| + // but both can be incremented independently.
|
| + Picture::LazyPixelRefIterator copy = iterator;
|
| + EXPECT_TRUE(++iterator);
|
| + EXPECT_TRUE(++iterator);
|
| + EXPECT_FALSE(++iterator);
|
| +
|
| + EXPECT_TRUE(copy);
|
| + EXPECT_TRUE(++copy);
|
| + EXPECT_TRUE(++copy);
|
| + EXPECT_FALSE(++copy);
|
| +}
|
| +
|
| } // namespace
|
| } // namespace cc
|
|
|