Skip to content

Commit

Permalink
JBR-6754 setting nopixfmt in case of running on Remote Desktop
Browse files Browse the repository at this point in the history
(cherry picked from commit 4329a53)
  • Loading branch information
dmitriimorskii authored and vprovodin committed Nov 18, 2024
1 parent d296d2a commit f27dcf1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ public class Win32GraphicsDevice extends GraphicsDevice implements
@SuppressWarnings("removal")
String nopixfmt = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.awt.nopixfmt"));
pfDisabled = (nopixfmt != null);
pfDisabled = (nopixfmt != null || isRemoteConnection() == 1);
initIDs();
}

private static native void initIDs();

private native void initDevice(int screen);
private static native int isRemoteConnection();
private static native void initNativeScale(int screen);
private static native void setNativeScale(int screen, float scaleX, float scaleY);
private static native float getNativeScaleX(int screen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <awt.h>
#include <sun_awt_Win32GraphicsDevice.h>
#include <wtsapi32.h>
#include "awt_Canvas.h"
#include "awt_Win32GraphicsDevice.h"
#include "awt_Window.h"
Expand Down Expand Up @@ -1132,6 +1133,43 @@ JNIEXPORT jint JNICALL Java_sun_awt_Win32GraphicsDevice_getDefaultPixIDImpl
CATCH_BAD_ALLOC_RET(0);
}

typedef BOOL (WINAPI *pfn_WTSQuerySessionInformationW)(HANDLE, DWORD, WTS_INFO_CLASS, LPWSTR*, DWORD*);
typedef BOOL (WINAPI *pfn_WTSFreeMemory)(PVOID);

/*
* Class: sun_awt_Win32GraphicsDevice
* Method: isRemoteConnection
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_sun_awt_Win32GraphicsDevice_isRemoteConnection
(JNIEnv *, jclass) {

TRY;

HMODULE libWtsapi32 = JDK_LoadSystemLibrary("Wtsapi32.dll");
CHECK_NULL_RETURN(libWtsapi32, JNI_ERR);
pfn_WTSQuerySessionInformationW fn_WTSQuerySessionInformationW = (pfn_WTSQuerySessionInformationW)
GetProcAddress(libWtsapi32, "WTSQuerySessionInformationW");
CHECK_NULL_RETURN(fn_WTSQuerySessionInformationW, JNI_ERR);
pfn_WTSFreeMemory fn_WTSFreeMemory = (pfn_WTSFreeMemory)
GetProcAddress(libWtsapi32, "WTSFreeMemory");
CHECK_NULL_RETURN(fn_WTSFreeMemory, JNI_ERR);

LPWSTR buffer = nullptr;
DWORD bufferLen = 0;
int res = fn_WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientProtocolType,
&buffer, &bufferLen);
if (res > 0 && bufferLen > 0) {
USHORT protocol = (USHORT) *buffer;
bool isRemoteConnection = (protocol == WTS_PROTOCOL_TYPE_RDP) || (protocol == WTS_PROTOCOL_TYPE_ICA);
fn_WTSFreeMemory(buffer);
return isRemoteConnection;
}
return JNI_ERR;

CATCH_BAD_ALLOC_RET(JNI_ERR);
}

/*
* Class: sun_awt_Win32GraphicsDevice
* Method: enterFullScreenExclusive
Expand Down

0 comments on commit f27dcf1

Please sign in to comment.