Skip to content

Commit

Permalink
8307160: Fix AWT/2D/A11Y to support the permissive- flag on the Micro…
Browse files Browse the repository at this point in the history
…soft Visual C compiler

Co-authored-by: Magnus Ihse Bursie <ihse@openjdk.org>
Reviewed-by: jwaters, prr
  • Loading branch information
TheShermanTanker and magicus committed Apr 5, 2024
1 parent 8efe569 commit 8bc1867
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 144 deletions.
4 changes: 2 additions & 2 deletions make/autoconf/flags-cflags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
# The -utf-8 option sets source and execution character sets to UTF-8 to enable correct
# compilation of all source files regardless of the active code page on Windows.
TOOLCHAIN_CFLAGS_JVM="-nologo -MD -Zc:preprocessor -Zc:strictStrings -Zc:inline -permissive- -utf-8 -MP"
TOOLCHAIN_CFLAGS_JDK="-nologo -MD -Zc:preprocessor -Zc:strictStrings -Zc:inline -utf-8 -Zc:wchar_t-"
TOOLCHAIN_CFLAGS_JVM="-nologo -MD -Zc:preprocessor -Zc:inline -permissive- -utf-8 -MP"
TOOLCHAIN_CFLAGS_JDK="-nologo -MD -Zc:preprocessor -Zc:inline -permissive- -utf-8 -Zc:wchar_t-"
fi
# CFLAGS C language level for JDK sources (hotspot only uses C++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "D3DTextRenderer.h"
#include "D3DRenderQueue.h"

void D3DGlyphCache_FlushGlyphVertexCache();
static void D3DGlyphCache_FlushGlyphVertexCache();

// static
HRESULT
Expand Down
22 changes: 17 additions & 5 deletions src/java.desktop/windows/native/libawt/windows/awt_Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,31 @@ void AwtCanvas::_SetEraseBackground(void *param)
{
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

SetEraseBackgroundStruct *sebs = (SetEraseBackgroundStruct *)param;
SetEraseBackgroundStruct *sebs = static_cast<SetEraseBackgroundStruct *>(param);
jobject canvas = sebs->canvas;
jboolean doErase = sebs->doErase;
jboolean doEraseOnResize = sebs->doEraseOnResize;

PDATA pData;
JNI_CHECK_PEER_GOTO(canvas, ret);
AwtCanvas *c = NULL;

if (canvas == NULL) {
env->ExceptionClear();
JNU_ThrowNullPointerException(env, "canvas");
delete sebs;
return;
} else {
c = (AwtCanvas*)JNI_GET_PDATA(canvas);
if (c == NULL) {
THROW_NULL_PDATA_IF_NOT_DESTROYED(canvas);
env->DeleteGlobalRef(canvas);
delete sebs;
return;
}
}

AwtCanvas *c = (AwtCanvas*)pData;
c->m_eraseBackground = doErase;
c->m_eraseBackgroundOnResize = doEraseOnResize;

ret:
env->DeleteGlobalRef(canvas);
delete sebs;
}
Expand Down
64 changes: 52 additions & 12 deletions src/java.desktop/windows/native/libawt/windows/awt_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6360,18 +6360,46 @@ void AwtComponent::_SetParent(void * param)
{
if (AwtToolkit::IsMainThread()) {
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
SetParentStruct *data = (SetParentStruct*) param;
SetParentStruct *data = static_cast<SetParentStruct*>(param);
jobject self = data->component;
jobject parent = data->parentComp;

AwtComponent *awtComponent = NULL;
AwtComponent *awtParent = NULL;

PDATA pData;
JNI_CHECK_PEER_GOTO(self, ret);
awtComponent = (AwtComponent *)pData;
JNI_CHECK_PEER_GOTO(parent, ret);
awtParent = (AwtComponent *)pData;
if (self == NULL) {
env->ExceptionClear();
JNU_ThrowNullPointerException(env, "self");
env->DeleteGlobalRef(parent);
delete data;
return;
} else {
awtComponent = (AwtComponent *)JNI_GET_PDATA(self);;
if (awtComponent == NULL) {
THROW_NULL_PDATA_IF_NOT_DESTROYED(self);
env->DeleteGlobalRef(self);
env->DeleteGlobalRef(parent);
delete data;
return;
}
}

if (parent == NULL) {
env->ExceptionClear();
JNU_ThrowNullPointerException(env, "parent");
env->DeleteGlobalRef(self);
delete data;
return;
} else {
awtParent = (AwtComponent *)JNI_GET_PDATA(parent);
if (awtParent == NULL) {
THROW_NULL_PDATA_IF_NOT_DESTROYED(parent);
env->DeleteGlobalRef(self);
env->DeleteGlobalRef(parent);
delete data;
return;
}
}

HWND selfWnd = awtComponent->GetHWnd();
HWND parentWnd = awtParent->GetHWnd();
Expand All @@ -6380,7 +6408,7 @@ void AwtComponent::_SetParent(void * param)
// (only the proxy may be the native focus owner).
::SetParent(selfWnd, parentWnd);
}
ret:

env->DeleteGlobalRef(self);
env->DeleteGlobalRef(parent);
delete data;
Expand Down Expand Up @@ -6539,19 +6567,31 @@ static void _GetInsets(void* param)
{
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

GetInsetsStruct *gis = (GetInsetsStruct *)param;
GetInsetsStruct *gis = static_cast<GetInsetsStruct *>(param);
jobject self = gis->window;

gis->insets->left = gis->insets->top =
gis->insets->right = gis->insets->bottom = 0;

PDATA pData;
JNI_CHECK_PEER_GOTO(self, ret);
AwtComponent *component = (AwtComponent *)pData;
AwtComponent *component = NULL;

if (self == NULL) {
env->ExceptionClear();
JNU_ThrowNullPointerException(env, "self");
delete gis;
return;
} else {
component = (AwtComponent *)JNI_GET_PDATA(self);
if (component == NULL) {
THROW_NULL_PDATA_IF_NOT_DESTROYED(self);
env->DeleteGlobalRef(self);
delete gis;
return;
}
}

component->GetInsets(gis->insets);

ret:
env->DeleteGlobalRef(self);
delete gis;
}
Expand Down
10 changes: 6 additions & 4 deletions src/java.desktop/windows/native/libawt/windows/awt_DnDDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ void * operator new(size_t size) {return operator new(size, "stl", 1);}
#pragma pop_macro("bad_alloc")
//"bad_alloc" is undefined from here

#include <awt.h>
#include <shlobj.h>

// These files must be included before awt.h, since the latter redefines malloc
// to Do_Not_Use_Malloc, etc, and that will break these files.
#include "awt_ole.h"
#include "awt_DCHolder.h"

#include "jlong.h"
#include "awt.h"
#include "awt_DataTransferer.h"
#include "awt_DnDDS.h"
#include "awt_DnDDT.h"
Expand All @@ -54,9 +59,6 @@ void * operator new(size_t size) {return operator new(size, "stl", 1);}
#include "java_awt_dnd_DnDConstants.h"
#include "sun_awt_windows_WDragSourceContextPeer.h"

#include "awt_ole.h"
#include "awt_DCHolder.h"

bool operator < (const FORMATETC &fr, const FORMATETC &fl) {
return memcmp(&fr, &fl, sizeof(FORMATETC)) < 0;
}
Expand Down
4 changes: 3 additions & 1 deletion src/java.desktop/windows/native/libawt/windows/awt_DnDDT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
#include <shellapi.h>
#include <memory.h>

// awt_ole.h must be included before awt.h, since the latter redefines malloc
// to Do_Not_Use_Malloc, etc, and that will break awt_ole.h.
#include "awt_ole.h"
#include "awt_DataTransferer.h"
#include "java_awt_dnd_DnDConstants.h"
#include "sun_awt_windows_WDropTargetContextPeer.h"
#include "awt_Container.h"
#include "awt_ole.h"
#include "awt_Toolkit.h"
#include "awt_DnDDT.h"
#include "awt_DnDDS.h"
Expand Down
74 changes: 62 additions & 12 deletions src/java.desktop/windows/native/libawt/windows/awt_Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,15 +1340,27 @@ void AwtFrame::_SetState(void *param)
{
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

SetStateStruct *sss = (SetStateStruct *)param;
SetStateStruct *sss = static_cast<SetStateStruct *>(param);
jobject self = sss->frame;
jint state = sss->state;

AwtFrame *f = NULL;

PDATA pData;
JNI_CHECK_PEER_GOTO(self, ret);
f = (AwtFrame *)pData;
if (self == NULL) {
env->ExceptionClear();
JNU_ThrowNullPointerException(env, "self");
delete sss;
return;
} else {
f = (AwtFrame *)JNI_GET_PDATA(self);
if (f == NULL) {
THROW_NULL_PDATA_IF_NOT_DESTROYED(self);
env->DeleteGlobalRef(self);
delete sss;
return;
}
}

HWND hwnd = f->GetHWnd();
if (::IsWindow(hwnd))
{
Expand Down Expand Up @@ -1405,7 +1417,7 @@ void AwtFrame::_SetState(void *param)
f->setZoomed(zoom);
}
}
ret:

env->DeleteGlobalRef(self);

delete sss;
Expand Down Expand Up @@ -1569,21 +1581,59 @@ void AwtFrame::_NotifyModalBlocked(void *param)
{
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);

NotifyModalBlockedStruct *nmbs = (NotifyModalBlockedStruct *)param;
NotifyModalBlockedStruct *nmbs = static_cast<NotifyModalBlockedStruct *>(param);
jobject self = nmbs->frame;
jobject peer = nmbs->peer;
jobject blockerPeer = nmbs->blockerPeer;
jboolean blocked = nmbs->blocked;

PDATA pData;
AwtFrame *f = NULL;

JNI_CHECK_PEER_GOTO(peer, ret);
AwtFrame *f = (AwtFrame *)pData;
if (peer == NULL) {
env->ExceptionClear();
JNU_ThrowNullPointerException(env, "peer");
env->DeleteGlobalRef(self);
env->DeleteGlobalRef(blockerPeer);

delete nmbs;
return;
} else {
f = (AwtFrame *)JNI_GET_PDATA(peer);
if (f == NULL) {
THROW_NULL_PDATA_IF_NOT_DESTROYED(peer);
env->DeleteGlobalRef(self);
env->DeleteGlobalRef(peer);
env->DeleteGlobalRef(blockerPeer);

delete nmbs;
return;
}
}

// dialog here may be NULL, for example, if the blocker is a native dialog
// however, we need to install/unistall modal hooks anyway
JNI_CHECK_PEER_GOTO(blockerPeer, ret);
AwtDialog *d = (AwtDialog *)pData;
AwtDialog *d = NULL;

if (blockerPeer == NULL) {
env->ExceptionClear();
JNU_ThrowNullPointerException(env, "blockerPeer");
env->DeleteGlobalRef(self);
env->DeleteGlobalRef(peer);

delete nmbs;
return;
} else {
d = (AwtDialog *)JNI_GET_PDATA(blockerPeer);
if (d == NULL) {
THROW_NULL_PDATA_IF_NOT_DESTROYED(blockerPeer);
env->DeleteGlobalRef(self);
env->DeleteGlobalRef(peer);
env->DeleteGlobalRef(blockerPeer);

delete nmbs;
return;
}
}

if ((f != NULL) && ::IsWindow(f->GetHWnd()))
{
Expand Down Expand Up @@ -1634,7 +1684,7 @@ void AwtFrame::_NotifyModalBlocked(void *param)
}
}
}
ret:

env->DeleteGlobalRef(self);
env->DeleteGlobalRef(peer);
env->DeleteGlobalRef(blockerPeer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

class AwtPrintDialog {
public:
static jfieldID AwtPrintDialog::controlID;
static jfieldID AwtPrintDialog::parentID;
static jfieldID AwtPrintDialog::pageID;
static jmethodID AwtPrintDialog::setHWndMID;
static jfieldID controlID;
static jfieldID parentID;
static jfieldID pageID;
static jmethodID setHWndMID;

static BOOL PrintDlg(LPPRINTDLG);

Expand Down
Loading

1 comment on commit 8bc1867

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.