@@ -1185,9 +1185,9 @@ public long getLayerPtr() {
1185
1185
1186
1186
private final static int INVOKE_LATER_FLUSH_BUFFERS = getInvokeLaterMode ();
1187
1187
1188
+ @ SuppressWarnings ("removal" )
1188
1189
private static int getInvokeLaterMode () {
1189
1190
final String invokeLaterKey = "awt.mac.flushBuffers.invokeLater" ;
1190
- @ SuppressWarnings ("removal" )
1191
1191
final String invokeLaterArg = AccessController .doPrivileged (
1192
1192
new GetPropertyAction (invokeLaterKey ));
1193
1193
final int result ;
@@ -1215,33 +1215,9 @@ private static int getInvokeLaterMode() {
1215
1215
return result ;
1216
1216
}
1217
1217
1218
- @ SuppressWarnings ("removal" )
1219
- private final static boolean INVOKE_LATER_USE_PWM = getInvokeLaterUsePWM ();
1220
-
1221
- private static boolean getInvokeLaterUsePWM () {
1222
- final String usePwmKey = "awt.mac.flushBuffers.pwm" ;
1223
- @ SuppressWarnings ("removal" )
1224
- final String usePwmArg = AccessController .doPrivileged (
1225
- new GetPropertyAction (usePwmKey ));
1226
- final boolean result ;
1227
- if (usePwmArg == null ) {
1228
- // default = 'false':
1229
- result = false ;
1230
- } else {
1231
- result = "true" .equalsIgnoreCase (usePwmArg );
1232
- logger .info ("CPlatformWindow: property \" {0}={1}\" , using usePWM={2}." ,
1233
- usePwmKey , usePwmArg , result );
1234
- }
1235
- return result ;
1236
- }
1237
- /* 10s period arround reference times (sleep/wake-up...)
1238
- * to ensure all displays are awaken properly */
1239
- private final static long NANOS_PER_SEC = 1000000000L ;
1240
- private final static long STATE_CHANGE_PERIOD = 10L * NANOS_PER_SEC ;
1241
-
1242
- private final AtomicBoolean mirroringState = new AtomicBoolean (false );
1243
- /** per window timestamp of disabling mirroring */
1244
- private final AtomicLong mirroringDisablingTime = new AtomicLong (0L );
1218
+ private final static int INVOKE_LATER_COUNT = 5 ;
1219
+ /** per window counter of remaining invokeLater calls */
1220
+ private final AtomicInteger invokeLaterCount = new AtomicInteger ();
1245
1221
1246
1222
// Specific class needed to get obvious stack traces:
1247
1223
private final class EmptyRunnable implements Runnable {
@@ -1257,10 +1233,7 @@ public void run() {
1257
1233
private final EmptyRunnable emptyTask = new EmptyRunnable ();
1258
1234
1259
1235
void flushBuffers () {
1260
- // Only 1 usage by deliverMoveResizeEvent():
1261
- // System-dependent appearance optimization.
1262
- // May be blocking so postpone this event processing:
1263
-
1236
+ // only 1 usage by deliverMoveResizeEvent():
1264
1237
if (isVisible () && !nativeBounds .isEmpty () && !isFullScreenMode ) {
1265
1238
// use the system property 'awt.mac.flushBuffers.invokeLater' to true/auto (default: auto)
1266
1239
// to avoid deadlocks caused by the LWCToolkit.invokeAndWait() call below:
@@ -1273,68 +1246,38 @@ void flushBuffers() {
1273
1246
default :
1274
1247
case INVOKE_LATER_AUTO :
1275
1248
useInvokeLater = false ;
1276
-
1277
- // JBR-5497: force using invokeLater() when computer returns from sleep or displayChanged()
1278
- // (mirroring case especially) to avoid deadlocks until solved definitely:
1279
-
1280
- boolean mirroring = false ;
1281
1249
if (peer != null ) {
1282
1250
final GraphicsDevice device = peer .getGraphicsConfiguration ().getDevice ();
1283
1251
if (device instanceof CGraphicsDevice ) {
1284
1252
// JBR-5497: avoid deadlock in mirroring mode (laptop + external screen):
1285
- // Note: the CGraphicsDevice instance will be recreated when mirroring is enabled/disabled.
1286
- mirroring = ((CGraphicsDevice )device ).isMirroring ();
1253
+ useInvokeLater = ((CGraphicsDevice )device ).isMirroring ();
1287
1254
if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1288
- logger .fine ("CPlatformWindow.flushBuffers[auto] : CGraphicsDevice.isMirroring = {0}" ,
1289
- mirroring );
1255
+ logger .fine ("CPlatformWindow.flushBuffers: CGraphicsDevice.isMirroring = {0}" ,
1256
+ useInvokeLater );
1290
1257
}
1291
1258
}
1292
1259
}
1293
- if (mirroring ) {
1294
- mirroringState .set (true );
1295
- } else if (mirroringState .get ()) {
1296
- // mirroringState trigger enabled but mirroring=false:
1297
- // keep mirroring enabled for some time (STATE_CHANGE_PERIOD):
1298
- mirroring = true ;
1299
- final long now = System .nanoTime (); // timestamp
1300
-
1301
- // should disable mirroring now ? check timestamp:
1302
- final long lastTime = mirroringDisablingTime .get ();
1303
- final long delta ;
1304
- if (lastTime == 0L ) {
1305
- delta = 0L ;
1306
- // unset: set timestamp of disabling mirroring:
1307
- mirroringDisablingTime .set (now );
1308
- } else {
1309
- delta = Math .abs (now - lastTime );
1310
- if (delta > STATE_CHANGE_PERIOD ) {
1311
- // disable mirroring as period is elapsed:
1312
- mirroring = false ;
1313
- mirroringState .set (false );
1314
- // reset timestamp:
1315
- mirroringDisablingTime .set (0L );
1316
- }
1317
- }
1318
- if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1319
- logger .fine ("CPlatformWindow.flushBuffers[auto]: mirroring = {0} (mirroring = {1} delta = {2} ms)" ,
1320
- mirroring , mirroringState .get (), delta * 1e-6 );
1260
+ // JBR-5497: keep few more invokeLater() when computer returns from sleep or displayChanged()
1261
+ // to avoid deadlocks until solved definitely:
1262
+ if (useInvokeLater ) {
1263
+ // reset to max count:
1264
+ invokeLaterCount .set (INVOKE_LATER_COUNT );
1265
+ } else {
1266
+ final int prev = invokeLaterCount .get ();
1267
+ if (prev > 0 ) {
1268
+ invokeLaterCount .compareAndSet (prev , prev - 1 );
1269
+ useInvokeLater = true ;
1321
1270
}
1322
1271
}
1323
- useInvokeLater = mirroring ;
1272
+ if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1273
+ logger .fine ("CPlatformWindow.flushBuffers: useInvokeLater = {0} (count = {1})" ,
1274
+ useInvokeLater , invokeLaterCount .get ());
1275
+ }
1324
1276
break ;
1325
1277
case INVOKE_LATER_ENABLED :
1326
1278
useInvokeLater = true ;
1327
1279
break ;
1328
1280
}
1329
- if (!useInvokeLater && INVOKE_LATER_USE_PWM ) {
1330
- // If the system property 'awt.mac.flushBuffers.pwm' is true,
1331
- // invokeLater is enforced during power transitions.
1332
- final boolean inTransition = LWCToolkit .isWithinPowerTransition ();
1333
- if (inTransition ) {
1334
- logger .fine ("CPlatformWindow.flushBuffers[pwm]: inTransition = true" );
1335
- useInvokeLater = true ;
1336
- }
1337
- }
1338
1281
try {
1339
1282
// check invokeAndWait: KO (operations require AWTLock and main thread)
1340
1283
// => use invokeLater as it is an empty event to force refresh ASAP
@@ -1347,13 +1290,7 @@ void flushBuffers() {
1347
1290
getIdentifier (target ));
1348
1291
}
1349
1292
1350
- /* Ensure >500ms = 666ms timeout to avoid any deadlock among
1351
- * appkit, EDT, Flusher & a11y threads, locks
1352
- * and various synchronization patterns... */
1353
- final double timeoutSeconds = 0.666 ; // seconds
1354
-
1355
- // FUCK: appKit is calling this method !
1356
- LWCToolkit .invokeAndWait (emptyTask , target , timeoutSeconds );
1293
+ LWCToolkit .invokeAndWait (emptyTask , target );
1357
1294
1358
1295
if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1359
1296
logger .fine ("CPlatformWindow.flushBuffers: exit " +
@@ -1362,9 +1299,7 @@ void flushBuffers() {
1362
1299
}
1363
1300
}
1364
1301
} catch (InvocationTargetException ite ) {
1365
- if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1366
- logger .fine ("CPlatformWindow.flushBuffers: timeout or LWCToolkit.invoke failure: " , ite );
1367
- }
1302
+ logger .severe ("CPlatformWindow.flushBuffers: exception occurred: " , ite );
1368
1303
}
1369
1304
}
1370
1305
}
@@ -1399,16 +1334,10 @@ private void deliverWindowFocusEvent(boolean gained, CPlatformWindow opposite){
1399
1334
responder .handleWindowFocusEvent (gained , oppositePeer );
1400
1335
}
1401
1336
1402
- /* useless ? */
1403
1337
public void doDeliverMoveResizeEvent () {
1404
- if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1405
- logger .fine ("CPlatformWindow.doDeliverMoveResizeEvent() called by {0}" ,
1406
- Thread .currentThread ());
1407
- }
1408
1338
execute (ptr -> nativeCallDeliverMoveResizeEvent (ptr ));
1409
1339
}
1410
1340
1411
- /* native call by AWTWindow._deliverMoveResizeEvent() */
1412
1341
protected void deliverMoveResizeEvent (int x , int y , int width , int height ,
1413
1342
boolean byUser ) {
1414
1343
AtomicBoolean ref = new AtomicBoolean ();
@@ -1422,17 +1351,9 @@ protected void deliverMoveResizeEvent(int x, int y, int width, int height,
1422
1351
nativeBounds = new Rectangle (x , y , width , height );
1423
1352
if (peer != null ) {
1424
1353
peer .notifyReshape (x , y , width , height );
1425
-
1426
- if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1427
- logger .fine ("CPlatformWindow.deliverMoveResizeEvent(): byUser = {0} " +
1428
- "isFullScreenAnimationOn = {1}" , byUser , isFullScreenAnimationOn );
1429
- }
1430
-
1431
1354
// System-dependent appearance optimization.
1432
1355
if ((byUser && !oldB .getSize ().equals (nativeBounds .getSize ()))
1433
1356
|| isFullScreenAnimationOn ) {
1434
-
1435
- // May be blocking so postpone this event processing:
1436
1357
flushBuffers ();
1437
1358
}
1438
1359
}
@@ -1661,46 +1582,30 @@ private long createNSWindow(long nsViewPtr,
1661
1582
// ----------------------------------------------------------------------
1662
1583
1663
1584
private void windowWillMiniaturize () {
1664
- logger .fine ("windowWillMiniaturize" );
1665
1585
isIconifyAnimationActive = true ;
1666
1586
}
1667
1587
1668
1588
private void windowDidBecomeMain () {
1669
- logger .fine ("windowDidBecomeMain" );
1670
1589
lastBecomeMainTime = System .currentTimeMillis ();
1671
1590
checkBlockingAndOrder ();
1672
1591
}
1673
1592
1674
1593
private void windowWillEnterFullScreen () {
1675
1594
isFullScreenAnimationOn = true ;
1676
- if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1677
- logger .fine ("windowWillEnterFullScreen: isFullScreenAnimationOn = {0}" , isFullScreenAnimationOn );
1678
- }
1679
1595
}
1680
1596
1681
1597
private void windowDidEnterFullScreen () {
1682
1598
isInFullScreen = true ;
1683
1599
isFullScreenAnimationOn = false ;
1684
- if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1685
- logger .fine ("windowWillEnterFullScreen: isFullScreenAnimationOn = {0} isInFullScreen = {1}" ,
1686
- isFullScreenAnimationOn , isInFullScreen );
1687
- }
1688
1600
}
1689
1601
1690
1602
private void windowWillExitFullScreen () {
1691
1603
isFullScreenAnimationOn = true ;
1692
- if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1693
- logger .fine ("windowWillExitFullScreen: isFullScreenAnimationOn = {0}" , isFullScreenAnimationOn );
1694
- }
1695
1604
}
1696
1605
1697
1606
private void windowDidExitFullScreen () {
1698
1607
isInFullScreen = false ;
1699
1608
isFullScreenAnimationOn = false ;
1700
- if (logger .isLoggable (PlatformLogger .Level .FINE )) {
1701
- logger .fine ("windowDidExitFullScreen: isFullScreenAnimationOn = {0} isInFullScreen = {1}" ,
1702
- isFullScreenAnimationOn , isInFullScreen );
1703
- }
1704
1609
}
1705
1610
1706
1611
@ JBRApi .Provides ("java.awt.Window.CustomTitleBarPeer#update" )
0 commit comments