Chromium Code Reviews| Index: experimental/SkV8Example/SkV8Example.h |
| diff --git a/experimental/SkV8Example/SkV8Example.h b/experimental/SkV8Example/SkV8Example.h |
| index 97cf58017122f860d2fdb29b78644bc94ebc8c97..b64860c3591862919fab87e8e519e834df9c6727 100644 |
| --- a/experimental/SkV8Example/SkV8Example.h |
| +++ b/experimental/SkV8Example/SkV8Example.h |
| @@ -14,36 +14,86 @@ |
| #include "SkWindow.h" |
| - |
| using namespace v8; |
| - |
| class SkCanvas; |
| - |
| +class JsCanvas; |
| class SkV8ExampleWindow : public SkOSWindow { |
| public: |
| - SkV8ExampleWindow(void* hwnd, |
| - Isolate* isolate, |
| - Handle<Context> context, |
| - Handle<Script> script); |
| - |
| + SkV8ExampleWindow(void* hwnd, JsCanvas* canvas); |
| protected: |
| virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE; |
| - |
| - |
| #ifdef SK_BUILD_FOR_WIN |
| virtual void onHandleInval(const SkIRect&) SK_OVERRIDE; |
| #endif |
| private: |
| typedef SkOSWindow INHERITED; |
| + SkScalar fRotationAngle; |
| + JsCanvas* fJsCanvas; |
| +}; |
| + |
| + |
| +// Provides the canvas implementation in JS, and the OnDraw() method in C++ |
| +// that's used to bridge from C++ to JS. Should be used in JS as: |
| +// |
| +// function onDraw(canvas) { |
| +// canvas.drawRect(); |
| +// canvas.inval(); |
| +// } |
| +// |
| +class JsCanvas { |
| +public: |
| + JsCanvas(Isolate* isolate) |
| + : fIsolate(isolate) |
| + , fCanvas(NULL) |
| + , fWindow(NULL) |
| + {} |
| + ~JsCanvas(); |
| + |
| + // Parse the script. |
|
robertphillips
2013/12/10 13:40:44
initialize?
|
| + bool Initialize(const char script[]); |
| + |
|
robertphillips
2013/12/10 13:40:44
rm first to?
Also onDraw?
|
| + // Call this with the SkCanvas you want to onDraw to draw on. |
| + void OnDraw(SkCanvas* canvas, SkOSWindow* window); |
| + |
| +private: |
| + // Implementation of the canvas.drawRect() JS function. |
| + static void DrawRect(const v8::FunctionCallbackInfo<Value>& args); |
| + |
| + // Implementation of the canvas.inval() JS function. |
| + static void Inval(const v8::FunctionCallbackInfo<Value>& args); |
| + |
| + // Get the pointer out of obj. |
| + static JsCanvas* Unwrap(Handle<Object> obj); |
| + |
| + // Create a template for JS object associated with JsCanvas, called lazily |
| + // by Wrap() and the results are stored in canvas_template_; |
|
robertphillips
2013/12/10 13:40:44
makeCanvasTemplate?
|
| + Handle<ObjectTemplate> MakeCanvasTemplate(); |
| + |
| + // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap. |
|
robertphillips
2013/12/10 13:40:44
wrap?
|
| + Handle<Object> Wrap(); |
| + |
| Isolate* fIsolate; |
| + |
| + // Only valid when inside OnDraw(). |
| + SkCanvas* fCanvas; |
| + |
| + // Only valid when inside OnDraw(). |
| + SkOSWindow* fWindow; |
| + |
| + // The context that the script will be parsed into. |
| Persistent<Context> fContext; |
| - Persistent<Script> fScript; |
| - SkScalar fRotationAngle; |
| + |
| + // A handle to the onDraw function defined in the script. |
| + Persistent<Function> fOnDraw; |
| + |
| + // The template for what a canvas object looks like. The canvas object is |
| + // what's passed into the JS onDraw() function. |
|
robertphillips
2013/12/10 13:40:44
gCanvasTemplate?
|
| + static Persistent<ObjectTemplate> canvas_template_; |
| }; |
| #endif |