1 #include <msp/core/application.h>
2 #include <msp/core/mainthread.h>
4 #include "display_private.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");
18 priv->input_queue = 0;
19 priv->native_window = 0;
21 thread->signal_native_window_created.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_created));
22 thread->signal_native_window_resized.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_resized));
23 thread->signal_native_window_destroyed.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::native_window_destroyed));
24 thread->signal_input_queue_created.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::input_queue_created));
25 thread->signal_input_queue_destroyed.connect(sigc::mem_fun(priv, &PlatformDisplayPrivate::input_queue_destroyed));
26 thread->resume_startup();
34 void Display::set_mode(const VideoMode &, bool)
36 throw runtime_error("video mode switching not supported");
39 bool Display::process_events()
41 MutexLock lock(priv->event_mutex);
42 if(!priv->input_queue)
46 if(!priv->events.empty())
48 event = priv->events.front();
49 priv->events.pop_front();
51 else if(AInputQueue_getEvent(priv->input_queue, &event.aevent)>=0)
53 if(AInputQueue_preDispatchEvent(priv->input_queue, event.aevent))
56 event.type = INPUT_EVENT;
62 if(!priv->windows.empty())
63 handled = priv->windows.begin()->second->event(event);
65 if(event.type==INPUT_EVENT)
66 AInputQueue_finishEvent(priv->input_queue, event.aevent, handled);
67 else if(event.type==WINDOW_CREATED)
68 priv->window_mutex.lock();
69 else if(event.type==WINDOW_DESTROYED)
70 priv->window_mutex.unlock();
75 void Display::check_error()
80 void PlatformDisplayPrivate::push_event(Msp::Graphics::AndroidEventType type)
82 MutexLock lock(event_mutex);
85 events.push_back(event);
88 void PlatformDisplayPrivate::native_window_created(ANativeWindow *window)
90 native_window = window;
91 push_event(WINDOW_CREATED);
94 void PlatformDisplayPrivate::native_window_resized(ANativeWindow *)
96 push_event(WINDOW_RESIZED);
99 void PlatformDisplayPrivate::native_window_destroyed(ANativeWindow *)
101 push_event(WINDOW_DESTROYED);
102 MutexLock lock(window_mutex);
106 void PlatformDisplayPrivate::input_queue_created(AInputQueue *queue)
108 MutexLock lock(event_mutex);
112 void PlatformDisplayPrivate::input_queue_destroyed(AInputQueue *)
114 MutexLock lock(event_mutex);
117 } // namespace Graphics