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

Unified Diff: src/core/SkBitmap.cpp

Issue 68973005: Expand pixelref to return SkImageInfo and rowbytes (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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: src/core/SkBitmap.cpp
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 2fae75ae3841dd39d53c305ee83f70b8ae806fe5..626499ad40e2bd86e2c2bf6cc4541763f0233448 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -368,6 +368,37 @@ void SkBitmap::updatePixelsFromRef() const {
}
}
+bool SkBitmap::asImageInfo(SkImageInfo* info) const {
+ SkColorType ct;
+ switch (this->config()) {
+ case kNo_Config:
+ case kA1_Config:
+ return false;
+ case kA8_Config:
+ ct = kAlpha_8_SkColorType;
+ break;
+ case kIndex8_Config:
+ ct = kIndex8_SkColorType;
+ break;
+ case kRGB_565_Config:
+ ct = kRGB_565_SkColorType;
+ break;
+ case kARGB_4444_Config:
+ ct = kARGB_4444_SkColorType;
+ break;
+ case kARGB_8888_Config:
+ ct = kPMColor_SkColorType;
+ break;
+ }
+ if (info) {
+ info->fWidth = fWidth;
+ info->fHeight = fHeight;
+ info->fAlphaType = this->alphaType();
+ info->fColorType = ct;
+ }
+ return true;
+}
+
SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, size_t offset) {
// do this first, we that we never have a non-zero offset with a null ref
if (NULL == pr) {
@@ -421,7 +452,12 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) {
Sk64 size = this->getSize64();
SkASSERT(!size.isNeg() && size.is32());
- this->setPixelRef(new SkMallocPixelRef(p, size.get32(), ctable, false))->unref();
+ SkImageInfo info;
+ if (!this->asImageInfo(&info)) {
+ this->setPixelRef(NULL, 0);
+ return;
+ }
+ this->setPixelRef(new SkMallocPixelRef(info, p, fRowBytes, ctable, false))->unref();
scroggo 2013/11/19 18:17:09 SkNEW_ARGS
reed1 2013/11/20 20:56:56 Done.
// since we're already allocated, we lockPixels right away
this->lockPixels();
SkDEBUGCODE(this->validate();)
@@ -491,12 +527,20 @@ bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst,
return false;
}
+ SkImageInfo info;
+ if (!dst->asImageInfo(&info)) {
+ SkDebugf("unsupported config for info %d\n", dst->config());
+ return false;
+ }
+
void* addr = sk_malloc_flags(size.get32(), 0); // returns NULL on failure
if (NULL == addr) {
return false;
}
- dst->setPixelRef(new SkMallocPixelRef(addr, size.get32(), ctable))->unref();
+ SkPixelRef* pr = SkNEW_ARGS(SkMallocPixelRef,
+ (info, addr, dst->rowBytes(), ctable, true));
+ dst->setPixelRef(pr, 0)->unref();
// since we're already allocated, we lockPixels right away
dst->lockPixels();
return true;

Powered by Google App Engine
This is Rietveld 408576698