aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/SkBitmap.cpp2
-rw-r--r--tests/BitmapTest.cpp8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 92d445396c..c438ecd2a2 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -175,7 +175,7 @@ void SkBitmap::setPixelRef(sk_sp<SkPixelRef> pr, int dx, int dy) {
#endif
fPixelRef = kUnknown_SkColorType != this->colorType() ? std::move(pr) : nullptr;
void* p = nullptr;
- size_t rowBytes = 0;
+ size_t rowBytes = this->rowBytes();
// ignore dx,dy if there is no pixelref
if (fPixelRef) {
rowBytes = fPixelRef->rowBytes();
diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp
index ddc770f99d..f62288cd22 100644
--- a/tests/BitmapTest.cpp
+++ b/tests/BitmapTest.cpp
@@ -218,3 +218,11 @@ DEF_TEST(Bitmap_erase_f16_erase_getColor, r) {
}
}
+// Make sure that the bitmap remains valid when pixelref is removed.
+DEF_TEST(Bitmap_clear_pixelref_keep_info, r) {
+ SkBitmap bm;
+ bm.allocPixels(SkImageInfo::MakeN32Premul(100,100));
+ bm.setPixelRef(nullptr, 0, 0);
+ SkDEBUGCODE(bm.validate();)
+}
+