OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * | 5 * |
6 * Use of this source code is governed by a BSD-style license that can be | 6 * Use of this source code is governed by a BSD-style license that can be |
7 * found in the LICENSE file. | 7 * found in the LICENSE file. |
8 * | 8 * |
9 */ | 9 */ |
10 #include <v8.h> | 10 #include <v8.h> |
11 | 11 |
12 using namespace v8; | 12 using namespace v8; |
13 | 13 |
14 #include "Global.h" | 14 #include "Global.h" |
15 #include "JsContext.h" | 15 #include "JsContext.h" |
16 #include "Path.h" | 16 #include "Path2D.h" |
17 #include "SkCanvas.h" | 17 #include "SkCanvas.h" |
18 | 18 |
19 | 19 |
20 // Extracts a C string from a V8 Utf8Value. | 20 // Extracts a C string from a V8 Utf8Value. |
21 // TODO(jcgregrio) Currently dup'd in two files, fix. | 21 // TODO(jcgregrio) Currently dup'd in two files, fix. |
22 static const char* to_cstring(const v8::String::Utf8Value& value) { | 22 static const char* to_cstring(const v8::String::Utf8Value& value) { |
23 return *value ? *value : "<string conversion failed>"; | 23 return *value ? *value : "<string conversion failed>"; |
24 } | 24 } |
25 | 25 |
26 JsContext* JsContext::Unwrap(Handle<Object> obj) { | 26 JsContext* JsContext::Unwrap(Handle<Object> obj) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 if (args.Length() != 1) { | 112 if (args.Length() != 1) { |
113 args.GetIsolate()->ThrowException( | 113 args.GetIsolate()->ThrowException( |
114 v8::String::NewFromUtf8( | 114 v8::String::NewFromUtf8( |
115 args.GetIsolate(), "Error: 1 arguments required.")); | 115 args.GetIsolate(), "Error: 1 arguments required.")); |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 Handle<External> field = Handle<External>::Cast( | 119 Handle<External> field = Handle<External>::Cast( |
120 args[0]->ToObject()->GetInternalField(0)); | 120 args[0]->ToObject()->GetInternalField(0)); |
121 void* ptr = field->Value(); | 121 void* ptr = field->Value(); |
122 Path* path = static_cast<Path*>(ptr); | 122 Path2D* path = static_cast<Path2D*>(ptr); |
123 | 123 |
124 canvas->drawPath(path->getSkPath(), jsContext->fStrokeStyle); | 124 canvas->drawPath(path->getSkPath(), jsContext->fStrokeStyle); |
125 } | 125 } |
126 | 126 |
127 void JsContext::Fill(const v8::FunctionCallbackInfo<Value>& args) { | 127 void JsContext::Fill(const v8::FunctionCallbackInfo<Value>& args) { |
128 JsContext* jsContext = Unwrap(args.This()); | 128 JsContext* jsContext = Unwrap(args.This()); |
129 SkCanvas* canvas = jsContext->fCanvas; | 129 SkCanvas* canvas = jsContext->fCanvas; |
130 | 130 |
131 if (args.Length() != 1) { | 131 if (args.Length() != 1) { |
132 args.GetIsolate()->ThrowException( | 132 args.GetIsolate()->ThrowException( |
133 v8::String::NewFromUtf8( | 133 v8::String::NewFromUtf8( |
134 args.GetIsolate(), "Error: 1 arguments required.")); | 134 args.GetIsolate(), "Error: 1 arguments required.")); |
135 return; | 135 return; |
136 } | 136 } |
137 | 137 |
138 Handle<External> field = Handle<External>::Cast( | 138 Handle<External> field = Handle<External>::Cast( |
139 args[0]->ToObject()->GetInternalField(0)); | 139 args[0]->ToObject()->GetInternalField(0)); |
140 void* ptr = field->Value(); | 140 void* ptr = field->Value(); |
141 Path* path = static_cast<Path*>(ptr); | 141 Path2D* path = static_cast<Path2D*>(ptr); |
142 | 142 |
143 canvas->drawPath(path->getSkPath(), jsContext->fFillStyle); | 143 canvas->drawPath(path->getSkPath(), jsContext->fFillStyle); |
144 } | 144 } |
145 | 145 |
146 void JsContext::GetStyle(Local<String> name, | 146 void JsContext::GetStyle(Local<String> name, |
147 const PropertyCallbackInfo<Value>& info, | 147 const PropertyCallbackInfo<Value>& info, |
148 const SkPaint& style) { | 148 const SkPaint& style) { |
149 char buf[8]; | 149 char buf[8]; |
150 SkColor color = style.getColor(); | 150 SkColor color = style.getColor(); |
151 sprintf(buf, "#%02X%02X%02X", SkColorGetR(color), SkColorGetG(color), | 151 sprintf(buf, "#%02X%02X%02X", SkColorGetR(color), SkColorGetG(color), |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 374 |
375 // It is a function; cast it to a Function. | 375 // It is a function; cast it to a Function. |
376 Handle<Function> fn_fun = Handle<Function>::Cast(fn_val); | 376 Handle<Function> fn_fun = Handle<Function>::Cast(fn_val); |
377 | 377 |
378 // Store the function in a Persistent handle, since we also want that to | 378 // Store the function in a Persistent handle, since we also want that to |
379 // remain after this call returns. | 379 // remain after this call returns. |
380 fOnDraw.Reset(fGlobal->getIsolate(), fn_fun); | 380 fOnDraw.Reset(fGlobal->getIsolate(), fn_fun); |
381 | 381 |
382 return true; | 382 return true; |
383 } | 383 } |
OLD | NEW |