diff options
author | Joe Onorato <joeo@google.com> | 2011-01-19 14:52:51 -0800 |
---|---|---|
committer | Joe Onorato <joeo@google.com> | 2011-01-19 15:15:01 -0800 |
commit | 9221e8085d77b0850a07c6585275ec7bb7e0931a (patch) | |
tree | ac421f3009c984b0febaa2d885ad26406b7a082f | |
parent | b450292fabdb04f8904725898ab7fa84abe51bdf (diff) | |
download | external_skia-9221e8085d77b0850a07c6585275ec7bb7e0931a.zip external_skia-9221e8085d77b0850a07c6585275ec7bb7e0931a.tar.gz external_skia-9221e8085d77b0850a07c6585275ec7bb7e0931a.tar.bz2 |
Implement SkRegion::toString().
Change-Id: I012feed3eb119a9eda98989e13dacc53c0199e19
-rw-r--r-- | include/core/SkRegion.h | 4 | ||||
-rw-r--r-- | src/core/SkRegion.cpp | 28 |
2 files changed, 32 insertions, 0 deletions
diff --git a/include/core/SkRegion.h b/include/core/SkRegion.h index 8b15a89..09b835d 100644 --- a/include/core/SkRegion.h +++ b/include/core/SkRegion.h @@ -242,6 +242,10 @@ public: */ bool op(const SkRegion& rgna, const SkRegion& rgnb, Op op); + /** Returns a new char* containing the list of rectangles in this region + */ + char* toString(); + /** Returns the sequence of rectangles, sorted in Y and X, that make up this region. */ diff --git a/src/core/SkRegion.cpp b/src/core/SkRegion.cpp index a5a1555..565b6ad 100644 --- a/src/core/SkRegion.cpp +++ b/src/core/SkRegion.cpp @@ -18,6 +18,7 @@ #include "SkRegionPriv.h" #include "SkTemplates.h" #include "SkThread.h" +#include <stdio.h> SkDEBUGCODE(int32_t gRgnAllocCounter;) @@ -211,6 +212,33 @@ bool SkRegion::op(const SkRegion& rgn, const SkIRect& rect, Op op) ////////////////////////////////////////////////////////////////////////////////////// +char* SkRegion::toString() +{ + Iterator iter(*this); + int count = 0; + while (!iter.done()) { + count++; + iter.next(); + } + // 4 ints, up to 10 digits each plus sign, 3 commas, '(', ')', SkRegion() and '\0' + const int max = (count*((11*4)+5))+11+1; + char* result = (char*)malloc(max); + if (result == NULL) { + return NULL; + } + count = sprintf(result, "SkRegion("); + iter.reset(*this); + while (!iter.done()) { + const SkIRect& r = iter.rect(); + count += sprintf(result+count, "(%d,%d,%d,%d)", r.fLeft, r.fTop, r.fRight, r.fBottom); + iter.next(); + } + count += sprintf(result+count, ")"); + return result; +} + +////////////////////////////////////////////////////////////////////////////////////// + int SkRegion::count_runtype_values(int* itop, int* ibot) const { if (this == NULL) |