diff options
Diffstat (limited to 'src/utils/SkPatchGrid.cpp')
-rw-r--r-- | src/utils/SkPatchGrid.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/utils/SkPatchGrid.cpp b/src/utils/SkPatchGrid.cpp index b7aaa82b9b..3b7c06e954 100644 --- a/src/utils/SkPatchGrid.cpp +++ b/src/utils/SkPatchGrid.cpp @@ -36,28 +36,28 @@ bool SkPatchGrid::setPatch(int x, int y, const SkPoint cubics[12], const SkColor if (x < 0 || y < 0 || x > fCols - 1 || y > fRows - 1 || nullptr == cubics) { return false; } - + // setup corners and colors int cornerPos = y * (fCols + 1) + x; fCornerPts[cornerPos] = cubics[SkPatchUtils::kTopP0_CubicCtrlPts]; fCornerPts[cornerPos + 1] = cubics[SkPatchUtils::kTopP3_CubicCtrlPts]; fCornerPts[cornerPos + (fCols + 1)] = cubics[SkPatchUtils::kBottomP0_CubicCtrlPts]; fCornerPts[cornerPos + (fCols + 1) + 1] = cubics[SkPatchUtils::kBottomP3_CubicCtrlPts]; - + // set horizontal control points int hrzPos = y * (fCols * 2) + (x * 2); fHrzCtrlPts[hrzPos] = cubics[SkPatchUtils::kTopP1_CubicCtrlPts]; fHrzCtrlPts[hrzPos + 1] = cubics[SkPatchUtils::kTopP2_CubicCtrlPts]; fHrzCtrlPts[hrzPos + (fCols * 2)] = cubics[SkPatchUtils::kBottomP1_CubicCtrlPts]; fHrzCtrlPts[hrzPos + (fCols * 2) + 1] = cubics[SkPatchUtils::kBottomP2_CubicCtrlPts]; - + // set vertical control points int vrtPos = (y*2) * (fCols + 1) + x; fVrtCtrlPts[vrtPos] = cubics[SkPatchUtils::kLeftP1_CubicCtrlPts]; fVrtCtrlPts[vrtPos + 1] = cubics[SkPatchUtils::kRightP1_CubicCtrlPts]; fVrtCtrlPts[vrtPos + (fCols + 1)] = cubics[SkPatchUtils::kLeftP2_CubicCtrlPts]; fVrtCtrlPts[vrtPos + (fCols + 1) + 1] = cubics[SkPatchUtils::kRightP2_CubicCtrlPts]; - + // set optional values (colors and texture coordinates) if ((fModeFlags & kColors_VertexType) && colors) { fCornerColors[cornerPos] = colors[0]; @@ -65,57 +65,57 @@ bool SkPatchGrid::setPatch(int x, int y, const SkPoint cubics[12], const SkColor fCornerColors[cornerPos + (fCols + 1)] = colors[3]; fCornerColors[cornerPos + (fCols + 1) + 1] = colors[2]; } - + if ((fModeFlags & kTexs_VertexType) && texCoords) { fTexCoords[cornerPos] = texCoords[0]; fTexCoords[cornerPos + 1] = texCoords[1]; fTexCoords[cornerPos + (fCols + 1)] = texCoords[3]; fTexCoords[cornerPos + (fCols + 1) + 1] = texCoords[2]; } - + return true; } bool SkPatchGrid::getPatch(int x, int y, SkPoint cubics[12], SkColor colors[4], SkPoint texCoords[4]) const { - + if (x < 0 || y < 0 || x > fCols - 1 || y > fRows - 1 || nullptr == cubics) { return false; } - + // set the patch by building the array of points and colors with the corresponding values. int cornerPos = y * (fCols + 1) + x; cubics[SkPatchUtils::kTopP0_CubicCtrlPts] = fCornerPts[cornerPos]; cubics[SkPatchUtils::kTopP3_CubicCtrlPts] = fCornerPts[cornerPos + 1]; cubics[SkPatchUtils::kBottomP0_CubicCtrlPts] = fCornerPts[cornerPos + (fCols + 1)]; cubics[SkPatchUtils::kBottomP3_CubicCtrlPts] = fCornerPts[cornerPos + (fCols + 1) + 1]; - + int hrzPos = y * (fCols * 2) + (x * 2); cubics[SkPatchUtils::kTopP1_CubicCtrlPts] = fHrzCtrlPts[hrzPos]; cubics[SkPatchUtils::kTopP2_CubicCtrlPts] = fHrzCtrlPts[hrzPos + 1]; cubics[SkPatchUtils::kBottomP1_CubicCtrlPts] = fHrzCtrlPts[hrzPos + (fCols * 2)]; cubics[SkPatchUtils::kBottomP2_CubicCtrlPts] = fHrzCtrlPts[hrzPos + (fCols * 2) + 1]; - + int vrtPos = (y*2) * (fCols + 1) + x; cubics[SkPatchUtils::kLeftP1_CubicCtrlPts] = fVrtCtrlPts[vrtPos]; cubics[SkPatchUtils::kRightP1_CubicCtrlPts] = fVrtCtrlPts[vrtPos + 1]; cubics[SkPatchUtils::kLeftP2_CubicCtrlPts] = fVrtCtrlPts[vrtPos + (fCols + 1)]; cubics[SkPatchUtils::kRightP2_CubicCtrlPts] = fVrtCtrlPts[vrtPos + (fCols + 1) + 1]; - + if ((fModeFlags & kColors_VertexType) && colors) { colors[0] = fCornerColors[cornerPos]; colors[1] = fCornerColors[cornerPos + 1]; colors[3] = fCornerColors[cornerPos + (fCols + 1)]; colors[2] = fCornerColors[cornerPos + (fCols + 1) + 1]; } - + if ((fModeFlags & kTexs_VertexType) && texCoords) { texCoords[0] = fTexCoords[cornerPos]; texCoords[1] = fTexCoords[cornerPos + 1]; texCoords[3] = fTexCoords[cornerPos + (fCols + 1)]; texCoords[2] = fTexCoords[cornerPos + (fCols + 1) + 1]; } - + return true; } @@ -137,12 +137,12 @@ void SkPatchGrid::reset(int rows, int cols, VertexType flags, SkXfermode* xMode) memset(fCornerPts, 0, (fRows + 1) * (fCols + 1) * sizeof(SkPoint)); memset(fHrzCtrlPts, 0, (fRows + 1) * fCols * 2 * sizeof(SkPoint)); memset(fVrtCtrlPts, 0, fRows * 2 * (fCols + 1) * sizeof(SkPoint)); - + if (fModeFlags & kColors_VertexType) { fCornerColors = new SkColor[(fRows + 1) * (fCols + 1)]; memset(fCornerColors, 0, (fRows + 1) * (fCols + 1) * sizeof(SkColor)); } - + if (fModeFlags & kTexs_VertexType) { fTexCoords = new SkPoint[(fRows + 1) * (fCols + 1)]; memset(fTexCoords, 0, (fRows + 1) * (fCols + 1) * sizeof(SkPoint)); @@ -154,7 +154,7 @@ void SkPatchGrid::draw(SkCanvas* canvas, SkPaint& paint) { int* maxRows = new int[fRows]; memset(maxCols, 0, fCols * sizeof(int)); memset(maxRows, 0, fRows * sizeof(int)); - + // Get the maximum level of detail per axis for each row and column for (int y = 0; y < fRows; y++) { for (int x = 0; x < fCols; x++) { |