Add some SkPath lua functions
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 24 Feb 2014 21:59:29 +0000 (21:59 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 24 Feb 2014 21:59:29 +0000 (21:59 +0000)
R=reed@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/178243002

git-svn-id: http://skia.googlecode.com/svn/trunk@13572 2bbb7eff-a529-9590-31e7-b0007b416f81

src/utils/SkLua.cpp
tools/lua/dump_clipstack_at_restore.lua

index d6ce0239e1c7edaa6c6bfd6c346da292b296ee9c..ec276db1f607b416efdea4bccdb8f3883fdf2d0d 100644 (file)
@@ -976,6 +976,73 @@ static int lpath_getBounds(lua_State* L) {
     return 1;
 }
 
+static const char* fill_type_to_str(SkPath::FillType fill) {
+    switch (fill) {
+        case SkPath::kEvenOdd_FillType:
+            return "even-odd";
+        case SkPath::kWinding_FillType:
+            return "winding";
+        case SkPath::kInverseEvenOdd_FillType:
+            return "inverse-even-odd";
+        case SkPath::kInverseWinding_FillType:
+            return "inverse-winding";
+    }
+    return "unknown";
+}
+
+static int lpath_getFillType(lua_State* L) {
+    SkPath::FillType fill = get_obj<SkPath>(L, 1)->getFillType();
+    SkLua(L).pushString(fill_type_to_str(fill));
+    return 1;
+}
+
+static SkString segment_masks_to_str(uint32_t segmentMasks) {
+    SkString result;
+    bool first = true;
+    if (SkPath::kLine_SegmentMask & segmentMasks) {
+        result.append("line");
+        first = false;
+        SkDEBUGCODE(segmentMasks &= ~SkPath::kLine_SegmentMask;)
+    }
+    if (SkPath::kQuad_SegmentMask & segmentMasks) {
+        if (!first) {
+            result.append(" ");
+        }
+        result.append("quad");
+        first = false;
+        SkDEBUGCODE(segmentMasks &= ~SkPath::kQuad_SegmentMask;)
+    }
+    if (SkPath::kConic_SegmentMask & segmentMasks) {
+        if (!first) {
+            result.append(" ");
+        }
+        result.append("conic");
+        first = false;
+        SkDEBUGCODE(segmentMasks &= ~SkPath::kConic_SegmentMask;)
+    }
+    if (SkPath::kCubic_SegmentMask & segmentMasks) {
+        if (!first) {
+            result.append(" ");
+        }
+        result.append("cubic");
+        SkDEBUGCODE(segmentMasks &= ~SkPath::kCubic_SegmentMask;)
+    }
+    SkASSERT(0 == segmentMasks);
+    return result;
+}
+
+static int lpath_getSegementTypes(lua_State* L) {
+    uint32_t segMasks = get_obj<SkPath>(L, 1)->getSegmentMasks();
+    SkLua(L).pushString(segment_masks_to_str(segMasks));
+    return 1;
+}
+
+static int lpath_isConvex(lua_State* L) {
+    bool isConvex = SkPath::kConvex_Convexity == get_obj<SkPath>(L, 1)->getConvexity();
+    SkLua(L).pushBool(isConvex);
+    return 1;
+}
+
 static int lpath_isEmpty(lua_State* L) {
     lua_pushboolean(L, get_obj<SkPath>(L, 1)->isEmpty());
     return 1;
@@ -1058,6 +1125,9 @@ static int lpath_gc(lua_State* L) {
 
 static const struct luaL_Reg gSkPath_Methods[] = {
     { "getBounds", lpath_getBounds },
+    { "getFillType", lpath_getFillType },
+    { "getSegmentTypes", lpath_getSegementTypes },
+    { "isConvex", lpath_isConvex },
     { "isEmpty", lpath_isEmpty },
     { "isRect", lpath_isRect },
     { "isNestedRects", lpath_isNestedRects },
index d53f5a3712b924acd3ca49b7b5faefa7fb604728..4691b5b250720fd6c906b3b9958cda7c14d3d8e9 100644 (file)
@@ -14,7 +14,13 @@ function sk_scrape_accumulate(t)
         io.write("Clip Stack at restore #", restoreCount, ":\n")
         for i = 1, #clipstack do
             local element = clipstack[i];
-            io.write("\t", element["op"], ", ", element["type"], ", aa:", tostring(element["aa"]), "\n")
+            io.write("\t", element["op"], ", ", element["type"], ", aa:", tostring(element["aa"]))
+            if (element["type"] == "path") then
+                io.write(", fill: ", element["path"]:getFillType())
+                io.write(", segments: \"", element["path"]:getSegmentTypes(), "\"")
+                io.write(", convex:", tostring(element["path"]:isConvex()))
+            end
+            io.write("\n")
         end
         io.write("\n")
     else