OLD | NEW |
(Empty) | |
| 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 SkPatch_DEFINED |
| 9 #define SkPatch_DEFINED |
| 10 |
| 11 #include "SkColor.h" |
| 12 #include "SkPreConfig.h" |
| 13 #include "SkPoint.h" |
| 14 |
| 15 /** |
| 16 * Class that represents a coons patch. |
| 17 */ |
| 18 class SK_API SkPatch { |
| 19 |
| 20 public: |
| 21 /** |
| 22 * Structure that holds the vertex data related to the tessellation of a SkP
atch. It is passed |
| 23 * as a parameter to the function getVertexData which sets the points, color
s and texture |
| 24 * coordinates of the vertices and the indices for them to be drawn as trian
gles. |
| 25 */ |
| 26 struct VertexData { |
| 27 int fVertexCount, fIndexCount; |
| 28 SkPoint* fPoints; |
| 29 SkPoint* fTexCoords; |
| 30 uint32_t* fColors; |
| 31 uint16_t* fIndices; |
| 32 |
| 33 VertexData() |
| 34 : fVertexCount(0) |
| 35 , fIndexCount(0) |
| 36 , fPoints(NULL) |
| 37 , fTexCoords(NULL) |
| 38 , fColors(NULL) |
| 39 , fIndices(NULL) { } |
| 40 |
| 41 ~VertexData() { |
| 42 SkDELETE_ARRAY(fPoints); |
| 43 SkDELETE_ARRAY(fTexCoords); |
| 44 SkDELETE_ARRAY(fColors); |
| 45 SkDELETE_ARRAY(fIndices); |
| 46 } |
| 47 }; |
| 48 |
| 49 enum CubicCtrlPts { |
| 50 kTopP0_CubicCtrlPts = 0, |
| 51 kTopP1_CubicCtrlPts = 1, |
| 52 kTopP2_CubicCtrlPts = 2, |
| 53 kTopP3_CubicCtrlPts = 3, |
| 54 |
| 55 kRightP0_CubicCtrlPts = 3, |
| 56 kRightP1_CubicCtrlPts = 4, |
| 57 kRightP2_CubicCtrlPts = 5, |
| 58 kRightP3_CubicCtrlPts = 6, |
| 59 |
| 60 kBottomP0_CubicCtrlPts = 9, |
| 61 kBottomP1_CubicCtrlPts = 8, |
| 62 kBottomP2_CubicCtrlPts = 7, |
| 63 kBottomP3_CubicCtrlPts = 6, |
| 64 |
| 65 kLeftP0_CubicCtrlPts = 0, |
| 66 kLeftP1_CubicCtrlPts = 11, |
| 67 kLeftP2_CubicCtrlPts = 10, |
| 68 kLeftP3_CubicCtrlPts = 9, |
| 69 }; |
| 70 |
| 71 /** |
| 72 * Points are in the following order: |
| 73 * (top curve) |
| 74 * 0 1 2 3 |
| 75 * (left curve) 11 4 (right curve) |
| 76 * 10 5 |
| 77 * 9 8 7 6 |
| 78 * (bottom curve) |
| 79 * Used pointer to an array to guarantee that this method receives an array
of 4 SkColors |
| 80 */ |
| 81 SkPatch(SkPoint points[12], SkColor colors[4]); |
| 82 |
| 83 /** |
| 84 * Function that evaluates the coons patch interpolation. |
| 85 * data refers to the pointer of the PatchData struct in which the tessellat
ion data is set. |
| 86 * divisions defines the number of steps in which the SkPatch is going to be
subdivided per |
| 87 * axis. |
| 88 */ |
| 89 bool getVertexData(SkPatch::VertexData* data, int divisions); |
| 90 |
| 91 void getTopPoints(SkPoint points[4]) { |
| 92 points[0] = fCtrlPoints[kTopP0_CubicCtrlPts]; |
| 93 points[1] = fCtrlPoints[kTopP1_CubicCtrlPts]; |
| 94 points[2] = fCtrlPoints[kTopP2_CubicCtrlPts]; |
| 95 points[3] = fCtrlPoints[kTopP3_CubicCtrlPts]; |
| 96 } |
| 97 |
| 98 void getBottomPoints(SkPoint points[4]) { |
| 99 points[0] = fCtrlPoints[kBottomP0_CubicCtrlPts]; |
| 100 points[1] = fCtrlPoints[kBottomP1_CubicCtrlPts]; |
| 101 points[2] = fCtrlPoints[kBottomP2_CubicCtrlPts]; |
| 102 points[3] = fCtrlPoints[kBottomP3_CubicCtrlPts]; |
| 103 } |
| 104 |
| 105 void getLeftPoints(SkPoint points[4]) { |
| 106 points[0] = fCtrlPoints[kLeftP0_CubicCtrlPts]; |
| 107 points[1] = fCtrlPoints[kLeftP1_CubicCtrlPts]; |
| 108 points[2] = fCtrlPoints[kLeftP2_CubicCtrlPts]; |
| 109 points[3] = fCtrlPoints[kLeftP3_CubicCtrlPts]; |
| 110 } |
| 111 |
| 112 void getRightPoints(SkPoint points[4]) { |
| 113 points[0] = fCtrlPoints[kRightP0_CubicCtrlPts]; |
| 114 points[1] = fCtrlPoints[kRightP1_CubicCtrlPts]; |
| 115 points[2] = fCtrlPoints[kRightP2_CubicCtrlPts]; |
| 116 points[3] = fCtrlPoints[kRightP3_CubicCtrlPts]; |
| 117 } |
| 118 |
| 119 private: |
| 120 SkPoint fCtrlPoints[12]; |
| 121 SkPMColor fCornerColors[4]; |
| 122 }; |
| 123 |
| 124 #endif |
OLD | NEW |