From f510149da8d32f60f08d0a809eb037496079af3c Mon Sep 17 00:00:00 2001 From: Ruiqi Mao Date: Fri, 29 Jun 2018 14:32:21 -0400 Subject: skeletal animation support added to API and software backend SkCanvas::drawVertices now supports overloads that take an array of bone deformation matrices. SkVertices::MakeCopy and SkVertices::Builder now support two additional optional attributes, boneIndices and boneWeights. Bug: skia: Change-Id: I30a3b11691e7cdb13924907cc1401ff86d127aea Reviewed-on: https://skia-review.googlesource.com/137221 Reviewed-by: Brian Osman Reviewed-by: Robert Phillips Commit-Queue: Ruiqi Mao --- src/pipe/SkPipeCanvas.cpp | 6 ++++-- src/pipe/SkPipeCanvas.h | 3 ++- src/pipe/SkPipeReader.cpp | 9 +++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src/pipe') diff --git a/src/pipe/SkPipeCanvas.cpp b/src/pipe/SkPipeCanvas.cpp index d66953c5bd..aabff5bfae 100644 --- a/src/pipe/SkPipeCanvas.cpp +++ b/src/pipe/SkPipeCanvas.cpp @@ -728,14 +728,16 @@ void SkPipeCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { write_paint(writer, paint, kGeometry_PaintUsage); } -void SkPipeCanvas::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode bmode, - const SkPaint& paint) { +void SkPipeCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkMatrix* bones, + int boneCount, SkBlendMode bmode, const SkPaint& paint) { unsigned extra = static_cast(bmode); SkPipeWriter writer(this); writer.write32(pack_verb(SkPipeVerb::kDrawVertices, extra)); // TODO: dedup vertices? writer.writeDataAsByteArray(vertices->encode().get()); + writer.write32(boneCount); + writer.write(bones, sizeof(SkMatrix) * boneCount); write_paint(writer, paint, kVertices_PaintUsage); } diff --git a/src/pipe/SkPipeCanvas.h b/src/pipe/SkPipeCanvas.h index 65bca4dfc4..b39f80920b 100644 --- a/src/pipe/SkPipeCanvas.h +++ b/src/pipe/SkPipeCanvas.h @@ -135,7 +135,8 @@ protected: const SkPaint*) override; void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst, const SkPaint*) override; - void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; + void onDrawVerticesObject(const SkVertices*, const SkMatrix* bones, int boneCount, SkBlendMode, + const SkPaint&) override; void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override; void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override; diff --git a/src/pipe/SkPipeReader.cpp b/src/pipe/SkPipeReader.cpp index ada4a21342..312e3da4e8 100644 --- a/src/pipe/SkPipeReader.cpp +++ b/src/pipe/SkPipeReader.cpp @@ -562,9 +562,14 @@ static void drawImageLattice_handler(SkPipeReader& reader, uint32_t packedVerb, static void drawVertices_handler(SkPipeReader& reader, uint32_t packedVerb, SkCanvas* canvas) { SkASSERT(SkPipeVerb::kDrawVertices == unpack_verb(packedVerb)); SkBlendMode bmode = (SkBlendMode)unpack_verb_extra(packedVerb); + sk_sp vertices = nullptr; if (sk_sp data = reader.readByteArrayAsData()) { - canvas->drawVertices(SkVertices::Decode(data->data(), data->size()), bmode, - read_paint(reader)); + vertices = SkVertices::Decode(data->data(), data->size()); + } + int boneCount = reader.read32(); + const SkMatrix* bones = boneCount ? reader.skipT(boneCount) : nullptr; + if (vertices) { + canvas->drawVertices(vertices, bones, boneCount, bmode, read_paint(reader)); } } -- cgit v1.2.3