From 4b99bbb076f0bf4c32a8146b6be9a1b2572fec30 Mon Sep 17 00:00:00 2001 From: Yuqian Li Date: Wed, 4 Apr 2018 15:57:37 -0400 Subject: 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 Commit-Queue: Yuqian Li --- src/core/SkThreadedBMPDevice.cpp | 18 +++++++++++------- src/core/SkThreadedBMPDevice.h | 7 +++++++ 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 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 + T* cloneArray(const T* array, int count) { + T* clone = fAlloc.makeArrayDefault(count); + memcpy(clone, array, sizeof(T) * count); + return clone; + } + const int fTileCnt; const int fThreadCnt; SkTArray fTileBounds; -- cgit v1.2.3