As I mentioned in an earlier thread I've been working on rendering text with a Device Context. Everything is working fine now, but it would seem that the GetDC() function is really slow. This wouldn't be a problem if I only had to call it once per frame, but apparently I'm not allowed to blit from the surface before I have released the Device Context. If I try I get an exception with the content "One or more surfaces are locked, preventing operation". This means that I will have to get and release the Device Context each time I need to draw some text, and seeing that this process easily takes about 25 ms this quickly becomes a major problem. Is there any way to blit from a surface without releasing the Device Context? If not, can you think of any other way to make this run faster?
Thanks in advance.
Per Rasmussen.
Hello Per!
If you need to use Device Contexts on every frame, you could do as follows:
1. Modify GapiApplication so you call CGapiDisplay::CreateOffscreenDisplay instead of CGapiDisplay::OpenDisplay. This means that your backbuffer will be stored as a Device Context DIB image. You then blit the backbuffer to the display using DC BitBlt instead of CGapiDisplay::Flip.
2. Modify the code inside CGapiSurface (assuming you have a GapiDraw source code license) so that each surface memory is allocated as a DC DIB image instead of just a memory block. You can then change the GetDC function of CGapiSurface so that it then just returns the handle to the DIB image that the surface represents.
All this is fairly simple to implement and could probably be done within an hour or so, assuming you have access to a source code license. The results would be a slightly slower final blit to the screen (since DC is used instead of DirectDraw) but all GetDC operations would be done with zero overhead.
Sincerely
Johan
Hi Johan,
Thank you for your reply. Honestly, I'm afraid the source code license is a bit outside of my budget. Is there no way to do this with the binary license?
Per Rasmussen.
Hi Per,
Can you send me a PM and we'll see how we can resolve this.
Sincerely
Johan