Work around broken std::unique_ptr<const T[]> constructor from std::unique_ptr<T>&& in older libstdc++.

Change-Id: Ie4190800369515168203ff98b3e3fe0e2d790f1a
Reviewed-on: https://skia-review.googlesource.com/8072
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Salomon 2017-02-06 14:11:51 -05:00
parent 8a945603e4
commit 604c9890cc
2 changed files with 26 additions and 14 deletions

View File

@ -100,10 +100,14 @@ protected:
memcpy(colors.get(), fColors, sizeof(SkColor) * kMeshVertexCnt); memcpy(colors.get(), fColors, sizeof(SkColor) * kMeshVertexCnt);
memcpy(texs.get(), fTexs, sizeof(SkPoint) * kMeshVertexCnt); memcpy(texs.get(), fTexs, sizeof(SkPoint) * kMeshVertexCnt);
memcpy(indices.get(), kMeshFan, sizeof(uint16_t) * kMeshIndexCnt); memcpy(indices.get(), kMeshFan, sizeof(uint16_t) * kMeshIndexCnt);
fVertices = SkVertices::MakeIndexed(SkCanvas::kTriangleFan_VertexMode, // Older libstdc++ does not allow moving a std::unique_ptr<T[]> into a
std::move(points), // std::unique_ptr<const T[]>. Hence the release() calls below.
std::move(colors), std::move(texs), kMeshVertexCnt, fVertices = SkVertices::MakeIndexed(
std::move(indices), kMeshIndexCnt); SkCanvas::kTriangleFan_VertexMode,
std::unique_ptr<const SkPoint[]>(points.release()),
std::unique_ptr<const SkColor[]>(colors.release()),
std::unique_ptr<const SkPoint[]>(texs.release()), kMeshVertexCnt,
std::unique_ptr<const uint16_t[]>(indices.release()), kMeshIndexCnt);
} }
} }
@ -230,11 +234,13 @@ static void draw_batching(SkCanvas* canvas, bool useObject) {
sk_sp<SkVertices> vertices; sk_sp<SkVertices> vertices;
if (useObject) { if (useObject) {
vertices = // Older libstdc++ does not allow moving a std::unique_ptr<T[]> into a
SkVertices::MakeIndexed(SkCanvas::kTriangles_VertexMode, std::move(pts), // std::unique_ptr<const T[]>. Hence the release() calls below.
std::move(colors), vertices = SkVertices::MakeIndexed(
std::move(texs), kMeshVertexCnt, std::move(indices), SkCanvas::kTriangles_VertexMode, std::unique_ptr<const SkPoint[]>(pts.release()),
3 * kNumTris); std::unique_ptr<const SkColor[]>(colors.release()),
std::unique_ptr<const SkPoint[]>(texs.release()), kMeshVertexCnt,
std::unique_ptr<const uint16_t[]>(indices.release()), 3 * kNumTris);
} }
canvas->save(); canvas->save();
canvas->translate(10, 10); canvas->translate(10, 10);

View File

@ -39,13 +39,19 @@ std::unique_ptr<GrDrawOp> GrDrawVerticesOp::Make(
} }
static constexpr SkCanvas::VertexMode kIgnoredMode = SkCanvas::kTriangles_VertexMode; static constexpr SkCanvas::VertexMode kIgnoredMode = SkCanvas::kTriangles_VertexMode;
sk_sp<SkVertices> vertices; 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) { if (indices) {
vertices = SkVertices::MakeIndexed(kIgnoredMode, std::move(pos), std::move(col), vertices = SkVertices::MakeIndexed(
std::move(lc), kIgnoredMode, std::unique_ptr<const SkPoint[]>((const SkPoint*)pos.release()),
vertexCount, std::move(idx), indexCount, bounds); std::unique_ptr<const SkColor[]>(col.release()),
std::unique_ptr<const SkPoint[]>(lc.release()), vertexCount,
std::unique_ptr<const uint16_t[]>(idx.release()), indexCount, bounds);
} else { } else {
vertices = SkVertices::Make(kIgnoredMode, std::move(pos), std::move(col), std::move(lc), vertices = SkVertices::Make(kIgnoredMode, std::unique_ptr<const SkPoint[]>(pos.release()),
vertexCount, bounds); std::unique_ptr<const SkColor[]>(col.release()),
std::unique_ptr<const SkPoint[]>(lc.release()), vertexCount,
bounds);
} }
if (!vertices) { if (!vertices) {
return nullptr; return nullptr;