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