src/windows/classes/sun/java2d/d3d/D3DPaints.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2008, 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.LinearGradientPaint;
  29 import java.awt.MultipleGradientPaint;
  30 import java.awt.MultipleGradientPaint.ColorSpaceType;
  31 import java.awt.MultipleGradientPaint.CycleMethod;
  32 import java.awt.TexturePaint;
  33 import java.awt.image.BufferedImage;
  34 import java.util.HashMap;
  35 import java.util.Map;
  36 import javax.tools.annotation.GenerateNativeHeader;
  37 import sun.java2d.SunGraphics2D;
  38 import sun.java2d.SurfaceData;
  39 import sun.java2d.loops.CompositeType;
  40 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
  41 
  42 abstract class D3DPaints {
  43 
  44     /**
  45      * Holds all registered implementations, using the corresponding
  46      * SunGraphics2D.PAINT_* constant as the hash key.
  47      */
  48     private static Map<Integer, D3DPaints> impls =
  49         new HashMap<Integer, D3DPaints>(4, 1.0f);
  50 
  51     static {
  52         impls.put(SunGraphics2D.PAINT_GRADIENT, new Gradient());
  53         impls.put(SunGraphics2D.PAINT_LIN_GRADIENT, new LinearGradient());
  54         impls.put(SunGraphics2D.PAINT_RAD_GRADIENT, new RadialGradient());
  55         impls.put(SunGraphics2D.PAINT_TEXTURE, new Texture());
  56     }


 141                 srcData =
 142                     dstData.getSourceSurfaceData(bi, sg2d.TRANSFORM_ISIDENT,
 143                                                  CompositeType.SrcOver, null);
 144                 if (!(srcData instanceof D3DSurfaceData)) {
 145                     return false;
 146                 }
 147             }
 148 
 149             // verify that the source surface is actually a texture
 150             D3DSurfaceData d3dData = (D3DSurfaceData)srcData;
 151             if (d3dData.getType() != D3DSurfaceData.TEXTURE) {
 152                 return false;
 153             }
 154 
 155             return true;
 156         }
 157     }
 158 
 159 /****************** Shared MultipleGradientPaint support ********************/
 160 
 161     /* No native methods here, but the constants are needed in the supporting JNI code */
 162     @GenerateNativeHeader
 163     private static abstract class MultiGradient extends D3DPaints {
 164 
 165         /**
 166          * Note that this number is lower than the MULTI_MAX_FRACTIONS
 167          * defined in the superclass.  The D3D pipeline now uses a
 168          * slightly more complicated shader (to avoid the gradient banding
 169          * issues), which has a higher instruction count.  To ensure that
 170          * all versions of the shader can be compiled for PS 2.0 hardware,
 171          * we need to cap this maximum value at 8.
 172          */
 173         public static final int MULTI_MAX_FRACTIONS_D3D = 8;
 174 
 175         protected MultiGradient() {}
 176 
 177         /**
 178          * Returns true if the given MultipleGradientPaint instance can be
 179          * used by the accelerated D3DPaints.MultiGradient implementation.
 180          * A MultipleGradientPaint is considered valid if the following
 181          * conditions are met:
 182          *   - the number of gradient "stops" is <= MAX_FRACTIONS
 183          *   - the destination has support for fragment shaders
 184          */
 185         @Override
 186         boolean isPaintValid(SunGraphics2D sg2d) {
 187             MultipleGradientPaint paint = (MultipleGradientPaint)sg2d.paint;
 188             // REMIND: ugh, this creates garbage; would be nicer if
 189             // we had a MultipleGradientPaint.getNumStops() method...
 190             if (paint.getFractions().length > MULTI_MAX_FRACTIONS_D3D) {
 191                 return false;
 192             }
 193 


   1 /*
   2  * Copyright (c) 2007, 2013, 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.LinearGradientPaint;
  29 import java.awt.MultipleGradientPaint;
  30 import java.awt.MultipleGradientPaint.ColorSpaceType;
  31 import java.awt.MultipleGradientPaint.CycleMethod;
  32 import java.awt.TexturePaint;
  33 import java.awt.image.BufferedImage;
  34 import java.util.HashMap;
  35 import java.util.Map;
  36 import java.lang.annotation.Native;
  37 import sun.java2d.SunGraphics2D;
  38 import sun.java2d.SurfaceData;
  39 import sun.java2d.loops.CompositeType;
  40 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
  41 
  42 abstract class D3DPaints {
  43 
  44     /**
  45      * Holds all registered implementations, using the corresponding
  46      * SunGraphics2D.PAINT_* constant as the hash key.
  47      */
  48     private static Map<Integer, D3DPaints> impls =
  49         new HashMap<Integer, D3DPaints>(4, 1.0f);
  50 
  51     static {
  52         impls.put(SunGraphics2D.PAINT_GRADIENT, new Gradient());
  53         impls.put(SunGraphics2D.PAINT_LIN_GRADIENT, new LinearGradient());
  54         impls.put(SunGraphics2D.PAINT_RAD_GRADIENT, new RadialGradient());
  55         impls.put(SunGraphics2D.PAINT_TEXTURE, new Texture());
  56     }


 141                 srcData =
 142                     dstData.getSourceSurfaceData(bi, sg2d.TRANSFORM_ISIDENT,
 143                                                  CompositeType.SrcOver, null);
 144                 if (!(srcData instanceof D3DSurfaceData)) {
 145                     return false;
 146                 }
 147             }
 148 
 149             // verify that the source surface is actually a texture
 150             D3DSurfaceData d3dData = (D3DSurfaceData)srcData;
 151             if (d3dData.getType() != D3DSurfaceData.TEXTURE) {
 152                 return false;
 153             }
 154 
 155             return true;
 156         }
 157     }
 158 
 159 /****************** Shared MultipleGradientPaint support ********************/
 160 


 161     private static abstract class MultiGradient extends D3DPaints {
 162 
 163         /**
 164          * Note that this number is lower than the MULTI_MAX_FRACTIONS
 165          * defined in the superclass.  The D3D pipeline now uses a
 166          * slightly more complicated shader (to avoid the gradient banding
 167          * issues), which has a higher instruction count.  To ensure that
 168          * all versions of the shader can be compiled for PS 2.0 hardware,
 169          * we need to cap this maximum value at 8.
 170          */
 171     @Native public static final int MULTI_MAX_FRACTIONS_D3D = 8;
 172 
 173         protected MultiGradient() {}
 174 
 175         /**
 176          * Returns true if the given MultipleGradientPaint instance can be
 177          * used by the accelerated D3DPaints.MultiGradient implementation.
 178          * A MultipleGradientPaint is considered valid if the following
 179          * conditions are met:
 180          *   - the number of gradient "stops" is <= MAX_FRACTIONS
 181          *   - the destination has support for fragment shaders
 182          */
 183         @Override
 184         boolean isPaintValid(SunGraphics2D sg2d) {
 185             MultipleGradientPaint paint = (MultipleGradientPaint)sg2d.paint;
 186             // REMIND: ugh, this creates garbage; would be nicer if
 187             // we had a MultipleGradientPaint.getNumStops() method...
 188             if (paint.getFractions().length > MULTI_MAX_FRACTIONS_D3D) {
 189                 return false;
 190             }
 191