< 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


  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                 }
 328             }
 329             return super.update(bb);


   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


  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 sun.java2d.SurfaceData;
  49 import static sun.java2d.pipe.hw.AccelSurface.*;
  50 import static sun.java2d.pipe.hw.ContextCapabilities.*;
  51 
  52 /**
  53  * This class handles the updates of the non-opaque windows.
  54  * The window associated with the peer is updated either given an image or
  55  * the window is repainted to an internal buffer which is then used to update
  56  * the window.
  57  *
  58  * Note: this class does not attempt to be thread safe, it is expected to be
  59  * called from a single thread (EDT).
  60  */
  61 abstract class TranslucentWindowPainter {
  62 
  63     protected Window window;
  64     protected WWindowPeer peer;
  65 
  66     // REMIND: we probably would want to remove this later
  67     private static final boolean forceOpt  =
  68         Boolean.valueOf(AccessController.doPrivileged(


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


 307                     final boolean arr[] = { false };
 308                     final AccelSurface as = (AccelSurface)s;
 309                     double scaleX = ((SurfaceData)as).getDefaultScaleX();
 310                     double scaleY = ((SurfaceData)as).getDefaultScaleY();
 311                     final int w = (int) Math.ceil(bb.getWidth(null) * scaleX);
 312                     final int h = (int) Math.ceil(bb.getHeight(null) * scaleY);
 313                     RenderQueue rq = as.getContext().getRenderQueue();
 314                     rq.lock();
 315                     try {
 316                         BufferedContext.validateContext(as);
 317                         rq.flushAndInvokeNow(new Runnable() {
 318                             @Override
 319                             public void run() {
 320                                 long psdops = as.getNativeOps();
 321                                 arr[0] = updateWindowAccel(psdops, w, h);
 322                             }
 323                         });
 324                     } catch (InvalidPipeException e) {
 325                         // ignore, false will be returned
 326                     } finally {
 327                         rq.unlock();
 328                     }
 329                     return arr[0];
 330                 }
 331             }
 332             return super.update(bb);


< prev index next >