import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
import static x30_pkg.x30_util.DynamicObject;
class main {
public static void main(final String[] args) throws Exception { { swing(new Runnable() { public void run() { try { new GraphicsTest();
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "new GraphicsTest();"; }}); }}
static class GraphicsTest extends JFrame {
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferCapabilities bufferCapabilities;
BufferStrategy bufferStrategy;
int y = 0;
int delta = 1;
public GraphicsTest() {
setTitle("Hardware Acceleration Test");
setSize(500, 300);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
createBufferStrategy(2);
bufferStrategy = getBufferStrategy();
bufferCapabilities = gc.getBufferCapabilities();
new AnimationThread().start();
}
class AnimationThread extends Thread {
@Override
public void run() {
while(true) {
Graphics2D g2 = null;
try {
g2 = (Graphics2D) bufferStrategy.getDrawGraphics();
draw(g2);
} finally {
if(g2 != null) g2.dispose();
}
bufferStrategy.show();
try {
// CHANGE HERE, DONT SLEEP
//Thread.sleep(16);
} catch(Exception err) {
err.printStackTrace();
}
}
}
}
public void draw(Graphics2D g2) {
if(!bufferCapabilities.isPageFlipping() || bufferCapabilities.isFullScreenRequired()) {
g2.setColor(Color.black);
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setColor(Color.red);
g2.drawString("Hardware Acceleration is not supported...", 100, 100);
g2.setColor(Color.white);
g2.drawString("Page Flipping: " + (bufferCapabilities.isPageFlipping() ? "Available" : "Not Supported"), 100, 130);
g2.drawString("Full Screen Required: " + (bufferCapabilities.isFullScreenRequired() ? "Required" : "Not Required"), 100, 160);
g2.drawString("Multiple Buffer Capable: " + (bufferCapabilities.isMultiBufferAvailable() ? "Yes" : "No"), 100, 190);
} else {
g2.setColor(Color.black);
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setColor(Color.white);
g2.drawString("Hardware Acceleration is Working...", 100, 100);
g2.drawString("Page Flipping: " + (bufferCapabilities.isPageFlipping() ? "Available" : "Not Supported"), 100, 130);
g2.drawString("Full Screen Required: " + (bufferCapabilities.isFullScreenRequired() ? "Required" : "Not Required"), 100, 160);
g2.drawString("Multiple Buffer Capable: " + (bufferCapabilities.isMultiBufferAvailable() ? "Yes" : "No"), 100, 190);
}
y += delta;
if((y + 50) > getHeight() || y < 0) {
delta *= -1;
}
g2.setColor(Color.blue);
g2.fillRect(getWidth()-50, y, 50, 50);
}
}
static Object swing(Object f) {
return swingAndWait(f);
}
static A swing(F0 f) {
return (A) swingAndWait(f);
}
static A swing(IF0 f) {
return (A) swingAndWait(f);
}
static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
static A setTitle(A c, String title) {
return setFrameTitle(c, title);
}
static A setTitle(String title, A c) {
return setFrameTitle(c, title);
}
static A setSize(final A c, final int w, final int h) {
if (c != null) { swing(new Runnable() { public void run() { try { c.setSize(w, h);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "c.setSize(w, h);"; }}); }
return c;
}
static void setSize(Component c, Dimension d) {
setSize(c, d.width, d.height);
}
static void setVisible(final Component c, final boolean visible) {
if (c != null) { swing(new Runnable() { public void run() { try { c.setVisible(visible);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "c.setVisible(visible);"; }}); }
}
static int getWidth(Component c) {
return c == null ? 0 : (int) swingCall(c, "getWidth");
}
static int getHeight(Component c) {
return c == null ? 0 : (int) swingCall(c, "getHeight");
}
static void swingAndWait(Runnable r) { try {
if (isAWTThread())
r.run();
else
EventQueue.invokeAndWait(addThreadInfoToRunnable(r));
} catch (Exception __e) { throw rethrow(__e); } }
static Object swingAndWait(final Object f) {
if (isAWTThread())
return callF(f);
else {
final Var result = new Var();
swingAndWait(new Runnable() { public void run() { try {
result.set(callF(f));
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "result.set(callF(f));"; }});
return result.get();
}
}
static void _handleError(Error e) {
call(javax(), "_handleError", e);
}
static A setFrameTitle(A c, final String title) {
final Frame f = getAWTFrame(c);
if (f != null) { swing(new Runnable() { public void run() { try { f.setTitle(title);
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "f.setTitle(title);"; }}); }
return c;
}
static A setFrameTitle(String title, A c) {
return setFrameTitle(c, title);
}
// magically find a field called "frame" in main class :-)
static JFrame setFrameTitle(String title) {
Object f = getOpt(mc(), "frame");
if (f instanceof JFrame)
return setFrameTitle((JFrame) f, title);
return null;
}
static Object swingCall(final Object o, final String method, final Object... args) {
return swing(new F0