aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
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/gpu
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/gpu')
-rw-r--r--src/gpu/ops/GrDrawVerticesOp.cpp39
1 files changed, 4 insertions, 35 deletions
diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp
index c79d9acf83..5d8837880f 100644
--- a/src/gpu/ops/GrDrawVerticesOp.cpp
+++ b/src/gpu/ops/GrDrawVerticesOp.cpp
@@ -15,46 +15,15 @@ std::unique_ptr<GrMeshDrawOp> GrDrawVerticesOp::Make(
const SkPoint* positions, int vertexCount, const uint16_t* indices, int indexCount,
const uint32_t* colors, const SkPoint* localCoords, const SkRect& bounds,
GrRenderTargetContext::ColorArrayType colorArrayType) {
+ static constexpr SkCanvas::VertexMode kIgnoredMode = SkCanvas::kTriangles_VertexMode;
SkASSERT(positions);
- std::unique_ptr<SkPoint[]> pos(new SkPoint[vertexCount]);
- memcpy(pos.get(), positions, sizeof(SkPoint) * vertexCount);
- std::unique_ptr<SkColor[]> col;
- if (colors) {
- col.reset(new SkColor[vertexCount]);
- memcpy(col.get(), colors, sizeof(SkColor) * vertexCount);
- } else {
+ if (!colors) {
// When we tessellate we will fill a color array with the GrColor value passed above as
// 'color'.
colorArrayType = GrRenderTargetContext::ColorArrayType::kPremulGrColor;
}
- std::unique_ptr<SkPoint[]> lc;
- if (localCoords) {
- lc.reset(new SkPoint[vertexCount]);
- memcpy(lc.get(), localCoords, sizeof(SkPoint) * vertexCount);
- }
- std::unique_ptr<uint16_t[]> idx;
- if (indexCount) {
- idx.reset(new uint16_t[indexCount]);
- memcpy(idx.get(), indices, sizeof(uint16_t) * indexCount);
- }
- static constexpr SkCanvas::VertexMode kIgnoredMode = SkCanvas::kTriangles_VertexMode;
- sk_sp<SkVertices> vertices;
- // Older libstdc++ does not allow moving a std::unique_ptr<T[]> into a
- // std::unique_ptr<const T[]>. Hence the release() calls below.
- if (indices) {
- vertices = SkVertices::MakeIndexed(
- kIgnoredMode, std::unique_ptr<const SkPoint[]>((const SkPoint*)pos.release()),
- std::unique_ptr<const SkColor[]>((const SkColor*)col.release()),
- std::unique_ptr<const SkPoint[]>((const SkPoint*)lc.release()), vertexCount,
- std::unique_ptr<const uint16_t[]>((const uint16_t*)idx.release()), indexCount,
- bounds);
- } else {
- vertices = SkVertices::Make(kIgnoredMode,
- std::unique_ptr<const SkPoint[]>((const SkPoint*)pos.release()),
- std::unique_ptr<const SkColor[]>((const SkColor*)col.release()),
- std::unique_ptr<const SkPoint[]>((const SkPoint*)lc.release()),
- vertexCount, bounds);
- }
+ sk_sp<SkVertices> vertices = SkVertices::MakeCopy(kIgnoredMode, vertexCount, positions,
+ localCoords, colors, indexCount, indices);
if (!vertices) {
return nullptr;
}