GetStatic<type>Field Routines - GetStaticBooleanField
NativeType GetStatic<type>Field
(JNIEnv *env, jclass clazz, jfieldID fieldID);
This family of accessor routines returns the value of a static field of an object. The field to access is specified by a field ID, which is obtained by calling
GetStaticFieldID()
. (GetStaticBooleanField)
The following table describes the family of get routine names and result types. You should replace type in GetStatic<type>Field with the Java type of the field, or one of the actual static field accessor routine names from the table, and replace NativeType with the corresponding native type for that routine.
Table 4-5a GetStatic<type>Field Family of Accessor Routines
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-5b GetStatic<type>Field Family of Accessor Routines
PARAMETERS:
env
: the JNI interface pointer.clazz
: a Java class object.fieldID
: a static field ID.RETURNS:
Returns the content of the static field.
Example of GetStaticBooleanField
#include <jni.h> #include <awt.h> #include "Trace.h" #include "WindowsFlags.h" #include "dxInit.h" BOOL ddVramForced; // disable punting of ddraw buffers BOOL accelReset; // reset registry 2d acceleration settings BOOL useDD; // ddraw enabled flag BOOL useD3D; // d3d enabled flag BOOL forceD3DUsage; // force d3d on or off jboolean g_offscreenSharing; // JAWT accelerated surface sharing BOOL useDDLock; // Disabled for win2k/XP BOOL checkRegistry; // Diagnostic tool: outputs 2d registry settings BOOL disableRegistry; // Diagnostic tool: disables registry interaction BOOL setHighDPIAware; // Whether to set the high-DPI awareness flag extern WCHAR *j2dAccelKey; // Name of java2d root key extern WCHAR *j2dAccelDriverKey; // Name of j2d per-device key static jfieldID ddEnabledID; static jfieldID d3dEnabledID; static jfieldID d3dSetID; static jfieldID ddSetID; static jclass wFlagsClassID; void SetIDs(JNIEnv *env, jclass wFlagsClass) { wFlagsClassID = (jclass)env->NewGlobalRef(wFlagsClass); ddEnabledID = env->GetStaticFieldID(wFlagsClass, "ddEnabled", "Z"); d3dEnabledID = env->GetStaticFieldID(wFlagsClass, "d3dEnabled", "Z"); d3dSetID = env->GetStaticFieldID(wFlagsClass, "d3dSet", "Z"); ddSetID = env->GetStaticFieldID(wFlagsClass, "ddSet", "Z"); } BOOL GetStaticBoolean(JNIEnv *env, jclass wfClass, const char *fieldName) { jfieldID fieldID = env->GetStaticFieldID(wfClass, fieldName, "Z"); return env->GetStaticBooleanField(wfClass, fieldID); } jobject GetStaticObject(JNIEnv *env, jclass wfClass, const char *fieldName, const char *signature) { jfieldID fieldID = env->GetStaticFieldID(wfClass, fieldName, signature); return env->GetStaticObjectField(wfClass, fieldID); } void GetFlagValues(JNIEnv *env, jclass wFlagsClass) { useDD = env->GetStaticBooleanField(wFlagsClass, ddEnabledID); jboolean ddSet = env->GetStaticBooleanField(wFlagsClass, ddSetID); jboolean d3dEnabled = env->GetStaticBooleanField(wFlagsClass, d3dEnabledID); jboolean d3dSet = env->GetStaticBooleanField(wFlagsClass, d3dSetID); if (!d3dSet) { // Only check environment variable if user did not set Java // command-line parameter; values of sun.java2d.d3d override // any setting of J2D_D3D environment variable. char *d3dEnv = getenv("J2D_D3D"); if (d3dEnv) { if (strcmp(d3dEnv, "false") == 0) { // printf("Java2D Direct3D usage disabled by J2D_D3D env\n"); d3dEnabled = FALSE; d3dSet = TRUE; SetD3DEnabledFlag(env, d3dEnabled, d3dSet); } else if (strcmp(d3dEnv, "true") == 0) { // printf("Java2D Direct3D usage forced on by J2D_D3D env\n"); d3dEnabled = TRUE; d3dSet = TRUE; SetD3DEnabledFlag(env, d3dEnabled, d3dSet); } } } useD3D = d3dEnabled; forceD3DUsage = d3dSet; ddVramForced = GetStaticBoolean(env, wFlagsClass, "ddVramForced"); g_offscreenSharing = GetStaticBoolean(env, wFlagsClass, "offscreenSharingEnabled"); useDDLock = GetStaticBoolean(env, wFlagsClass, "ddLockEnabled"); jboolean ddLockSet = GetStaticBoolean(env, wFlagsClass, "ddLockSet"); accelReset = GetStaticBoolean(env, wFlagsClass, "accelReset"); checkRegistry = GetStaticBoolean(env, wFlagsClass, "checkRegistry"); disableRegistry = GetStaticBoolean(env, wFlagsClass, "disableRegistry"); jstring javaVersionString = (jstring)GetStaticObject(env, wFlagsClass, "javaVersion", "Ljava/lang/String;"); jboolean isCopy; const jchar *javaVersion = env->GetStringChars(javaVersionString, &isCopy); jsize versionLength = env->GetStringLength(javaVersionString); size_t j2dRootKeyLength = wcslen(J2D_ACCEL_KEY_ROOT); j2dAccelKey = (WCHAR *)safe_Calloc((j2dRootKeyLength + versionLength + 2), sizeof(WCHAR)); wcscpy(j2dAccelKey, J2D_ACCEL_KEY_ROOT); wcscat(j2dAccelKey, (WCHAR *)javaVersion); wcscat(j2dAccelKey, L"\\"); j2dAccelDriverKey = (WCHAR *)safe_Calloc((wcslen(j2dAccelKey) + wcslen(J2D_ACCEL_DRIVER_SUBKEY) + 1), sizeof(WCHAR)); wcscpy(j2dAccelDriverKey, j2dAccelKey); wcscat(j2dAccelDriverKey, J2D_ACCEL_DRIVER_SUBKEY); env->ReleaseStringChars(javaVersionString, javaVersion); setHighDPIAware = (IS_WINVISTA && GetStaticBoolean(env, wFlagsClass, "setHighDPIAware")); // Change default value of some flags based on OS-specific requirements if (IS_WINVISTA && !(ddSet && useDD)) { // Disable ddraw on vista due to issues with mixing GDI and ddraw // unless ddraw is forced SetDDEnabledFlag(env, FALSE); J2dRlsTraceLn(J2D_TRACE_WARNING, "GetFlagValues: DDraw/D3D is disabled on Windows Vista"); } #ifdef __WIN32OS2__ SetD3DEnabledFlag(env, FALSE, FALSE); J2dRlsTraceLn(J2D_TRACE_WARNING, "GetFlagValues: D3D is disabled on OS/2"); #else if (IS_NT && !(IS_WIN2000)) { // Do not enable d3d on NT4; d3d is only supported through // software on that platform SetD3DEnabledFlag(env, FALSE, FALSE); J2dRlsTraceLn(J2D_TRACE_WARNING, "GetFlagValues: D3D is disabled on Win NT"); } if (IS_WIN64 && !d3dSet) { // Only enable d3d on Itanium if user forces it on. // D3d was not functioning on initial XP Itanium releases // so we do not want it suddenly enabled in the field without // having tested that codepath first. SetD3DEnabledFlag(env, FALSE, FALSE); J2dRlsTraceLn(J2D_TRACE_WARNING, "GetFlagValues: D3D is disabled on 64-bit OSs"); } #endif if (IS_WIN2000 && !ddLockSet) { // valid for win2k, XP, and future OSs // Fix for cursor flicker on win2k and XP (bug 4409306). The // fix is to avoid using DDraw for locking the // screen. Ideally, we will handle most operations to the // screen through new GDI Blt loops (GDIBlitLoops.cpp), // but failing there we will punt to GDI instead of DDraw for // locking the screen. useDDLock = FALSE; J2dRlsTraceLn(J2D_TRACE_WARNING, "GetFlagValues: DDraw screen locking is "\ "disabled (W2K, XP+)"); } J2dTraceLn(J2D_TRACE_INFO, "WindowsFlags (native):"); J2dTraceLn1(J2D_TRACE_INFO, " ddEnabled = %s", (useDD ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " ddSet = %s", (ddSet ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " ddVramForced = %s", (ddVramForced ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " d3dEnabled = %s", (useD3D ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " d3dSet = %s", (forceD3DUsage ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " ddLockEnabled = %s", (useDDLock ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " ddLockSet = %s", (ddLockSet ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " offscreenSharing = %s", (g_offscreenSharing ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " accelReset = %s", (accelReset ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " checkRegistry = %s", (checkRegistry ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " disableRegistry = %s", (disableRegistry ? "true" : "false")); J2dTraceLn1(J2D_TRACE_INFO, " setHighDPIAware = %s", (setHighDPIAware ? "true" : "false")); }