reed@google.com | dff7e11 | 2013-05-15 19:34:20 +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 | #include "SkLuaCanvas.h" |
Hal Canary | ee08b4a | 2018-03-01 15:56:37 -0500 | [diff] [blame] | 9 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 10 | #include "SkLua.h" |
Hal Canary | ee08b4a | 2018-03-01 15:56:37 -0500 | [diff] [blame] | 11 | #include "SkStringUtils.h" |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame^] | 12 | #include "SkTo.h" |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 13 | |
| 14 | extern "C" { |
| 15 | #include "lua.h" |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 16 | #include "lauxlib.h" |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 17 | } |
| 18 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 19 | class AutoCallLua : public SkLua { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 20 | public: |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 21 | AutoCallLua(lua_State* L, const char func[], const char verb[]) : INHERITED(L) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 22 | lua_getglobal(L, func); |
| 23 | if (!lua_isfunction(L, -1)) { |
| 24 | int t = lua_type(L, -1); |
| 25 | SkDebugf("--- expected function %d\n", t); |
| 26 | } |
skia.committer@gmail.com | 539f364 | 2013-05-16 07:01:00 +0000 | [diff] [blame] | 27 | |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 28 | lua_newtable(L); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 29 | this->pushString(verb, "verb"); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | ~AutoCallLua() { |
reed@google.com | 3597b73 | 2013-05-22 20:12:50 +0000 | [diff] [blame] | 33 | lua_State* L = this->get(); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 34 | if (lua_pcall(L, 1, 0, 0) != LUA_OK) { |
| 35 | SkDebugf("lua err: %s\n", lua_tostring(L, -1)); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 36 | } |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 37 | lua_settop(L, -1); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 38 | } |
| 39 | |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 40 | void pushEncodedText(SkPaint::TextEncoding, const void*, size_t); |
| 41 | |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 42 | private: |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 43 | typedef SkLua INHERITED; |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 46 | #define AUTO_LUA(verb) AutoCallLua lua(fL, fFunc.c_str(), verb) |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame] | 47 | |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 48 | |
| 49 | /////////////////////////////////////////////////////////////////////////////// |
| 50 | |
| 51 | void AutoCallLua::pushEncodedText(SkPaint::TextEncoding enc, const void* text, |
| 52 | size_t length) { |
| 53 | switch (enc) { |
| 54 | case SkPaint::kUTF8_TextEncoding: |
| 55 | this->pushString((const char*)text, length, "text"); |
| 56 | break; |
Hal Canary | ee08b4a | 2018-03-01 15:56:37 -0500 | [diff] [blame] | 57 | case SkPaint::kUTF16_TextEncoding: |
| 58 | this->pushString(SkStringFromUTF16((const uint16_t*)text, length), "text"); |
| 59 | break; |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 60 | case SkPaint::kGlyphID_TextEncoding: |
reed@google.com | 7fa2a65 | 2014-01-27 13:42:58 +0000 | [diff] [blame] | 61 | this->pushArrayU16((const uint16_t*)text, SkToInt(length >> 1), |
| 62 | "glyphs"); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 63 | break; |
| 64 | case SkPaint::kUTF32_TextEncoding: |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | |
reed@google.com | 9a73104 | 2013-05-21 17:52:33 +0000 | [diff] [blame] | 69 | /////////////////////////////////////////////////////////////////////////////// |
| 70 | |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 71 | void SkLuaCanvas::pushThis() { |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 72 | SkLua(fL).pushCanvas(this); |
mike@reedtribe.org | f02fe3d | 2013-05-21 12:20:39 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /////////////////////////////////////////////////////////////////////////////// |
| 76 | |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 77 | SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[]) |
commit-bot@chromium.org | e254310 | 2014-01-31 19:42:58 +0000 | [diff] [blame] | 78 | : INHERITED(width, height) |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 79 | , fL(L) |
| 80 | , fFunc(func) { |
| 81 | } |
| 82 | |
| 83 | SkLuaCanvas::~SkLuaCanvas() {} |
| 84 | |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 85 | void SkLuaCanvas::willSave() { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 86 | AUTO_LUA("save"); |
Florin Malita | 5f6102d | 2014-06-30 10:13:28 -0400 | [diff] [blame] | 87 | this->INHERITED::willSave(); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 88 | } |
| 89 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 90 | SkCanvas::SaveLayerStrategy SkLuaCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 91 | AUTO_LUA("saveLayer"); |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 92 | if (rec.fBounds) { |
| 93 | lua.pushRect(*rec.fBounds, "bounds"); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 94 | } |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 95 | if (rec.fPaint) { |
| 96 | lua.pushPaint(*rec.fPaint, "paint"); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 97 | } |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 98 | |
reed | 4960eee | 2015-12-18 07:09:18 -0800 | [diff] [blame] | 99 | (void)this->INHERITED::getSaveLayerStrategy(rec); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 100 | // No need for a layer. |
| 101 | return kNoLayer_SaveLayerStrategy; |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 102 | } |
| 103 | |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 104 | void SkLuaCanvas::willRestore() { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 105 | AUTO_LUA("restore"); |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame] | 106 | this->INHERITED::willRestore(); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 107 | } |
| 108 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 109 | void SkLuaCanvas::didConcat(const SkMatrix& matrix) { |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 110 | switch (matrix.getType()) { |
| 111 | case SkMatrix::kTranslate_Mask: { |
| 112 | AUTO_LUA("translate"); |
| 113 | lua.pushScalar(matrix.getTranslateX(), "dx"); |
| 114 | lua.pushScalar(matrix.getTranslateY(), "dy"); |
| 115 | break; |
| 116 | } |
| 117 | case SkMatrix::kScale_Mask: { |
| 118 | AUTO_LUA("scale"); |
| 119 | lua.pushScalar(matrix.getScaleX(), "sx"); |
| 120 | lua.pushScalar(matrix.getScaleY(), "sy"); |
| 121 | break; |
| 122 | } |
| 123 | default: { |
| 124 | AUTO_LUA("concat"); |
commit-bot@chromium.org | ab885be | 2014-05-13 20:32:32 +0000 | [diff] [blame] | 125 | // pushMatrix added in https://codereview.chromium.org/203203004/ |
| 126 | // Doesn't seem to have ever been working correctly since added |
| 127 | // lua.pushMatrix(matrix); |
commit-bot@chromium.org | d9ea09e | 2014-03-25 17:32:26 +0000 | [diff] [blame] | 128 | break; |
| 129 | } |
| 130 | } |
| 131 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 132 | this->INHERITED::didConcat(matrix); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 133 | } |
| 134 | |
commit-bot@chromium.org | 44c48d0 | 2014-03-13 20:03:58 +0000 | [diff] [blame] | 135 | void SkLuaCanvas::didSetMatrix(const SkMatrix& matrix) { |
| 136 | this->INHERITED::didSetMatrix(matrix); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 139 | void SkLuaCanvas::onClipRect(const SkRect& r, SkClipOp op, ClipEdgeStyle edgeStyle) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 140 | AUTO_LUA("clipRect"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 141 | lua.pushRect(r, "rect"); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 142 | lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa"); |
| 143 | this->INHERITED::onClipRect(r, op, edgeStyle); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 146 | void SkLuaCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 147 | AUTO_LUA("clipRRect"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 148 | lua.pushRRect(rrect, "rrect"); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 149 | lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa"); |
| 150 | this->INHERITED::onClipRRect(rrect, op, edgeStyle); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 153 | void SkLuaCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 154 | AUTO_LUA("clipPath"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 155 | lua.pushPath(path, "path"); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 156 | lua.pushBool(kSoft_ClipEdgeStyle == edgeStyle, "aa"); |
| 157 | this->INHERITED::onClipPath(path, op, edgeStyle); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 160 | void SkLuaCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 161 | AUTO_LUA("clipRegion"); |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 162 | this->INHERITED::onClipRegion(deviceRgn, op); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 163 | } |
| 164 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 165 | void SkLuaCanvas::onDrawPaint(const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 166 | AUTO_LUA("drawPaint"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 167 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 168 | } |
| 169 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 170 | void SkLuaCanvas::onDrawPoints(PointMode mode, size_t count, |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 171 | const SkPoint pts[], const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 172 | AUTO_LUA("drawPoints"); |
commit-bot@chromium.org | 2cfa320 | 2014-04-19 22:00:40 +0000 | [diff] [blame] | 173 | lua.pushArrayPoint(pts, SkToInt(count), "points"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 174 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 175 | } |
| 176 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 177 | void SkLuaCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 178 | AUTO_LUA("drawOval"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 179 | lua.pushRect(rect, "rect"); |
| 180 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 181 | } |
| 182 | |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 183 | void SkLuaCanvas::onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, |
| 184 | bool useCenter, const SkPaint& paint) { |
| 185 | AUTO_LUA("drawArc"); |
| 186 | lua.pushRect(rect, "rect"); |
| 187 | lua.pushScalar(startAngle, "startAngle"); |
| 188 | lua.pushScalar(sweepAngle, "sweepAngle"); |
| 189 | lua.pushBool(useCenter, "useCenter"); |
| 190 | lua.pushPaint(paint, "paint"); |
| 191 | } |
| 192 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 193 | void SkLuaCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 194 | AUTO_LUA("drawRect"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 195 | lua.pushRect(rect, "rect"); |
| 196 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 197 | } |
| 198 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 199 | void SkLuaCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 200 | AUTO_LUA("drawRRect"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 201 | lua.pushRRect(rrect, "rrect"); |
| 202 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 203 | } |
| 204 | |
commit-bot@chromium.org | ab58273 | 2014-02-21 12:20:45 +0000 | [diff] [blame] | 205 | void SkLuaCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 206 | const SkPaint& paint) { |
| 207 | AUTO_LUA("drawDRRect"); |
| 208 | lua.pushRRect(outer, "outer"); |
| 209 | lua.pushRRect(inner, "inner"); |
| 210 | lua.pushPaint(paint, "paint"); |
| 211 | } |
| 212 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 213 | void SkLuaCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 214 | AUTO_LUA("drawPath"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 215 | lua.pushPath(path, "path"); |
| 216 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 217 | } |
| 218 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 219 | void SkLuaCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, |
| 220 | const SkPaint* paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 221 | AUTO_LUA("drawBitmap"); |
| 222 | if (paint) { |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 223 | lua.pushPaint(*paint, "paint"); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 224 | } |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 225 | } |
| 226 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 227 | void SkLuaCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 228 | const SkPaint* paint, SrcRectConstraint) { |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 229 | AUTO_LUA("drawBitmapRect"); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 230 | if (paint) { |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 231 | lua.pushPaint(*paint, "paint"); |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 232 | } |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 233 | } |
| 234 | |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 235 | void SkLuaCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, |
| 236 | const SkPaint* paint) { |
| 237 | AUTO_LUA("drawBitmapNine"); |
| 238 | if (paint) { |
| 239 | lua.pushPaint(*paint, "paint"); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | void SkLuaCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) { |
| 244 | AUTO_LUA("drawImage"); |
| 245 | if (paint) { |
| 246 | lua.pushPaint(*paint, "paint"); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | void SkLuaCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 251 | const SkPaint* paint, SrcRectConstraint) { |
reed | 41af966 | 2015-01-05 07:49:08 -0800 | [diff] [blame] | 252 | AUTO_LUA("drawImageRect"); |
| 253 | if (paint) { |
| 254 | lua.pushPaint(*paint, "paint"); |
| 255 | } |
| 256 | } |
| 257 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 258 | void SkLuaCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, |
| 259 | const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 260 | AUTO_LUA("drawText"); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 261 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 262 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 263 | } |
| 264 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 265 | void SkLuaCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], |
| 266 | const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 267 | AUTO_LUA("drawPosText"); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 268 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 269 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 270 | } |
| 271 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 272 | void SkLuaCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| 273 | SkScalar constY, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 274 | AUTO_LUA("drawPosTextH"); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 275 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 276 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 277 | } |
| 278 | |
reed@google.com | e0d9ce8 | 2014-04-23 04:00:17 +0000 | [diff] [blame] | 279 | void SkLuaCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, |
| 280 | const SkMatrix* matrix, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 281 | AUTO_LUA("drawTextOnPath"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 282 | lua.pushPath(path, "path"); |
reed@google.com | e3823fd | 2013-05-30 18:55:14 +0000 | [diff] [blame] | 283 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 284 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 285 | } |
| 286 | |
reed | 45561a0 | 2016-07-07 12:47:17 -0700 | [diff] [blame] | 287 | void SkLuaCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], |
| 288 | const SkRect* cull, const SkPaint& paint) { |
| 289 | AUTO_LUA("drawTextRSXform"); |
| 290 | lua.pushEncodedText(paint.getTextEncoding(), text, byteLength); |
| 291 | // TODO: export other params |
| 292 | lua.pushPaint(paint, "paint"); |
| 293 | } |
| 294 | |
fmalita | b742517 | 2014-08-26 07:56:44 -0700 | [diff] [blame] | 295 | void SkLuaCanvas::onDrawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, |
| 296 | const SkPaint &paint) { |
| 297 | AUTO_LUA("drawTextBlob"); |
| 298 | lua.pushTextBlob(blob, "blob"); |
| 299 | lua.pushScalar(x, "x"); |
| 300 | lua.pushScalar(y, "y"); |
| 301 | lua.pushPaint(paint, "paint"); |
| 302 | } |
| 303 | |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 304 | void SkLuaCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, |
| 305 | const SkPaint* paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 306 | AUTO_LUA("drawPicture"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 307 | // call through so we can see the nested picture ops |
reed | d5fa1a4 | 2014-08-09 11:08:05 -0700 | [diff] [blame] | 308 | this->INHERITED::onDrawPicture(picture, matrix, paint); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Florin Malita | adaeaed | 2017-09-21 15:28:29 -0400 | [diff] [blame] | 311 | void SkLuaCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { |
| 312 | AUTO_LUA("drawDrawable"); |
| 313 | // call through so we can see the nested ops |
| 314 | this->INHERITED::onDrawDrawable(drawable, matrix); |
| 315 | } |
| 316 | |
Mike Reed | 02f577b | 2017-03-20 16:13:34 -0400 | [diff] [blame] | 317 | void SkLuaCanvas::onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint& paint) { |
mike@reedtribe.org | 1c5a94f | 2013-05-16 04:20:23 +0000 | [diff] [blame] | 318 | AUTO_LUA("drawVertices"); |
reed@google.com | 74ce6f0 | 2013-05-22 15:13:18 +0000 | [diff] [blame] | 319 | lua.pushPaint(paint, "paint"); |
reed@google.com | dff7e11 | 2013-05-15 19:34:20 +0000 | [diff] [blame] | 320 | } |