reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef SkLua_DEFINED |
| 9 | #define SkLua_DEFINED |
| 10 | |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 11 | #include "SkClipStack.h" |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 12 | #include "SkColor.h" |
commit-bot@chromium.org | 4d803a9 | 2014-05-14 16:03:14 +0000 | [diff] [blame] | 13 | #include "SkPathEffect.h" |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 14 | #include "SkScalar.h" |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 15 | #include "SkString.h" |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 16 | |
| 17 | struct lua_State; |
| 18 | |
| 19 | class SkCanvas; |
| 20 | class SkMatrix; |
| 21 | class SkPaint; |
| 22 | class SkPath; |
| 23 | struct SkRect; |
| 24 | class SkRRect; |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 25 | class SkTextBlob; |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 26 | |
| 27 | #define SkScalarToLua(x) SkScalarToDouble(x) |
| 28 | #define SkLuaToScalar(x) SkDoubleToScalar(x) |
| 29 | |
| 30 | class SkLua { |
| 31 | public: |
| 32 | static void Load(lua_State*); |
| 33 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 34 | SkLua(const char termCode[] = NULL); // creates a new L, will close it |
| 35 | SkLua(lua_State*); // uses L, will not close it |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 36 | ~SkLua(); |
| 37 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 38 | lua_State* get() const { return fL; } |
| 39 | lua_State* operator*() const { return fL; } |
| 40 | lua_State* operator->() const { return fL; } |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 41 | |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 42 | bool runCode(const char code[]); |
| 43 | bool runCode(const void* code, size_t size); |
skia.committer@gmail.com | 2d816ad | 2013-05-23 07:01:22 +0000 | [diff] [blame] | 44 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 45 | void pushBool(bool, const char tableKey[] = NULL); |
| 46 | void pushString(const char[], const char tableKey[] = NULL); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 47 | void pushString(const char[], size_t len, const char tableKey[] = NULL); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 48 | void pushString(const SkString&, const char tableKey[] = NULL); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 49 | void pushArrayU16(const uint16_t[], int count, const char tableKey[] = NULL); |
commit-bot@chromium.org | 1301bf3 | 2014-03-17 23:09:47 +0000 | [diff] [blame] | 50 | void pushArrayPoint(const SkPoint[], int count, const char key[] = NULL); |
commit-bot@chromium.org | 4d803a9 | 2014-05-14 16:03:14 +0000 | [diff] [blame] | 51 | void pushArrayScalar(const SkScalar[], int count, const char key[] = NULL); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 52 | void pushColor(SkColor, const char tableKey[] = NULL); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 53 | void pushU32(uint32_t, const char tableKey[] = NULL); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 54 | void pushScalar(SkScalar, const char tableKey[] = NULL); |
| 55 | void pushRect(const SkRect&, const char tableKey[] = NULL); |
| 56 | void pushRRect(const SkRRect&, const char tableKey[] = NULL); |
commit-bot@chromium.org | 4d803a9 | 2014-05-14 16:03:14 +0000 | [diff] [blame] | 57 | void pushDash(const SkPathEffect::DashInfo&, const char tableKey[] = NULL); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 58 | void pushMatrix(const SkMatrix&, const char tableKey[] = NULL); |
| 59 | void pushPaint(const SkPaint&, const char tableKey[] = NULL); |
| 60 | void pushPath(const SkPath&, const char tableKey[] = NULL); |
| 61 | void pushCanvas(SkCanvas*, const char tableKey[] = NULL); |
commit-bot@chromium.org | 5cc2535 | 2014-02-24 18:59:48 +0000 | [diff] [blame] | 62 | void pushClipStack(const SkClipStack&, const char tableKey[] = NULL); |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 63 | void pushClipStackElement(const SkClipStack::Element& element, const char tableKey[] = NULL); |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 64 | void pushTextBlob(const SkTextBlob*, const char tableKey[] = NULL); |
bsalomon@google.com | 4ebe382 | 2014-02-26 20:22:32 +0000 | [diff] [blame] | 65 | |
| 66 | // This SkCanvas lua methods is declared here to benefit from SkLua's friendship with SkCanvas. |
| 67 | static int lcanvas_getReducedClipStack(lua_State* L); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 68 | |
| 69 | private: |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 70 | lua_State* fL; |
| 71 | SkString fTermCode; |
| 72 | bool fWeOwnL; |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | #endif |