| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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_Path2D_DEFINED | 10 #ifndef SkV8Example_Path2D_DEFINED |
| 11 #define SkV8Example_Path2D_DEFINED | 11 #define SkV8Example_Path2D_DEFINED |
| 12 | 12 |
| 13 #include <v8.h> | 13 #include <v8.h> |
| 14 | 14 |
| 15 #include "SkPath.h" | 15 #include "SkPath.h" |
| 16 #include "SkTypes.h" | 16 #include "SkTypes.h" |
| 17 | 17 |
| 18 class Global; | 18 class Global; |
| 19 | 19 |
| 20 // Path2D bridges between JS and SkPath. |
| 20 class Path2D : SkNoncopyable { | 21 class Path2D : SkNoncopyable { |
| 21 public: | 22 public: |
| 22 Path2D() : fSkPath() {} | 23 Path2D(SkPath* path); |
| 23 virtual ~Path2D() {} | 24 virtual ~Path2D(); |
| 24 | 25 |
| 25 const SkPath& getSkPath() { return fSkPath; } | 26 static void AddToGlobal(Global* global) { |
| 27 gGlobal = global; |
| 28 } |
| 26 | 29 |
| 27 // The JS Path2D constuctor implementation. | 30 v8::Persistent<v8::Object>& persistent() { |
| 28 static void ConstructPath(const v8::FunctionCallbackInfo<v8::Value>& args); | 31 return handle_; |
| 32 } |
| 29 | 33 |
| 30 // Add the Path2D JS constructor to the global context. | 34 SkPath* path() { |
| 31 static void AddToGlobal(Global* global); | 35 return path_; |
| 36 } |
| 32 | 37 |
| 33 // Path2D JS methods. | |
| 34 static void ClosePath(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 35 static void MoveTo(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 36 static void LineTo(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 37 static void QuadraticCurveTo( | |
| 38 const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 39 static void BezierCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 40 static void Arc(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 41 static void Rect(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 42 static void Oval(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 43 static void ConicTo(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 44 private: | 38 private: |
| 45 SkPath fSkPath; | 39 // The handle to this object in JS space. |
| 40 v8::Persistent<v8::Object> handle_; |
| 46 | 41 |
| 47 static Path2D* Unwrap(const v8::FunctionCallbackInfo<v8::Value>& args); | 42 SkPath* path_; |
| 48 | 43 |
| 44 // The global context we are running in. |
| 49 static Global* gGlobal; | 45 static Global* gGlobal; |
| 46 |
| 47 // The template for what a JS Path2D object looks like. |
| 48 static v8::Persistent<v8::ObjectTemplate> gPath2DTemplate; |
| 50 }; | 49 }; |
| 51 | 50 |
| 52 #endif | 51 #endif |
| OLD | NEW |