Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions src/java.desktop/windows/classes/sun/awt/PlatformGraphicsInfo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,41 +28,20 @@
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;

import sun.awt.windows.WToolkit;

public class PlatformGraphicsInfo {

private static final boolean hasDisplays;

static {
loadAWTLibrary();
hasDisplays = hasDisplays0();
}

@SuppressWarnings("removal")
private static void loadAWTLibrary() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("awt");
return null;
}
});
}

private static native boolean hasDisplays0();

public static GraphicsEnvironment createGE() {
return new Win32GraphicsEnvironment();
}

public static Toolkit createToolkit() {
return new WToolkit();
return new sun.awt.windows.WToolkit();
}

public static boolean getDefaultHeadlessProperty() {
// If we don't find usable displays, we run headless.
return !hasDisplays;
// On Windows, we assume we can always create headful apps.
// Here is where we can add code that would actually check.
return false;
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -60,8 +60,7 @@ public final class Win32GraphicsEnvironment extends SunGraphicsEnvironment {
WToolkit.loadLibraries();
// setup flags before initializing native layer
WindowsFlags.initFlags();

initDisplay();
initDisplayWrapper();

// Install correct surface manager factory.
SurfaceManagerFactory.setInstance(new WindowsSurfaceManagerFactory());
Expand Down Expand Up @@ -89,6 +88,14 @@ public final class Win32GraphicsEnvironment extends SunGraphicsEnvironment {
*/
private static native void initDisplay();

private static boolean displayInitialized; // = false;
public static void initDisplayWrapper() {
if (!displayInitialized) {
displayInitialized = true;
initDisplay();
}
}

public Win32GraphicsEnvironment() {
}

Expand Down
81 changes: 33 additions & 48 deletions src/java.desktop/windows/native/libawt/windows/Devices.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -85,75 +85,60 @@
#include "Trace.h"
#include "D3DPipelineManager.h"

typedef struct {
int monitorCounter;
int monitorLimit;
HMONITOR* hmpMonitors;
} MonitorData;

/* Some helper functions (from awt_MMStub.h/cpp) */

// Only monitors where CreateDC does not fail are valid
static BOOL IsValidMonitor(HMONITOR hMon)
{
MONITORINFOEX mieInfo;
memset((void*)(&mieInfo), 0, sizeof(MONITORINFOEX));
mieInfo.cbSize = sizeof(MONITORINFOEX);
if (!::GetMonitorInfo(hMon, (LPMONITORINFOEX)(&mieInfo))) {
J2dTraceLn1(J2D_TRACE_INFO, "Devices::IsValidMonitor: GetMonitorInfo failed for monitor with handle %p", hMon);
return FALSE;
}

HDC hDC = CreateDC(mieInfo.szDevice, NULL, NULL, NULL);
if (NULL == hDC) {
J2dTraceLn2(J2D_TRACE_INFO, "Devices::IsValidMonitor: CreateDC failed for monitor with handle %p, device: %S", hMon, mieInfo.szDevice);
return FALSE;
}

::DeleteDC(hDC);
return TRUE;
}
int g_nMonitorCounter;
int g_nMonitorLimit;
HMONITOR* g_hmpMonitors;

// Callback for CountMonitors below
static BOOL WINAPI clb_fCountMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lpMonitorCounter)
BOOL WINAPI clb_fCountMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lP)
{
if (IsValidMonitor(hMon)) {
(*((int *)lpMonitorCounter))++;
}

g_nMonitorCounter ++;
return TRUE;
}

int WINAPI CountMonitors(void)
{
int monitorCounter = 0;
::EnumDisplayMonitors(NULL, NULL, clb_fCountMonitors, (LPARAM)&monitorCounter);
return monitorCounter;
g_nMonitorCounter = 0;
::EnumDisplayMonitors(NULL, NULL, clb_fCountMonitors, 0L);
return g_nMonitorCounter;

}

// Callback for CollectMonitors below
static BOOL WINAPI clb_fCollectMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lpMonitorData)
BOOL WINAPI clb_fCollectMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lP)
{
MonitorData* pMonitorData = (MonitorData *)lpMonitorData;
if ((pMonitorData->monitorCounter < pMonitorData->monitorLimit) && (IsValidMonitor(hMon))) {
pMonitorData->hmpMonitors[pMonitorData->monitorCounter] = hMon;
pMonitorData->monitorCounter++;

if ((g_nMonitorCounter < g_nMonitorLimit) && (NULL != g_hmpMonitors)) {
g_hmpMonitors[g_nMonitorCounter] = hMon;
g_nMonitorCounter ++;
}

return TRUE;
}

static int WINAPI CollectMonitors(HMONITOR* hmpMonitors, int nNum)
int WINAPI CollectMonitors(HMONITOR* hmpMonitors, int nNum)
{
int retCode = 0;

if (NULL != hmpMonitors) {
MonitorData monitorData;
monitorData.monitorCounter = 0;
monitorData.monitorLimit = nNum;
monitorData.hmpMonitors = hmpMonitors;
::EnumDisplayMonitors(NULL, NULL, clb_fCollectMonitors, (LPARAM)&monitorData);
return monitorData.monitorCounter;
} else {
return 0;

g_nMonitorCounter = 0;
g_nMonitorLimit = nNum;
g_hmpMonitors = hmpMonitors;

::EnumDisplayMonitors(NULL, NULL, clb_fCollectMonitors, 0L);

retCode = g_nMonitorCounter;

g_nMonitorCounter = 0;
g_nMonitorLimit = 0;
g_hmpMonitors = NULL;

}
return retCode;
}

BOOL WINAPI MonitorBounds(HMONITOR hmMonitor, RECT* rpBounds)
Expand Down
4 changes: 1 addition & 3 deletions src/java.desktop/windows/native/libawt/windows/Devices.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -74,6 +74,4 @@ static CriticalSection arrayLock;

BOOL WINAPI MonitorBounds (HMONITOR, RECT*);

int WINAPI CountMonitors (void);

#endif // _DEVICES_H_

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -33,6 +33,7 @@
/**
* @test
* @bug 8189604 8208702
* @requires !vm.debug | os.family != "windows"
* @run main/othervm -Djava.awt.headless=false HangDuringStaticInitialization
* @run main/othervm -Djava.awt.headless=true HangDuringStaticInitialization
*/
Expand Down