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(texs.get(), fTexs, sizeof(SkPoint) * kMeshVertexCnt);
memcpy(indices.get(), kMeshFan, sizeof(uint16_t) * kMeshIndexCnt);
fVertices = SkVertices::MakeIndexed(SkCanvas::kTriangleFan_VertexMode,
std::move(points),
std::move(colors), std::move(texs), kMeshVertexCnt,
std::move(indices), kMeshIndexCnt);
// Older libstdc++ does not allow moving a std::unique_ptr<T[]> into a
// std::unique_ptr<const T[]>. Hence the release() calls below.
fVertices = SkVertices::MakeIndexed(
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;
if (useObject) {
vertices =
SkVertices::MakeIndexed(SkCanvas::kTriangles_VertexMode, std::move(pts),
std::move(colors),
std::move(texs), kMeshVertexCnt, std::move(indices),
3 * kNumTris);
// Older libstdc++ does not allow moving a std::unique_ptr<T[]> into a
// std::unique_ptr<const T[]>. Hence the release() calls below.
vertices = SkVertices::MakeIndexed(
SkCanvas::kTriangles_VertexMode, std::unique_ptr<const SkPoint[]>(pts.release()),
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->translate(10, 10);

View File

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