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

Side by Side Diff: experimental/SkV8Example/JsContext.h

Issue 122373003: Add the gears.js demo and all the code changes needed to get it working, including (Closed) Base URL: https://skia.googlesource.com/skia.git@gl
Patch Set: rename Created 6 years, 11 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
« no previous file with comments | « no previous file | experimental/SkV8Example/JsContext.cpp » ('j') | 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 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 * 7 *
8 */ 8 */
9 9
10 #ifndef SkV8Example_JsContext_DEFINED 10 #ifndef SkV8Example_JsContext_DEFINED
(...skipping 14 matching lines...) Expand all
25 // function onDraw(context) { 25 // function onDraw(context) {
26 // context.fillStyle="#FF0000"; 26 // context.fillStyle="#FF0000";
27 // context.fillRect(x, y, w, h); 27 // context.fillRect(x, y, w, h);
28 // } 28 // }
29 class JsContext { 29 class JsContext {
30 public: 30 public:
31 JsContext(Global* global) 31 JsContext(Global* global)
32 : fGlobal(global) 32 : fGlobal(global)
33 , fCanvas(NULL) 33 , fCanvas(NULL)
34 { 34 {
35 fFillStyle.setColor(SK_ColorRED); 35 fFillStyle.setColor(SK_ColorBLACK);
36 fFillStyle.setAntiAlias(true);
37 fFillStyle.setStyle(SkPaint::kFill_Style);
38 fStrokeStyle.setColor(SK_ColorBLACK);
39 fStrokeStyle.setAntiAlias(true);
40 fStrokeStyle.setStyle(SkPaint::kStroke_Style);
36 } 41 }
37 ~JsContext(); 42 ~JsContext();
38 43
39 // Parse the script. 44 // Parse the script.
40 bool initialize(); 45 bool initialize();
41 46
42 // Call this with the SkCanvas you want onDraw to draw on. 47 // Call this with the SkCanvas you want onDraw to draw on.
43 void onDraw(SkCanvas* canvas); 48 void onDraw(SkCanvas* canvas);
44 49
45 private: 50 private:
46 // Implementation of the context.fillStyle field. 51 static void GetStyle(Local<String> name,
52 const PropertyCallbackInfo<Value>& info,
53 const SkPaint& style);
54 static void SetStyle(Local<String> name, Local<Value> value,
55 const PropertyCallbackInfo<void>& info,
56 SkPaint& style);
57 // JS Attributes
47 static void GetFillStyle(Local<String> name, 58 static void GetFillStyle(Local<String> name,
48 const PropertyCallbackInfo<Value>& info); 59 const PropertyCallbackInfo<Value>& info);
49 static void SetFillStyle(Local<String> name, Local<Value> value, 60 static void SetFillStyle(Local<String> name, Local<Value> value,
50 const PropertyCallbackInfo<void>& info); 61 const PropertyCallbackInfo<void>& info);
62 static void GetStrokeStyle(Local<String> name,
63 const PropertyCallbackInfo<Value>& info);
64 static void SetStrokeStyle(Local<String> name, Local<Value> value,
65 const PropertyCallbackInfo<void>& info);
51 static void GetWidth(Local<String> name, 66 static void GetWidth(Local<String> name,
52 const PropertyCallbackInfo<Value>& info); 67 const PropertyCallbackInfo<Value>& info);
53 static void GetHeight(Local<String> name, 68 static void GetHeight(Local<String> name,
54 const PropertyCallbackInfo<Value>& info); 69 const PropertyCallbackInfo<Value>& info);
55 70
56 // Implementation of the context.fillRect() JS function. 71 // JS Methods
57 static void FillRect(const v8::FunctionCallbackInfo<Value>& args); 72 static void FillRect(const v8::FunctionCallbackInfo<Value>& args);
58
59 // Implementation of the context.stroke(Path path) JS function.
60 static void Stroke(const v8::FunctionCallbackInfo<Value>& args); 73 static void Stroke(const v8::FunctionCallbackInfo<Value>& args);
61
62 // Implementation of the context.fill(Path path) JS function.
63 static void Fill(const v8::FunctionCallbackInfo<Value>& args); 74 static void Fill(const v8::FunctionCallbackInfo<Value>& args);
64 75 static void Rotate(const v8::FunctionCallbackInfo<Value>& args);
65 // Implementation of the context.translate(dx, dy) JS function. 76 static void Save(const v8::FunctionCallbackInfo<Value>& args);
77 static void Restore(const v8::FunctionCallbackInfo<Value>& args);
66 static void Translate(const v8::FunctionCallbackInfo<Value>& args); 78 static void Translate(const v8::FunctionCallbackInfo<Value>& args);
67
68 // Implementation of the context.resetTransform() JS function.
69 static void ResetTransform(const v8::FunctionCallbackInfo<Value>& args); 79 static void ResetTransform(const v8::FunctionCallbackInfo<Value>& args);
70 80
71 // Get the pointer out of obj. 81 // Get the pointer out of obj.
72 static JsContext* Unwrap(Handle<Object> obj); 82 static JsContext* Unwrap(Handle<Object> obj);
73 83
74 // Create a template for JS object associated with JsContext, called lazily 84 // Create a template for JS object associated with JsContext, called lazily
75 // by Wrap() and the results are stored in gContextTemplate; 85 // by Wrap() and the results are stored in gContextTemplate;
76 Handle<ObjectTemplate> makeContextTemplate(); 86 Handle<ObjectTemplate> makeContextTemplate();
77 87
78 // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap. 88 // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap.
79 Handle<Object> wrap(); 89 Handle<Object> wrap();
80 90
81 Global* fGlobal; 91 Global* fGlobal;
82 92
83 // Only valid when inside OnDraw(). 93 // Only valid when inside OnDraw().
84 SkCanvas* fCanvas; 94 SkCanvas* fCanvas;
85 95
86 SkPaint fFillStyle; 96 SkPaint fFillStyle;
97 SkPaint fStrokeStyle;
87 98
88 // A handle to the onDraw function defined in the script. 99 // A handle to the onDraw function defined in the script.
89 Persistent<Function> fOnDraw; 100 Persistent<Function> fOnDraw;
90 101
91 // The template for what a canvas context object looks like. The canvas 102 // The template for what a canvas context object looks like. The canvas
92 // context object is what's passed into the JS onDraw() function. 103 // context object is what's passed into the JS onDraw() function.
93 static Persistent<ObjectTemplate> gContextTemplate; 104 static Persistent<ObjectTemplate> gContextTemplate;
94 }; 105 };
95 106
96 #endif 107 #endif
OLDNEW
« no previous file with comments | « no previous file | experimental/SkV8Example/JsContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698