aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkShadowTessellator.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-03-14 12:04:16 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-14 16:57:49 +0000
commit97eb4feb112967ba7fcb00d6995adda1002873c2 (patch)
tree4fb8569365aabaac2b2ef0d3cee88e4b9e7a4fdf /src/utils/SkShadowTessellator.cpp
parent8f7d9b9784fc22b809ef1d2fa301b7b95efd2a90 (diff)
add SkVertices::Builder
Possible next iterations: - remove another allocation use the SkData trick to share the object and its (trailing) data - store a bit that tells use to free each pointer, allowing the builder to "adopt" some allocations instead of copy. Larger idea: - merge with drawPoints to have a single object for both. BUG=skia:6366 Change-Id: Iec33239aa2ad5d00b36469ca0b88934ddf6f22eb Reviewed-on: https://skia-review.googlesource.com/9604 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/utils/SkShadowTessellator.cpp')
-rw-r--r--src/utils/SkShadowTessellator.cpp21
1 files changed, 3 insertions, 18 deletions
diff --git a/src/utils/SkShadowTessellator.cpp b/src/utils/SkShadowTessellator.cpp
index 2cd5d9c7fd..ed9e62af7a 100644
--- a/src/utils/SkShadowTessellator.cpp
+++ b/src/utils/SkShadowTessellator.cpp
@@ -29,24 +29,9 @@ public:
if (!fSucceeded) {
return nullptr;
}
- int vCount = this->vertexCount();
- int iCount = this->indexCount();
- // We copy here for two reasons: 1) To tighten up our arrays and 2) to get into memory
- // allocated by new[] rather than malloc.
- // TODO: If we know we're not caching then we should avoid this.
- SkPoint* positions = new SkPoint[vCount];
- SkColor* colors = new SkColor[vCount];
- uint16_t* indices = new uint16_t[iCount];
- memcpy(positions, fPositions.begin(), sizeof(SkPoint) * vCount);
- memcpy(colors, fColors.begin(), sizeof(SkColor) * vCount);
- memcpy(indices, fIndices.begin(), sizeof(uint16_t) * iCount);
- return SkVertices::MakeIndexed(SkCanvas::kTriangles_VertexMode,
- std::unique_ptr<const SkPoint[]>((const SkPoint*)positions),
- std::unique_ptr<const SkColor[]>((const SkColor*)colors),
- nullptr,
- vCount,
- std::unique_ptr<const uint16_t[]>((const uint16_t*)indices),
- iCount);
+ return SkVertices::MakeCopy(SkCanvas::kTriangles_VertexMode, this->vertexCount(),
+ fPositions.begin(), nullptr, fColors.begin(),
+ this->indexCount(), fIndices.begin());
}
protected: