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