diff options
author | Cary Clark <caryclark@skia.org> | 2017-09-29 14:25:30 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-29 20:15:14 +0000 |
commit | 4b85b6dd5a7296f4543b226a534c76ef6f438e55 (patch) | |
tree | 2cf08925d1c1d3ac9a85b1a14d607655f329e3f8 /src/core | |
parent | 9a3478bf82ca528d7e82d715595b08860aac2734 (diff) |
fix setPixelRef
In setPixelRef()
If dx or dy are negative, assert in debug.
Pin pixel ref origin to account for dx and dy on right.
If colorType is unknown, ignore pr pixelref.
Set Bitmap rowbytes to match pixelref rowbytes.
In tryAllocPixels()
Return true early if colorType is unknown.
This assumes that the desired behavior is for Bitmaps
set to kUnknown_SkColorType to avoid allocating SkPixelRef
while avoiding debug asserts, which is what current
gm tests like BitmapCopy_extractSubset test for.
R=reed@google.com
Change-Id: I0d36032d36a0b7dc111f4aff18c71382874fe1f5
Reviewed-on: https://skia-review.googlesource.com/53420
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Cary Clark <caryclark@skia.org>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmap.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index c3bc4a9d63..9de2261a9a 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -190,15 +190,15 @@ void SkBitmap::setPixelRef(sk_sp<SkPixelRef> pr, int dx, int dy) { #ifdef SK_DEBUG if (pr) { if (kUnknown_SkColorType != fInfo.colorType()) { - SkASSERT(fInfo.width() + dx <= pr->width()); - SkASSERT(fInfo.height() + dy <= pr->height()); + SkASSERT(dx >= 0 && fInfo.width() + dx <= pr->width()); + SkASSERT(dy >= 0 && fInfo.height() + dy <= pr->height()); } } #endif - - fPixelRef = std::move(pr); + fPixelRef = kUnknown_SkColorType != fInfo.colorType() ? std::move(pr) : nullptr; if (fPixelRef) { - fPixelRefOrigin.set(SkTPin(dx, 0, fPixelRef->width()), SkTPin(dy, 0, fPixelRef->height())); + fPixelRefOrigin.set(dx, dy); + fRowBytes = fPixelRef->rowBytes(); this->updatePixelsFromRef(); } else { // ignore dx,dy if there is no pixelref @@ -245,6 +245,9 @@ bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes) // setInfo may have corrected info (e.g. 565 is always opaque). const SkImageInfo& correctedInfo = this->info(); + if (kUnknown_SkColorType == correctedInfo.colorType()) { + return true; + } // setInfo may have computed a valid rowbytes if 0 were passed in rowBytes = this->rowBytes(); |