author | serb |
Tue, 15 Oct 2019 22:42:23 -0700 | |
changeset 59167 | 2cf90f3e8195 |
parent 49090 | test/jdk/java/awt/Color/XRenderTranslucentColorDrawTest.java@82c1fe23c469 |
permissions | -rw-r--r-- |
48647
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
1 |
/* |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
4 |
* |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
8 |
* |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
13 |
* accompanied this code). |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
14 |
* |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
18 |
* |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
21 |
* questions. |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
22 |
*/ |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
23 |
|
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
24 |
/* |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
25 |
* @test |
49090
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
48647
diff
changeset
|
26 |
* @key headful |
48647
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
27 |
* @bug 8176795 |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
28 |
* @summary Test verifies that we get proper color when we draw translucent |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
29 |
* color over an opaque color using X Render extension in Linux. |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
30 |
* @requires (os.family == "linux") |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
31 |
* @run main XRenderTranslucentColorDrawTest -Dsun.java2d.xrender=true |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
32 |
*/ |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
33 |
|
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
34 |
import java.awt.Color; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
35 |
import java.awt.Graphics2D; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
36 |
import java.awt.GraphicsConfiguration; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
37 |
import java.awt.GraphicsDevice; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
38 |
import java.awt.GraphicsEnvironment; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
39 |
import java.awt.image.BufferedImage; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
40 |
import java.awt.image.VolatileImage; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
41 |
|
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
42 |
public class XRenderTranslucentColorDrawTest { |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
43 |
|
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
44 |
public static void main(String[] args) throws Exception { |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
45 |
GraphicsEnvironment env = GraphicsEnvironment. |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
46 |
getLocalGraphicsEnvironment(); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
47 |
GraphicsConfiguration translucentGC = null; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
48 |
SCREENS: for (GraphicsDevice screen : env.getScreenDevices()) { |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
49 |
for (GraphicsConfiguration gc : screen.getConfigurations()) { |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
50 |
if (gc.isTranslucencyCapable()) { |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
51 |
translucentGC = gc; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
52 |
break SCREENS; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
53 |
} |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
54 |
} |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
55 |
} |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
56 |
if (translucentGC == null) { |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
57 |
throw new RuntimeException("No suitable gc found."); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
58 |
} |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
59 |
int width = 10; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
60 |
int height = 10; |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
61 |
VolatileImage image = translucentGC. |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
62 |
createCompatibleVolatileImage(width, height); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
63 |
Graphics2D g = image.createGraphics(); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
64 |
// draw opaque black color |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
65 |
g.setColor(new Color(0xff000000, true)); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
66 |
g.fillRect(0, 0, width, height); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
67 |
// draw translucent white color over opaque black color |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
68 |
g.setColor(new Color(0x80ffffff, true)); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
69 |
g.fillRect(0, 0, width, height); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
70 |
g.dispose(); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
71 |
// Get snapshot of VolatileImage to pick color and verify the same |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
72 |
BufferedImage snapshot = image.getSnapshot(); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
73 |
int argb = snapshot.getRGB(width / 2, height / 2); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
74 |
// we expect the resultant rgb hex value to be ff808080 |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
75 |
if (!(Integer.toHexString(argb).equals("ff808080"))) { |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
76 |
throw new RuntimeException("Using X Render extension for drawing" |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
77 |
+ " translucent color is not giving expected results."); |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
78 |
} |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
79 |
} |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
80 |
} |
e4b03365ddbf
8176795: Wrong color drawn when painting translucent colors on volatile images using XRender.
jdv
parents:
diff
changeset
|
81 |