| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/test/skia_common.h" | 5 #include "cc/test/skia_common.h" |
| 6 | 6 |
| 7 #include "cc/resources/picture.h" | 7 #include "cc/resources/picture.h" |
| 8 #include "skia/ext/refptr.h" | 8 #include "skia/ext/refptr.h" |
| 9 #include "third_party/skia/include/core/SkBitmapDevice.h" | 9 #include "third_party/skia/include/core/SkBitmapDevice.h" |
| 10 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 SkPixelRef* TestPixelRef::deepCopy( | 26 SkPixelRef* TestPixelRef::deepCopy( |
| 27 SkBitmap::Config config, | 27 SkBitmap::Config config, |
| 28 const SkIRect* subset) { | 28 const SkIRect* subset) { |
| 29 this->ref(); | 29 this->ref(); |
| 30 return this; | 30 return this; |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 TestLazyPixelRef::TestLazyPixelRef(const SkImageInfo& info) | |
| 35 : skia::LazyPixelRef(info), | |
| 36 pixels_(new char[4 * info.fWidth * info.fHeight]) {} | |
| 37 | |
| 38 TestLazyPixelRef::~TestLazyPixelRef() {} | |
| 39 | |
| 40 SkFlattenable::Factory TestLazyPixelRef::getFactory() const { return NULL; } | |
| 41 | |
| 42 void* TestLazyPixelRef::onLockPixels(SkColorTable** color_table) { | |
| 43 return pixels_.get(); | |
| 44 } | |
| 45 | |
| 46 bool TestLazyPixelRef::PrepareToDecode(const PrepareParams& params) { | |
| 47 return true; | |
| 48 } | |
| 49 | |
| 50 bool TestLazyPixelRef::MaybeDecoded() { | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 SkPixelRef* TestLazyPixelRef::deepCopy( | |
| 55 SkBitmap::Config config, | |
| 56 const SkIRect* subset) { | |
| 57 this->ref(); | |
| 58 return this; | |
| 59 } | |
| 60 | |
| 61 void DrawPicture(unsigned char* buffer, | 34 void DrawPicture(unsigned char* buffer, |
| 62 gfx::Rect layer_rect, | 35 gfx::Rect layer_rect, |
| 63 scoped_refptr<Picture> picture) { | 36 scoped_refptr<Picture> picture) { |
| 64 SkBitmap bitmap; | 37 SkBitmap bitmap; |
| 65 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 38 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 66 layer_rect.width(), | 39 layer_rect.width(), |
| 67 layer_rect.height()); | 40 layer_rect.height()); |
| 68 bitmap.setPixels(buffer); | 41 bitmap.setPixels(buffer); |
| 69 SkBitmapDevice device(bitmap); | 42 SkBitmapDevice device(bitmap); |
| 70 SkCanvas canvas(&device); | 43 SkCanvas canvas(&device); |
| 71 canvas.clipRect(gfx::RectToSkRect(layer_rect)); | 44 canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 72 picture->Raster(&canvas, NULL, layer_rect, 1.0f); | 45 picture->Raster(&canvas, NULL, layer_rect, 1.0f); |
| 73 } | 46 } |
| 74 | 47 |
| 75 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { | 48 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { |
| 76 SkImageInfo info = { | 49 SkImageInfo info = { |
| 77 size.width(), | 50 size.width(), |
| 78 size.height(), | 51 size.height(), |
| 79 kPMColor_SkColorType, | 52 kPMColor_SkColorType, |
| 80 kPremul_SkAlphaType | 53 kPremul_SkAlphaType |
| 81 }; | 54 }; |
| 82 | 55 |
| 83 skia::RefPtr<TestLazyPixelRef> lazy_pixel_ref = | 56 skia::RefPtr<TestPixelRef> pixel_ref = |
| 84 skia::AdoptRef(new TestLazyPixelRef(info)); | 57 skia::AdoptRef(new TestPixelRef(info)); |
| 85 lazy_pixel_ref->setURI(uri); | 58 pixel_ref->setURI(uri); |
| 86 | 59 |
| 87 bitmap->setConfig(info); | 60 bitmap->setConfig(info); |
| 88 bitmap->setPixelRef(lazy_pixel_ref.get()); | 61 bitmap->setPixelRef(pixel_ref.get()); |
| 89 } | 62 } |
| 90 | 63 |
| 91 | 64 |
| 92 } // namespace cc | 65 } // namespace cc |
| OLD | NEW |