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

Side by Side Diff: src/utils/SkLua.cpp

Issue 177933003: Add getClipStack method to lua SkCanvas (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove extra code from lua script Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/utils/SkLua.h ('k') | tools/lua/dump_clipstack_at_restore.lua » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkLua.h" 8 #include "SkLua.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkClipStack.h"
10 #include "SkData.h" 11 #include "SkData.h"
11 #include "SkDocument.h" 12 #include "SkDocument.h"
12 #include "SkImage.h" 13 #include "SkImage.h"
13 #include "SkMatrix.h" 14 #include "SkMatrix.h"
14 #include "SkPaint.h" 15 #include "SkPaint.h"
15 #include "SkPath.h" 16 #include "SkPath.h"
16 #include "SkPixelRef.h" 17 #include "SkPixelRef.h"
17 #include "SkRRect.h" 18 #include "SkRRect.h"
18 #include "SkString.h" 19 #include "SkString.h"
19 #include "SkTypeface.h" 20 #include "SkTypeface.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void SkLua::pushPath(const SkPath& path, const char key[]) { 228 void SkLua::pushPath(const SkPath& path, const char key[]) {
228 push_obj(fL, path); 229 push_obj(fL, path);
229 CHECK_SETFIELD(key); 230 CHECK_SETFIELD(key);
230 } 231 }
231 232
232 void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) { 233 void SkLua::pushCanvas(SkCanvas* canvas, const char key[]) {
233 push_ref(fL, canvas); 234 push_ref(fL, canvas);
234 CHECK_SETFIELD(key); 235 CHECK_SETFIELD(key);
235 } 236 }
236 237
238 static const char* element_type(SkClipStack::Element::Type type) {
239 switch (type) {
240 case SkClipStack::Element::kEmpty_Type:
241 return "empty";
242 case SkClipStack::Element::kRect_Type:
243 return "rect";
244 case SkClipStack::Element::kRRect_Type:
245 return "rrect";
246 case SkClipStack::Element::kPath_Type:
247 return "path";
248 }
249 return "unknown";
250 }
251
252 static const char* region_op(SkRegion::Op op) {
253 switch (op) {
254 case SkRegion::kDifference_Op:
255 return "difference";
256 case SkRegion::kIntersect_Op:
257 return "intersect";
258 case SkRegion::kUnion_Op:
259 return "union";
260 case SkRegion::kXOR_Op:
261 return "xor";
262 case SkRegion::kReverseDifference_Op:
263 return "reverse-difference";
264 case SkRegion::kReplace_Op:
265 return "replace";
266 }
267 return "unknown";
268 }
269
270 void SkLua::pushClipStack(const SkClipStack& stack, const char* key) {
271 lua_newtable(fL);
272 SkClipStack::B2TIter iter(stack);
273 const SkClipStack::Element* element;
274 int i = 0;
275 while (NULL != (element = iter.next())) {
276 lua_newtable(fL);
277 SkClipStack::Element::Type type = element->getType();
278 this->pushString(element_type(type), "type");
279 switch (type) {
280 case SkClipStack::Element::kEmpty_Type:
281 break;
282 case SkClipStack::Element::kRect_Type:
283 this->pushRect(element->getRect(), "rect");
284 break;
285 case SkClipStack::Element::kRRect_Type:
286 this->pushRRect(element->getRRect(), "rrect");
287 break;
288 case SkClipStack::Element::kPath_Type:
289 this->pushPath(element->getPath(), "path");
290 break;
291 }
292 this->pushString(region_op(element->getOp()), "op");
293 this->pushBool(element->isAA(), "aa");
294 lua_rawseti(fL, -2, ++i);
295 }
296 CHECK_SETFIELD(key);
297 }
298
237 /////////////////////////////////////////////////////////////////////////////// 299 ///////////////////////////////////////////////////////////////////////////////
238 /////////////////////////////////////////////////////////////////////////////// 300 ///////////////////////////////////////////////////////////////////////////////
239 301
240 static SkScalar lua2scalar(lua_State* L, int index) { 302 static SkScalar lua2scalar(lua_State* L, int index) {
241 SkASSERT(lua_isnumber(L, index)); 303 SkASSERT(lua_isnumber(L, index));
242 return SkLuaToScalar(lua_tonumber(L, index)); 304 return SkLuaToScalar(lua_tonumber(L, index));
243 } 305 }
244 306
245 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) { 307 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) {
246 if (lua_isnumber(L, index)) { 308 if (lua_isnumber(L, index)) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 static int lcanvas_getSaveCount(lua_State* L) { 432 static int lcanvas_getSaveCount(lua_State* L) {
371 lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount()); 433 lua_pushnumber(L, get_ref<SkCanvas>(L, 1)->getSaveCount());
372 return 1; 434 return 1;
373 } 435 }
374 436
375 static int lcanvas_getTotalMatrix(lua_State* L) { 437 static int lcanvas_getTotalMatrix(lua_State* L) {
376 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix()); 438 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix());
377 return 1; 439 return 1;
378 } 440 }
379 441
442 static int lcanvas_getClipStack(lua_State* L) {
443 SkLua(L).pushClipStack(*get_ref<SkCanvas>(L, 1)->getClipStack());
444 return 1;
445 }
446
380 static int lcanvas_save(lua_State* L) { 447 static int lcanvas_save(lua_State* L) {
381 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save()); 448 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save());
382 return 1; 449 return 1;
383 } 450 }
384 451
385 static int lcanvas_restore(lua_State* L) { 452 static int lcanvas_restore(lua_State* L) {
386 get_ref<SkCanvas>(L, 1)->restore(); 453 get_ref<SkCanvas>(L, 1)->restore();
387 return 0; 454 return 0;
388 } 455 }
389 456
(...skipping 25 matching lines...) Expand all
415 static const struct luaL_Reg gSkCanvas_Methods[] = { 482 static const struct luaL_Reg gSkCanvas_Methods[] = {
416 { "drawColor", lcanvas_drawColor }, 483 { "drawColor", lcanvas_drawColor },
417 { "drawRect", lcanvas_drawRect }, 484 { "drawRect", lcanvas_drawRect },
418 { "drawOval", lcanvas_drawOval }, 485 { "drawOval", lcanvas_drawOval },
419 { "drawCircle", lcanvas_drawCircle }, 486 { "drawCircle", lcanvas_drawCircle },
420 { "drawImage", lcanvas_drawImage }, 487 { "drawImage", lcanvas_drawImage },
421 { "drawPath", lcanvas_drawPath }, 488 { "drawPath", lcanvas_drawPath },
422 { "drawText", lcanvas_drawText }, 489 { "drawText", lcanvas_drawText },
423 { "getSaveCount", lcanvas_getSaveCount }, 490 { "getSaveCount", lcanvas_getSaveCount },
424 { "getTotalMatrix", lcanvas_getTotalMatrix }, 491 { "getTotalMatrix", lcanvas_getTotalMatrix },
492 { "getClipStack", lcanvas_getClipStack },
425 { "save", lcanvas_save }, 493 { "save", lcanvas_save },
426 { "restore", lcanvas_restore }, 494 { "restore", lcanvas_restore },
427 { "scale", lcanvas_scale }, 495 { "scale", lcanvas_scale },
428 { "translate", lcanvas_translate }, 496 { "translate", lcanvas_translate },
429 { "rotate", lcanvas_rotate }, 497 { "rotate", lcanvas_rotate },
430 { "__gc", lcanvas_gc }, 498 { "__gc", lcanvas_gc },
431 { NULL, NULL } 499 { NULL, NULL }
432 }; 500 };
433 501
434 /////////////////////////////////////////////////////////////////////////////// 502 ///////////////////////////////////////////////////////////////////////////////
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 REG_CLASS(L, SkShader); 1296 REG_CLASS(L, SkShader);
1229 REG_CLASS(L, SkTypeface); 1297 REG_CLASS(L, SkTypeface);
1230 REG_CLASS(L, SkMatrix); 1298 REG_CLASS(L, SkMatrix);
1231 } 1299 }
1232 1300
1233 extern "C" int luaopen_skia(lua_State* L); 1301 extern "C" int luaopen_skia(lua_State* L);
1234 extern "C" int luaopen_skia(lua_State* L) { 1302 extern "C" int luaopen_skia(lua_State* L) {
1235 SkLua::Load(L); 1303 SkLua::Load(L);
1236 return 0; 1304 return 0;
1237 } 1305 }
OLDNEW
« no previous file with comments | « include/utils/SkLua.h ('k') | tools/lua/dump_clipstack_at_restore.lua » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698