OLD | NEW |
(Empty) | |
| 1 #include "jni/dart_host.h" |
| 2 |
| 3 #include <math.h> |
| 4 #include <unistd.h> |
| 5 |
| 6 #include "bin/eventhandler.h" |
| 7 #include "bin/isolate_data.h" |
| 8 #include "bin/log.h" |
| 9 #include "bin/platform.h" |
| 10 #include "bin/process.h" |
| 11 #include "vm/flags.h" |
| 12 |
| 13 DartHost::DartHost(Context *context) |
| 14 : input_handler_(context->input_handler), |
| 15 timer_(context->timer), |
| 16 graphics_(context->graphics), |
| 17 vm_glue_(context->vm_glue), |
| 18 active_(false) { |
| 19 Log::Print("Creating DartHost"); |
| 20 } |
| 21 |
| 22 DartHost::~DartHost() { |
| 23 Log::Print("Freeing DartHost"); |
| 24 } |
| 25 |
| 26 int32_t DartHost::OnActivate() { |
| 27 return Activate(); |
| 28 } |
| 29 |
| 30 int32_t DartHost::Activate() { |
| 31 if (!active_) { |
| 32 Log::Print("Activating DartHost"); |
| 33 if (graphics_->Start() != 0) { |
| 34 return -1; |
| 35 } |
| 36 if (input_handler_->Start() != 0) { |
| 37 return -1; |
| 38 } |
| 39 timer_->reset(); |
| 40 Log::Print("Starting main isolate"); |
| 41 int result = vm_glue_->StartMainIsolate(); |
| 42 if (result != 0) { |
| 43 Log::PrintErr("startMainIsolate returned %d", result); |
| 44 return -1; |
| 45 } |
| 46 active_ = true; |
| 47 vm_glue_->CallSetup(); |
| 48 } |
| 49 return 0; |
| 50 } |
| 51 |
| 52 void DartHost::OnDeactivate() { |
| 53 Deactivate(); |
| 54 } |
| 55 |
| 56 void DartHost::Deactivate() { |
| 57 if (active_) { |
| 58 active_ = false; |
| 59 vm_glue_->FinishMainIsolate(); |
| 60 Log::Print("Deactivating DartHost"); |
| 61 graphics_->Stop(); |
| 62 } |
| 63 } |
| 64 |
| 65 int32_t DartHost::OnStep() { |
| 66 timer_->update(); |
| 67 vm_glue_->CallUpdate(); |
| 68 if (graphics_->Update() != 0) { |
| 69 return -1; |
| 70 } |
| 71 return 0; |
| 72 } |
| 73 |
| 74 void DartHost::OnStart() { |
| 75 Log::Print("Starting DartHost"); |
| 76 } |
| 77 |
| 78 void DartHost::OnResume() { |
| 79 Log::Print("Resuming DartHost"); |
| 80 } |
| 81 |
| 82 void DartHost::OnPause() { |
| 83 Log::Print("Pausing DartHost"); |
| 84 } |
| 85 |
| 86 void DartHost::OnStop() { |
| 87 Log::Print("Stopping DartHost"); |
| 88 } |
| 89 |
| 90 void DartHost::OnDestroy() { |
| 91 Log::Print("Destroying DartHost"); |
| 92 } |
| 93 |
| 94 void DartHost::OnSaveState(void** data, size_t size) { |
| 95 Log::Print("Saving DartHost state"); |
| 96 } |
| 97 |
| 98 void DartHost::OnConfigurationChanged() { |
| 99 Log::Print("DartHost config changed"); |
| 100 } |
| 101 |
| 102 void DartHost::OnLowMemory() { |
| 103 Log::Print("DartHost low on memory"); |
| 104 } |
| 105 |
| 106 void DartHost::OnCreateWindow() { |
| 107 Log::Print("DartHost creating window"); |
| 108 } |
| 109 |
| 110 void DartHost::OnDestroyWindow() { |
| 111 Log::Print("DartHost destroying window"); |
| 112 } |
| 113 |
| 114 void DartHost::OnGainedFocus() { |
| 115 Log::Print("DartHost gained focus"); |
| 116 } |
| 117 |
| 118 void DartHost::OnLostFocus() { |
| 119 Log::Print("DartHost lost focus"); |
| 120 } |
| 121 |
| 122 void DartHost::Clear() { |
| 123 memset(window_buffer_.bits, 0, |
| 124 window_buffer_.stride * window_buffer_.height * sizeof(int32_t)); |
| 125 } |
| 126 |
OLD | NEW |