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

Unified Diff: experimental/SkV8Example/SkV8Example.cpp

Issue 111853008: Add command line flag for optionally loading JS from external files. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: retry. Created 7 years 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 | « no previous file | experimental/SkV8Example/sample.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/SkV8Example.cpp
diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp
index a57232e7a5fe1bffbc559917ebea7fa1ced4be08..106bef99de2a88e27d24bab722cabebb4d978c2d 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);
}
« no previous file with comments | « no previous file | experimental/SkV8Example/sample.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698