Chromium Code Reviews| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "cc/test/fake_picture_pile_impl.h" | 6 #include "cc/test/fake_picture_pile_impl.h" |
| 7 #include "cc/test/skia_common.h" | |
| 7 #include "skia/ext/lazy_pixel_ref.h" | 8 #include "skia/ext/lazy_pixel_ref.h" |
| 9 #include "skia/ext/refptr.h" | |
|
danakj
2013/05/17 13:56:55
unused?
| |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkPixelRef.h" | 11 #include "third_party/skia/include/core/SkPixelRef.h" |
| 10 #include "third_party/skia/include/core/SkShader.h" | 12 #include "third_party/skia/include/core/SkShader.h" |
| 11 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
| 12 | 14 |
| 13 namespace cc { | 15 namespace cc { |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 class TestPixelRef : public SkPixelRef { | |
| 17 public: | |
| 18 // Pure virtual implementation. | |
| 19 TestPixelRef(int width, int height) | |
| 20 : pixels_(new char[4 * width * height]) {} | |
| 21 virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; } | |
| 22 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE { | |
| 23 return pixels_.get(); | |
| 24 } | |
| 25 virtual void onUnlockPixels() OVERRIDE {} | |
| 26 virtual SkPixelRef* deepCopy( | |
| 27 SkBitmap::Config config, | |
| 28 const SkIRect* subset) OVERRIDE { | |
| 29 this->ref(); | |
| 30 return this; | |
| 31 } | |
| 32 private: | |
| 33 scoped_ptr<char[]> pixels_; | |
| 34 }; | |
| 35 | |
| 36 class TestLazyPixelRef : public skia::LazyPixelRef { | |
| 37 public: | |
| 38 // Pure virtual implementation. | |
| 39 TestLazyPixelRef(int width, int height) | |
| 40 : pixels_(new char[4 * width * height]) {} | |
| 41 virtual SkFlattenable::Factory getFactory() OVERRIDE { return NULL; } | |
| 42 virtual void* onLockPixels(SkColorTable** color_table) OVERRIDE { | |
| 43 return pixels_.get(); | |
| 44 } | |
| 45 virtual void onUnlockPixels() OVERRIDE {} | |
| 46 virtual bool PrepareToDecode(const PrepareParams& params) OVERRIDE { | |
| 47 return true; | |
| 48 } | |
| 49 virtual SkPixelRef* deepCopy( | |
| 50 SkBitmap::Config config, | |
| 51 const SkIRect* subset) OVERRIDE { | |
| 52 this->ref(); | |
| 53 return this; | |
| 54 } | |
| 55 virtual void Decode() OVERRIDE {} | |
| 56 private: | |
| 57 scoped_ptr<char[]> pixels_; | |
| 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(PicturePileImplTest, AnalyzeIsSolidUnscaled) { | 18 TEST(PicturePileImplTest, AnalyzeIsSolidUnscaled) { |
| 72 gfx::Size tile_size(100, 100); | 19 gfx::Size tile_size(100, 100); |
| 73 gfx::Size layer_bounds(400, 400); | 20 gfx::Size layer_bounds(400, 400); |
| 74 | 21 |
| 75 scoped_refptr<FakePicturePileImpl> pile = | 22 scoped_refptr<FakePicturePileImpl> pile = |
| 76 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 23 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 77 | 24 |
| 78 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 25 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
| 79 SkPaint solid_paint; | 26 SkPaint solid_paint; |
| 80 solid_paint.setColor(solid_color); | 27 solid_paint.setColor(solid_color); |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 PicturePileImpl::PixelRefIterator iterator( | 798 PicturePileImpl::PixelRefIterator iterator( |
| 852 gfx::Rect(0, 128, 128, 128), | 799 gfx::Rect(0, 128, 128, 128), |
| 853 1.0, | 800 1.0, |
| 854 pile); | 801 pile); |
| 855 EXPECT_FALSE(iterator); | 802 EXPECT_FALSE(iterator); |
| 856 } | 803 } |
| 857 } | 804 } |
| 858 | 805 |
| 859 } // namespace | 806 } // namespace |
| 860 } // namespace cc | 807 } // namespace cc |
| OLD | NEW |