1 #include <msp/core/application.h>
2 #include <msp/core/mainthread.h>
4 #include "display_private.h"
11 Display::Display(const string &):
14 Android::MainThread *thread = reinterpret_cast<Android::MainThread *>(Application::get_data());
15 if(!thread->is_starting_up())
16 throw logic_error("Display must be created during startup");
19 priv->input_queue = 0;
20 priv->native_window = 0;
22 thread->signal_native_window_created.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_created));
23 thread->signal_native_window_resized.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_resized));
24 thread->signal_native_window_destroyed.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_destroyed));
25 thread->signal_input_queue_created.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::input_queue_created));
26 thread->signal_input_queue_destroyed.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::input_queue_destroyed));
27 thread->resume_startup();
35 void Display::set_mode(const VideoMode &, bool)
37 throw runtime_error("video mode switching not supported");
40 bool Display::process_events()
42 MutexLock lock(priv->event_mutex);
43 if(!priv->input_queue)
47 if(!priv->events.empty())
49 event = priv->events.front();
50 priv->events.pop_front();
52 else if(AInputQueue_getEvent(priv->input_queue, &event.aevent)>=0)
54 if(AInputQueue_preDispatchEvent(priv->input_queue, event.aevent))
57 event.type = INPUT_EVENT;
63 if(!priv->windows.empty())
64 handled = priv->windows.begin()->second->event(event);
66 if(event.type==INPUT_EVENT)
67 AInputQueue_finishEvent(priv->input_queue, event.aevent, handled);
68 else if(event.type==WINDOW_CREATED)
69 priv->window_mutex.lock();
70 else if(event.type==WINDOW_DESTROYED)
71 priv->window_mutex.unlock();
76 void Display::check_error()
81 void PlatformDisplayPrivate::push_event(Msp::Graphics::AndroidEventType type)
83 MutexLock lock(event_mutex);
86 events.push_back(event);
89 void PlatformDisplayPrivate::native_window_created(ANativeWindow *window)
91 native_window = window;
92 push_event(WINDOW_CREATED);
95 void PlatformDisplayPrivate::native_window_resized(ANativeWindow *)
97 push_event(WINDOW_RESIZED);
100 void PlatformDisplayPrivate::native_window_destroyed(ANativeWindow *)
102 push_event(WINDOW_DESTROYED);
103 MutexLock lock(window_mutex);
107 void PlatformDisplayPrivate::input_queue_created(AInputQueue *queue)
109 MutexLock lock(event_mutex);
113 void PlatformDisplayPrivate::input_queue_destroyed(AInputQueue *)
115 MutexLock lock(event_mutex);
118 } // namespace Graphics