| OLD | NEW |
| 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> |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 Dart_Handle url = CheckError(Dart_NewStringFromCString(main_script_)); | 192 Dart_Handle url = CheckError(Dart_NewStringFromCString(main_script_)); |
| 193 Dart_Handle source = LoadSourceFromFile(main_script_); | 193 Dart_Handle source = LoadSourceFromFile(main_script_); |
| 194 CheckError(Dart_LoadScript(url, source)); | 194 CheckError(Dart_LoadScript(url, source)); |
| 195 | 195 |
| 196 Dart_ExitScope(); | 196 Dart_ExitScope(); |
| 197 Dart_ExitIsolate(); | 197 Dart_ExitIsolate(); |
| 198 return 0; | 198 return 0; |
| 199 } | 199 } |
| 200 | 200 |
| 201 int VMGlue::CallSetup() { | 201 int VMGlue::CallSetup(bool force) { |
| 202 if (!initialized_script_) { | 202 // TODO(gram): See if we actually need this flag guard here, or if |
| 203 // we can eliminate it along with the need for the force parameter. |
| 204 if (!initialized_script_ || force) { |
| 203 initialized_script_ = true; | 205 initialized_script_ = true; |
| 204 LOGI("Invoking setup(NULL, %d,%d)", surface_->width(), surface_->height()); | 206 LOGI("Invoking setup(NULL, %d,%d)", surface_->width(), surface_->height()); |
| 205 Dart_EnterIsolate(isolate_); | 207 Dart_EnterIsolate(isolate_); |
| 206 Dart_EnterScope(); | 208 Dart_EnterScope(); |
| 207 Dart_Handle args[3]; | 209 Dart_Handle args[3]; |
| 208 args[0] = CheckError(Dart_Null()); | 210 args[0] = CheckError(Dart_Null()); |
| 209 args[1] = CheckError(Dart_NewInteger(surface_->width())); | 211 args[1] = CheckError(Dart_NewInteger(surface_->width())); |
| 210 args[2] = CheckError(Dart_NewInteger(surface_->height())); | 212 args[2] = CheckError(Dart_NewInteger(surface_->height())); |
| 211 int rtn = Invoke("setup", 3, args); | 213 int rtn = Invoke("setup", 3, args); |
| 212 | 214 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 226 Dart_ExitScope(); | 228 Dart_ExitScope(); |
| 227 Dart_ExitIsolate(); | 229 Dart_ExitIsolate(); |
| 228 LOGI("Done setup"); | 230 LOGI("Done setup"); |
| 229 return rtn; | 231 return rtn; |
| 230 } | 232 } |
| 231 return 0; | 233 return 0; |
| 232 } | 234 } |
| 233 | 235 |
| 234 int VMGlue::CallUpdate() { | 236 int VMGlue::CallUpdate() { |
| 235 if (initialized_script_) { | 237 if (initialized_script_) { |
| 236 LOGI("Invoking update"); | |
| 237 Dart_EnterIsolate(isolate_); | 238 Dart_EnterIsolate(isolate_); |
| 238 Dart_EnterScope(); | 239 Dart_EnterScope(); |
| 239 int rtn = Invoke("update", 0, 0); | 240 int rtn = Invoke("update", 0, 0); |
| 240 Dart_ExitScope(); | 241 Dart_ExitScope(); |
| 241 Dart_ExitIsolate(); | 242 Dart_ExitIsolate(); |
| 242 LOGI("Done update"); | 243 return rtn; |
| 244 } |
| 245 return -1; |
| 246 } |
| 247 |
| 248 int VMGlue::CallShutdown() { |
| 249 if (initialized_script_) { |
| 250 Dart_EnterIsolate(isolate_); |
| 251 Dart_EnterScope(); |
| 252 int rtn = Invoke("shutdown", 0, 0); |
| 253 Dart_ExitScope(); |
| 254 Dart_ExitIsolate(); |
| 243 return rtn; | 255 return rtn; |
| 244 } | 256 } |
| 245 return -1; | 257 return -1; |
| 246 } | 258 } |
| 247 | 259 |
| 248 int VMGlue::OnMotionEvent(const char* pFunction, int64_t pWhen, | 260 int VMGlue::OnMotionEvent(const char* pFunction, int64_t pWhen, |
| 249 float pMoveX, float pMoveY) { | 261 float pMoveX, float pMoveY) { |
| 250 if (initialized_script_) { | 262 if (initialized_script_) { |
| 251 LOGI("Invoking %s", pFunction); | 263 LOGI("Invoking %s", pFunction); |
| 252 Dart_EnterIsolate(isolate_); | 264 Dart_EnterIsolate(isolate_); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 282 LOGI("Done %s", function); | 294 LOGI("Done %s", function); |
| 283 return rtn; | 295 return rtn; |
| 284 } | 296 } |
| 285 return -1; | 297 return -1; |
| 286 } | 298 } |
| 287 | 299 |
| 288 int VMGlue::Invoke(const char* function, | 300 int VMGlue::Invoke(const char* function, |
| 289 int argc, | 301 int argc, |
| 290 Dart_Handle* args, | 302 Dart_Handle* args, |
| 291 bool failIfNotDefined) { | 303 bool failIfNotDefined) { |
| 292 LOGI("in invoke(%s)", function); | |
| 293 | |
| 294 // Lookup the library of the root script. | 304 // Lookup the library of the root script. |
| 295 LOGI("looking up the root library"); | |
| 296 Dart_Handle library = Dart_RootLibrary(); | 305 Dart_Handle library = Dart_RootLibrary(); |
| 297 if (Dart_IsNull(library)) { | 306 if (Dart_IsNull(library)) { |
| 298 LOGE("Unable to find root library\n"); | 307 LOGE("Unable to find root library\n"); |
| 299 return -1; | 308 return -1; |
| 300 } | 309 } |
| 301 | 310 |
| 302 Dart_Handle nameHandle = Dart_NewStringFromCString(function); | 311 Dart_Handle nameHandle = Dart_NewStringFromCString(function); |
| 303 | 312 |
| 304 LOGI("invoking %s", function); | |
| 305 Dart_Handle result = Dart_Invoke(library, nameHandle, argc, args); | 313 Dart_Handle result = Dart_Invoke(library, nameHandle, argc, args); |
| 306 | 314 |
| 307 if (Dart_IsError(result)) { | 315 if (Dart_IsError(result)) { |
| 308 const char* error = Dart_GetError(result); | 316 const char* error = Dart_GetError(result); |
| 309 LOGE("Invoke %s failed: %s", function, error); | 317 LOGE("Invoke %s failed: %s", function, error); |
| 310 if (failIfNotDefined) { | 318 if (failIfNotDefined) { |
| 311 return -1; | 319 return -1; |
| 312 } | 320 } |
| 313 } | 321 } |
| 314 | 322 |
| 315 // TODO(vsm): I don't think we need this. | 323 // TODO(vsm): I don't think we need this. |
| 316 // Keep handling messages until the last active receive port is closed. | 324 // Keep handling messages until the last active receive port is closed. |
| 317 LOGI("Entering Dart message loop"); | |
| 318 result = Dart_RunLoop(); | 325 result = Dart_RunLoop(); |
| 319 if (Dart_IsError(result)) { | 326 if (Dart_IsError(result)) { |
| 320 LOGE("Dart_RunLoop: %s\n", Dart_GetError(result)); | 327 LOGE("Dart_RunLoop: %s\n", Dart_GetError(result)); |
| 321 return -1; | 328 return -1; |
| 322 } | 329 } |
| 323 | 330 |
| 324 LOGI("out invoke"); | |
| 325 return 0; | 331 return 0; |
| 326 } | 332 } |
| 327 | 333 |
| 328 void VMGlue::FinishMainIsolate() { | 334 void VMGlue::FinishMainIsolate() { |
| 329 LOGI("Finish main isolate"); | 335 LOGI("Finish main isolate"); |
| 330 Dart_EnterIsolate(isolate_); | 336 Dart_EnterIsolate(isolate_); |
| 331 // Shutdown the isolate. | 337 // Shutdown the isolate. |
| 332 Dart_ShutdownIsolate(); | 338 Dart_ShutdownIsolate(); |
| 333 isolate_ = NULL; | 339 isolate_ = NULL; |
| 334 initialized_script_ = false; | 340 initialized_script_ = false; |
| 335 } | 341 } |
| 336 | 342 |
| OLD | NEW |