diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-16 18:24:51 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-16 18:24:51 +0000 |
commit | 48d94b8ce51a4b75fe1fe996b135fcd5b2d34779 (patch) | |
tree | 0a97c2ff4c86ada4e4d65c8c5e697306bd4b476a /experimental | |
parent | afada4c2e6214871f51146398265a96026fc7674 (diff) |
Add command line flag for optionally loading JS from external files.
BUG=
R=robertphillips@google.com
Author: jcgregorio@google.com
Review URL: https://codereview.chromium.org/111853008
git-svn-id: http://skia.googlecode.com/svn/trunk@12692 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/SkV8Example/SkV8Example.cpp | 33 | ||||
-rw-r--r-- | experimental/SkV8Example/sample.js | 13 |
2 files changed, 35 insertions, 11 deletions
diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp index a57232e7a5..106bef99de 100644 --- a/experimental/SkV8Example/SkV8Example.cpp +++ b/experimental/SkV8Example/SkV8Example.cpp @@ -16,12 +16,16 @@ using namespace v8; #include "gl/GrGLDefines.h" #include "gl/GrGLInterface.h" #include "SkApplication.h" +#include "SkCommandLineFlags.h" +#include "SkData.h" #include "SkDraw.h" #include "SkGpuDevice.h" #include "SkGraphics.h" #include "SkScalar.h" +DEFINE_string2(infile, i, NULL, "Name of file to load JS from.\n"); + void application_init() { SkGraphics::Init(); SkEvent::Init(); @@ -375,25 +379,32 @@ bool JsCanvas::initialize(const char script[]) { SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { printf("Started\n"); + SkCommandLineFlags::Parse(argc, argv); + // Get the default Isolate created at startup. Isolate* isolate = Isolate::GetCurrent(); JsCanvas* jsCanvas = new JsCanvas(isolate); + const char* script = -"var onDraw = function(){ \n" -" var tick = 0; \n" -" function f(canvas) { \n" -" tick += 0.001; \n" -" canvas.fillStyle = '#00FF00'; \n" -" canvas.fillRect(20, 20, 100, Math.abs(Math.cos(tick)*100)); \n" -" canvas.inval(); \n" -" }; \n" -" return f; \n" -"}(); \n"; +"function onDraw(canvas) { \n" +" canvas.fillStyle = '#00FF00'; \n" +" canvas.fillRect(20, 20, 100, 100); \n" +" canvas.inval(); \n" +"} \n"; + + SkAutoTUnref<SkData> data; + if (FLAGS_infile.count()) { + data.reset(SkData::NewFromFileName(FLAGS_infile[0])); + script = static_cast<const char*>(data->data()); + } + if (NULL == script) { + printf("Could not load file: %s.\n", FLAGS_infile[0]); + exit(1); + } if (!jsCanvas->initialize(script)) { printf("Failed to initialize.\n"); exit(1); } - return new SkV8ExampleWindow(hwnd, jsCanvas); } diff --git a/experimental/SkV8Example/sample.js b/experimental/SkV8Example/sample.js new file mode 100644 index 0000000000..3a95e55106 --- /dev/null +++ b/experimental/SkV8Example/sample.js @@ -0,0 +1,13 @@ +/** + * @fileoverview Sample onDraw script for use with SkV8Example. + */ +var onDraw = function(){ + var tick = 0; + function f(canvas) { + tick += 0.01; + canvas.fillStyle = '#0000ff'; + canvas.fillRect(100, 100, Math.sin(tick)*100, Math.cos(tick)*100); + canvas.inval(); + }; + return f; +}(); |