jdk/src/windows/classes/sun/java2d/windows/DDScaleLoops.java
changeset 1024 2253d6d6cf2c
parent 1023 9a1c25552b10
parent 945 6838c1a3296a
child 1025 a9ba5ea0f1f7
equal deleted inserted replaced
1023:9a1c25552b10 1024:2253d6d6cf2c
     1 /*
       
     2  * Copyright 2001-2007 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 package sun.java2d.windows;
       
    27 
       
    28 import sun.java2d.loops.GraphicsPrimitive;
       
    29 import sun.java2d.loops.GraphicsPrimitiveMgr;
       
    30 import sun.java2d.loops.GraphicsPrimitiveProxy;
       
    31 import sun.java2d.loops.CompositeType;
       
    32 import sun.java2d.loops.SurfaceType;
       
    33 import sun.java2d.loops.ScaledBlit;
       
    34 import sun.java2d.pipe.Region;
       
    35 import sun.java2d.SurfaceData;
       
    36 import java.awt.Composite;
       
    37 
       
    38 /**
       
    39  * DDScaleLoops
       
    40  *
       
    41  * This class accelerates ScaledBlits between two DirectDraw surfaces.  Since
       
    42  * the onscreen surface is of that type and some of the offscreen surfaces
       
    43  * may be of that type (if they were created in a SurfaceDataProxy), then
       
    44  * this type of ScaledBlit will accelerated double-buffer copies between those
       
    45  * two surfaces.
       
    46 */
       
    47 public class DDScaleLoops extends ScaledBlit {
       
    48     private ScaledBlit swblit;
       
    49 
       
    50     public static void register()
       
    51     {
       
    52         GraphicsPrimitive[] primitives = {
       
    53             new DDScaleLoops(Win32SurfaceData.IntRgbDD),
       
    54             new DDScaleLoops(Win32SurfaceData.Ushort565RgbDD),
       
    55             new DDScaleLoops(Win32SurfaceData.IntRgbxDD),
       
    56             new DDScaleLoops(Win32SurfaceData.Ushort555RgbxDD),
       
    57             new DDScaleLoops(Win32SurfaceData.Ushort555RgbDD),
       
    58             new DDScaleLoops(Win32SurfaceData.ByteIndexedOpaqueDD),
       
    59             new DDScaleLoops(Win32SurfaceData.ThreeByteBgrDD)
       
    60         };
       
    61         GraphicsPrimitiveMgr.register(primitives);
       
    62     }
       
    63 
       
    64     public DDScaleLoops(SurfaceType surfType) {
       
    65         super(surfType, CompositeType.SrcNoEa, surfType);
       
    66     }
       
    67 
       
    68     /**
       
    69      * Scale
       
    70      * This native method is where all of the work happens in the
       
    71      * accelerated ScaledBlit for the scaling case.
       
    72      */
       
    73     public native void Scale(SurfaceData src, SurfaceData dst,
       
    74                              Composite comp, int sx, int sy,
       
    75                              int dx, int dy, int sw, int sh,
       
    76                              int dw, int dh);
       
    77 
       
    78     public void Scale(SurfaceData src, SurfaceData dst,
       
    79                       Composite comp, Region clip,
       
    80                       int sx1, int sy1,
       
    81                       int sx2, int sy2,
       
    82                       double dx1, double dy1,
       
    83                       double dx2, double dy2)
       
    84     {
       
    85         // REMIND: We can still do it if the clip equals the device
       
    86         // bounds for a destination window, but this logic rejects
       
    87         // that case...
       
    88         int dx = (int) Math.round(dx1);
       
    89         int dy = (int) Math.round(dy1);
       
    90         int dw = (int) Math.round(dx2) - dx;
       
    91         int dh = (int) Math.round(dy2) - dy;
       
    92         if (clip.encompassesXYWH(dx, dy, dw, dh)) {
       
    93             // Note that this rounding creates inaccuracies, but these
       
    94             // loops are disabled by default until a user specifically
       
    95             // enables them so this rounding behavior can be one of
       
    96             // the drawbacks that the user accepts when enabling this
       
    97             // non-standard feature.
       
    98             // If we should ever want to turn them on by default then
       
    99             // we will need to decide what better handling to put here.
       
   100             Scale(src, dst, comp, sx1, sy1, dx, dy, sx2-sx1, sy2-sy1, dw, dh);
       
   101         } else {
       
   102             if (swblit == null) {
       
   103                 // REMIND: This assumes that the DD surface types are
       
   104                 // directly derived from a non-DD type that has a loop.
       
   105                 swblit = ScaledBlit.getFromCache(getSourceType().getSuperType(),
       
   106                                                  getCompositeType(),
       
   107                                                  getDestType().getSuperType());
       
   108             }
       
   109             swblit.Scale(src, dst, comp, clip,
       
   110                          sx1, sy1, sx2, sy2,
       
   111                          dx1, dy1, dx2, dy2);
       
   112         }
       
   113     }
       
   114 }