Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/utils/SkLuaCanvas.cpp

Issue 15192003: add the following fields to the lua accumulate table: - rrect.rect - rrect[1..8] for radii - rrect.… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkLuaCanvas.h" 8 #include "SkLuaCanvas.h"
9 #include "SkRRect.h" 9 #include "SkRRect.h"
10 10
11 extern "C" { 11 extern "C" {
12 #include "lua.h" 12 #include "lua.h"
13 } 13 }
14 14
15 static void setfield_string(lua_State* L, const char key[], const char value[]) { 15 static void setfield_string(lua_State* L, const char key[], const char value[]) {
16 lua_pushstring(L, value); 16 lua_pushstring(L, value);
17 lua_setfield(L, -2, key); 17 lua_setfield(L, -2, key);
18 } 18 }
19 19
20 static void setfield_number(lua_State* L, const char key[], double value) { 20 static void setfield_number(lua_State* L, const char key[], double value) {
21 lua_pushnumber(L, value); 21 lua_pushnumber(L, value);
22 lua_setfield(L, -2, key); 22 lua_setfield(L, -2, key);
23 } 23 }
24 24
25 static void setfield_bool(lua_State* L, const char key[], bool value) { 25 static void setfield_bool(lua_State* L, const char key[], bool value) {
26 lua_pushboolean(L, value); 26 lua_pushboolean(L, value);
27 lua_setfield(L, -2, key); 27 lua_setfield(L, -2, key);
28 } 28 }
29 29
30 // sets [1]...[count] in the table on the top of the stack
31 static void setfield_arrayf(lua_State* L, const SkScalar array[], int count) {
32 for (int i = 0; i < count; ++i) {
33 lua_pushnumber(L, SkScalarToDouble(i + 1)); // key
34 lua_pushnumber(L, SkScalarToDouble(array[i])); // value
35 lua_settable(L, -3);
36 }
37 }
38
30 static void setfield_rect(lua_State* L, const char key[], const SkRect& r) { 39 static void setfield_rect(lua_State* L, const char key[], const SkRect& r) {
31 lua_newtable(L); 40 lua_newtable(L);
32 setfield_number(L, "left", r.fLeft); 41 setfield_number(L, "left", r.fLeft);
33 setfield_number(L, "top", r.fTop); 42 setfield_number(L, "top", r.fTop);
34 setfield_number(L, "right", r.fRight); 43 setfield_number(L, "right", r.fRight);
35 setfield_number(L, "bottom", r.fBottom); 44 setfield_number(L, "bottom", r.fBottom);
36 lua_setfield(L, -2, key); 45 lua_setfield(L, -2, key);
37 } 46 }
38 47
48 static const char* rrect_type(const SkRRect& rr) {
49 switch (rr.getType()) {
50 case SkRRect::kUnknown_Type: return "unknown";
51 case SkRRect::kEmpty_Type: return "empty";
52 case SkRRect::kRect_Type: return "rect";
53 case SkRRect::kOval_Type: return "oval";
54 case SkRRect::kSimple_Type: return "simple";
55 case SkRRect::kComplex_Type: return "complex";
56 }
57 SkASSERT(!"never get here");
58 return "";
59 }
60
61 static void setfield_rrect(lua_State* L, const char key[], const SkRRect& rr) {
62 lua_newtable(L);
63 setfield_rect(L, "rect", rr.getBounds());
64 setfield_string(L, "type", rrect_type(rr));
65
66 SkVector rad[4] = {
67 rr.radii(SkRRect::kUpperLeft_Corner),
68 rr.radii(SkRRect::kUpperRight_Corner),
69 rr.radii(SkRRect::kLowerRight_Corner),
70 rr.radii(SkRRect::kLowerLeft_Corner),
71 };
72 setfield_arrayf(L, &rad[0].fX, 8);
73 lua_setfield(L, -2, key);
74 }
75
39 enum PaintUsage { 76 enum PaintUsage {
40 kText_PaintUsage, 77 kText_PaintUsage,
41 kImage_PaintUsage, 78 kImage_PaintUsage,
42 kGeometry_PaintUsage 79 kGeometry_PaintUsage
43 }; 80 };
44 81
45 static const char* color2string(SkColor c, SkString* str) { 82 static const char* color2string(SkColor c, SkString* str) {
46 str->printf("0x%08X", c); 83 str->printf("0x%08X", c);
47 return str->c_str(); 84 return str->c_str();
48 } 85 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 202
166 bool SkLuaCanvas::clipRect(const SkRect& r, SkRegion::Op op, bool doAA) { 203 bool SkLuaCanvas::clipRect(const SkRect& r, SkRegion::Op op, bool doAA) {
167 AUTO_LUA("clipRect"); 204 AUTO_LUA("clipRect");
168 setfield_rect(fL, "rect", r); 205 setfield_rect(fL, "rect", r);
169 setfield_bool(fL, "aa", doAA); 206 setfield_bool(fL, "aa", doAA);
170 return this->INHERITED::clipRect(r, op, doAA); 207 return this->INHERITED::clipRect(r, op, doAA);
171 } 208 }
172 209
173 bool SkLuaCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { 210 bool SkLuaCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
174 AUTO_LUA("clipRRect"); 211 AUTO_LUA("clipRRect");
212 setfield_rrect(fL, "rrect", rrect);
175 setfield_bool(fL, "aa", doAA); 213 setfield_bool(fL, "aa", doAA);
176 return this->INHERITED::clipRRect(rrect, op, doAA); 214 return this->INHERITED::clipRRect(rrect, op, doAA);
177 } 215 }
178 216
179 bool SkLuaCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { 217 bool SkLuaCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
180 AUTO_LUA("clipPath"); 218 AUTO_LUA("clipPath");
181 setfield_bool(fL, "aa", doAA); 219 setfield_bool(fL, "aa", doAA);
182 return this->INHERITED::clipPath(path, op, doAA); 220 return this->INHERITED::clipPath(path, op, doAA);
183 } 221 }
184 222
185 bool SkLuaCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { 223 bool SkLuaCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
186 AUTO_LUA("clipRegion"); 224 AUTO_LUA("clipRegion");
187 return this->INHERITED::clipRegion(deviceRgn, op); 225 return this->INHERITED::clipRegion(deviceRgn, op);
188 } 226 }
189 227
190 void SkLuaCanvas::drawPaint(const SkPaint& paint) { 228 void SkLuaCanvas::drawPaint(const SkPaint& paint) {
191 AUTO_LUA("drawPaint"); 229 AUTO_LUA("drawPaint");
192 setfield_paint(fL, paint); 230 setfield_paint(fL, paint);
193 } 231 }
194 232
195 void SkLuaCanvas::drawPoints(PointMode mode, size_t count, 233 void SkLuaCanvas::drawPoints(PointMode mode, size_t count,
196 const SkPoint pts[], const SkPaint& paint) { 234 const SkPoint pts[], const SkPaint& paint) {
197 AUTO_LUA("drawPoints"); 235 AUTO_LUA("drawPoints");
198 setfield_paint(fL, paint); 236 setfield_paint(fL, paint);
199 } 237 }
200 238
201 void SkLuaCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { 239 void SkLuaCanvas::drawOval(const SkRect& rect, const SkPaint& paint) {
202 AUTO_LUA("drawOval"); 240 AUTO_LUA("drawOval");
203 setfield_rect(fL, "rect", rect); 241 setfield_rect(fL, "oval", rect);
204 setfield_paint(fL, paint); 242 setfield_paint(fL, paint);
205 } 243 }
206 244
207 void SkLuaCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { 245 void SkLuaCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
208 AUTO_LUA("drawRect"); 246 AUTO_LUA("drawRect");
209 setfield_rect(fL, "rect", rect); 247 setfield_rect(fL, "rect", rect);
210 setfield_paint(fL, paint); 248 setfield_paint(fL, paint);
211 } 249 }
212 250
213 void SkLuaCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 251 void SkLuaCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
214 AUTO_LUA("drawRRect"); 252 AUTO_LUA("drawRRect");
215 setfield_rect(fL, "rect", rrect.getBounds()); 253 setfield_rrect(fL, "rrect", rrect);
216 setfield_paint(fL, paint); 254 setfield_paint(fL, paint);
217 } 255 }
218 256
219 void SkLuaCanvas::drawPath(const SkPath& path, const SkPaint& paint) { 257 void SkLuaCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
220 AUTO_LUA("drawPath"); 258 AUTO_LUA("drawPath");
221 setfield_rect(fL, "bounds", path.getBounds()); 259 setfield_rect(fL, "bounds", path.getBounds());
260 setfield_bool(fL, "isRect", path.isRect(NULL));
261 setfield_bool(fL, "isOval", path.isOval(NULL));
222 setfield_paint(fL, paint); 262 setfield_paint(fL, paint);
223 } 263 }
224 264
225 void SkLuaCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, 265 void SkLuaCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
226 const SkPaint* paint) { 266 const SkPaint* paint) {
227 AUTO_LUA("drawBitmap"); 267 AUTO_LUA("drawBitmap");
228 if (paint) { 268 if (paint) {
229 setfield_paint(fL, *paint, kImage_PaintUsage); 269 setfield_paint(fL, *paint, kImage_PaintUsage);
230 } 270 }
231 } 271 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 const SkColor colors[], SkXfermode* xmode, 331 const SkColor colors[], SkXfermode* xmode,
292 const uint16_t indices[], int indexCount, 332 const uint16_t indices[], int indexCount,
293 const SkPaint& paint) { 333 const SkPaint& paint) {
294 AUTO_LUA("drawVertices"); 334 AUTO_LUA("drawVertices");
295 setfield_paint(fL, paint); 335 setfield_paint(fL, paint);
296 } 336 }
297 337
298 void SkLuaCanvas::drawData(const void* data, size_t length) { 338 void SkLuaCanvas::drawData(const void* data, size_t length) {
299 AUTO_LUA("drawData"); 339 AUTO_LUA("drawData");
300 } 340 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698