OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/test/skia_common.h" |
| 6 |
| 7 #include "cc/resources/picture.h" |
| 8 #include "skia/ext/refptr.h" |
| 9 #include "third_party/skia/include/core/SkDevice.h" |
| 10 #include "ui/gfx/rect.h" |
| 11 #include "ui/gfx/skia_util.h" |
| 12 |
| 13 namespace cc { |
| 14 |
| 15 TestPixelRef::TestPixelRef(int width, int height) |
| 16 : pixels_(new char[4 * width * height]) {} |
| 17 |
| 18 TestPixelRef::~TestPixelRef() {} |
| 19 |
| 20 SkFlattenable::Factory TestPixelRef::getFactory() { return NULL; } |
| 21 |
| 22 void* TestPixelRef::onLockPixels(SkColorTable** color_table) { |
| 23 return pixels_.get(); |
| 24 } |
| 25 |
| 26 SkPixelRef* TestPixelRef::deepCopy( |
| 27 SkBitmap::Config config, |
| 28 const SkIRect* subset) { |
| 29 this->ref(); |
| 30 return this; |
| 31 } |
| 32 |
| 33 |
| 34 TestLazyPixelRef::TestLazyPixelRef(int width, int height) |
| 35 : pixels_(new char[4 * width * height]) {} |
| 36 |
| 37 TestLazyPixelRef::~TestLazyPixelRef() {} |
| 38 |
| 39 SkFlattenable::Factory TestLazyPixelRef::getFactory() { return NULL; } |
| 40 |
| 41 void* TestLazyPixelRef::onLockPixels(SkColorTable** color_table) { |
| 42 return pixels_.get(); |
| 43 } |
| 44 |
| 45 bool TestLazyPixelRef::PrepareToDecode(const PrepareParams& params) { |
| 46 return true; |
| 47 } |
| 48 |
| 49 SkPixelRef* TestLazyPixelRef::deepCopy( |
| 50 SkBitmap::Config config, |
| 51 const SkIRect* subset) { |
| 52 this->ref(); |
| 53 return this; |
| 54 } |
| 55 |
| 56 void DrawPicture(unsigned char* buffer, |
| 57 gfx::Rect layer_rect, |
| 58 scoped_refptr<Picture> picture) { |
| 59 SkBitmap bitmap; |
| 60 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
| 61 layer_rect.width(), |
| 62 layer_rect.height()); |
| 63 bitmap.setPixels(buffer); |
| 64 SkDevice device(bitmap); |
| 65 SkCanvas canvas(&device); |
| 66 canvas.clipRect(gfx::RectToSkRect(layer_rect)); |
| 67 picture->Raster(&canvas, layer_rect, 1.0f, false); |
| 68 } |
| 69 |
| 70 void CreateBitmap(gfx::Size size, const char* uri, SkBitmap* bitmap) { |
| 71 skia::RefPtr<TestLazyPixelRef> lazy_pixel_ref = |
| 72 skia::AdoptRef(new TestLazyPixelRef(size.width(), size.height())); |
| 73 lazy_pixel_ref->setURI(uri); |
| 74 |
| 75 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 76 size.width(), |
| 77 size.height()); |
| 78 bitmap->setPixelRef(lazy_pixel_ref.get()); |
| 79 } |
| 80 |
| 81 |
| 82 } // namespace cc |
OLD | NEW |