mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-07 22:50:49 +00:00
8275843: Random crashes while the UI code is executed
Reviewed-by: azvegint
This commit is contained in:
parent
3f91948c59
commit
a9c1acbb8a
@ -25,15 +25,18 @@
|
||||
|
||||
package sun.java2d.xr;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.*;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Paint;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.NoninvertibleTransformException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import sun.font.*;
|
||||
import sun.java2d.*;
|
||||
import sun.java2d.loops.*;
|
||||
import sun.awt.image.PixelConverter;
|
||||
import sun.font.XRTextRenderer;
|
||||
import sun.java2d.SunGraphics2D;
|
||||
import sun.java2d.loops.XORComposite;
|
||||
|
||||
/**
|
||||
* Manages per-application resources, e.g. the 1x1 pixmap used for solid color
|
||||
@ -68,6 +71,7 @@ public class XRCompositeManager {
|
||||
int gradCachePicture;
|
||||
|
||||
boolean xorEnabled = false;
|
||||
int eargb;
|
||||
int validatedPixel = 0;
|
||||
Composite validatedComp;
|
||||
Paint validatedPaint;
|
||||
@ -170,8 +174,10 @@ public class XRCompositeManager {
|
||||
validatedComp = comp;
|
||||
}
|
||||
|
||||
if (sg2d != null && (validatedPixel != sg2d.pixel || updatePaint)) {
|
||||
validatedPixel = sg2d.pixel;
|
||||
if (sg2d != null && (eargb != sg2d.eargb || updatePaint)) {
|
||||
eargb = sg2d.eargb;
|
||||
validatedPixel = PixelConverter.ArgbPre.instance
|
||||
.rgbToPixel(eargb, null);
|
||||
setForeground(validatedPixel);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 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
|
||||
@ -25,14 +25,12 @@
|
||||
|
||||
package sun.java2d.xr;
|
||||
|
||||
import java.awt.Transparency;
|
||||
import sun.awt.X11GraphicsConfig;
|
||||
import sun.awt.X11ComponentPeer;
|
||||
import sun.awt.X11GraphicsConfig;
|
||||
import sun.awt.X11GraphicsDevice;
|
||||
import sun.awt.X11GraphicsEnvironment;
|
||||
import sun.awt.image.SurfaceManager;
|
||||
import sun.java2d.SurfaceData;
|
||||
import sun.java2d.loops.SurfaceType;
|
||||
|
||||
public class XRGraphicsConfig extends X11GraphicsConfig implements
|
||||
SurfaceManager.ProxiedGraphicsConfig {
|
||||
@ -58,14 +56,4 @@ public class XRGraphicsConfig extends X11GraphicsConfig implements
|
||||
public Object getProxyKey() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public synchronized SurfaceType getSurfaceType() {
|
||||
if (surfaceType != null) {
|
||||
return surfaceType;
|
||||
}
|
||||
|
||||
surfaceType = XRSurfaceData.getSurfaceType(this, Transparency.OPAQUE);
|
||||
return surfaceType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -36,10 +36,12 @@ import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.image.Raster;
|
||||
|
||||
import sun.awt.SunHints;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.X11ComponentPeer;
|
||||
import sun.awt.image.PixelConverter;
|
||||
import sun.font.FontManagerNativeLibrary;
|
||||
import sun.java2d.InvalidPipeException;
|
||||
import sun.java2d.SunGraphics2D;
|
||||
import sun.java2d.SurfaceData;
|
||||
@ -55,7 +57,6 @@ import sun.java2d.pipe.ShapeDrawPipe;
|
||||
import sun.java2d.pipe.TextPipe;
|
||||
import sun.java2d.pipe.ValidatePipe;
|
||||
import sun.java2d.x11.XSurfaceData;
|
||||
import sun.font.FontManagerNativeLibrary;
|
||||
|
||||
public abstract class XRSurfaceData extends XSurfaceData {
|
||||
X11ComponentPeer peer;
|
||||
@ -276,7 +277,7 @@ public abstract class XRSurfaceData extends XSurfaceData {
|
||||
}
|
||||
|
||||
return new XRPixmapSurfaceData
|
||||
(gc, width, height, image, getSurfaceType(gc, transparency),
|
||||
(gc, width, height, image, getPixmapSurfaceType(transparency),
|
||||
cm, drawable, transparency,
|
||||
XRUtils.getPictureFormatForTransparency(transparency), depth, isTexture);
|
||||
}
|
||||
@ -395,8 +396,7 @@ public abstract class XRSurfaceData extends XSurfaceData {
|
||||
* Returns the XRender SurfaceType which is able to fullfill the specified
|
||||
* transparency requirement.
|
||||
*/
|
||||
public static SurfaceType getSurfaceType(XRGraphicsConfig gc,
|
||||
int transparency) {
|
||||
public static SurfaceType getPixmapSurfaceType(int transparency) {
|
||||
SurfaceType sType = null;
|
||||
|
||||
switch (transparency) {
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8204931 8227392 8224825 8233910
|
||||
* @bug 8204931 8227392 8224825 8233910 8275843
|
||||
* @summary test alpha colors are blended with background.
|
||||
*/
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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
|
||||
@ -21,14 +21,15 @@
|
||||
* questions.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8176795
|
||||
* @bug 8176795 8275843
|
||||
* @summary Test verifies that we get proper color when we draw translucent
|
||||
* color over an opaque color using X Render extension in Linux.
|
||||
* @requires (os.family == "linux")
|
||||
* @run main XRenderTranslucentColorDrawTest -Dsun.java2d.xrender=true
|
||||
* @run main/othervm XRenderTranslucentColorDrawTest
|
||||
* @run main/othervm -Dsun.java2d.xrender=true XRenderTranslucentColorDrawTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
@ -36,30 +37,28 @@ import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.VolatileImage;
|
||||
|
||||
public class XRenderTranslucentColorDrawTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
GraphicsEnvironment env = GraphicsEnvironment.
|
||||
getLocalGraphicsEnvironment();
|
||||
GraphicsConfiguration translucentGC = null;
|
||||
SCREENS: for (GraphicsDevice screen : env.getScreenDevices()) {
|
||||
public static void main(String[] args) {
|
||||
var env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
for (GraphicsDevice screen : env.getScreenDevices()) {
|
||||
for (GraphicsConfiguration gc : screen.getConfigurations()) {
|
||||
if (gc.isTranslucencyCapable()) {
|
||||
translucentGC = gc;
|
||||
break SCREENS;
|
||||
}
|
||||
test(gc, Transparency.OPAQUE);
|
||||
test(gc, Transparency.BITMASK);
|
||||
test(gc, Transparency.TRANSLUCENT);
|
||||
}
|
||||
}
|
||||
if (translucentGC == null) {
|
||||
throw new RuntimeException("No suitable gc found.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(GraphicsConfiguration gc, int transparency) {
|
||||
int width = 10;
|
||||
int height = 10;
|
||||
VolatileImage image = translucentGC.
|
||||
createCompatibleVolatileImage(width, height);
|
||||
VolatileImage image = gc.createCompatibleVolatileImage(width, height,
|
||||
transparency);
|
||||
Graphics2D g = image.createGraphics();
|
||||
// draw opaque black color
|
||||
g.setColor(new Color(0xff000000, true));
|
||||
@ -72,10 +71,10 @@ public class XRenderTranslucentColorDrawTest {
|
||||
BufferedImage snapshot = image.getSnapshot();
|
||||
int argb = snapshot.getRGB(width / 2, height / 2);
|
||||
// we expect the resultant rgb hex value to be ff808080
|
||||
if (!(Integer.toHexString(argb).equals("ff808080"))) {
|
||||
throw new RuntimeException("Using X Render extension for drawing"
|
||||
+ " translucent color is not giving expected results.");
|
||||
String actual = Integer.toHexString(argb);
|
||||
if (!(actual.equals("ff808080"))) {
|
||||
throw new RuntimeException("Drawing translucent color is not " +
|
||||
"giving expected results: " + actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
79
test/jdk/java/awt/image/ColorModel/DrawCustomColorModel.java
Normal file
79
test/jdk/java/awt/image/ColorModel/DrawCustomColorModel.java
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright Amazon.com Inc. 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8275843
|
||||
* @key headful
|
||||
* @summary No exception or errors should occur.
|
||||
*/
|
||||
public final class DrawCustomColorModel {
|
||||
|
||||
public static void main(String[] args) {
|
||||
var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
for (GraphicsDevice gd : ge.getScreenDevices()) {
|
||||
GraphicsConfiguration[] gcs = gd.getConfigurations();
|
||||
for (GraphicsConfiguration gc : gcs) {
|
||||
test(gc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(GraphicsConfiguration gc) {
|
||||
Frame frame = new Frame(gc);
|
||||
frame.setUndecorated(true);
|
||||
frame.pack();
|
||||
frame.setSize(15, 15);
|
||||
ColorModel cm = new DirectColorModel(32,
|
||||
0xff000000, // Red
|
||||
0x00ff0000, // Green
|
||||
0x0000ff00, // Blue
|
||||
0x000000FF // Alpha
|
||||
);
|
||||
WritableRaster wr = cm.createCompatibleWritableRaster(16, 16);
|
||||
DataBufferInt buff = (DataBufferInt) wr.getDataBuffer();
|
||||
int[] data = buff.getData();
|
||||
Arrays.fill(data, -1); // more chance to reproduce
|
||||
Image image = new BufferedImage(cm, wr, false, null);
|
||||
|
||||
Graphics2D graphics = (Graphics2D) frame.getGraphics();
|
||||
graphics.setComposite(AlphaComposite.Src);
|
||||
graphics.drawImage(image, 0, 0, null);
|
||||
graphics.dispose();
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user