Directx control in browser plugin

青春壹個敷衍的年華 提交于 2019-11-28 12:39:05

问题


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.

  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) {
    ...
}


来源:https://stackoverflow.com/questions/6097069/directx-control-in-browser-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!