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

Unified Diff: experimental/SkV8Example/SkV8Example.cpp

Issue 93933005: V8 and Skia (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: no v8 in .h Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/SkV8Example/SkV8Example.h ('k') | gyp/everything.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/SkV8Example.cpp
===================================================================
--- experimental/SkV8Example/SkV8Example.cpp (revision 0)
+++ experimental/SkV8Example/SkV8Example.cpp (revision 0)
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ */
+#include <v8.h>
+
+using namespace v8;
+
+#include "SkV8Example.h"
+
+#include "gl/GrGLUtil.h"
+#include "gl/GrGLDefines.h"
+#include "gl/GrGLInterface.h"
+#include "SkApplication.h"
+#include "SkDraw.h"
+#include "SkGpuDevice.h"
+#include "SkGraphics.h"
+
+
+void application_init() {
+ SkGraphics::Init();
+ SkEvent::Init();
+}
+
+void application_term() {
+ SkEvent::Term();
+ SkGraphics::Term();
+}
+
+SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd)
+ : INHERITED(hwnd) {
+
+ this->setConfig(SkBitmap::kARGB_8888_Config);
+ this->setVisibleP(true);
+ this->setClipToBounds(false);
+}
+
+
+void SkV8ExampleWindow::onDraw(SkCanvas* canvas) {
+ printf("Draw\n");
+
+ canvas->drawColor(SK_ColorWHITE);
+ SkPaint paint;
+ paint.setColor(SK_ColorRED);
+
+ // Draw a rectangle with blue paint
+ SkRect rect = {
+ SkIntToScalar(10), SkIntToScalar(10),
+ SkIntToScalar(128), SkIntToScalar(128)
+ };
+ canvas->drawRect(rect, paint);
+
+ INHERITED::onDraw(canvas);
+}
+
+#ifdef SK_BUILD_FOR_WIN
+void SkV8ExampleWindow::onHandleInval(const SkIRect& rect) {
+ RECT winRect;
+ winRect.top = rect.top();
+ winRect.bottom = rect.bottom();
+ winRect.right = rect.right();
+ winRect.left = rect.left();
+ InvalidateRect((HWND)this->getHWND(), &winRect, false);
+}
+#endif
+
+
+SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
+ printf("Started\n");
+
+ // Get the default Isolate created at startup.
+ Isolate* isolate = Isolate::GetCurrent();
+
+ // Create a stack-allocated handle scope.
+ HandleScope handle_scope(isolate);
+
+ // Create a new context.
+ Handle<Context> context = Context::New(isolate);
+
+ // Here's how you could create a Persistent handle to the context, if needed.
+ Persistent<Context> persistent_context(isolate, context);
+
+ // Enter the created context for compiling and
+ // running the hello world script.
+ Context::Scope context_scope(context);
+
+ // Create a string containing the JavaScript source code.
+ Handle<String> source = String::New("'Hello' + ', World!'");
+
+ // Compile the source code.
+ Handle<Script> script = Script::Compile(source);
+
+ // Run the script to get the result.
+ Handle<Value> result = script->Run();
+
+ // The persistent handle needs to be eventually disposed.
+ persistent_context.Dispose();
+
+ // Convert the result to an ASCII string and print it.
+ String::AsciiValue ascii(result);
+ printf("%s\n", *ascii);
+
+ return new SkV8ExampleWindow(hwnd);
+}
« no previous file with comments | « experimental/SkV8Example/SkV8Example.h ('k') | gyp/everything.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698