aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-29 19:54:52 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-29 19:54:52 +0000
commit744fabad474e3e111e7cbd8609cf7e209df17f32 (patch)
treed6248924804bf175d102ebe6c01306b8eec89e40 /src
parent4196c0e0e8f39a125dca5d7111449df34dfeadbe (diff)
addPoly() entry-point, to quickly add MoveTo+N*LineTo (useful in dashing)
Review URL: https://codereview.appspot.com/6256063 git-svn-id: http://skia.googlecode.com/svn/trunk@4061 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkPath.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index ee6a1712f5..5f63651d6d 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -12,6 +12,11 @@
#include "SkWriter32.h"
#include "SkMath.h"
+// This value is just made-up for now. When count is 4, calling memset was much
+// slower than just writing the loop. This seems odd, and hopefully in the
+// future this we appear to have been a fluke...
+#define MIN_COUNT_FOR_MEMSET_TO_BE_FAST 16
+
////////////////////////////////////////////////////////////////////////////
/**
@@ -627,6 +632,39 @@ void SkPath::addRect(SkScalar left, SkScalar top, SkScalar right,
this->close();
}
+void SkPath::addPoly(const SkPoint pts[], int count, bool close) {
+ SkDEBUGCODE(this->validate();)
+ if (count <= 0) {
+ return;
+ }
+
+ fLastMoveToIndex = fPts.count();
+ fPts.append(count, pts);
+
+ // +close makes room for the extra kClose_Verb
+ uint8_t* vb = fVerbs.append(count + close);
+ vb[0] = kMove_Verb;
+
+ if (count > 1) {
+ // cast to unsigned, so if MIN_COUNT_FOR_MEMSET_TO_BE_FAST is defined to
+ // be 0, the compiler will remove the test/branch entirely.
+ if ((unsigned)count >= MIN_COUNT_FOR_MEMSET_TO_BE_FAST) {
+ memset(&vb[1], kLine_Verb, count - 1);
+ } else {
+ for (int i = 1; i < count; ++i) {
+ vb[i] = kLine_Verb;
+ }
+ }
+ fSegmentMask |= kLine_SegmentMask;
+ }
+ if (close) {
+ vb[count] = kClose_Verb;
+ }
+
+ GEN_ID_INC;
+ DIRTY_AFTER_EDIT;
+}
+
#define CUBIC_ARC_FACTOR ((SK_ScalarSqrt2 - SK_Scalar1) * 4 / 3)
void SkPath::addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry,