I haven't updated my blog for a long time. I will continue to work hard today.
Keep going
Work to continue
The dream must continue!
I wrote an article about DirectX screenshots.ArticleSome netizens commented on the black screen issue, so they studied it over the past few days and shared it with everyone.
Why is the screen black?
In a word, the black screen is caused by ddraw acceleration!
Let's talk about the display principle of DirectX. The data on the screen we usually see is sent to the display through the primary surface. What is the primary surface? The Chinese name is the primary display surface. That is to say, the image data on the current screen comes from this surface. In addition to the primary surface accidents, there are also off-screen surfaces, which are called offscreensuface. The data on this surface is not directly displayed on the screen. Common screenshot functions are also implemented by intercepting data in the primary surface. Most video playing software is now written in ddraw (now ddraw has been integrated into the graphics score of DirectX, and the word ddraw has become history .), In addition, we use a surface called overlay. Our commonly used screenshot functions intercept data in a normal primary surface and cannot intercept data in the overlay surface, microsoft does not provide public APIs to obtain data in Overlay surface. Therefore, black screens are not surprising. The following is the black screen of Windows Media Player using Overlay Technology.
Overlay is only supported by hardware, and ddraw does not use software to implement this function. The special feature of this surface is that it is equivalent to a plastic sheet on the screen, that is, if this surface is used, it is located at the front of all surfaces. When the display device displays data to the screen, it first determines whether the position has an overlay. If yes, it displays the pixels in the overlay. If not, it uses the pixels in the primary surface. Therefore, when you open a player to play a video, you will find that the player window is black. The reason is that this area corresponds to overlay. Of course, it cannot be intercepted.
For more information about overlay surfaces, see here.
How to Avoid black screen
In addition to the rendering mode of ddraw, most software also provides a software Renderer mode, that is, the software mode, which is used only when the ddraw acceleration is unavailable, so one way to avoid the black screen is to disable the ddraw acceleration and force the software to use the software Renderer mode. In this way, the overlay surface will not exist and the screen will not be black. The specific method is as follows:
Method 1: use the software settings to disable the overlay technology. This method only affects the software itself. Take the common Windows Media Player as an example and set the following settings (overwrite is used to remove the overlay technology, in this way, the software will not use overlay surface)
Method 2: Use the DirectX Control Panel to disable ddraw acceleration. The method above is equivalent to closing the branch switch, and this method is equivalent to closing the General gate, no other software in the system can use ddraw acceleration. If the DirectX SDK is installed, enter dxdiag in the running column to open the DirectX control panel. The settings are as follows.
Method 3: Another method is to useProgramOverlay surface is occupied. This method is too troublesome and won't be used by ordinary people, because the average independent graphics card supports overlay surface and supports a limited number, if we use a program to occupy all the overlay surfaces in advance, other programs will no longer be used, so it will not cause a black screen. Before using this method, you should first check whether your video card supports Overlay Technology and how many. If the DirectX SDK is installed, you can expand it in sequence: Start-Program-Microsoft DirectX SDK-DirectX utilities-DirectX caps viewer. As you can see, my video card supports an overlay surface, I have not played any advanced graphics card, but I have never seen any graphics card that supports multiple overlay. Which of the following has a good graphics card, and I will also send a picture to show it to my younger brother.
However, this method has one drawback: if the software does not support the software Renderer mode, if you first use the program to occupy the overlay and then start the playing software, it will cause an error.
The above methods are actually one of them. They are not allowed to use overlay surface. In addition, these methods all have the disadvantage of being preemptible, that is, before the software is started (or, specifically, before the video is played), and then start the software. If the video has been played (overlay is occupied), all these methods will be invalid.
In addition, you can also use off-the-shelf software. Many software can handle black screens, such as hypersnap 6.
How to intercept data in overlay?
This is not a simple problem. I have searched the internet for a long time and have not found a proper solution. It is said that the hook technology may be used, but I am not familiar with the hook, so I didn't try it either. I hope anyone who is interested can try it. For this topic, I have a post in the Google discussion group, which will introduce more details. If you are interested, please refer to here.
Challenge!
Here is a demo about overlay surface (download ). This demo comes from the DirectX 7 SDK and is a flying mosquito. Because the version is old, it is no longer common on the Internet. According to the above study, it is no easy task to capture this small mosquito. If you are interested, try it!
References
Hardware overlay http://www.fox-magic.com/sva_overlays.php