1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
21
21
* questions.
22
22
*/
23
23
24
+
24
25
/*
25
26
* @test
26
27
* @key headful
27
- * @bug 8176795
28
+ * @bug 8176795 8275843
28
29
* @summary Test verifies that we get proper color when we draw translucent
29
30
* 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
32
33
*/
33
34
34
35
import java .awt .Color ;
35
36
import java .awt .Graphics2D ;
36
37
import java .awt .GraphicsConfiguration ;
37
38
import java .awt .GraphicsDevice ;
38
39
import java .awt .GraphicsEnvironment ;
40
+ import java .awt .Transparency ;
39
41
import java .awt .image .BufferedImage ;
40
42
import java .awt .image .VolatileImage ;
41
43
42
44
public class XRenderTranslucentColorDrawTest {
43
45
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 ()) {
49
49
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 );
54
53
}
55
54
}
56
- if ( translucentGC == null ) {
57
- throw new RuntimeException ( "No suitable gc found." );
58
- }
55
+ }
56
+
57
+ private static void test ( GraphicsConfiguration gc , int transparency ) {
59
58
int width = 10 ;
60
59
int height = 10 ;
61
- VolatileImage image = translucentGC .
62
- createCompatibleVolatileImage ( width , height );
60
+ VolatileImage image = gc . createCompatibleVolatileImage ( width , height ,
61
+ transparency );
63
62
Graphics2D g = image .createGraphics ();
64
63
// draw opaque black color
65
64
g .setColor (new Color (0xff000000 , true ));
@@ -72,10 +71,10 @@ public static void main(String[] args) throws Exception {
72
71
BufferedImage snapshot = image .getSnapshot ();
73
72
int argb = snapshot .getRGB (width / 2 , height / 2 );
74
73
// 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 );
78
78
}
79
79
}
80
- }
81
-
80
+ }
0 commit comments