diff options
author | Ruiqi Mao <ruiqimao@google.com> | 2018-06-29 14:32:21 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-29 19:34:28 +0000 |
commit | f510149da8d32f60f08d0a809eb037496079af3c (patch) | |
tree | 13b3670a481f3bae652968165d04f9ca4890d9bf /include | |
parent | 38f118a2e7f986b06d69d0af41ec2d1af53dac39 (diff) |
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 <brianosman@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Ruiqi Mao <ruiqimao@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkCanvas.h | 42 | ||||
-rw-r--r-- | include/core/SkCanvasVirtualEnforcer.h | 4 | ||||
-rw-r--r-- | include/core/SkOverdrawCanvas.h | 3 | ||||
-rw-r--r-- | include/core/SkVertices.h | 82 | ||||
-rw-r--r-- | include/utils/SkLuaCanvas.h | 3 | ||||
-rw-r--r-- | include/utils/SkNWayCanvas.h | 3 | ||||
-rw-r--r-- | include/utils/SkNoDrawCanvas.h | 3 | ||||
-rw-r--r-- | include/utils/SkPaintFilterCanvas.h | 3 |
8 files changed, 125 insertions, 18 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 5a307c8e6b..15ed034db6 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -2149,6 +2149,40 @@ public: */ void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint); + /** Draw SkVertices vertices, a triangle mesh, using clip and SkMatrix. Bone data is used to + deform vertices with bone weights. + If vertices texs and vertices colors are defined in vertices, and SkPaint paint + contains SkShader, SkBlendMode mode combines vertices colors with SkShader. + The first element of bones should be an object to world space transformation matrix that + will be applied before performing mesh deformations. If no such transformation is needed, + it should be the identity matrix. + + @param vertices triangle mesh to draw + @param bones bone matrix data + @param boneCount number of bone matrices + @param mode combines vertices colors with SkShader, if both are present + @param paint specifies the SkShader, used as SkVertices texture, may be nullptr + */ + void drawVertices(const SkVertices* vertices, const SkMatrix* bones, int boneCount, + SkBlendMode mode, const SkPaint& paint); + + /** Draw SkVertices vertices, a triangle mesh, using clip and SkMatrix. Bone data is used to + deform vertices with bone weights. + If vertices texs and vertices colors are defined in vertices, and SkPaint paint + contains SkShader, SkBlendMode mode combines vertices colors with SkShader. + The first element of bones should be an object to world space transformation matrix that + will be applied before performing mesh deformations. If no such transformation is needed, + it should be the identity matrix. + + @param vertices triangle mesh to draw + @param bones bone matrix data + @param boneCount number of bone matrices + @param mode combines vertices colors with SkShader, if both are present + @param paint specifies the SkShader, used as SkVertices texture, may be nullptr + */ + void drawVertices(const sk_sp<SkVertices> vertices, const SkMatrix* bones, int boneCount, + SkBlendMode mode, const SkPaint& paint); + /** Draws a Coons patch: the interpolation of four cubics with shared corners, associating a color, and optionally a texture SkPoint, with each corner. @@ -2472,8 +2506,14 @@ protected: const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint); virtual void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint); + + // TODO: Remove old signature virtual void onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode, - const SkPaint& paint); + const SkPaint& paint) { + this->onDrawVerticesObject(vertices, nullptr, 0, mode, paint); + } + virtual void onDrawVerticesObject(const SkVertices* vertices, const SkMatrix* bones, + int boneCount, SkBlendMode mode, const SkPaint& paint); virtual void onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, const SkPaint* paint); virtual void onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, diff --git a/include/core/SkCanvasVirtualEnforcer.h b/include/core/SkCanvasVirtualEnforcer.h index 1999802170..84b209d895 100644 --- a/include/core/SkCanvasVirtualEnforcer.h +++ b/include/core/SkCanvasVirtualEnforcer.h @@ -48,8 +48,8 @@ protected: const SkPaint& paint) override = 0; void onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) override = 0; - void onDrawVerticesObject(const SkVertices* vertices, SkBlendMode mode, - const SkPaint& paint) override = 0; + void onDrawVerticesObject(const SkVertices*, const SkMatrix* bones, int boneCount, SkBlendMode, + const SkPaint&) override = 0; void onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, const SkPaint* paint) override = 0; diff --git a/include/core/SkOverdrawCanvas.h b/include/core/SkOverdrawCanvas.h index 47b5e04872..380f9ebb87 100644 --- a/include/core/SkOverdrawCanvas.h +++ b/include/core/SkOverdrawCanvas.h @@ -39,7 +39,8 @@ public: void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; void onDrawRRect(const SkRRect&, const SkPaint&) override; void onDrawPoints(PointMode, size_t, const SkPoint[], 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 onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode, const SkRect*, const SkPaint*) override; void onDrawPath(const SkPath&, const SkPaint&) override; diff --git a/include/core/SkVertices.h b/include/core/SkVertices.h index d5e97e12d5..6c4fb390d0 100644 --- a/include/core/SkVertices.h +++ b/include/core/SkVertices.h @@ -19,6 +19,20 @@ */ class SK_API SkVertices : public SkNVRefCnt<SkVertices> { public: + // BoneIndices indicates which (of a maximum of 4 bones) a given vertex will interpolate + // between. To indicate that a slot is not used, the convention is to assign the bone index + // to 0. + struct BoneIndices { + uint32_t indices[4]; + }; + + // BoneWeights stores the interpolation weight for each of the (maximum of 4) bones a given + // vertex interpolates between. To indicate that a slot is not used, the weight for that + // slot should be 0. + struct BoneWeights { + float weights[4]; + }; + enum VertexMode { kTriangles_VertexMode, kTriangleStrip_VertexMode, @@ -28,21 +42,60 @@ public: }; /** - * Create a vertices by copying the specified arrays. texs and colors may be nullptr, - * and indices is ignored if indexCount == 0. + * Create a vertices by copying the specified arrays. texs, colors, boneIndices, and + * boneWeights may be nullptr, and indices is ignored if indexCount == 0. + * + * boneIndices and boneWeights must either both be nullptr or both point to valid data. + * If specified, they must both contain 'vertexCount' entries. */ static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount, const SkPoint positions[], const SkPoint texs[], const SkColor colors[], + const BoneIndices boneIndices[], + const BoneWeights boneWeights[], int indexCount, const uint16_t indices[]); static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount, const SkPoint positions[], const SkPoint texs[], + const SkColor colors[], + const BoneIndices boneIndices[], + const BoneWeights boneWeights[]) { + return MakeCopy(mode, + vertexCount, + positions, + texs, + colors, + boneIndices, + boneWeights, + 0, + nullptr); + } + + static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount, + const SkPoint positions[], + const SkPoint texs[], + const SkColor colors[], + int indexCount, + const uint16_t indices[]) { + return MakeCopy(mode, + vertexCount, + positions, + texs, + colors, + nullptr, + nullptr, + indexCount, + indices); + } + + static sk_sp<SkVertices> MakeCopy(VertexMode mode, int vertexCount, + const SkPoint positions[], + const SkPoint texs[], const SkColor colors[]) { - return MakeCopy(mode, vertexCount, positions, texs, colors, 0, nullptr); + return MakeCopy(mode, vertexCount, positions, texs, colors, nullptr, nullptr); } struct Sizes; @@ -50,6 +103,7 @@ public: enum BuilderFlags { kHasTexCoords_BuilderFlag = 1 << 0, kHasColors_BuilderFlag = 1 << 1, + kHasBones_BuilderFlag = 1 << 2, }; class Builder { public: @@ -61,9 +115,11 @@ public: int vertexCount() const; int indexCount() const; SkPoint* positions(); - SkPoint* texCoords(); // returns null if there are no texCoords - SkColor* colors(); // returns null if there are no colors - uint16_t* indices(); // returns null if there are no indices + SkPoint* texCoords(); // returns null if there are no texCoords + SkColor* colors(); // returns null if there are no colors + BoneIndices* boneIndices(); // returns null if there are no bone indices + BoneWeights* boneWeights(); // returns null if there are no bone weights + uint16_t* indices(); // returns null if there are no indices // Detach the built vertices object. After the first call, this will always return null. sk_sp<SkVertices> detach(); @@ -88,6 +144,7 @@ public: bool hasColors() const { return SkToBool(this->colors()); } bool hasTexCoords() const { return SkToBool(this->texCoords()); } + bool hasBones() const { return SkToBool(this->boneIndices()); } bool hasIndices() const { return SkToBool(this->indices()); } int vertexCount() const { return fVertexCnt; } @@ -95,6 +152,9 @@ public: const SkPoint* texCoords() const { return fTexs; } const SkColor* colors() const { return fColors; } + const BoneIndices* boneIndices() const { return fBoneIndices; } + const BoneWeights* boneWeights() const { return fBoneWeights; } + int indexCount() const { return fIndexCnt; } const uint16_t* indices() const { return fIndices; } @@ -128,10 +188,12 @@ private: uint32_t fUniqueID; // these point inside our allocation, so none of these can be "freed" - SkPoint* fPositions; - SkPoint* fTexs; - SkColor* fColors; - uint16_t* fIndices; + SkPoint* fPositions; + SkPoint* fTexs; + SkColor* fColors; + BoneIndices* fBoneIndices; + BoneWeights* fBoneWeights; + uint16_t* fIndices; SkRect fBounds; // computed to be the union of the fPositions[] int fVertexCnt; diff --git a/include/utils/SkLuaCanvas.h b/include/utils/SkLuaCanvas.h index 2fef2c0785..e29e0b5eb3 100644 --- a/include/utils/SkLuaCanvas.h +++ b/include/utils/SkLuaCanvas.h @@ -58,7 +58,8 @@ protected: const SkPaint*, SrcRectConstraint) override; void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, 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/include/utils/SkNWayCanvas.h b/include/utils/SkNWayCanvas.h index e6a6b9962e..188c0a102c 100644 --- a/include/utils/SkNWayCanvas.h +++ b/include/utils/SkNWayCanvas.h @@ -78,7 +78,8 @@ protected: const SkPaint*) override; void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, 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 onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode, const SkRect*, const SkPaint*) override; void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; diff --git a/include/utils/SkNoDrawCanvas.h b/include/utils/SkNoDrawCanvas.h index 518d090786..0e86ed65e7 100644 --- a/include/utils/SkNoDrawCanvas.h +++ b/include/utils/SkNoDrawCanvas.h @@ -75,7 +75,8 @@ protected: const SkPaint*) override {} void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&, const SkPaint*) override {} - void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override {} + void onDrawVerticesObject(const SkVertices*, const SkMatrix*, int, SkBlendMode, + const SkPaint&) override {} void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode, const SkRect*, const SkPaint*) override {} void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override {} diff --git a/include/utils/SkPaintFilterCanvas.h b/include/utils/SkPaintFilterCanvas.h index 72c9784725..4728792013 100644 --- a/include/utils/SkPaintFilterCanvas.h +++ b/include/utils/SkPaintFilterCanvas.h @@ -88,7 +88,8 @@ protected: const SkPaint*) override; void onDrawImageLattice(const SkImage*, const Lattice&, const SkRect&, 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 onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint) override; |