Skip to content

Commit f8ed0fe

Browse files
committed
8251558: J2DBench should support shaped and translucent windows
Reviewed-by: shade Backport-of: 484864c
1 parent db702ee commit f8ed0fe

File tree

4 files changed

+128
-10
lines changed

4 files changed

+128
-10
lines changed

src/demo/share/java2d/J2DBench/options/default.opt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ global.env.testtime=2500
88
global.results.workunits=units
99
global.results.timeunits=sec
1010
global.results.ratio=unitspersec
11-
global.dest.screen=disabled
1211
global.dest.offscreen=disabled
12+
global.dest.frame.defaultframe=disabled
13+
global.dest.frame.transframe=disabled
14+
global.dest.frame.shapedframe=disabled
15+
global.dest.frame.shapedtransframe=disabled
1316
global.dest.compatimg.compatimg=disabled
1417
global.dest.compatimg.opqcompatimg=disabled
1518
global.dest.compatimg.bmcompatimg=disabled

src/demo/share/java2d/J2DBench/src/j2dbench/Destinations.java

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -40,21 +40,26 @@
4040

4141
package j2dbench;
4242

43-
import java.awt.Image;
4443
import java.awt.Component;
44+
import java.awt.Frame;
4545
import java.awt.GraphicsConfiguration;
46+
import java.awt.Image;
47+
import java.awt.Polygon;
4648
import java.awt.Transparency;
4749
import java.awt.color.ColorSpace;
4850
import java.awt.image.BufferedImage;
4951
import java.awt.image.ComponentColorModel;
5052
import java.awt.image.DataBuffer;
5153
import java.awt.image.WritableRaster;
5254

55+
import javax.swing.SwingUtilities;
56+
5357
import j2dbench.tests.GraphicsTests;
5458
import j2dbench.tests.ImageTests;
5559

5660
public abstract class Destinations extends Option.Enable {
5761
public static Group.EnableSet destroot;
62+
public static Group frameroot;
5863
public static Group bufimgdestroot;
5964
public static Group compatimgdestroot;
6065
public static Group volimgdestroot;
@@ -63,9 +68,22 @@ public static void init() {
6368
destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
6469
"dest", "Output Destination Options");
6570

66-
new Screen();
6771
new OffScreen();
6872

73+
frameroot = new Group.EnableSet(destroot, "frame", "Output to Frame");
74+
frameroot.setHorizontal();
75+
76+
new Screen(false, false);
77+
if (ImageTests.hasOpacityWindow) {
78+
new Screen(true, false);
79+
}
80+
if (ImageTests.hasShapedWindow) {
81+
new Screen(false, true);
82+
}
83+
if (ImageTests.hasShapedWindow && ImageTests.hasOpacityWindow) {
84+
new Screen(true, true);
85+
}
86+
6987
if (GraphicsTests.hasGraphics2D) {
7088
if (ImageTests.hasCompatImage) {
7189
compatimgdestroot =
@@ -129,17 +147,95 @@ public String getAbbreviatedModifierDescription(Object val) {
129147
public abstract void setDestination(TestEnvironment env);
130148

131149
public static class Screen extends Destinations {
132-
public Screen() {
133-
super(destroot, "screen", "Output to Screen", false);
150+
151+
private boolean opacity;
152+
private boolean shaped;
153+
154+
public Screen(boolean opacity, boolean shaped) {
155+
super(frameroot, getDescription(opacity,shaped),
156+
getLongDescription(opacity,shaped), false);
157+
this.opacity = opacity;
158+
this.shaped = shaped;
159+
}
160+
161+
private static String getDescription(boolean opacity, boolean shaped){
162+
if (opacity && shaped) {
163+
return "shapedtransframe";
164+
}
165+
if (shaped) {
166+
return "shapedframe";
167+
}
168+
if (opacity) {
169+
return "transframe";
170+
}
171+
return "defaultframe";
172+
}
173+
174+
private static String getLongDescription(boolean opacity, boolean shaped){
175+
if (opacity && shaped) {
176+
return "Translucent and Shaped";
177+
}
178+
if (shaped) {
179+
return "Shaped";
180+
}
181+
if (opacity) {
182+
return "Translucent";
183+
}
184+
return "Default";
134185
}
135186

136187
public String getModifierValueName(Object val) {
137-
return "Screen";
188+
if (opacity && shaped) {
189+
return "Translucent and Shaped Frame";
190+
}
191+
if (shaped) {
192+
return "Shaped Frame";
193+
}
194+
if (opacity) {
195+
return "Translucent Frame";
196+
}
197+
return "Default Frame";
138198
}
139199

140200
public void setDestination(TestEnvironment env) {
141201
env.setTestImage(null);
142202
}
203+
204+
public void modifyTest(TestEnvironment env) {
205+
setDestination(env);
206+
Frame frame = (Frame) SwingUtilities.getWindowAncestor(env.comp);
207+
if (frame != null && (opacity || shaped)) {
208+
frame.dispose();
209+
frame.setUndecorated(true);
210+
int w = frame.getWidth();
211+
int h = frame.getHeight();
212+
if (shaped) {
213+
Polygon p = new Polygon();
214+
p.addPoint(0, 0);
215+
p.addPoint(w, 0);
216+
p.addPoint(0, h);
217+
p.addPoint(w, h);
218+
p.addPoint(0, 0);
219+
frame.setShape(p);
220+
}
221+
if (opacity) {
222+
frame.setOpacity(0.5f);
223+
}
224+
frame.setVisible(true);
225+
}
226+
}
227+
228+
public void restoreTest(TestEnvironment env) {
229+
env.setTestImage(null);
230+
Frame frame = (Frame) SwingUtilities.getWindowAncestor(env.comp);
231+
if (frame != null && (opacity || shaped)) {
232+
frame.dispose();
233+
frame.setShape(null);
234+
frame.setOpacity(1);
235+
frame.setUndecorated(false);
236+
frame.setVisible(true);
237+
}
238+
}
143239
}
144240

145241
public static class OffScreen extends Destinations {

src/demo/share/java2d/J2DBench/src/j2dbench/J2DBench.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -40,6 +40,8 @@
4040

4141
package j2dbench;
4242

43+
import java.awt.GraphicsEnvironment;
44+
import java.awt.Rectangle;
4345
import java.io.PrintWriter;
4446
import java.io.FileReader;
4547
import java.io.FileWriter;
@@ -780,7 +782,10 @@ public void actionPerformed(ActionEvent e) {
780782
f.getContentPane().add(p, BorderLayout.SOUTH);
781783
f.pack();
782784
f.setLocationRelativeTo(null);
783-
f.show();
785+
Rectangle usable = GraphicsEnvironment.getLocalGraphicsEnvironment()
786+
.getMaximumWindowBounds().intersection(f.getBounds());
787+
f.setBounds(usable);
788+
f.setVisible(true);
784789
}
785790

786791
public static void runTests(boolean showresults) {

src/demo/share/java2d/J2DBench/src/j2dbench/tests/ImageTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -53,7 +53,9 @@
5353
import java.awt.AlphaComposite;
5454
import java.awt.Dimension;
5555
import java.awt.GraphicsConfiguration;
56+
import java.awt.Rectangle;
5657
import java.awt.RenderingHints;
58+
import java.awt.Window;
5759
import java.awt.image.BufferedImage;
5860
import java.awt.image.BufferedImageOp;
5961
import java.awt.image.ByteLookupTable;
@@ -79,6 +81,8 @@
7981
public abstract class ImageTests extends GraphicsTests {
8082
public static boolean hasVolatileImage;
8183
public static boolean hasTransparentVolatileImage;
84+
public static boolean hasShapedWindow;
85+
public static boolean hasOpacityWindow;
8286
public static boolean hasCompatImage;
8387

8488
static {
@@ -96,6 +100,16 @@ public abstract class ImageTests extends GraphicsTests {
96100
hasTransparentVolatileImage = true;
97101
} catch (NoSuchMethodError e) {
98102
}
103+
try {
104+
new Window(null).setShape(new Rectangle());
105+
hasShapedWindow = true;
106+
} catch (Exception e) {
107+
}
108+
try {
109+
new Window(null).setOpacity(0.5f);
110+
hasOpacityWindow = true;
111+
} catch (Exception e) {
112+
}
99113
}
100114

101115
static Group imageroot;

0 commit comments

Comments
 (0)