aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yuqian Li <liyuqian@google.com>2018-04-04 15:57:37 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-04 20:46:59 +0000
commit4b99bbb076f0bf4c32a8146b6be9a1b2572fec30 (patch)
treef8fc69adca6b56ee22e2a1659c65af16a3c02322
parent9bd736b9b4be1ea23baa3975bbe855cee74f43e8 (diff)
Ensure that pointers/arrays are valid until flush in threaded backend
Bug: skia:7672 skia:7414 Change-Id: Ia000781401fe7b1df8040abb97692e6ca35b312f Reviewed-on: https://skia-review.googlesource.com/118626 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Yuqian Li <liyuqian@google.com>
-rw-r--r--src/core/SkThreadedBMPDevice.cpp18
-rw-r--r--src/core/SkThreadedBMPDevice.h7
2 files changed, 18 insertions, 7 deletions
diff --git a/src/core/SkThreadedBMPDevice.cpp b/src/core/SkThreadedBMPDevice.cpp
index 320eb25a44..989e96aca3 100644
--- a/src/core/SkThreadedBMPDevice.cpp
+++ b/src/core/SkThreadedBMPDevice.cpp
@@ -124,9 +124,10 @@ void SkThreadedBMPDevice::drawPaint(const SkPaint& paint) {
void SkThreadedBMPDevice::drawPoints(SkCanvas::PointMode mode, size_t count,
const SkPoint pts[], const SkPaint& paint) {
+ SkPoint* clonedPts = this->cloneArray(pts, count);
SkRect drawBounds = SkRectPriv::MakeLargest(); // TODO tighter drawBounds
fQueue.push(drawBounds, [=](SkArenaAlloc*, const DrawState& ds, const SkIRect& tileBounds){
- TileDraw(ds, tileBounds).drawPoints(mode, count, pts, paint, nullptr);
+ TileDraw(ds, tileBounds).drawPoints(mode, count, clonedPts, paint, nullptr);
});
}
@@ -195,30 +196,33 @@ void SkThreadedBMPDevice::drawSprite(const SkBitmap& bitmap, int x, int y, const
void SkThreadedBMPDevice::drawText(const void* text, size_t len, SkScalar x, SkScalar y,
const SkPaint& paint) {
+ char* clonedText = this->cloneArray((const char*)text, len);
SkRect drawBounds = SkRectPriv::MakeLargest(); // TODO tighter drawBounds
fQueue.push(drawBounds, [=](SkArenaAlloc*, const DrawState& ds, const SkIRect& tileBounds){
- TileDraw(ds, tileBounds).drawText((const char*)text, len, x, y, paint,
+ TileDraw(ds, tileBounds).drawText(clonedText, len, x, y, paint,
&this->surfaceProps());
});
}
void SkThreadedBMPDevice::drawPosText(const void* text, size_t len, const SkScalar xpos[],
int scalarsPerPos, const SkPoint& offset, const SkPaint& paint) {
+ char* clonedText = this->cloneArray((const char*)text, len);
SkRect drawBounds = SkRectPriv::MakeLargest(); // TODO tighter drawBounds
fQueue.push(drawBounds, [=](SkArenaAlloc*, const DrawState& ds, const SkIRect& tileBounds){
- TileDraw(ds, tileBounds).drawPosText((const char*)text, len, xpos, scalarsPerPos, offset,
+ TileDraw(ds, tileBounds).drawPosText(clonedText, len, xpos, scalarsPerPos, offset,
paint, &surfaceProps());
});
}
void SkThreadedBMPDevice::drawVertices(const SkVertices* vertices, SkBlendMode bmode,
const SkPaint& paint) {
+ const sk_sp<SkVertices> verts = sk_ref_sp(vertices); // retain vertices until flush
SkRect drawBounds = SkRectPriv::MakeLargest(); // TODO tighter drawBounds
fQueue.push(drawBounds, [=](SkArenaAlloc*, const DrawState& ds, const SkIRect& tileBounds){
- TileDraw(ds, tileBounds).drawVertices(vertices->mode(), vertices->vertexCount(),
- vertices->positions(), vertices->texCoords(),
- vertices->colors(), bmode, vertices->indices(),
- vertices->indexCount(), paint);
+ TileDraw(ds, tileBounds).drawVertices(verts->mode(), verts->vertexCount(),
+ verts->positions(), verts->texCoords(),
+ verts->colors(), bmode, verts->indices(),
+ verts->indexCount(), paint);
});
}
diff --git a/src/core/SkThreadedBMPDevice.h b/src/core/SkThreadedBMPDevice.h
index 32fedc4004..fd6eb09825 100644
--- a/src/core/SkThreadedBMPDevice.h
+++ b/src/core/SkThreadedBMPDevice.h
@@ -159,6 +159,13 @@ private:
SkIRect transformDrawBounds(const SkRect& drawBounds) const;
+ template<typename T>
+ T* cloneArray(const T* array, int count) {
+ T* clone = fAlloc.makeArrayDefault<T>(count);
+ memcpy(clone, array, sizeof(T) * count);
+ return clone;
+ }
+
const int fTileCnt;
const int fThreadCnt;
SkTArray<SkIRect> fTileBounds;