gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash/plugin/win32 plugin.cpp plugin.h


From: Dossy Shiobara
Subject: [Gnash-commit] gnash/plugin/win32 plugin.cpp plugin.h
Date: Thu, 13 Mar 2008 17:18:58 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Dossy Shiobara <dossy>  08/03/13 17:18:58

Modified files:
        plugin/win32   : plugin.cpp plugin.h 

Log message:
        Use the Windows GDI DIB buffer directly with AGG,
        eliminating an unnecessary buffer and memcpy.  Correctly
        prevent multiple streams from launching a player thread.
        Implement mouse movement and clicking support.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/plugin/win32/plugin.cpp?cvsroot=gnash&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gnash/plugin/win32/plugin.h?cvsroot=gnash&r1=1.9&r2=1.10

Patches:
Index: plugin.cpp
===================================================================
RCS file: /sources/gnash/gnash/plugin/win32/plugin.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- plugin.cpp  12 Mar 2008 04:03:21 -0000      1.13
+++ plugin.cpp  13 Mar 2008 17:18:57 -0000      1.14
@@ -71,6 +71,7 @@
 #include "plugin.h"
 
 static PRLock* playerLock = NULL;
+static int instances = 0;
 
 char* NPP_GetMIMEDescription(void);
 static const char* getPluginDescription(void);
@@ -174,6 +175,10 @@
 NS_NewPluginInstance(nsPluginCreateData* aCreateDataStruct)
 {
     DBG("NS_NewPluginInstance\n");
+    if (instances > 0) {
+        return NULL;
+    }
+    instances++; // N.B. This is a threading race condition. FIXME.
     if (!playerLock) {
         playerLock = PR_NewLock();
     }
@@ -194,6 +199,7 @@
                PR_DestroyLock(playerLock);
                playerLock = NULL;
     }
+    instances--;
 }
  
 // nsPluginInstance class implementation
@@ -211,11 +217,13 @@
     _width(0),
     _height(0),
     _rowstride(0),
+    _hMemDC(NULL),
+    _bmp(NULL),
     _memaddr(NULL),
     mouse_x(0),
     mouse_y(0),
     mouse_buttons(0),
-    lpOldProc(NULL)
+    _oldWndProc(NULL)
 {
     DBG("nsPluginInstance::nsPluginInstance\n");
 }
@@ -225,9 +233,17 @@
 {
     DBG("nsPluginInstance::~nsPluginInstance\n");
     if (_memaddr) {
-        free(_memaddr);
+        // Deleting _bmp should free this memory.
         _memaddr = NULL;
     }
+    if (_hMemDC) {
+        DeleteObject(_hMemDC);
+        _hMemDC = NULL;
+    }
+    if (_bmp) {
+        DeleteObject(_bmp);
+        _bmp = NULL;
+    }
 }
  
 NPBool
@@ -247,6 +263,27 @@
     // Windows DIB row stride is always a multiple of 4 bytes.
     _rowstride = /* 24 bits */ 3 * _width;
     _rowstride += _rowstride % 4;
+
+    memset(&_bmpInfo, 0, sizeof(BITMAPINFOHEADER));
+    _bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+    _bmpInfo.bmiHeader.biWidth = _width; 
+    // Negative height means first row comes first in memory.
+    _bmpInfo.bmiHeader.biHeight = -1 * _height; 
+    _bmpInfo.bmiHeader.biPlanes = 1; 
+    _bmpInfo.bmiHeader.biBitCount = 24; 
+    _bmpInfo.bmiHeader.biCompression = BI_RGB; 
+    _bmpInfo.bmiHeader.biSizeImage = 0; 
+    _bmpInfo.bmiHeader.biXPelsPerMeter = 0; 
+    _bmpInfo.bmiHeader.biYPelsPerMeter = 0; 
+    _bmpInfo.bmiHeader.biClrUsed = 0; 
+    _bmpInfo.bmiHeader.biClrImportant = 0; 
+
+    HDC hDC = GetDC(_window);
+    _hMemDC = CreateCompatibleDC(hDC);
+    _bmp = CreateDIBSection(_hMemDC, &_bmpInfo,
+            DIB_RGB_COLORS, (void **) &_memaddr, 0, 0);
+    SelectObject(_hMemDC, _bmp);
+
     DBG("aWindow->type: %s (%u)\n", 
             (aWindow->type == NPWindowTypeWindow) ? "NPWindowTypeWindow" :
             (aWindow->type == NPWindowTypeDrawable) ? "NPWindowTypeDrawable" :
@@ -255,7 +292,7 @@
 
     // subclass window so we can intercept window messages and
     // do our drawing to it
-    lpOldProc = SubclassWindow(_window, (WNDPROC)PluginWinProc);
+    _oldWndProc = SubclassWindow(_window, (WNDPROC) PluginWinProc);
  
     // associate window with our nsPluginInstance object so we can access 
     // it in the window procedure
@@ -283,7 +320,7 @@
     }
 
     // subclass it back
-    SubclassWindow(_window, lpOldProc);
+    SubclassWindow(_window, _oldWndProc);
 
     _initialized = FALSE;
 }
@@ -295,6 +332,7 @@
     DBG("nsPluginInstance::NewStream\n");
     DBG("stream->url: %s\n", stream->url);
 
+    if (!_stream) {
     _stream = stream;
     _url = stream->url;
 #if 0
@@ -302,6 +340,7 @@
         *stype = NP_SEEK;
     }
 #endif
+    }
 
     return NPERR_NO_ERROR;
 }
@@ -342,6 +381,7 @@
 nsPluginInstance::threadMain(void)
 {
     DBG("nsPluginInstance::threadMain started\n");
+    DBG("URL: %s\n", _url.c_str());
 
        PR_Lock(playerLock);
 
@@ -367,9 +407,10 @@
     DBG("Gnash sound initialized.\n");
 
     // Init GUI.
+    int old_mouse_x = 0, old_mouse_y = 0, old_mouse_buttons = 0;
     _render_handler =
         (gnash::render_handler *) gnash::create_render_handler_agg("BGR24");
-    _memaddr = (unsigned char *) malloc(getMemSize());
+    // _memaddr = (unsigned char *) malloc(getMemSize());
     static_cast<gnash::render_handler_agg_base 
*>(_render_handler)->init_buffer(
             getMemAddr(), getMemSize(), _width, _height, _rowstride);
     gnash::set_render_handler(_render_handler);
@@ -420,6 +461,7 @@
     root.setRootMovie(mr.release());
     root.set_display_viewport(0, 0, _width, _height);
     root.set_background_alpha(1.0f);
+    gnash::movie_instance* mi = root.getRootMovie();
     DBG("Movie instance created.\n");
 
     ShowWindow(_window, SW_SHOW);
@@ -432,7 +474,6 @@
             break;
         }
 
-        gnash::movie_instance* mi = root.getRootMovie();
         size_t cur_frame = mi->get_current_frame();
         // DBG("Got current frame number: %d.\n", cur_frame);
         size_t tot_frames = mi->get_frame_count();
@@ -447,12 +488,38 @@
         // DBG("Setting play state to PLAY.\n");
         root.set_play_state(gnash::sprite_instance::PLAY);
 
+        if (old_mouse_x != mouse_x || old_mouse_y != mouse_y) {
+            old_mouse_x = mouse_x;
+            old_mouse_y = mouse_y;
+            root.notify_mouse_moved(mouse_x, mouse_y);
+        }
+        if (old_mouse_buttons != mouse_buttons) {
+            old_mouse_buttons = mouse_buttons;
+            int mask = 1;
+            root.notify_mouse_clicked(mouse_buttons > 0, mask);
+        }
+
         root.display();
 
         RECT rt;
         GetClientRect(_window, &rt);
         InvalidateRect(_window, &rt, FALSE);
 
+#if 0
+        InvalidatedRanges ranges;
+        ranges.setSnapFactor(1.3f);
+        ranges.setSingleMode(false);
+        root.add_invalidated_bounds(ranges, false);
+        ranges.growBy(40.0f);
+        ranges.combine_ranges();
+
+        if (!ranges.isNull()) {
+            InvalidateRect(_window, &rt, FALSE);
+        }
+
+        root.display();
+#endif
+
         // DBG("Unlocking playerLock mutex.\n");
         PR_Unlock(playerLock);
         // DBG("Sleeping.\n");
@@ -505,39 +572,8 @@
                 int w = rt.right - rt.left;
                 int h = rt.bottom - rt.top;
 
-                BITMAPINFO bmpInfo;
-                memset(&bmpInfo, 0, sizeof(BITMAPINFOHEADER));
-                bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-                bmpInfo.bmiHeader.biWidth = w; 
-                // Negative height means first row comes first in memory.
-                bmpInfo.bmiHeader.biHeight = -1 * h; 
-                bmpInfo.bmiHeader.biPlanes = 1; 
-                bmpInfo.bmiHeader.biBitCount = 24; 
-                bmpInfo.bmiHeader.biCompression = BI_RGB; 
-                bmpInfo.bmiHeader.biSizeImage = 0; 
-                bmpInfo.bmiHeader.biXPelsPerMeter = 0; 
-                bmpInfo.bmiHeader.biYPelsPerMeter = 0; 
-                bmpInfo.bmiHeader.biClrUsed = 0; 
-                bmpInfo.bmiHeader.biClrImportant = 0; 
-                
-                HDC hMemDC = CreateCompatibleDC(hDC);
-                void* buf = NULL;
-                HBITMAP bmp = CreateDIBSection(hMemDC, &bmpInfo,
-                        DIB_RGB_COLORS, &buf, 0, 0);
-                HBITMAP temp = (HBITMAP) SelectObject(hMemDC, bmp);
-
-                unsigned char* mem = plugin->getMemAddr();
-                int memSize = plugin->getMemSize();
-                int height = plugin->getHeight();
- 
-                memcpy(buf, mem, memSize);
-
-                BitBlt(hDC, rt.left, rt.top, w, h, hMemDC, 0, 0,
-                        SRCCOPY);
-
-                SelectObject(hMemDC, temp);
-                DeleteObject(bmp);
-                DeleteObject(hMemDC);
+                BitBlt(hDC, rt.left, rt.top, w, h,
+                        plugin->getMemDC(), 0, 0, SRCCOPY);
 
                 EndPaint(hWnd, &ps);
                 return 0L;

Index: plugin.h
===================================================================
RCS file: /sources/gnash/gnash/plugin/win32/plugin.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- plugin.h    12 Mar 2008 04:03:21 -0000      1.9
+++ plugin.h    13 Mar 2008 17:18:57 -0000      1.10
@@ -58,6 +58,7 @@
     int32 Write(NPStream *stream, int32 offset, int32 len, void *buffer);
 
     // locals
+    typedef std::map<std::string, std::string> VariableMap;
     const char* getVersion();
     void threadMain(void);
 
@@ -65,26 +66,25 @@
     int getWidth() { return _width; };
     int getHeight() { return _height; };
     int getRowStride() { return _rowstride; }
+    HDC getMemDC() { return _hMemDC; }
+    HBITMAP getBitmap() { return _bmp; }
     unsigned char* getMemAddr() { return _memaddr; }
     size_t getMemSize() { return _rowstride * _height; }
     void notify_mouse_state(int x, int y, int buttons)
     {
         mouse_x = x;
         mouse_y = y;
-        if (buttons >= 0)
-        {
+        if (buttons >= 0) {
             mouse_buttons = buttons;
         }
     }
 
-    typedef std::map<std::string, std::string> VariableMap;
-
 private:
     NPP         _instance;
     HWND        _window;
     NPBool      _initialized;
     NPBool      _shutdown;
-    WNDPROC     lpOldProc;
+    WNDPROC     _oldWndProc;
 
     NPStream*   _stream;
     std::string _url;
@@ -95,7 +95,11 @@
     uint32_t    _width;
     uint32_t    _height;
     uint32_t    _rowstride;
+    HDC         _hMemDC;
+    BITMAPINFO  _bmpInfo;
+    HBITMAP     _bmp;
     unsigned char* _memaddr;
+
     std::auto_ptr<gnash::media::sound_handler> _sound_handler;
     gnash::render_handler* _render_handler;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]