8251558: J2DBench should support shaped and translucent windows

Reviewed-by: avu
This commit is contained in:
Sergey Bylokhov 2020-08-24 00:34:35 +01:00
parent b6c861f9f8
commit 484864c932
9 changed files with 139 additions and 20 deletions

@ -1,5 +1,5 @@
# #
# Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions # modification, are permitted provided that the following conditions
@ -120,7 +120,7 @@ $(CLASSES):
mkdirs: $(DIST) $(CLASSES) mkdirs: $(DIST) $(CLASSES)
$(CLASSES)/j2dbench/%.class: $(SOURCEPATH)/j2dbench/%.java $(CLASSES)/j2dbench/%.class: $(SOURCEPATH)/j2dbench/%.java
javac -g:none -source 1.6 -target 1.6 -d $(CLASSES) -sourcepath $(SOURCEPATH) $< javac -g:none -source 1.7 -target 1.7 -d $(CLASSES) -sourcepath $(SOURCEPATH) $<
clean: clean:
rm -rf $(CLASSES) rm -rf $(CLASSES)

@ -20,8 +20,9 @@ Minimum requirements
----------------------------------------------------------------------- -----------------------------------------------------------------------
The benchmark requires at least jdk1.4 to compile and run. Note that The benchmark requires at least jdk1.4 to compile and run. Note that
source/target is set to 1.6 in the makefile and build.xml, because of source/target is set to 1.7 in the makefile and build.xml, because of
support in jdk 9 compiler. support in jdk 14 compiler. To check compatibility with jdk1.4 you can
use "-source 1.4 -target 1.4" options and jdk1.7.
----------------------------------------------------------------------- -----------------------------------------------------------------------
How To Compile How To Compile

@ -1,5 +1,5 @@
<!-- <!--
Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@ -49,7 +49,7 @@
<target name="compile" depends="init" <target name="compile" depends="init"
description="compile the source " > description="compile the source " >
<!-- Compile the java code from ${src} into ${build} --> <!-- Compile the java code from ${src} into ${build} -->
<javac debug="off" source="1.6" target="1.6" srcdir="${src}" destdir="${build}"/> <javac debug="off" source="1.7" target="1.7" srcdir="${src}" destdir="${build}"/>
</target> </target>
<target name="run" depends="dist" <target name="run" depends="dist"

@ -8,8 +8,11 @@ global.env.testtime=2500
global.results.workunits=units global.results.workunits=units
global.results.timeunits=sec global.results.timeunits=sec
global.results.ratio=unitspersec global.results.ratio=unitspersec
global.dest.screen=disabled
global.dest.offscreen=disabled global.dest.offscreen=disabled
global.dest.frame.defaultframe=disabled
global.dest.frame.transframe=disabled
global.dest.frame.shapedframe=disabled
global.dest.frame.shapedtransframe=disabled
global.dest.compatimg.compatimg=disabled global.dest.compatimg.compatimg=disabled
global.dest.compatimg.opqcompatimg=disabled global.dest.compatimg.opqcompatimg=disabled
global.dest.compatimg.bmcompatimg=disabled global.dest.compatimg.bmcompatimg=disabled

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -40,9 +40,11 @@
package j2dbench; package j2dbench;
import java.awt.Image;
import java.awt.Component; import java.awt.Component;
import java.awt.Frame;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Polygon;
import java.awt.Transparency; import java.awt.Transparency;
import java.awt.color.ColorSpace; import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -50,11 +52,14 @@ import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer; import java.awt.image.DataBuffer;
import java.awt.image.WritableRaster; import java.awt.image.WritableRaster;
import javax.swing.SwingUtilities;
import j2dbench.tests.GraphicsTests; import j2dbench.tests.GraphicsTests;
import j2dbench.tests.ImageTests; import j2dbench.tests.ImageTests;
public abstract class Destinations extends Option.Enable { public abstract class Destinations extends Option.Enable {
public static Group.EnableSet destroot; public static Group.EnableSet destroot;
public static Group frameroot;
public static Group bufimgdestroot; public static Group bufimgdestroot;
public static Group compatimgdestroot; public static Group compatimgdestroot;
public static Group volimgdestroot; public static Group volimgdestroot;
@ -63,9 +68,22 @@ public abstract class Destinations extends Option.Enable {
destroot = new Group.EnableSet(TestEnvironment.globaloptroot, destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
"dest", "Output Destination Options"); "dest", "Output Destination Options");
new Screen();
new OffScreen(); new OffScreen();
frameroot = new Group.EnableSet(destroot, "frame", "Output to Frame");
frameroot.setHorizontal();
new Screen(false, false);
if (ImageTests.hasOpacityWindow) {
new Screen(true, false);
}
if (ImageTests.hasShapedWindow) {
new Screen(false, true);
}
if (ImageTests.hasShapedWindow && ImageTests.hasOpacityWindow) {
new Screen(true, true);
}
if (GraphicsTests.hasGraphics2D) { if (GraphicsTests.hasGraphics2D) {
if (ImageTests.hasCompatImage) { if (ImageTests.hasCompatImage) {
compatimgdestroot = compatimgdestroot =
@ -129,17 +147,95 @@ public abstract class Destinations extends Option.Enable {
public abstract void setDestination(TestEnvironment env); public abstract void setDestination(TestEnvironment env);
public static class Screen extends Destinations { public static class Screen extends Destinations {
public Screen() {
super(destroot, "screen", "Output to Screen", false); private boolean opacity;
private boolean shaped;
public Screen(boolean opacity, boolean shaped) {
super(frameroot, getDescription(opacity,shaped),
getLongDescription(opacity,shaped), false);
this.opacity = opacity;
this.shaped = shaped;
}
private static String getDescription(boolean opacity, boolean shaped){
if (opacity && shaped) {
return "shapedtransframe";
}
if (shaped) {
return "shapedframe";
}
if (opacity) {
return "transframe";
}
return "defaultframe";
}
private static String getLongDescription(boolean opacity, boolean shaped){
if (opacity && shaped) {
return "Translucent and Shaped";
}
if (shaped) {
return "Shaped";
}
if (opacity) {
return "Translucent";
}
return "Default";
} }
public String getModifierValueName(Object val) { public String getModifierValueName(Object val) {
return "Screen"; if (opacity && shaped) {
return "Translucent and Shaped Frame";
}
if (shaped) {
return "Shaped Frame";
}
if (opacity) {
return "Translucent Frame";
}
return "Default Frame";
} }
public void setDestination(TestEnvironment env) { public void setDestination(TestEnvironment env) {
env.setTestImage(null); env.setTestImage(null);
} }
public void modifyTest(TestEnvironment env) {
setDestination(env);
Frame frame = (Frame) SwingUtilities.getWindowAncestor(env.comp);
if (frame != null && (opacity || shaped)) {
frame.dispose();
frame.setUndecorated(true);
int w = frame.getWidth();
int h = frame.getHeight();
if (shaped) {
Polygon p = new Polygon();
p.addPoint(0, 0);
p.addPoint(w, 0);
p.addPoint(0, h);
p.addPoint(w, h);
p.addPoint(0, 0);
frame.setShape(p);
}
if (opacity) {
frame.setOpacity(0.5f);
}
frame.setVisible(true);
}
}
public void restoreTest(TestEnvironment env) {
env.setTestImage(null);
Frame frame = (Frame) SwingUtilities.getWindowAncestor(env.comp);
if (frame != null && (opacity || shaped)) {
frame.dispose();
frame.setShape(null);
frame.setOpacity(1);
frame.setUndecorated(false);
frame.setVisible(true);
}
}
} }
public static class OffScreen extends Destinations { public static class OffScreen extends Destinations {

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -40,6 +40,8 @@
package j2dbench; package j2dbench;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
@ -780,7 +782,10 @@ public class J2DBench {
f.getContentPane().add(p, BorderLayout.SOUTH); f.getContentPane().add(p, BorderLayout.SOUTH);
f.pack(); f.pack();
f.setLocationRelativeTo(null); f.setLocationRelativeTo(null);
f.show(); Rectangle usable = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getMaximumWindowBounds().intersection(f.getBounds());
f.setBounds(usable);
f.setVisible(true);
} }
public static void runTests(boolean showresults) { public static void runTests(boolean showresults) {

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -53,7 +53,9 @@ import java.awt.Canvas;
import java.awt.AlphaComposite; import java.awt.AlphaComposite;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GraphicsConfiguration; import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Window;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp; import java.awt.image.BufferedImageOp;
import java.awt.image.ByteLookupTable; import java.awt.image.ByteLookupTable;
@ -79,6 +81,8 @@ import javax.swing.JComponent;
public abstract class ImageTests extends GraphicsTests { public abstract class ImageTests extends GraphicsTests {
public static boolean hasVolatileImage; public static boolean hasVolatileImage;
public static boolean hasTransparentVolatileImage; public static boolean hasTransparentVolatileImage;
public static boolean hasShapedWindow;
public static boolean hasOpacityWindow;
public static boolean hasCompatImage; public static boolean hasCompatImage;
static { static {
@ -96,6 +100,16 @@ public abstract class ImageTests extends GraphicsTests {
hasTransparentVolatileImage = true; hasTransparentVolatileImage = true;
} catch (NoSuchMethodError e) { } catch (NoSuchMethodError e) {
} }
try {
new Window(null).setShape(new Rectangle());
hasShapedWindow = true;
} catch (Exception e) {
}
try {
new Window(null).setOpacity(0.5f);
hasOpacityWindow = true;
} catch (Exception e) {
}
} }
static Group imageroot; static Group imageroot;

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -184,7 +184,7 @@ abstract class InputImageTests extends InputTests {
String klass = spi.getClass().getName(); String klass = spi.getClass().getName();
String format = spi.getFormatNames()[0].toLowerCase(); String format = spi.getFormatNames()[0].toLowerCase();
String suffix = spi.getFileSuffixes()[0].toLowerCase(); String suffix = spi.getFileSuffixes()[0].toLowerCase();
if (suffix == null || suffix.isEmpty()) { if (suffix == null || suffix.equals("")) {
suffix = format; suffix = format;
} }
String shortName; String shortName;

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -143,7 +143,7 @@ abstract class OutputImageTests extends OutputTests {
String klass = spi.getClass().getName(); String klass = spi.getClass().getName();
String format = spi.getFormatNames()[0].toLowerCase(); String format = spi.getFormatNames()[0].toLowerCase();
String suffix = spi.getFileSuffixes()[0].toLowerCase(); String suffix = spi.getFileSuffixes()[0].toLowerCase();
if (suffix == null || suffix.isEmpty()) { if (suffix == null || suffix.equals("")) {
suffix = format; suffix = format;
} }
String shortName; String shortName;