Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1636)

Unified Diff: experimental/SkV8Example/Path2DBuilder.cpp

Issue 661033005: SkV8Sample: Now with Path2D and Path2DBuilder. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: path* Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/SkV8Example/Path2DBuilder.h ('k') | experimental/SkV8Example/SkV8Example.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/Path2DBuilder.cpp
diff --git a/experimental/SkV8Example/Path2D.cpp b/experimental/SkV8Example/Path2DBuilder.cpp
similarity index 76%
copy from experimental/SkV8Example/Path2D.cpp
copy to experimental/SkV8Example/Path2DBuilder.cpp
index 5956f69de3ade6e6fea477cb364cbe34220e4371..ad05668139a514113e5bbd769409eec3bd41bbfd 100644
--- a/experimental/SkV8Example/Path2D.cpp
+++ b/experimental/SkV8Example/Path2DBuilder.cpp
@@ -7,14 +7,16 @@
*
*/
-#include "Path2D.h"
#include "Global.h"
+#include "Path2DBuilder.h"
+#include "Path2D.h"
+#include "SkPath.h"
-Global* Path2D::gGlobal = NULL;
+Global* Path2DBuilder::gGlobal = NULL;
-void Path2D::ConstructPath(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::ConstructPath(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handleScope(gGlobal->getIsolate());
- Path2D* path = new Path2D();
+ Path2DBuilder* path = new Path2DBuilder();
args.This()->SetInternalField(
0, v8::External::New(gGlobal->getIsolate(), path));
}
@@ -26,9 +28,9 @@ void Path2D::ConstructPath(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::String::kInternalizedString), \
v8::FunctionTemplate::New(global->getIsolate(), fn))
-// Install the constructor in the global scope so Path2Ds can be constructed
+// Install the constructor in the global scope so Path2DBuilders can be constructed
// in JS.
-void Path2D::AddToGlobal(Global* global) {
+void Path2DBuilder::AddToGlobal(Global* global) {
gGlobal = global;
// Create a stack-allocated handle scope.
@@ -40,10 +42,10 @@ void Path2D::AddToGlobal(Global* global) {
v8::Context::Scope contextScope(context);
v8::Local<v8::FunctionTemplate> constructor = v8::FunctionTemplate::New(
- gGlobal->getIsolate(), Path2D::ConstructPath);
+ gGlobal->getIsolate(), Path2DBuilder::ConstructPath);
constructor->InstanceTemplate()->SetInternalFieldCount(1);
- ADD_METHOD("closePath", ClosePath);
+ ADD_METHOD("close", ClosePath);
ADD_METHOD("moveTo", MoveTo);
ADD_METHOD("lineTo", LineTo);
ADD_METHOD("quadraticCurveTo", QuadraticCurveTo);
@@ -53,23 +55,25 @@ void Path2D::AddToGlobal(Global* global) {
ADD_METHOD("oval", Oval);
ADD_METHOD("conicTo", ConicTo);
+ ADD_METHOD("finalize", Finalize);
+
context->Global()->Set(v8::String::NewFromUtf8(
- gGlobal->getIsolate(), "Path2D"), constructor->GetFunction());
+ gGlobal->getIsolate(), "Path2DBuilder"), constructor->GetFunction());
}
-Path2D* Path2D::Unwrap(const v8::FunctionCallbackInfo<v8::Value>& args) {
+Path2DBuilder* Path2DBuilder::Unwrap(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(
args.This()->GetInternalField(0));
void* ptr = field->Value();
- return static_cast<Path2D*>(ptr);
+ return static_cast<Path2DBuilder*>(ptr);
}
-void Path2D::ClosePath(const v8::FunctionCallbackInfo<v8::Value>& args) {
- Path2D* path = Unwrap(args);
+void Path2DBuilder::ClosePath(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ Path2DBuilder* path = Unwrap(args);
path->fSkPath.close();
}
-void Path2D::MoveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::MoveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -78,11 +82,11 @@ void Path2D::MoveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
double x = args[0]->NumberValue();
double y = args[1]->NumberValue();
- Path2D* path = Unwrap(args);
+ Path2DBuilder* path = Unwrap(args);
path->fSkPath.moveTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
}
-void Path2D::LineTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::LineTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 2) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -91,11 +95,11 @@ void Path2D::LineTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
double x = args[0]->NumberValue();
double y = args[1]->NumberValue();
- Path2D* path = Unwrap(args);
+ Path2DBuilder* path = Unwrap(args);
path->fSkPath.lineTo(SkDoubleToScalar(x), SkDoubleToScalar(y));
}
-void Path2D::QuadraticCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::QuadraticCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 4) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -106,7 +110,7 @@ void Path2D::QuadraticCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
double cpy = args[1]->NumberValue();
double x = args[2]->NumberValue();
double y = args[3]->NumberValue();
- Path2D* path = Unwrap(args);
+ Path2DBuilder* path = Unwrap(args);
// TODO(jcgregorio) Doesn't handle the empty last path case correctly per
// the HTML 5 spec.
path->fSkPath.quadTo(
@@ -114,7 +118,7 @@ void Path2D::QuadraticCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
SkDoubleToScalar(x), SkDoubleToScalar(y));
}
-void Path2D::BezierCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::BezierCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 6) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -127,7 +131,7 @@ void Path2D::BezierCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
double cp2y = args[3]->NumberValue();
double x = args[4]->NumberValue();
double y = args[5]->NumberValue();
- Path2D* path = Unwrap(args);
+ Path2DBuilder* path = Unwrap(args);
// TODO(jcgregorio) Doesn't handle the empty last path case correctly per
// the HTML 5 spec.
path->fSkPath.cubicTo(
@@ -136,7 +140,7 @@ void Path2D::BezierCurveTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
SkDoubleToScalar(x), SkDoubleToScalar(y));
}
-void Path2D::Arc(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::Arc(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 5 && args.Length() != 6) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -160,7 +164,7 @@ void Path2D::Arc(const v8::FunctionCallbackInfo<v8::Value>& args) {
startAngle = endAngle;
}
- Path2D* path = Unwrap(args);
+ Path2DBuilder* path = Unwrap(args);
SkRect rect = {
SkDoubleToScalar(x-radius),
SkDoubleToScalar(y-radius),
@@ -172,7 +176,7 @@ void Path2D::Arc(const v8::FunctionCallbackInfo<v8::Value>& args) {
SkRadiansToDegrees(sweepAngle));
}
-void Path2D::Rect(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::Rect(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 4) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -190,11 +194,11 @@ void Path2D::Rect(const v8::FunctionCallbackInfo<v8::Value>& args) {
SkDoubleToScalar(x) + SkDoubleToScalar(w),
SkDoubleToScalar(y) + SkDoubleToScalar(h)
};
- Path2D* path = Unwrap(args);
+ Path2DBuilder* path = Unwrap(args);
path->fSkPath.addRect(rect);
}
-void Path2D::Oval(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::Oval(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 4 && args.Length() != 5) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -209,7 +213,7 @@ void Path2D::Oval(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() == 5 && !args[4]->BooleanValue()) {
dir = SkPath::kCCW_Direction;
}
- Path2D* path = Unwrap(args);
+ Path2DBuilder* path = Unwrap(args);
SkRect rect = {
SkDoubleToScalar(x-radiusX),
SkDoubleToScalar(y-radiusX),
@@ -220,7 +224,7 @@ void Path2D::Oval(const v8::FunctionCallbackInfo<v8::Value>& args) {
path->fSkPath.addOval(rect, dir);
}
-void Path2D::ConicTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
+void Path2DBuilder::ConicTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 5) {
args.GetIsolate()->ThrowException(
v8::String::NewFromUtf8(
@@ -232,7 +236,7 @@ void Path2D::ConicTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
double x2 = args[2]->NumberValue();
double y2 = args[3]->NumberValue();
double w = args[4]->NumberValue();
- Path2D* path = Unwrap(args);
+ Path2DBuilder* path = Unwrap(args);
path->fSkPath.conicTo(
SkDoubleToScalar(x1),
@@ -242,3 +246,16 @@ void Path2D::ConicTo(const v8::FunctionCallbackInfo<v8::Value>& args) {
SkDoubleToScalar(w)
);
}
+
+void Path2DBuilder::Finalize(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ Path2DBuilder* path = Unwrap(args);
+
+ // Build Path2D from out fSkPath and return it.
+ SkPath* skPath = new SkPath(path->fSkPath);
+
+ path->fSkPath.reset();
+
+ Path2D* pathWrap = new Path2D(skPath);
+
+ args.GetReturnValue().Set(pathWrap->persistent());
+}
« no previous file with comments | « experimental/SkV8Example/Path2DBuilder.h ('k') | experimental/SkV8Example/SkV8Example.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698