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

Side by Side Diff: experimental/SkV8Example/Global.h

Issue 118473006: Allow multiple concurrent timers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up 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 unified diff | Download patch
« no previous file with comments | « no previous file | experimental/SkV8Example/Global.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 #ifndef SkV8Example_Global_DEFINED 10 #ifndef SkV8Example_Global_DEFINED
11 #define SkV8Example_Global_DEFINED 11 #define SkV8Example_Global_DEFINED
12 12
robertphillips 2013/12/20 14:49:43 I'm not sure if we want to start using STL. Though
jcgregorio 2013/12/20 14:53:07 Yeah, I was hesitant on that, are there Sk* altern
13 #include <map>
14
13 #include <v8.h> 15 #include <v8.h>
14 16
15 using namespace v8; 17 using namespace v8;
16 18
17 #include "SkTypes.h" 19 #include "SkTypes.h"
18 #include "SkEvent.h" 20 #include "SkEvent.h"
19 21
20 class SkOSWindow; 22 class SkOSWindow;
21 23
24 typedef Persistent<Function, CopyablePersistentTraits<Function> > CopyablePersis tentFn;
25
22 // Provides the global isolate and context for our V8 instance. 26 // Provides the global isolate and context for our V8 instance.
23 // Also implements all the global level functions. 27 // Also implements all the global level functions.
24 class Global : SkNoncopyable { 28 class Global : SkNoncopyable {
25 public: 29 public:
26 Global(Isolate* isolate) 30 Global(Isolate* isolate)
27 : fIsolate(isolate) 31 : fIsolate(isolate)
28 , fWindow(NULL) 32 , fWindow(NULL)
33 , fLastTimerID(0)
29 { 34 {
30 gGlobal = this; 35 gGlobal = this;
31 } 36 }
32 virtual ~Global() {} 37 virtual ~Global() {}
33 38
34 // The script will be parsed into the context this Global contains. 39 // The script will be parsed into the context this Global contains.
35 bool parseScript(const char script[]); 40 bool parseScript(const char script[]);
36 41
37 Local<Context> getContext() { 42 Local<Context> getContext() {
38 return Local<Context>::New(fIsolate, fContext); 43 return Local<Context>::New(fIsolate, fContext);
39 } 44 }
40 45
41 Isolate* getIsolate() { 46 Isolate* getIsolate() {
42 return fIsolate; 47 return fIsolate;
43 } 48 }
44 49
45 void setWindow(SkOSWindow* win) { 50 void setWindow(SkOSWindow* win) {
46 fWindow = win; 51 fWindow = win;
47 } 52 }
48 SkOSWindow* getWindow() { 53 SkOSWindow* getWindow() {
49 return fWindow; 54 return fWindow;
50 } 55 }
51 56
52 void reportException(TryCatch* tryCatch); 57 void reportException(TryCatch* tryCatch);
53 58
54 private: 59 private:
55 Handle<Context> createRootContext(); 60 Handle<Context> createRootContext();
61 int32_t getNextTimerID();
56 62
57 static bool TimeOutProc(const SkEvent& evt); 63 static bool TimeOutProc(const SkEvent& evt);
58 64
59 // Static functions that implement the global JS functions we add to 65 // Static functions that implement the global JS functions we add to
60 // the context. 66 // the context.
61 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args); 67 static void SetTimeout(const v8::FunctionCallbackInfo<v8::Value>& args);
62 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args); 68 static void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
63 static void Inval(const v8::FunctionCallbackInfo<Value>& args); 69 static void Inval(const v8::FunctionCallbackInfo<Value>& args);
64 70
65 Persistent<Context> fContext; 71 Persistent<Context> fContext;
66 Isolate* fIsolate; 72 Isolate* fIsolate;
67 SkOSWindow* fWindow; 73 SkOSWindow* fWindow;
68 static Global* gGlobal; 74 static Global* gGlobal;
69 75
70 // Handle to the function to call when the timeout triggers. 76 // Handle to the functions to call when a timeout triggers as indexed by id.
71 Persistent<Function> fTimeout; 77 std::map<int32_t, CopyablePersistentFn > fTimeouts;
78
79 // Last timer ID generated.
80 int32_t fLastTimerID;
72 }; 81 };
73 82
74 #endif 83 #endif
OLDNEW
« 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