Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/java.desktop/share/classes/javax/swing/JComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ public void paint(Graphics g) {
} finally {
repaintManager.endPaint();
}
repaintManager.afterPaint(this);
}
else {
// Will occasionally happen in 1.2, especially when printing.
Expand Down Expand Up @@ -1162,6 +1163,7 @@ void paintForceDoubleBuffered(Graphics g) {
rm.endPaint();
setFlag(IS_REPAINTING, false);
}
rm.afterPaint(this);
}

/**
Expand Down Expand Up @@ -5272,6 +5274,7 @@ void _paintImmediately(int x, int y, int w, int h) {
} finally {
rm.endPaint();
}
rm.afterPaint(this);
} else {
g.setClip(paintImmediatelyClip.x, paintImmediatelyClip.y,
paintImmediatelyClip.width, paintImmediatelyClip.height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,9 @@ void paint(JComponent paintingComponent,
g.setClip(x, y, w, h);
paintingComponent.paintToOffscreen(g, x, y, w, h, x + w, y + h);
}
}

void afterPaint(JComponent paintingComponent) {
if (Toolkit.getDefaultToolkit() instanceof SunToolkit tk) {
final Window window = SwingUtilities.getWindowAncestor(paintingComponent);
if (window != null && tk.needUpdateWindowAfterPaint()) {
Expand Down
53 changes: 53 additions & 0 deletions src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -3469,6 +3469,13 @@ public boolean drawImage(Image img,
return true;
}

boolean blitImageDrawn = drawImageBlit(img, dx1, dy1, dx2, dy2,
sx1, sy1, sx2, sy2,
bgcolor, observer);
if (blitImageDrawn) {
return true;
}

Boolean hidpiImageDrawn = drawHiDPIImage(img, dx1, dy1, dx2, dy2,
sx1, sy1, sx2, sy2,
bgcolor, observer, null);
Expand Down Expand Up @@ -3525,6 +3532,52 @@ public boolean drawImage(Image img,
}
}

/**
* Tries to draw the image via copyImage if the image is compatible with
* the current transformation. That is, the scaling of the image is the
* same as the scaling of the transformation and the transformation does
* not contain any rotation. This leads to better results when the scaling
* is fractional.
*/
private boolean drawImageBlit(Image img,
int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2,
Color bgcolor, ImageObserver observer) {
if (dx2 - dx1 == sx2 - sx1 &&
dy2 - dy1 == sy2 - sy1 &&
sx1 <= sx2 &&
sy1 <= sy2 &&
dx1 <= dx2 &&
dy1 <= dy2 &&
transformState <= TRANSFORM_TRANSLATESCALE
) {
final SurfaceData sd;
try {
sd = SurfaceManager.getManager(img).getPrimarySurfaceData();
} catch (InvalidPipeException e) {
return false;
}
if (sd.getDefaultScaleX() == transform.getScaleX() && sd.getDefaultScaleY() == transform.getScaleY()) {
dx1 = Region.clipRound(transform.getScaleX() * dx1);
dx2 = Region.clipRound(transform.getScaleX() * dx2);
dy1 = Region.clipRound(transform.getScaleY() * dy1);
dy2 = Region.clipRound(transform.getScaleY() * dy2);
sx1 = Region.clipRound(transform.getScaleX() * sx1);
sy1 = Region.clipRound(transform.getScaleY() * sy1);
int width = dx2 - dx1;
int height = dy2 - dy1;
AffineTransform old = new AffineTransform(transform);
setTransform(AffineTransform.getTranslateInstance(transform.getTranslateX(), transform.getTranslateY()));
try {
return copyImage(img, dx1, dy1, sx1, sy1, width, height, bgcolor, observer);
} finally {
setTransform(old);
}
}
}
return false;
}

/**
* Draw an image, applying a transform from image space into user space
* before drawing.
Expand Down
Loading