| 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" |
| 9 | |
| 10 | extern "C" { |
| 11 | #include "lua.h" |
| 12 | } |
| 13 | |
| 14 | void SkLuaCanvas::sendverb(const char str[]) { |
| 15 | lua_getglobal(fL, fFunc.c_str()); |
| 16 | if (!lua_isfunction(fL, -1)) { |
| 17 | int t = lua_type(fL, -1); |
| 18 | SkDebugf("--- expected function %d\n", t); |
| 19 | } |
| 20 | lua_pushstring(fL, str); |
| 21 | |
| 22 | if (lua_pcall(fL, 1, 0, 0) != LUA_OK) { |
| 23 | SkDebugf("lua err: %s\n", lua_tostring(fL, -1)); |
| 24 | } |
| 25 | lua_settop(fL, -1); |
| 26 | } |
| 27 | |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | |
| 30 | static SkBitmap make_bm(int width, int height) { |
| 31 | SkBitmap bm; |
| 32 | bm.setConfig(SkBitmap::kNo_Config, width, height); |
| 33 | return bm; |
| 34 | } |
| 35 | |
| 36 | SkLuaCanvas::SkLuaCanvas(int width, int height, lua_State* L, const char func[]) |
| 37 | : INHERITED(make_bm(width, height)) |
| 38 | , fL(L) |
| 39 | , fFunc(func) { |
| 40 | } |
| 41 | |
| 42 | SkLuaCanvas::~SkLuaCanvas() {} |
| 43 | |
| 44 | int SkLuaCanvas::save(SaveFlags flags) { |
| 45 | sendverb("save"); |
| 46 | return this->INHERITED::save(flags); |
| 47 | } |
| 48 | |
| 49 | int SkLuaCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 50 | SaveFlags flags) { |
| 51 | sendverb("saveLayer"); |
| 52 | return this->INHERITED::save(flags); |
| 53 | } |
| 54 | |
| 55 | void SkLuaCanvas::restore() { |
| 56 | sendverb("restore"); |
| 57 | this->INHERITED::restore(); |
| 58 | } |
| 59 | |
| 60 | bool SkLuaCanvas::translate(SkScalar dx, SkScalar dy) { |
| 61 | sendverb("translate"); |
| 62 | return this->INHERITED::translate(dx, dy); |
| 63 | } |
| 64 | |
| 65 | bool SkLuaCanvas::scale(SkScalar sx, SkScalar sy) { |
| 66 | sendverb("scale"); |
| 67 | return this->INHERITED::scale(sx, sy); |
| 68 | } |
| 69 | |
| 70 | bool SkLuaCanvas::rotate(SkScalar degrees) { |
| 71 | sendverb("rotate"); |
| 72 | return this->INHERITED::rotate(degrees); |
| 73 | } |
| 74 | |
| 75 | bool SkLuaCanvas::skew(SkScalar sx, SkScalar sy) { |
| 76 | sendverb("skew"); |
| 77 | return this->INHERITED::skew(sx, sy); |
| 78 | } |
| 79 | |
| 80 | bool SkLuaCanvas::concat(const SkMatrix& matrix) { |
| 81 | sendverb("concat"); |
| 82 | return this->INHERITED::concat(matrix); |
| 83 | } |
| 84 | |
| 85 | void SkLuaCanvas::setMatrix(const SkMatrix& matrix) { |
| 86 | this->INHERITED::setMatrix(matrix); |
| 87 | } |
| 88 | |
| 89 | bool SkLuaCanvas::clipRect(const SkRect& r, SkRegion::Op op, bool doAA) { |
| 90 | sendverb("clipRect"); |
| 91 | return this->INHERITED::clipRect(r, op, doAA); |
| 92 | } |
| 93 | |
| 94 | bool SkLuaCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
| 95 | sendverb("clipRRect"); |
| 96 | return this->INHERITED::clipRRect(rrect, op, doAA); |
| 97 | } |
| 98 | |
| 99 | bool SkLuaCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
| 100 | sendverb("clipPath"); |
| 101 | return this->INHERITED::clipPath(path, op, doAA); |
| 102 | } |
| 103 | |
| 104 | bool SkLuaCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
| 105 | sendverb("clipRegion"); |
| 106 | return this->INHERITED::clipRegion(deviceRgn, op); |
| 107 | } |
| 108 | |
| 109 | void SkLuaCanvas::drawPaint(const SkPaint& paint) { |
| 110 | sendverb("drawPaint"); |
| 111 | } |
| 112 | |
| 113 | void SkLuaCanvas::drawPoints(PointMode mode, size_t count, |
| 114 | const SkPoint pts[], const SkPaint& paint) { |
| 115 | sendverb("drawPoints"); |
| 116 | } |
| 117 | |
| 118 | void SkLuaCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { |
| 119 | sendverb("drawOval"); |
| 120 | } |
| 121 | |
| 122 | void SkLuaCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
| 123 | sendverb("drawRect"); |
| 124 | } |
| 125 | |
| 126 | void SkLuaCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 127 | sendverb("drawRRect"); |
| 128 | } |
| 129 | |
| 130 | void SkLuaCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| 131 | sendverb("drawPath"); |
| 132 | } |
| 133 | |
| 134 | void SkLuaCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, |
| 135 | const SkPaint* paint) { |
| 136 | sendverb("drawBitmap"); |
| 137 | } |
| 138 | |
| 139 | void SkLuaCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, |
| 140 | const SkRect& dst, const SkPaint* paint) { |
| 141 | sendverb("drawBitmapRectToRect"); |
| 142 | } |
| 143 | |
| 144 | void SkLuaCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, |
| 145 | const SkPaint* paint) { |
| 146 | sendverb("drawBitmapMatrix"); |
| 147 | } |
| 148 | |
| 149 | void SkLuaCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
| 150 | const SkPaint* paint) { |
| 151 | sendverb("drawSprite"); |
| 152 | } |
| 153 | |
| 154 | void SkLuaCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
| 155 | SkScalar y, const SkPaint& paint) { |
| 156 | sendverb("drawText"); |
| 157 | } |
| 158 | |
| 159 | void SkLuaCanvas::drawPosText(const void* text, size_t byteLength, |
| 160 | const SkPoint pos[], const SkPaint& paint) { |
| 161 | sendverb("drawPosText"); |
| 162 | } |
| 163 | |
| 164 | void SkLuaCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 165 | const SkScalar xpos[], SkScalar constY, |
| 166 | const SkPaint& paint) { |
| 167 | sendverb("drawPosTextH"); |
| 168 | } |
| 169 | |
| 170 | void SkLuaCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 171 | const SkPath& path, const SkMatrix* matrix, |
| 172 | const SkPaint& paint) { |
| 173 | sendverb("drawTextOnPath"); |
| 174 | } |
| 175 | |
| 176 | void SkLuaCanvas::drawPicture(SkPicture& picture) { |
| 177 | sendverb("drawPicture"); |
| 178 | // call through so we can see the nested picture ops |
| 179 | this->INHERITED::drawPicture(picture); |
| 180 | } |
| 181 | |
| 182 | void SkLuaCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 183 | const SkPoint vertices[], const SkPoint texs[], |
| 184 | const SkColor colors[], SkXfermode* xmode, |
| 185 | const uint16_t indices[], int indexCount, |
| 186 | const SkPaint& paint) { |
| 187 | sendverb("drawVertices"); |
| 188 | } |
| 189 | |
| 190 | void SkLuaCanvas::drawData(const void* data, size_t length) { |
| 191 | sendverb("drawData"); |
| 192 | } |