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 { 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; 203 } else if (bb instanceof VolatileImage) { 204 viBB = (VolatileImage)bb; 205 if (bb instanceof DestSurfaceProvider) { 206 Surface s = ((DestSurfaceProvider)bb).getDestSurface(); 207 if (s instanceof BufImgSurfaceData) { 208 // the image is probably lost, upload the data from the | 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 { 163 return bb; 164 } 165 166 /** 167 * A painter which uses BufferedImage as the internal buffer. The window 168 * is painted into this buffer, and the contents then are uploaded 169 * into the layered window. 170 * 171 * This painter handles all types of images passed to its paint(Image) 172 * method (VI, BI, regular Images). 173 */ 174 private static class BIWindowPainter extends TranslucentWindowPainter { 175 private BufferedImage backBuffer; 176 177 protected BIWindowPainter(WWindowPeer peer) { 178 super(peer); 179 } 180 181 @Override 182 protected Image getBackBuffer(boolean clear) { 183 GraphicsConfiguration gc = peer.getGraphicsConfiguration(); 184 AffineTransform transform = gc.getDefaultTransform(); 185 int w = Region.clipRound( 186 window.getWidth() * transform.getScaleX()); 187 int h = Region.clipRound( 188 window.getHeight() * transform.getScaleY()); 189 if (backBuffer == null || 190 backBuffer.getWidth() != w || 191 backBuffer.getHeight() != h) 192 { 193 flush(); 194 backBuffer = new BufferedImage(gc, w, h, BufferedImage 195 .TYPE_INT_ARGB_PRE); 196 } 197 return clear ? (BufferedImage)clearImage(backBuffer) : backBuffer; 198 } 199 200 @Override 201 protected boolean update(Image bb) { 202 VolatileImage viBB = null; 203 204 if (bb instanceof BufferedImage) { 205 BufferedImage bi = (BufferedImage)bb; 206 int data[] = 207 ((DataBufferInt)bi.getRaster().getDataBuffer()).getData(); 208 peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight()); 209 return true; 210 } else if (bb instanceof VolatileImage) { 211 viBB = (VolatileImage)bb; 212 if (bb instanceof DestSurfaceProvider) { 213 Surface s = ((DestSurfaceProvider)bb).getDestSurface(); 214 if (s instanceof BufImgSurfaceData) { 215 // the image is probably lost, upload the data from the |