aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2015-05-26 13:57:04 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-26 13:57:04 -0700
commit5bcef1b3e806e50d85c201435e7e93f882100911 (patch)
treeb46abd6792f7760cac4d9a5e0be9eb1d8d096182 /src
parent7a9c45c01cadea5d8b3e9671a57311247a8c414d (diff)
speculative revert change to pixmap for bitmapscaler
BUG=491891 TBR= Review URL: https://codereview.chromium.org/1159793003
Diffstat (limited to 'src')
-rw-r--r--src/core/SkBitmapScaler.cpp110
1 files changed, 53 insertions, 57 deletions
diff --git a/src/core/SkBitmapScaler.cpp b/src/core/SkBitmapScaler.cpp
index 9ce4171879..f016098636 100644
--- a/src/core/SkBitmapScaler.cpp
+++ b/src/core/SkBitmapScaler.cpp
@@ -248,78 +248,74 @@ static SkBitmapScaler::ResizeMethod ResizeMethodToAlgorithmMethod(
}
}
-static bool resize(const SkPixmap& pmap, SkBitmap* resultPtr, SkBitmapScaler::ResizeMethod method,
- float destWidth, float destHeight, SkBitmap::Allocator* allocator,
- const SkConvolutionProcs& convolveProcs) {
- const SkRect destSubset = SkRect::MakeWH(destWidth, destHeight);
- SkResizeFilter filter(method, pmap.width(), pmap.height(),
- destWidth, destHeight, destSubset, convolveProcs);
-
- // Get a source bitmap encompassing this touched area. We construct the
- // offsets and row strides such that it looks like a new bitmap, while
- // referring to the old data.
- const uint8_t* sourceSubset = reinterpret_cast<const uint8_t*>(pmap.addr());
-
- // Convolve into the result.
- SkBitmap result;
- result.setInfo(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()),
- SkScalarCeilToInt(destSubset.height()),
- pmap.alphaType()));
- result.allocPixels(allocator, NULL);
- if (!result.readyToDraw()) {
- return false;
- }
-
- BGRAConvolve2D(sourceSubset, static_cast<int>(pmap.rowBytes()),
- !pmap.isOpaque(), filter.xFilter(), filter.yFilter(),
- static_cast<int>(result.rowBytes()),
- static_cast<unsigned char*>(result.getPixels()),
- convolveProcs, true);
-
- *resultPtr = result;
- resultPtr->lockPixels();
- SkASSERT(resultPtr->getPixels());
- return true;
-}
-
+// static
bool SkBitmapScaler::Resize(SkBitmap* resultPtr,
const SkBitmap& source,
ResizeMethod method,
float destWidth, float destHeight,
SkBitmap::Allocator* allocator) {
- if (source.colorType() != kN32_SkColorType) {
- return false;
- }
- SkConvolutionProcs convolveProcs= { 0, NULL, NULL, NULL, NULL };
- PlatformConvolutionProcs(&convolveProcs);
+ SkConvolutionProcs convolveProcs= { 0, NULL, NULL, NULL, NULL };
+ PlatformConvolutionProcs(&convolveProcs);
+
+ SkRect destSubset = { 0, 0, destWidth, destHeight };
- // Ensure that the ResizeMethod enumeration is sound.
- SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) &&
+ // Ensure that the ResizeMethod enumeration is sound.
+ SkASSERT(((RESIZE_FIRST_QUALITY_METHOD <= method) &&
(method <= RESIZE_LAST_QUALITY_METHOD)) ||
((RESIZE_FIRST_ALGORITHM_METHOD <= method) &&
(method <= RESIZE_LAST_ALGORITHM_METHOD)));
- // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just
- // return empty.
- if (source.width() < 1 || source.height() < 1 || destWidth < 1 || destHeight < 1) {
- // todo: seems like we could handle negative dstWidth/Height, since that
- // is just a negative scale (flip)
- return false;
- }
+ // If the size of source or destination is 0, i.e. 0x0, 0xN or Nx0, just
+ // return empty.
+ if (source.width() < 1 || source.height() < 1 ||
+ destWidth < 1 || destHeight < 1) {
+ // todo: seems like we could handle negative dstWidth/Height, since that
+ // is just a negative scale (flip)
+ return false;
+ }
- method = ResizeMethodToAlgorithmMethod(method);
+ method = ResizeMethodToAlgorithmMethod(method);
- // Check that we deal with an "algorithm methods" from this point onward.
- SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) &&
+ // Check that we deal with an "algorithm methods" from this point onward.
+ SkASSERT((SkBitmapScaler::RESIZE_FIRST_ALGORITHM_METHOD <= method) &&
(method <= SkBitmapScaler::RESIZE_LAST_ALGORITHM_METHOD));
- SkAutoPixmapUnlock result;
- if (!source.requestLock(&result)) {
- return false;
- }
- return resize(result.pixmap(), resultPtr, method, destWidth, destHeight, allocator,
- convolveProcs);
+ SkAutoLockPixels locker(source);
+ if (!source.readyToDraw() ||
+ source.colorType() != kN32_SkColorType) {
+ return false;
+ }
+
+ SkResizeFilter filter(method, source.width(), source.height(),
+ destWidth, destHeight, destSubset, convolveProcs);
+
+ // Get a source bitmap encompassing this touched area. We construct the
+ // offsets and row strides such that it looks like a new bitmap, while
+ // referring to the old data.
+ const unsigned char* sourceSubset =
+ reinterpret_cast<const unsigned char*>(source.getPixels());
+
+ // Convolve into the result.
+ SkBitmap result;
+ result.setInfo(SkImageInfo::MakeN32(SkScalarCeilToInt(destSubset.width()),
+ SkScalarCeilToInt(destSubset.height()),
+ source.alphaType()));
+ result.allocPixels(allocator, NULL);
+ if (!result.readyToDraw()) {
+ return false;
+ }
+
+ BGRAConvolve2D(sourceSubset, static_cast<int>(source.rowBytes()),
+ !source.isOpaque(), filter.xFilter(), filter.yFilter(),
+ static_cast<int>(result.rowBytes()),
+ static_cast<unsigned char*>(result.getPixels()),
+ convolveProcs, true);
+
+ *resultPtr = result;
+ resultPtr->lockPixels();
+ SkASSERT(resultPtr->getPixels());
+ return true;
}
// static -- simpler interface to the resizer; returns a default bitmap if scaling