jdk/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7943 5229d3140556
child 9842 7471b93771b0
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7943
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3928
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <awt.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <sun_awt_Win32GraphicsEnvironment.h>
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
    28
#include <sun_awt_Win32FontManager.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "awt_Canvas.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt_Win32GraphicsDevice.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "Devices.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "WindowsFlags.h"
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
    33
#include "DllUtil.h"
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    34
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    35
BOOL DWMIsCompositionEnabled();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
void initScreens(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    if (!Devices::UpdateInstance(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        JNU_ThrowInternalError(env, "Could not update the devices array.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * This function attempts to make a Win32 API call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *   BOOL SetProcessDPIAware(VOID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * which is only present on Windows Vista, and which instructs the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Vista Windows Display Manager that this application is High DPI Aware
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * and does not need to be scaled by the WDM and lied about the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * actual system dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
SetProcessDPIAwareProperty()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
{
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    56
    typedef BOOL (WINAPI SetProcessDPIAwareFunc)(void);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static BOOL bAlreadySet = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // setHighDPIAware is set in WindowsFlags.cpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    if (!setHighDPIAware || bAlreadySet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    bAlreadySet = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    66
    HMODULE hLibUser32Dll = ::LoadLibrary(TEXT("user32.dll"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    if (hLibUser32Dll != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        SetProcessDPIAwareFunc *lpSetProcessDPIAware =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            (SetProcessDPIAwareFunc*)GetProcAddress(hLibUser32Dll,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                                    "SetProcessDPIAware");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (lpSetProcessDPIAware != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            lpSetProcessDPIAware();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        ::FreeLibrary(hLibUser32Dll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    79
#define DWM_COMP_UNDEFINED (~(TRUE|FALSE))
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    80
static int dwmIsCompositionEnabled = DWM_COMP_UNDEFINED;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    81
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    82
/**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    83
 * This function is called from toolkit event handling code when
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    84
 * WM_DWMCOMPOSITIONCHANGED event is received
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    85
 */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    86
void DWMResetCompositionEnabled() {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    87
    dwmIsCompositionEnabled = DWM_COMP_UNDEFINED;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    88
    (void)DWMIsCompositionEnabled();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    89
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    90
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    91
/**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    92
 * Returns true if dwm composition is enabled, false if it is not applicable
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    93
 * (if the OS is not Vista) or dwm composition is disabled.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    94
 */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    95
BOOL DWMIsCompositionEnabled() {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    96
    // cheaper to check than whether it's vista or not
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    97
    if (dwmIsCompositionEnabled != DWM_COMP_UNDEFINED) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    98
        return (BOOL)dwmIsCompositionEnabled;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    99
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   100
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   101
    if (!IS_WINVISTA) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   102
        dwmIsCompositionEnabled = FALSE;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   103
        return FALSE;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   104
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   105
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   106
    BOOL bRes = FALSE;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   107
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   108
    try {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   109
        BOOL bEnabled;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   110
        HRESULT res = DwmAPI::DwmIsCompositionEnabled(&bEnabled);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   111
        if (SUCCEEDED(res)) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   112
            bRes = bEnabled;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   113
            J2dTraceLn1(J2D_TRACE_VERBOSE, " composition enabled: %d",bRes);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   114
        } else {
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   115
            J2dTraceLn1(J2D_TRACE_ERROR,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   116
                    "IsDWMCompositionEnabled: error %x when detecting"\
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   117
                    "if composition is enabled", res);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   118
        }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   119
    } catch (const DllUtil::Exception &) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   120
        J2dTraceLn(J2D_TRACE_ERROR,
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   121
                "IsDWMCompositionEnabled: no DwmIsCompositionEnabled() "\
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 1954
diff changeset
   122
                "in dwmapi.dll or dwmapi.dll cannot be loaded");
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   123
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   124
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   125
    dwmIsCompositionEnabled = bRes;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   126
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   127
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   128
    JNU_CallStaticMethodByName(env, NULL,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   129
                              "sun/awt/Win32GraphicsEnvironment",
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   130
                              "dwmCompositionChanged", "(Z)V", (jboolean)bRes);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   131
    return bRes;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   132
}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   133
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * Class:     sun_awt_Win32GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * Method:    initDisplay
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
Java_sun_awt_Win32GraphicsEnvironment_initDisplay(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                                  jclass thisClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    // This method needs to be called prior to any display-related activity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    SetProcessDPIAwareProperty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   146
    DWMIsCompositionEnabled();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   147
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    initScreens(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * Class:     sun_awt_Win32GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * Method:    getNumScreens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
Java_sun_awt_Win32GraphicsEnvironment_getNumScreens(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                                    jobject thisobj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    Devices::InstanceAccess devices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    return devices->GetNumDevices();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * Class:     sun_awt_Win32GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * Method:    getDefaultScreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
Java_sun_awt_Win32GraphicsEnvironment_getDefaultScreen(JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                                       jobject thisobj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    return AwtWin32GraphicsDevice::GetDefaultDeviceIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
/*
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   177
 * Class:     sun_awt_Win32FontManager
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * Method:    registerFontWithPlatform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * Signature: (Ljava/lang/String;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
JNIEXPORT void JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   182
Java_sun_awt_Win32FontManager_registerFontWithPlatform(JNIEnv *env,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   183
                                                       jclass cl,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   184
                                                       jstring fontName)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
{
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 888
diff changeset
   186
    LPTSTR file = (LPTSTR)JNU_GetStringPlatformChars(env, fontName, JNI_FALSE);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 888
diff changeset
   187
    if (file) {
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 888
diff changeset
   188
        ::AddFontResourceEx(file, FR_PRIVATE, NULL);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 888
diff changeset
   189
        JNU_ReleaseStringPlatformChars(env, fontName, file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
/*
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   195
 * Class:     sun_awt_Win32FontManagerEnvironment
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * Method:    deRegisterFontWithPlatform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * Signature: (Ljava/lang/String;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * This method intended for future use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
JNIEXPORT void JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   202
Java_sun_awt_Win32FontManager_deRegisterFontWithPlatform(JNIEnv *env,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   203
                                                         jclass cl,
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   204
                                                         jstring fontName)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
{
1954
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 888
diff changeset
   206
    LPTSTR file = (LPTSTR)JNU_GetStringPlatformChars(env, fontName, JNI_FALSE);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 888
diff changeset
   207
    if (file) {
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 888
diff changeset
   208
        ::RemoveFontResourceEx(file, FR_PRIVATE, NULL);
b93b85df3211 6585765: RFE: Remove Unicows-related code from AWT
art
parents: 888
diff changeset
   209
        JNU_ReleaseStringPlatformChars(env, fontName, file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
#define EUDCKEY_JA_JP  L"EUDC\\932"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
#define EUDCKEY_ZH_CN  L"EUDC\\936"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
#define EUDCKEY_ZH_TW  L"EUDC\\950"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
#define EUDCKEY_KO_KR  L"EUDC\\949"
7943
5229d3140556 6951501: EUDC character is not displayed on Swing
prr
parents: 7668
diff changeset
   217
#define EUDCKEY_EN_US  L"EUDC\\1252"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
#define LANGID_JA_JP   0x411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
#define LANGID_ZH_CN   0x0804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#define LANGID_ZH_SG   0x1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
#define LANGID_ZH_TW   0x0404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
#define LANGID_ZH_HK   0x0c04
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
#define LANGID_ZH_MO   0x1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
#define LANGID_KO_KR   0x0412
7943
5229d3140556 6951501: EUDC character is not displayed on Swing
prr
parents: 7668
diff changeset
   225
#define LANGID_EN_US   0x0409
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
JNIEXPORT jstring JNICALL
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 2472
diff changeset
   229
Java_sun_awt_Win32FontManager_getEUDCFontFile(JNIEnv *env, jclass cl) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    int    rc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    HKEY   key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    DWORD  type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    WCHAR  fontPathBuf[MAX_PATH + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    unsigned long fontPathLen = MAX_PATH + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    WCHAR  tmpPath[MAX_PATH + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    LPWSTR fontPath = fontPathBuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    LPWSTR eudcKey = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    LANGID langID = GetSystemDefaultLangID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    //lookup for encoding ID, EUDC only supported in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    //codepage 932, 936, 949, 950 (and unicode)
7943
5229d3140556 6951501: EUDC character is not displayed on Swing
prr
parents: 7668
diff changeset
   242
    // On Windows 7, at least for me, it shows up in Cp1252 if
5229d3140556 6951501: EUDC character is not displayed on Swing
prr
parents: 7668
diff changeset
   243
    // I create a custom font. Might as well support that as it makes
5229d3140556 6951501: EUDC character is not displayed on Swing
prr
parents: 7668
diff changeset
   244
    // verification easier.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    if (langID == LANGID_JA_JP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        eudcKey = EUDCKEY_JA_JP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    } else if (langID == LANGID_ZH_CN || langID == LANGID_ZH_SG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        eudcKey = EUDCKEY_ZH_CN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    } else if (langID == LANGID_ZH_HK || langID == LANGID_ZH_TW ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
               langID == LANGID_ZH_MO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      eudcKey = EUDCKEY_ZH_TW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    } else if (langID == LANGID_KO_KR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        eudcKey = EUDCKEY_KO_KR;
7943
5229d3140556 6951501: EUDC character is not displayed on Swing
prr
parents: 7668
diff changeset
   254
    } else if (langID == LANGID_EN_US) {
5229d3140556 6951501: EUDC character is not displayed on Swing
prr
parents: 7668
diff changeset
   255
        eudcKey = EUDCKEY_EN_US;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    rc = RegOpenKeyEx(HKEY_CURRENT_USER, eudcKey, 0, KEY_READ, &key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    if (rc != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    rc = RegQueryValueEx(key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                         L"SystemDefaultEUDCFont",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                         0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                         &type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                         (LPBYTE)fontPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                         &fontPathLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    if (rc != ERROR_SUCCESS || type != REG_SZ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    fontPath[fontPathLen] = L'\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    if (wcsstr(fontPath, L"%SystemRoot%")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        //if the fontPath includes %SystemRoot%
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        LPWSTR systemRoot = _wgetenv(L"SystemRoot");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (systemRoot != NULL
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   279
            && swprintf(tmpPath, MAX_PATH, L"%s%s", systemRoot, fontPath + 12) != -1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            fontPath = tmpPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    } else if (wcscmp(fontPath, L"EUDC.TTE") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        //else to see if it only inludes "EUDC.TTE"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        WCHAR systemRoot[MAX_PATH + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (GetWindowsDirectory(systemRoot, MAX_PATH + 1) != 0) {
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   289
            swprintf(tmpPath, MAX_PATH, L"%s\\FONTS\\EUDC.TTE", systemRoot);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            fontPath = tmpPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    return JNU_NewStringPlatform(env, fontPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * Class:     sun_awt_Win32GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * Method:    getXResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
Java_sun_awt_Win32GraphicsEnvironment_getXResolution(JNIEnv *env, jobject wge)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    HWND hWnd = ::GetDesktopWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    HDC hDC = ::GetDC(hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    jint result = ::GetDeviceCaps(hDC, LOGPIXELSX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    ::ReleaseDC(hWnd, hDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 * Class:     sun_awt_Win32GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 * Method:    getYResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
Java_sun_awt_Win32GraphicsEnvironment_getYResolution(JNIEnv *env, jobject wge)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    TRY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    HWND hWnd = ::GetDesktopWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    HDC hDC = ::GetDC(hWnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    jint result = ::GetDeviceCaps(hDC, LOGPIXELSY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    ::ReleaseDC(hWnd, hDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    CATCH_BAD_ALLOC_RET(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
}
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   336
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   337
/*
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   338
 * Class:     sun_awt_Win32GraphicsEnvironment
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   339
 * Method:    isVistaOS
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   340
 * Signature: ()Z
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   341
 */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   342
JNIEXPORT jboolean JNICALL Java_sun_awt_Win32GraphicsEnvironment_isVistaOS
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   343
  (JNIEnv *env, jclass wgeclass)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   344
{
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   345
    return IS_WINVISTA;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   346
}