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

Unified Diff: src/core/SkBitmap.cpp

Issue 111323005: Remvoe duplicate impl for SkImageInfo flattening (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 | « samplecode/SamplePicture.cpp ('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 25a6b1dba44790ce0bee01bb22f4b92bfd54c426..7a7f690b2a5159ac1c09ff744adf62a36ba6df6e 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -453,10 +453,20 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) {
return;
}
- Sk64 size = this->getSize64();
- SkASSERT(!size.isNeg() && size.is32());
+ SkImageInfo info;
+ if (!this->asImageInfo(&info)) {
+ this->setPixelRef(NULL, 0);
+ return;
+ }
+
+ SkPixelRef* pr = SkMallocPixelRef::NewDirect(info, p, fRowBytes, ctable);
+ if (NULL == pr) {
+ this->setPixelRef(NULL, 0);
+ return;
+ }
+
+ this->setPixelRef(pr)->unref();
- this->setPixelRef(new SkMallocPixelRef(p, size.get32(), ctable, false))->unref();
// since we're already allocated, we lockPixels right away
this->lockPixels();
SkDEBUGCODE(this->validate();)
@@ -521,17 +531,19 @@ GrTexture* SkBitmap::getTexture() const {
*/
bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst,
SkColorTable* ctable) {
- Sk64 size = dst->getSize64();
- if (size.isNeg() || !size.is32()) {
+ 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) {
+
+ SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(),
+ ctable);
+ if (NULL == pr) {
return false;
}
- dst->setPixelRef(new SkMallocPixelRef(addr, size.get32(), ctable))->unref();
+ dst->setPixelRef(pr, 0)->unref();
// since we're already allocated, we lockPixels right away
dst->lockPixels();
return true;
« no previous file with comments | « samplecode/SamplePicture.cpp ('k') | src/core/SkBitmapDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698