Commit 14236761 authored by Simon Mueller's avatar Simon Mueller Committed by Jehan

Bug 793722 - Capture screenshot of single window fails if...

... thewindow is IE 11.

The screenshot plugin for windows had a problem when capturing
applications that use hardware rendering acceleration (e.g.
Chromium-based Apps, IE11). Those applications seem to render their
content to a device context (DC) that is different from the one that can
be retrieved via GetDCEx(hWnd). So a screenshot that simply copies the
main window DC will be incomplete (see bug attachment) or just plain

This patch removes the code that uses GetDCEx for single window
screenshots and always uses the display device context instead. This
makes sure that all window contents are actually visible in the
screenshot. With this change, we now have to set the source coordinates
in the call to BitBlt() to the window's coordinates to exclude
everything that isn't the window from the screenshot when doing a single
window screenshot.

Review comment by Jehan: as Simon notes in bug 793722, there is a
regression though, which is that this new code cannot capture any part
of a window which is not in any screen. This is still an improvement
because at least for what is on screen, we always get exactly the same
as what is displayed. This is especially true since hardware-accelerated
applications are more and more common. So let's push this first commit
and hope for further improvements.
parent cd2fcc3d
......@@ -407,7 +407,7 @@ primDoWindowCapture (HDC hdcWindow,
if (!BitBlt(hdcCompat, 0,0,
width, height,
hdcWindow, 0,0,
hdcWindow, rect.left,,
formatWindowsError (buffer, sizeof buffer);
......@@ -433,7 +433,6 @@ doCapture (HWND selectedHwnd)
HDC hdcSrc;
HDC hdcCompat;
HRGN capRegion;
HWND oldForeground;
RECT rect;
......@@ -443,10 +442,17 @@ doCapture (HWND selectedHwnd)
Sleep (500 + winsnapvals.delay * 1000);
/* Get the device context for the whole screen
* even if we just want to capture a window.
* this will allow to capture applications that
* don't render to their main window's device
* context (e.g. browsers).
hdcSrc = CreateDC (TEXT("DISPLAY"), NULL, NULL, NULL);
/* Are we capturing a window or the whole screen */
if (selectedHwnd)
/* Set to foreground window */
oldForeground = GetForegroundWindow ();
SetForegroundWindow (selectedHwnd);
......@@ -456,27 +462,10 @@ doCapture (HWND selectedHwnd)
/* Build a region for the capture */
GetWindowRect (selectedHwnd, &rect);
capRegion = CreateRectRgn (rect.left,,
rect.right, rect.bottom);
if (!capRegion)
formatWindowsError (buffer, sizeof buffer);
g_error ("Error creating region: %s", buffer);
return FALSE;
/* Get the device context for the selected
* window. Create a memory DC to use for the
* Bit copy.
hdcSrc = GetDCEx (selectedHwnd, capRegion,
/* Get the device context for the whole screen */
hdcSrc = CreateDC ("DISPLAY", NULL, NULL, NULL);
/* Get the screen's rectangle */ = 0;
rect.bottom = GetDeviceCaps (hdcSrc, VERTRES);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment