Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************\
- Auto-generated threadedOpenGLTestPlugin.cpp
- This file contains the auto-generated main plugin object
- implementation for the threadedOpenGLTestPlugin project
- Example from Kai Rathmann and Eamon Woortman
- \**********************************************************/
- #include <sstream>
- #include <stdio.h>
- #include "threadedOpenGLTestPluginAPI.h"
- #include "threadedOpenGLTestPlugin.h"
- #include "DOM/Window.h"
- #include "URI.h"
- #include "PluginEvents/KeyCodes.h"
- #ifdef FB_WIN
- #include "PluginWindowWin.h"
- #include "PluginWindowlessWin.h"
- #ifdef HAS_LEAKFINDER
- #define XML_LEAK_FINDER
- #include "LeakFinder/LeakFinder.h"
- #endif
- #endif
- #ifdef HAS_LEAKFINDER
- boost::scoped_ptr<LeakFinderXmlOutput> FBTestPlugin::pOut;
- #endif
- //openGL stuff
- //opengl thread stuff
- #include <windows.h>
- #include <strsafe.h>
- #include <stdio.h>
- HANDLE openGLThreadHandle;
- DWORD dwThreadID;
- float theta = 0.0f;
- #include "win_common.h"
- #include "logging.h"
- #include <gl\gl.h>
- HWND hWnd;
- HDC hDC;
- HGLRC hRC;
- GLfloat rtri = 0.1f;
- bool run = true;
- FB::PluginWindowWin* pluginWindowWin;
- FB::PluginWindow* pluginWindow;
- #include <tchar.h>
- #include <stdio.h>
- //long timeSinceLastFrame;
- #ifndef __PLUGIN_KEYS__
- #define __PLUGIN_KEYS__
- bool pluginKeys[256];
- #endif
- LPTHREAD_START_ROUTINE threadedOpenGLTestPlugin::drawThreaded( LPVOID lpParam )
- {
- EnableOpenGL( pluginWindowWin->getHWND(), &hDC, &hRC );
- SetFocus(pluginWindowWin->getHWND());
- //FB::
- FBLOG_INFO("BrowserHost", "Logging to HTML: " << "Bla!");
- static int fps = 1;
- static double start = 0, diff, wait;
- wait = 1 / fps;
- //return 0;
- while(run)
- {
- //lets check for keyboard input
- if(pluginKeys[FB::FBKeyCode::FBKEY_F1]==true)
- {
- pluginKeys[FB::FBKeyCode::FBKEY_F1]=false;
- rtri = 0.1f;
- //run = false; //stop refreshing
- }
- if(pluginKeys[FB::FBKeyCode::FBKEY_F2]==true)
- {
- pluginKeys[FB::FBKeyCode::FBKEY_F2]=false;
- rtri -= 0.1f;
- }
- if(pluginKeys[FB::FBKeyCode::FBKEY_F3]==true)
- {
- pluginKeys[FB::FBKeyCode::FBKEY_F3]=false;
- rtri += 0.1f;
- }
- if(pluginKeys[FB::FBKeyCode::FBKEY_F4]==true)
- {
- pluginKeys[FB::FBKeyCode::FBKEY_F4]=false;
- rtri = 0.0f;
- }
- try
- {
- FB::Rect pos = pluginWindow->getWindowPosition();
- #if FB_WIN
- //HDC hDC;
- //FB::PluginWindowlessWin *wndLess = dynamic_cast<FB::PluginWindowlessWin*>(pluginWindow);
- //FB::PluginWindowWin *wnd = dynamic_cast<FB::PluginWindowWin*>(pluginWindow);
- PAINTSTRUCT ps;
- /*if (wndLess) {
- hDC = wndLess->getHDC();
- } else if (wnd) {*/
- if(pluginWindowWin){
- //if(!hDC)
- hDC = BeginPaint(pluginWindowWin->getHWND(), &ps);
- pos.right -= pos.left;
- pos.left = 0;
- pos.bottom -= pos.top;
- pos.top = 0;
- glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
- glClear( GL_COLOR_BUFFER_BIT );
- glPushMatrix();
- glRotatef(rtri,0.0f,1.0f,0.0f);
- glBegin( GL_TRIANGLES );
- glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
- glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
- glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
- glEnd();
- glBegin(GL_QUADS); // Draw A Quad
- glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f(-0.5f, 0.5f, 0.0f); // Top Left
- glColor3f( 0.0f, 1.0f, 0.0f );glVertex3f( 0.5f, 0.5f, 0.0f); // Top Right
- glColor3f( 0.0f, 0.0f, 1.0f ); glVertex3f( 0.5f,-0.5f, 0.0f); // Bottom Right
- glColor3f( 0.0f, 0.0f, 0.0f ); glVertex3f(-0.5f,-0.5f, 0.0f); // Bottom Left
- glEnd(); // Done Drawing The Quad
- glPopMatrix();
- glRotatef(rtri,0.0f,1.0f,0.0f);
- SwapBuffers( hDC );
- //me end
- }
- //rtri+=0.1f;
- ::SetTextAlign(hDC, TA_CENTER|TA_BASELINE);
- LPCTSTR pszText = _T("FireBreath Plugin!\n:-)");
- ::TextOut(hDC, pos.left + (pos.right - pos.left) / 2, pos.top + (pos.bottom - pos.top) / 2, pszText, lstrlen(pszText));
- if (pluginWindowWin) {
- // Release the device context
- EndPaint(pluginWindowWin->getHWND(), &ps);
- }
- #endif
- //return true;
- }catch(...)
- {
- return 0;
- }
- //doesnt work
- /*
- diff = GetTickCount() - start;
- if (diff < wait) {
- Sleep(wait - diff);
- }
- start = GetTickCount();*/
- Sleep(10);
- }//end of while run
- return 0;
- }
- void threadedOpenGLTestPlugin::EnableOpenGL(HWND handleWnd, HDC * hdc, HGLRC * hRC)
- {
- PIXELFORMATDESCRIPTOR pfd;
- int format;
- // get the device context (DC)
- *hdc = GetDC( handleWnd );
- // set the pixel format for the DC
- ZeroMemory( &pfd, sizeof( pfd ) );
- pfd.nSize = sizeof( pfd );
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
- pfd.cDepthBits = 16;
- pfd.iLayerType = PFD_MAIN_PLANE;
- format = ChoosePixelFormat( *hdc, &pfd );
- SetPixelFormat( *hdc, format, &pfd );
- // create and enable the render context (RC)
- *hRC = wglCreateContext( *hdc );
- wglMakeCurrent( *hdc, *hRC );
- hDC = *hdc;
- }
- // Disable OpenGL
- void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC)
- {
- wglMakeCurrent( NULL, NULL );
- wglDeleteContext( hRC );
- ReleaseDC( hWnd, hDC );
- }
- ///////////////////////////////////////////////////////////////////////////////
- /// @fn threadedOpenGLTestPlugin::StaticInitialize()
- ///
- /// @brief Called from PluginFactory::globalPluginInitialize()
- ///
- /// @see FB::FactoryBase::globalPluginInitialize
- ///////////////////////////////////////////////////////////////////////////////
- void threadedOpenGLTestPlugin::StaticInitialize()
- {
- // Place one-time initialization stuff here; As of FireBreath 1.4 this should only
- // be called once per process
- }
- ///////////////////////////////////////////////////////////////////////////////
- /// @fn threadedOpenGLTestPlugin::StaticInitialize()
- ///
- /// @brief Called from PluginFactory::globalPluginDeinitialize()
- ///
- /// @see FB::FactoryBase::globalPluginDeinitialize
- ///////////////////////////////////////////////////////////////////////////////
- void threadedOpenGLTestPlugin::StaticDeinitialize()
- {
- // Place one-time deinitialization stuff here. As of FireBreath 1.4 this should
- // always be called just before the plugin library is unloaded
- }
- ///////////////////////////////////////////////////////////////////////////////
- /// @brief threadedOpenGLTestPlugin constructor. Note that your API is not available
- /// at this point, nor the window. For best results wait to use
- /// the JSAPI object until the onPluginReady method is called
- ///////////////////////////////////////////////////////////////////////////////
- threadedOpenGLTestPlugin::threadedOpenGLTestPlugin()
- {
- }
- ///////////////////////////////////////////////////////////////////////////////
- /// @brief threadedOpenGLTestPlugin destructor.
- ///////////////////////////////////////////////////////////////////////////////
- threadedOpenGLTestPlugin::~threadedOpenGLTestPlugin()
- {
- // This is optional, but if you reset m_api (the shared_ptr to your JSAPI
- // root object) and tell the host to free the retained JSAPI objects then
- // unless you are holding another shared_ptr reference to your JSAPI object
- // they will be released here.
- releaseRootJSAPI();
- m_host->freeRetainedObjects();
- }
- void threadedOpenGLTestPlugin::onPluginReady()
- {
- // When this is called, the BrowserHost is attached, the JSAPI object is
- // created, and we are ready to interact with the page and such. The
- // PluginWindow may or may not have already fire the AttachedEvent at
- // this point.
- }
- void threadedOpenGLTestPlugin::shutdown()
- {
- // This will be called when it is time for the plugin to shut down;
- // any threads or anything else that may hold a shared_ptr to this
- // object should be released here so that this object can be safely
- // destroyed. This is the last point that shared_from_this and weak_ptr
- // references to this object will be valid
- }
- ///////////////////////////////////////////////////////////////////////////////
- /// @brief Creates an instance of the JSAPI object that provides your main
- /// Javascript interface.
- ///
- /// Note that m_host is your BrowserHost and shared_ptr returns a
- /// FB::PluginCorePtr, which can be used to provide a
- /// boost::weak_ptr<threadedOpenGLTestPlugin> for your JSAPI class.
- ///
- /// Be very careful where you hold a shared_ptr to your plugin class from,
- /// as it could prevent your plugin class from getting destroyed properly.
- ///////////////////////////////////////////////////////////////////////////////
- FB::JSAPIPtr threadedOpenGLTestPlugin::createJSAPI()
- {
- // m_host is the BrowserHost
- return boost::make_shared<threadedOpenGLTestPluginAPI>(FB::ptr_cast<threadedOpenGLTestPlugin>(shared_from_this()), m_host);
- }
- bool threadedOpenGLTestPlugin::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *)
- {
- //printf("Mouse down at: %d, %d\n", evt->m_x, evt->m_y);
- return false;
- }
- bool threadedOpenGLTestPlugin::onMouseUp(FB::MouseUpEvent *evt, FB::PluginWindow *)
- {
- //printf("Mouse up at: %d, %d\n", evt->m_x, evt->m_y);
- return false;
- }
- bool threadedOpenGLTestPlugin::onKeyDown(FB::KeyDownEvent* evt, FB::PluginWindow* window)
- {
- //set the key to true
- pluginKeys[evt->m_key_code] = true;
- return true;
- }
- bool threadedOpenGLTestPlugin::onMouseMove(FB::MouseMoveEvent *evt, FB::PluginWindow *)
- {
- //printf("Mouse move at: %d, %d\n", evt->m_x, evt->m_y);
- return false;
- }
- bool threadedOpenGLTestPlugin::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow* window)
- {
- pluginWindow = window;
- FB::PluginWindowlessWin *wndLess = dynamic_cast<FB::PluginWindowlessWin*>(window);
- pluginWindowWin = dynamic_cast<FB::PluginWindowWin*>(window);
- boost::thread t(boost::bind(&threadedOpenGLTestPlugin::drawThreaded, this));
- return false;
- }
- bool threadedOpenGLTestPlugin::onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindow *)
- {
- // The window is about to be detached; act appropriately
- return false;
- }
- bool threadedOpenGLTestPlugin::draw( FB::RefreshEvent *evt, FB::PluginWindow* win )
- {
- //Refresh Events... nothing todo since the opengl is running in it's own thread
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement