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

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

Issue 103143009: Add a setTimer() function. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 7 years 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 | « experimental/SkV8Example/Global.cpp ('k') | experimental/SkV8Example/SkV8Example.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 2013 Google Inc. 2 * Copyright 2013 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_DEFINED 10 #ifndef SkV8Example_DEFINED
11 #define SkV8Example_DEFINED 11 #define SkV8Example_DEFINED
12 12
13 #include <v8.h> 13 #include <v8.h>
14 14
15 #include "SkWindow.h" 15 #include "SkWindow.h"
16 #include "SkPaint.h" 16 #include "SkPaint.h"
17 17
18 using namespace v8; 18 using namespace v8;
19 19
20 class SkCanvas; 20 class SkCanvas;
21 class JsCanvas; 21 class JsCanvas;
22 class Global;
22 23
23 class SkV8ExampleWindow : public SkOSWindow { 24 class SkV8ExampleWindow : public SkOSWindow {
24 public: 25 public:
25 SkV8ExampleWindow(void* hwnd, JsCanvas* canvas); 26 SkV8ExampleWindow(void* hwnd, JsCanvas* canvas);
26 27
27 protected: 28 protected:
28 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE; 29 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE;
29 30
30 #ifdef SK_BUILD_FOR_WIN 31 #ifdef SK_BUILD_FOR_WIN
31 virtual void onHandleInval(const SkIRect&) SK_OVERRIDE; 32 virtual void onHandleInval(const SkIRect&) SK_OVERRIDE;
32 #endif 33 #endif
33 34
34 private: 35 private:
35 typedef SkOSWindow INHERITED; 36 typedef SkOSWindow INHERITED;
36 JsCanvas* fJsCanvas; 37 JsCanvas* fJsCanvas;
37 }; 38 };
38 39
39 40
40 // Provides the canvas implementation in JS, and the OnDraw() method in C++ 41 // Provides the canvas implementation in JS, and the OnDraw() method in C++
41 // that's used to bridge from C++ to JS. Should be used in JS as: 42 // that's used to bridge from C++ to JS. Should be used in JS as:
42 // 43 //
43 // function onDraw(canvas) { 44 // function onDraw(canvas) {
44 // canvas.fillStyle="#FF0000"; 45 // canvas.fillStyle="#FF0000";
45 // canvas.fillRect(x, y, w, h); 46 // canvas.fillRect(x, y, w, h);
46 // canvas.inval();
47 // } 47 // }
48 class JsCanvas { 48 class JsCanvas {
49 public: 49 public:
50 JsCanvas(Isolate* isolate) 50 JsCanvas(Global* global)
51 : fIsolate(isolate) 51 : fGlobal(global)
52 , fCanvas(NULL) 52 , fCanvas(NULL)
53 , fWindow(NULL)
54 { 53 {
55 fFillStyle.setColor(SK_ColorRED); 54 fFillStyle.setColor(SK_ColorRED);
56 } 55 }
57 ~JsCanvas(); 56 ~JsCanvas();
58 57
59 // Parse the script. 58 // Parse the script.
60 bool initialize(const char script[]); 59 bool initialize();
61 60
62 // Call this with the SkCanvas you want onDraw to draw on. 61 // Call this with the SkCanvas you want onDraw to draw on.
63 void onDraw(SkCanvas* canvas, SkOSWindow* window); 62 void onDraw(SkCanvas* canvas);
64 63
65 private: 64 private:
66 // Implementation of the canvas.fillStyle field. 65 // Implementation of the canvas.fillStyle field.
67 static void GetFillStyle(Local<String> name, 66 static void GetFillStyle(Local<String> name,
68 const PropertyCallbackInfo<Value>& info); 67 const PropertyCallbackInfo<Value>& info);
69 static void SetFillStyle(Local<String> name, Local<Value> value, 68 static void SetFillStyle(Local<String> name, Local<Value> value,
70 const PropertyCallbackInfo<void>& info); 69 const PropertyCallbackInfo<void>& info);
71 70
72 // Implementation of the canvas.fillRect() JS function. 71 // Implementation of the canvas.fillRect() JS function.
73 static void FillRect(const v8::FunctionCallbackInfo<Value>& args); 72 static void FillRect(const v8::FunctionCallbackInfo<Value>& args);
74 73
75 // Implementation of the canvas.inval() JS function.
76 static void Inval(const v8::FunctionCallbackInfo<Value>& args);
77
78 // Get the pointer out of obj. 74 // Get the pointer out of obj.
79 static JsCanvas* Unwrap(Handle<Object> obj); 75 static JsCanvas* Unwrap(Handle<Object> obj);
80 76
81 // Create a template for JS object associated with JsCanvas, called lazily 77 // Create a template for JS object associated with JsCanvas, called lazily
82 // by Wrap() and the results are stored in fCanvasTemplate; 78 // by Wrap() and the results are stored in fCanvasTemplate;
83 Handle<ObjectTemplate> makeCanvasTemplate(); 79 Handle<ObjectTemplate> makeCanvasTemplate();
84 80
85 // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap. 81 // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap.
86 Handle<Object> wrap(); 82 Handle<Object> wrap();
87 83
88 Isolate* fIsolate; 84 Global* fGlobal;
89 85
90 // Only valid when inside OnDraw(). 86 // Only valid when inside OnDraw().
91 SkCanvas* fCanvas; 87 SkCanvas* fCanvas;
92 88
93 SkPaint fFillStyle; 89 SkPaint fFillStyle;
94 90
95 // Only valid when inside OnDraw().
96 SkOSWindow* fWindow;
97
98 // The context that the script will be parsed into.
99 Persistent<Context> fContext;
100
101 // A handle to the onDraw function defined in the script. 91 // A handle to the onDraw function defined in the script.
102 Persistent<Function> fOnDraw; 92 Persistent<Function> fOnDraw;
103 93
104 // The template for what a canvas object looks like. The canvas object is 94 // The template for what a canvas object looks like. The canvas object is
105 // what's passed into the JS onDraw() function. 95 // what's passed into the JS onDraw() function.
106 static Persistent<ObjectTemplate> fCanvasTemplate; 96 static Persistent<ObjectTemplate> fCanvasTemplate;
107 }; 97 };
108 98
109 #endif 99 #endif
OLDNEW
« no previous file with comments | « experimental/SkV8Example/Global.cpp ('k') | experimental/SkV8Example/SkV8Example.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698