use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.
the class bug8071705 method main.
public static void main(String[] args) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final boolean[] result = new boolean[1];
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = createGUI();
GraphicsDevice[] devices = checkScreens();
// check if we have more than one and if they are stacked
// vertically
GraphicsDevice device = checkConfigs(devices);
if (device == null) {
// just pass the test
frame.dispose();
result[0] = true;
latch.countDown();
} else {
FrameListener listener = new FrameListener(device, latch, result);
frame.addComponentListener(listener);
frame.setVisible(true);
}
}
});
latch.await();
if (result[0] == false) {
throw new RuntimeException("popup menu rendered in wrong position");
}
System.out.println("OK");
}
use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.
the class OpaqueImageToSurfaceBlitTest method main.
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
vi.validate(gc);
BufferedImage bi = new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
int[] data = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
data[0] = 0x0000007f;
data[1] = 0x0000007f;
data[2] = 0xff00007f;
data[3] = 0xff00007f;
Graphics2D g = vi.createGraphics();
g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
g.drawImage(bi, 0, 0, null);
bi = vi.getSnapshot();
if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
throw new RuntimeException("Test FAILED: color at 0x0 =" + Integer.toHexString(bi.getRGB(0, 0)) + " differs from 1x1 =" + Integer.toHexString(bi.getRGB(1, 1)));
}
System.out.println("Test PASSED.");
}
use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.
the class TSFrame method createGui.
public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
Frame frame;
done = false;
if (useNonOpaque) {
if (useSwing) {
frame = new NonOpaqueJFrame();
// frame = new NonOpaqueJAppletFrame(gc);
} else {
frame = new NonOpaqueFrame();
}
animateComponent(frame);
} else if (useSwing) {
frame = new JFrame("Swing Frame");
JComponent p = new JButton("Swing!");
p.setPreferredSize(new Dimension(200, 100));
frame.add("North", p);
p = new MyJPanel();
animateComponent(p);
frame.add("Center", p);
} else {
frame = new Frame("AWT Frame") {
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
}
};
frame.setLayout(new BorderLayout());
Canvas c = new MyCanvas();
frame.add("North", c);
animateComponent(c);
c = new MyCanvas();
frame.add("Center", c);
animateComponent(c);
c = new MyCanvas();
frame.add("South", c);
animateComponent(c);
}
final Frame finalFrame = frame;
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
finalFrame.dispose();
done = true;
}
});
frame.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
finalFrame.dispose();
done = true;
}
});
frame.setPreferredSize(new Dimension(800, 600));
if (useShape) {
frame.setUndecorated(true);
}
frame.setLocation(450, 10);
frame.pack();
GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
if (useShape) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
System.out.println("applying PERPIXEL_TRANSPARENT");
frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
frame.setTitle("PERPIXEL_TRANSPARENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
}
}
if (useTransl) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
System.out.println("applying TRANSLUCENT");
frame.setOpacity(factor);
frame.setTitle("TRANSLUCENT");
} else {
System.out.println("Passed: TRANSLUCENT unsupported");
}
}
if (useNonOpaque) {
if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
System.out.println("applying PERPIXEL_TRANSLUCENT");
frame.setBackground(new Color(0, 0, 0, 0));
frame.setTitle("PERPIXEL_TRANSLUCENT");
} else {
System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
}
}
frame.setVisible(true);
return frame;
}
use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.
the class UnmanagedDrawImagePerformance method makeVI.
private static VolatileImage makeVI(final int type) {
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice gd = ge.getDefaultScreenDevice();
final GraphicsConfiguration gc = gd.getDefaultConfiguration();
return gc.createCompatibleVolatileImage(SIZE, SIZE, type);
}
use of java.awt.GraphicsDevice in project jdk8u_jdk by JetBrains.
the class RSLContextInvalidationTest method main.
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
vi.validate(gc);
VolatileImage vi1 = gc.createCompatibleVolatileImage(100, 100);
vi1.validate(gc);
if (!(vi instanceof DestSurfaceProvider)) {
System.out.println("Test considered PASSED: no HW acceleration");
return;
}
DestSurfaceProvider p = (DestSurfaceProvider) vi;
Surface s = p.getDestSurface();
if (!(s instanceof AccelSurface)) {
System.out.println("Test considered PASSED: no HW acceleration");
return;
}
AccelSurface dst = (AccelSurface) s;
Graphics g = vi.createGraphics();
g.drawImage(vi1, 95, 95, null);
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.black);
g.fillRect(0, 0, 100, 100);
// after this the validated context color is black
RenderQueue rq = dst.getContext().getRenderQueue();
rq.lock();
try {
dst.getContext().saveState();
dst.getContext().restoreState();
} finally {
rq.unlock();
}
// this will cause ResetPaint (it will set color to extended EA=ff,
// which is ffffffff==Color.white)
g.drawImage(vi1, 95, 95, null);
// now try filling with black again, but it will come up as white
// because this fill rect won't validate the color properly
g.setColor(Color.black);
g.fillRect(0, 0, 100, 100);
BufferedImage bi = vi.getSnapshot();
if (bi.getRGB(50, 50) != Color.black.getRGB()) {
throw new RuntimeException("Test FAILED: found color=" + Integer.toHexString(bi.getRGB(50, 50)) + " instead of " + Integer.toHexString(Color.black.getRGB()));
}
System.out.println("Test PASSED.");
}
Aggregations