src/java.desktop/windows/classes/sun/java2d/d3d/D3DScreenUpdateManager.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 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 
  26 package sun.java2d.d3d;
  27 
  28 import java.awt.Color;
  29 import java.awt.Component;
  30 import java.awt.Container;
  31 import java.awt.Font;
  32 import java.awt.Graphics2D;
  33 import java.awt.Rectangle;
  34 import java.awt.Window;
  35 import java.security.AccessController;
  36 import java.security.PrivilegedAction;
  37 import java.util.ArrayList;
  38 import java.util.HashMap;
  39 
  40 import sun.awt.AWTAccessor;

  41 import sun.awt.util.ThreadGroupUtils;
  42 import sun.awt.Win32GraphicsConfig;
  43 import sun.awt.windows.WComponentPeer;
  44 import sun.java2d.InvalidPipeException;
  45 import sun.java2d.ScreenUpdateManager;
  46 import sun.java2d.SunGraphics2D;
  47 import sun.java2d.SurfaceData;
  48 import sun.java2d.windows.GDIWindowSurfaceData;
  49 import sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData;
  50 import sun.java2d.windows.WindowsFlags;
  51 
  52 /**
  53  * This class handles rendering to the screen with the D3D pipeline.
  54  *
  55  * Since it is not possible to render directly to the front buffer
  56  * with D3D9, we create a swap chain surface (with COPY effect) in place of the
  57  * GDIWindowSurfaceData. A background thread handles the swap chain flips.
  58  *
  59  * There are some restrictions to which windows we would use this for.
  60  * @see #createScreenSurface()


 506      */
 507     private synchronized SurfaceData getGdiSurface(D3DWindowSurfaceData d3dw) {
 508         if (gdiSurfaces == null) {
 509             gdiSurfaces =
 510                 new HashMap<D3DWindowSurfaceData, GDIWindowSurfaceData>();
 511         }
 512         GDIWindowSurfaceData gdisd = gdiSurfaces.get(d3dw);
 513         if (gdisd == null) {
 514             gdisd = GDIWindowSurfaceData.createData(d3dw.getPeer());
 515             gdiSurfaces.put(d3dw, gdisd);
 516         }
 517         return gdisd;
 518     }
 519 
 520     /**
 521      * Returns true if the component has heavyweight children.
 522      *
 523      * @param comp component to check for hw children
 524      * @return true if Component has heavyweight children
 525      */
 526     @SuppressWarnings("deprecation")
 527     private static boolean hasHWChildren(Component comp) {

 528         if (comp instanceof Container) {
 529             for (Component c : ((Container)comp).getComponents()) {
 530                 if (c.getPeer() instanceof WComponentPeer || hasHWChildren(c)) {
 531                     return true;
 532                 }
 533             }
 534         }
 535         return false;
 536     }
 537 }
   1 /*
   2  * Copyright (c) 2007, 2015, 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 
  26 package sun.java2d.d3d;
  27 
  28 import java.awt.Color;
  29 import java.awt.Component;
  30 import java.awt.Container;
  31 import java.awt.Font;
  32 import java.awt.Graphics2D;
  33 import java.awt.Rectangle;
  34 import java.awt.Window;
  35 import java.security.AccessController;
  36 import java.security.PrivilegedAction;
  37 import java.util.ArrayList;
  38 import java.util.HashMap;
  39 
  40 import sun.awt.AWTAccessor;
  41 import sun.awt.AWTAccessor.ComponentAccessor;
  42 import sun.awt.util.ThreadGroupUtils;
  43 import sun.awt.Win32GraphicsConfig;
  44 import sun.awt.windows.WComponentPeer;
  45 import sun.java2d.InvalidPipeException;
  46 import sun.java2d.ScreenUpdateManager;
  47 import sun.java2d.SunGraphics2D;
  48 import sun.java2d.SurfaceData;
  49 import sun.java2d.windows.GDIWindowSurfaceData;
  50 import sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData;
  51 import sun.java2d.windows.WindowsFlags;
  52 
  53 /**
  54  * This class handles rendering to the screen with the D3D pipeline.
  55  *
  56  * Since it is not possible to render directly to the front buffer
  57  * with D3D9, we create a swap chain surface (with COPY effect) in place of the
  58  * GDIWindowSurfaceData. A background thread handles the swap chain flips.
  59  *
  60  * There are some restrictions to which windows we would use this for.
  61  * @see #createScreenSurface()


 507      */
 508     private synchronized SurfaceData getGdiSurface(D3DWindowSurfaceData d3dw) {
 509         if (gdiSurfaces == null) {
 510             gdiSurfaces =
 511                 new HashMap<D3DWindowSurfaceData, GDIWindowSurfaceData>();
 512         }
 513         GDIWindowSurfaceData gdisd = gdiSurfaces.get(d3dw);
 514         if (gdisd == null) {
 515             gdisd = GDIWindowSurfaceData.createData(d3dw.getPeer());
 516             gdiSurfaces.put(d3dw, gdisd);
 517         }
 518         return gdisd;
 519     }
 520 
 521     /**
 522      * Returns true if the component has heavyweight children.
 523      *
 524      * @param comp component to check for hw children
 525      * @return true if Component has heavyweight children
 526      */

 527     private static boolean hasHWChildren(Component comp) {
 528         final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
 529         if (comp instanceof Container) {
 530             for (Component c : ((Container)comp).getComponents()) {
 531                 if (acc.getPeer(c) instanceof WComponentPeer || hasHWChildren(c)) {
 532                     return true;
 533                 }
 534             }
 535         }
 536         return false;
 537     }
 538 }