Chromium Code Reviews| Index: cc/resources/ui_resource_bitmap.cc |
| diff --git a/cc/resources/ui_resource_bitmap.cc b/cc/resources/ui_resource_bitmap.cc |
| index 8bbfb37deee70a1ebaede084bea89fcc1361064d..dade09da6a225940e9b334754e055b5b6d0fc93c 100644 |
| --- a/cc/resources/ui_resource_bitmap.cc |
| +++ b/cc/resources/ui_resource_bitmap.cc |
| @@ -4,23 +4,74 @@ |
| #include "cc/resources/ui_resource_bitmap.h" |
| +#include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "third_party/skia/include/core/SkBitmap.h" |
| namespace cc { |
| -scoped_refptr<UIResourceBitmap> |
| -UIResourceBitmap::Create(uint8_t* pixels, |
| - UIResourceFormat format, |
| - gfx::Size size) { |
| - scoped_refptr<UIResourceBitmap> ret = new UIResourceBitmap(); |
| - ret->pixels_ = scoped_ptr<uint8_t[]>(pixels); |
| - ret->format_ = format; |
| - ret->size_ = size; |
| +uint8_t* UIResourceBitmap::GetPixels() const { |
| + if (!pixel_ref_) |
| + return NULL; |
| + return static_cast<uint8_t*>(pixel_ref_->pixels()); |
| +} |
| + |
| +void UIResourceBitmap::Create(SkPixelRef* pixel_ref, |
| + UIResourceFormat format, |
| + gfx::Size size) { |
| + DCHECK(size.width() && size.height()); |
| + DCHECK(pixel_ref && pixel_ref->isImmutable()); |
| + format_ = format; |
| + size_ = size; |
| + pixel_ref_ = pixel_ref; |
| + SkSafeRef(pixel_ref_); |
| +} |
| + |
| +UIResourceBitmap::UIResourceBitmap(SkPixelRef* pixel_ref, |
| + UIResourceFormat format, |
| + gfx::Size size) { |
| + Create(pixel_ref, format, size); |
| +} |
| + |
| +UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { |
| + DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config); |
|
aelias_OOO_until_Jul13
2013/09/06 04:17:37
Please also DCHECK(skbitmap.width(), skbitmap.rowB
powei
2013/09/10 00:42:44
Done.
|
| + SkPixelRef* pixel_ref = NULL; |
| + SkBitmap skbitmap_copy; |
| + if (skbitmap.isImmutable()) { |
| + pixel_ref = skbitmap.pixelRef(); |
| + } else { |
| + skbitmap.copyTo(&skbitmap_copy, skbitmap.config()); |
|
aelias_OOO_until_Jul13
2013/09/06 04:17:37
Please DCHECK that the SkBitmap is immutable inste
powei
2013/09/10 00:42:44
Done.
|
| + skbitmap_copy.setImmutable(); |
| + pixel_ref = skbitmap_copy.pixelRef(); |
| + } |
| + |
| + Create(pixel_ref, |
| + UIResourceBitmap::RGBA8, |
| + gfx::Size(skbitmap.width(), skbitmap.height())); |
| +} |
| - return ret; |
| +UIResourceBitmap::UIResourceBitmap(const UIResourceBitmap& src) |
| + : pixel_ref_(NULL), format_(INVALID_FORMAT), size_(gfx::Size()) { |
| + (*this) = src; |
| } |
| -UIResourceBitmap::UIResourceBitmap() {} |
| -UIResourceBitmap::~UIResourceBitmap() {} |
| +UIResourceBitmap& UIResourceBitmap::operator=(const UIResourceBitmap& src) { |
| + SkSafeUnref(pixel_ref_); |
| + |
| + pixel_ref_ = src.pixel_ref_; |
| + format_ = src.format_; |
| + size_ = src.size_; |
| + |
| + SkSafeRef(pixel_ref_); |
| + return *this; |
| +} |
| + |
| +UIResourceBitmap::UIResourceBitmap() |
| + : pixel_ref_(NULL), format_(INVALID_FORMAT), size_(gfx::Size()) { |
| +} |
| + |
| +UIResourceBitmap::~UIResourceBitmap() { |
| + SkSafeUnref(pixel_ref_); |
| +} |
| } // namespace cc |