| Index: experimental/SkV8Example/BaseContext.h
|
| diff --git a/experimental/SkV8Example/JsContext.h b/experimental/SkV8Example/BaseContext.h
|
| similarity index 64%
|
| copy from experimental/SkV8Example/JsContext.h
|
| copy to experimental/SkV8Example/BaseContext.h
|
| index c1466a08dda05e4cb7dc3b99dcc68865e6493c36..b7fe3815a6aedb30737ad5abbefe171451c45b2c 100644
|
| --- a/experimental/SkV8Example/JsContext.h
|
| +++ b/experimental/SkV8Example/BaseContext.h
|
| @@ -7,8 +7,8 @@
|
| *
|
| */
|
|
|
| -#ifndef SkV8Example_JsContext_DEFINED
|
| -#define SkV8Example_JsContext_DEFINED
|
| +#ifndef SkV8Example_BaseContext_DEFINED
|
| +#define SkV8Example_BaseContext_DEFINED
|
|
|
| #include <v8.h>
|
|
|
| @@ -19,18 +19,12 @@ using namespace v8;
|
| class SkCanvas;
|
| class Global;
|
|
|
| -// Provides the canvas context 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(context) {
|
| -// context.fillStyle="#FF0000";
|
| -// context.fillRect(x, y, w, h);
|
| -// }
|
| -class JsContext {
|
| +// BaseContext contains common functionality for both JsContext
|
| +// and DisplayList.
|
| +class BaseContext {
|
| public:
|
| - JsContext(Global* global)
|
| + BaseContext(Global* global)
|
| : fGlobal(global)
|
| - , fCanvas(NULL)
|
| {
|
| fFillStyle.setColor(SK_ColorBLACK);
|
| fFillStyle.setAntiAlias(true);
|
| @@ -39,13 +33,21 @@ public:
|
| fStrokeStyle.setAntiAlias(true);
|
| fStrokeStyle.setStyle(SkPaint::kStroke_Style);
|
| }
|
| - ~JsContext();
|
| + virtual ~BaseContext() {}
|
|
|
| - // Parse the script.
|
| - bool initialize();
|
| + // Retrieve the SkCanvas to draw on. May return NULL.
|
| + virtual SkCanvas* getCanvas() = 0;
|
|
|
| - // Call this with the SkCanvas you want onDraw to draw on.
|
| - void onDraw(SkCanvas* canvas);
|
| + // Add the Javascript attributes and methods that BaseContext implements to the ObjectTemplate.
|
| + void addAttributesAndMethods(Handle<ObjectTemplate> tmpl);
|
| +
|
| +protected:
|
| + // Get the pointer out of obj.
|
| + static BaseContext* Unwrap(Handle<Object> obj);
|
| +
|
| + Global* fGlobal;
|
| + SkPaint fFillStyle;
|
| + SkPaint fStrokeStyle;
|
|
|
| private:
|
| static void GetStyle(Local<String> name,
|
| @@ -77,31 +79,6 @@ private:
|
| static void Restore(const v8::FunctionCallbackInfo<Value>& args);
|
| static void Translate(const v8::FunctionCallbackInfo<Value>& args);
|
| static void ResetTransform(const v8::FunctionCallbackInfo<Value>& args);
|
| -
|
| - // Get the pointer out of obj.
|
| - static JsContext* Unwrap(Handle<Object> obj);
|
| -
|
| - // Create a template for JS object associated with JsContext, called lazily
|
| - // by Wrap() and the results are stored in gContextTemplate;
|
| - Handle<ObjectTemplate> makeContextTemplate();
|
| -
|
| - // Wrap the 'this' pointer into an Object. Can be retrieved via Unwrap.
|
| - Handle<Object> wrap();
|
| -
|
| - Global* fGlobal;
|
| -
|
| - // Only valid when inside OnDraw().
|
| - SkCanvas* fCanvas;
|
| -
|
| - SkPaint fFillStyle;
|
| - SkPaint fStrokeStyle;
|
| -
|
| - // A handle to the onDraw function defined in the script.
|
| - Persistent<Function> fOnDraw;
|
| -
|
| - // The template for what a canvas context object looks like. The canvas
|
| - // context object is what's passed into the JS onDraw() function.
|
| - static Persistent<ObjectTemplate> gContextTemplate;
|
| };
|
|
|
| #endif
|
|
|