Reduce usage of g_Instance

This commit is contained in:
Cameron Gutman 2016-02-29 13:37:53 -05:00
parent 62df62f857
commit be7f316c50
2 changed files with 13 additions and 12 deletions

View File

@ -30,7 +30,7 @@ void MoonlightInstance::DidLockMouse(int32_t result) {
if (m_MouseLocked) { if (m_MouseLocked) {
// Request an IDR frame to dump the frame queue that may have // Request an IDR frame to dump the frame queue that may have
// built up from the GL pipeline being stalled. // built up from the GL pipeline being stalled.
g_Instance->m_RequestIdrFrame = true; m_RequestIdrFrame = true;
} }
} }
@ -75,7 +75,7 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
case PP_INPUTEVENT_TYPE_MOUSEDOWN: { case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
// Lock the mouse cursor when the user clicks on the stream // Lock the mouse cursor when the user clicks on the stream
if (!m_MouseLocked) { if (!m_MouseLocked) {
g_Instance->LockMouse(g_Instance->m_CallbackFactory.NewCallback(&MoonlightInstance::DidLockMouse)); LockMouse(m_CallbackFactory.NewCallback(&MoonlightInstance::DidLockMouse));
// Assume it worked until we get a callback telling us otherwise // Assume it worked until we get a callback telling us otherwise
m_MouseLocked = true; m_MouseLocked = true;
@ -173,7 +173,7 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
// Check if all modifiers are up now // Check if all modifiers are up now
if (m_WaitingForAllModifiersUp && m_KeyModifiers == 0) { if (m_WaitingForAllModifiersUp && m_KeyModifiers == 0) {
g_Instance->UnlockMouse(); UnlockMouse();
m_MouseLocked = false; m_MouseLocked = false;
m_WaitingForAllModifiersUp = false; m_WaitingForAllModifiersUp = false;
} }

View File

@ -31,29 +31,30 @@ class MoonlightModule : public pp::Module {
void MoonlightInstance::OnConnectionStarted(uint32_t unused) { void MoonlightInstance::OnConnectionStarted(uint32_t unused) {
// Tell the front end // Tell the front end
pp::Var response("Connection Established"); pp::Var response("Connection Established");
g_Instance->PostMessage(response); PostMessage(response);
// Start receiving input events // Start receiving input events
g_Instance->RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
g_Instance->RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD); RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
} }
void MoonlightInstance::OnConnectionStopped(uint32_t error) { void MoonlightInstance::OnConnectionStopped(uint32_t error) {
// Not running anymore // Not running anymore
g_Instance->m_Running = false; m_Running = false;
// Stop receiving input events // Stop receiving input events
g_Instance->ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD); ClearInputEventRequest(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL | PP_INPUTEVENT_CLASS_KEYBOARD);
// Unlock the mouse // Unlock the mouse
g_Instance->UnlockMouse(); UnlockMouse();
// Join threads // Join threads
pthread_join(g_Instance->m_ConnectionThread, NULL); pthread_join(m_ConnectionThread, NULL);
pthread_join(g_Instance->m_GamepadThread, NULL); pthread_join(m_GamepadThread, NULL);
// Notify the JS code that the stream has ended // Notify the JS code that the stream has ended
pp::Var response(MSG_STREAM_TERMINATED); pp::Var response(MSG_STREAM_TERMINATED);
g_Instance->PostMessage(response); PostMessage(response);
} }
void MoonlightInstance::StopConnection() { void MoonlightInstance::StopConnection() {