| 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 "embedders/openglui/android/eventloop.h" | 5 #include "embedders/openglui/android/eventloop.h" |
| 6 | 6 |
| 7 #include "embedders/openglui/common/log.h" | 7 #include "embedders/openglui/common/log.h" |
| 8 | 8 |
| 9 EventLoop::EventLoop(android_app* application) | 9 EventLoop::EventLoop(android_app* application) |
| 10 : enabled_(false), | 10 : enabled_(false), |
| 11 quit_(false), | 11 quit_(false), |
| 12 application_(application), | 12 application_(application), |
| 13 lifecycle_handler_(NULL), | 13 lifecycle_handler_(NULL), |
| 14 input_handler_(NULL) { | 14 input_handler_(NULL) { |
| 15 application_->onAppCmd = ActivityCallback; | 15 application_->onAppCmd = ActivityCallback; |
| 16 application_->onInputEvent = InputCallback; | 16 application_->onInputEvent = InputCallback; |
| 17 application_->userData = this; | 17 application_->userData = this; |
| 18 } | 18 } |
| 19 | 19 |
| 20 void EventLoop::Run(LifeCycleHandler* lifecycle_handler, | 20 void EventLoop::Run(LifeCycleHandler* lifecycle_handler, |
| 21 InputHandler* input_handler) { | 21 InputHandler* input_handler) { |
| 22 int32_t result; | 22 int32_t result; |
| 23 int32_t events; | 23 int32_t events; |
| 24 android_poll_source* source; | 24 android_poll_source* source; |
| 25 | 25 |
| 26 lifecycle_handler_ = lifecycle_handler; | 26 lifecycle_handler_ = lifecycle_handler; |
| 27 input_handler_ = input_handler; | 27 input_handler_ = input_handler; |
| 28 LOGI("Starting event loop"); | 28 LOGI("Starting event loop"); |
| 29 while (true) { | 29 while (true) { |
| 30 // If not enabled, block on events. If enabled, don't block | 30 // If not enabled, block indefinitely on events. If enabled, block |
| 31 // so we can do useful work in onStep. | 31 // briefly so we can do useful work in onStep. Ultimately this is |
| 32 while ((result = ALooper_pollAll(enabled_ ? 0 : -1, | 32 // where we would want to look at elapsed time since the last call |
| 33 // to onStep completed and use a delay that gives us ~60fps. |
| 34 while ((result = ALooper_pollAll(enabled_ ? (1000/60) : -1, |
| 33 NULL, | 35 NULL, |
| 34 &events, | 36 &events, |
| 35 reinterpret_cast<void**>(&source))) >= 0) { | 37 reinterpret_cast<void**>(&source))) >= 0) { |
| 36 if (source != NULL) { | 38 if (source != NULL) { |
| 37 source->process(application_, source); | 39 source->process(application_, source); |
| 38 } | 40 } |
| 39 if (application_->destroyRequested) { | 41 if (application_->destroyRequested) { |
| 40 return; | 42 return; |
| 41 } | 43 } |
| 42 } | 44 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 EventLoop* event_loop = reinterpret_cast<EventLoop*>(application->userData); | 231 EventLoop* event_loop = reinterpret_cast<EventLoop*>(application->userData); |
| 230 event_loop->ProcessActivityEvent(command); | 232 event_loop->ProcessActivityEvent(command); |
| 231 } | 233 } |
| 232 | 234 |
| 233 int32_t EventLoop::InputCallback(android_app* application, | 235 int32_t EventLoop::InputCallback(android_app* application, |
| 234 AInputEvent* event) { | 236 AInputEvent* event) { |
| 235 EventLoop* event_loop = reinterpret_cast<EventLoop*>(application->userData); | 237 EventLoop* event_loop = reinterpret_cast<EventLoop*>(application->userData); |
| 236 return event_loop->ProcessInputEvent(event); | 238 return event_loop->ProcessInputEvent(event); |
| 237 } | 239 } |
| 238 | 240 |
| OLD | NEW |