diff options
Diffstat (limited to 'o3d/plugin')
-rw-r--r-- | o3d/plugin/cross/o3d_glue.cc | 19 | ||||
-rw-r--r-- | o3d/plugin/cross/o3d_glue.h | 5 | ||||
-rw-r--r-- | o3d/plugin/win/main_win.cc | 38 |
3 files changed, 31 insertions, 31 deletions
diff --git a/o3d/plugin/cross/o3d_glue.cc b/o3d/plugin/cross/o3d_glue.cc index a91d370..68565aa 100644 --- a/o3d/plugin/cross/o3d_glue.cc +++ b/o3d/plugin/cross/o3d_glue.cc @@ -743,9 +743,6 @@ void PluginObject::set_cursor(o3d::Cursor::CursorType cursor_type) { } #ifdef OS_WIN -bool PluginObject::fullscreen_class_registered_ = false; -WNDCLASSEX PluginObject::fullscreen_class_; - static const wchar_t* kWindowPropertyName = L"o3d"; void PluginObject::StorePluginProperty(HWND hWnd, PluginObject *obj) { @@ -774,22 +771,6 @@ void PluginObject::ClearPluginProperty(HWND hWnd) { } } -WNDCLASSEX *PluginObject::GetFullscreenWindowClass(HINSTANCE hInstance, - WNDPROC window_proc) { - if (!fullscreen_class_registered_) { - ZeroMemory(&fullscreen_class_, sizeof(WNDCLASSEX)); - fullscreen_class_.cbSize = sizeof(WNDCLASSEX); - fullscreen_class_.hInstance = hInstance; - fullscreen_class_.lpfnWndProc = window_proc; - fullscreen_class_.lpszClassName = L"O3DFullScreenWindowClass"; - fullscreen_class_.style = CS_DBLCLKS; - - RegisterClassEx(&fullscreen_class_); - fullscreen_class_registered_ = true; - } - return &fullscreen_class_; -} - static LPCTSTR O3DToWindowsCursor(o3d::Cursor::CursorType cursor_type) { switch (cursor_type) { case o3d::Cursor::DEFAULT: diff --git a/o3d/plugin/cross/o3d_glue.h b/o3d/plugin/cross/o3d_glue.h index 5153ecd..016b58b 100644 --- a/o3d/plugin/cross/o3d_glue.h +++ b/o3d/plugin/cross/o3d_glue.h @@ -406,9 +406,6 @@ class PluginObject: public NPObject { static PluginObject *GetPluginProperty(HWND hWnd); // Clears out the plugin stored on this HWND. static void ClearPluginProperty(HWND hWnd); - // WNDCLASSEX used for constructing fullscreen windows. - static WNDCLASSEX *GetFullscreenWindowClass( - HINSTANCE instance, WNDPROC window_proc); // One bit of state that helps us turn the sequence of events that windows // produces on a double click into what JavaScript is expecting. bool got_dblclick_; @@ -435,8 +432,6 @@ class PluginObject: public NPObject { HCURSOR cursors_[o3d::Cursor::NUM_CURSORS]; // loaded windows cursors. HCURSOR hCursor_; WNDPROC default_plugin_window_proc_; - static WNDCLASSEX fullscreen_class_; - static bool fullscreen_class_registered_; bool painted_once_; #endif // OS_WIN }; diff --git a/o3d/plugin/win/main_win.cc b/o3d/plugin/win/main_win.cc index 594dbff..48c1be1 100644 --- a/o3d/plugin/win/main_win.cc +++ b/o3d/plugin/win/main_win.cc @@ -55,14 +55,22 @@ using glue::StreamManager; using o3d::DisplayWindowWindows; using o3d::Event; +namespace { +// The instance handle of the O3D DLL. +HINSTANCE g_module_instance; +} // namespace anonymous + +#if !defined(O3D_INTERNAL_PLUGIN) + o3d::PluginLogging* g_logger = NULL; bool g_logging_initialized = false; o3d::BluescreenDetector *g_bluescreen_detector = NULL; -#if !defined(O3D_INTERNAL_PLUGIN) extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) { + g_module_instance = instance; + if (reason == DLL_PROCESS_DETACH) { // Teardown V8 when the plugin dll is unloaded. // NOTE: NP_Shutdown would have been a good place for this code but @@ -79,6 +87,8 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, #endif // O3D_INTERNAL_PLUGIN namespace { +const wchar_t* const kFullScreenWindowClassName = L"O3DFullScreenWindowClass"; + // We would normally make this a stack variable in main(), but in a // plugin, that's not possible, so we allocate it dynamically and // destroy it explicitly. @@ -657,6 +667,19 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { return 0; } +bool RegisterFullScreenWindowClass() { + WNDCLASSEX window_class = { sizeof(WNDCLASSEX) }; + window_class.hInstance = g_module_instance; + window_class.lpfnWndProc = WindowProc; + window_class.lpszClassName = kFullScreenWindowClassName; + window_class.style = CS_DBLCLKS; + return RegisterClassEx(&window_class) != 0; +} + +void UnregisterFullScreenWindowClass() { + UnregisterClass(kFullScreenWindowClassName, g_module_instance); +} + NPError InitializePlugin() { #if !defined(O3D_INTERNAL_PLUGIN) if (!o3d::SetupOutOfMemoryHandler()) @@ -682,6 +705,9 @@ NPError InitializePlugin() { DLOG(INFO) << "NP_Initialize"; + if (!RegisterFullScreenWindowClass()) + return NPERR_MODULE_LOAD_FAILED_ERROR; + return NPERR_NO_ERROR; } @@ -716,12 +742,8 @@ HWND CreateFullscreenWindow(PluginObject *obj, } CHECK(mode.width() > 0 && mode.height() > 0); - HINSTANCE instance = - reinterpret_cast<HINSTANCE>( - ::GetWindowLongPtr(obj->GetPluginHWnd(), GWLP_HINSTANCE)); - WNDCLASSEX *wcx = obj->GetFullscreenWindowClass(instance, WindowProc); HWND hWnd = CreateWindowEx(NULL, - wcx->lpszClassName, + kFullScreenWindowClassName, L"O3D Test Fullscreen Window", WS_POPUP, 0, 0, @@ -729,7 +751,7 @@ HWND CreateFullscreenWindow(PluginObject *obj, mode.height(), NULL, NULL, - instance, + g_module_instance, NULL); ShowWindow(hWnd, SW_SHOW); @@ -754,6 +776,8 @@ NPError OSCALL NP_Shutdown(void) { HANDLE_CRASHES; DLOG(INFO) << "NP_Shutdown"; + UnregisterFullScreenWindowClass(); + #if !defined(O3D_INTERNAL_PLUGIN) if (g_logger) { |