dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkPatchUtils_DEFINED |
| 9 | #define SkPatchUtils_DEFINED |
| 10 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 11 | #include "SkColorPriv.h" |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 12 | #include "SkMatrix.h" |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 13 | #include "SkVertices.h" |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 14 | |
| 15 | class SK_API SkPatchUtils { |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 16 | |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 17 | public: |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 18 | // DEPRECATED -- use MakeVertices() |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 19 | /** |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 20 | * Structure that holds the vertex data related to the tessellation of a patch. It is passed |
| 21 | * as a parameter to the function getVertexData which sets the points, colors and texture |
| 22 | * coordinates of the vertices and the indices for them to be drawn as triangles. |
| 23 | */ |
| 24 | struct VertexData { |
| 25 | int fVertexCount, fIndexCount; |
| 26 | SkPoint* fPoints; |
| 27 | SkPoint* fTexCoords; |
| 28 | uint32_t* fColors; |
| 29 | uint16_t* fIndices; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 30 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 31 | VertexData() |
| 32 | : fVertexCount(0) |
| 33 | , fIndexCount(0) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 34 | , fPoints(nullptr) |
| 35 | , fTexCoords(nullptr) |
| 36 | , fColors(nullptr) |
| 37 | , fIndices(nullptr) { } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 38 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 39 | ~VertexData() { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 40 | delete[] fPoints; |
| 41 | delete[] fTexCoords; |
| 42 | delete[] fColors; |
| 43 | delete[] fIndices; |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 44 | } |
| 45 | }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 46 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 47 | // Enums for control points based on the order specified in the constructor (clockwise). |
| 48 | enum CubicCtrlPts { |
| 49 | kTopP0_CubicCtrlPts = 0, |
| 50 | kTopP1_CubicCtrlPts = 1, |
| 51 | kTopP2_CubicCtrlPts = 2, |
| 52 | kTopP3_CubicCtrlPts = 3, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 53 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 54 | kRightP0_CubicCtrlPts = 3, |
| 55 | kRightP1_CubicCtrlPts = 4, |
| 56 | kRightP2_CubicCtrlPts = 5, |
| 57 | kRightP3_CubicCtrlPts = 6, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 58 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 59 | kBottomP0_CubicCtrlPts = 9, |
| 60 | kBottomP1_CubicCtrlPts = 8, |
| 61 | kBottomP2_CubicCtrlPts = 7, |
| 62 | kBottomP3_CubicCtrlPts = 6, |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 63 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 64 | kLeftP0_CubicCtrlPts = 0, |
| 65 | kLeftP1_CubicCtrlPts = 11, |
| 66 | kLeftP2_CubicCtrlPts = 10, |
| 67 | kLeftP3_CubicCtrlPts = 9, |
| 68 | }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 69 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 70 | // Enum for corner also clockwise. |
| 71 | enum Corner { |
| 72 | kTopLeft_Corner = 0, |
| 73 | kTopRight_Corner, |
| 74 | kBottomRight_Corner, |
| 75 | kBottomLeft_Corner |
| 76 | }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 77 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 78 | enum { |
| 79 | kNumCtrlPts = 12, |
| 80 | kNumCorners = 4, |
| 81 | kNumPtsCubic = 4 |
| 82 | }; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 83 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 84 | /** |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 85 | * Method that calculates a level of detail (number of subdivisions) for a patch in both axis. |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 86 | */ |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 87 | static SkISize GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 88 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 89 | /** |
| 90 | * Get the points corresponding to the top cubic of cubics. |
| 91 | */ |
| 92 | static void getTopCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 93 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Get the points corresponding to the bottom cubic of cubics. |
| 96 | */ |
| 97 | static void getBottomCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 98 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Get the points corresponding to the left cubic of cubics. |
| 101 | */ |
| 102 | static void getLeftCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 103 | |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 104 | /** |
| 105 | * Get the points corresponding to the right cubic of cubics. |
| 106 | */ |
| 107 | static void getRightCubic(const SkPoint cubics[12], SkPoint points[4]); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 108 | |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 109 | // DEPRECATED -- use MakeVertices() |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Function that evaluates the coons patch interpolation. |
| 112 | * data refers to the pointer of the PatchData struct in which the tessellation data is set. |
| 113 | * cubics refers to the points of the cubics. |
| 114 | * lod refers the level of detail for each axis. |
| 115 | * colors refers to the corner colors that will be bilerp across the patch (optional parameter) |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 116 | * texCoords refers to the corner texture coordinates that will be bilerp across the patch |
dandov | b3c9d1c | 2014-08-12 08:34:29 -0700 | [diff] [blame] | 117 | (optional parameter) |
| 118 | */ |
| 119 | static bool getVertexData(SkPatchUtils::VertexData* data, const SkPoint cubics[12], |
| 120 | const SkColor colors[4], const SkPoint texCoords[4], |
| 121 | int lodX, int lodY); |
Mike Reed | 795c5ea | 2017-03-17 14:29:05 -0400 | [diff] [blame] | 122 | |
| 123 | static sk_sp<SkVertices> MakeVertices(const SkPoint cubics[12], const SkColor colors[4], |
| 124 | const SkPoint texCoords[4], int lodX, int lodY); |
dandov | ecfff21 | 2014-08-04 10:02:00 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | #endif |