[vlc-devel] [PATCH 5/5] Use Core Animation drawing model, Cocoa event model in 64 bit plugin.
David Menestrina
dmenest-vlc at ofb.net
Tue May 11 00:32:05 CEST 2010
---
projects/mozilla/vlcplugin.cpp | 21 ++++++++
projects/mozilla/vlcplugin.h | 15 +++++-
projects/mozilla/vlcshell.cpp | 112 +++++++++++++++++++++++++++++++++------
projects/mozilla/vlcshell.h | 2 +-
4 files changed, 129 insertions(+), 21 deletions(-)
diff --git a/projects/mozilla/vlcplugin.cpp b/projects/mozilla/vlcplugin.cpp
index 2a15a2a..f012788 100644
--- a/projects/mozilla/vlcplugin.cpp
+++ b/projects/mozilla/vlcplugin.cpp
@@ -31,6 +31,9 @@
#include "vlcplugin.h"
#include "control/npolibvlc.h"
+#if defined(XP_MACOSX) && defined(__x86_64__)
+# include "coreanim.h"
+#endif
#include <ctype.h>
#if defined(XP_UNIX)
@@ -318,6 +321,7 @@ void EventObj::unask_for_event(event_t e)
}
+
NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
{
/* prepare VLC command line */
@@ -331,7 +335,11 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
/* locate VLC module path */
#ifdef XP_MACOSX
ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/plugins";
+#ifdef __x86_64__
+ ppsz_argv[ppsz_argc++] = "--vout=calayer";
+#else // not 64 bit
ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
+#endif
#elif defined(XP_WIN)
HKEY h_key;
DWORD i_type, i_data = MAX_PATH + 1;
@@ -487,6 +495,10 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
if( !events.init() )
return NPERR_GENERIC_ERROR;
+#if defined(XP_MACOSX) && defined(__x86_64__)
+ this->p_coreanim = coreanim_init();
+#endif
+
return NPERR_NO_ERROR;
}
@@ -507,6 +519,11 @@ VlcPlugin::~VlcPlugin()
libvlc_media_list_release( libvlc_media_list );
if( libvlc_instance )
libvlc_release(libvlc_instance);
+
+#if defined(XP_MACOSX) && defined(__x86_64__)
+ if( this->p_coreanim )
+ coreanim_destroy(this->p_coreanim);
+#endif
}
/*****************************************************************************
@@ -519,8 +536,12 @@ void VlcPlugin::set_player_window()
(uint32_t)getVideoWindow());
#endif
#ifdef XP_MACOSX
+#ifdef __x86_64__
+ libvlc_media_player_set_nsobject(libvlc_media_player, coreanim_get_calayer(p_coreanim));
+#else
// XXX FIXME insert appropriate call here
#endif
+#endif
#ifdef XP_WIN
libvlc_media_player_set_hwnd(libvlc_media_player,
getWindow().window);
diff --git a/projects/mozilla/vlcplugin.h b/projects/mozilla/vlcplugin.h
index ff2e4cf..46263cf 100644
--- a/projects/mozilla/vlcplugin.h
+++ b/projects/mozilla/vlcplugin.h
@@ -53,7 +53,7 @@
# include <winbase.h>
#endif
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) && !defined(__x86_64__)
/* Mac OS X stuff */
# include <Quickdraw.h>
#endif
@@ -71,6 +71,10 @@
# endif
#endif
+#if defined(XP_MACOSX) && defined(__x86_64__)
+#include "coreanim.h"
+#endif
+
#ifndef __MAX
# define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
#endif
@@ -107,7 +111,6 @@ typedef enum vlc_toolbar_clicked_e {
clicked_Unmute
} vlc_toolbar_clicked_t;
-
// Note that the accessor functions are unsafe, but this is handled in
// the next layer up. 64bit uints can be substituted to taste (shift=6).
template<size_t M> class bitmap
@@ -222,6 +225,11 @@ public:
{ pf_wndproc = wndproc; };
#endif
+#if defined(XP_MACOSX) && defined(__x86_64__)
+ void* getCALayer()
+ { return coreanim_get_calayer(p_coreanim); };
+#endif
+
#if defined(XP_UNIX)
int setSize(unsigned width, unsigned height);
Window getVideoWindow()
@@ -350,6 +358,9 @@ private:
int i_last_position;
#endif
+#if defined(XP_MACOSX) && defined(__x86_64__)
+ coreanim_instance_t *p_coreanim;
+#endif
static void eventAsync(void *);
static void event_callback(const libvlc_event_t *, void *);
diff --git a/projects/mozilla/vlcshell.cpp b/projects/mozilla/vlcshell.cpp
index 883205b..601084b 100644
--- a/projects/mozilla/vlcshell.cpp
+++ b/projects/mozilla/vlcshell.cpp
@@ -129,6 +129,12 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
break;
}
+#if defined(XP_MACOSX) && defined(__x86_64__)
+ case NPPVpluginCoreAnimationLayer:
+ *((void **)value) = p_plugin->getCALayer();
+ return NPERR_NO_ERROR;
+#endif
+
default:
;
}
@@ -149,23 +155,10 @@ NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
* Mac-only API calls
*****************************************************************************/
#ifdef XP_MACOSX
-int16_t NPP_HandleEvent( NPP instance, void * event )
+#ifndef __x86_64__
+static int16_t HandleCarbonEvent( VlcPlugin * p_plugin, EventRecord *myEvent )
{
static UInt32 lastMouseUp = 0;
- if( instance == NULL )
- {
- return false;
- }
-
- VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
- if( p_plugin == NULL )
- {
- return false;
- }
-
-#ifndef __x86_64__
- EventRecord *myEvent = (EventRecord*)event;
-
switch( myEvent->what )
{
case nullEvent:
@@ -256,9 +249,68 @@ int16_t NPP_HandleEvent( NPP instance, void * event )
default:
;
}
-#endif // __x86_64__
return false;
}
+#endif
+#ifdef __x86_64__
+static int16_t HandleCocoaEvent( VlcPlugin * p_plugin, NPCocoaEvent * event )
+{
+ switch( event->type )
+ {
+ case NPCocoaEventDrawRect:
+ break;
+ case NPCocoaEventMouseDown:
+ if( event->data.mouse.clickCount > 1 )
+ p_plugin->toggle_fullscreen();
+ return true;
+ case NPCocoaEventMouseUp:
+ break;
+ case NPCocoaEventMouseMoved:
+ break;
+ case NPCocoaEventMouseEntered:
+ break;
+ case NPCocoaEventMouseExited:
+ break;
+ case NPCocoaEventMouseDragged:
+ break;
+ case NPCocoaEventKeyDown:
+ break;
+ case NPCocoaEventKeyUp:
+ break;
+ case NPCocoaEventFlagsChanged:
+ break;
+ case NPCocoaEventFocusChanged:
+ break;
+ case NPCocoaEventWindowFocusChanged:
+ break;
+ case NPCocoaEventScrollWheel:
+ break;
+ case NPCocoaEventTextInput:
+ break;
+ }
+ return false;
+}
+#endif
+
+int16_t NPP_HandleEvent( NPP instance, void * event )
+{
+ if( instance == NULL )
+ {
+ return false;
+ }
+
+ VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
+ if( p_plugin == NULL )
+ {
+ return false;
+ }
+#ifdef __x86_64__
+ return HandleCocoaEvent(p_plugin, (NPCocoaEvent*) event);
+#else
+ return HandleCarbonEvent(p_plugin, (EventRecord*) event);
+#endif
+
+}
#endif /* XP_MACOSX */
/******************************************************************************
@@ -289,7 +341,7 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance,
#endif
char* argn[], char* argv[], NPSavedData* saved )
{
- NPError status;
+ NPError status = NPERR_NO_ERROR;
if( instance == NULL )
{
@@ -302,7 +354,31 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance,
return NPERR_OUT_OF_MEMORY_ERROR;
}
- status = p_plugin->init(argc, argn, argv);
+#if defined(XP_MACOSX) && defined(__x86_64__)
+ if( NPERR_NO_ERROR == status )
+ {
+ // Check if the browser supports the CoreAnimation drawing model
+ NPBool supportsCoreAnimation = FALSE;
+ NPError err = NPN_GetValue(instance,
+ (NPNVariable)NPNVsupportsCoreAnimationBool,
+ &supportsCoreAnimation);
+ if( err != NPERR_NO_ERROR || !supportsCoreAnimation )
+ status = NPERR_INCOMPATIBLE_VERSION_ERROR;
+ else
+ {
+ // Set the drawing model
+ err = NPN_SetValue(instance,
+ (NPPVariable)NPNVpluginDrawingModel,
+ (void*)NPDrawingModelCoreAnimation);
+ if( err != NPERR_NO_ERROR )
+ status = NPERR_INCOMPATIBLE_VERSION_ERROR;
+ }
+ }
+#endif // defined(XP_MACOSX) && defined(__x86_64__)
+
+ if( NPERR_NO_ERROR == status )
+ status = p_plugin->init(argc, argn, argv);
+
if( NPERR_NO_ERROR == status )
{
instance->pdata = reinterpret_cast<void*>(p_plugin);
diff --git a/projects/mozilla/vlcshell.h b/projects/mozilla/vlcshell.h
index a91a06e..452b7c8 100644
--- a/projects/mozilla/vlcshell.h
+++ b/projects/mozilla/vlcshell.h
@@ -28,7 +28,7 @@ char * NPP_GetMIMEDescription( void );
NPError NPP_Initialize( void );
-#ifdef OJI
+#ifdef OJI
jref NPP_GetJavaClass( void );
#endif
void NPP_Shutdown( void );
--
1.7.0.3
More information about the vlc-devel
mailing list