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 | 10 #include <include/libplatform/libplatform.h> |
11 using namespace v8; | |
12 | 11 |
13 #include "SkV8Example.h" | 12 #include "SkV8Example.h" |
14 #include "Global.h" | 13 #include "Global.h" |
15 #include "JsContext.h" | 14 #include "JsContext.h" |
16 #include "Path2D.h" | 15 #include "Path2D.h" |
17 | 16 |
18 #include "gl/GrGLUtil.h" | 17 #include "gl/GrGLUtil.h" |
19 #include "gl/GrGLDefines.h" | 18 #include "gl/GrGLDefines.h" |
20 #include "gl/GrGLInterface.h" | 19 #include "gl/GrGLInterface.h" |
21 #include "GrRenderTarget.h" | 20 #include "GrRenderTarget.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 102 |
104 SkSafeUnref(fCurRenderTarget); | 103 SkSafeUnref(fCurRenderTarget); |
105 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc); | 104 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc); |
106 SkSafeUnref(fCurSurface); | 105 SkSafeUnref(fCurSurface); |
107 fCurSurface = SkSurface::NewRenderTargetDirect(fCurRenderTarget); | 106 fCurSurface = SkSurface::NewRenderTargetDirect(fCurRenderTarget); |
108 } | 107 } |
109 } | 108 } |
110 #endif | 109 #endif |
111 | 110 |
112 #if SK_SUPPORT_GPU | 111 #if SK_SUPPORT_GPU |
113 SkCanvas* SkV8ExampleWindow::createCanvas() { | 112 SkSurface* SkV8ExampleWindow::createSurface() { |
114 if (FLAGS_gpu) { | 113 if (FLAGS_gpu) { |
115 SkCanvas* c = fCurSurface->getCanvas(); | 114 // Increase the ref count since callers of createSurface put the |
116 // Increase the ref count since the surface keeps a reference | 115 // results in a SkAutoTUnref. |
117 // to the canvas, but callers of createCanvas put the results | 116 fCurSurface->ref(); |
118 // in a SkAutoTUnref. | 117 return fCurSurface; |
119 c->ref(); | |
120 return c; | |
121 } else { | 118 } else { |
122 return this->INHERITED::createCanvas(); | 119 return this->INHERITED::createSurface(); |
123 } | 120 } |
124 } | 121 } |
125 #endif | 122 #endif |
126 | 123 |
127 void SkV8ExampleWindow::onSizeChange() { | 124 void SkV8ExampleWindow::onSizeChange() { |
128 this->INHERITED::onSizeChange(); | 125 this->INHERITED::onSizeChange(); |
129 | 126 |
130 #if SK_SUPPORT_GPU | 127 #if SK_SUPPORT_GPU |
131 this->windowSizeChanged(); | 128 this->windowSizeChanged(); |
132 #endif | 129 #endif |
(...skipping 23 matching lines...) Expand all Loading... |
156 void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) { | 153 void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) { |
157 RECT winRect; | 154 RECT winRect; |
158 winRect.top = rect.top(); | 155 winRect.top = rect.top(); |
159 winRect.bottom = rect.bottom(); | 156 winRect.bottom = rect.bottom(); |
160 winRect.right = rect.right(); | 157 winRect.right = rect.right(); |
161 winRect.left = rect.left(); | 158 winRect.left = rect.left(); |
162 InvalidateRect((HWND)this->getHWND(), &winRect, false); | 159 InvalidateRect((HWND)this->getHWND(), &winRect, false); |
163 } | 160 } |
164 #endif | 161 #endif |
165 | 162 |
| 163 |
166 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { | 164 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { |
167 printf("Started\n"); | 165 printf("Started\n"); |
168 | 166 |
169 SkCommandLineFlags::Parse(argc, argv); | 167 SkCommandLineFlags::Parse(argc, argv); |
170 | 168 |
171 // Get the default Isolate created at startup. | 169 v8::V8::InitializeICU(); |
172 Isolate* isolate = Isolate::GetCurrent(); | 170 v8::Platform* platform = v8::platform::CreateDefaultPlatform(); |
| 171 v8::V8::InitializePlatform(platform); |
| 172 v8::V8::Initialize(); |
| 173 |
| 174 v8::Isolate* isolate = v8::Isolate::New(); |
| 175 v8::Isolate::Scope isolate_scope(isolate); |
| 176 v8::HandleScope handle_scope(isolate); |
| 177 isolate->Enter(); |
| 178 |
173 Global* global = new Global(isolate); | 179 Global* global = new Global(isolate); |
174 | 180 |
175 | 181 |
176 // Set up things to look like a browser by creating | 182 // Set up things to look like a browser by creating |
177 // a console object that invokes our print function. | 183 // a console object that invokes our print function. |
178 const char* startupScript = | 184 const char* startupScript = |
179 "function Console() {}; \n" | 185 "function Console() {}; \n" |
180 "Console.prototype.log = function() { \n" | 186 "Console.prototype.log = function() { \n" |
181 " var args = Array.prototype.slice.call(arguments).join(' '); \n" | 187 " var args = Array.prototype.slice.call(arguments).join(' '); \n" |
182 " print(args); \n" | 188 " print(args); \n" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 222 |
217 if (!jsContext->initialize()) { | 223 if (!jsContext->initialize()) { |
218 printf("Failed to initialize.\n"); | 224 printf("Failed to initialize.\n"); |
219 exit(1); | 225 exit(1); |
220 } | 226 } |
221 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); | 227 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); |
222 global->setWindow(win); | 228 global->setWindow(win); |
223 | 229 |
224 return win; | 230 return win; |
225 } | 231 } |
OLD | NEW |