Skip to content

Commit 6dbb692

Browse files
author
duke
committedDec 14, 2021
Automatic merge of jdk:master into master
2 parents 3fb3305 + a9c1acb commit 6dbb692

File tree

6 files changed

+122
-50
lines changed

6 files changed

+122
-50
lines changed
 

‎src/java.desktop/unix/classes/sun/java2d/xr/XRCompositeManager.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@
2525

2626
package sun.java2d.xr;
2727

28-
import java.awt.*;
29-
import java.awt.geom.*;
30-
28+
import java.awt.AlphaComposite;
29+
import java.awt.Composite;
30+
import java.awt.Paint;
31+
import java.awt.geom.AffineTransform;
32+
import java.awt.geom.NoninvertibleTransformException;
3133
import java.security.AccessController;
3234
import java.security.PrivilegedAction;
3335

34-
import sun.font.*;
35-
import sun.java2d.*;
36-
import sun.java2d.loops.*;
36+
import sun.awt.image.PixelConverter;
37+
import sun.font.XRTextRenderer;
38+
import sun.java2d.SunGraphics2D;
39+
import sun.java2d.loops.XORComposite;
3740

3841
/**
3942
* Manages per-application resources, e.g. the 1x1 pixmap used for solid color
@@ -68,6 +71,7 @@ public class XRCompositeManager {
6871
int gradCachePicture;
6972

7073
boolean xorEnabled = false;
74+
int eargb;
7175
int validatedPixel = 0;
7276
Composite validatedComp;
7377
Paint validatedPaint;
@@ -170,8 +174,10 @@ public void validateCompositeState(Composite comp, AffineTransform xform,
170174
validatedComp = comp;
171175
}
172176

173-
if (sg2d != null && (validatedPixel != sg2d.pixel || updatePaint)) {
174-
validatedPixel = sg2d.pixel;
177+
if (sg2d != null && (eargb != sg2d.eargb || updatePaint)) {
178+
eargb = sg2d.eargb;
179+
validatedPixel = PixelConverter.ArgbPre.instance
180+
.rgbToPixel(eargb, null);
175181
setForeground(validatedPixel);
176182
}
177183

‎src/java.desktop/unix/classes/sun/java2d/xr/XRGraphicsConfig.java

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,14 +25,12 @@
2525

2626
package sun.java2d.xr;
2727

28-
import java.awt.Transparency;
29-
import sun.awt.X11GraphicsConfig;
3028
import sun.awt.X11ComponentPeer;
29+
import sun.awt.X11GraphicsConfig;
3130
import sun.awt.X11GraphicsDevice;
3231
import sun.awt.X11GraphicsEnvironment;
3332
import sun.awt.image.SurfaceManager;
3433
import sun.java2d.SurfaceData;
35-
import sun.java2d.loops.SurfaceType;
3634

3735
public class XRGraphicsConfig extends X11GraphicsConfig implements
3836
SurfaceManager.ProxiedGraphicsConfig {
@@ -58,14 +56,4 @@ public static XRGraphicsConfig getConfig(X11GraphicsDevice device,
5856
public Object getProxyKey() {
5957
return this;
6058
}
61-
62-
public synchronized SurfaceType getSurfaceType() {
63-
if (surfaceType != null) {
64-
return surfaceType;
65-
}
66-
67-
surfaceType = XRSurfaceData.getSurfaceType(this, Transparency.OPAQUE);
68-
return surfaceType;
69-
}
70-
7159
}

‎src/java.desktop/unix/classes/sun/java2d/xr/XRSurfaceData.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
import java.awt.image.ColorModel;
3737
import java.awt.image.DirectColorModel;
3838
import java.awt.image.Raster;
39+
3940
import sun.awt.SunHints;
4041
import sun.awt.SunToolkit;
4142
import sun.awt.X11ComponentPeer;
4243
import sun.awt.image.PixelConverter;
44+
import sun.font.FontManagerNativeLibrary;
4345
import sun.java2d.InvalidPipeException;
4446
import sun.java2d.SunGraphics2D;
4547
import sun.java2d.SurfaceData;
@@ -55,7 +57,6 @@
5557
import sun.java2d.pipe.TextPipe;
5658
import sun.java2d.pipe.ValidatePipe;
5759
import sun.java2d.x11.XSurfaceData;
58-
import sun.font.FontManagerNativeLibrary;
5960

6061
public abstract class XRSurfaceData extends XSurfaceData {
6162
X11ComponentPeer peer;
@@ -276,7 +277,7 @@ public static XRPixmapSurfaceData createData(XRGraphicsConfig gc,
276277
}
277278

278279
return new XRPixmapSurfaceData
279-
(gc, width, height, image, getSurfaceType(gc, transparency),
280+
(gc, width, height, image, getPixmapSurfaceType(transparency),
280281
cm, drawable, transparency,
281282
XRUtils.getPictureFormatForTransparency(transparency), depth, isTexture);
282283
}
@@ -395,8 +396,7 @@ public boolean copyArea(SunGraphics2D sg2d, int x, int y, int w, int h,
395396
* Returns the XRender SurfaceType which is able to fullfill the specified
396397
* transparency requirement.
397398
*/
398-
public static SurfaceType getSurfaceType(XRGraphicsConfig gc,
399-
int transparency) {
399+
public static SurfaceType getPixmapSurfaceType(int transparency) {
400400
SurfaceType sType = null;
401401

402402
switch (transparency) {

‎test/jdk/java/awt/ColorClass/AlphaColorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* @test
2626
* @key headful
27-
* @bug 8204931 8227392 8224825 8233910
27+
* @bug 8204931 8227392 8224825 8233910 8275843
2828
* @summary test alpha colors are blended with background.
2929
*/
3030

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,45 +21,44 @@
2121
* questions.
2222
*/
2323

24+
2425
/*
2526
* @test
2627
* @key headful
27-
* @bug 8176795
28+
* @bug 8176795 8275843
2829
* @summary Test verifies that we get proper color when we draw translucent
2930
* color over an opaque color using X Render extension in Linux.
30-
* @requires (os.family == "linux")
31-
* @run main XRenderTranslucentColorDrawTest -Dsun.java2d.xrender=true
31+
* @run main/othervm XRenderTranslucentColorDrawTest
32+
* @run main/othervm -Dsun.java2d.xrender=true XRenderTranslucentColorDrawTest
3233
*/
3334

3435
import java.awt.Color;
3536
import java.awt.Graphics2D;
3637
import java.awt.GraphicsConfiguration;
3738
import java.awt.GraphicsDevice;
3839
import java.awt.GraphicsEnvironment;
40+
import java.awt.Transparency;
3941
import java.awt.image.BufferedImage;
4042
import java.awt.image.VolatileImage;
4143

4244
public class XRenderTranslucentColorDrawTest {
4345

44-
public static void main(String[] args) throws Exception {
45-
GraphicsEnvironment env = GraphicsEnvironment.
46-
getLocalGraphicsEnvironment();
47-
GraphicsConfiguration translucentGC = null;
48-
SCREENS: for (GraphicsDevice screen : env.getScreenDevices()) {
46+
public static void main(String[] args) {
47+
var env = GraphicsEnvironment.getLocalGraphicsEnvironment();
48+
for (GraphicsDevice screen : env.getScreenDevices()) {
4949
for (GraphicsConfiguration gc : screen.getConfigurations()) {
50-
if (gc.isTranslucencyCapable()) {
51-
translucentGC = gc;
52-
break SCREENS;
53-
}
50+
test(gc, Transparency.OPAQUE);
51+
test(gc, Transparency.BITMASK);
52+
test(gc, Transparency.TRANSLUCENT);
5453
}
5554
}
56-
if (translucentGC == null) {
57-
throw new RuntimeException("No suitable gc found.");
58-
}
55+
}
56+
57+
private static void test(GraphicsConfiguration gc, int transparency) {
5958
int width = 10;
6059
int height = 10;
61-
VolatileImage image = translucentGC.
62-
createCompatibleVolatileImage(width, height);
60+
VolatileImage image = gc.createCompatibleVolatileImage(width, height,
61+
transparency);
6362
Graphics2D g = image.createGraphics();
6463
// draw opaque black color
6564
g.setColor(new Color(0xff000000, true));
@@ -72,10 +71,10 @@ public static void main(String[] args) throws Exception {
7271
BufferedImage snapshot = image.getSnapshot();
7372
int argb = snapshot.getRGB(width / 2, height / 2);
7473
// we expect the resultant rgb hex value to be ff808080
75-
if (!(Integer.toHexString(argb).equals("ff808080"))) {
76-
throw new RuntimeException("Using X Render extension for drawing"
77-
+ " translucent color is not giving expected results.");
74+
String actual = Integer.toHexString(argb);
75+
if (!(actual.equals("ff808080"))) {
76+
throw new RuntimeException("Drawing translucent color is not " +
77+
"giving expected results: " + actual);
7878
}
7979
}
80-
}
81-
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.AlphaComposite;
25+
import java.awt.Frame;
26+
import java.awt.Graphics2D;
27+
import java.awt.GraphicsConfiguration;
28+
import java.awt.GraphicsDevice;
29+
import java.awt.GraphicsEnvironment;
30+
import java.awt.Image;
31+
import java.awt.image.BufferedImage;
32+
import java.awt.image.ColorModel;
33+
import java.awt.image.DataBufferInt;
34+
import java.awt.image.DirectColorModel;
35+
import java.awt.image.WritableRaster;
36+
import java.util.Arrays;
37+
38+
/**
39+
* @test
40+
* @bug 8275843
41+
* @key headful
42+
* @summary No exception or errors should occur.
43+
*/
44+
public final class DrawCustomColorModel {
45+
46+
public static void main(String[] args) {
47+
var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
48+
for (GraphicsDevice gd : ge.getScreenDevices()) {
49+
GraphicsConfiguration[] gcs = gd.getConfigurations();
50+
for (GraphicsConfiguration gc : gcs) {
51+
test(gc);
52+
}
53+
}
54+
}
55+
56+
private static void test(GraphicsConfiguration gc) {
57+
Frame frame = new Frame(gc);
58+
frame.setUndecorated(true);
59+
frame.pack();
60+
frame.setSize(15, 15);
61+
ColorModel cm = new DirectColorModel(32,
62+
0xff000000, // Red
63+
0x00ff0000, // Green
64+
0x0000ff00, // Blue
65+
0x000000FF // Alpha
66+
);
67+
WritableRaster wr = cm.createCompatibleWritableRaster(16, 16);
68+
DataBufferInt buff = (DataBufferInt) wr.getDataBuffer();
69+
int[] data = buff.getData();
70+
Arrays.fill(data, -1); // more chance to reproduce
71+
Image image = new BufferedImage(cm, wr, false, null);
72+
73+
Graphics2D graphics = (Graphics2D) frame.getGraphics();
74+
graphics.setComposite(AlphaComposite.Src);
75+
graphics.drawImage(image, 0, 0, null);
76+
graphics.dispose();
77+
frame.dispose();
78+
}
79+
}

0 commit comments

Comments
 (0)
Failed to load comments.