< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2008, 2014, 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
  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 {
  61 
  62     protected Window window;
  63     protected WWindowPeer peer;
  64 
  65     // REMIND: we probably would want to remove this later
  66     private static final boolean forceOpt  =
  67         Boolean.valueOf(AccessController.doPrivileged(


 286     }
 287 
 288     /**
 289      * Optimized version of hw painter. Uses VolatileImages for the
 290      * buffer, and uses an optimized path to pull the data from those into
 291      * the layered window, bypassing Java heap-based image.
 292      */
 293     private abstract static class VIOptWindowPainter extends VIWindowPainter {
 294 
 295         protected VIOptWindowPainter(WWindowPeer peer) {
 296             super(peer);
 297         }
 298 
 299         protected abstract boolean updateWindowAccel(long psdops, int w, int h);
 300 
 301         @Override
 302         protected boolean update(Image bb) {
 303             if (bb instanceof DestSurfaceProvider) {
 304                 Surface s = ((DestSurfaceProvider)bb).getDestSurface();
 305                 if (s instanceof AccelSurface) {
 306                     final int w = bb.getWidth(null);
 307                     final int h = bb.getHeight(null);




 308                     final boolean arr[] = { false };
 309                     final AccelSurface as = (AccelSurface)s;
 310                     RenderQueue rq = as.getContext().getRenderQueue();
 311                     rq.lock();
 312                     try {
 313                         BufferedContext.validateContext(as);
 314                         rq.flushAndInvokeNow(new Runnable() {
 315                             @Override
 316                             public void run() {
 317                                 long psdops = as.getNativeOps();
 318                                 arr[0] = updateWindowAccel(psdops, w, h);
 319                             }
 320                         });
 321                     } catch (InvalidPipeException e) {
 322                         // ignore, false will be returned
 323                     } finally {
 324                         rq.unlock();
 325                     }
 326                     return arr[0];
 327                 }


   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
  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.RenderQueue;
  43 import sun.java2d.pipe.BufferedContext;
  44 import sun.java2d.pipe.hw.AccelGraphicsConfig;
  45 import sun.java2d.pipe.hw.AccelSurface;
  46 import sun.security.action.GetPropertyAction;
  47 
  48 import static java.awt.image.VolatileImage.*;
  49 import sun.java2d.pipe.Region;
  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 {
  63 
  64     protected Window window;
  65     protected WWindowPeer peer;
  66 
  67     // REMIND: we probably would want to remove this later
  68     private static final boolean forceOpt  =
  69         Boolean.valueOf(AccessController.doPrivileged(


 288     }
 289 
 290     /**
 291      * Optimized version of hw painter. Uses VolatileImages for the
 292      * buffer, and uses an optimized path to pull the data from those into
 293      * the layered window, bypassing Java heap-based image.
 294      */
 295     private abstract static class VIOptWindowPainter extends VIWindowPainter {
 296 
 297         protected VIOptWindowPainter(WWindowPeer peer) {
 298             super(peer);
 299         }
 300 
 301         protected abstract boolean updateWindowAccel(long psdops, int w, int h);
 302 
 303         @Override
 304         protected boolean update(Image bb) {
 305             if (bb instanceof DestSurfaceProvider) {
 306                 Surface s = ((DestSurfaceProvider)bb).getDestSurface();
 307                 if (s instanceof AccelSurface) {
 308                     AffineTransform tx = ((Graphics2D) bb.getGraphics()).
 309                             getTransform();
 310                     final int w = Region.
 311                             clipScale(bb.getWidth(null), tx.getScaleX());
 312                     final int h = Region.
 313                             clipScale(bb.getHeight(null), tx.getScaleY());
 314                     final boolean arr[] = { false };
 315                     final AccelSurface as = (AccelSurface)s;
 316                     RenderQueue rq = as.getContext().getRenderQueue();
 317                     rq.lock();
 318                     try {
 319                         BufferedContext.validateContext(as);
 320                         rq.flushAndInvokeNow(new Runnable() {
 321                             @Override
 322                             public void run() {
 323                                 long psdops = as.getNativeOps();
 324                                 arr[0] = updateWindowAccel(psdops, w, h);
 325                             }
 326                         });
 327                     } catch (InvalidPipeException e) {
 328                         // ignore, false will be returned
 329                     } finally {
 330                         rq.unlock();
 331                     }
 332                     return arr[0];
 333                 }


< prev index next >