| Index: src/core/SkPatch.cpp
|
| diff --git a/src/core/SkPatch.cpp b/src/core/SkPatch.cpp
|
| index cc967d5ceece7d1698cbc0648c2f1ae39fc22b0c..1831669d7255094e9830812c2c488c9b424e6974 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,9 @@ 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[SkPatch::kNumCtrlPts],
|
| + const SkColor colors[SkPatch::kNumColors]) {
|
| + this->reset(points, colors);
|
| }
|
|
|
| uint8_t bilinear(SkScalar tx, SkScalar ty, SkScalar c00, SkScalar c10, SkScalar c01, SkScalar c11) {
|
| @@ -141,8 +136,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 +152,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 +231,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))) {
|
| + return byteCount;
|
| + }
|
| + byteCount += kNumCtrlPts * sizeof(SkPoint);
|
| +
|
| + if (!buffer.read(fCornerColors, kNumColors * sizeof(SkColor))) {
|
| + return byteCount;
|
| + }
|
| + byteCount += kNumColors * sizeof(SkColor);
|
| +
|
| + return byteCount;
|
| +}
|
|
|