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

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

Issue 180283004: Add getReducedClipStack to lua canvas (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: make getTopLayer*() private Created 6 years, 9 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 | « src/core/SkTLList.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
10 #include "GrReducedClip.h"
9 #include "SkCanvas.h" 11 #include "SkCanvas.h"
10 #include "SkClipStack.h"
11 #include "SkData.h" 12 #include "SkData.h"
12 #include "SkDocument.h" 13 #include "SkDocument.h"
13 #include "SkImage.h" 14 #include "SkImage.h"
14 #include "SkMatrix.h" 15 #include "SkMatrix.h"
15 #include "SkPaint.h" 16 #include "SkPaint.h"
16 #include "SkPath.h" 17 #include "SkPath.h"
17 #include "SkPixelRef.h" 18 #include "SkPixelRef.h"
18 #include "SkRRect.h" 19 #include "SkRRect.h"
19 #include "SkString.h" 20 #include "SkString.h"
20 #include "SkTypeface.h" 21 #include "SkTypeface.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 267 }
267 return "unknown"; 268 return "unknown";
268 } 269 }
269 270
270 void SkLua::pushClipStack(const SkClipStack& stack, const char* key) { 271 void SkLua::pushClipStack(const SkClipStack& stack, const char* key) {
271 lua_newtable(fL); 272 lua_newtable(fL);
272 SkClipStack::B2TIter iter(stack); 273 SkClipStack::B2TIter iter(stack);
273 const SkClipStack::Element* element; 274 const SkClipStack::Element* element;
274 int i = 0; 275 int i = 0;
275 while (NULL != (element = iter.next())) { 276 while (NULL != (element = iter.next())) {
276 lua_newtable(fL); 277 this->pushClipStackElement(*element);
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); 278 lua_rawseti(fL, -2, ++i);
295 } 279 }
296 CHECK_SETFIELD(key); 280 CHECK_SETFIELD(key);
297 } 281 }
298 282
283 void SkLua::pushClipStackElement(const SkClipStack::Element& element, const char * key) {
284 lua_newtable(fL);
285 SkClipStack::Element::Type type = element.getType();
286 this->pushString(element_type(type), "type");
287 switch (type) {
288 case SkClipStack::Element::kEmpty_Type:
289 break;
290 case SkClipStack::Element::kRect_Type:
291 this->pushRect(element.getRect(), "rect");
292 break;
293 case SkClipStack::Element::kRRect_Type:
294 this->pushRRect(element.getRRect(), "rrect");
295 break;
296 case SkClipStack::Element::kPath_Type:
297 this->pushPath(element.getPath(), "path");
298 break;
299 }
300 this->pushString(region_op(element.getOp()), "op");
301 this->pushBool(element.isAA(), "aa");
302 CHECK_SETFIELD(key);
303 }
304
305
299 /////////////////////////////////////////////////////////////////////////////// 306 ///////////////////////////////////////////////////////////////////////////////
300 /////////////////////////////////////////////////////////////////////////////// 307 ///////////////////////////////////////////////////////////////////////////////
301 308
302 static SkScalar lua2scalar(lua_State* L, int index) { 309 static SkScalar lua2scalar(lua_State* L, int index) {
303 SkASSERT(lua_isnumber(L, index)); 310 SkASSERT(lua_isnumber(L, index));
304 return SkLuaToScalar(lua_tonumber(L, index)); 311 return SkLuaToScalar(lua_tonumber(L, index));
305 } 312 }
306 313
307 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) { 314 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) {
308 if (lua_isnumber(L, index)) { 315 if (lua_isnumber(L, index)) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 static int lcanvas_getTotalMatrix(lua_State* L) { 444 static int lcanvas_getTotalMatrix(lua_State* L) {
438 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix()); 445 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix());
439 return 1; 446 return 1;
440 } 447 }
441 448
442 static int lcanvas_getClipStack(lua_State* L) { 449 static int lcanvas_getClipStack(lua_State* L) {
443 SkLua(L).pushClipStack(*get_ref<SkCanvas>(L, 1)->getClipStack()); 450 SkLua(L).pushClipStack(*get_ref<SkCanvas>(L, 1)->getClipStack());
444 return 1; 451 return 1;
445 } 452 }
446 453
454 int SkLua::lcanvas_getReducedClipStack(lua_State* L) {
455 const SkCanvas* canvas = get_ref<SkCanvas>(L, 1);
456 SkISize layerSize = canvas->getTopLayerSize();
457 SkIPoint layerOrigin = canvas->getTopLayerOrigin();
458 SkIRect queryBounds = SkIRect::MakeXYWH(layerOrigin.fX, layerOrigin.fY,
459 layerSize.fWidth, layerSize.fHeight) ;
460
461 GrReducedClip::ElementList elements;
462 GrReducedClip::InitialState initialState;
463 int32_t genID;
464 SkIRect resultBounds;
465
466 const SkClipStack& stack = *canvas->getClipStack();
467
468 GrReducedClip::ReduceClipStack(stack,
469 queryBounds,
470 &elements,
471 &genID,
472 &initialState,
473 &resultBounds,
474 NULL);
475
476 GrReducedClip::ElementList::Iter iter(elements);
477 int i = 0;
478 lua_newtable(L);
479 while(NULL != iter.get()) {
480 SkLua(L).pushClipStackElement(*iter.get());
481 iter.next();
482 lua_rawseti(L, -2, ++i);
483 }
484 // Currently this only returns the element list to lua, not the initial stat e or result bounds.
485 // It could return these as additional items on the lua stack.
486 return 1;
487 }
488
447 static int lcanvas_save(lua_State* L) { 489 static int lcanvas_save(lua_State* L) {
448 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save()); 490 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save());
449 return 1; 491 return 1;
450 } 492 }
451 493
452 static int lcanvas_restore(lua_State* L) { 494 static int lcanvas_restore(lua_State* L) {
453 get_ref<SkCanvas>(L, 1)->restore(); 495 get_ref<SkCanvas>(L, 1)->restore();
454 return 0; 496 return 0;
455 } 497 }
456 498
(...skipping 15 matching lines...) Expand all
472 SkScalar degrees = lua2scalar_def(L, 2, 0); 514 SkScalar degrees = lua2scalar_def(L, 2, 0);
473 get_ref<SkCanvas>(L, 1)->rotate(degrees); 515 get_ref<SkCanvas>(L, 1)->rotate(degrees);
474 return 0; 516 return 0;
475 } 517 }
476 518
477 static int lcanvas_gc(lua_State* L) { 519 static int lcanvas_gc(lua_State* L) {
478 get_ref<SkCanvas>(L, 1)->unref(); 520 get_ref<SkCanvas>(L, 1)->unref();
479 return 0; 521 return 0;
480 } 522 }
481 523
482 static const struct luaL_Reg gSkCanvas_Methods[] = { 524 const struct luaL_Reg gSkCanvas_Methods[] = {
483 { "drawColor", lcanvas_drawColor }, 525 { "drawColor", lcanvas_drawColor },
484 { "drawRect", lcanvas_drawRect }, 526 { "drawRect", lcanvas_drawRect },
485 { "drawOval", lcanvas_drawOval }, 527 { "drawOval", lcanvas_drawOval },
486 { "drawCircle", lcanvas_drawCircle }, 528 { "drawCircle", lcanvas_drawCircle },
487 { "drawImage", lcanvas_drawImage }, 529 { "drawImage", lcanvas_drawImage },
488 { "drawPath", lcanvas_drawPath }, 530 { "drawPath", lcanvas_drawPath },
489 { "drawText", lcanvas_drawText }, 531 { "drawText", lcanvas_drawText },
490 { "getSaveCount", lcanvas_getSaveCount }, 532 { "getSaveCount", lcanvas_getSaveCount },
491 { "getTotalMatrix", lcanvas_getTotalMatrix }, 533 { "getTotalMatrix", lcanvas_getTotalMatrix },
492 { "getClipStack", lcanvas_getClipStack }, 534 { "getClipStack", lcanvas_getClipStack },
535 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack },
493 { "save", lcanvas_save }, 536 { "save", lcanvas_save },
494 { "restore", lcanvas_restore }, 537 { "restore", lcanvas_restore },
495 { "scale", lcanvas_scale }, 538 { "scale", lcanvas_scale },
496 { "translate", lcanvas_translate }, 539 { "translate", lcanvas_translate },
497 { "rotate", lcanvas_rotate }, 540 { "rotate", lcanvas_rotate },
498 { "__gc", lcanvas_gc }, 541 { "__gc", lcanvas_gc },
499 { NULL, NULL } 542 { NULL, NULL }
500 }; 543 };
501 544
502 /////////////////////////////////////////////////////////////////////////////// 545 ///////////////////////////////////////////////////////////////////////////////
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 REG_CLASS(L, SkShader); 1409 REG_CLASS(L, SkShader);
1367 REG_CLASS(L, SkTypeface); 1410 REG_CLASS(L, SkTypeface);
1368 REG_CLASS(L, SkMatrix); 1411 REG_CLASS(L, SkMatrix);
1369 } 1412 }
1370 1413
1371 extern "C" int luaopen_skia(lua_State* L); 1414 extern "C" int luaopen_skia(lua_State* L);
1372 extern "C" int luaopen_skia(lua_State* L) { 1415 extern "C" int luaopen_skia(lua_State* L) {
1373 SkLua::Load(L); 1416 SkLua::Load(L);
1374 return 0; 1417 return 0;
1375 } 1418 }
OLDNEW
« no previous file with comments | « src/core/SkTLList.h ('k') | tools/lua/dump_clipstack_at_restore.lua » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698