| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/picture.h" | 5 #include "cc/resources/picture.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "cc/test/fake_content_layer_client.h" | 9 #include "cc/test/fake_content_layer_client.h" |
| 10 #include "cc/test/skia_common.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "third_party/skia/include/core/SkDevice.h" | 13 #include "third_party/skia/include/core/SkDevice.h" |
| 13 #include "third_party/skia/include/core/SkGraphics.h" | 14 #include "third_party/skia/include/core/SkGraphics.h" |
| 14 #include "third_party/skia/include/core/SkPixelRef.h" | 15 #include "third_party/skia/include/core/SkPixelRef.h" |
| 15 #include "third_party/skia/include/core/SkTileGridPicture.h" | 16 #include "third_party/skia/include/core/SkTileGridPicture.h" |
| 16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/skia_util.h" | 18 #include "ui/gfx/skia_util.h" |
| 18 | 19 |
| 19 namespace cc { | 20 namespace cc { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 class TestLazyPixelRef : public skia::LazyPixelRef { | |
| 23 public: | |
| 24 // Pure virtual implementation. | |
| 25 TestLazyPixelRef(int width, int height) | |
| 26 : pixels_(new char[4 * width * height]) {} | |
| 27 virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; } | |
| 28 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE { | |
| 29 return pixels_.get(); | |
| 30 } | |
| 31 virtual void onUnlockPixels() OVERRIDE {} | |
| 32 virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE { | |
| 33 return true; | |
| 34 } | |
| 35 virtual SkPixelRef* deepCopy( | |
| 36 SkBitmap::Config config, | |
| 37 const SkIRect* subset) OVERRIDE { | |
| 38 this->ref(); | |
| 39 return this; | |
| 40 } | |
| 41 virtual void Decode() OVERRIDE {} | |
| 42 private: | |
| 43 scoped_ptr<char[]> pixels_; | |
| 44 }; | |
| 45 | |
| 46 void DrawPicture(unsigned char* buffer, | |
| 47 gfx::Rect layer_rect, | |
| 48 scoped_refptr<Picture> picture) { | |
| 49 SkBitmap bitmap; | |
| 50 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | |
| 51 layer_rect.width(), | |
| 52 layer_rect.height()); | |
| 53 bitmap.setPixels(buffer); | |
| 54 SkDevice device(bitmap); | |
| 55 SkCanvas canvas(&device); | |
| 56 canvas.clipRect(gfx::RectToSkRect(layer_rect)); | |
| 57 picture->Raster(&canvas, layer_rect, 1.0f, false); | |
| 58 } | |
| 59 | |
| 60 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { | |
| 61 SkAutoTUnref<TestLazyPixelRef> lazy_pixel_ref; | |
| 62 lazy_pixel_ref.reset(new TestLazyPixelRef(size.width(), size.height())); | |
| 63 lazy_pixel_ref->setURI(uri); | |
| 64 | |
| 65 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | |
| 66 size.width(), | |
| 67 size.height()); | |
| 68 bitmap->setPixelRef(lazy_pixel_ref); | |
| 69 } | |
| 70 | |
| 71 TEST(PictureTest, AsBase64String) { | 23 TEST(PictureTest, AsBase64String) { |
| 72 SkGraphics::Init(); | 24 SkGraphics::Init(); |
| 73 | 25 |
| 74 gfx::Rect layer_rect(100, 100); | 26 gfx::Rect layer_rect(100, 100); |
| 75 | 27 |
| 76 SkTileGridPicture::TileGridInfo tile_grid_info; | 28 SkTileGridPicture::TileGridInfo tile_grid_info; |
| 77 tile_grid_info.fTileInterval = SkISize::Make(100, 100); | 29 tile_grid_info.fTileInterval = SkISize::Make(100, 100); |
| 78 tile_grid_info.fMargin.setEmpty(); | 30 tile_grid_info.fMargin.setEmpty(); |
| 79 tile_grid_info.fOffset.setZero(); | 31 tile_grid_info.fOffset.setZero(); |
| 80 | 32 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 EXPECT_TRUE(*iterator == lazy_bitmap[y][x].pixelRef()); | 379 EXPECT_TRUE(*iterator == lazy_bitmap[y][x].pixelRef()); |
| 428 EXPECT_FALSE(++iterator) << x << " " << y; | 380 EXPECT_FALSE(++iterator) << x << " " << y; |
| 429 } else { | 381 } else { |
| 430 EXPECT_FALSE(iterator) << x << " " << y; | 382 EXPECT_FALSE(iterator) << x << " " << y; |
| 431 } | 383 } |
| 432 } | 384 } |
| 433 } | 385 } |
| 434 } | 386 } |
| 435 } // namespace | 387 } // namespace |
| 436 } // namespace cc | 388 } // namespace cc |
| OLD | NEW |