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

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: changed from raw SkPixelRef pointers to skia::RefPtr<SkPixelRef> Created 7 years, 3 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..f68c9f4bfda26b130dd06a18ea52fa6dccd06d33 100644
--- a/cc/resources/ui_resource_bitmap.cc
+++ b/cc/resources/ui_resource_bitmap.cc
@@ -4,23 +4,60 @@
#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());
+}
- return ret;
+void UIResourceBitmap::Create(const skia::RefPtr<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;
}
-UIResourceBitmap::UIResourceBitmap() {}
+UIResourceBitmap::UIResourceBitmap(const SkBitmap& skbitmap) {
+ DCHECK_EQ(skbitmap.config(), SkBitmap::kARGB_8888_Config);
+ skia::RefPtr<SkPixelRef> pixel_ref;
+ SkBitmap skbitmap_copy;
+ if (skbitmap.isImmutable()) {
+ pixel_ref = skia::SharePtr(skbitmap.pixelRef());
+ } else {
+ skbitmap.copyTo(&skbitmap_copy, skbitmap.config());
+ skbitmap_copy.setImmutable();
+ pixel_ref = skia::SharePtr(skbitmap_copy.pixelRef());
+ }
+
+ Create(pixel_ref,
+ UIResourceBitmap::RGBA8,
+ gfx::Size(skbitmap.width(), skbitmap.height()));
+}
+
+UIResourceBitmap::UIResourceBitmap(const UIResourceBitmap& src)
+ : format_(INVALID_FORMAT), size_(gfx::Size()) {
+ (*this) = src;
+}
+
+UIResourceBitmap& UIResourceBitmap::operator=(const UIResourceBitmap& src) {
+ format_ = src.format_;
+ size_ = src.size_;
+ pixel_ref_ = src.pixel_ref_;
+ return *this;
+}
+
+UIResourceBitmap::UIResourceBitmap()
+ : format_(INVALID_FORMAT), size_(gfx::Size()) {}
+
UIResourceBitmap::~UIResourceBitmap() {}
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698