diff options
author | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-25 22:00:51 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-25 22:00:51 +0000 |
commit | 0046982c81ef5cf5cca021ec4bb1bfc83d0c3973 (patch) | |
tree | a601b47203a8a032442be78df0df496d42c7f37b /cc/resources/ui_resource_bitmap.cc | |
parent | c14865ce46b841b4b2f86f8016e42939b8387022 (diff) | |
download | chromium_src-0046982c81ef5cf5cca021ec4bb1bfc83d0c3973.zip chromium_src-0046982c81ef5cf5cca021ec4bb1bfc83d0c3973.tar.gz chromium_src-0046982c81ef5cf5cca021ec4bb1bfc83d0c3973.tar.bz2 |
SkColorType instead of (deprecated) SkBitmap::Config
Part of this refactoring was the recognition of a common pattern:
- setConfig + alloc + setImmutable + pass_to_UIResourceBitmap
This CL introduces a direct way on UIResourceBitmap to create such a bitmap, by just specifying its dimensions. This encapsulates internal requirements (e.g. colortype and immutability).
Review URL: https://codereview.chromium.org/197883017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259349 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources/ui_resource_bitmap.cc')
-rw-r--r-- | cc/resources/ui_resource_bitmap.cc | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/cc/resources/ui_resource_bitmap.cc b/cc/resources/ui_resource_bitmap.cc index 562e13a..58df9d9 100644 --- a/cc/resources/ui_resource_bitmap.cc +++ b/cc/resources/ui_resource_bitmap.cc @@ -13,7 +13,7 @@ namespace cc { void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref, - gfx::Size size, + const gfx::Size& size, UIResourceFormat format) { DCHECK(size.width()); DCHECK(size.height()); @@ -29,7 +29,7 @@ void UIResourceBitmap::Create(const skia::RefPtr<SkPixelRef>& pixel_ref, } UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { - DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config); + DCHECK_EQ(skbitmap.colorType(), kPMColor_SkColorType); DCHECK_EQ(skbitmap.width(), skbitmap.rowBytesAsPixels()); DCHECK(skbitmap.isImmutable()); @@ -41,8 +41,19 @@ UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) { SetOpaque(skbitmap.isOpaque()); } +UIResourceBitmap::UIResourceBitmap(const gfx::Size& size, bool is_opaque) { + SkAlphaType alphaType = is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; + SkImageInfo info = + SkImageInfo::MakeN32(size.width(), size.height(), alphaType); + skia::RefPtr<SkPixelRef> pixel_ref = skia::AdoptRef( + SkMallocPixelRef::NewAllocate(info, info.minRowBytes(), NULL)); + pixel_ref->setImmutable(); + Create(pixel_ref, size, UIResourceBitmap::RGBA8); + SetOpaque(is_opaque); +} + UIResourceBitmap::UIResourceBitmap(const skia::RefPtr<SkPixelRef>& pixel_ref, - gfx::Size size) { + const gfx::Size& size) { Create(pixel_ref, size, UIResourceBitmap::ETC1); } |