2 * Copyright 2014 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef SkV8Example_JsContext_DEFINED
11 #define SkV8Example_JsContext_DEFINED
16 #include "BaseContext.h"
23 // Provides the canvas context implementation in JS, and the OnDraw() method in
24 // C++ that's used to bridge from C++ to JS. Should be used in JS as:
26 // function onDraw(context) {
27 // context.fillStyle="#FF0000";
28 // context.fillRect(x, y, w, h);
30 class JsContext : public BaseContext {
32 JsContext(Global* global)
37 virtual ~JsContext() {}
42 // Call this with the SkCanvas you want onDraw to draw on.
43 void onDraw(SkCanvas* canvas);
45 virtual SkCanvas* getCanvas() { return fCanvas; };
49 // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap.
50 Handle<Object> wrap();
52 // A handle to the onDraw function defined in the script.
53 Persistent<Function> fOnDraw;
55 // The template for what a canvas context object looks like. The canvas
56 // context object is what's passed into the JS onDraw() function.
57 static Persistent<ObjectTemplate> gContextTemplate;
59 // Only valid when inside OnDraw().
62 typedef BaseContext INHERITED;