Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8251558: J2DBench should support shaped and translucent windows #613

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/demo/share/java2d/J2DBench/options/default.opt
Original file line number Diff line number Diff line change
@@ -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
108 changes: 102 additions & 6 deletions src/demo/share/java2d/J2DBench/src/j2dbench/Destinations.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2014, 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
@@ -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;
@@ -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 =
@@ -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 {
9 changes: 7 additions & 2 deletions src/demo/share/java2d/J2DBench/src/j2dbench/J2DBench.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2015, 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
@@ -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;
@@ -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) {
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2014, 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
@@ -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;
@@ -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 {
@@ -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;