Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: src/utils/SkLua.cpp

Issue 267423006: Add asADash to Lua for scraping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/utils/SkLua.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkLua.cpp
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 346899a5dde785b0e00fd233aa1df8df494b7c06..50478773240ef046dcc8c846176e066cbe84282f 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -18,7 +18,6 @@
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkPath.h"
-#include "SkPathEffect.h"
#include "SkPixelRef.h"
#include "SkRRect.h"
#include "SkString.h"
@@ -157,6 +156,10 @@ static void setarray_number(lua_State* L, int index, double value) {
lua_rawseti(L, -2, index);
}
+static void setarray_scalar(lua_State* L, int index, SkScalar value) {
+ setarray_number(L, index, SkScalarToLua(value));
+}
+
void SkLua::pushBool(bool value, const char key[]) {
lua_pushboolean(fL, value);
CHECK_SETFIELD(key);
@@ -219,6 +222,15 @@ void SkLua::pushArrayPoint(const SkPoint array[], int count, const char key[]) {
CHECK_SETFIELD(key);
}
+void SkLua::pushArrayScalar(const SkScalar array[], int count, const char key[]) {
+ lua_newtable(fL);
+ for (int i = 0; i < count; ++i) {
+ // make it base-1 to match lua convention
+ setarray_scalar(fL, i + 1, array[i]);
+ }
+ CHECK_SETFIELD(key);
+}
+
void SkLua::pushRect(const SkRect& r, const char key[]) {
lua_newtable(fL);
setfield_scalar(fL, "left", r.fLeft);
@@ -233,6 +245,14 @@ void SkLua::pushRRect(const SkRRect& rr, const char key[]) {
CHECK_SETFIELD(key);
}
+void SkLua::pushDash(const SkPathEffect::DashInfo& info, const char key[]) {
+ lua_newtable(fL);
+ setfield_scalar(fL, "phase", info.fPhase);
+ this->pushArrayScalar(info.fIntervals, info.fCount, "intervals");
+ CHECK_SETFIELD(key);
+}
+
+
void SkLua::pushMatrix(const SkMatrix& matrix, const char key[]) {
push_obj(fL, matrix);
CHECK_SETFIELD(key);
@@ -1006,12 +1026,29 @@ static const struct luaL_Reg gSkShader_Methods[] = {
///////////////////////////////////////////////////////////////////////////////
+static int lpatheffect_asADash(lua_State* L) {
+ SkPathEffect* pe = get_ref<SkPathEffect>(L, 1);
+ if (pe) {
+ SkPathEffect::DashInfo info;
+ SkPathEffect::DashType dashType = pe->asADash(&info);
+ if (SkPathEffect::kDash_DashType == dashType) {
+ SkAutoTArray<SkScalar> intervals(info.fCount);
+ info.fIntervals = intervals.get();
+ pe->asADash(&info);
+ SkLua(L).pushDash(info);
+ return 1;
+ }
+ }
+ return 0;
+}
+
static int lpatheffect_gc(lua_State* L) {
get_ref<SkPathEffect>(L, 1)->unref();
return 0;
}
static const struct luaL_Reg gSkPathEffect_Methods[] = {
+ { "asADash", lpatheffect_asADash },
{ "__gc", lpatheffect_gc },
{ NULL, NULL }
};
« no previous file with comments | « include/utils/SkLua.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698