| 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 // Enums for control points based on the order specified in the constructor
(clockwise). | |
| 50 enum CubicCtrlPts { | |
| 51 kTopP0_CubicCtrlPts = 0, | |
| 52 kTopP1_CubicCtrlPts = 1, | |
| 53 kTopP2_CubicCtrlPts = 2, | |
| 54 kTopP3_CubicCtrlPts = 3, | |
| 55 | |
| 56 kRightP0_CubicCtrlPts = 3, | |
| 57 kRightP1_CubicCtrlPts = 4, | |
| 58 kRightP2_CubicCtrlPts = 5, | |
| 59 kRightP3_CubicCtrlPts = 6, | |
| 60 | |
| 61 kBottomP0_CubicCtrlPts = 9, | |
| 62 kBottomP1_CubicCtrlPts = 8, | |
| 63 kBottomP2_CubicCtrlPts = 7, | |
| 64 kBottomP3_CubicCtrlPts = 6, | |
| 65 | |
| 66 kLeftP0_CubicCtrlPts = 0, | |
| 67 kLeftP1_CubicCtrlPts = 11, | |
| 68 kLeftP2_CubicCtrlPts = 10, | |
| 69 kLeftP3_CubicCtrlPts = 9, | |
| 70 }; | |
| 71 | |
| 72 // Enum for corner colors also clockwise. | |
| 73 enum CornerColors { | |
| 74 kTopLeft_CornerColors = 0, | |
| 75 kTopRight_CornerColors, | |
| 76 kBottomRight_CornerColors, | |
| 77 kBottomLeft_CornerColors | |
| 78 }; | |
| 79 | |
| 80 enum { | |
| 81 kNumCtrlPts = 12, | |
| 82 kNumColors = 4, | |
| 83 kNumPtsCubic = 4 | |
| 84 }; | |
| 85 | |
| 86 /** | |
| 87 * Points are in the following order: | |
| 88 * (top curve) | |
| 89 * 0 1 2 3 | |
| 90 * (left curve) 11 4 (right curve) | |
| 91 * 10 5 | |
| 92 * 9 8 7 6 | |
| 93 * (bottom curve) | |
| 94 */ | |
| 95 SkPatch() { } | |
| 96 SkPatch(const SkPoint points[12], const SkColor colors[4]); | |
| 97 | |
| 98 /** | |
| 99 * Function that evaluates the coons patch interpolation. | |
| 100 * data refers to the pointer of the PatchData struct in which the tessellat
ion data is set. | |
| 101 * lod refers the level of detail for each axis. | |
| 102 */ | |
| 103 bool getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const; | |
| 104 | |
| 105 void getTopPoints(SkPoint points[4]) const { | |
| 106 points[0] = fCtrlPoints[kTopP0_CubicCtrlPts]; | |
| 107 points[1] = fCtrlPoints[kTopP1_CubicCtrlPts]; | |
| 108 points[2] = fCtrlPoints[kTopP2_CubicCtrlPts]; | |
| 109 points[3] = fCtrlPoints[kTopP3_CubicCtrlPts]; | |
| 110 } | |
| 111 | |
| 112 void getBottomPoints(SkPoint points[4]) const { | |
| 113 points[0] = fCtrlPoints[kBottomP0_CubicCtrlPts]; | |
| 114 points[1] = fCtrlPoints[kBottomP1_CubicCtrlPts]; | |
| 115 points[2] = fCtrlPoints[kBottomP2_CubicCtrlPts]; | |
| 116 points[3] = fCtrlPoints[kBottomP3_CubicCtrlPts]; | |
| 117 } | |
| 118 | |
| 119 void getLeftPoints(SkPoint points[4]) const { | |
| 120 points[0] = fCtrlPoints[kLeftP0_CubicCtrlPts]; | |
| 121 points[1] = fCtrlPoints[kLeftP1_CubicCtrlPts]; | |
| 122 points[2] = fCtrlPoints[kLeftP2_CubicCtrlPts]; | |
| 123 points[3] = fCtrlPoints[kLeftP3_CubicCtrlPts]; | |
| 124 } | |
| 125 | |
| 126 void getRightPoints(SkPoint points[4]) const { | |
| 127 points[0] = fCtrlPoints[kRightP0_CubicCtrlPts]; | |
| 128 points[1] = fCtrlPoints[kRightP1_CubicCtrlPts]; | |
| 129 points[2] = fCtrlPoints[kRightP2_CubicCtrlPts]; | |
| 130 points[3] = fCtrlPoints[kRightP3_CubicCtrlPts]; | |
| 131 } | |
| 132 | |
| 133 void getCornerPoints(SkPoint points[4]) const { | |
| 134 points[0] = fCtrlPoints[kTopP0_CubicCtrlPts]; | |
| 135 points[1] = fCtrlPoints[kTopP3_CubicCtrlPts]; | |
| 136 points[2] = fCtrlPoints[kBottomP3_CubicCtrlPts]; | |
| 137 points[3] = fCtrlPoints[kBottomP0_CubicCtrlPts]; | |
| 138 } | |
| 139 | |
| 140 const SkPoint* getControlPoints() const { | |
| 141 return fCtrlPoints; | |
| 142 } | |
| 143 | |
| 144 const SkColor* getColors() const { | |
| 145 return fCornerColors; | |
| 146 } | |
| 147 | |
| 148 void setPoints(const SkPoint points[12]) { | |
| 149 memcpy(fCtrlPoints, points, kNumCtrlPts * sizeof(SkPoint)); | |
| 150 } | |
| 151 | |
| 152 void setColors(const SkColor colors[4]) { | |
| 153 memcpy(fCornerColors, colors, kNumColors * sizeof(SkColor)); | |
| 154 } | |
| 155 | |
| 156 void reset(const SkPoint points[12], const SkColor colors[4]) { | |
| 157 this->setPoints(points); | |
| 158 this->setColors(colors); | |
| 159 } | |
| 160 | |
| 161 /** | |
| 162 * Write the patch to the buffer, and return the number of bytes written. | |
| 163 * If buffer is NULL, it still returns the number of bytes. | |
| 164 */ | |
| 165 size_t writeToMemory(void* buffer) const; | |
| 166 | |
| 167 /** | |
| 168 * Initializes the patch from the buffer | |
| 169 * | |
| 170 * buffer Memory to read from | |
| 171 * length Amount of memory available in the buffer | |
| 172 * returns the number of bytes read (must be a multiple of 4) or | |
| 173 * 0 if there was not enough memory available | |
| 174 */ | |
| 175 size_t readFromMemory(const void* buffer, size_t length); | |
| 176 | |
| 177 private: | |
| 178 SkPoint fCtrlPoints[kNumCtrlPts]; | |
| 179 SkColor fCornerColors[kNumColors]; | |
| 180 }; | |
| 181 | |
| 182 #endif | |
| OLD | NEW |