Merge pull request #540 from oOMoeOo/master

Removed Sysout-Calls in AwtPanel (Issue #539)
define_list_fix
empirephoenix 9 years ago committed by GitHub
commit 671be243b0
  1. 95
      jme3-desktop/src/main/java/com/jme3/system/awt/AwtPanel.java

@ -51,6 +51,8 @@ import java.nio.IntBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AwtPanel extends Canvas implements SceneProcessor { public class AwtPanel extends Canvas implements SceneProcessor {
@ -78,28 +80,27 @@ public class AwtPanel extends Canvas implements SceneProcessor {
private AtomicBoolean reshapeNeeded = new AtomicBoolean(false); private AtomicBoolean reshapeNeeded = new AtomicBoolean(false);
private final Object lock = new Object(); private final Object lock = new Object();
public AwtPanel(PaintMode paintMode){ public AwtPanel(PaintMode paintMode) {
this(paintMode, false); this(paintMode, false);
} }
public AwtPanel(PaintMode paintMode, boolean srgb){ public AwtPanel(PaintMode paintMode, boolean srgb) {
this.paintMode = paintMode; this.paintMode = paintMode;
this.srgb = srgb; this.srgb = srgb;
if (paintMode == PaintMode.Accelerated){ if (paintMode == PaintMode.Accelerated) {
setIgnoreRepaint(true); setIgnoreRepaint(true);
} }
addComponentListener(new ComponentAdapter(){ addComponentListener(new ComponentAdapter() {
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
synchronized (lock){ synchronized (lock) {
int newWidth2 = Math.max(getWidth(), 1); int newWidth2 = Math.max(getWidth(), 1);
int newHeight2 = Math.max(getHeight(), 1); int newHeight2 = Math.max(getHeight(), 1);
if (newWidth != newWidth2 || newHeight != newHeight2){ if (newWidth != newWidth2 || newHeight != newHeight2) {
newWidth = newWidth2; newWidth = newWidth2;
newHeight = newHeight2; newHeight = newHeight2;
reshapeNeeded.set(true); reshapeNeeded.set(true);
System.out.println("EDT: componentResized " + newWidth + ", " + newHeight);
} }
} }
} }
@ -107,62 +108,53 @@ public class AwtPanel extends Canvas implements SceneProcessor {
} }
@Override @Override
public void addNotify(){ public void addNotify() {
super.addNotify(); super.addNotify();
synchronized (lock){ synchronized (lock) {
hasNativePeer.set(true); hasNativePeer.set(true);
System.out.println("EDT: addNotify");
} }
requestFocusInWindow(); requestFocusInWindow();
} }
@Override @Override
public void removeNotify(){ public void removeNotify() {
synchronized (lock){ synchronized (lock) {
hasNativePeer.set(false); hasNativePeer.set(false);
System.out.println("EDT: removeNotify");
} }
super.removeNotify(); super.removeNotify();
} }
@Override @Override
public void paint(Graphics g){ public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
synchronized (lock){ synchronized (lock) {
g2d.drawImage(img, transformOp, 0, 0); g2d.drawImage(img, transformOp, 0, 0);
} }
} }
public boolean checkVisibilityState(){ public boolean checkVisibilityState() {
if (!hasNativePeer.get()){ if (!hasNativePeer.get()) {
if (strategy != null){ if (strategy != null) {
// strategy.dispose(); // strategy.dispose();
strategy = null; strategy = null;
System.out.println("OGL: Not visible. Destroy strategy.");
} }
return false; return false;
} }
boolean currentShowing = isShowing(); boolean currentShowing = isShowing();
if (showing.getAndSet(currentShowing) != currentShowing){ showing.set(currentShowing);
if (currentShowing){
System.out.println("OGL: Enter showing state.");
}else{
System.out.println("OGL: Exit showing state.");
}
}
return currentShowing; return currentShowing;
} }
public void repaintInThread(){ public void repaintInThread() {
// Convert screenshot. // Convert screenshot.
byteBuf.clear(); byteBuf.clear();
rm.getRenderer().readFrameBuffer(fb, byteBuf); rm.getRenderer().readFrameBuffer(fb, byteBuf);
synchronized (lock){ synchronized (lock) {
// All operations on img must be synchronized // All operations on img must be synchronized
// as it is accessed from EDT. // as it is accessed from EDT.
Screenshots.convertScreenShot2(intBuf, img); Screenshots.convertScreenShot2(intBuf, img);
@ -170,15 +162,15 @@ public class AwtPanel extends Canvas implements SceneProcessor {
} }
} }
public void drawFrameInThread(){ public void drawFrameInThread() {
// Convert screenshot. // Convert screenshot.
byteBuf.clear(); byteBuf.clear();
rm.getRenderer().readFrameBuffer(fb, byteBuf); rm.getRenderer().readFrameBuffer(fb, byteBuf);
Screenshots.convertScreenShot2(intBuf, img); Screenshots.convertScreenShot2(intBuf, img);
synchronized (lock){ synchronized (lock) {
// All operations on strategy should be synchronized (?) // All operations on strategy should be synchronized (?)
if (strategy == null){ if (strategy == null) {
try { try {
createBufferStrategy(1, createBufferStrategy(1,
new BufferCapabilities( new BufferCapabilities(
@ -190,15 +182,14 @@ public class AwtPanel extends Canvas implements SceneProcessor {
ex.printStackTrace(); ex.printStackTrace();
} }
strategy = getBufferStrategy(); strategy = getBufferStrategy();
System.out.println("OGL: Visible. Create strategy.");
} }
// Draw screenshot. // Draw screenshot.
do { do {
do { do {
Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics(); Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
if (g2d == null){ if (g2d == null) {
System.out.println("OGL: DrawGraphics was null."); Logger.getLogger(AwtPanel.class.getName()).log(Level.WARNING, "OGL: DrawGraphics was null.");
return; return;
} }
@ -213,26 +204,27 @@ public class AwtPanel extends Canvas implements SceneProcessor {
} }
} }
public boolean isActiveDrawing(){ public boolean isActiveDrawing() {
return paintMode != PaintMode.OnRequest && showing.get(); return paintMode != PaintMode.OnRequest && showing.get();
} }
public void attachTo(boolean overrideMainFramebuffer, ViewPort ... vps){ public void attachTo(boolean overrideMainFramebuffer, ViewPort... vps) {
if (viewPorts.size() > 0){ if (viewPorts.size() > 0) {
for (ViewPort vp : viewPorts){ for (ViewPort vp : viewPorts) {
vp.setOutputFrameBuffer(null); vp.setOutputFrameBuffer(null);
} }
viewPorts.get(viewPorts.size()-1).removeProcessor(this); viewPorts.get(viewPorts.size() - 1).removeProcessor(this);
} }
viewPorts.addAll(Arrays.asList(vps)); viewPorts.addAll(Arrays.asList(vps));
viewPorts.get(viewPorts.size()-1).addProcessor(this); viewPorts.get(viewPorts.size() - 1).addProcessor(this);
this.attachAsMain = overrideMainFramebuffer; this.attachAsMain = overrideMainFramebuffer;
} }
@Override
public void initialize(RenderManager rm, ViewPort vp) { public void initialize(RenderManager rm, ViewPort vp) {
if (this.rm == null){ if (this.rm == null) {
// First time called in OGL thread // First time called in OGL thread
this.rm = rm; this.rm = rm;
reshapeInThread(1, 1); reshapeInThread(1, 1);
@ -253,48 +245,50 @@ public class AwtPanel extends Canvas implements SceneProcessor {
fb.setColorBuffer(Format.RGB8); fb.setColorBuffer(Format.RGB8);
fb.setSrgb(srgb); fb.setSrgb(srgb);
if (attachAsMain){ if (attachAsMain) {
rm.getRenderer().setMainFrameBufferOverride(fb); rm.getRenderer().setMainFrameBufferOverride(fb);
} }
synchronized (lock){ synchronized (lock) {
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); img = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
} }
// synchronized (lock){ // synchronized (lock){
// img = (BufferedImage) getGraphicsConfiguration().createCompatibleImage(width, height); // img = (BufferedImage) getGraphicsConfiguration().createCompatibleImage(width, height);
// } // }
AffineTransform tx = AffineTransform.getScaleInstance(1, -1); AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -img.getHeight()); tx.translate(0, -img.getHeight());
transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
for (ViewPort vp : viewPorts){ for (ViewPort vp : viewPorts) {
if (!attachAsMain){ if (!attachAsMain) {
vp.setOutputFrameBuffer(fb); vp.setOutputFrameBuffer(fb);
} }
vp.getCamera().resize(width, height, true); vp.getCamera().resize(width, height, true);
// NOTE: Hack alert. This is done ONLY for custom framebuffers. // NOTE: Hack alert. This is done ONLY for custom framebuffers.
// Main framebuffer should use RenderManager.notifyReshape(). // Main framebuffer should use RenderManager.notifyReshape().
for (SceneProcessor sp : vp.getProcessors()){ for (SceneProcessor sp : vp.getProcessors()) {
sp.reshape(vp, width, height); sp.reshape(vp, width, height);
} }
} }
} }
@Override
public boolean isInitialized() { public boolean isInitialized() {
return fb != null; return fb != null;
} }
@Override
public void preFrame(float tpf) { public void preFrame(float tpf) {
} }
@Override
public void postQueue(RenderQueue rq) { public void postQueue(RenderQueue rq) {
} }
@Override @Override
public void invalidate(){ public void invalidate() {
// For "PaintMode.OnDemand" only. // For "PaintMode.OnDemand" only.
repaintRequest.set(true); repaintRequest.set(true);
} }
@ -323,17 +317,20 @@ public class AwtPanel extends Canvas implements SceneProcessor {
} }
} }
@Override
public void postFrame(FrameBuffer out) { public void postFrame(FrameBuffer out) {
if (!attachAsMain && out != fb){ if (!attachAsMain && out != fb) {
throw new IllegalStateException("Why did you change the output framebuffer?"); throw new IllegalStateException("Why did you change the output framebuffer?");
} }
// onFrameEnd(); // onFrameEnd();
} }
@Override
public void reshape(ViewPort vp, int w, int h) { public void reshape(ViewPort vp, int w, int h) {
} }
@Override
public void cleanup() { public void cleanup() {
} }
} }

Loading…
Cancel
Save