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

Side by Side Diff: experimental/SkV8Example/SkV8Example.cpp

Issue 132413002: Just use one version of the scripts in both the browser and in SkV8. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: merge Created 6 years, 11 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 unified diff | Download patch
« no previous file with comments | « experimental/SkV8Example/Path.cpp ('k') | experimental/SkV8Example/compare/gears.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 * 7 *
8 */ 8 */
9 #include <v8.h> 9 #include <v8.h>
10 10
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { 150 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
151 printf("Started\n"); 151 printf("Started\n");
152 152
153 SkCommandLineFlags::Parse(argc, argv); 153 SkCommandLineFlags::Parse(argc, argv);
154 154
155 // Get the default Isolate created at startup. 155 // Get the default Isolate created at startup.
156 Isolate* isolate = Isolate::GetCurrent(); 156 Isolate* isolate = Isolate::GetCurrent();
157 Global* global = new Global(isolate); 157 Global* global = new Global(isolate);
158 158
159
160 // Set up things to look like a browser by creating
161 // a console object that invokes our print function.
162 const char* startupScript =
163 "function Console() {}; \n"
164 "Console.prototype.log = function() { \n"
165 " var args = Array.prototype.slice.call(arguments).join(' '); \n"
166 " print(args); \n"
167 "}; \n"
168 "console = new Console(); \n";
169
170 if (!global->parseScript(startupScript)) {
171 printf("Failed to parse startup script: %s.\n", FLAGS_infile[0]);
172 exit(1);
173 }
174
159 const char* script = 175 const char* script =
160 "function onDraw(canvas) { \n" 176 "function onDraw(canvas) { \n"
161 " canvas.fillStyle = '#00FF00'; \n" 177 " canvas.fillStyle = '#00FF00'; \n"
162 " canvas.fillRect(20, 20, 100, 100); \n" 178 " canvas.fillRect(20, 20, 100, 100); \n"
163 " canvas.inval(); \n" 179 " canvas.inval(); \n"
164 "} \n"; 180 "} \n";
165 181
166 SkAutoTUnref<SkData> data; 182 SkAutoTUnref<SkData> data;
167 if (FLAGS_infile.count()) { 183 if (FLAGS_infile.count()) {
168 data.reset(SkData::NewFromFileName(FLAGS_infile[0])); 184 data.reset(SkData::NewFromFileName(FLAGS_infile[0]));
169 script = static_cast<const char*>(data->data()); 185 script = static_cast<const char*>(data->data());
170 } 186 }
171 if (NULL == script) { 187 if (NULL == script) {
172 printf("Could not load file: %s.\n", FLAGS_infile[0]); 188 printf("Could not load file: %s.\n", FLAGS_infile[0]);
173 exit(1); 189 exit(1);
174 } 190 }
175 Path::AddToGlobal(global); 191 Path::AddToGlobal(global);
176 192
177 if (!global->parseScript(script)) { 193 if (!global->parseScript(script)) {
178 printf("Failed to parse file: %s.\n", FLAGS_infile[0]); 194 printf("Failed to parse file: %s.\n", FLAGS_infile[0]);
179 exit(1); 195 exit(1);
180 } 196 }
181 197
198
182 JsContext* jsContext = new JsContext(global); 199 JsContext* jsContext = new JsContext(global);
183 200
184 if (!jsContext->initialize()) { 201 if (!jsContext->initialize()) {
185 printf("Failed to initialize.\n"); 202 printf("Failed to initialize.\n");
186 exit(1); 203 exit(1);
187 } 204 }
188 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); 205 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext);
189 global->setWindow(win); 206 global->setWindow(win);
190 207
191 return win; 208 return win;
192 } 209 }
OLDNEW
« no previous file with comments | « experimental/SkV8Example/Path.cpp ('k') | experimental/SkV8Example/compare/gears.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698