|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
85 | 85 | #include "Trace.h"
|
86 | 86 | #include "D3DPipelineManager.h"
|
87 | 87 |
|
88 |
| -typedef struct { |
89 |
| - int monitorCounter; |
90 |
| - int monitorLimit; |
91 |
| - HMONITOR* hmpMonitors; |
92 |
| -} MonitorData; |
93 | 88 |
|
| 89 | +/* Some helper functions (from awt_MMStub.h/cpp) */ |
94 | 90 |
|
95 |
| -// Only monitors where CreateDC does not fail are valid |
96 |
| -static BOOL IsValidMonitor(HMONITOR hMon) |
97 |
| -{ |
98 |
| - MONITORINFOEX mieInfo; |
99 |
| - memset((void*)(&mieInfo), 0, sizeof(MONITORINFOEX)); |
100 |
| - mieInfo.cbSize = sizeof(MONITORINFOEX); |
101 |
| - if (!::GetMonitorInfo(hMon, (LPMONITORINFOEX)(&mieInfo))) { |
102 |
| - J2dTraceLn1(J2D_TRACE_INFO, "Devices::IsValidMonitor: GetMonitorInfo failed for monitor with handle %p", hMon); |
103 |
| - return FALSE; |
104 |
| - } |
105 |
| - |
106 |
| - HDC hDC = CreateDC(mieInfo.szDevice, NULL, NULL, NULL); |
107 |
| - if (NULL == hDC) { |
108 |
| - J2dTraceLn2(J2D_TRACE_INFO, "Devices::IsValidMonitor: CreateDC failed for monitor with handle %p, device: %S", hMon, mieInfo.szDevice); |
109 |
| - return FALSE; |
110 |
| - } |
111 |
| - |
112 |
| - ::DeleteDC(hDC); |
113 |
| - return TRUE; |
114 |
| -} |
| 91 | +int g_nMonitorCounter; |
| 92 | +int g_nMonitorLimit; |
| 93 | +HMONITOR* g_hmpMonitors; |
115 | 94 |
|
116 | 95 | // Callback for CountMonitors below
|
117 |
| -static BOOL WINAPI clb_fCountMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lpMonitorCounter) |
| 96 | +BOOL WINAPI clb_fCountMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lP) |
118 | 97 | {
|
119 |
| - if (IsValidMonitor(hMon)) { |
120 |
| - (*((int *)lpMonitorCounter))++; |
121 |
| - } |
122 |
| - |
| 98 | + g_nMonitorCounter ++; |
123 | 99 | return TRUE;
|
124 | 100 | }
|
125 | 101 |
|
126 | 102 | int WINAPI CountMonitors(void)
|
127 | 103 | {
|
128 |
| - int monitorCounter = 0; |
129 |
| - ::EnumDisplayMonitors(NULL, NULL, clb_fCountMonitors, (LPARAM)&monitorCounter); |
130 |
| - return monitorCounter; |
| 104 | + g_nMonitorCounter = 0; |
| 105 | + ::EnumDisplayMonitors(NULL, NULL, clb_fCountMonitors, 0L); |
| 106 | + return g_nMonitorCounter; |
| 107 | + |
131 | 108 | }
|
132 | 109 |
|
133 | 110 | // Callback for CollectMonitors below
|
134 |
| -static BOOL WINAPI clb_fCollectMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lpMonitorData) |
| 111 | +BOOL WINAPI clb_fCollectMonitors(HMONITOR hMon, HDC hDC, LPRECT rRect, LPARAM lP) |
135 | 112 | {
|
136 |
| - MonitorData* pMonitorData = (MonitorData *)lpMonitorData; |
137 |
| - if ((pMonitorData->monitorCounter < pMonitorData->monitorLimit) && (IsValidMonitor(hMon))) { |
138 |
| - pMonitorData->hmpMonitors[pMonitorData->monitorCounter] = hMon; |
139 |
| - pMonitorData->monitorCounter++; |
| 113 | + |
| 114 | + if ((g_nMonitorCounter < g_nMonitorLimit) && (NULL != g_hmpMonitors)) { |
| 115 | + g_hmpMonitors[g_nMonitorCounter] = hMon; |
| 116 | + g_nMonitorCounter ++; |
140 | 117 | }
|
141 | 118 |
|
142 | 119 | return TRUE;
|
143 | 120 | }
|
144 | 121 |
|
145 |
| -static int WINAPI CollectMonitors(HMONITOR* hmpMonitors, int nNum) |
| 122 | +int WINAPI CollectMonitors(HMONITOR* hmpMonitors, int nNum) |
146 | 123 | {
|
| 124 | + int retCode = 0; |
| 125 | + |
147 | 126 | if (NULL != hmpMonitors) {
|
148 |
| - MonitorData monitorData; |
149 |
| - monitorData.monitorCounter = 0; |
150 |
| - monitorData.monitorLimit = nNum; |
151 |
| - monitorData.hmpMonitors = hmpMonitors; |
152 |
| - ::EnumDisplayMonitors(NULL, NULL, clb_fCollectMonitors, (LPARAM)&monitorData); |
153 |
| - return monitorData.monitorCounter; |
154 |
| - } else { |
155 |
| - return 0; |
| 127 | + |
| 128 | + g_nMonitorCounter = 0; |
| 129 | + g_nMonitorLimit = nNum; |
| 130 | + g_hmpMonitors = hmpMonitors; |
| 131 | + |
| 132 | + ::EnumDisplayMonitors(NULL, NULL, clb_fCollectMonitors, 0L); |
| 133 | + |
| 134 | + retCode = g_nMonitorCounter; |
| 135 | + |
| 136 | + g_nMonitorCounter = 0; |
| 137 | + g_nMonitorLimit = 0; |
| 138 | + g_hmpMonitors = NULL; |
| 139 | + |
156 | 140 | }
|
| 141 | + return retCode; |
157 | 142 | }
|
158 | 143 |
|
159 | 144 | BOOL WINAPI MonitorBounds(HMONITOR hmMonitor, RECT* rpBounds)
|
|
0 commit comments