问题
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
回答1:
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.
- Create a new thread to handle drawing (your DirectX drawing must not be on the main thread)
- Get the HWND from the PluginWindowWin object (cast the FB::PluginWindow* to FB::PluginWindowWin and call getHWND())
- 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.
- Handle the RefreshEvent (comes from WM_PAINT) by posting a message somehow to your render thread so it redraws when that event is fired.
- 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) {
...
}
来源:https://stackoverflow.com/questions/6097069/directx-control-in-browser-plugin