| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #ifndef EMBEDDERS_OPENGLUI_COMMON_VM_GLUE_H_ | |
| 6 #define EMBEDDERS_OPENGLUI_COMMON_VM_GLUE_H_ | |
| 7 | |
| 8 #include <stdlib.h> | |
| 9 | |
| 10 #include "embedders/openglui/common/events.h" | |
| 11 #include "embedders/openglui/common/isized.h" | |
| 12 #include "include/dart_api.h" | |
| 13 | |
| 14 class VMGlue { | |
| 15 public: | |
| 16 explicit VMGlue(ISized* surface, | |
| 17 const char* script_path, | |
| 18 const char* extension_script = NULL, | |
| 19 const char* main_script = NULL, | |
| 20 int setup_flag = 0); | |
| 21 ~VMGlue() { | |
| 22 delete[] main_script_; | |
| 23 delete[] extension_script_; | |
| 24 } | |
| 25 | |
| 26 int InitializeVM(); | |
| 27 int StartMainIsolate(); | |
| 28 int CallSetup(bool force = false); | |
| 29 int CallUpdate(); | |
| 30 int CallShutdown(); | |
| 31 int OnMotionEvent(const char* funtion, int64_t when, | |
| 32 float move_x, float move_y); | |
| 33 int OnKeyEvent(const char* funtion, int64_t when, int32_t key_code, | |
| 34 bool isAltKeyDown, bool isCtrlKeyDown, bool isShiftKeyDown, | |
| 35 int32_t repeat); | |
| 36 inline void OnAccelerometerEvent(float x, float y, float z) { | |
| 37 if (x != x_ || y != y_ || z != z_) { | |
| 38 x_ = x; | |
| 39 y_ = y; | |
| 40 z_ = z; | |
| 41 accelerometer_changed_ = true; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 void FinishMainIsolate(); | |
| 46 | |
| 47 private: | |
| 48 int Invoke(const char *function, int argc, Dart_Handle* args, | |
| 49 bool failIfNotDefined = true); | |
| 50 | |
| 51 static Dart_Handle CheckError(Dart_Handle); | |
| 52 | |
| 53 static Dart_Isolate CreateIsolateAndSetupHelper(const char* script_uri, | |
| 54 const char* main, | |
| 55 void* data, | |
| 56 char** error); | |
| 57 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | |
| 58 const char* main, | |
| 59 void* data, char** error); | |
| 60 static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, | |
| 61 Dart_Handle library, | |
| 62 Dart_Handle urlHandle); | |
| 63 static Dart_Handle LoadSourceFromFile(const char* url); | |
| 64 static void ShutdownIsolate(void* callback_data); | |
| 65 | |
| 66 static bool initialized_vm_; | |
| 67 static char* extension_script_; | |
| 68 ISized* surface_; | |
| 69 Dart_Isolate isolate_; | |
| 70 bool initialized_script_; | |
| 71 char* main_script_; | |
| 72 float x_, y_, z_; // Last values from accelerometer. | |
| 73 bool accelerometer_changed_; | |
| 74 int setup_flag_; | |
| 75 }; | |
| 76 | |
| 77 #endif // EMBEDDERS_OPENGLUI_COMMON_VM_GLUE_H_ | |
| 78 | |
| OLD | NEW |