Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(666)

Unified Diff: cc/resources/ui_resource_bitmap.cc

Issue 22870016: Update the nine patch layer to use UI resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments by danakj and aelias. Modified tests. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..852b6c0db1acdea293c72a21a6d3bcf3367ddf94 100644
--- a/cc/resources/ui_resource_bitmap.cc
+++ b/cc/resources/ui_resource_bitmap.cc
@@ -4,7 +4,9 @@
#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 {
@@ -12,6 +14,9 @@ scoped_refptr<UIResourceBitmap>
UIResourceBitmap::Create(uint8_t* pixels,
UIResourceFormat format,
gfx::Size size) {
+ // Check for a non-empty bitmap.
+ DCHECK(size.width() && size.height());
+
scoped_refptr<UIResourceBitmap> ret = new UIResourceBitmap();
ret->pixels_ = scoped_ptr<uint8_t[]>(pixels);
ret->format_ = format;
@@ -21,6 +26,18 @@ UIResourceBitmap::Create(uint8_t* pixels,
}
UIResourceBitmap::UIResourceBitmap() {}
+
UIResourceBitmap::~UIResourceBitmap() {}
+scoped_refptr<UIResourceBitmap> UIResourceBitmap::CreateFromSkBitmap(
+ const SkBitmap& skbitmap) {
+ DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config);
+
+ gfx::Size size(skbitmap.width(), skbitmap.height());
+ uint8_t* dst_pixels = new uint8_t[size.GetArea() * 4];
+ uint8_t* src_pixels = static_cast<uint8_t*>(skbitmap.getPixels());
+ memcpy(dst_pixels, src_pixels, size.GetArea() * 4);
+ return UIResourceBitmap::Create(dst_pixels, UIResourceBitmap::RGBA8, size);
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698