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
4040
4141package j2dbench ;
4242
43- import java .awt .Image ;
4443import java .awt .Component ;
44+ import java .awt .Frame ;
4545import java .awt .GraphicsConfiguration ;
46+ import java .awt .Image ;
47+ import java .awt .Polygon ;
4648import java .awt .Transparency ;
4749import java .awt .color .ColorSpace ;
4850import java .awt .image .BufferedImage ;
4951import java .awt .image .ComponentColorModel ;
5052import java .awt .image .DataBuffer ;
5153import java .awt .image .WritableRaster ;
5254
55+ import javax .swing .SwingUtilities ;
56+
5357import j2dbench .tests .GraphicsTests ;
5458import j2dbench .tests .ImageTests ;
5559
5660public 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 {
0 commit comments