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
This commit is contained in:
commit-bot@chromium.org 2013-12-16 18:24:51 +00:00
parent afada4c2e6
commit 48d94b8ce5
3 changed files with 36 additions and 11 deletions

View File

@ -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);
}

View File

@ -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;
}();

View File

@ -18,6 +18,7 @@
'skia_lib.gyp:skia_lib',
'views.gyp:views',
'xml.gyp:xml',
'flags.gyp:flags',
],
'link_settings': {