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

Unified Diff: src/core/SkBitmap.cpp

Issue 143073008: add installPixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 6 years, 11 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/SkPixelRef.h ('k') | src/core/SkBitmapDevice.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmap.cpp
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 2464d5d5967409f77d87ce7cbf26cc5e4b82ab4d..9227906eab643a60d51e008d0a1d631176c81419 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -488,13 +488,67 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) {
bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) {
HeapAllocator stdalloc;
-
+
if (NULL == allocator) {
allocator = &stdalloc;
}
return allocator->allocPixelRef(this, ctable);
}
+///////////////////////////////////////////////////////////////////////////////
+
+static bool reset_return_false(SkBitmap* bm) {
+ bm->reset();
+ return false;
+}
+
+bool SkBitmap::allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory,
+ SkColorTable* ctable) {
+ if (kIndex_8_SkColorType == info.fColorType && NULL == ctable) {
+ return reset_return_false(this);
+ }
+ if (!this->setConfig(info)) {
+ return reset_return_false(this);
+ }
+
+ SkMallocPixelRef::PRFactory defaultFactory;
+ if (NULL == factory) {
+ factory = &defaultFactory;
+ }
+
+ SkPixelRef* pr = factory->create(info, ctable);
+ if (NULL == pr) {
+ return reset_return_false(this);
+ }
+ this->setPixelRef(pr)->unref();
+
+ // TODO: lockPixels could/should return bool or void*/NULL
+ this->lockPixels();
+ if (NULL == this->getPixels()) {
+ return reset_return_false(this);
+ }
+ return true;
+}
+
+bool SkBitmap::installPixels(const SkImageInfo& info, void* pixels, size_t rb,
+ void (*releaseProc)(void* addr, void* context),
+ void* context) {
+ if (!this->setConfig(info)) {
+ this->reset();
+ return false;
+ }
+
+ SkPixelRef* pr = SkMallocPixelRef::NewWithProc(info, rb, NULL, pixels,
+ releaseProc, context);
+ if (!pr) {
+ this->reset();
+ return false;
+ }
+
+ this->setPixelRef(pr)->unref();
+ return true;
+}
+
void SkBitmap::freePixels() {
// if we're gonna free the pixels, we certainly need to free the mipmap
this->freeMipMap();
« no previous file with comments | « include/core/SkPixelRef.h ('k') | src/core/SkBitmapDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698