| OLD | NEW |
| 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 #include <include/libplatform/libplatform.h> | 10 #include <include/libplatform/libplatform.h> |
| 11 | 11 |
| 12 #include "SkV8Example.h" | 12 #include "SkV8Example.h" |
| 13 #include "Global.h" | 13 #include "Global.h" |
| 14 #include "JsContext.h" | 14 #include "JsContext.h" |
| 15 #include "Path2D.h" | 15 #include "Path2D.h" |
| 16 #include "Path2DBuilder.h" |
| 16 | 17 |
| 17 #include "gl/GrGLUtil.h" | 18 #include "gl/GrGLUtil.h" |
| 18 #include "gl/GrGLDefines.h" | 19 #include "gl/GrGLDefines.h" |
| 19 #include "gl/GrGLInterface.h" | 20 #include "gl/GrGLInterface.h" |
| 20 #include "GrRenderTarget.h" | 21 #include "GrRenderTarget.h" |
| 21 #include "GrContext.h" | 22 #include "GrContext.h" |
| 22 #include "SkApplication.h" | 23 #include "SkApplication.h" |
| 23 #include "SkCommandLineFlags.h" | 24 #include "SkCommandLineFlags.h" |
| 24 #include "SkData.h" | 25 #include "SkData.h" |
| 25 #include "SkDraw.h" | 26 #include "SkDraw.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 #endif | 123 #endif |
| 123 | 124 |
| 124 void SkV8ExampleWindow::onSizeChange() { | 125 void SkV8ExampleWindow::onSizeChange() { |
| 125 this->INHERITED::onSizeChange(); | 126 this->INHERITED::onSizeChange(); |
| 126 | 127 |
| 127 #if SK_SUPPORT_GPU | 128 #if SK_SUPPORT_GPU |
| 128 this->windowSizeChanged(); | 129 this->windowSizeChanged(); |
| 129 #endif | 130 #endif |
| 130 } | 131 } |
| 131 | 132 |
| 133 Global* global = NULL; |
| 134 |
| 132 void SkV8ExampleWindow::onDraw(SkCanvas* canvas) { | 135 void SkV8ExampleWindow::onDraw(SkCanvas* canvas) { |
| 133 | 136 |
| 134 canvas->save(); | 137 canvas->save(); |
| 135 canvas->drawColor(SK_ColorWHITE); | 138 canvas->drawColor(SK_ColorWHITE); |
| 136 | 139 |
| 137 // Now jump into JS and call the onDraw(canvas) method defined there. | 140 // Now jump into JS and call the onDraw(canvas) method defined there. |
| 138 fJsContext->onDraw(canvas); | 141 fJsContext->onDraw(canvas); |
| 139 | 142 |
| 140 canvas->restore(); | 143 canvas->restore(); |
| 141 | 144 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 157 winRect.right = rect.right(); | 160 winRect.right = rect.right(); |
| 158 winRect.left = rect.left(); | 161 winRect.left = rect.left(); |
| 159 InvalidateRect((HWND)this->getHWND(), &winRect, false); | 162 InvalidateRect((HWND)this->getHWND(), &winRect, false); |
| 160 } | 163 } |
| 161 #endif | 164 #endif |
| 162 | 165 |
| 163 | 166 |
| 164 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { | 167 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { |
| 165 printf("Started\n"); | 168 printf("Started\n"); |
| 166 | 169 |
| 170 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 167 SkCommandLineFlags::Parse(argc, argv); | 171 SkCommandLineFlags::Parse(argc, argv); |
| 168 | 172 |
| 169 v8::V8::InitializeICU(); | 173 v8::V8::InitializeICU(); |
| 170 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); | 174 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 171 v8::V8::InitializePlatform(platform); | 175 v8::V8::InitializePlatform(platform); |
| 172 v8::V8::Initialize(); | 176 v8::V8::Initialize(); |
| 173 | 177 |
| 174 v8::Isolate* isolate = v8::Isolate::New(); | 178 v8::Isolate* isolate = v8::Isolate::New(); |
| 175 v8::Isolate::Scope isolate_scope(isolate); | 179 v8::Isolate::Scope isolate_scope(isolate); |
| 176 v8::HandleScope handle_scope(isolate); | 180 v8::HandleScope handle_scope(isolate); |
| 177 isolate->Enter(); | 181 isolate->Enter(); |
| 178 | 182 |
| 179 Global* global = new Global(isolate); | 183 global = new Global(isolate); |
| 180 | 184 |
| 181 | 185 |
| 182 // Set up things to look like a browser by creating | 186 // Set up things to look like a browser by creating |
| 183 // a console object that invokes our print function. | 187 // a console object that invokes our print function. |
| 184 const char* startupScript = | 188 const char* startupScript = |
| 185 "function Console() {}; \n" | 189 "function Console() {}; \n" |
| 186 "Console.prototype.log = function() { \n" | 190 "Console.prototype.log = function() { \n" |
| 187 " var args = Array.prototype.slice.call(arguments).join(' '); \n" | 191 " var args = Array.prototype.slice.call(arguments).join(' '); \n" |
| 188 " print(args); \n" | 192 " print(args); \n" |
| 189 "}; \n" | 193 "}; \n" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 203 | 207 |
| 204 SkAutoTUnref<SkData> data; | 208 SkAutoTUnref<SkData> data; |
| 205 if (FLAGS_infile.count()) { | 209 if (FLAGS_infile.count()) { |
| 206 data.reset(SkData::NewFromFileName(FLAGS_infile[0])); | 210 data.reset(SkData::NewFromFileName(FLAGS_infile[0])); |
| 207 script = static_cast<const char*>(data->data()); | 211 script = static_cast<const char*>(data->data()); |
| 208 } | 212 } |
| 209 if (NULL == script) { | 213 if (NULL == script) { |
| 210 printf("Could not load file: %s.\n", FLAGS_infile[0]); | 214 printf("Could not load file: %s.\n", FLAGS_infile[0]); |
| 211 exit(1); | 215 exit(1); |
| 212 } | 216 } |
| 217 Path2DBuilder::AddToGlobal(global); |
| 213 Path2D::AddToGlobal(global); | 218 Path2D::AddToGlobal(global); |
| 214 | 219 |
| 215 if (!global->parseScript(script)) { | 220 if (!global->parseScript(script)) { |
| 216 printf("Failed to parse file: %s.\n", FLAGS_infile[0]); | 221 printf("Failed to parse file: %s.\n", FLAGS_infile[0]); |
| 217 exit(1); | 222 exit(1); |
| 218 } | 223 } |
| 219 | 224 |
| 220 | 225 |
| 221 JsContext* jsContext = new JsContext(global); | 226 JsContext* jsContext = new JsContext(global); |
| 222 | 227 |
| 223 if (!jsContext->initialize()) { | 228 if (!jsContext->initialize()) { |
| 224 printf("Failed to initialize.\n"); | 229 printf("Failed to initialize.\n"); |
| 225 exit(1); | 230 exit(1); |
| 226 } | 231 } |
| 227 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); | 232 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); |
| 228 global->setWindow(win); | 233 global->setWindow(win); |
| 229 | 234 |
| 230 return win; | 235 return win; |
| 231 } | 236 } |
| OLD | NEW |