[vlc-commits] mac: added a basic class for a windowless plugin

Felix Paul Kühne git at videolan.org
Mon Dec 31 16:21:49 CET 2012


npapi-vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon Dec 31 16:21:13 2012 +0100| [89c682f165e7fe1c3cfb2edc1c5d6209ca07246b] | committer: Felix Paul Kühne

mac: added a basic class for a windowless plugin

no video output yet

> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=89c682f165e7fe1c3cfb2edc1c5d6209ca07246b
---

 npapi/Makefile.am           |    4 +-
 npapi/vlcplugin.h           |    5 ++
 npapi/vlcwindowless_mac.cpp |  109 +++++++++++++++++++++++++++++++++++++++++++
 npapi/vlcwindowless_mac.h   |   42 +++++++++++++++++
 4 files changed, 159 insertions(+), 1 deletion(-)

diff --git a/npapi/Makefile.am b/npapi/Makefile.am
index 4e16c86..05e6c2b 100644
--- a/npapi/Makefile.am
+++ b/npapi/Makefile.am
@@ -136,7 +136,9 @@ AM_CPPFLAGS += -I. -I$(top_builddir) -c \
 
 SOURCES_support = support/npmac.cpp \
                   vlcplugin_mac.cpp \
-                  vlcplugin_mac.h
+                  vlcplugin_mac.h \
+                  vlcwindowless_mac.cpp \
+                  vlcwindowless_mac.h
 libvlcplugin_la_LDFLAGS += \
 	-bundle -Wl,-headerpad_max_install_names \
 	-Wl,-framework,CoreFoundation -Wl,-framework,ApplicationServices \
diff --git a/npapi/vlcplugin.h b/npapi/vlcplugin.h
index 1bcc58a..a0daa03 100644
--- a/npapi/vlcplugin.h
+++ b/npapi/vlcplugin.h
@@ -52,8 +52,13 @@
 #   include "vlcplugin_win.h"
     typedef class VlcPluginWin VlcPlugin;
 #elif defined(XP_MACOSX)
+#   define WINDOWLESS
+
 #   include "vlcplugin_mac.h"
     typedef class VlcPluginMac VlcPlugin;
+
+#   include "vlcwindowless_mac.h"
+    typedef class VlcWindowlessMac VlcWindowless;
 #endif
 
 
diff --git a/npapi/vlcwindowless_mac.cpp b/npapi/vlcwindowless_mac.cpp
new file mode 100644
index 0000000..cb7d6ea
--- /dev/null
+++ b/npapi/vlcwindowless_mac.cpp
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * vlcwindowless_mac.cpp: VLC NPAPI windowless plugin for Mac
+ *****************************************************************************
+ * Copyright (C) 2012 VLC Authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan # org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include <npapi.h>
+#include "vlcwindowless_mac.h"
+
+VlcWindowlessMac::VlcWindowlessMac(NPP instance, NPuint16_t mode) :
+    VlcWindowlessBase(instance, mode)
+{
+    // get first screen
+    printf("should init\n");
+}
+
+VlcWindowlessMac::~VlcWindowlessMac()
+{
+
+}
+
+void VlcWindowlessMac::drawBackground(NPCocoaEvent *cocoaEvent)
+{
+    CGContextRef cgContext = cocoaEvent->data.draw.context;
+    if (!cgContext)
+        return;
+
+    float windowWidth = npwindow.width;
+    float windowHeight = npwindow.height;
+
+    CGContextSaveGState(cgContext);
+
+    // this context is flipped..
+    CGContextTranslateCTM(cgContext, 0.0, windowHeight);
+    CGContextScaleCTM(cgContext, 1., -1.);
+
+    // fetch background color
+    unsigned r = 0, g = 0, b = 0;
+    HTMLColor2RGB(get_options().get_bg_color().c_str(), &r, &g, &b);
+
+    // draw a gray background
+    CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
+    CGContextSetRGBFillColor(cgContext,r/255.,g/255.,b/255.,1.);
+    CGContextDrawPath(cgContext, kCGPathFill);
+
+    CGContextRestoreGState(cgContext);
+}
+
+bool VlcWindowlessMac::handle_event(void *event)
+{
+    NPCocoaEvent* cocoaEvent = (NPCocoaEvent*)event;
+
+    if (!event)
+        return false;
+
+    NPCocoaEventType eventType = cocoaEvent->type;
+
+    switch (eventType) {
+        case NPCocoaEventMouseDown:
+        {
+            if (cocoaEvent->data.mouse.clickCount >= 2)
+                VlcWindowlessBase::toggle_fullscreen();
+
+            return true;
+        }
+        case NPCocoaEventMouseUp:
+        case NPCocoaEventKeyUp:
+        case NPCocoaEventKeyDown:
+        case NPCocoaEventFocusChanged:
+        case NPCocoaEventScrollWheel:
+            return true;
+
+        default:
+            break;
+    }
+
+    if (eventType == NPCocoaEventDrawRect) {
+        if (VlcPluginBase::playlist_isplaying() && VlcPluginBase::player_has_vout())
+            return false;
+
+        CGContextRef cgContext = cocoaEvent->data.draw.context;
+        if (!cgContext) {
+            return false;
+        }
+
+        drawBackground(cocoaEvent);
+
+        return true;
+    }
+
+    return VlcPluginBase::handle_event(event);
+}
diff --git a/npapi/vlcwindowless_mac.h b/npapi/vlcwindowless_mac.h
new file mode 100644
index 0000000..5a85f13
--- /dev/null
+++ b/npapi/vlcwindowless_mac.h
@@ -0,0 +1,42 @@
+/*****************************************************************************
+ * vlcwindowsless_mac.h: VLC NPAPI windowless plugin for Mac
+ *****************************************************************************
+ * Copyright (C) 2012 VLC Authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne # videolan # org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef __VLCWINDOWLESS_MAC_H__
+#define __VLCWINDOWLESS_MAC_H__
+
+#define WINDOWLESS
+#include "vlcplugin_base.h"
+
+class VlcWindowlessMac : public VlcWindowlessBase
+{
+public:
+    VlcWindowlessMac(NPP instance, NPuint16_t mode);
+    virtual ~VlcWindowlessMac();
+
+    bool handle_event(void *event);
+
+protected:
+    void drawBackground(NPCocoaEvent *cocoaEvent);
+};
+
+#endif /* __VLCWINDOWLESS_MAC_H__ */



More information about the vlc-commits mailing list