From: res Date: Wed, 16 Jan 2008 10:52:17 +0000 (+0000) Subject: Gecko: load OffscreenGecko dynamically X-Git-Tag: xonotic-v0.1.0preview~2546 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=46cfccb1fef9095b35d4f6c37876a178361e3174;p=xonotic%2Fdarkplaces.git Gecko: load OffscreenGecko dynamically git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7962 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_gecko.c b/cl_gecko.c index 0bc62fdf..3819aea2 100644 --- a/cl_gecko.c +++ b/cl_gecko.c @@ -1,12 +1,236 @@ -#ifdef SUPPORT_GECKO +/* --- 8< --- 8< --- OffscreenGecko headers --- >8 --- >8 --- */ -// includes everything! -#include +/* OffscreenGecko/defs.h */ -#ifdef _MSC_VER -# pragma comment( lib, "OffscreenGecko" ) +#define OSGK_CLASSTYPE_DEF struct +#define OSGK_CLASSTYPE_REF struct + +#include +#define OSGK_ASSERT(x) assert(x) + +typedef unsigned int OSGK_GeckoResult; + +#if defined(__cplusplus) || defined(__GNUC__) +# define OSGK_INLINE inline +#elif defined(_MSC_VER) +# define OSGK_INLINE __inline +#else +# define OSGK_INLINE #endif +/* OffscreenGecko/baseobj.h */ + +struct OSGK_BaseObject_s +{ + int reserved; +}; +typedef struct OSGK_BaseObject_s OSGK_BaseObject; + +#define OSGK_DERIVEDTYPE(T) \ + typedef struct T ## _s { \ + OSGK_BaseObject baseobj; \ + } T + +static int (*osgk_addref) (OSGK_BaseObject* obj); +static int (*osgk_release) (OSGK_BaseObject* obj); + +static OSGK_INLINE int osgk_addref_real (OSGK_BaseObject* obj) +{ + return osgk_addref (obj); +} + +static OSGK_INLINE int osgk_release_real (OSGK_BaseObject* obj) +{ + return osgk_release (obj); +} + +#define osgk_addref(obj) osgk_addref_real (&((obj)->baseobj)) +#define osgk_release(obj) osgk_release_real (&((obj)->baseobj)) + +/* OffscreenGecko/embedding.h */ + +OSGK_DERIVEDTYPE(OSGK_EmbeddingOptions); + +static OSGK_EmbeddingOptions* (*osgk_embedding_options_create) (void); +static void (*osgk_embedding_options_add_search_path) ( + OSGK_EmbeddingOptions* options, const char* path); +/*static void (*osgk_embedding_options_add_components_path) ( + OSGK_EmbeddingOptions* options, const char* path);*/ +static void (*osgk_embedding_options_set_profile_dir) ( + OSGK_EmbeddingOptions* options, const char* profileDir, + const char* localProfileDir); + +OSGK_DERIVEDTYPE(OSGK_Embedding); + +#define OSGK_API_VERSION 1 + +static OSGK_Embedding* (*osgk_embedding_create2) ( + unsigned int apiVer, OSGK_EmbeddingOptions* options, + OSGK_GeckoResult* geckoResult); + +static OSGK_INLINE OSGK_Embedding* osgk_embedding_create ( + OSGK_GeckoResult* geckoResult) +{ + return osgk_embedding_create2 (OSGK_API_VERSION, 0, geckoResult); +} + +static OSGK_INLINE OSGK_Embedding* osgk_embedding_create_with_options ( + OSGK_EmbeddingOptions* options, OSGK_GeckoResult* geckoResult) +{ + return osgk_embedding_create2 (OSGK_API_VERSION, options, geckoResult); +} + +/*static OSGK_GeckoMem* (*osgk_embedding_get_gecko_mem) ( + OSGK_Embedding* embedding);*/ + +/*static OSGK_ComponentMgr* (*osgk_embedding_get_component_mgr) ( + OSGK_Embedding* embedding);*/ + +/*OSGK_CLASSTYPE_DEF nsIComponentManager; +OSGK_CLASSTYPE_DEF nsIComponentRegistrar; +OSGK_CLASSTYPE_DEF nsIServiceManager;*/ + +/*static OSGK_CLASSTYPE_REF nsIComponentManager* +(*osgk_embedding_get_gecko_component_manager) (OSGK_Embedding* embedding);*/ +/*static OSGK_CLASSTYPE_REF nsIComponentRegistrar* +(*osgk_embedding_get_gecko_component_registrar) (OSGK_Embedding* embedding);*/ +/*static OSGK_CLASSTYPE_REF nsIServiceManager* +(*osgk_embedding_get_gecko_service_manager) (OSGK_Embedding* embedding);*/ + +enum +{ + jsgPrivileged = 1 +}; +/*static int (*osgk_embedding_register_js_global) ( + OSGK_Embedding* embedding, const char* name, const char* contractID, + unsigned int flags, OSGK_String** previousContract, + OSGK_GeckoResult* geckoResult);*/ + +/*static void (*osgk_embedding_clear_focus*) (OSGK_Embedding* embedding);*/ +/*void (*osgk_embedding_set_auto_focus) (OSGK_Embedding* embedding, int autoFocus);*/ +/*static int (*osgk_embedding_get_auto_focus) (OSGK_Embedding* embedding);*/ + +/* OffscreenGecko/browser.h */ +OSGK_DERIVEDTYPE(OSGK_Browser); + +static OSGK_Browser* (*osgk_browser_create) ( + OSGK_Embedding* embedding, int width, int height); +static void (*osgk_browser_navigate) (OSGK_Browser* browser, + const char* uri); + +static int (*osgk_browser_query_dirty) (OSGK_Browser* browser); +static const unsigned char* (*osgk_browser_lock_data) ( + OSGK_Browser* browser, int* isDirty); +static void (*osgk_browser_unlock_data) (OSGK_Browser* browser, + const unsigned char* data); + +typedef enum OSGK_MouseButton +{ + mbLeft, + mbRight, + mbMiddle +} OSGK_MouseButton; + +typedef enum OSGK_MouseButtonEventType +{ + meDown, + meUp, + meDoubleClick +} OSGK_MouseButtonEventType; + +static void (*osgk_browser_event_mouse_move) ( + OSGK_Browser* browser, int x, int y); +static void (*osgk_browser_event_mouse_button) ( + OSGK_Browser* browser, OSGK_MouseButton button, + OSGK_MouseButtonEventType eventType); + +typedef enum OSGK_WheelAxis +{ + waVertical, + waHorizontal +} OSGK_WheelAxis; + +typedef enum OSGK_WheelDirection +{ + wdPositive, + wdNegative, + wdPositivePage, + wdNegativePage +} OSGK_WheelDirection; + +static void (*osgk_browser_event_mouse_wheel) ( + OSGK_Browser* browser, OSGK_WheelAxis axis, + OSGK_WheelDirection direction); + +typedef enum OSGK_KeyboardEventType +{ + keDown, + keUp, + kePress +} OSGK_KeyboardEventType; + +enum +{ + OSGKKey_First = 0x110000, + + OSGKKey_Backspace = OSGKKey_First, + OSGKKey_Tab, + OSGKKey_Return, + OSGKKey_Shift, + OSGKKey_Control, + OSGKKey_Alt, + OSGKKey_CapsLock, + OSGKKey_Escape, + OSGKKey_Space, + OSGKKey_PageUp, + OSGKKey_PageDown, + OSGKKey_End, + OSGKKey_Home, + OSGKKey_Left, + OSGKKey_Up, + OSGKKey_Right, + OSGKKey_Down, + OSGKKey_Insert, + OSGKKey_Delete, + OSGKKey_F1, + OSGKKey_F2, + OSGKKey_F3, + OSGKKey_F4, + OSGKKey_F5, + OSGKKey_F6, + OSGKKey_F7, + OSGKKey_F8, + OSGKKey_F9, + OSGKKey_F10, + OSGKKey_F11, + OSGKKey_F12, + OSGKKey_NumLock, + OSGKKey_ScrollLock, + OSGKKey_Meta +}; + +static int (*osgk_browser_event_key) ( + OSGK_Browser* browser, unsigned int key, + OSGK_KeyboardEventType eventType); + +typedef enum OSGK_AntiAliasType +{ + aaNone, + aaGray, + aaSubpixel +} OSGK_AntiAliasType; + +/*static void (*osgk_browser_set_antialias) ( + OSGK_Browser* browser, OSGK_AntiAliasType aaType);*/ +/*static OSGK_AntiAliasType (*osgk_browser_get_antialias) (OSGK_Browser* browser);*/ + +/*static void (*osgk_browser_focus) (OSGK_Browser* browser);*/ + +static void (*osgk_browser_resize) (OSGK_Browser* browser, + int width, int height); + +/* --- >8 --- >8 --- End OffscreenGecko headers --- 8< --- 8< --- */ + #include "quakedef.h" #include "cl_dyntexture.h" #include "cl_gecko.h" @@ -30,6 +254,8 @@ struct clgecko_s { static clgecko_t cl_geckoinstances[ MAX_GECKO_INSTANCES ]; +static dllhandle_t osgk_dll = NULL; + static clgecko_t * cl_gecko_findunusedinstance( void ) { int i; for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) { @@ -135,8 +361,12 @@ void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* pwidth, float* pheig clgecko_t * CL_Gecko_CreateBrowser( const char *name ) { + clgecko_t *instance; + + if (!osgk_dll) return NULL; + // TODO: verify that we dont use a name twice - clgecko_t *instance = cl_gecko_findunusedinstance(); + instance = cl_gecko_findunusedinstance(); // TODO: assert != NULL if( cl_geckoembedding == NULL ) { @@ -248,6 +478,11 @@ void CL_Gecko_Shutdown( void ) { osgk_release( cl_geckoembedding ); cl_geckoembedding = NULL; } + + if (osgk_dll != NULL) + { + Sys_UnloadLibrary (&osgk_dll); + } } static void cl_gecko_create_f( void ) { @@ -358,8 +593,54 @@ static void gl_gecko_movecursor_f( void ) { CL_Gecko_Event_CursorMove( CL_Gecko_FindBrowser( name ), x, y ); } +#undef osgk_addref +#undef osgk_release + +static const dllfunction_t osgkFuncs[] = +{ + {"osgk_addref", (void **) &osgk_addref}, + {"osgk_release", (void **) &osgk_release}, + {"osgk_embedding_create2", (void **) &osgk_embedding_create2}, + {"osgk_embedding_options_create", (void **) &osgk_embedding_options_create}, + {"osgk_embedding_options_add_search_path", (void **) &osgk_embedding_options_add_search_path}, + {"osgk_embedding_options_set_profile_dir", (void **) &osgk_embedding_options_set_profile_dir}, + {"osgk_browser_create", (void **) &osgk_browser_create}, + {"osgk_browser_query_dirty", (void **) &osgk_browser_query_dirty}, + {"osgk_browser_navigate", (void **) &osgk_browser_navigate}, + {"osgk_browser_lock_data", (void **) &osgk_browser_lock_data}, + {"osgk_browser_unlock_data", (void **) &osgk_browser_unlock_data}, + {"osgk_browser_resize", (void **) &osgk_browser_resize}, + {"osgk_browser_event_mouse_move", (void **) &osgk_browser_event_mouse_move}, + {"osgk_browser_event_mouse_button", (void **) &osgk_browser_event_mouse_button}, + {"osgk_browser_event_mouse_wheel", (void **) &osgk_browser_event_mouse_wheel}, + {"osgk_browser_event_key", (void **) &osgk_browser_event_key}, + {NULL, NULL} +}; + void CL_Gecko_Init( void ) { + const char* dllnames [] = + { + #if defined(WIN64) + "OffscreenGecko64.dll", + #elif defined(WIN32) + "OffscreenGecko.dll", + #elif defined(MACOSX) + "OffscreenGecko.dylib", + #else + "OffscreenGecko.so", + #endif + NULL + }; + + if (!osgk_dll) + { + if (! Sys_LoadLibrary (dllnames, &osgk_dll, osgkFuncs)) + { + Con_Printf ("Could not load OffscreenGecko, Gecko support unavailable\n"); + } + } + Cmd_AddCommand( "gecko_create", cl_gecko_create_f, "Create a gecko browser instance" ); Cmd_AddCommand( "gecko_destroy", cl_gecko_destroy_f, "Destroy a gecko browser instance" ); Cmd_AddCommand( "gecko_navigate", cl_gecko_navigate_f, "Navigate a gecko browser to a URI" ); @@ -505,5 +786,3 @@ qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventty // TODO: error? return false; } - -#endif diff --git a/cl_main.c b/cl_main.c index ef26dc6f..d0a1010a 100644 --- a/cl_main.c +++ b/cl_main.c @@ -2322,9 +2322,7 @@ void CL_Init (void) CL_Screen_Init(); CL_Video_Init(); -#ifdef SUPPORT_GECKO CL_Gecko_Init(); -#endif } diff --git a/clvm_cmds.c b/clvm_cmds.c index 9e1f1d61..1de807cb 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -3392,7 +3392,6 @@ VM_CL_pointsound, // #483 void(vector origin, string sample, float volume, fl VM_strreplace, // #484 string(string search, string replace, string subject) strreplace (DP_QC_STRREPLACE) VM_strireplace, // #485 string(string search, string replace, string subject) strireplace (DP_QC_STRREPLACE) VM_CL_getsurfacepointattribute,// #486 vector(entity e, float s, float n, float a) getsurfacepointattribute -#ifdef SUPPORT_GECKO VM_gecko_create, // #487 float gecko_create( string name ) VM_gecko_destroy, // #488 void gecko_destroy( string name ) VM_gecko_navigate, // #489 void gecko_navigate( string name, string URI ) @@ -3400,15 +3399,6 @@ VM_gecko_keyevent, // #490 float gecko_keyevent( string name, float key, floa VM_gecko_movemouse, // #491 void gecko_mousemove( string name, float x, float y ) VM_gecko_resize, // #492 void gecko_resize( string name, float w, float h ) VM_gecko_get_texture_extent, // #493 vector gecko_get_texture_extent( string name ) -#else -NULL, // #487 -NULL, // #488 -NULL, // #489 -NULL, // #490 -NULL, // #491 -NULL, // #492 -NULL, // #493 -#endif NULL, // #494 NULL, // #495 NULL, // #496 diff --git a/host.c b/host.c index 060bbea7..62192c14 100644 --- a/host.c +++ b/host.c @@ -857,9 +857,7 @@ void Host_Main(void) //ui_update(); CL_Video_Frame(); -#ifdef SUPPORT_GECKO CL_Gecko_Frame(); -#endif CL_UpdateScreen(); @@ -1172,9 +1170,7 @@ void Host_Shutdown(void) // AK shutdown PRVM // AK hmm, no PRVM_Shutdown(); yet -#ifdef SUPPORT_GECKO CL_Gecko_Shutdown(); -#endif CL_Video_Shutdown(); Host_SaveConfig(); diff --git a/mvm_cmds.c b/mvm_cmds.c index fda7feae..71e59ab2 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -21,9 +21,7 @@ char *vm_m_extensions = "DP_QC_STRREPLACE " "DP_FONT_VARIABLEWIDTH " // FIXME: rename this extension maybe? [12/5/2007 Black] -#ifdef SUPPORT_GECKO "DP_GECKO_SUPPORT " -#endif "DP_QC_RENDER_SCENE" ; @@ -1272,7 +1270,6 @@ NULL, // #483 VM_strreplace, // #484 string(string search, string replace, string subject) strreplace (DP_QC_STRREPLACE) VM_strireplace, // #485 string(string search, string replace, string subject) strireplace (DP_QC_STRREPLACE) NULL, // #486 -#ifdef SUPPORT_GECKO VM_gecko_create, // #487 float gecko_create( string name ) VM_gecko_destroy, // #488 void gecko_destroy( string name ) VM_gecko_navigate, // #489 void gecko_navigate( string name, string URI ) @@ -1280,15 +1277,6 @@ VM_gecko_keyevent, // #490 float gecko_keyevent( string name, float key, floa VM_gecko_movemouse, // #491 void gecko_mousemove( string name, float x, float y ) VM_gecko_resize, // #492 void gecko_resize( string name, float w, float h ) VM_gecko_get_texture_extent, // #493 vector gecko_get_texture_extent( string name ) -#else -NULL, // #487 -NULL, // #488 -NULL, // #489 -NULL, // #490 -NULL, // #491 -NULL, // #492 -NULL, // #493 -#endif NULL, // #494 NULL, // #495 NULL, // #496 diff --git a/progsvm.h b/progsvm.h index 9c907fed..629e414c 100644 --- a/progsvm.h +++ b/progsvm.h @@ -33,10 +33,8 @@ The code uses void pointers instead. #include "progdefs.h" // generated by program cdefs #include "clprogdefs.h" // generated by program cdefs -#ifdef SUPPORT_GECKO // forward declaration of clgecko_t struct clgecko_s; -#endif typedef struct prvm_stack_s { @@ -119,9 +117,7 @@ typedef struct prvm_edict_s #define PRVM_MAX_OPENFILES 256 #define PRVM_MAX_OPENSEARCHES 128 -#ifdef SUPPORT_GECKO #define PRVM_MAX_GECKOINSTANCES 32 -#endif typedef void (*prvm_builtin_t) (void); @@ -353,9 +349,7 @@ typedef struct prvm_prog_s qfile_t *openfiles[PRVM_MAX_OPENFILES]; fssearch_t *opensearches[PRVM_MAX_OPENSEARCHES]; -#ifdef SUPPORT_GECKO struct clgecko_s *opengeckoinstances[PRVM_MAX_GECKOINSTANCES]; -#endif // copies of some vars that were former read from sv int num_edicts; diff --git a/prvm_cmds.c b/prvm_cmds.c index b7cae0d2..2c8878bf 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -3073,7 +3073,6 @@ void VM_cin_restart( void ) CL_RestartVideo( video ); } -#ifdef SUPPORT_GECKO /* ======================== VM_Gecko_Init @@ -3314,7 +3313,6 @@ void VM_gecko_get_texture_extent( void ) { } -#endif /* ============== @@ -4527,9 +4525,7 @@ void VM_Cmd_Init(void) // only init the stuff for the current prog VM_Files_Init(); VM_Search_Init(); -#ifdef SUPPORT_GECKO VM_Gecko_Init(); -#endif // VM_BufStr_Init(); } @@ -4538,9 +4534,7 @@ void VM_Cmd_Reset(void) CL_PurgeOwner( MENUOWNER ); VM_Search_Reset(); VM_Files_CloseAll(); -#ifdef SUPPORT_GECKO VM_Gecko_Destroy(); -#endif // VM_BufStr_ShutDown(); } diff --git a/prvm_cmds.h b/prvm_cmds.h index 73c8c191..85f8e876 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -149,13 +149,11 @@ void cin_setstate(string name, float type) float cin_getstate(string name) void cin_restart(string name) -#ifdef SUPPORT_GECKO float[bool] gecko_create( string name ) void gecko_destroy( string name ) void gecko_navigate( string name, string URI ) float[bool] gecko_keyevent( string name, float key, float eventtype ) void gecko_mousemove( string name, float x, float y ) -#endif ============================================================================== menu cmd list: @@ -195,9 +193,7 @@ float getserverlistindexforkey(string key) #include "mprogdefs.h" #include "cl_video.h" -#ifdef SUPPORT_GECKO #include "cl_gecko.h" -#endif //============================================================================ // nice helper macros @@ -358,7 +354,6 @@ void VM_cin_setstate( void ); void VM_cin_getstate( void ); void VM_cin_restart( void ); -#ifdef SUPPORT_GECKO void VM_gecko_create( void ); void VM_gecko_destroy( void ); void VM_gecko_navigate( void ); @@ -366,7 +361,6 @@ void VM_gecko_keyevent( void ); void VM_gecko_movemouse( void ); void VM_gecko_resize( void ); void VM_gecko_get_texture_extent( void ); -#endif void VM_drawline (void);