aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuqian Li <liyuqian@google.com>2018-04-12 14:57:05 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-16 18:37:10 +0000
commit6b7b1dcc863ae8877f33532df05c921e12c67675 (patch)
treeed1319b9f14f68ae3c648813fa11c6e5664bee8f /src
parenta16e1b6c0066c2ecda4ec31ea9b7e434a4aff2ad (diff)
Snap the bitmap as it may be changed later
Bug: skia: Change-Id: If06510f6fd3b64cce3440a543973c9c83913da10 Reviewed-on: https://skia-review.googlesource.com/120141 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Yuqian Li <liyuqian@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkThreadedBMPDevice.cpp15
-rw-r--r--src/core/SkThreadedBMPDevice.h2
2 files changed, 15 insertions, 2 deletions
diff --git a/src/core/SkThreadedBMPDevice.cpp b/src/core/SkThreadedBMPDevice.cpp
index 0cff9681c3..0c302370b0 100644
--- a/src/core/SkThreadedBMPDevice.cpp
+++ b/src/core/SkThreadedBMPDevice.cpp
@@ -161,6 +161,15 @@ void SkThreadedBMPDevice::drawPath(const SkPath& path, const SkPaint& paint,
}
}
+SkBitmap SkThreadedBMPDevice::snapBitmap(const SkBitmap& bitmap) {
+ // We can't use bitmap.isImmutable() because it could be temporarily immutable
+ // TODO(liyuqian): use genID to reduce the copy frequency
+ SkBitmap snap;
+ snap.allocPixels(bitmap.info());
+ bitmap.readPixels(snap.pixmap());
+ return snap;
+}
+
void SkThreadedBMPDevice::drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
const SkRect* dstOrNull, const SkPaint& paint) {
SkRect drawBounds;
@@ -173,16 +182,18 @@ void SkThreadedBMPDevice::drawBitmap(const SkBitmap& bitmap, const SkMatrix& mat
clonedDstOrNull = fAlloc.make<SkRect>(*dstOrNull);
}
+ SkBitmap snap = this->snapBitmap(bitmap);
fQueue.push(drawBounds, [=](SkArenaAlloc*, const DrawState& ds, const SkIRect& tileBounds){
- TileDraw(ds, tileBounds).drawBitmap(bitmap, matrix, clonedDstOrNull, paint);
+ TileDraw(ds, tileBounds).drawBitmap(snap, matrix, clonedDstOrNull, paint);
});
}
void SkThreadedBMPDevice::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& paint) {
SkRect drawBounds = SkRect::MakeXYWH(x, y, bitmap.width(), bitmap.height());
+ SkBitmap snap = this->snapBitmap(bitmap);
fQueue.push<false>(drawBounds, [=](SkArenaAlloc*, const DrawState& ds,
const SkIRect& tileBounds){
- TileDraw(ds, tileBounds).drawSprite(bitmap, x, y, paint);
+ TileDraw(ds, tileBounds).drawSprite(snap, x, y, paint);
});
}
diff --git a/src/core/SkThreadedBMPDevice.h b/src/core/SkThreadedBMPDevice.h
index b539a5609e..a901470255 100644
--- a/src/core/SkThreadedBMPDevice.h
+++ b/src/core/SkThreadedBMPDevice.h
@@ -183,6 +183,8 @@ private:
return clone;
}
+ SkBitmap snapBitmap(const SkBitmap& bitmap);
+
const int fTileCnt;
const int fThreadCnt;
SkTArray<SkIRect> fTileBounds;