| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 /* | 
|  | 2  * Copyright 2013 Google Inc. | 
|  | 3  * | 
|  | 4  * | 
|  | 5  * Use of this source code is governed by a BSD-style license that can be | 
|  | 6  * found in the LICENSE file. | 
|  | 7  * | 
|  | 8  */ | 
|  | 9 #include <v8.h> | 
|  | 10 | 
|  | 11 using namespace v8; | 
|  | 12 | 
|  | 13 #include "SkV8Example.h" | 
|  | 14 | 
|  | 15 #include "gl/GrGLUtil.h" | 
|  | 16 #include "gl/GrGLDefines.h" | 
|  | 17 #include "gl/GrGLInterface.h" | 
|  | 18 #include "SkApplication.h" | 
|  | 19 #include "SkDraw.h" | 
|  | 20 #include "SkGpuDevice.h" | 
|  | 21 #include "SkGraphics.h" | 
|  | 22 | 
|  | 23 | 
|  | 24 void application_init() { | 
|  | 25     SkGraphics::Init(); | 
|  | 26     SkEvent::Init(); | 
|  | 27 } | 
|  | 28 | 
|  | 29 void application_term() { | 
|  | 30     SkEvent::Term(); | 
|  | 31     SkGraphics::Term(); | 
|  | 32 } | 
|  | 33 | 
|  | 34 SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd) | 
|  | 35     : INHERITED(hwnd) { | 
|  | 36 | 
|  | 37     this->setConfig(SkBitmap::kARGB_8888_Config); | 
|  | 38     this->setVisibleP(true); | 
|  | 39     this->setClipToBounds(false); | 
|  | 40 } | 
|  | 41 | 
|  | 42 | 
|  | 43 void SkV8ExampleWindow::onDraw(SkCanvas* canvas) { | 
|  | 44   printf("Draw\n"); | 
|  | 45 | 
|  | 46   canvas->drawColor(SK_ColorWHITE); | 
|  | 47   SkPaint paint; | 
|  | 48   paint.setColor(SK_ColorRED); | 
|  | 49 | 
|  | 50   // Draw a rectangle with blue paint | 
|  | 51   SkRect rect = { | 
|  | 52     SkIntToScalar(10), SkIntToScalar(10), | 
|  | 53     SkIntToScalar(128), SkIntToScalar(128) | 
|  | 54   }; | 
|  | 55   canvas->drawRect(rect, paint); | 
|  | 56 | 
|  | 57   INHERITED::onDraw(canvas); | 
|  | 58 } | 
|  | 59 | 
|  | 60 #ifdef SK_BUILD_FOR_WIN | 
|  | 61 void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) { | 
|  | 62     RECT winRect; | 
|  | 63     winRect.top = rect.top(); | 
|  | 64     winRect.bottom = rect.bottom(); | 
|  | 65     winRect.right = rect.right(); | 
|  | 66     winRect.left = rect.left(); | 
|  | 67     InvalidateRect((HWND)this->getHWND(), &winRect, false); | 
|  | 68 } | 
|  | 69 #endif | 
|  | 70 | 
|  | 71 | 
|  | 72 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { | 
|  | 73   printf("Started\n"); | 
|  | 74 | 
|  | 75   // Get the default Isolate created at startup. | 
|  | 76   Isolate* isolate = Isolate::GetCurrent(); | 
|  | 77 | 
|  | 78   // Create a stack-allocated handle scope. | 
|  | 79   HandleScope handle_scope(isolate); | 
|  | 80 | 
|  | 81   // Create a new context. | 
|  | 82   Handle<Context> context = Context::New(isolate); | 
|  | 83 | 
|  | 84   // Here's how you could create a Persistent handle to the context, if needed. | 
|  | 85   Persistent<Context> persistent_context(isolate, context); | 
|  | 86 | 
|  | 87   // Enter the created context for compiling and | 
|  | 88   // running the hello world script. | 
|  | 89   Context::Scope context_scope(context); | 
|  | 90 | 
|  | 91   // Create a string containing the JavaScript source code. | 
|  | 92   Handle<String> source = String::New("'Hello' + ', World!'"); | 
|  | 93 | 
|  | 94   // Compile the source code. | 
|  | 95   Handle<Script> script = Script::Compile(source); | 
|  | 96 | 
|  | 97   // Run the script to get the result. | 
|  | 98   Handle<Value> result = script->Run(); | 
|  | 99 | 
|  | 100   // The persistent handle needs to be eventually disposed. | 
|  | 101   persistent_context.Dispose(); | 
|  | 102 | 
|  | 103   // Convert the result to an ASCII string and print it. | 
|  | 104   String::AsciiValue ascii(result); | 
|  | 105   printf("%s\n", *ascii); | 
|  | 106 | 
|  | 107     return new SkV8ExampleWindow(hwnd); | 
|  | 108 } | 
| OLD | NEW | 
|---|