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

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

Issue 121303004: Fleshed out a lot of the Path interfac (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: review feedback 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
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"
tfarina 2014/01/06 16:03:55 you can remove this.
jcgregorio 2014/01/06 16:32:48 Done.
17 17
18 using namespace v8; 18 using namespace v8;
19 19
20 class SkCanvas; 20 class SkCanvas;
tfarina 2014/01/06 16:03:55 and this.
jcgregorio 2014/01/06 16:32:48 Done.
21 class JsCanvas; 21 class JsContext;
22 class Global;
23 22
24 class SkV8ExampleWindow : public SkOSWindow { 23 class SkV8ExampleWindow : public SkOSWindow {
25 public: 24 public:
26 SkV8ExampleWindow(void* hwnd, JsCanvas* canvas); 25 SkV8ExampleWindow(void* hwnd, JsContext* canvas);
27 26
28 protected: 27 protected:
29 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE; 28 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE;
30 29
31 #ifdef SK_BUILD_FOR_WIN 30 #ifdef SK_BUILD_FOR_WIN
32 virtual void onHandleInval(const SkIRect&) SK_OVERRIDE; 31 virtual void onHandleInval(const SkIRect&) SK_OVERRIDE;
33 #endif 32 #endif
34 33
35 private: 34 private:
36 typedef SkOSWindow INHERITED; 35 typedef SkOSWindow INHERITED;
37 JsCanvas* fJsCanvas; 36 JsContext* fJsContext;
38 };
39
40
41 // Provides the canvas implementation in JS, and the OnDraw() method in C++
42 // that's used to bridge from C++ to JS. Should be used in JS as:
43 //
44 // function onDraw(canvas) {
45 // canvas.fillStyle="#FF0000";
46 // canvas.fillRect(x, y, w, h);
47 // }
48 class JsCanvas {
49 public:
50 JsCanvas(Global* global)
51 : fGlobal(global)
52 , fCanvas(NULL)
53 {
54 fFillStyle.setColor(SK_ColorRED);
55 }
56 ~JsCanvas();
57
58 // Parse the script.
59 bool initialize();
60
61 // Call this with the SkCanvas you want onDraw to draw on.
62 void onDraw(SkCanvas* canvas);
63
64 private:
65 // Implementation of the canvas.fillStyle field.
66 static void GetFillStyle(Local<String> name,
67 const PropertyCallbackInfo<Value>& info);
68 static void SetFillStyle(Local<String> name, Local<Value> value,
69 const PropertyCallbackInfo<void>& info);
70
71 // Implementation of the canvas.fillRect() JS function.
72 static void FillRect(const v8::FunctionCallbackInfo<Value>& args);
73
74 // Get the pointer out of obj.
75 static JsCanvas* Unwrap(Handle<Object> obj);
76
77 // Create a template for JS object associated with JsCanvas, called lazily
78 // by Wrap() and the results are stored in fCanvasTemplate;
79 Handle<ObjectTemplate> makeCanvasTemplate();
80
81 // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap.
82 Handle<Object> wrap();
83
84 Global* fGlobal;
85
86 // Only valid when inside OnDraw().
87 SkCanvas* fCanvas;
88
89 SkPaint fFillStyle;
90
91 // A handle to the onDraw function defined in the script.
92 Persistent<Function> fOnDraw;
93
94 // The template for what a canvas object looks like. The canvas object is
95 // what's passed into the JS onDraw() function.
96 static Persistent<ObjectTemplate> fCanvasTemplate;
97 }; 37 };
98 38
99 #endif 39 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698