1 #include <msp/core/application.h>
2 #include <msp/core/mainthread.h>
4 #include "display_private.h"
11 Display::Display(const string &):
15 Android::MainThread *thread = reinterpret_cast<Android::MainThread *>(Application::get_data());
16 if(!thread->is_starting_up())
17 throw logic_error("Display must be created during startup");
20 priv->input_queue = 0;
21 priv->native_window = 0;
23 thread->signal_native_window_created.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_created));
24 thread->signal_native_window_resized.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_resized));
25 thread->signal_native_window_destroyed.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_destroyed));
26 thread->signal_input_queue_created.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::input_queue_created));
27 thread->signal_input_queue_destroyed.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::input_queue_destroyed));
28 thread->resume_startup();
36 void Display::set_mode(const VideoMode &, bool)
38 throw runtime_error("video mode switching not supported");
41 bool Display::process_events()
43 MutexLock lock(priv->event_mutex);
44 if(!priv->input_queue)
48 if(!priv->events.empty())
50 event = priv->events.front();
51 priv->events.pop_front();
53 else if(AInputQueue_getEvent(priv->input_queue, &event.aevent)>=0)
55 if(AInputQueue_preDispatchEvent(priv->input_queue, event.aevent))
58 event.type = INPUT_EVENT;
64 if(!priv->windows.empty())
65 handled = priv->windows.begin()->second->event(event);
67 if(event.type==INPUT_EVENT)
68 AInputQueue_finishEvent(priv->input_queue, event.aevent, handled);
69 else if(event.type==WINDOW_CREATED)
70 priv->window_mutex.lock();
71 else if(event.type==WINDOW_DESTROYED)
72 priv->window_mutex.unlock();
77 void Display::check_error()
82 void PlatformDisplayPrivate::push_event(Msp::Graphics::AndroidEventType type)
84 MutexLock lock(event_mutex);
87 events.push_back(event);
90 void PlatformDisplayPrivate::native_window_created(ANativeWindow *window)
92 native_window = window;
93 push_event(WINDOW_CREATED);
96 void PlatformDisplayPrivate::native_window_resized(ANativeWindow *)
98 push_event(WINDOW_RESIZED);
101 void PlatformDisplayPrivate::native_window_destroyed(ANativeWindow *)
103 push_event(WINDOW_DESTROYED);
104 MutexLock lock(window_mutex);
108 void PlatformDisplayPrivate::input_queue_created(AInputQueue *queue)
110 MutexLock lock(event_mutex);
114 void PlatformDisplayPrivate::input_queue_destroyed(AInputQueue *)
116 MutexLock lock(event_mutex);
120 } // namespace Graphics