aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar dandov <dandov@google.com>2014-08-07 07:49:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-07 07:49:53 -0700
commit963137b75c0a1fe91f35e9826742f36309f5e65d (patch)
treeff5a20f44233835c8faecc42b7c77de014aab433 /include
parent2dd85a3eb280f5ecc2c35be57da779ed7bddaad3 (diff)
Stopped skipping tests in dm of SkPatch by implementing the
corresponding drawPath calls on classes that derive from SkCanvas. BUG=skia: R=egdaniel@google.com, bsalomon@google.com, mtklein@google.com, robertphillips@google.com Author: dandov@google.com Review URL: https://codereview.chromium.org/429343004
Diffstat (limited to 'include')
-rw-r--r--include/core/SkCanvas.h7
-rw-r--r--include/core/SkPatch.h42
-rw-r--r--include/core/SkReadBuffer.h1
-rw-r--r--include/core/SkReader32.h13
-rw-r--r--include/core/SkWriter32.h7
-rw-r--r--include/utils/SkDumpCanvas.h2
-rw-r--r--include/utils/SkNWayCanvas.h1
-rw-r--r--include/utils/SkProxyCanvas.h1
8 files changed, 67 insertions, 7 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 5c4db207cc..f74ebb7f56 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -1008,6 +1008,13 @@ public:
const uint16_t indices[], int indexCount,
const SkPaint& paint);
+ /**
+
+ Draw a SkPatch
+
+ @param patch specifies the 4 bounding cubic bezier curves of a patch.
+ @param paint Specifies the shader/texture if present.
+ */
virtual void drawPatch(const SkPatch& patch, const SkPaint& paint);
/** Send a blob of data to the canvas.
diff --git a/include/core/SkPatch.h b/include/core/SkPatch.h
index 3e06c3fc91..698b1cbf30 100644
--- a/include/core/SkPatch.h
+++ b/include/core/SkPatch.h
@@ -77,6 +77,12 @@ public:
kBottomLeft_CornerColors
};
+ enum {
+ kNumCtrlPts = 12,
+ kNumColors = 4,
+ kNumPtsCubic = 4
+ };
+
/**
* Points are in the following order:
* (top curve)
@@ -86,7 +92,8 @@ public:
* 9 8 7 6
* (bottom curve)
*/
- SkPatch(SkPoint points[12], SkColor colors[4]);
+ SkPatch() { }
+ SkPatch(const SkPoint points[12], const SkColor colors[4]);
/**
* Function that evaluates the coons patch interpolation.
@@ -138,9 +145,38 @@ public:
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);
+ }
+
+ /**
+ * Write the patch to the buffer, and return the number of bytes written.
+ * If buffer is NULL, it still returns the number of bytes.
+ */
+ size_t writeToMemory(void* buffer) const;
+
+ /**
+ * Initializes the patch from the buffer
+ *
+ * buffer Memory to read from
+ * length Amount of memory available in the buffer
+ * returns the number of bytes read (must be a multiple of 4) or
+ * 0 if there was not enough memory available
+ */
+ size_t readFromMemory(const void* buffer, size_t length);
+
private:
- SkPoint fCtrlPoints[12];
- SkColor fCornerColors[4];
+ SkPoint fCtrlPoints[kNumCtrlPts];
+ SkColor fCornerColors[kNumColors];
};
#endif
diff --git a/include/core/SkReadBuffer.h b/include/core/SkReadBuffer.h
index 2beb7ac738..e4f33af038 100644
--- a/include/core/SkReadBuffer.h
+++ b/include/core/SkReadBuffer.h
@@ -108,6 +108,7 @@ public:
virtual void readIRect(SkIRect* rect);
virtual void readRect(SkRect* rect);
virtual void readRegion(SkRegion* region);
+ virtual void readPatch(SkPatch* patch);
virtual void readPath(SkPath* path);
void readPaint(SkPaint* paint) { paint->unflatten(*this); }
diff --git a/include/core/SkReader32.h b/include/core/SkReader32.h
index 51e28ef146..3ee63bed18 100644
--- a/include/core/SkReader32.h
+++ b/include/core/SkReader32.h
@@ -15,6 +15,7 @@
#include "SkRegion.h"
#include "SkRRect.h"
#include "SkScalar.h"
+#include "SkPatch.h"
class SkString;
@@ -105,21 +106,25 @@ public:
uint16_t readU16() { return (uint16_t)this->readInt(); }
int32_t readS32() { return this->readInt(); }
uint32_t readU32() { return this->readInt(); }
+
+ bool readPatch(SkPatch* patch) {
+ return this->readObjectFromMemory(patch);
+ }
bool readPath(SkPath* path) {
- return readObjectFromMemory(path);
+ return this->readObjectFromMemory(path);
}
bool readMatrix(SkMatrix* matrix) {
- return readObjectFromMemory(matrix);
+ return this->readObjectFromMemory(matrix);
}
bool readRRect(SkRRect* rrect) {
- return readObjectFromMemory(rrect);
+ return this->readObjectFromMemory(rrect);
}
bool readRegion(SkRegion* rgn) {
- return readObjectFromMemory(rgn);
+ return this->readObjectFromMemory(rgn);
}
/**
diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h
index fd24ba9ddf..737ffd581d 100644
--- a/include/core/SkWriter32.h
+++ b/include/core/SkWriter32.h
@@ -12,6 +12,7 @@
#include "SkData.h"
#include "SkMatrix.h"
+#include "SkPatch.h"
#include "SkPath.h"
#include "SkPoint.h"
#include "SkRRect.h"
@@ -137,6 +138,12 @@ public:
void writeRRect(const SkRRect& rrect) {
rrect.writeToMemory(this->reserve(SkRRect::kSizeInMemory));
}
+
+ void writePatch(const SkPatch& patch) {
+ size_t size = patch.writeToMemory(NULL);
+ SkASSERT(SkAlign4(size) == size);
+ patch.writeToMemory(this->reserve(size));
+ }
void writePath(const SkPath& path) {
size_t size = path.writeToMemory(NULL);
diff --git a/include/utils/SkDumpCanvas.h b/include/utils/SkDumpCanvas.h
index 91d698fa38..53b97554b5 100644
--- a/include/utils/SkDumpCanvas.h
+++ b/include/utils/SkDumpCanvas.h
@@ -46,6 +46,7 @@ public:
kDrawText_Verb,
kDrawPicture_Verb,
kDrawVertices_Verb,
+ kDrawPatch_Verb,
kDrawData_Verb,
kBeginCommentGroup_Verb,
@@ -95,6 +96,7 @@ public:
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint) SK_OVERRIDE;
+ virtual void drawPatch(const SkPatch& patch, const SkPaint& paint) SK_OVERRIDE;
virtual void drawData(const void*, size_t) SK_OVERRIDE;
virtual void beginCommentGroup(const char* description) SK_OVERRIDE;
virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
diff --git a/include/utils/SkNWayCanvas.h b/include/utils/SkNWayCanvas.h
index aabf27436c..a4bfa887f9 100644
--- a/include/utils/SkNWayCanvas.h
+++ b/include/utils/SkNWayCanvas.h
@@ -48,6 +48,7 @@ public:
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint&) SK_OVERRIDE;
+ virtual void drawPatch(const SkPatch& patch, const SkPaint& paint) SK_OVERRIDE;
virtual void drawData(const void* data, size_t length) SK_OVERRIDE;
virtual SkDrawFilter* setDrawFilter(SkDrawFilter*) SK_OVERRIDE;
diff --git a/include/utils/SkProxyCanvas.h b/include/utils/SkProxyCanvas.h
index 6055db9bed..d31806ff44 100644
--- a/include/utils/SkProxyCanvas.h
+++ b/include/utils/SkProxyCanvas.h
@@ -47,6 +47,7 @@ public:
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint) SK_OVERRIDE;
+ virtual void drawPatch(const SkPatch& patch, const SkPaint& paint) SK_OVERRIDE;
virtual void drawData(const void* data, size_t length) SK_OVERRIDE;
virtual void beginCommentGroup(const char* description) SK_OVERRIDE;