]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Gecko: load OffscreenGecko dynamically
authorres <res@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 16 Jan 2008 10:52:17 +0000 (10:52 +0000)
committerres <res@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 16 Jan 2008 10:52:17 +0000 (10:52 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7962 d7cf8633-e32d-0410-b094-e92efae38249

cl_gecko.c
cl_main.c
clvm_cmds.c
host.c
mvm_cmds.c
progsvm.h
prvm_cmds.c
prvm_cmds.h

index 0bc62fdf0eb95d74e8feee2f58f129ac36f96115..3819aea2ee2255f1a7556d37e1b3e164ffe7b051 100644 (file)
-#ifdef SUPPORT_GECKO\r
+/* --- 8< --- 8< ---   OffscreenGecko headers   --- >8 --- >8 --- */\r
 \r
-// includes everything!\r
-#include <OffscreenGecko/browser.h>\r
+/* OffscreenGecko/defs.h */\r
 \r
-#ifdef _MSC_VER\r
-#      pragma comment( lib, "OffscreenGecko" )\r
+#define OSGK_CLASSTYPE_DEF     struct\r
+#define OSGK_CLASSTYPE_REF     struct\r
+\r
+#include <assert.h>\r
+#define OSGK_ASSERT(x) assert(x)\r
+\r
+typedef unsigned int OSGK_GeckoResult;\r
+\r
+#if defined(__cplusplus) || defined(__GNUC__)\r
+#  define OSGK_INLINE  inline\r
+#elif defined(_MSC_VER)\r
+#  define OSGK_INLINE  __inline\r
+#else\r
+#  define OSGK_INLINE\r
 #endif\r
 \r
+/* OffscreenGecko/baseobj.h */\r
+\r
+struct OSGK_BaseObject_s\r
+{\r
+  int reserved;\r
+};\r
+typedef struct OSGK_BaseObject_s OSGK_BaseObject;\r
+\r
+#define OSGK_DERIVEDTYPE(T)           \\r
+  typedef struct T ## _s {            \\r
+    OSGK_BaseObject baseobj;          \\r
+  } T\r
+\r
+static int (*osgk_addref) (OSGK_BaseObject* obj);\r
+static int (*osgk_release) (OSGK_BaseObject* obj);\r
+\r
+static OSGK_INLINE int osgk_addref_real (OSGK_BaseObject* obj)\r
+{\r
+  return osgk_addref (obj);\r
+}\r
+\r
+static OSGK_INLINE int osgk_release_real (OSGK_BaseObject* obj)\r
+{\r
+  return osgk_release (obj);\r
+}\r
+\r
+#define osgk_addref(obj)    osgk_addref_real (&((obj)->baseobj))\r
+#define osgk_release(obj)   osgk_release_real (&((obj)->baseobj))\r
+\r
+/* OffscreenGecko/embedding.h */\r
+\r
+OSGK_DERIVEDTYPE(OSGK_EmbeddingOptions);\r
+\r
+static OSGK_EmbeddingOptions* (*osgk_embedding_options_create) (void);\r
+static void (*osgk_embedding_options_add_search_path) (\r
+  OSGK_EmbeddingOptions* options, const char* path);\r
+/*static void (*osgk_embedding_options_add_components_path) (\r
+  OSGK_EmbeddingOptions* options, const char* path);*/\r
+static void (*osgk_embedding_options_set_profile_dir) (\r
+  OSGK_EmbeddingOptions* options, const char* profileDir,\r
+  const char* localProfileDir);\r
+\r
+OSGK_DERIVEDTYPE(OSGK_Embedding);\r
+\r
+#define OSGK_API_VERSION    1\r
+\r
+static OSGK_Embedding* (*osgk_embedding_create2) (\r
+  unsigned int apiVer, OSGK_EmbeddingOptions* options, \r
+  OSGK_GeckoResult* geckoResult);\r
+\r
+static OSGK_INLINE OSGK_Embedding* osgk_embedding_create (\r
+  OSGK_GeckoResult* geckoResult)\r
+{\r
+  return osgk_embedding_create2 (OSGK_API_VERSION, 0, geckoResult);\r
+}\r
+\r
+static OSGK_INLINE OSGK_Embedding* osgk_embedding_create_with_options (\r
+  OSGK_EmbeddingOptions* options, OSGK_GeckoResult* geckoResult)\r
+{\r
+  return osgk_embedding_create2 (OSGK_API_VERSION, options, geckoResult);\r
+}\r
+\r
+/*static OSGK_GeckoMem* (*osgk_embedding_get_gecko_mem) (\r
+  OSGK_Embedding* embedding);*/\r
+\r
+/*static OSGK_ComponentMgr* (*osgk_embedding_get_component_mgr) (\r
+  OSGK_Embedding* embedding);*/\r
+\r
+/*OSGK_CLASSTYPE_DEF nsIComponentManager;\r
+OSGK_CLASSTYPE_DEF nsIComponentRegistrar;\r
+OSGK_CLASSTYPE_DEF nsIServiceManager;*/\r
+\r
+/*static OSGK_CLASSTYPE_REF nsIComponentManager* \r
+(*osgk_embedding_get_gecko_component_manager) (OSGK_Embedding* embedding);*/\r
+/*static OSGK_CLASSTYPE_REF nsIComponentRegistrar* \r
+(*osgk_embedding_get_gecko_component_registrar) (OSGK_Embedding* embedding);*/\r
+/*static OSGK_CLASSTYPE_REF nsIServiceManager* \r
+(*osgk_embedding_get_gecko_service_manager) (OSGK_Embedding* embedding);*/\r
+\r
+enum\r
+{\r
+  jsgPrivileged = 1\r
+};\r
+/*static int (*osgk_embedding_register_js_global) (\r
+  OSGK_Embedding* embedding, const char* name, const char* contractID,\r
+  unsigned int flags, OSGK_String** previousContract,\r
+  OSGK_GeckoResult* geckoResult);*/\r
+\r
+/*static void (*osgk_embedding_clear_focus*) (OSGK_Embedding* embedding);*/\r
+/*void (*osgk_embedding_set_auto_focus) (OSGK_Embedding* embedding, int autoFocus);*/\r
+/*static int (*osgk_embedding_get_auto_focus) (OSGK_Embedding* embedding);*/\r
+\r
+/* OffscreenGecko/browser.h */\r
+OSGK_DERIVEDTYPE(OSGK_Browser);\r
+\r
+static OSGK_Browser* (*osgk_browser_create) (\r
+  OSGK_Embedding* embedding, int width, int height);\r
+static void (*osgk_browser_navigate) (OSGK_Browser* browser,\r
+  const char* uri);\r
+\r
+static int (*osgk_browser_query_dirty) (OSGK_Browser* browser);\r
+static const unsigned char* (*osgk_browser_lock_data) (\r
+  OSGK_Browser* browser, int* isDirty);\r
+static void (*osgk_browser_unlock_data) (OSGK_Browser* browser,\r
+  const unsigned char* data);\r
+\r
+typedef enum OSGK_MouseButton\r
+{\r
+  mbLeft, \r
+  mbRight, \r
+  mbMiddle\r
+} OSGK_MouseButton;\r
+\r
+typedef enum OSGK_MouseButtonEventType\r
+{\r
+  meDown,\r
+  meUp,\r
+  meDoubleClick\r
+} OSGK_MouseButtonEventType;\r
+\r
+static void (*osgk_browser_event_mouse_move) (\r
+  OSGK_Browser* browser, int x, int y);\r
+static void (*osgk_browser_event_mouse_button) (\r
+  OSGK_Browser* browser, OSGK_MouseButton button, \r
+  OSGK_MouseButtonEventType eventType);\r
+\r
+typedef enum OSGK_WheelAxis\r
+{\r
+  waVertical,\r
+  waHorizontal\r
+} OSGK_WheelAxis;\r
+\r
+typedef enum OSGK_WheelDirection\r
+{\r
+  wdPositive,\r
+  wdNegative,\r
+  wdPositivePage,\r
+  wdNegativePage\r
+} OSGK_WheelDirection;\r
+\r
+static void (*osgk_browser_event_mouse_wheel) (\r
+  OSGK_Browser* browser, OSGK_WheelAxis axis, \r
+  OSGK_WheelDirection direction);\r
+\r
+typedef enum OSGK_KeyboardEventType\r
+{\r
+  keDown,\r
+  keUp,\r
+  kePress\r
+} OSGK_KeyboardEventType;\r
+\r
+enum\r
+{\r
+  OSGKKey_First = 0x110000,\r
+\r
+  OSGKKey_Backspace = OSGKKey_First,\r
+  OSGKKey_Tab,\r
+  OSGKKey_Return,\r
+  OSGKKey_Shift,\r
+  OSGKKey_Control,\r
+  OSGKKey_Alt,\r
+  OSGKKey_CapsLock,\r
+  OSGKKey_Escape,\r
+  OSGKKey_Space,\r
+  OSGKKey_PageUp,\r
+  OSGKKey_PageDown,\r
+  OSGKKey_End,\r
+  OSGKKey_Home,\r
+  OSGKKey_Left,\r
+  OSGKKey_Up,\r
+  OSGKKey_Right,\r
+  OSGKKey_Down,\r
+  OSGKKey_Insert,\r
+  OSGKKey_Delete,\r
+  OSGKKey_F1,\r
+  OSGKKey_F2,\r
+  OSGKKey_F3,\r
+  OSGKKey_F4,\r
+  OSGKKey_F5,\r
+  OSGKKey_F6,\r
+  OSGKKey_F7,\r
+  OSGKKey_F8,\r
+  OSGKKey_F9,\r
+  OSGKKey_F10,\r
+  OSGKKey_F11,\r
+  OSGKKey_F12,\r
+  OSGKKey_NumLock,\r
+  OSGKKey_ScrollLock,\r
+  OSGKKey_Meta\r
+};\r
+\r
+static int (*osgk_browser_event_key) (\r
+  OSGK_Browser* browser, unsigned int key,\r
+  OSGK_KeyboardEventType eventType);\r
+\r
+typedef enum OSGK_AntiAliasType\r
+{\r
+  aaNone,\r
+  aaGray,\r
+  aaSubpixel\r
+} OSGK_AntiAliasType;\r
+\r
+/*static void (*osgk_browser_set_antialias) (\r
+  OSGK_Browser* browser, OSGK_AntiAliasType aaType);*/\r
+/*static OSGK_AntiAliasType (*osgk_browser_get_antialias) (OSGK_Browser* browser);*/\r
+\r
+/*static void (*osgk_browser_focus) (OSGK_Browser* browser);*/\r
+\r
+static void (*osgk_browser_resize) (OSGK_Browser* browser,\r
+  int width, int height);\r
+\r
+/* --- >8 --- >8 --- End OffscreenGecko headers --- 8< --- 8< --- */\r
+\r
 #include "quakedef.h"\r
 #include "cl_dyntexture.h"\r
 #include "cl_gecko.h"\r
@@ -30,6 +254,8 @@ struct clgecko_s {
 \r
 static clgecko_t cl_geckoinstances[ MAX_GECKO_INSTANCES ];\r
 \r
+static dllhandle_t osgk_dll = NULL;\r
+\r
 static clgecko_t * cl_gecko_findunusedinstance( void ) {\r
        int i;\r
        for( i = 0 ; i < MAX_GECKO_INSTANCES ; i++ ) {\r
@@ -135,8 +361,12 @@ void CL_Gecko_GetTextureExtent( clgecko_t *instance, float* pwidth, float* pheig
 \r
 \r
 clgecko_t * CL_Gecko_CreateBrowser( const char *name ) {\r
+       clgecko_t *instance;\r
+\r
+       if (!osgk_dll) return NULL;\r
+\r
        // TODO: verify that we dont use a name twice\r
-       clgecko_t *instance = cl_gecko_findunusedinstance();\r
+       instance = cl_gecko_findunusedinstance();\r
        // TODO: assert != NULL\r
        \r
        if( cl_geckoembedding == NULL ) {\r
@@ -248,6 +478,11 @@ void CL_Gecko_Shutdown( void ) {
            osgk_release( cl_geckoembedding );\r
            cl_geckoembedding = NULL;\r
        }\r
+\r
+       if (osgk_dll != NULL)\r
+       {\r
+           Sys_UnloadLibrary (&osgk_dll);\r
+       }\r
 }\r
 \r
 static void cl_gecko_create_f( void ) {\r
@@ -358,8 +593,54 @@ static void gl_gecko_movecursor_f( void ) {
        CL_Gecko_Event_CursorMove( CL_Gecko_FindBrowser( name ), x, y );\r
 }\r
 \r
+#undef osgk_addref\r
+#undef osgk_release\r
+\r
+static const dllfunction_t osgkFuncs[] =\r
+{\r
+       {"osgk_addref",                             (void **) &osgk_addref},\r
+       {"osgk_release",                            (void **) &osgk_release},\r
+       {"osgk_embedding_create2",                  (void **) &osgk_embedding_create2},\r
+       {"osgk_embedding_options_create",           (void **) &osgk_embedding_options_create},\r
+       {"osgk_embedding_options_add_search_path",  (void **) &osgk_embedding_options_add_search_path},\r
+       {"osgk_embedding_options_set_profile_dir",  (void **) &osgk_embedding_options_set_profile_dir},\r
+       {"osgk_browser_create",                     (void **) &osgk_browser_create},\r
+       {"osgk_browser_query_dirty",                (void **) &osgk_browser_query_dirty},\r
+       {"osgk_browser_navigate",                   (void **) &osgk_browser_navigate},\r
+       {"osgk_browser_lock_data",                  (void **) &osgk_browser_lock_data},\r
+       {"osgk_browser_unlock_data",                (void **) &osgk_browser_unlock_data},\r
+       {"osgk_browser_resize",                     (void **) &osgk_browser_resize},\r
+       {"osgk_browser_event_mouse_move",           (void **) &osgk_browser_event_mouse_move},\r
+       {"osgk_browser_event_mouse_button",         (void **) &osgk_browser_event_mouse_button},\r
+       {"osgk_browser_event_mouse_wheel",          (void **) &osgk_browser_event_mouse_wheel},\r
+       {"osgk_browser_event_key",                  (void **) &osgk_browser_event_key},\r
+       {NULL, NULL}\r
+};\r
+\r
 void CL_Gecko_Init( void )\r
 {\r
+       const char* dllnames [] =\r
+       {\r
+       #if defined(WIN64)\r
+               "OffscreenGecko64.dll",\r
+       #elif defined(WIN32)\r
+               "OffscreenGecko.dll",\r
+       #elif defined(MACOSX)\r
+               "OffscreenGecko.dylib",\r
+       #else\r
+               "OffscreenGecko.so",\r
+       #endif\r
+               NULL\r
+       };\r
+       \r
+       if (!osgk_dll)\r
+       {\r
+               if (! Sys_LoadLibrary (dllnames, &osgk_dll, osgkFuncs))\r
+               {\r
+                       Con_Printf ("Could not load OffscreenGecko, Gecko support unavailable\n");\r
+               }\r
+       }\r
+\r
        Cmd_AddCommand( "gecko_create", cl_gecko_create_f, "Create a gecko browser instance" );\r
        Cmd_AddCommand( "gecko_destroy", cl_gecko_destroy_f, "Destroy a gecko browser instance" );\r
        Cmd_AddCommand( "gecko_navigate", cl_gecko_navigate_f, "Navigate a gecko browser to a URI" );\r
@@ -505,5 +786,3 @@ qboolean CL_Gecko_Event_Key( clgecko_t *instance, int key, clgecko_buttoneventty
        // TODO: error?\r
        return false;\r
 }\r
-\r
-#endif\r
index ef26dc6f076bd6ab5b693ef3a9f719a84a30b0ea..d0a1010af7b442e4669790b5b41009b45704a11a 100644 (file)
--- 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
 }
 
 
index 9e1f1d61161a617bac97f673db42876605346faa..1de807cbc9dc6d0cc88ee4812fd0ee3ccceab449 100644 (file)
@@ -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 060bbea771352ffa12236382c08349955f30b4cb..62192c141a30de3868e29ca405fa15c75af1fe94 100644 (file)
--- 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();
index fda7feae551fa84ca2d4e4ddae4cc2a59736c811..71e59ab20e1e72918542a0bda2d678decf1540b7 100644 (file)
@@ -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
index 9c907feddcf7aa287cd0ec8d05ea113b3a5af244..629e414ca41d804805a8766fdf78da7af73a7f39 100644 (file)
--- 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;
index b7cae0d24e345234b08789055f888fcaed3820e4..2c8878bff39f640f736349794853960dd4b2b4da 100644 (file)
@@ -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();
 }
 
index 73c8c1911fa86647867deda41fba111f5d44c138..85f8e8763bbda113c7b492ef59b2aea960b96d52 100644 (file)
@@ -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);