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

Side by Side Diff: runtime/embedders/openglui/common/vm_glue.cc

Issue 13042015: Various OpenGLUI changes: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <math.h> 5 #include <math.h>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 12
13 #include "embedders/openglui/common/extension.h" 13 #include "embedders/openglui/common/extension.h"
14 #include "embedders/openglui/common/log.h" 14 #include "embedders/openglui/common/log.h"
15 #include "embedders/openglui/common/vm_glue.h" 15 #include "embedders/openglui/common/vm_glue.h"
16 #include "include/dart_api.h" 16 #include "include/dart_api.h"
17 17
18 char* VMGlue::extension_script_ = NULL; 18 char* VMGlue::extension_script_ = NULL;
19 bool VMGlue::initialized_vm_ = false; 19 bool VMGlue::initialized_vm_ = false;
20 20
21 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise 21 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise
22 // it is initialized to NULL. 22 // it is initialized to NULL.
23 23
24 VMGlue::VMGlue(ISized* surface, 24 VMGlue::VMGlue(ISized* surface,
25 const char* script_path, 25 const char* script_path,
26 const char* extension_script, 26 const char* extension_script,
27 const char* main_script) 27 const char* main_script)
28 : surface_(surface), 28 : surface_(surface),
29 isolate_(NULL), 29 isolate_(NULL),
30 initialized_script_(false) { 30 initialized_script_(false),
31 x_(0.0),
32 y_(0.0),
33 z_(0.0),
34 accelerometer_changed_(false) {
31 LOGI("Creating VMGlue"); 35 LOGI("Creating VMGlue");
32 if (main_script == NULL) { 36 if (main_script == NULL) {
33 main_script = "main.dart"; 37 main_script = "main.dart";
34 } 38 }
35 if (extension_script == NULL) { 39 if (extension_script == NULL) {
36 extension_script = "gl.dart"; 40 extension_script = "gl.dart";
37 } 41 }
38 size_t len = strlen(script_path) + strlen(main_script) + 2; 42 size_t len = strlen(script_path) + strlen(main_script) + 2;
39 main_script_ = new char[len]; 43 main_script_ = new char[len];
40 snprintf(main_script_, len, "%s/%s", script_path, main_script); 44 snprintf(main_script_, len, "%s/%s", script_path, main_script);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 Dart_ExitScope(); 232 Dart_ExitScope();
229 Dart_ExitIsolate(); 233 Dart_ExitIsolate();
230 LOGI("Done setup"); 234 LOGI("Done setup");
231 return rtn; 235 return rtn;
232 } 236 }
233 return 0; 237 return 0;
234 } 238 }
235 239
236 int VMGlue::CallUpdate() { 240 int VMGlue::CallUpdate() {
237 if (initialized_script_) { 241 if (initialized_script_) {
242 // If the accelerometer has changed, first do that
243 // event.
238 Dart_EnterIsolate(isolate_); 244 Dart_EnterIsolate(isolate_);
245 if (accelerometer_changed_) {
246 Dart_Handle args[3];
247 LOGI("Invoking onAccelerometer(%f,%f,%f)", x_, y_, z_);
248 Dart_EnterScope();
249 args[0] = CheckError(Dart_NewDouble(x_));
250 args[1] = CheckError(Dart_NewDouble(y_));
251 args[2] = CheckError(Dart_NewDouble(z_));
252 Invoke("onAccelerometer", 3, args, false);
253 Dart_ExitScope();
254 accelerometer_changed_ = false;
255 }
239 Dart_EnterScope(); 256 Dart_EnterScope();
240 int rtn = Invoke("update_", 0, 0); 257 int rtn = Invoke("update_", 0, 0);
241 Dart_ExitScope(); 258 Dart_ExitScope();
242 Dart_ExitIsolate(); 259 Dart_ExitIsolate();
260 LOGI("Invoke update_ returns %d", rtn);
243 return rtn; 261 return rtn;
244 } 262 }
245 return -1; 263 return -1;
246 } 264 }
247 265
248 int VMGlue::CallShutdown() { 266 int VMGlue::CallShutdown() {
249 if (initialized_script_) { 267 if (initialized_script_) {
250 Dart_EnterIsolate(isolate_); 268 Dart_EnterIsolate(isolate_);
251 Dart_EnterScope(); 269 Dart_EnterScope();
252 int rtn = Invoke("shutdown", 0, 0); 270 int rtn = Invoke("shutdown", 0, 0);
(...skipping 20 matching lines...) Expand all
273 LOGI("Done %s", pFunction); 291 LOGI("Done %s", pFunction);
274 return rtn; 292 return rtn;
275 } 293 }
276 return -1; 294 return -1;
277 } 295 }
278 296
279 int VMGlue::OnKeyEvent(const char* function, int64_t when, int32_t key_code, 297 int VMGlue::OnKeyEvent(const char* function, int64_t when, int32_t key_code,
280 bool isAltKeyDown, bool isCtrlKeyDown, 298 bool isAltKeyDown, bool isCtrlKeyDown,
281 bool isShiftKeyDown, int32_t repeat) { 299 bool isShiftKeyDown, int32_t repeat) {
282 if (initialized_script_) { 300 if (initialized_script_) {
283 LOGI("Invoking %s", function); 301 LOGI("Invoking %s(_,%d,...)", function, key_code);
284 Dart_EnterIsolate(isolate_); 302 Dart_EnterIsolate(isolate_);
285 Dart_EnterScope(); 303 Dart_EnterScope();
286 Dart_Handle args[6]; 304 Dart_Handle args[6];
287 args[0] = CheckError(Dart_NewInteger(when)); 305 args[0] = CheckError(Dart_NewInteger(when));
288 args[1] = CheckError(Dart_NewInteger(key_code)); 306 args[1] = CheckError(Dart_NewInteger(key_code));
289 args[2] = CheckError(Dart_NewBoolean(isAltKeyDown)); 307 args[2] = CheckError(Dart_NewBoolean(isAltKeyDown));
290 args[3] = CheckError(Dart_NewBoolean(isCtrlKeyDown)); 308 args[3] = CheckError(Dart_NewBoolean(isCtrlKeyDown));
291 args[4] = CheckError(Dart_NewBoolean(isShiftKeyDown)); 309 args[4] = CheckError(Dart_NewBoolean(isShiftKeyDown));
292 args[5] = CheckError(Dart_NewInteger(repeat)); 310 args[5] = CheckError(Dart_NewInteger(repeat));
293 int rtn = Invoke(function, 6, args, false); 311 int rtn = Invoke(function, 6, args, false);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 353
336 void VMGlue::FinishMainIsolate() { 354 void VMGlue::FinishMainIsolate() {
337 LOGI("Finish main isolate"); 355 LOGI("Finish main isolate");
338 Dart_EnterIsolate(isolate_); 356 Dart_EnterIsolate(isolate_);
339 // Shutdown the isolate. 357 // Shutdown the isolate.
340 Dart_ShutdownIsolate(); 358 Dart_ShutdownIsolate();
341 isolate_ = NULL; 359 isolate_ = NULL;
342 initialized_script_ = false; 360 initialized_script_ = false;
343 } 361 }
344 362
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698