< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/TranslucentWindowPainter.java

Print this page


   1 /*
   2  * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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


 190             int w = Region.clipRound(
 191                     window.getWidth() * transform.getScaleX());
 192             int h = Region.clipRound(
 193                     window.getHeight() * transform.getScaleY());
 194             if (backBuffer == null ||
 195                 backBuffer.getWidth() != w ||
 196                 backBuffer.getHeight() != h)
 197             {
 198                 flush();
 199                 backBuffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
 200             }
 201             return clear ? (BufferedImage)clearImage(backBuffer) : backBuffer;
 202         }
 203 
 204         @Override
 205         protected boolean update(Image bb) {
 206             VolatileImage viBB = null;
 207 
 208             if (bb instanceof BufferedImage) {
 209                 BufferedImage bi = (BufferedImage)bb;
 210                 int data[] =
 211                     ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
 212                 peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight());
 213                 return true;
 214             } else if (bb instanceof VolatileImage) {
 215                 viBB = (VolatileImage)bb;
 216                 if (bb instanceof DestSurfaceProvider) {
 217                     Surface s = ((DestSurfaceProvider)bb).getDestSurface();
 218                     if (s instanceof BufImgSurfaceData) {
 219                         // the image is probably lost, upload the data from the
 220                         // backup surface to avoid creating another heap-based
 221                         // image (the parent's buffer)
 222                         int w = viBB.getWidth();
 223                         int h = viBB.getHeight();
 224                         BufImgSurfaceData bisd = (BufImgSurfaceData)s;
 225                         int data[] = ((DataBufferInt)bisd.getRaster(0,0,w,h).
 226                             getDataBuffer()).getData();
 227                         peer.updateWindowImpl(data, w, h);
 228                         return true;
 229                     }
 230                 }
 231             }
 232 
 233             // copy the passed image into our own buffer, then upload
 234             BufferedImage bi = (BufferedImage)clearImage(backBuffer);
 235 
 236             int data[] =
 237                 ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
 238             peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight());
 239 
 240             return (viBB != null ? !viBB.contentsLost() : true);
 241         }
 242 
 243         @Override
 244         public void flush() {
 245             if (backBuffer != null) {
 246                 backBuffer.flush();
 247                 backBuffer = null;
 248             }
 249         }
 250 
 251         @Override
 252         protected Graphics getGraphics(boolean clear) {
 253             Graphics g = getBackBuffer(clear).getGraphics();
 254             /*
 255              * This graphics object returned by BuffereImage is not scaled to
 256              * graphics configuration, but this graphics object can be used by


 315     }
 316 
 317     /**
 318      * Optimized version of hw painter. Uses VolatileImages for the
 319      * buffer, and uses an optimized path to pull the data from those into
 320      * the layered window, bypassing Java heap-based image.
 321      */
 322     private abstract static class VIOptWindowPainter extends VIWindowPainter {
 323 
 324         protected VIOptWindowPainter(WWindowPeer peer) {
 325             super(peer);
 326         }
 327 
 328         protected abstract boolean updateWindowAccel(long psdops, int w, int h);
 329 
 330         @Override
 331         protected boolean update(Image bb) {
 332             if (bb instanceof DestSurfaceProvider) {
 333                 Surface s = ((DestSurfaceProvider)bb).getDestSurface();
 334                 if (s instanceof AccelSurface) {
 335                     final boolean arr[] = { false };
 336                     final AccelSurface as = (AccelSurface)s;
 337                     final int w = as.getBounds().width;
 338                     final int h = as.getBounds().height;
 339                     RenderQueue rq = as.getContext().getRenderQueue();
 340                     rq.lock();
 341                     try {
 342                         BufferedContext.validateContext(as);
 343                         rq.flushAndInvokeNow(new Runnable() {
 344                             @Override
 345                             public void run() {
 346                                 long psdops = as.getNativeOps();
 347                                 arr[0] = updateWindowAccel(psdops, w, h);
 348                             }
 349                         });
 350                     } catch (InvalidPipeException e) {
 351                         // ignore, false will be returned
 352                     } finally {
 353                         rq.unlock();
 354                     }
 355                     return arr[0];


   1 /*
   2  * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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


 190             int w = Region.clipRound(
 191                     window.getWidth() * transform.getScaleX());
 192             int h = Region.clipRound(
 193                     window.getHeight() * transform.getScaleY());
 194             if (backBuffer == null ||
 195                 backBuffer.getWidth() != w ||
 196                 backBuffer.getHeight() != h)
 197             {
 198                 flush();
 199                 backBuffer = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
 200             }
 201             return clear ? (BufferedImage)clearImage(backBuffer) : backBuffer;
 202         }
 203 
 204         @Override
 205         protected boolean update(Image bb) {
 206             VolatileImage viBB = null;
 207 
 208             if (bb instanceof BufferedImage) {
 209                 BufferedImage bi = (BufferedImage)bb;
 210                 int[] data =
 211                     ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
 212                 peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight());
 213                 return true;
 214             } else if (bb instanceof VolatileImage) {
 215                 viBB = (VolatileImage)bb;
 216                 if (bb instanceof DestSurfaceProvider) {
 217                     Surface s = ((DestSurfaceProvider)bb).getDestSurface();
 218                     if (s instanceof BufImgSurfaceData) {
 219                         // the image is probably lost, upload the data from the
 220                         // backup surface to avoid creating another heap-based
 221                         // image (the parent's buffer)
 222                         int w = viBB.getWidth();
 223                         int h = viBB.getHeight();
 224                         BufImgSurfaceData bisd = (BufImgSurfaceData)s;
 225                         int[] data = ((DataBufferInt)bisd.getRaster(0,0,w,h).
 226                             getDataBuffer()).getData();
 227                         peer.updateWindowImpl(data, w, h);
 228                         return true;
 229                     }
 230                 }
 231             }
 232 
 233             // copy the passed image into our own buffer, then upload
 234             BufferedImage bi = (BufferedImage)clearImage(backBuffer);
 235 
 236             int[] data =
 237                 ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
 238             peer.updateWindowImpl(data, bi.getWidth(), bi.getHeight());
 239 
 240             return (viBB != null ? !viBB.contentsLost() : true);
 241         }
 242 
 243         @Override
 244         public void flush() {
 245             if (backBuffer != null) {
 246                 backBuffer.flush();
 247                 backBuffer = null;
 248             }
 249         }
 250 
 251         @Override
 252         protected Graphics getGraphics(boolean clear) {
 253             Graphics g = getBackBuffer(clear).getGraphics();
 254             /*
 255              * This graphics object returned by BuffereImage is not scaled to
 256              * graphics configuration, but this graphics object can be used by


 315     }
 316 
 317     /**
 318      * Optimized version of hw painter. Uses VolatileImages for the
 319      * buffer, and uses an optimized path to pull the data from those into
 320      * the layered window, bypassing Java heap-based image.
 321      */
 322     private abstract static class VIOptWindowPainter extends VIWindowPainter {
 323 
 324         protected VIOptWindowPainter(WWindowPeer peer) {
 325             super(peer);
 326         }
 327 
 328         protected abstract boolean updateWindowAccel(long psdops, int w, int h);
 329 
 330         @Override
 331         protected boolean update(Image bb) {
 332             if (bb instanceof DestSurfaceProvider) {
 333                 Surface s = ((DestSurfaceProvider)bb).getDestSurface();
 334                 if (s instanceof AccelSurface) {
 335                     final boolean[] arr = { false };
 336                     final AccelSurface as = (AccelSurface)s;
 337                     final int w = as.getBounds().width;
 338                     final int h = as.getBounds().height;
 339                     RenderQueue rq = as.getContext().getRenderQueue();
 340                     rq.lock();
 341                     try {
 342                         BufferedContext.validateContext(as);
 343                         rq.flushAndInvokeNow(new Runnable() {
 344                             @Override
 345                             public void run() {
 346                                 long psdops = as.getNativeOps();
 347                                 arr[0] = updateWindowAccel(psdops, w, h);
 348                             }
 349                         });
 350                     } catch (InvalidPipeException e) {
 351                         // ignore, false will be returned
 352                     } finally {
 353                         rq.unlock();
 354                     }
 355                     return arr[0];


< prev index next >