Index: src/core/SkPatch.cpp |
diff --git a/src/core/SkPatch.cpp b/src/core/SkPatch.cpp |
index cc967d5ceece7d1698cbc0648c2f1ae39fc22b0c..002d79589e5e00ca5d5a2b41ffe94f40a3aafe31 100644 |
--- a/src/core/SkPatch.cpp |
+++ b/src/core/SkPatch.cpp |
@@ -9,6 +9,7 @@ |
#include "SkGeometry.h" |
#include "SkColorPriv.h" |
+#include "SkBuffer.h" |
//////////////////////////////////////////////////////////////////////////////// |
@@ -117,15 +118,8 @@ private: |
//////////////////////////////////////////////////////////////////////////////// |
-SkPatch::SkPatch(SkPoint points[12], SkColor colors[4]) { |
- |
- for (int i = 0; i < 12; i++) { |
- fCtrlPoints[i] = points[i]; |
- } |
- for (int i = 0; i < 4; i++) { |
- fCornerColors[i] = colors[i]; |
- } |
- |
+SkPatch::SkPatch(const SkPoint points[12], const SkColor colors[4]) { |
+ this->reset(points, colors); |
} |
uint8_t bilinear(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01, SkScalar c11) { |
@@ -141,8 +135,8 @@ bool SkPatch::getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const |
} |
// premultiply colors to avoid color bleeding. |
- SkPMColor colors[4]; |
- for (int i = 0; i < 4; i++) { |
+ SkPMColor colors[SkPatch::kNumColors]; |
+ for (int i = 0; i < SkPatch::kNumColors; i++) { |
colors[i] = SkPreMultiplyColor(fCornerColors[i]); |
} |
@@ -157,7 +151,7 @@ bool SkPatch::getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const |
data->fTexCoords = SkNEW_ARRAY(SkPoint, data->fVertexCount); |
data->fIndices = SkNEW_ARRAY(uint16_t, data->fIndexCount); |
- SkPoint pts[4]; |
+ SkPoint pts[SkPatch::kNumPtsCubic]; |
this->getBottomPoints(pts); |
FwDCubicEvaluator fBottom(pts); |
this->getTopPoints(pts); |
@@ -236,3 +230,37 @@ bool SkPatch::getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const |
} |
return true; |
} |
+ |
+size_t SkPatch::writeToMemory(void* storage) const { |
+ int byteCount = kNumCtrlPts * sizeof(SkPoint) + kNumColors * sizeof(SkColor); |
+ |
+ if (NULL == storage) { |
+ return SkAlign4(byteCount); |
+ } |
+ |
+ SkWBuffer buffer(storage); |
+ |
+ buffer.write(fCtrlPoints, kNumCtrlPts * sizeof(SkPoint)); |
+ buffer.write(fCornerColors, kNumColors * sizeof(SkColor)); |
+ |
+ buffer.padToAlign4(); |
+ return buffer.pos(); |
+} |
+ |
+size_t SkPatch::readFromMemory(const void* storage, size_t length) { |
+ SkRBufferWithSizeCheck buffer(storage, length); |
+ |
+ int byteCount = 0; |
+ |
+ if (!buffer.read(fCtrlPoints, kNumCtrlPts * sizeof(SkPoint))) { |
robertphillips
2014/08/05 15:42:00
By the header comment - aren't we supposed to retu
dandov
2014/08/05 17:34:05
Done.
|
+ return byteCount; |
+ } |
+ byteCount += kNumCtrlPts * sizeof(SkPoint); |
+ |
+ if (!buffer.read(fCornerColors, kNumColors * sizeof(SkColor))) { |
robertphillips
2014/08/05 15:42:00
And here ?
dandov
2014/08/05 17:34:05
Done.
|
+ return byteCount; |
+ } |
+ byteCount += kNumColors * sizeof(SkColor); |
+ |
+ return byteCount; |
+} |