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

Unified Diff: experimental/SkV8Example/Global.h

Issue 103143009: Add a setTimer() function. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | experimental/SkV8Example/Global.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/SkV8Example/Global.h
diff --git a/experimental/SkV8Example/Global.h b/experimental/SkV8Example/Global.h
new file mode 100644
index 0000000000000000000000000000000000000000..aa05b01aaf8c806452003816696137be7bed6557
--- /dev/null
+++ b/experimental/SkV8Example/Global.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ */
+
+#ifndef SkV8Example_Global_DEFINED
+#define SkV8Example_Global_DEFINED
+
+#include <v8.h>
+
+using namespace v8;
+
+#include "SkTypes.h"
+#include "SkEvent.h"
+
+class SkOSWindow;
+
+// Provides the global isolate and context for our V8 instance.
+// Also implements all the global level functions.
+class Global : SkNoncopyable {
+public:
+ Global(Isolate* isolate)
+ : fIsolate(isolate)
+ , fWindow(NULL)
+ {
+ gGlobal = this;
+ }
+ virtual ~Global() {}
+
+ // The script will be parsed into the context this Global contains.
+ bool parseScript(const char script[]);
+
+ Local<Context> getContext() {
+ return Local<Context>::New(fIsolate, fContext);
+ }
+
+ Isolate* getIsolate() {
+ return fIsolate;
+ }
+
+ void setWindow(SkOSWindow* win) {
+ fWindow = win;
+ }
+ SkOSWindow* getWindow() {
+ return fWindow;
+ }
+
+ void reportException(TryCatch* tryCatch);
+
+private:
+ Handle<Context> createRootContext();
+
+ static bool TimeOutProc(const SkEvent& evt);
+
+ // Static functions that implement the global JS functions we add to
+ // the context.
+ static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
+ static void Inval(const v8::FunctionCallbackInfo<Value>& args);
+
+ Persistent<Context> fContext;
+ Isolate* fIsolate;
+ SkOSWindow* fWindow;
+ static Global* gGlobal;
+
+ // Handle to the function to call when the timeout triggers.
+ Persistent<Function> fTimeout;
+};
+
+#endif
« no previous file with comments | « no previous file | experimental/SkV8Example/Global.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698