Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: include/core/SkPatch.h

Issue 463493002: SkCanvas::drawPatch param SkPoint[12] (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Virtual call onDrawPatch Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkDevice.h ('k') | include/utils/SkDeferredCanvas.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkPatch.h
diff --git a/include/core/SkPatch.h b/include/core/SkPatch.h
index 698b1cbf306e14dcddb0ce48aad2e886c63f3077..4390c7c537009aef18e1ce69ad7b435a438791b7 100644
--- a/include/core/SkPatch.h
+++ b/include/core/SkPatch.h
@@ -11,6 +11,7 @@
#include "SkColor.h"
#include "SkPreConfig.h"
#include "SkPoint.h"
+#include "SkRect.h"
/**
* Class that represents a coons patch.
@@ -69,17 +70,17 @@ public:
kLeftP3_CubicCtrlPts = 9,
};
- // Enum for corner colors also clockwise.
- enum CornerColors {
- kTopLeft_CornerColors = 0,
- kTopRight_CornerColors,
- kBottomRight_CornerColors,
- kBottomLeft_CornerColors
+ // Enum for corner also clockwise.
+ enum Corner {
+ kTopLeft_Corner = 0,
+ kTopRight_Corner,
+ kBottomRight_Corner,
+ kBottomLeft_Corner
};
enum {
kNumCtrlPts = 12,
- kNumColors = 4,
+ kNumCorners = 4,
kNumPtsCubic = 4
};
@@ -93,16 +94,20 @@ public:
* (bottom curve)
*/
SkPatch() { }
- SkPatch(const SkPoint points[12], const SkColor colors[4]);
+ SkPatch(const SkPoint points[12]);
/**
* Function that evaluates the coons patch interpolation.
* data refers to the pointer of the PatchData struct in which the tessellation data is set.
* lod refers the level of detail for each axis.
*/
- bool getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const;
+ bool getVertexData(SkPatch::VertexData* data, const SkColor colors[4],
+ const SkPoint texCoords[4], int lodX, int lodY) const;
void getTopPoints(SkPoint points[4]) const {
+ if (NULL == points) {
reed1 2014/08/11 15:38:44 Hmmm, why is this check here? I can't think of a r
dandov 2014/08/11 18:07:52 I added them to avoid crashing but I see now that
+ return;
+ }
points[0] = fCtrlPoints[kTopP0_CubicCtrlPts];
points[1] = fCtrlPoints[kTopP1_CubicCtrlPts];
points[2] = fCtrlPoints[kTopP2_CubicCtrlPts];
@@ -110,6 +115,9 @@ public:
}
void getBottomPoints(SkPoint points[4]) const {
+ if (NULL == points) {
+ return;
+ }
points[0] = fCtrlPoints[kBottomP0_CubicCtrlPts];
points[1] = fCtrlPoints[kBottomP1_CubicCtrlPts];
points[2] = fCtrlPoints[kBottomP2_CubicCtrlPts];
@@ -117,6 +125,9 @@ public:
}
void getLeftPoints(SkPoint points[4]) const {
+ if (NULL == points) {
+ return;
+ }
points[0] = fCtrlPoints[kLeftP0_CubicCtrlPts];
points[1] = fCtrlPoints[kLeftP1_CubicCtrlPts];
points[2] = fCtrlPoints[kLeftP2_CubicCtrlPts];
@@ -124,6 +135,9 @@ public:
}
void getRightPoints(SkPoint points[4]) const {
+ if (NULL == points) {
+ return;
+ }
points[0] = fCtrlPoints[kRightP0_CubicCtrlPts];
points[1] = fCtrlPoints[kRightP1_CubicCtrlPts];
points[2] = fCtrlPoints[kRightP2_CubicCtrlPts];
@@ -131,31 +145,23 @@ public:
}
void getCornerPoints(SkPoint points[4]) const {
+ if (NULL == points) {
+ return;
+ }
points[0] = fCtrlPoints[kTopP0_CubicCtrlPts];
points[1] = fCtrlPoints[kTopP3_CubicCtrlPts];
points[2] = fCtrlPoints[kBottomP3_CubicCtrlPts];
points[3] = fCtrlPoints[kBottomP0_CubicCtrlPts];
}
+ const SkRect getBounds() const;
+
const SkPoint* getControlPoints() const {
return fCtrlPoints;
}
-
- const SkColor* getColors() const {
- return fCornerColors;
- }
-
- void setPoints(const SkPoint points[12]) {
- memcpy(fCtrlPoints, points, kNumCtrlPts * sizeof(SkPoint));
- }
-
- void setColors(const SkColor colors[4]) {
- memcpy(fCornerColors, colors, kNumColors * sizeof(SkColor));
- }
- void reset(const SkPoint points[12], const SkColor colors[4]) {
- this->setPoints(points);
- this->setColors(colors);
+ void reset(const SkPoint points[12]) {
+ memcpy(fCtrlPoints, points, kNumCtrlPts * sizeof(SkPoint));
}
/**
@@ -176,7 +182,68 @@ public:
private:
SkPoint fCtrlPoints[kNumCtrlPts];
- SkColor fCornerColors[kNumColors];
+};
+
+/**
+ * Evaluator to sample the values of a cubic bezier using forward differences.
+ * Forward differences is a method for evaluating a nth degree polynomial at a uniform step by only
+ * adding precalculated values.
+ * For a linear example we have the function f(t) = m*t+b, then the value of that function at t+h
+ * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first
+ * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After
+ * obtaining this value (mh) we could just add this constant step to our first sampled point
+ * to compute the next one.
+ *
+ * For the cubic case the first difference gives as a result a quadratic polynomial to which we can
+ * apply again forward differences and get linear function to which we can apply again forward
+ * differences to get a constant difference. This is why we keep an array of size 4, the 0th
+ * position keeps the sampled value while the next ones keep the quadratic, linear and constant
+ * difference values.
+ */
+
+class FwDCubicEvaluator {
+
+public:
+ FwDCubicEvaluator();
+
+ /**
+ * Receives the 4 control points of the cubic bezier.
+ */
+ FwDCubicEvaluator(SkPoint a, SkPoint b, SkPoint c, SkPoint d);
+
+ explicit FwDCubicEvaluator(const SkPoint points[4]);
+
+ /**
+ * Restarts the forward differences evaluator to the first value of t = 0.
+ */
+ void restart(int divisions);
+
+ /**
+ * Check if the evaluator is still within the range of 0<=t<=1
+ */
+ bool done() const {
+ return fCurrent > fMax;
+ }
+
+ /**
+ * Call next to obtain the SkPoint sampled and move to the next one.
+ */
+ SkPoint next() {
+ SkPoint point = fFwDiff[0];
+ fFwDiff[0] += fFwDiff[1];
+ fFwDiff[1] += fFwDiff[2];
+ fFwDiff[2] += fFwDiff[3];
+ fCurrent++;
+ return point;
+ }
+
+ const SkPoint* getCtrlPoints() const {
+ return fPoints;
+ }
+
+private:
+ int fMax, fCurrent, fDivisions;
+ SkPoint fFwDiff[4], fCoefs[4], fPoints[4];
};
#endif
« no previous file with comments | « include/core/SkDevice.h ('k') | include/utils/SkDeferredCanvas.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698