Skip to content

Commit

Permalink
8251558: J2DBench should support shaped and translucent windows
Browse files Browse the repository at this point in the history
Reviewed-by: avu
  • Loading branch information
mrserb committed Aug 23, 2020
1 parent b6c861f commit 484864c
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/demo/share/java2d/J2DBench/Makefile
@@ -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
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -120,7 +120,7 @@ $(CLASSES):
mkdirs: $(DIST) $(CLASSES)

$(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:
rm -rf $(CLASSES)
Expand Down
5 changes: 3 additions & 2 deletions src/demo/share/java2d/J2DBench/README
Expand Up @@ -20,8 +20,9 @@ Minimum requirements
-----------------------------------------------------------------------

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
support in jdk 9 compiler.
source/target is set to 1.7 in the makefile and build.xml, because of
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
Expand Down
4 changes: 2 additions & 2 deletions src/demo/share/java2d/J2DBench/build.xml
@@ -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
modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -49,7 +49,7 @@
<target name="compile" depends="init"
description="compile the source " >
<!-- 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 name="run" depends="dist"
Expand Down
5 changes: 4 additions & 1 deletion src/demo/share/java2d/J2DBench/options/default.opt
Expand Up @@ -8,8 +8,11 @@ global.env.testtime=2500
global.results.workunits=units
global.results.timeunits=sec
global.results.ratio=unitspersec
global.dest.screen=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.opqcompatimg=disabled
global.dest.compatimg.bmcompatimg=disabled
Expand Down
108 changes: 102 additions & 6 deletions src/demo/share/java2d/J2DBench/src/j2dbench/Destinations.java
@@ -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
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -40,21 +40,26 @@

package j2dbench;

import java.awt.Image;
import java.awt.Component;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Polygon;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.WritableRaster;

import javax.swing.SwingUtilities;

import j2dbench.tests.GraphicsTests;
import j2dbench.tests.ImageTests;

public abstract class Destinations extends Option.Enable {
public static Group.EnableSet destroot;
public static Group frameroot;
public static Group bufimgdestroot;
public static Group compatimgdestroot;
public static Group volimgdestroot;
Expand All @@ -63,9 +68,22 @@ public static void init() {
destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
"dest", "Output Destination Options");

new Screen();
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 (ImageTests.hasCompatImage) {
compatimgdestroot =
Expand Down Expand Up @@ -129,17 +147,95 @@ public String getAbbreviatedModifierDescription(Object val) {
public abstract void setDestination(TestEnvironment env);

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) {
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) {
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 {
Expand Down
9 changes: 7 additions & 2 deletions src/demo/share/java2d/J2DBench/src/j2dbench/J2DBench.java
@@ -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
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -40,6 +40,8 @@

package j2dbench;

import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.FileWriter;
Expand Down Expand Up @@ -780,7 +782,10 @@ public void actionPerformed(ActionEvent e) {
f.getContentPane().add(p, BorderLayout.SOUTH);
f.pack();
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) {
Expand Down
@@ -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
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -53,7 +53,9 @@
import java.awt.AlphaComposite;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Window;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ByteLookupTable;
Expand All @@ -79,6 +81,8 @@
public abstract class ImageTests extends GraphicsTests {
public static boolean hasVolatileImage;
public static boolean hasTransparentVolatileImage;
public static boolean hasShapedWindow;
public static boolean hasOpacityWindow;
public static boolean hasCompatImage;

static {
Expand All @@ -96,6 +100,16 @@ public abstract class ImageTests extends GraphicsTests {
hasTransparentVolatileImage = true;
} 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;
Expand Down
@@ -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
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -184,7 +184,7 @@ private static void initIIOReadFormats() {
String klass = spi.getClass().getName();
String format = spi.getFormatNames()[0].toLowerCase();
String suffix = spi.getFileSuffixes()[0].toLowerCase();
if (suffix == null || suffix.isEmpty()) {
if (suffix == null || suffix.equals("")) {
suffix = format;
}
String shortName;
Expand Down
@@ -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
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -143,7 +143,7 @@ private static void initIIOWriteFormats() {
String klass = spi.getClass().getName();
String format = spi.getFormatNames()[0].toLowerCase();
String suffix = spi.getFileSuffixes()[0].toLowerCase();
if (suffix == null || suffix.isEmpty()) {
if (suffix == null || suffix.equals("")) {
suffix = format;
}
String shortName;
Expand Down

0 comments on commit 484864c

Please sign in to comment.