From 9a518565fac7553ef9e5183b699e4cb13090fde9 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Wed, 8 Oct 2014 20:15:37 -0400 Subject: [PATCH] add more notes and continue the destruction --- core/README.md | 4 +- core/src/processing/core/PApplet.java | 6 ++- core/src/processing/core/PSurface.java | 4 +- core/src/processing/core/PSurfaceAWT.java | 47 +++-------------------- core/todo.txt | 2 + 5 files changed, 19 insertions(+), 44 deletions(-) diff --git a/core/README.md b/core/README.md index c84db2fef..f9e8cd278 100644 --- a/core/README.md +++ b/core/README.md @@ -4,7 +4,7 @@ We're removing `Applet` as the base class for `PApplet` and redoing the entire rendering and threading model for Processing sketches. #### Why? -1. The changes will improve performance--greatly, in some cases--and reduce flicker and quirkiness in others. Using AWT objects like Applet (which subclasses Component) cause (sometimes major) performance restrictions or other visual glitches like flicker. +1. The changes will improve performance--greatly, in some cases--and reduce flicker and quirkiness in others. Using AWT objects like `Applet` (which subclasses `Component`) cause (sometimes major) performance restrictions or other visual glitches like flicker. 2. The code to mitigate the issues from #1 is very difficult to debug and make work properly across the many platforms we support (Macs, Macs with retina displays, Windows 7, Windows 8, 32- and 64-bit machines, Linux who-knows-what, and so on) 3. The design of `core` is 13 years old, and the graphics features available (OpenGL, VolatileImage, BufferStrategy, etc) have changed drastically since then. I've papered over these changes and done my best to keep performance on-pace so that we don't break a lot of old code (or libraries), but now is the time for a clean break. 4. With the death of applets, keeping the Applet base class is anachronistic. However, we're keeping the name `PApplet` because with any luck, these changes will only require a recompile of any sketch (or library) code. @@ -13,6 +13,8 @@ We're removing `Applet` as the base class for `PApplet` and redoing the entire r 1. A new `PSurface` object has been added that acts as the layer between `PApplet` and `PGraphics`. It will handle interaction with the OS (creation of a window, placement on screen, getting events) as well as the animation thread (because OpenGL's animation thread is very different from an AWT animation thread). 2. Many deprecated functions (notably, the pre-2.0 only method registration mechanism used by libraries) are being removed. (Not a final decision.) 3. Undocumented features (such as the `image` object in `PGraphics`) may disappear and break code from advanced users. +4. We're working to add the ability to span multiple screens in "full screen" mode. +5. In 3.0a2 we introduced a change on OS X to use Apple's "official" full screen mode. With this comes a dorky animation and the inability to span multiple screens. We've rolled that back. #### But what about...? 1. One downside is that you'll no longer be able to just drop a Processing sketch into other Java code, because `PApplet` will no longer subclass `Applet` (and therefore, `Component`). This is a huge downside for a tiny number of users. For the majority of users, re-read the "why" section. We'll try to figure out ways to continue embedding in other Java code, however, since we use this in our own work, and even within Processing itself (the Color Selector). diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 432674223..11c56b16f 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -9339,7 +9339,11 @@ public class PApplet implements PConstants { } } - surface.placeSketch(); + if (present) { + surface.placeFullScreen(); + } else { + surface.placeWindow(); + } } diff --git a/core/src/processing/core/PSurface.java b/core/src/processing/core/PSurface.java index d1e6cafe7..e04401f20 100644 --- a/core/src/processing/core/PSurface.java +++ b/core/src/processing/core/PSurface.java @@ -13,7 +13,9 @@ public interface PSurface { public Frame initFrame(int width, int height, Color backgroundColor, int deviceIndex, boolean fullScreen, boolean spanDisplays); - public void placeSketch(); + public void placeWindow(); + + public void placeFullScreen(); // sets displayWidth/Height inside PApplet public void checkDisplaySize(); diff --git a/core/src/processing/core/PSurfaceAWT.java b/core/src/processing/core/PSurfaceAWT.java index 3fb1f40ca..b393f856c 100644 --- a/core/src/processing/core/PSurfaceAWT.java +++ b/core/src/processing/core/PSurfaceAWT.java @@ -287,13 +287,13 @@ public class PSurfaceAWT implements PSurface { if (useStrategy) { render(); } else { - Graphics screen = getGraphics(); + Graphics screen = canvas.getGraphics(); if (screen != null) { screen.drawImage(g.image, 0, 0, width, height, null); } } } else { - repaint(); + canvas.repaint(); } // getToolkit().sync(); // force repaint now (proper method) } @@ -397,37 +397,7 @@ public class PSurfaceAWT implements PSurface { } - public void placeSketch() { -// // If 'present' wasn't already set, but the applet initializes -// // to full screen, attempt to make things full screen anyway. -// if (!present && -// applet.width == screenRect.width && -// applet.height == screenRect.height) { -// // bounds will be set below, but can't change to setUndecorated() now -// present = true; -// } -// // Opting not to do this, because we can't remove the decorations on the -// // window at this point. And re-opening a new winodw is a lot of mess. -// // Better all around to just encourage the use of sketchFullScreen() -// // or cmd/ctrl-shift-R in the PDE. - - if (present) { -// if (platform == MACOSX) { -// println("before"); -// println(screenRect); -// println(frame.getBounds()); -// -// // Call some native code to remove the menu bar on OS X. Not necessary -// // on Linux and Windows, who are happy to make full screen windows. -//// japplemenubar.JAppleMenuBar.hide(); -// toggleFullScreen(frame); -// println("after"); -// println(screenRect); -// println(frame.getBounds()); -// -// println(applet.width + " " + applet.height); -// } - + public void placeFullScreen() { // After the pack(), the screen bounds are gonna be 0s frame.setBounds(screenRect); applet.setBounds((screenRect.width - applet.width) / 2, @@ -438,13 +408,6 @@ public class PSurfaceAWT implements PSurface { macosxFullScreenEnable(frame); macosxFullScreenToggle(frame); -// toggleFullScreen(frame); -// println("after"); -// println(screenRect); -// println(frame.getBounds()); -// println(applet.width + " " + applet.height); - } - if (!hideStop) { Label label = new Label("stop"); label.setForeground(stopColor); @@ -468,8 +431,10 @@ public class PSurfaceAWT implements PSurface { if (external) { applet.setupExternalMessages(); } + } - } else { // if not presenting + + public void placeWindow() { // can't do pack earlier cuz present mode don't like it // (can't go full screen with a frame after calling pack) // frame.pack(); diff --git a/core/todo.txt b/core/todo.txt index 862e0d03f..665fccd04 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,4 +1,6 @@ 0232 core (3.0a5) +X roll back full screen changes +X https://github.com/processing/processing/issues/2641 pulls