Browse Source

integrating awesomium with panda

Redmond Urbino 16 years ago
parent
commit
2407c6883a

+ 36 - 0
panda/src/awesomium/Sources.pp

@@ -0,0 +1,36 @@
+#define BUILD_DIRECTORY $[HAVE_AWESOMIUM]
+#define BUILDING_DLL BUILDING_PANDAAWESOMIUM
+
+#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
+                   dtoolutil:c dtoolbase:c dtool:m prc:c
+
+#begin lib_target
+  //I don't understand why ode can have TARGET as just pode, here it needs pandaawesomium
+  #define TARGET pandaawesomium
+  #define LOCAL_LIBS \
+    pgraph physics
+
+  #define USE_PACKAGES awesomium
+    
+  #define COMBINED_SOURCES $[TARGET]_composite1.cxx 
+
+  #define SOURCES \
+    awesomium_includes.h config_awesomium.h \
+    awWebCore.I awWebCore.h \
+    awWebView.I awWebView.h
+
+  #define INCLUDED_SOURCES \
+    config_awesomium.cxx \
+    awWebCore.cxx \
+    awWebView.cxx
+
+
+  #define INSTALL_HEADERS \
+    awesomium_includes.h config_awesomium.h \
+    awWebCore.h awWebCore.I \
+    awWebView.h awWebView.I
+
+  #define IGATESCAN all
+
+#end lib_target
+

+ 52 - 0
panda/src/awesomium/awWebCore.I

@@ -0,0 +1,52 @@
+// Filename: awWebCore.I
+// Created by:  rurbino (12Oct09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+
+INLINE void AwWebCore::
+setBaseDirectory(const std::string& baseDirectory) {
+  WebCore::setBaseDirectory(baseDirectory);
+}
+
+INLINE void AwWebCore::
+setCustomResponsePage(int statusCode, const std::string& filePath) {
+  WebCore::setCustomResponsePage(statusCode, filePath);
+}
+
+INLINE void AwWebCore::
+update() {
+  WebCore::update();
+}
+
+INLINE const std::string& AwWebCore::
+getBaseDirectory() const {
+  return WebCore::getBaseDirectory();
+}
+
+INLINE bool AwWebCore::
+arePluginsEnabled() const {
+  return WebCore::arePluginsEnabled();
+}
+
+
+INLINE void AwWebCore::
+pause(){
+  WebCore::pause();
+}
+
+INLINE void AwWebCore::
+resume() {
+  WebCore::resume();
+}
+
+

+ 52 - 0
panda/src/awesomium/awWebCore.cxx

@@ -0,0 +1,52 @@
+// Filename: awWebCore.cxx
+// Created by:  rurbino (12Oct09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "config_awesomium.h"
+#include "awWebCore.h"
+#include "WebCore.h"
+
+TypeHandle AwWebCore::_type_handle;
+
+AwWebCore::
+AwWebCore(AwWebCore::LogLevel level, bool enablePlugins , AwWebCore::PixelFormat pixelFormat) :
+  WebCore(static_cast<Awesomium::LogLevel>(level), enablePlugins, static_cast<Awesomium::PixelFormat>(pixelFormat)) {  
+  awesomium_cat.info() << "constructing webcore";
+}
+
+AwWebCore::
+~AwWebCore() {
+}
+
+Awesomium::WebCore& AwWebCore::
+Get() {
+  return WebCore::Get();
+}
+
+Awesomium::WebCore* AwWebCore::
+GetPointer() {
+  return WebCore::GetPointer();
+}
+
+AwWebView *  AwWebCore::
+createWebView(int width, int height, bool isTransparent , bool enableAsyncRendering , int maxAsyncRenderPerSec ) {
+  Awesomium::WebView * newView = WebCore::createWebView(width, height, isTransparent, enableAsyncRendering, maxAsyncRenderPerSec);
+  AwWebView * result = new AwWebView(newView);
+  return result;
+}
+
+AwWebCore::PixelFormat AwWebCore::
+getPixelFormat() const {
+  return ( static_cast<AwWebCore::PixelFormat>( WebCore::getPixelFormat()) );
+}
+

+ 95 - 0
panda/src/awesomium/awWebCore.h

@@ -0,0 +1,95 @@
+// Filename: awWebCore.h
+// Created by:  rurbino (12Oct09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+#ifndef AWWEBCORE_H
+#define AWWEBCORE_H
+
+#include "pandabase.h"
+#include "typedReferenceCount.h"
+#include "luse.h"
+
+#include "awesomium_includes.h"
+
+class AwWebView;
+////////////////////////////////////////////////////////////////////
+//       Class : AwWebCore
+// Description : Thin wrappings arround WebCore.h
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDAAWESOMIUM AwWebCore : public TypedReferenceCount, public Awesomium::WebCore {
+PUBLISHED:
+  /**
+  * An enumeration of the three verbosity settings for the Awesomium Log.
+  */
+  enum LogLevel
+  {
+	LOG_NONE , 		// No log is created
+	LOG_NORMAL ,		// Logs only errors
+	LOG_VERBOSE 		// Logs everything
+  };
+
+  /**
+  * An enumeration of the two output pixel formats that WebView::render will use.
+  */
+  enum PixelFormat
+  {
+	PF_BGRA,	// BGRA byte ordering [Blue, Green, Red, Alpha]
+	PF_RGBA		// RGBA byte ordering [Red, Green, Blue, Alpha]
+  };
+
+  AwWebCore(LogLevel level = LOG_NORMAL, bool enablePlugins = true, PixelFormat pixelFormat = PF_BGRA);
+
+  virtual ~AwWebCore();
+
+  static Awesomium::WebCore& Get();
+
+  static Awesomium::WebCore* GetPointer();
+
+  INLINE void setBaseDirectory(const std::string& baseDirectory);
+
+  AwWebView * createWebView(int width, int height, bool isTransparent = false, bool enableAsyncRendering = false, int maxAsyncRenderPerSec = 70);
+
+  INLINE void setCustomResponsePage(int statusCode, const std::string& filePath);
+
+  INLINE void update();
+
+  INLINE const std::string& getBaseDirectory() const;
+
+  AwWebCore::PixelFormat getPixelFormat() const;
+
+  INLINE bool arePluginsEnabled() const;
+
+  INLINE void pause();
+
+  INLINE void resume();
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    TypedReferenceCount::init_type();
+    register_type(_type_handle, "AwWebCore",
+                  TypedReferenceCount::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "awWebCore.I"
+
+#endif

+ 84 - 0
panda/src/awesomium/awWebView.I

@@ -0,0 +1,84 @@
+// Filename: awWebView.I
+// Created by:  rurbino (12Oct09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+INLINE void AwWebView::
+destroy(void)
+{
+  _myWebView->destroy();
+}
+
+
+INLINE void AwWebView::
+setListener(Awesomium::WebViewListener *  listener) {
+  _myWebView->setListener(listener);
+}
+
+INLINE Awesomium::WebViewListener* AwWebView::
+getListener() {
+  return _myWebView->getListener();
+}
+
+INLINE void AwWebView::
+goToHistoryOffset(int offset) {
+  _myWebView->goToHistoryOffset(offset);
+}
+
+INLINE void AwWebView::
+executeJavascript2(const std::string& javascript, const std::string& frameName ) {
+  _myWebView->executeJavascript2(javascript, frameName);
+}
+
+INLINE Awesomium::FutureJSValue AwWebView::
+executeJavascriptWithResult2(const std::string& javascript, const std::string& frameName ) {
+  return _myWebView->executeJavascriptWithResult2(javascript, frameName);
+}
+
+INLINE void AwWebView::
+setProperty(const std::string& name, const Awesomium::JSValue& value) {
+  _myWebView->setProperty(name, value);
+}
+
+INLINE void AwWebView::
+setCallback(const std::string& name) {
+  _myWebView->setCallback(name);
+}
+
+INLINE bool AwWebView::
+isDirty() {
+  return _myWebView->isDirty();
+}
+
+INLINE void AwWebView::
+render( size_t  destination, int destRowSpan, int destDepth)
+{
+  _myWebView->render( reinterpret_cast<unsigned char *>(destination), destRowSpan, destDepth, 0);
+}
+
+
+
+INLINE void AwWebView::
+injectMouseUp(AwWebView::MouseButton button) {
+  _myWebView->injectMouseUp(static_cast<Awesomium::MouseButton>(button));
+}
+
+INLINE void AwWebView::
+injectMouseWheelXY(int scrollAmountX, int scrollAmountY){
+  _myWebView->injectMouseWheelXY(scrollAmountX, scrollAmountY);
+}
+
+INLINE void AwWebView::
+injectKeyEvent(bool press, int modifiers, int windowsCode, int nativeCode) {
+  _myWebView->injectKeyEvent(press, modifiers, windowsCode, nativeCode);
+}
+

+ 76 - 0
panda/src/awesomium/awWebView.cxx

@@ -0,0 +1,76 @@
+// Filename: awWebView.cxx
+// Created by:  rurbino (12Oct09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "config_awesomium.h"
+#include "awWebView.h"
+
+TypeHandle AwWebView::_type_handle;
+
+AwWebView::
+AwWebView(Awesomium::WebView * webViewPtr)  {  
+  _myWebView = webViewPtr;
+
+}
+
+AwWebView::
+~AwWebView() {
+}
+
+
+void AwWebView::
+loadURL2(const string& url, const string& frameName , const string& username , const string& password )
+{
+  _myWebView->loadURL2(url, frameName, username, password);
+
+}
+
+void AwWebView::
+loadHTML2(const std::string& html, const std::string& frameName )
+{
+  _myWebView->loadHTML2(html, frameName);
+}
+
+
+void AwWebView::
+loadFile2(const std::string& file, const std::string& frameName )
+{
+  _myWebView->loadFile2(file, frameName);
+}
+
+
+void AwWebView::
+render(size_t destination, int destRowSpan, int destDepth, AwWebView::Rect * renderedRect) {
+  if (renderedRect) {
+    Awesomium::Rect rect(renderedRect->x, renderedRect->y, renderedRect->width, renderedRect->height);
+    _myWebView->Awesomium::WebView::render( reinterpret_cast<unsigned char *>(destination), destRowSpan, destDepth, &rect);    
+  }
+  else
+  {
+    AwWebView::render(destination, destRowSpan, destDepth, 0);
+  }
+}
+
+void AwWebView::
+injectMouseDown(AwWebView::MouseButton button) {
+  awesomium_cat.debug() <<"got mouse down " << button << "\n";
+  _myWebView->injectMouseDown(static_cast<Awesomium::MouseButton>(button));
+}
+
+
+void AwWebView::
+injectMouseMove(int x, int y) {
+  //awesomium_cat.debug() <<"got mouse move " << x << " " << y << "\n";
+  _myWebView->injectMouseMove(x,y);
+}
+

+ 128 - 0
panda/src/awesomium/awWebView.h

@@ -0,0 +1,128 @@
+// Filename: awWebCore.h
+// Created by:  rurbino (12Oct09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+#ifndef AWWEBVIEW_H
+#define AWWEBVIEW_H
+
+#include "pandabase.h"
+#include "typedReferenceCount.h"
+#include "luse.h"
+
+#include "awesomium_includes.h"
+
+class WebViewListener;
+
+////////////////////////////////////////////////////////////////////
+//       Class : AwWebView
+// Description : Thin bindings, wraps a WebView * returned from WebCore.createWebView
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDAAWESOMIUM AwWebView : public TypedReferenceCount{
+PUBLISHED:
+
+  /**
+  * Mouse button enumerations, used with WebView::injectMouseDown 
+  * and WebView::injectMouseUp
+  */
+  enum MouseButton {
+  	LEFT_MOUSE_BTN,
+  	MIDDLE_MOUSE_BTN,
+  	RIGHT_MOUSE_BTN
+  };
+
+  /**
+   * A simple rectangle class, used with WebView::render
+   */
+  struct Rect {
+    int x, y, width, height;
+    
+    Rect();
+    Rect(int x, int y, int width, int height);
+    bool isEmpty() const;
+  };
+
+
+PUBLISHED:
+  AwWebView(Awesomium::WebView * webView);
+  
+  virtual ~AwWebView();
+  
+  INLINE void destroy(void);
+  
+  INLINE void setListener(Awesomium::WebViewListener * listener);
+
+  INLINE Awesomium::WebViewListener* getListener();
+  
+  // VC7 linker doesn't like wstring from VS2008, hence using the all regular string version
+  void loadURL2(const string& url, const string& frameName ="", const string& username="" , const string& password="");
+  
+  // VC7 linker doesn't like wstring from VS2008, hence using the all regular string version
+  void loadHTML2(const std::string& html, const std::string& frameName = "");
+  
+  // VC7 linker doesn't like wstring from VS2008, hence using the all regular string version
+  void loadFile2(const std::string& file, const std::string& frameName = "" );
+  
+  INLINE void goToHistoryOffset(int offset);
+
+  // VC7 linker doesn't like wstring from VS2008, hence using the all regular string version
+  INLINE void executeJavascript2(const std::string& javascript, const std::string& frameName = "" );
+
+  INLINE Awesomium::FutureJSValue executeJavascriptWithResult2(const std::string& javascript, const std::string& frameName = "");
+
+  INLINE void setProperty(const std::string& name, const Awesomium::JSValue& value);
+
+  INLINE void setCallback(const std::string& name);
+
+  INLINE bool isDirty();
+
+  INLINE void render(size_t destination, int destRowSpan, int destDepth);
+
+  void render(size_t destination, int destRowSpan, int destDepth, AwWebView::Rect * renderedRect);
+
+  void injectMouseMove(int x, int y);
+
+  void injectMouseDown(AwWebView::MouseButton button);
+
+  INLINE void injectMouseUp(AwWebView::MouseButton button);
+
+  INLINE void injectMouseWheelXY(int scrollAmountX, int scrollAmountY);
+
+  INLINE void injectMouseWheel(int scrollAmountY) {
+    injectMouseWheelXY(0, scrollAmountY);
+  }
+
+  INLINE void injectKeyEvent(bool press, int modifiers, int windowsCode, int nativeCode=0);
+  
+private:
+  Awesomium::WebView * _myWebView;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    TypedReferenceCount::init_type();
+    register_type(_type_handle, "AwWebView",
+                  TypedReferenceCount::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "awWebView.I"
+
+#endif

+ 22 - 0
panda/src/awesomium/awesomium_includes.h

@@ -0,0 +1,22 @@
+// Filename: awesomium_includes.h
+// Created by:  rurbino (08Oct10)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef _AWESOMIUM_INCLUDES_H_
+#define _AWESOMIUM_INCLUDES_H_
+
+
+#include "WebCore.h"
+#include "WebView.h"
+
+#endif

+ 47 - 0
panda/src/awesomium/config_awesomium.cxx

@@ -0,0 +1,47 @@
+// Filename: config_awesomium.cxx
+// Created by:  rurbino (12Oct09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source cawesomium in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "config_awesomium.h"
+#include "awWebCore.h"
+#include "awWebView.h"
+#include "dconfig.h"
+
+Configure(config_awesomium);
+NotifyCategoryDef(awesomium, "");
+
+
+ConfigureFn(config_awesomium) {
+  init_libawesomium();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: init_libawesomium
+//  Description: Initializes the library.  This must be called at
+//               least once before any of the functions or classes in
+//               this library can be used.  Normally it will be
+//               called by the static initializers and need not be
+//               called explicitly, but special cases exist.
+////////////////////////////////////////////////////////////////////
+void
+init_libawesomium() {
+  static bool initialized = false;
+  if (initialized) {
+    return;
+  }
+  initialized = true;
+  
+  AwWebCore::init_type();
+  AwWebView::init_type();
+
+}

+ 27 - 0
panda/src/awesomium/config_awesomium.h

@@ -0,0 +1,27 @@
+// Filename: config_awesomium.h
+// Created by:  rurbino (12Oct09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef CONFIG_AWESOMIUM_H
+#define CONFIG_AWESOMIUM_H
+
+#include "pandabase.h"
+#include "notifyCategoryProxy.h"
+
+#include "dconfig.h"
+
+NotifyCategoryDecl(awesomium, EXPCL_PANDAAWESOMIUM, EXPTP_PANDAAWESOMIUM);
+
+extern EXPCL_PANDAAWESOMIUM void init_libawesomium();
+
+#endif /* CONFIG_AWESOMIUM_H */

+ 3 - 0
panda/src/awesomium/pandaawesomium_composite1.cxx

@@ -0,0 +1,3 @@
+#include "config_awesomium.cxx"
+#include "awWebCore.cxx"
+#include "awWebView.cxx"

+ 12 - 0
panda/src/pandabase/pandasymbols.h

@@ -72,6 +72,14 @@
   #define EXPTP_PANDA extern
 #endif
 
+#ifdef BUILDING_PANDAAWESOMIUM
+  #define EXPCL_PANDAAWESOMIUM __declspec(dllexport)
+  #define EXPTP_PANDAAWESOMIUM
+#else
+  #define EXPCL_PANDAAWESOMIUM __declspec(dllimport)
+  #define EXPTP_PANDAAWESOMIUM extern
+#endif
+
 #ifdef BUILDING_PANDACR
   #define EXPCL_PANDACR __declspec(dllexport)
   #define EXPTP_PANDACR
@@ -252,6 +260,9 @@
 #define EXPCL_PANDA
 #define EXPTP_PANDA
 
+#define EXPCL_PANDAAWESOMIUM
+#define EXPTP_PANDAAWESOMIUM
+
 #define EXPCL_PANDACR
 #define EXPTP_PANDACR
 
@@ -285,6 +296,7 @@
 #define EXPCL_PANDAODE
 #define EXPTP_PANDAODE
 
+
 #define EXPCL_PANDAPHYSICS
 #define EXPTP_PANDAPHYSICS