diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-05-06 17:44:34 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-05-06 17:44:34 +0000 |
commit | fbaa88d9695347299321cbce2bf803726999fb58 (patch) | |
tree | 94b3dc91ce737dd7ac23adae3805227b02da2493 /src | |
parent | 311c82db3115fc6810855cbcc42a6bc6fbd48265 (diff) |
add canCopyTo(), to preflight if copyTo can succeed. update unittests for it
git-svn-id: http://skia.googlecode.com/svn/trunk@169 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBitmap.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 2765fab194..0d475086ee 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -682,13 +682,12 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { #include "SkCanvas.h" #include "SkPaint.h" -bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { - if (NULL == dst || this->getConfig() == kNo_Config - || this->width() == 0 || this->height() == 0) { +bool SkBitmap::canCopyTo(Config dstConfig) const { + if (this->getConfig() == kNo_Config) { return false; } - bool sameConfigs = (dstConfig == this->config()); + bool sameConfigs = (this->config() == dstConfig); switch (dstConfig) { case kA8_Config: case kARGB_4444_Config: @@ -710,8 +709,19 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { return false; } + return true; +} + +bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { + if (!this->canCopyTo(dstConfig)) { + return false; + } + // we lock this now, since we may need its colortable SkAutoLockPixels srclock(*this); + if (!this->readyToDraw()) { + return false; + } SkBitmap tmp; tmp.setConfig(dstConfig, this->width(), this->height()); @@ -725,16 +735,14 @@ bool SkBitmap::copyTo(SkBitmap* dst, Config dstConfig, Allocator* alloc) const { } SkAutoLockPixels dstlock(tmp); - - if (!this->readyToDraw() || !tmp.readyToDraw()) { + if (!tmp.readyToDraw()) { // allocator/lock failed return false; } - /* do memcpy for the sameConfigs cases and - re-draw for the !sameConfigs cases + /* do memcpy for the same configs cases, else use drawing */ - if (sameConfigs) { + if (this->config() == dstConfig) { if (tmp.getSize() == this->getSize()) { memcpy(tmp.getPixels(), this->getPixels(), this->getSize()); } else { |