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

Unified Diff: src/image/SkImage.cpp

Issue 1208993017: Add image->bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add check for immutable Created 5 years, 5 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
« no previous file with comments | « include/core/SkImage.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage.cpp
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 3817733942d4efcc5f80a1c42688912a2bd41c57..e8a3ead2b11a3015cae907cd7a014aac7051ea1f 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -257,6 +257,29 @@ SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
return SkNewImageFromRasterBitmap(bm, false, NULL);
}
+bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
+ return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
+}
+
+bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
+ // As the base-class, all we can do is make a copy (regardless of mode).
+ // Subclasses that want to be more optimal should override.
+ SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(),
+ this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
+ if (!bitmap->tryAllocPixels(info)) {
+ return false;
+ }
+ if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
+ bitmap->reset();
+ return false;
+ }
+
+ if (kRO_LegacyBitmapMode == mode) {
+ bitmap->setImmutable();
+ }
+ return true;
+}
+
//////////////////////////////////////////////////////////////////////////////////////
#if !SK_SUPPORT_GPU
« no previous file with comments | « include/core/SkImage.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698