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

Unified Diff: src/core/SkBitmap.cpp

Issue 108513003: Revert "PixelRef now returns (nearly) everything that is currently in SkBitmap. The goal is to refa… (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 900a3abcd0519eae9ffadf966e334085abc65538..d2a308b03ab950fe536980ea0a84a8d6122f62f9 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -361,47 +361,6 @@ void SkBitmap::updatePixelsFromRef() const {
}
}
-static bool config_to_colorType(SkBitmap::Config config, SkColorType* ctOut) {
- SkColorType ct;
- switch (config) {
- case SkBitmap::kNo_Config:
- return false;
- case SkBitmap::kA8_Config:
- ct = kAlpha_8_SkColorType;
- break;
- case SkBitmap::kIndex8_Config:
- ct = kIndex8_SkColorType;
- break;
- case SkBitmap::kRGB_565_Config:
- ct = kRGB_565_SkColorType;
- break;
- case SkBitmap::kARGB_4444_Config:
- ct = kARGB_4444_SkColorType;
- break;
- case SkBitmap::kARGB_8888_Config:
- ct = kPMColor_SkColorType;
- break;
- }
- if (ctOut) {
- *ctOut = ct;
- }
- return true;
-}
-
-bool SkBitmap::asImageInfo(SkImageInfo* info) const {
- SkColorType ct;
- if (!config_to_colorType(this->config(), &ct)) {
- return false;
- }
- 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) {
@@ -452,20 +411,10 @@ void SkBitmap::setPixels(void* p, SkColorTable* ctable) {
return;
}
- 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();
+ Sk64 size = this->getSize64();
+ SkASSERT(!size.isNeg() && size.is32());
+ this->setPixelRef(new SkMallocPixelRef(p, size.get32(), ctable, false))->unref();
// since we're already allocated, we lockPixels right away
this->lockPixels();
SkDEBUGCODE(this->validate();)
@@ -530,19 +479,17 @@ GrTexture* SkBitmap::getTexture() const {
*/
bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst,
SkColorTable* ctable) {
- SkImageInfo info;
- if (!dst->asImageInfo(&info)) {
-// SkDebugf("unsupported config for info %d\n", dst->config());
+ Sk64 size = dst->getSize64();
+ if (size.isNeg() || !size.is32()) {
return false;
}
-
- SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(),
- ctable);
- if (NULL == pr) {
+
+ void* addr = sk_malloc_flags(size.get32(), 0); // returns NULL on failure
+ if (NULL == addr) {
return false;
}
- dst->setPixelRef(pr, 0)->unref();
+ dst->setPixelRef(new SkMallocPixelRef(addr, size.get32(), ctable))->unref();
// since we're already allocated, we lockPixels right away
dst->lockPixels();
return true;
@@ -1649,28 +1596,6 @@ SkBitmap::RLEPixels::~RLEPixels() {
///////////////////////////////////////////////////////////////////////////////
-void SkImageInfo::unflatten(SkFlattenableReadBuffer& buffer) {
- fWidth = buffer.read32();
- fHeight = buffer.read32();
-
- uint32_t packed = buffer.read32();
- SkASSERT(0 == (packed >> 16));
- fAlphaType = (SkAlphaType)((packed >> 8) & 0xFF);
- fColorType = (SkColorType)((packed >> 0) & 0xFF);
-}
-
-void SkImageInfo::flatten(SkFlattenableWriteBuffer& buffer) const {
- buffer.write32(fWidth);
- buffer.write32(fHeight);
-
- SkASSERT(0 == (fAlphaType & ~0xFF));
- SkASSERT(0 == (fColorType & ~0xFF));
- uint32_t packed = (fAlphaType << 8) | fColorType;
- buffer.write32(packed);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
#ifdef SK_DEBUG
void SkBitmap::validate() const {
SkASSERT(fConfig < kConfigCount);
« 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