diff options
author | 2011-11-02 19:39:51 +0000 | |
---|---|---|
committer | 2011-11-02 19:39:51 +0000 | |
commit | ace7bd5623354ffabbd224d5b76550bab159c296 (patch) | |
tree | ecdfbbd957509e31c8b1313fc6b73d301865630d /src/core/SkDevice.cpp | |
parent | 1a8ddf0a35bfb6c21a1184f81d2fdd50053acf31 (diff) |
Revert r2584 (new test fails in fixed pt builds)
git-svn-id: http://skia.googlecode.com/svn/trunk@2585 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkDevice.cpp')
-rw-r--r-- | src/core/SkDevice.cpp | 67 |
1 files changed, 12 insertions, 55 deletions
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index f5523bd9db..18087ae04d 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -102,70 +102,27 @@ void SkDevice::setMatrixClip(const SkMatrix& matrix, const SkRegion& region, /////////////////////////////////////////////////////////////////////////////// -bool SkDevice::readPixels(SkBitmap* bitmap, int x, int y) { - if (SkBitmap::kARGB_8888_Config != bitmap->config() || - NULL != bitmap->getTexture()) { - return false; - } - +bool SkDevice::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { const SkBitmap& src = this->accessBitmap(false); - SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), - bitmap->height()); - SkIRect devbounds = SkIRect::MakeWH(src.width(), src.height()); - if (!srcRect.intersect(devbounds)) { + SkIRect bounds; + bounds.set(0, 0, src.width(), src.height()); + if (!bounds.intersect(srcRect)) { return false; } - SkBitmap tmp; - SkBitmap* bmp; - if (bitmap->isNull()) { - tmp.setConfig(SkBitmap::kARGB_8888_Config, bitmap->width(), - bitmap->height()); - if (!tmp.allocPixels()) { - return false; - } - bmp = &tmp; - } else { - bmp = bitmap; - } - - SkIRect subrect = srcRect; - subrect.offset(-x, -y); - SkBitmap bmpSubset; - bmp->extractSubset(&bmpSubset, subrect); - - bool result = this->onReadPixels(&bmpSubset, srcRect.fLeft, srcRect.fTop); - if (result && bmp == &tmp) { - tmp.swap(*bitmap); - } - return result; -} - -bool SkDevice::onReadPixels(const SkBitmap* bitmap, int x, int y) { - SkASSERT(SkBitmap::kARGB_8888_Config == bitmap->config()); - SkASSERT(!bitmap->isNull()); - SkASSERT(SkIRect::MakeWH(this->width(), this->height()).contains(SkIRect::MakeXYWH(x, y, bitmap->width(), bitmap->height()))); - - SkIRect srcRect = SkIRect::MakeXYWH(x, y, bitmap->width(), - bitmap->height()); - const SkBitmap& src = this->accessBitmap(false); - SkBitmap subset; - if (!src.extractSubset(&subset, srcRect)) { + if (!src.extractSubset(&subset, bounds)) { return false; } - if (SkBitmap::kARGB_8888_Config != subset.config()) { - // It'd be preferable to do this directly to bitmap. - // We'd need a SkBitmap::copyPixelsTo that takes a config - // or make copyTo lazily allocate. - subset.copyTo(&subset, SkBitmap::kARGB_8888_Config); + + SkBitmap tmp; + if (!subset.copyTo(&tmp, SkBitmap::kARGB_8888_Config)) { + return false; } - SkAutoLockPixels alp(*bitmap); - return subset.copyPixelsTo(bitmap->getPixels(), - bitmap->getSize(), - bitmap->rowBytes(), - true); + + tmp.swap(*bitmap); + return true; } void SkDevice::writePixels(const SkBitmap& bitmap, int x, int y) { |