| OLD | NEW |
| 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" | |
| 11 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkClipStack.h" |
| 12 #include "SkData.h" | 11 #include "SkData.h" |
| 13 #include "SkDocument.h" | 12 #include "SkDocument.h" |
| 14 #include "SkImage.h" | 13 #include "SkImage.h" |
| 15 #include "SkMatrix.h" | 14 #include "SkMatrix.h" |
| 16 #include "SkPaint.h" | 15 #include "SkPaint.h" |
| 17 #include "SkPath.h" | 16 #include "SkPath.h" |
| 18 #include "SkPixelRef.h" | 17 #include "SkPixelRef.h" |
| 19 #include "SkRRect.h" | 18 #include "SkRRect.h" |
| 20 #include "SkString.h" | 19 #include "SkString.h" |
| 21 #include "SkTypeface.h" | 20 #include "SkTypeface.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 266 } |
| 268 return "unknown"; | 267 return "unknown"; |
| 269 } | 268 } |
| 270 | 269 |
| 271 void SkLua::pushClipStack(const SkClipStack& stack, const char* key) { | 270 void SkLua::pushClipStack(const SkClipStack& stack, const char* key) { |
| 272 lua_newtable(fL); | 271 lua_newtable(fL); |
| 273 SkClipStack::B2TIter iter(stack); | 272 SkClipStack::B2TIter iter(stack); |
| 274 const SkClipStack::Element* element; | 273 const SkClipStack::Element* element; |
| 275 int i = 0; | 274 int i = 0; |
| 276 while (NULL != (element = iter.next())) { | 275 while (NULL != (element = iter.next())) { |
| 277 this->pushClipStackElement(*element); | 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"); |
| 278 lua_rawseti(fL, -2, ++i); | 294 lua_rawseti(fL, -2, ++i); |
| 279 } | 295 } |
| 280 CHECK_SETFIELD(key); | 296 CHECK_SETFIELD(key); |
| 281 } | 297 } |
| 282 | 298 |
| 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 | |
| 306 /////////////////////////////////////////////////////////////////////////////// | 299 /////////////////////////////////////////////////////////////////////////////// |
| 307 /////////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////////// |
| 308 | 301 |
| 309 static SkScalar lua2scalar(lua_State* L, int index) { | 302 static SkScalar lua2scalar(lua_State* L, int index) { |
| 310 SkASSERT(lua_isnumber(L, index)); | 303 SkASSERT(lua_isnumber(L, index)); |
| 311 return SkLuaToScalar(lua_tonumber(L, index)); | 304 return SkLuaToScalar(lua_tonumber(L, index)); |
| 312 } | 305 } |
| 313 | 306 |
| 314 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) { | 307 static SkScalar lua2scalar_def(lua_State* L, int index, SkScalar defaultValue) { |
| 315 if (lua_isnumber(L, index)) { | 308 if (lua_isnumber(L, index)) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 static int lcanvas_getTotalMatrix(lua_State* L) { | 437 static int lcanvas_getTotalMatrix(lua_State* L) { |
| 445 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix()); | 438 SkLua(L).pushMatrix(get_ref<SkCanvas>(L, 1)->getTotalMatrix()); |
| 446 return 1; | 439 return 1; |
| 447 } | 440 } |
| 448 | 441 |
| 449 static int lcanvas_getClipStack(lua_State* L) { | 442 static int lcanvas_getClipStack(lua_State* L) { |
| 450 SkLua(L).pushClipStack(*get_ref<SkCanvas>(L, 1)->getClipStack()); | 443 SkLua(L).pushClipStack(*get_ref<SkCanvas>(L, 1)->getClipStack()); |
| 451 return 1; | 444 return 1; |
| 452 } | 445 } |
| 453 | 446 |
| 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 | |
| 489 static int lcanvas_save(lua_State* L) { | 447 static int lcanvas_save(lua_State* L) { |
| 490 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save()); | 448 lua_pushinteger(L, get_ref<SkCanvas>(L, 1)->save()); |
| 491 return 1; | 449 return 1; |
| 492 } | 450 } |
| 493 | 451 |
| 494 static int lcanvas_restore(lua_State* L) { | 452 static int lcanvas_restore(lua_State* L) { |
| 495 get_ref<SkCanvas>(L, 1)->restore(); | 453 get_ref<SkCanvas>(L, 1)->restore(); |
| 496 return 0; | 454 return 0; |
| 497 } | 455 } |
| 498 | 456 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 514 SkScalar degrees = lua2scalar_def(L, 2, 0); | 472 SkScalar degrees = lua2scalar_def(L, 2, 0); |
| 515 get_ref<SkCanvas>(L, 1)->rotate(degrees); | 473 get_ref<SkCanvas>(L, 1)->rotate(degrees); |
| 516 return 0; | 474 return 0; |
| 517 } | 475 } |
| 518 | 476 |
| 519 static int lcanvas_gc(lua_State* L) { | 477 static int lcanvas_gc(lua_State* L) { |
| 520 get_ref<SkCanvas>(L, 1)->unref(); | 478 get_ref<SkCanvas>(L, 1)->unref(); |
| 521 return 0; | 479 return 0; |
| 522 } | 480 } |
| 523 | 481 |
| 524 const struct luaL_Reg gSkCanvas_Methods[] = { | 482 static const struct luaL_Reg gSkCanvas_Methods[] = { |
| 525 { "drawColor", lcanvas_drawColor }, | 483 { "drawColor", lcanvas_drawColor }, |
| 526 { "drawRect", lcanvas_drawRect }, | 484 { "drawRect", lcanvas_drawRect }, |
| 527 { "drawOval", lcanvas_drawOval }, | 485 { "drawOval", lcanvas_drawOval }, |
| 528 { "drawCircle", lcanvas_drawCircle }, | 486 { "drawCircle", lcanvas_drawCircle }, |
| 529 { "drawImage", lcanvas_drawImage }, | 487 { "drawImage", lcanvas_drawImage }, |
| 530 { "drawPath", lcanvas_drawPath }, | 488 { "drawPath", lcanvas_drawPath }, |
| 531 { "drawText", lcanvas_drawText }, | 489 { "drawText", lcanvas_drawText }, |
| 532 { "getSaveCount", lcanvas_getSaveCount }, | 490 { "getSaveCount", lcanvas_getSaveCount }, |
| 533 { "getTotalMatrix", lcanvas_getTotalMatrix }, | 491 { "getTotalMatrix", lcanvas_getTotalMatrix }, |
| 534 { "getClipStack", lcanvas_getClipStack }, | 492 { "getClipStack", lcanvas_getClipStack }, |
| 535 { "getReducedClipStack", SkLua::lcanvas_getReducedClipStack }, | |
| 536 { "save", lcanvas_save }, | 493 { "save", lcanvas_save }, |
| 537 { "restore", lcanvas_restore }, | 494 { "restore", lcanvas_restore }, |
| 538 { "scale", lcanvas_scale }, | 495 { "scale", lcanvas_scale }, |
| 539 { "translate", lcanvas_translate }, | 496 { "translate", lcanvas_translate }, |
| 540 { "rotate", lcanvas_rotate }, | 497 { "rotate", lcanvas_rotate }, |
| 541 { "__gc", lcanvas_gc }, | 498 { "__gc", lcanvas_gc }, |
| 542 { NULL, NULL } | 499 { NULL, NULL } |
| 543 }; | 500 }; |
| 544 | 501 |
| 545 /////////////////////////////////////////////////////////////////////////////// | 502 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 REG_CLASS(L, SkShader); | 1366 REG_CLASS(L, SkShader); |
| 1410 REG_CLASS(L, SkTypeface); | 1367 REG_CLASS(L, SkTypeface); |
| 1411 REG_CLASS(L, SkMatrix); | 1368 REG_CLASS(L, SkMatrix); |
| 1412 } | 1369 } |
| 1413 | 1370 |
| 1414 extern "C" int luaopen_skia(lua_State* L); | 1371 extern "C" int luaopen_skia(lua_State* L); |
| 1415 extern "C" int luaopen_skia(lua_State* L) { | 1372 extern "C" int luaopen_skia(lua_State* L) { |
| 1416 SkLua::Load(L); | 1373 SkLua::Load(L); |
| 1417 return 0; | 1374 return 0; |
| 1418 } | 1375 } |
| OLD | NEW |