mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2026-02-03 06:06:30 +01:00
JBR-9350 javax/swing/JOptionPane/8081019/bug8081019.java: Cannot invoke "sun.lwawt.LWWindowPeer.getTarget()" because "this.peer" is null
Added peer null checks + use perfCountersEnabled flag
This commit is contained in:
@@ -50,12 +50,13 @@ public final class MTLLayer extends CFLayer {
|
||||
private static native void nativeSetOpaque(long layerPtr, boolean opaque);
|
||||
|
||||
private int scale = 1;
|
||||
private final boolean perfCountersEnabled;
|
||||
|
||||
public MTLLayer(LWWindowPeer peer) {
|
||||
super(0, true);
|
||||
|
||||
Window target = (peer != null) ? peer.getTarget() : null;
|
||||
boolean perfCountersEnabled = (target != null) && AWTAccessor.getWindowAccessor().countersEnabled(target);
|
||||
this.perfCountersEnabled = (target != null) && AWTAccessor.getWindowAccessor().countersEnabled(target);
|
||||
|
||||
setPtr(nativeCreateLayer(perfCountersEnabled));
|
||||
this.peer = peer;
|
||||
@@ -157,18 +158,22 @@ public final class MTLLayer extends CFLayer {
|
||||
|
||||
private void addStat(int type, double value) {
|
||||
// Called from the native code when this layer has been presented on screen
|
||||
Component target = peer.getTarget();
|
||||
if (target instanceof Window window) {
|
||||
AWTAccessor.getWindowAccessor().addStat(window,
|
||||
((type >= 0) && (type < STAT_NAMES.length)) ? STAT_NAMES[type] : "undefined", value);
|
||||
if (perfCountersEnabled && (peer != null)) {
|
||||
final Component target = peer.getTarget();
|
||||
if (target instanceof Window window) {
|
||||
AWTAccessor.getWindowAccessor().addStat(window,
|
||||
((type >= 0) && (type < STAT_NAMES.length)) ? STAT_NAMES[type] : "undefined", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void countNewFrame() {
|
||||
// Called from the native code when this layer has been presented on screen
|
||||
Component target = peer.getTarget();
|
||||
if (target instanceof Window window) {
|
||||
AWTAccessor.getWindowAccessor().incrementCounter(window, "java2d.native.frames");
|
||||
if (perfCountersEnabled && (peer != null)) {
|
||||
final Component target = peer.getTarget();
|
||||
if (target instanceof Window window) {
|
||||
AWTAccessor.getWindowAccessor().incrementCounter(window, "java2d.native.frames");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,9 +181,11 @@ public final class MTLLayer extends CFLayer {
|
||||
// Called from the native code when an attempt was made to present this layer
|
||||
// on screen, but that attempt was not successful. This can happen, for example,
|
||||
// when those attempts are too frequent.
|
||||
Component target = peer.getTarget();
|
||||
if (target instanceof Window window) {
|
||||
AWTAccessor.getWindowAccessor().incrementCounter(window, "java2d.native.framesDropped");
|
||||
if (perfCountersEnabled && (peer != null)) {
|
||||
final Component target = peer.getTarget();
|
||||
if (target instanceof Window window) {
|
||||
AWTAccessor.getWindowAccessor().incrementCounter(window, "java2d.native.framesDropped");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,8 +239,9 @@ BOOL MTLLayer_isExtraRedrawEnabled() {
|
||||
static const NSTimeInterval a = 0.25;
|
||||
|
||||
if (nextDrawableLatency > 0.0) {
|
||||
[self addStatCallback:1 value:1000.0 * nextDrawableLatency]; // See MTLLayer.STAT_NAMES[1]
|
||||
|
||||
if (self.perfCountersEnabled) {
|
||||
[self addStatCallback:1 value:1000.0 * nextDrawableLatency]; // See MTLLayer.STAT_NAMES[1]
|
||||
}
|
||||
#if TRACE_DISPLAY_ON
|
||||
self.avgNextDrawableTime = nextDrawableLatency * a + self.avgNextDrawableTime * (1.0 - a);
|
||||
|
||||
@@ -399,7 +400,9 @@ BOOL MTLLayer_isExtraRedrawEnabled() {
|
||||
|
||||
const CFTimeInterval drawInMTLContextLatency = (CACurrentMediaTime() - beforeMethod);
|
||||
if (drawInMTLContextLatency > 0.0) {
|
||||
[self addStatCallback:0 value:1000.0 * drawInMTLContextLatency]; // See MTLLayer.STAT_NAMES[0]
|
||||
if (self.perfCountersEnabled) {
|
||||
[self addStatCallback:0 value:1000.0 * drawInMTLContextLatency]; // See MTLLayer.STAT_NAMES[0]
|
||||
}
|
||||
}
|
||||
(*env)->DeleteLocalRef(env, javaLayerLocalRef);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user