Chromium Code Reviews| Index: include/core/SkPatch.h |
| diff --git a/include/core/SkPatch.h b/include/core/SkPatch.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ccb7b80b3b49992caf08dfd9b5ab849f7e226031 |
| --- /dev/null |
| +++ b/include/core/SkPatch.h |
| @@ -0,0 +1,117 @@ |
| +/* |
| + * Copyright 2014 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#ifndef SkPatch_DEFINED |
| +#define SkPatch_DEFINED |
| + |
| +#include "SkColor.h" |
| +#include "SkPreConfig.h" |
| +#include "SkPoint.h" |
| + |
| +/** |
| + * Class that represents a coons patch. |
| + */ |
| +class SK_API SkPatch { |
| + |
| +public: |
| + /** |
| + * Structure that holds the vertex data related to the tessellation of a SkPatch. It is passed |
| + * as a parameter to the function getVertexData. |
|
bsalomon
2014/07/25 14:16:37
"The generated arrays can be used with SkCanvas::d
dandov
2014/07/25 15:07:09
The idea is to add a SkCanvas::drawPatch.
|
| + */ |
| + struct PatchData { |
| + int fVertexCount, fIndexCount; |
| + SkPoint* fPoints; |
| + SkPoint* fTexCoords; |
| + uint32_t* fColors; |
| + uint16_t* fIndices; |
| + |
| + PatchData() |
| + : fVertexCount(0) |
| + , fIndexCount(0) |
| + , fPoints(NULL) |
| + , fTexCoords(NULL) |
| + , fColors(NULL) |
| + , fIndices(NULL) { } |
| + |
| + ~PatchData() { |
| + SkDELETE_ARRAY(fPoints); |
| + SkDELETE_ARRAY(fTexCoords); |
| + SkDELETE_ARRAY(fColors); |
| + SkDELETE_ARRAY(fIndices); |
| + } |
| + }; |
| + |
| + enum SkCubicCtrlPts { |
|
egdaniel
2014/07/25 14:49:27
Remove the Sk since we are already inside of SkPat
dandov
2014/07/25 15:07:09
Done.
|
| + kTopP0_CubicCtrlPts=0, |
|
egdaniel
2014/07/25 14:49:26
Nit space around =
dandov
2014/07/25 15:07:09
Done.
|
| + kTopP1_CubicCtrlPts=1, |
| + kTopP2_CubicCtrlPts=2, |
| + kTopP3_CubicCtrlPts=3, |
| + |
| + kRightP0_CubicCtrlPts=3, |
| + kRightP1_CubicCtrlPts=4, |
| + kRightP2_CubicCtrlPts=5, |
| + kRightP3_CubicCtrlPts=6, |
| + |
| + kBottomP0_CubicCtrlPts=9, |
| + kBottomP1_CubicCtrlPts=8, |
| + kBottomP2_CubicCtrlPts=7, |
| + kBottomP3_CubicCtrlPts=6, |
| + |
| + kLeftP0_CubicCtrlPts=0, |
| + kLeftP1_CubicCtrlPts=11, |
| + kLeftP2_CubicCtrlPts=10, |
| + kLeftP3_CubicCtrlPts=9, |
| + }; |
| + |
| + /** |
| + * Points are in the following order: |
| + * (top curve) |
| + * 0 1 2 3 |
| + * (left curve) 11 4 (right curve) |
| + * 10 5 |
| + * 9 8 7 6 |
| + * (bottom curve) |
| + * Used pointer to an array to guarantee that this method receives an array of 4 SkColors |
| + */ |
| + SkPatch(SkPoint points[12], SkColor colors[4]); |
| + |
| + bool getVertexData(SkPatch::PatchData* data, int divisions); |
|
bsalomon
2014/07/25 14:16:37
Comment about what divisions means?
dandov
2014/07/25 15:07:09
Done.
|
| + |
| + void getTopPoints(SkPoint points[4]) { |
| + points[0] = fCtrlPoints[kTopP0_CubicCtrlPts]; |
| + points[1] = fCtrlPoints[kTopP1_CubicCtrlPts]; |
| + points[2] = fCtrlPoints[kTopP2_CubicCtrlPts]; |
| + points[3] = fCtrlPoints[kTopP3_CubicCtrlPts]; |
| + } |
| + |
| + const void getBottomPoints(SkPoint points[4]) { |
| + points[0] = fCtrlPoints[kBottomP0_CubicCtrlPts]; |
| + points[1] = fCtrlPoints[kBottomP1_CubicCtrlPts]; |
| + points[2] = fCtrlPoints[kBottomP2_CubicCtrlPts]; |
| + points[3] = fCtrlPoints[kBottomP3_CubicCtrlPts]; |
| + } |
| + |
| + const void getLeftPoints(SkPoint points[4]) { |
| + points[0] = fCtrlPoints[kLeftP0_CubicCtrlPts]; |
| + points[1] = fCtrlPoints[kLeftP1_CubicCtrlPts]; |
| + points[2] = fCtrlPoints[kLeftP2_CubicCtrlPts]; |
| + points[3] = fCtrlPoints[kLeftP3_CubicCtrlPts]; |
| + } |
| + |
| + const void getRightPoints(SkPoint points[4]) { |
| + points[0] = fCtrlPoints[kRightP0_CubicCtrlPts]; |
| + points[1] = fCtrlPoints[kRightP1_CubicCtrlPts]; |
| + points[2] = fCtrlPoints[kRightP2_CubicCtrlPts]; |
| + points[3] = fCtrlPoints[kRightP3_CubicCtrlPts]; |
| + } |
| + |
| +private: |
| + SkPoint fCtrlPoints[12]; |
| + SkPMColor fCornerColors[4]; |
| +}; |
| + |
| +#endif |