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

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

Issue 13345002: Cleaned up OpenGLUI samples and added Blasteroids. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 int setup_flag)
28 : surface_(surface), 29 : surface_(surface),
29 isolate_(NULL), 30 isolate_(NULL),
30 initialized_script_(false), 31 initialized_script_(false),
31 x_(0.0), 32 x_(0.0),
32 y_(0.0), 33 y_(0.0),
33 z_(0.0), 34 z_(0.0),
34 accelerometer_changed_(false) { 35 accelerometer_changed_(false),
36 setup_flag_(setup_flag) {
35 LOGI("Creating VMGlue"); 37 LOGI("Creating VMGlue");
36 if (main_script == NULL) { 38 if (main_script == NULL) {
37 main_script = "main.dart"; 39 main_script = "main.dart";
38 } 40 }
39 if (extension_script == NULL) { 41 if (extension_script == NULL) {
40 extension_script = "gl.dart"; 42 extension_script = "gl.dart";
41 } 43 }
42 size_t len = strlen(script_path) + strlen(main_script) + 2; 44 size_t len = strlen(script_path) + strlen(main_script) + 2;
43 main_script_ = new char[len]; 45 main_script_ = new char[len];
44 snprintf(main_script_, len, "%s/%s", script_path, main_script); 46 snprintf(main_script_, len, "%s/%s", script_path, main_script);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 Dart_ExitScope(); 202 Dart_ExitScope();
201 Dart_ExitIsolate(); 203 Dart_ExitIsolate();
202 return 0; 204 return 0;
203 } 205 }
204 206
205 int VMGlue::CallSetup(bool force) { 207 int VMGlue::CallSetup(bool force) {
206 // TODO(gram): See if we actually need this flag guard here, or if 208 // TODO(gram): See if we actually need this flag guard here, or if
207 // we can eliminate it along with the need for the force parameter. 209 // we can eliminate it along with the need for the force parameter.
208 if (!initialized_script_ || force) { 210 if (!initialized_script_ || force) {
209 initialized_script_ = true; 211 initialized_script_ = true;
210 LOGI("Invoking setup(NULL, %d,%d)", surface_->width(), surface_->height()); 212 LOGI("Invoking setup(null, %d,%d,%d)",
213 surface_->width(), surface_->height(), setup_flag_);
211 Dart_EnterIsolate(isolate_); 214 Dart_EnterIsolate(isolate_);
212 Dart_EnterScope(); 215 Dart_EnterScope();
213 Dart_Handle args[3]; 216 Dart_Handle args[4];
214 args[0] = CheckError(Dart_Null()); 217 args[0] = CheckError(Dart_Null());
215 args[1] = CheckError(Dart_NewInteger(surface_->width())); 218 args[1] = CheckError(Dart_NewInteger(surface_->width()));
216 args[2] = CheckError(Dart_NewInteger(surface_->height())); 219 args[2] = CheckError(Dart_NewInteger(surface_->height()));
217 int rtn = Invoke("setup", 3, args); 220 args[3] = CheckError(Dart_NewInteger(setup_flag_));
221 int rtn = Invoke("setup", 4, args);
218 222
219 if (rtn == 0) { 223 if (rtn == 0) {
220 // Plug in the print handler. It would be nice if we could do this 224 // Plug in the print handler. It would be nice if we could do this
221 // before calling setup, but the call to GetField blows up if we 225 // before calling setup, but the call to GetField blows up if we
222 // haven't run anything yet. 226 // haven't run anything yet.
223 Dart_Handle library = CheckError(Dart_LookupLibrary( 227 Dart_Handle library = CheckError(Dart_LookupLibrary(
224 Dart_NewStringFromCString("gl.dart"))); 228 Dart_NewStringFromCString("gl.dart")));
225 Dart_Handle print = CheckError( 229 Dart_Handle print = CheckError(
226 Dart_GetField(library, Dart_NewStringFromCString("_printClosure"))); 230 Dart_GetField(library, Dart_NewStringFromCString("_printClosure")));
227 Dart_Handle corelib = CheckError(Dart_LookupLibrary( 231 Dart_Handle corelib = CheckError(Dart_LookupLibrary(
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 357
354 void VMGlue::FinishMainIsolate() { 358 void VMGlue::FinishMainIsolate() {
355 LOGI("Finish main isolate"); 359 LOGI("Finish main isolate");
356 Dart_EnterIsolate(isolate_); 360 Dart_EnterIsolate(isolate_);
357 // Shutdown the isolate. 361 // Shutdown the isolate.
358 Dart_ShutdownIsolate(); 362 Dart_ShutdownIsolate();
359 isolate_ = NULL; 363 isolate_ = NULL;
360 initialized_script_ = false; 364 initialized_script_ = false;
361 } 365 }
362 366
OLDNEW
« no previous file with comments | « runtime/embedders/openglui/common/vm_glue.h ('k') | runtime/embedders/openglui/emulator/emulator_embedder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698