diff options
author | hstern <hstern@google.com> | 2016-08-02 09:17:59 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-02 09:17:59 -0700 |
commit | 0b401ce663ef80222e0eb3a54bdd4c42af8e48e1 (patch) | |
tree | 47ddeb87c605f20d65dbc0f7dbbda85e1a11a88a | |
parent | 86baf3d8de02a2118ac6e603b1152c3bc5d8b2b3 (diff) |
Add code to lua paths to get the fill path and get lists of verbs and
points
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2199823002
Review-Url: https://codereview.chromium.org/2199823002
-rw-r--r-- | src/utils/SkLua.cpp | 59 | ||||
-rw-r--r-- | tools/lua/count_dashes.lua | 60 |
2 files changed, 119 insertions, 0 deletions
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index a3a1685eae..3a335ad17c 100644 --- a/src/utils/SkLua.cpp +++ b/src/utils/SkLua.cpp @@ -221,6 +221,11 @@ static void setarray_scalar(lua_State* L, int index, SkScalar value) { setarray_number(L, index, SkScalarToLua(value)); } +static void setarray_string(lua_State* L, int index, const char str[]) { + lua_pushstring(L, str); + lua_rawseti(L, -2, index); +} + void SkLua::pushBool(bool value, const char key[]) { lua_pushboolean(fL, value); CHECK_SETFIELD(key); @@ -1159,6 +1164,19 @@ static int lpaint_getPathEffect(lua_State* L) { return 0; } +static int lpaint_getFillPath(lua_State* L) { + const SkPaint* paint = get_obj<SkPaint>(L, 1); + const SkPath* path = get_obj<SkPath>(L, 2); + + SkPath fillpath; + paint->getFillPath(*path, &fillpath); + + SkLua lua(L); + lua.pushPath(fillpath); + + return 1; +} + static int lpaint_gc(lua_State* L) { get_obj<SkPaint>(L, 1)->~SkPaint(); return 0; @@ -1217,6 +1235,7 @@ static const struct luaL_Reg gSkPaint_Methods[] = { { "getShader", lpaint_getShader }, { "setShader", lpaint_setShader }, { "getPathEffect", lpaint_getPathEffect }, + { "getFillPath", lpaint_getFillPath }, { "__gc", lpaint_gc }, { nullptr, nullptr } }; @@ -1586,6 +1605,45 @@ static int lpath_countPoints(lua_State* L) { return 1; } +static int lpath_getVerbs(lua_State* L) { + const SkPath* path = get_obj<SkPath>(L, 1); + SkPath::Iter iter(*path, false); + SkPoint pts[4]; + + lua_newtable(L); + + bool done = false; + int i = 0; + do { + switch (iter.next(pts, true)) { + case SkPath::kMove_Verb: + setarray_string(L, ++i, "move"); + break; + case SkPath::kClose_Verb: + setarray_string(L, ++i, "close"); + break; + case SkPath::kLine_Verb: + setarray_string(L, ++i, "line"); + break; + case SkPath::kQuad_Verb: + setarray_string(L, ++i, "quad"); + break; + case SkPath::kConic_Verb: + setarray_string(L, ++i, "conic"); + break; + case SkPath::kCubic_Verb: + setarray_string(L, ++i, "cubic"); + break; + case SkPath::kDone_Verb: + setarray_string(L, ++i, "done"); + done = true; + break; + } + } while (!done); + + return 1; +} + static int lpath_reset(lua_State* L) { get_obj<SkPath>(L, 1)->reset(); return 0; @@ -1628,6 +1686,7 @@ static const struct luaL_Reg gSkPath_Methods[] = { { "getBounds", lpath_getBounds }, { "getFillType", lpath_getFillType }, { "getSegmentTypes", lpath_getSegmentTypes }, + { "getVerbs", lpath_getVerbs }, { "isConvex", lpath_isConvex }, { "isEmpty", lpath_isEmpty }, { "isRect", lpath_isRect }, diff --git a/tools/lua/count_dashes.lua b/tools/lua/count_dashes.lua new file mode 100644 index 0000000000..20502a9f01 --- /dev/null +++ b/tools/lua/count_dashes.lua @@ -0,0 +1,60 @@ +-- +-- Copyright 2016 Google Inc. +-- +-- Use of this source code is governed by a BSD-style license that can be +-- found in the LICENSE file. +-- + +-- Dashed path scraping script. +-- This script is designed to count the total number of dashes in a dashed path +-- by computing the fill path and then counting how many individual segments are +-- inside the resulting fill path. + +dashes = 0 + +pathPieces = {} + +function sk_scrape_startcanvas(c, fileName) +end + +function sk_scrape_endcanvas(c, fileName) +end + +function sk_scrape_accumulate(t) + local paint = t.paint + if paint then + local pe = paint:getPathEffect() + if pe then + if t.verb == "drawPath" and pe:asADash() then + dashes = dashes + 1 + pathPieces[dashes] = 0 + + local path = t.path + local fillpath = paint:getFillPath(path) + local verbs = fillpath:getVerbs() + for _, verb in ipairs(verbs) do + if verb == "move" then + pathPieces[dashes] = pathPieces[dashes] + 1 + end + end + end + end + end +end + +-- We mulitply by two because for each segment of the dash, we do two measurements: +-- One for the beginning and one for the end of each dash. +function sk_scrape_summarize() + local pieces5 = 0; + local pieces10 = 0; + for _, p in ipairs(pathPieces) do + local pieces = 2*p + if pieces < 5 then + pieces5 = pieces5 + 1 + end + if pieces > 5 and pieces < 10 then + pieces10 = pieces10 + 1 + end + end + io.write(string.format("%d %d %d\n", 2*dashes, pieces5, pieces10)) +end |