Awesomium bindings


23-08-2009 10:23:28

Hey, I was getting any responses on the mailing list, so I thought I'd try here :P

I'm currently working on getting awesomium ported to python. I've
hit a barrier unfortunately. I'm not too experienced in wrapped C++
libraries to python, so bare with me. I'm using py++ and Boost.python.
I haven't really done much script wise with py++, as using the GUI
seems to be suffient enough.
Now on to my problem. Awesomium's webview render method takes in
an unsigned char* as such:

void Awesomium::WebView::render(unsigned char* destination, int
destRowSpan, int destDepth, Awesomium::Rect* renderedRect)

and here is how it is used in it's C++ demo:

Ogre::HardwarePixelBufferSharedPtr pixelBuffer = webTexture->getBuffer
const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
size_t dstBpp = Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
size_t dstPitch = pixelBox.rowPitch * dstBpp;
Ogre::uint8* dstData = static_cast<Ogre::uint8*>(;
std::cout << dstData << std::endl;
view->render(dstData, (int)dstPitch, (int)dstBpp, 0);

here is my python code:

pixelBuffer = self.webTexture.getBuffer()
pixelBox = pixelBuffer.getCurrentLock()
dstBpp = ogre.PixelUtil.getNumElemBytes(pixelBox.format)
dstPitch = pixelBox.rowPitch * dstBpp
dataType = ctypes.POINTER(ctypes.c_uint8)
data = dataType.from_address(
print data,type(data)

and this is the error I'm getting:

ArgumentError: Python argument types in
WebView.render(WebView, LP_c_ubyte, int, int)
did not match C++ signature:
render(class Awesomium::WebView {lvalue}, unsigned char *, int,

Now I realize I'll probably have to do something in boost.python to
have the types match up, but I'm not sure what to do. I've messed
around a bit with to_python_converter, but haven't had much luck
unfortunately. Here is the boost.python code:

.def( "render"
,bp::make_function( (void (*)( ::Awesomium::WebView &,unsigned
char*,int,int ))(&WebView_wrapper::render),
bp::with_custodian_and_ward_postcall< 1, 2 >() ))

static void render( ::Awesomium::WebView& instance, unsigned char*
destination, int destRowSpan, int destDepth ){
instance.render( destination, destRowSpan, destDepth, 0 );

Hopefully it's something fairly simple to solve. Like I mentioned I
don't have too much experience with using boost.python or py++, so
forgive me if it's something fairly obvious. We'll probably be
releasing the port once we have everything working, there are a few
other things I still have to sort out with the bindings, but it's
almost done.


24-08-2009 11:22:15

In the Python-Ogre code generation I look for the char * and change them to unsigned int's which them allows them to work with CTYPES..

it's done in the code_generators/common/ -- function Auto_Functional_Transformation

Basically it uses the add_tranformation function of Py++ function -- something like
fun.add_transformation( ft.modify_type(arg_position,_ReturnUnsignedInt ) )



24-08-2009 11:55:51

Ah, thank you very much. I'll let you know how it goes :)