Issue #5066: Create From Screenshot Crash.
(cherry picked from commit 029ffd5778
)
This commit is contained in:
@ -43,6 +43,9 @@ typedef enum _DWMWINDOWATTRIBUTE {
|
||||
DWMWA_LAST
|
||||
} DWMWINDOWATTRIBUTE;
|
||||
|
||||
typedef HRESULT (WINAPI* DWMISCOMPOSITIONENABLED) (BOOL *pfEnabled);
|
||||
DWMISCOMPOSITIONENABLED DwmIsCompositionEnabled;
|
||||
|
||||
static HMODULE dwmApi = NULL;
|
||||
|
||||
void
|
||||
@ -62,7 +65,8 @@ LoadRequiredDwmFunctions (void)
|
||||
if (! dwmApi) return FALSE;
|
||||
|
||||
DwmGetWindowAttribute = (DWMGETWINDOWATTRIBUTE) GetProcAddress (dwmApi, "DwmGetWindowAttribute");
|
||||
if (! DwmGetWindowAttribute)
|
||||
DwmIsCompositionEnabled = (DWMISCOMPOSITIONENABLED) GetProcAddress (dwmApi, "DwmIsCompositionEnabled");
|
||||
if (! (DwmGetWindowAttribute && DwmIsCompositionEnabled))
|
||||
{
|
||||
UnloadRequiredDwmFunctions ();
|
||||
return FALSE;
|
||||
|
@ -106,6 +106,8 @@ static gboolean doCaptureBitBlt (HWND selectedHwnd
|
||||
BOOL CALLBACK dialogProc (HWND, UINT, WPARAM, LPARAM);
|
||||
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
gboolean isDwmCompositionEnabled (void);
|
||||
|
||||
/* Data structure holding data between runs */
|
||||
typedef struct {
|
||||
gint root;
|
||||
@ -480,7 +482,7 @@ GetAccurateWindowRect_MonitorEnumProc (HMONITOR hMonitor,
|
||||
if (! (*rectScreens))
|
||||
*rectScreens = (RECT*) g_malloc (sizeof (RECT)*(rectScreensCount+1));
|
||||
else
|
||||
*rectScreens = (RECT*) g_realloc (rectScreens,
|
||||
*rectScreens = (RECT*) g_realloc (*rectScreens,
|
||||
sizeof (RECT)*(rectScreensCount+1));
|
||||
|
||||
if (*rectScreens == NULL)
|
||||
@ -578,6 +580,24 @@ GetAccurateWindowRect (HWND hwndTarget,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean isDwmCompositionEnabled (void)
|
||||
{
|
||||
HRESULT err;
|
||||
BOOL result;
|
||||
|
||||
if (LoadRequiredDwmFunctions ())
|
||||
{
|
||||
err = DwmIsCompositionEnabled (&result);
|
||||
if (err != S_OK)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* doCapture
|
||||
*
|
||||
@ -598,6 +618,8 @@ doCapture (HWND selectedHwnd)
|
||||
/* Are we capturing a window or the whole screen */
|
||||
if (selectedHwnd)
|
||||
{
|
||||
gboolean compositionEnabled;
|
||||
|
||||
if (! GetAccurateWindowRect (selectedHwnd, &rect))
|
||||
/* For some reason it works only if we return here TRUE. strange... */
|
||||
return TRUE;
|
||||
@ -605,8 +627,9 @@ doCapture (HWND selectedHwnd)
|
||||
/* First try to capture the window with the magnification api.
|
||||
* This will solve the bug https://bugzilla.gnome.org/show_bug.cgi?id=793722/
|
||||
*/
|
||||
compositionEnabled = isDwmCompositionEnabled ();
|
||||
|
||||
if (! doCaptureMagnificationAPI (selectedHwnd, rect))
|
||||
if (! (compositionEnabled && doCaptureMagnificationAPI (selectedHwnd, rect)))
|
||||
{
|
||||
/* If for some reason this capture method failed then
|
||||
* capture the window with the normal method:
|
||||
|
Reference in New Issue
Block a user