diff options
author | 2013-12-18 04:45:37 +0000 | |
---|---|---|
committer | 2013-12-18 04:45:37 +0000 | |
commit | 0fc0dea333f313a579558beb7ba498db0711780e (patch) | |
tree | 02bbfa9462cbe17476c7f06e594a9db8a8c8652c /experimental/SkV8Example/Global.h | |
parent | 4e8f1e56b17c3663d1892f44a4c1893b568ce67f (diff) |
Add a setTimer() function.
Seemed simple, but required adding a Global class that contains all the global state (instance and context) for our running V8 instance. Also moved canvas.inval to be just inval() at the global level.
BUG=
R=robertphillips@google.com
Author: jcgregorio@google.com
Review URL: https://codereview.chromium.org/103143009
git-svn-id: http://skia.googlecode.com/svn/trunk@12730 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/SkV8Example/Global.h')
-rw-r--r-- | experimental/SkV8Example/Global.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/experimental/SkV8Example/Global.h b/experimental/SkV8Example/Global.h new file mode 100644 index 0000000000..aa05b01aaf --- /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 |