| 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 #include "Path.h" | 10 #include "Path.h" |
| 11 #include "Global.h" | 11 #include "Global.h" |
| 12 | 12 |
| 13 Global* Path::gGlobal = NULL; | 13 Global* Path::gGlobal = NULL; |
| 14 | 14 |
| 15 void Path::ConstructPath(const v8::FunctionCallbackInfo<Value>& args) { | 15 void Path::ConstructPath(const v8::FunctionCallbackInfo<Value>& args) { |
| 16 HandleScope handleScope(gGlobal->getIsolate()); | 16 HandleScope handleScope(gGlobal->getIsolate()); |
| 17 Path* path = new Path(); | 17 Path* path = new Path(); |
| 18 args.This()->SetInternalField(0, External::New(path)); | 18 args.This()->SetInternalField( |
| 19 0, External::New(gGlobal->getIsolate(), path)); |
| 19 } | 20 } |
| 20 | 21 |
| 21 #define ADD_METHOD(name, fn) \ | 22 #define ADD_METHOD(name, fn) \ |
| 22 constructor->InstanceTemplate()->Set( \ | 23 constructor->InstanceTemplate()->Set( \ |
| 23 String::NewFromUtf8( \ | 24 String::NewFromUtf8( \ |
| 24 global->getIsolate(), name, \ | 25 global->getIsolate(), name, \ |
| 25 String::kInternalizedString), \ | 26 String::kInternalizedString), \ |
| 26 FunctionTemplate::New(fn)) | 27 FunctionTemplate::New(global->getIsolate(), fn)) |
| 27 | 28 |
| 28 // Install the constructor in the global scope so Paths can be constructed | 29 // Install the constructor in the global scope so Paths can be constructed |
| 29 // in JS. | 30 // in JS. |
| 30 void Path::AddToGlobal(Global* global) { | 31 void Path::AddToGlobal(Global* global) { |
| 31 gGlobal = global; | 32 gGlobal = global; |
| 32 | 33 |
| 33 // Create a stack-allocated handle scope. | 34 // Create a stack-allocated handle scope. |
| 34 HandleScope handleScope(gGlobal->getIsolate()); | 35 HandleScope handleScope(gGlobal->getIsolate()); |
| 35 | 36 |
| 36 Handle<Context> context = gGlobal->getContext(); | 37 Handle<Context> context = gGlobal->getContext(); |
| 37 | 38 |
| 38 // Enter the scope so all operations take place in the scope. | 39 // Enter the scope so all operations take place in the scope. |
| 39 Context::Scope contextScope(context); | 40 Context::Scope contextScope(context); |
| 40 | 41 |
| 41 Local<FunctionTemplate> constructor = FunctionTemplate::New( | 42 Local<FunctionTemplate> constructor = FunctionTemplate::New( |
| 42 Path::ConstructPath); | 43 gGlobal->getIsolate(), Path::ConstructPath); |
| 43 constructor->InstanceTemplate()->SetInternalFieldCount(1); | 44 constructor->InstanceTemplate()->SetInternalFieldCount(1); |
| 44 | 45 |
| 45 ADD_METHOD("close", ClosePath); | 46 ADD_METHOD("close", ClosePath); |
| 46 ADD_METHOD("moveTo", MoveTo); | 47 ADD_METHOD("moveTo", MoveTo); |
| 47 ADD_METHOD("lineTo", LineTo); | 48 ADD_METHOD("lineTo", LineTo); |
| 48 ADD_METHOD("quadraticCurveTo", QuadraticCurveTo); | 49 ADD_METHOD("quadraticCurveTo", QuadraticCurveTo); |
| 49 ADD_METHOD("bezierCurveTo", BezierCurveTo); | 50 ADD_METHOD("bezierCurveTo", BezierCurveTo); |
| 50 ADD_METHOD("arc", Arc); | 51 ADD_METHOD("arc", Arc); |
| 51 ADD_METHOD("rect", Rect); | 52 ADD_METHOD("rect", Rect); |
| 52 | 53 |
| 53 context->Global()->Set(String::New("Path"), constructor->GetFunction()); | 54 context->Global()->Set(String::NewFromUtf8( |
| 55 gGlobal->getIsolate(), "Path"), constructor->GetFunction()); |
| 54 } | 56 } |
| 55 | 57 |
| 56 Path* Path::Unwrap(const v8::FunctionCallbackInfo<Value>& args) { | 58 Path* Path::Unwrap(const v8::FunctionCallbackInfo<Value>& args) { |
| 57 Handle<External> field = Handle<External>::Cast( | 59 Handle<External> field = Handle<External>::Cast( |
| 58 args.This()->GetInternalField(0)); | 60 args.This()->GetInternalField(0)); |
| 59 void* ptr = field->Value(); | 61 void* ptr = field->Value(); |
| 60 return static_cast<Path*>(ptr); | 62 return static_cast<Path*>(ptr); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void Path::ClosePath(const v8::FunctionCallbackInfo<Value>& args) { | 65 void Path::ClosePath(const v8::FunctionCallbackInfo<Value>& args) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 184 |
| 183 SkRect rect = { | 185 SkRect rect = { |
| 184 SkDoubleToScalar(x), | 186 SkDoubleToScalar(x), |
| 185 SkDoubleToScalar(y), | 187 SkDoubleToScalar(y), |
| 186 SkDoubleToScalar(x) + SkDoubleToScalar(w), | 188 SkDoubleToScalar(x) + SkDoubleToScalar(w), |
| 187 SkDoubleToScalar(y) + SkDoubleToScalar(h) | 189 SkDoubleToScalar(y) + SkDoubleToScalar(h) |
| 188 }; | 190 }; |
| 189 Path* path = Unwrap(args); | 191 Path* path = Unwrap(args); |
| 190 path->fSkPath.addRect(rect); | 192 path->fSkPath.addRect(rect); |
| 191 } | 193 } |
| OLD | NEW |