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

Unified Diff: include/core/SkPatch.h

Issue 405163003: SkPatch abstraction (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Get data directly from SkPatch Created 6 years, 5 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
« gm/patch.cpp ('K') | « gyp/gmslides.gypi ('k') | src/core/SkPatch.cpp » ('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
new file mode 100644
index 0000000000000000000000000000000000000000..9ffb0d9523b84e340b045b8b0f3dd4acb95574a6
--- /dev/null
+++ b/include/core/SkPatch.h
@@ -0,0 +1,124 @@
+/*
+ * 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 "SkPoint.h"
+
+class SkFwDCubicEvaluator {
+
+public:
+ SkFwDCubicEvaluator(){ }
+
+ /**
+ * Receives the 4 control points for the cubic.
+ */
+ SkFwDCubicEvaluator(SkPoint a, SkPoint b, SkPoint c, SkPoint d);
+
+ /**
+ * Resets the forward differences evaluator to the first value of t = 0.
+ */
+ void reset(int res);
egdaniel 2014/07/22 19:09:36 what exactly is the meaning behind res? Maybe I ju
dandov 2014/07/22 20:23:28 I changed the name to divisions meaning the number
+
+ /*
+ * Evaluate cubic bezier using forward differences.
+ * Call operator* to check if the next value is still within the range t=[0,1].
+ * Call operator++ to obtain the SkPoint sampled at the next t.
+ * Call reset to start sampling from t=0
+ */
+ inline bool operator*() {
egdaniel 2014/07/22 19:09:35 The * operator seems weird to be used as a bool (u
dandov 2014/07/22 20:23:28 I adjusted the operator* to get the current value
+ return fCurrent <= fMax;
+ }
+
+ inline SkPoint operator++() {
+ SkPoint point = fFwDiff[0];
+ fFwDiff[0] += fFwDiff[1];
+ fFwDiff[1] += fFwDiff[2];
+ fFwDiff[2] += fFwDiff[3];
+ fCurrent++;
+ return point;
+ }
+
+ inline SkPoint operator++(int) {
+ //repeat this code? inline is affected if not?
+ SkPoint point = fFwDiff[0];
+ fFwDiff[0] += fFwDiff[1];
+ fFwDiff[1] += fFwDiff[2];
+ fFwDiff[2] += fFwDiff[3];
+ fCurrent++;
+ return point;
+ }
+
+ const SkPoint* getPoints();
+
+ const SkPoint* getCoefs();
egdaniel 2014/07/22 19:09:35 Do you have a need for getCoefs() or getResolution
dandov 2014/07/22 20:23:28 Done.
+
+ int getResolution();
+
+private:
+ int fMax, fCurrent, fRes;
+ SkPoint fFwDiff[4], fCoefs[4], fPoints[4];
+};
+
+/**
+ * Class that represents a coons patch.
+ */
+class SK_API SkPatch {
+
+public:
+ /*
+ * Points are in the following order:
+ * (bottom curve)
+ * 0 1 2 3
+ * (left curve) 8 10 (right curve)
+ * 9 11
+ * 4 5 6 7
+ * (top curve)
+ * Used pointer to an array to guarantee that this method receives an array of 4 SkColors
+ */
+ SkPatch(SkPoint points[12], SkColor (*colors)[4], int res);
+
+ ~SkPatch();
+
+ void clean();
+
+ const SkPoint* getTopPoints() { return fTop.getPoints(); }
+
+ const SkPoint* getLeftPoints() { return fLeft.getPoints(); }
+
+ const SkPoint* getRightPoints() { return fRight.getPoints(); }
+
+ const SkPoint* getBottomPoints() { return fBottom.getPoints(); }
+
+ void setData();
+
+ int getVertexCount() { return fVertCount; }
+ int getIndexCount() { return fIndexCount; }
+ SkPoint* getPoints() { return fPoints; }
+ SkPoint* getTexCoords() { return fTexCoords; }
+ uint32_t* getColors() { return fColors; }
+ uint16_t* getIndices() { return fIndices; }
+
+private:
+ SkPoint* fCtrlPoints;
+ SkFwDCubicEvaluator fBottom, fTop, fLeft, fRight;
+ SkPMColor fCornerColors[4];
+ int fResX, fResY;
+
+ int fVertCount, fIndexCount;
+ SkPoint* fPoints;
+ SkPoint* fTexCoords;
+ uint32_t* fColors;
+ uint16_t* fIndices;
+ bool fIsSet;
+
+ typedef SkPatch INHERITED;
+};
+
+#endif
« gm/patch.cpp ('K') | « gyp/gmslides.gypi ('k') | src/core/SkPatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698