2 #include "display_private.h"
3 #include <msp/core/application.h>
4 #include <msp/core/mainthread.h>
11 Display::Display(const string &)
13 Android::MainThread *thread = reinterpret_cast<Android::MainThread *>(Application::get_data());
14 if(!thread->is_starting_up())
15 throw logic_error("Display must be created during startup");
19 thread->signal_native_window_created.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_created));
20 thread->signal_native_window_resized.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_resized));
21 thread->signal_native_window_destroyed.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_destroyed));
22 thread->signal_input_queue_created.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::input_queue_created));
23 thread->signal_input_queue_destroyed.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::input_queue_destroyed));
24 thread->resume_startup();
32 void Display::set_mode(const VideoMode &, bool)
34 throw runtime_error("video mode switching not supported");
37 bool Display::process_events()
39 MutexLock lock(priv->event_mutex);
40 if(!priv->input_queue)
44 if(!priv->events.empty())
46 event = priv->events.front();
47 priv->events.pop_front();
49 else if(AInputQueue_getEvent(priv->input_queue, &event.aevent)>=0)
51 if(AInputQueue_preDispatchEvent(priv->input_queue, event.aevent))
54 event.type = INPUT_EVENT;
60 if(!priv->windows.empty())
61 handled = priv->windows.begin()->second->event(event);
63 if(event.type==INPUT_EVENT)
64 AInputQueue_finishEvent(priv->input_queue, event.aevent, handled);
65 else if(event.type==WINDOW_CREATED)
66 priv->window_mutex.lock();
67 else if(event.type==WINDOW_DESTROYED)
68 priv->window_mutex.unlock();
73 void Display::check_error()
78 void PlatformDisplayPrivate::push_event(Msp::Graphics::AndroidEventType type)
80 MutexLock lock(event_mutex);
83 events.push_back(event);
86 void PlatformDisplayPrivate::native_window_created(ANativeWindow *window)
88 native_window = window;
89 push_event(WINDOW_CREATED);
92 void PlatformDisplayPrivate::native_window_resized(ANativeWindow *)
94 push_event(WINDOW_RESIZED);
97 void PlatformDisplayPrivate::native_window_destroyed(ANativeWindow *)
99 push_event(WINDOW_DESTROYED);
100 MutexLock lock(window_mutex);
104 void PlatformDisplayPrivate::input_queue_created(AInputQueue *queue)
106 MutexLock lock(event_mutex);
110 void PlatformDisplayPrivate::input_queue_destroyed(AInputQueue *)
112 MutexLock lock(event_mutex);
116 } // namespace Graphics