friend class SkDrawIter; // needs setupDrawForLayerDevice()
friend class AutoDrawLooper;
- friend class SkLua; // needs top layer size and offset
friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip
friend class SkSurface_Raster; // needs getDevice()
friend class SkRecorder; // resetForNextPicture
#ifndef SkLua_DEFINED
#define SkLua_DEFINED
-#include "SkClipStack.h"
#include "SkColor.h"
#include "SkPathEffect.h"
#include "SkScalar.h"
void pushPaint(const SkPaint&, const char tableKey[] = NULL);
void pushPath(const SkPath&, const char tableKey[] = NULL);
void pushCanvas(SkCanvas*, const char tableKey[] = NULL);
- void pushClipStack(const SkClipStack&, const char tableKey[] = NULL);
- void pushClipStackElement(const SkClipStack::Element& element, const char tableKey[] = NULL);
void pushTextBlob(const SkTextBlob*, const char tableKey[] = NULL);
- // This SkCanvas lua methods is declared here to benefit from SkLua's friendship with SkCanvas.
- static int lcanvas_getReducedClipStack(lua_State* L);
-
private:
lua_State* fL;
SkString fTermCode;
#include "SkLua.h"
#if SK_SUPPORT_GPU
-#include "GrReducedClip.h"
+//#include "GrReducedClip.h"
#endif
#include "SkBlurImageFilter.h"
CHECK_SETFIELD(key);
}
-static const char* element_type(SkClipStack::Element::Type type) {
- switch (type) {
- case SkClipStack::Element::kEmpty_Type:
- return "empty";
- case SkClipStack::Element::kRect_Type:
- return "rect";
- case SkClipStack::Element::kRRect_Type:
- return "rrect";
- case SkClipStack::Element::kPath_Type:
- return "path";
- }
- return "unknown";
-}
-
-static const char* region_op(SkRegion::Op op) {
- switch (op) {
- case SkRegion::kDifference_Op:
- return "difference";
- case SkRegion::kIntersect_Op:
- return "intersect";
- case SkRegion::kUnion_Op:
- return "union";
- case SkRegion::kXOR_Op:
- return "xor";
- case SkRegion::kReverseDifference_Op:
- return "reverse-difference";
- case SkRegion::kReplace_Op:
- return "replace";
- }
- return "unknown";
-}
-
-void SkLua::pushClipStack(const SkClipStack& stack, const char* key) {
- lua_newtable(fL);
- SkClipStack::B2TIter iter(stack);
- const SkClipStack::Element* element;
- int i = 0;
- while ((element = iter.next())) {
- this->pushClipStackElement(*element);
- lua_rawseti(fL, -2, ++i);
- }
- CHECK_SETFIELD(key);
-}
-
-void SkLua::pushClipStackElement(const SkClipStack::Element& element, const char* key) {
- lua_newtable(fL);
- SkClipStack::Element::Type type = element.getType();
- this->pushString(element_type(type), "type");
- switch (type) {
- case SkClipStack::Element::kEmpty_Type:
- break;
- case SkClipStack::Element::kRect_Type:
- this->pushRect(element.getRect(), "rect");
- break;
- case SkClipStack::Element::kRRect_Type:
- this->pushRRect(element.getRRect(), "rrect");
- break;
- case SkClipStack::Element::kPath_Type:
- this->pushPath(element.getPath(), "path");
- break;
- }
- this->pushString(region_op((SkRegion::Op)element.getOp()), "op");
- this->pushBool(element.isAA(), "aa");
- CHECK_SETFIELD(key);
-}
-
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
return 1;
}
-static int lcanvas_getClipStack(lua_State* L) {
- SkLua(L).pushClipStack(*get_ref<SkCanvas>(L, 1)->getClipStack());
- return 1;
-}
-
-int SkLua::lcanvas_getReducedClipStack(lua_State* L) {
-#if SK_SUPPORT_GPU
- const SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
- SkRect queryBounds = SkRect::Make(canvas->getTopLayerBounds());
- const GrReducedClip reducedClip(*canvas->getClipStack(), queryBounds);
-
- GrReducedClip::ElementList::Iter iter(reducedClip.elements());
- int i = 0;
- lua_newtable(L);
- while(iter.get()) {
- SkLua(L).pushClipStackElement(*iter.get());
- iter.next();
- lua_rawseti(L, -2, ++i);
- }
- // Currently this only returns the element list to lua, not the initial state or result bounds.
- // It could return these as additional items on the lua stack.
- return 1;
-#else
- return 0;
-#endif
-}
-
static int lcanvas_save(lua_State* L) {
lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save());
return 1;
{ "drawTextBlob", lcanvas_drawTextBlob },
{ "getSaveCount", lcanvas_getSaveCount },
{ "getTotalMatrix", lcanvas_getTotalMatrix },
- { "getClipStack", lcanvas_getClipStack },
-#if SK_SUPPORT_GPU
- { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack },
-#endif
{ "save", lcanvas_save },
{ "saveLayer", lcanvas_saveLayer },
{ "restore", lcanvas_restore },
+++ /dev/null
-stats = {}
-
--- switch this to run on the automated scraper system
-newline = "\n"
--- newline = "\\n"
-
-function sk_scrape_startcanvas(c, fileName)
- canvas = c
- oldstackstr = "<invalid>"
-end
-
-function sk_scrape_endcanvas(c, fileName)
- canvas = nil
-end
-
-function string.starts(String,Start)
- return string.sub(String,1,string.len(Start))==Start
-end
-
-function build_stack_string(stack)
- local info = ""
- for i = 1, #stack do
- local element = stack[i];
- info = info .. element["op"] .. ", " .. element["type"] .. ", aa:" .. tostring(element["aa"])
- if (element["type"] == "path") then
- if (element["path"]:getSegmentTypes() == "line" and element["path"]:isConvex()) then
- info = info .. ", convex_poly " .. element["path"]:countPoints() .. " points"
- else
- info = info .. ", fill: " .. element["path"]:getFillType()
- info = info .. ", segments: (" .. element["path"]:getSegmentTypes() .. ")"
- info = info .. ", convex:" .. tostring(element["path"]:isConvex())
- end
- end
- info = info .. newline
- end
- return info
-end
-
-function sk_scrape_accumulate(t)
- if (string.starts(t.verb, "draw")) then
- local stack = canvas:getReducedClipStack()
- local stackstr = build_stack_string(stack)
- if (stackstr ~= "") then
- if (stats[stackstr] == nil) then
- stats[stackstr] = {}
- stats[stackstr].drawCnt = 0
- stats[stackstr].instanceCnt = 0
- end
- stats[stackstr].drawCnt = stats[stackstr].drawCnt + 1
- if (stackstr ~= oldstackstr) then
- stats[stackstr].instanceCnt = stats[stackstr].instanceCnt + 1
- end
- end
- oldstackstr = stackstr
- end
-end
-
-function print_stats(stats)
- function sort_by_draw_cnt(a, b)
- return a.data.drawCnt > b.data.drawCnt
- end
- array = {}
- for k,v in pairs(stats) do
- array[#array + 1] = { name = k, data = v }
- end
- table.sort(array, sort_by_draw_cnt)
- for i = 1, #array do
- io.write("\n-------\n", array[i].name, tostring(array[i].data.drawCnt), " draws, ", tostring(array[i].data.instanceCnt), " instances.\n")
- end
-end
-
-function sk_scrape_summarize()
- print_stats(stats)
- --[[ To use the web scraper comment out the print above, run the code below to generate an
- aggregate table on the automated scraper system. Then use the print_stats function on
- agg_stats in the aggregator step.
- for k,v in pairs(stats) do
- if (v.drawCnt ~= nil) then
- -- io.write("\n-------\n", k, tostring(v.drawCnt), " draws, ", tostring(v.instanceCnt), " instances.\n")
- local tableEntry = 'agg_stats["' .. k .. '"]'
- io.write(tableEntry, " = ", tableEntry, " or {}\n")
- io.write(tableEntry, ".drawCnt = (", tableEntry, ".drawCnt or 0 ) + ", v.drawCnt, "\n")
- io.write(tableEntry, ".instanceCnt = (", tableEntry, ".instanceCnt or 0 ) + ", v.instanceCnt, "\n")
- end
- end
- --]]
-end
+++ /dev/null
-function sk_scrape_startcanvas(c, fileName)
- canvas = c
- clipstack = {}
- restoreCount = 0
-end
-
-function sk_scrape_endcanvas(c, fileName)
- canvas = nil
-end
-
-function sk_scrape_accumulate(t)
- if (t.verb == "restore") then
- restoreCount = restoreCount + 1;
- -- io.write("Clip Stack at restore #", restoreCount, ":\n")
- io.write("Reduced 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"]))
- 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
- -- clipstack = canvas:getClipStack()
- clipstack = canvas:getReducedClipStack()
- end
-end
-
-function sk_scrape_summarize() end