0

I have to insert a directx control to a firebreath plug in for a browser. Can anyone post a sample how to do it? I have no knowledge in plugins...

10x

gln
  • 1,011
  • 5
  • 31
  • 61

1 Answers1

2

I don't have an example that I can give you, but I can tell you roughly what you need to do.

First, read this: http://colonelpanic.net/2010/11/firebreath-tips-drawing-on-windows/

That will give you an overview of how drawing works in FireBreath.

First, you set everything up when handling AttachedEvent.

  1. Create a new thread to handle drawing (your DirectX drawing must not be on the main thread)
  2. Get the HWND from the PluginWindowWin object (cast the FB::PluginWindow* to FB::PluginWindowWin and call getHWND())
  3. Initialize DirectX on the secondary thread with the provided HWND. Set up some form of render loop and make sure you can send it commands from the main thread.
  4. Handle the RefreshEvent (comes from WM_PAINT) by posting a message somehow to your render thread so it redraws when that event is fired.
  5. Make sure that on DetachedEvent you shut down your thread.

You need to do all initialization, drawing, and shutdown of the DirectX stuff on the same thread. This needs to all happen on a thread that is not just the main thread (don't just use timers) because otherwise it'll mess up the browser rendering context on some versions of Firefox -- not sure why.

Anyway, hope this helps.

Edit: To pass parameters into the start of a boost::thread, should that be the threading abstraction you decide to use, simply pass it in as a parameter.

boost::thread t(&MyClass::someFunction, this, theHWND);

That will start the thread. In actuality, you probably want to make the thread a class variable or something so that you can access it later -- remember that you'll want the thread to have stopped during the handling of DetachedEvent. For messages I'd probably use FB::SafeQueue, which is a threadsafe queue that is part of FireBreath. Look at the sources for how to use it; it's pretty straightforward (stolen from a codeproject article, I think).

// Inside MyClass
void someFunction(HWND theHWND) {
    ...
}
taxilian
  • 14,229
  • 4
  • 34
  • 73
  • 10x! that helps. can you provide an example of drwing a simple picture? – gln May 25 '11 at 06:51
  • Do you mean to use a Boost::thread? How do I pass the HWND as paramter? Do I have to create a wrapper class? – gln May 25 '11 at 10:46
  • 1
    You can use whatever thread abstraction you want. You don't need a wrapper class with boost::thread. Learning how to use boost::thread properly is really outside of the scope of this question; there are plenty of examples available. I've updated my answer to include a rough example. I don't have *any* examples I can give you, but if you do some homework and try some things that should get you going. – taxilian May 26 '11 at 05:35