1

I am using ffmpeg, hardware acceleration and directx 9 for video stream application. The application includes c# for user interface and c++ for rendering. At the beginning, I used directx for simple overlays like line, rectangle, polygon, triangle, text etc. But now, I need more complex overlays. Then, I think to use directx for video and GDI for overlays.

I tried to call GDI fuction in c# side for the same handle when directx Present is finished. Actually it works but overlay, that is drawn by GDI, is flickering.

I changed PresentationInterval in D3DPRESENT_PARAMETERS to D3DPRESENT_INTERVAL_TWO and D3DPRESENT_INTERVAL_THREE. Result is application crashed.

I called LockWindowUpdate(myHandle) before directx Present and called LockWindowUpdate(IntPtr.Zero) after GDI function. Result is application crashed.

1.Is drawing overlay with GDI on directx a nice solution?
If YES, is there a way to do it without flickering?
If NO, should i do all work with directx?

Update: Panel control , that displays video, is already set DoubleBuffered

System.Reflection.PropertyInfo prop =
             typeof(System.Windows.Forms.Control).GetProperty(
             "DoubleBuffered", 
             System.Reflection.BindingFlags.NonPublic |
             System.Reflection.BindingFlags.Instance);

prop.SetValue(displayPnl,true,null);
Ksilon
  • 66
  • 7
  • I'm totally not an expert here, but when I see _"GDI"_ and _"flickering"_ - I always start searching _"how to enable double buffering?"_ – vasily.sib Sep 19 '19 at 07:49
  • Sorry I forget to mention that my display panel is already DoubleBuffered, question is updated. Thanks for advice – Ksilon Sep 19 '19 at 08:20
  • 1
    Also I would like to notice, that just setting `someControl.DoubleBuffered = true;` doesn't work in all usecases (for example, this doesn't work for `TreeView` for sure), so you maybe intrerested in one of [this](https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/how-to-reduce-graphics-flicker-with-double-buffering-for-forms-and-controls), [this](http://gregback.net/double-buffered-panels-in-c.html) or [that](https://stackoverflow.com/a/818447/2716623) solution. – vasily.sib Sep 19 '19 at 08:26

0 Answers0