Chromium Code Reviews| 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" | |
|
egdaniel
2014/07/24 19:07:38
Is it possible to not include skcolor or point in
dandov
2014/07/24 19:56:46
To make the forward declaration should I declare t
| |
| 12 #include "SkPoint.h" | |
| 13 | |
| 14 | |
|
jvanverth1
2014/07/24 17:37:05
If this class is internal to the SkPatch implement
bsalomon
2014/07/24 18:10:23
Yeah it might not even need to be nested in SkPatc
dandov
2014/07/24 19:56:46
I moved it to SkPatch.cpp and removed the FwDCubic
| |
| 15 /** | |
| 16 * Evaluator to sample the values of a cubic bezier using forward differences. | |
| 17 * Forward differences is a method for evaluating a nth degree polynomial at a u niform step by only | |
| 18 * adding precalculated values. | |
| 19 * For a linear example we have the function f(t) = m*t+b, then the value of tha t function at t+h | |
| 20 * would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first | |
| 21 * evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After | |
| 22 * obtaining this value (mh) we could just add this constant step to our first s ampled point | |
| 23 * to compute the next one. | |
| 24 * | |
| 25 * For the cubic case the first difference gives as a result a quadratic polynom ial to which we can | |
| 26 * apply again forward differences and get linear function to which we can apply again forward | |
| 27 * differences to get a constant difference. This is why we keep an array of siz e 4, the 0th | |
| 28 * position keeps the sampled value while the next ones keep the quadratic, line ar and constant | |
| 29 * difference values. | |
| 30 */ | |
| 31 class SkFwDCubicEvaluator { | |
| 32 | |
| 33 public: | |
| 34 SkFwDCubicEvaluator(){ } | |
| 35 | |
| 36 /** | |
| 37 * Receives the 4 control points for the cubic. | |
| 38 */ | |
| 39 SkFwDCubicEvaluator(SkPoint a, SkPoint b, SkPoint c, SkPoint d); | |
| 40 | |
| 41 /** | |
| 42 * Resets the forward differences evaluator to the first value of t = 0. | |
| 43 */ | |
| 44 void reset(int divisions); | |
|
bsalomon
2014/07/24 18:10:23
Can we call this restart? We usually use reset() t
dandov
2014/07/24 19:56:46
Done.
| |
| 45 | |
| 46 /* | |
| 47 * Evaluate cubic bezier using forward differences. | |
| 48 * Call operator* to check the current sampled value. | |
| 49 * Call operator++ to obtain the SkPoint sampled and move to the next one. | |
| 50 * Call reset to start sampling from t=0 | |
| 51 */ | |
| 52 inline bool done() { | |
| 53 return fCurrent <= fMax; | |
| 54 } | |
| 55 | |
| 56 inline SkPoint operator*() { | |
|
jvanverth1
2014/07/24 17:37:04
If this isn't used (it looks like you use getPoint
dandov
2014/07/24 19:56:46
I removed the operator* and changed the name to ge
| |
| 57 return fFwDiff[0]; | |
| 58 } | |
| 59 | |
| 60 inline SkPoint operator++() { | |
|
bsalomon
2014/07/24 18:10:23
We're pretty conservative about using operators. U
jvanverth1
2014/07/24 18:25:21
My bad, I suggested operator++.
dandov
2014/07/24 19:56:46
Done.
| |
| 61 SkPoint point = fFwDiff[0]; | |
| 62 fFwDiff[0] += fFwDiff[1]; | |
| 63 fFwDiff[1] += fFwDiff[2]; | |
| 64 fFwDiff[2] += fFwDiff[3]; | |
| 65 fCurrent++; | |
| 66 return point; | |
| 67 } | |
| 68 | |
| 69 inline SkPoint operator++(int) { | |
|
jvanverth1
2014/07/24 17:37:05
I'm not sure what the point of this operator is...
dandov
2014/07/24 19:56:46
It goes away with the operator changed to next() f
| |
| 70 SkPoint point = fFwDiff[0]; | |
| 71 fFwDiff[0] += fFwDiff[1]; | |
| 72 fFwDiff[1] += fFwDiff[2]; | |
| 73 fFwDiff[2] += fFwDiff[3]; | |
| 74 fCurrent++; | |
| 75 return point; | |
| 76 } | |
| 77 | |
| 78 const SkPoint* getPoints(); | |
| 79 | |
| 80 private: | |
| 81 int fMax, fCurrent, fDivisions; | |
| 82 SkPoint fFwDiff[4], fCoefs[4], fPoints[4]; | |
| 83 }; | |
| 84 | |
| 85 /** | |
| 86 * Class that represents a coons patch. | |
| 87 */ | |
| 88 class SK_API SkPatch { | |
| 89 | |
| 90 public: | |
| 91 /** | |
| 92 * Points are in the following order: | |
| 93 * (bottom curve) | |
|
bsalomon
2014/07/24 18:10:23
It's kind of weird that the diagram has bottom abo
egdaniel
2014/07/24 19:07:38
Also I feel like it would make more sense to pass
dandov
2014/07/24 19:56:46
I had them like that before but I changed them bec
| |
| 94 * 0 1 2 3 | |
| 95 * (left curve) 8 10 (right curve) | |
| 96 * 9 11 | |
| 97 * 4 5 6 7 | |
| 98 * (top curve) | |
| 99 * Used pointer to an array to guarantee that this method receives an array of 4 SkColors | |
| 100 */ | |
|
dandov
2014/07/22 20:23:28
Changed colors parameter to be just pointer to SkC
| |
| 101 SkPatch(SkPoint points[12], SkColor colors[4], int res); | |
| 102 | |
| 103 ~SkPatch(); | |
| 104 | |
| 105 void clean(); | |
|
bsalomon
2014/07/24 18:10:23
I think in Skia we'd normally call this reset().
dandov
2014/07/24 19:56:46
Done.
| |
| 106 | |
| 107 const SkPoint* getTopPoints() { return fTop.getPoints(); } | |
| 108 | |
| 109 const SkPoint* getLeftPoints() { return fLeft.getPoints(); } | |
| 110 | |
| 111 const SkPoint* getRightPoints() { return fRight.getPoints(); } | |
| 112 | |
| 113 const SkPoint* getBottomPoints() { return fBottom.getPoints(); } | |
| 114 | |
| 115 void setData(); | |
|
bsalomon
2014/07/24 18:10:23
It's non-obvious what this does.
Also, does it ma
dandov
2014/07/24 19:56:46
Changed the method signature to void setVertexData
| |
| 116 | |
| 117 int getVertexCount() { return fVertCount; } | |
| 118 | |
| 119 int getIndexCount() { return fIndexCount; } | |
| 120 | |
| 121 SkPoint* getPoints() { return fPoints; } | |
| 122 | |
| 123 SkPoint* getTexCoords() { return fTexCoords; } | |
| 124 | |
| 125 uint32_t* getColors() { return fColors; } | |
| 126 | |
| 127 uint16_t* getIndices() { return fIndices; } | |
| 128 | |
| 129 private: | |
| 130 SkPoint* fCtrlPoints; | |
| 131 SkFwDCubicEvaluator fBottom, fTop, fLeft, fRight; | |
| 132 SkPMColor fCornerColors[4]; | |
| 133 int fDivX, fDivY; | |
| 134 | |
| 135 int fVertCount, fIndexCount; | |
| 136 SkPoint* fPoints; | |
| 137 SkPoint* fTexCoords; | |
| 138 uint32_t* fColors; | |
| 139 uint16_t* fIndices; | |
| 140 bool fIsSet; | |
| 141 | |
| 142 typedef SkPatch INHERITED; | |
| 143 }; | |
| 144 | |
| 145 #endif | |
| OLD | NEW |