13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package sun.awt.windows; 26 27 import java.awt.AlphaComposite; 28 import java.awt.Color; 29 import java.awt.Graphics2D; 30 import java.awt.GraphicsConfiguration; 31 import java.awt.Image; 32 import java.awt.Window; 33 import java.awt.image.BufferedImage; 34 import java.awt.image.DataBufferInt; 35 import java.awt.image.VolatileImage; 36 import java.security.AccessController; 37 import sun.awt.image.BufImgSurfaceData; 38 import sun.java2d.DestSurfaceProvider; 39 import sun.java2d.InvalidPipeException; 40 import sun.java2d.Surface; 41 import sun.java2d.pipe.RenderQueue; 42 import sun.java2d.pipe.BufferedContext; 43 import sun.java2d.pipe.hw.AccelGraphicsConfig; 44 import sun.java2d.pipe.hw.AccelSurface; 45 import sun.security.action.GetPropertyAction; 46 47 import static java.awt.image.VolatileImage.*; 48 import static sun.java2d.pipe.hw.AccelSurface.*; 49 import static sun.java2d.pipe.hw.ContextCapabilities.*; 50 51 /** 52 * This class handles the updates of the non-opaque windows. 53 * The window associated with the peer is updated either given an image or 54 * the window is repainted to an internal buffer which is then used to update 55 * the window. 56 * 57 * Note: this class does not attempt to be thread safe, it is expected to be 58 * called from a single thread (EDT). 59 */ 60 abstract class TranslucentWindowPainter { 117 protected abstract boolean update(Image bb); 118 119 /** 120 * Flushes the resources associated with the painter. They will be 121 * recreated as needed. 122 */ 123 public abstract void flush(); 124 125 /** 126 * Updates the window associated with the painter. 127 * 128 * @param repaint indicates if the window should be completely repainted 129 * to the back buffer using {@link java.awt.Window#paintAll} before update. 130 */ 131 public void updateWindow(boolean repaint) { 132 boolean done = false; 133 Image bb = getBackBuffer(repaint); 134 while (!done) { 135 if (repaint) { 136 Graphics2D g = (Graphics2D)bb.getGraphics(); 137 try { 138 window.paintAll(g); 139 } finally { 140 g.dispose(); 141 } 142 } 143 144 done = update(bb); 145 if (!done) { 146 repaint = true; 147 bb = getBackBuffer(true); 148 } 149 } 150 } 151 152 private static final Image clearImage(Image bb) { 153 Graphics2D g = (Graphics2D)bb.getGraphics(); 154 int w = bb.getWidth(null); 155 int h = bb.getHeight(null); 156 161 return bb; 162 } 163 164 /** 165 * A painter which uses BufferedImage as the internal buffer. The window 166 * is painted into this buffer, and the contents then are uploaded 167 * into the layered window. 168 * 169 * This painter handles all types of images passed to its paint(Image) 170 * method (VI, BI, regular Images). 171 */ 172 private static class BIWindowPainter extends TranslucentWindowPainter { 173 private BufferedImage backBuffer; 174 175 protected BIWindowPainter(WWindowPeer peer) { 176 super(peer); 177 } 178 179 @Override 180 protected Image getBackBuffer(boolean clear) { 181 int w = window.getWidth(); 182 int h = window.getHeight(); 183 if (backBuffer == null || 184 backBuffer.getWidth() != w || 185 backBuffer.getHeight() != h) 186 { 187 flush(); 188 backBuffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); 189 } 190 return clear ? (BufferedImage)clearImage(backBuffer) : backBuffer; 191 } 192 193 @Override 194 protected boolean update(Image bb) { 195 VolatileImage viBB = null; 196 197 if (bb instanceof BufferedImage) { 198 BufferedImage bi = (BufferedImage)bb; 199 int data[] = 200 ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); 201 peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight()); 202 return true; | 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package sun.awt.windows; 26 27 import java.awt.AlphaComposite; 28 import java.awt.Color; 29 import java.awt.Graphics2D; 30 import java.awt.GraphicsConfiguration; 31 import java.awt.Image; 32 import java.awt.Window; 33 import java.awt.geom.AffineTransform; 34 import java.awt.image.BufferedImage; 35 import java.awt.image.DataBufferInt; 36 import java.awt.image.VolatileImage; 37 import java.security.AccessController; 38 import sun.awt.image.BufImgSurfaceData; 39 import sun.java2d.DestSurfaceProvider; 40 import sun.java2d.InvalidPipeException; 41 import sun.java2d.Surface; 42 import sun.java2d.pipe.Region; 43 import sun.java2d.pipe.RenderQueue; 44 import sun.java2d.pipe.BufferedContext; 45 import sun.java2d.pipe.hw.AccelGraphicsConfig; 46 import sun.java2d.pipe.hw.AccelSurface; 47 import sun.security.action.GetPropertyAction; 48 49 import static java.awt.image.VolatileImage.*; 50 import static sun.java2d.pipe.hw.AccelSurface.*; 51 import static sun.java2d.pipe.hw.ContextCapabilities.*; 52 53 /** 54 * This class handles the updates of the non-opaque windows. 55 * The window associated with the peer is updated either given an image or 56 * the window is repainted to an internal buffer which is then used to update 57 * the window. 58 * 59 * Note: this class does not attempt to be thread safe, it is expected to be 60 * called from a single thread (EDT). 61 */ 62 abstract class TranslucentWindowPainter { 119 protected abstract boolean update(Image bb); 120 121 /** 122 * Flushes the resources associated with the painter. They will be 123 * recreated as needed. 124 */ 125 public abstract void flush(); 126 127 /** 128 * Updates the window associated with the painter. 129 * 130 * @param repaint indicates if the window should be completely repainted 131 * to the back buffer using {@link java.awt.Window#paintAll} before update. 132 */ 133 public void updateWindow(boolean repaint) { 134 boolean done = false; 135 Image bb = getBackBuffer(repaint); 136 while (!done) { 137 if (repaint) { 138 Graphics2D g = (Graphics2D)bb.getGraphics(); 139 g.transform(peer.getGraphicsConfiguration() 140 .getDefaultTransform()); 141 try { 142 window.paintAll(g); 143 } finally { 144 g.dispose(); 145 } 146 } 147 148 done = update(bb); 149 if (!done) { 150 repaint = true; 151 bb = getBackBuffer(true); 152 } 153 } 154 } 155 156 private static final Image clearImage(Image bb) { 157 Graphics2D g = (Graphics2D)bb.getGraphics(); 158 int w = bb.getWidth(null); 159 int h = bb.getHeight(null); 160 165 return bb; 166 } 167 168 /** 169 * A painter which uses BufferedImage as the internal buffer. The window 170 * is painted into this buffer, and the contents then are uploaded 171 * into the layered window. 172 * 173 * This painter handles all types of images passed to its paint(Image) 174 * method (VI, BI, regular Images). 175 */ 176 private static class BIWindowPainter extends TranslucentWindowPainter { 177 private BufferedImage backBuffer; 178 179 protected BIWindowPainter(WWindowPeer peer) { 180 super(peer); 181 } 182 183 @Override 184 protected Image getBackBuffer(boolean clear) { 185 GraphicsConfiguration gc = peer.getGraphicsConfiguration(); 186 AffineTransform transform = gc.getDefaultTransform(); 187 int w = Region.clipRound( 188 window.getWidth() * transform.getScaleX()); 189 int h = Region.clipRound( 190 window.getHeight() * transform.getScaleY()); 191 if (backBuffer == null || 192 backBuffer.getWidth() != w || 193 backBuffer.getHeight() != h) 194 { 195 flush(); 196 backBuffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); 197 } 198 return clear ? (BufferedImage)clearImage(backBuffer) : backBuffer; 199 } 200 201 @Override 202 protected boolean update(Image bb) { 203 VolatileImage viBB = null; 204 205 if (bb instanceof BufferedImage) { 206 BufferedImage bi = (BufferedImage)bb; 207 int data[] = 208 ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); 209 peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight()); 210 return true; |