jdk/src/solaris/classes/sun/java2d/x11/X11PMBlitLoops.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 2758 d2fbe9b5857a
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d.x11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.java2d.loops.GraphicsPrimitive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.java2d.loops.GraphicsPrimitiveMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.java2d.loops.GraphicsPrimitiveProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.java2d.loops.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.java2d.loops.Blit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.java2d.loops.MaskBlit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.image.IndexColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * X11PMBlitLoops
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class accelerates Blits between two surfaces of types *PM.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the onscreen surface is of that type and some of the offscreen surfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * may be of that type (if they were created via X11OffScreenImage), then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * this type of Blit will accelerated double-buffer copies between those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * two surfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class X11PMBlitLoops extends Blit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static void register()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        GraphicsPrimitive[] primitives = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            new X11PMBlitLoops(X11SurfaceData.IntBgrX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                               X11SurfaceData.IntBgrX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            new X11PMBlitLoops(X11SurfaceData.IntRgbX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                               X11SurfaceData.IntRgbX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            new X11PMBlitLoops(X11SurfaceData.ThreeByteBgrX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                               X11SurfaceData.ThreeByteBgrX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            new X11PMBlitLoops(X11SurfaceData.ThreeByteRgbX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                               X11SurfaceData.ThreeByteRgbX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            new X11PMBlitLoops(X11SurfaceData.ByteIndexedOpaqueX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                               X11SurfaceData.ByteIndexedOpaqueX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            new X11PMBlitLoops(X11SurfaceData.ByteGrayX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                               X11SurfaceData.ByteGrayX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            new X11PMBlitLoops(X11SurfaceData.Index8GrayX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                               X11SurfaceData.Index8GrayX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            new X11PMBlitLoops(X11SurfaceData.UShort555RgbX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                               X11SurfaceData.UShort555RgbX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            new X11PMBlitLoops(X11SurfaceData.UShort565RgbX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                               X11SurfaceData.UShort565RgbX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            new X11PMBlitLoops(X11SurfaceData.UShortIndexedX11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                               X11SurfaceData.UShortIndexedX11, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            // 1-bit transparent to opaque loops
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            new X11PMBlitLoops(X11SurfaceData.IntBgrX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                               X11SurfaceData.IntBgrX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            new X11PMBlitLoops(X11SurfaceData.IntRgbX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                               X11SurfaceData.IntRgbX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            new X11PMBlitLoops(X11SurfaceData.ThreeByteBgrX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                               X11SurfaceData.ThreeByteBgrX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            new X11PMBlitLoops(X11SurfaceData.ThreeByteRgbX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                               X11SurfaceData.ThreeByteRgbX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            new X11PMBlitLoops(X11SurfaceData.ByteIndexedX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                               X11SurfaceData.ByteIndexedOpaqueX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            new X11PMBlitLoops(X11SurfaceData.ByteGrayX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                               X11SurfaceData.ByteGrayX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            new X11PMBlitLoops(X11SurfaceData.Index8GrayX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                               X11SurfaceData.Index8GrayX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            new X11PMBlitLoops(X11SurfaceData.UShort555RgbX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                               X11SurfaceData.UShort555RgbX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            new X11PMBlitLoops(X11SurfaceData.UShort565RgbX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                               X11SurfaceData.UShort565RgbX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            new X11PMBlitLoops(X11SurfaceData.UShortIndexedX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                               X11SurfaceData.UShortIndexedX11, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            // delegate loops
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            new DelegateBlitLoop(X11SurfaceData.IntBgrX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                 X11SurfaceData.IntBgrX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            new DelegateBlitLoop(X11SurfaceData.IntRgbX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                 X11SurfaceData.IntRgbX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            new DelegateBlitLoop(X11SurfaceData.ThreeByteBgrX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                 X11SurfaceData.ThreeByteBgrX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            new DelegateBlitLoop(X11SurfaceData.ThreeByteRgbX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                 X11SurfaceData.ThreeByteRgbX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            new DelegateBlitLoop(X11SurfaceData.ByteIndexedX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                 X11SurfaceData.ByteIndexedOpaqueX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            new DelegateBlitLoop(X11SurfaceData.ByteGrayX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                 X11SurfaceData.ByteGrayX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            new DelegateBlitLoop(X11SurfaceData.Index8GrayX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                 X11SurfaceData.Index8GrayX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            new DelegateBlitLoop(X11SurfaceData.UShort555RgbX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                 X11SurfaceData.UShort555RgbX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            new DelegateBlitLoop(X11SurfaceData.UShort565RgbX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                 X11SurfaceData.UShort565RgbX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            new DelegateBlitLoop(X11SurfaceData.UShortIndexedX11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                 X11SurfaceData.UShortIndexedX11),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        GraphicsPrimitiveMgr.register(primitives);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public X11PMBlitLoops(SurfaceType srcType, SurfaceType dstType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                          boolean over) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        super(srcType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
              over ? CompositeType.SrcOverNoEa : CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
              dstType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void Blit(SurfaceData src, SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                     Composite comp, Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                     int sx, int sy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                     int dx, int dy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                     int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        SunToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            X11SurfaceData x11sd = (X11SurfaceData)dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            // pass null clip region here since we clip manually in native code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            // also use false for needExposures since we clip to the pixmap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            long xgc = x11sd.getBlitGC(null, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            nativeBlit(src.getNativeOps(), dst.getNativeOps(), xgc, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                       sx, sy, dx, dy, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            SunToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Blit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * This native method is where all of the work happens in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * accelerated Blit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private native void nativeBlit(long srcData, long dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                   long xgc, Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                   int sx, int sy, int dx, int dy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                   int w, int h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * This loop is used to render from a BITMASK Sw surface data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * to the Hw cached copies managed by SurfaceDataProxies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * It first uses a delegate opaque Blit to perform the copy of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * the pixel data and then updates the X11 clipping bitmask from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * the transparent pixels in the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    static class DelegateBlitLoop extends Blit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        SurfaceType dstType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
         * @param realDstType SurfaceType for which the loop should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         * registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
         * @param delegateDstType SurfaceType which will be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         * for finding delegate loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        public DelegateBlitLoop(SurfaceType realDstType, SurfaceType delegateDstType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            super(SurfaceType.Any, CompositeType.SrcNoEa, realDstType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            this.dstType = delegateDstType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        public void Blit(SurfaceData src, SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                         Composite comp, Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                         int sx, int sy, int dx, int dy, int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            Blit blit = Blit.getFromCache(src.getSurfaceType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                          CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                          dstType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            blit.Blit(src, dst, comp, clip, sx, sy, dx, dy, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            updateBitmask(src, dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                          src.getColorModel() instanceof IndexColorModel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private static native void updateBitmask(SurfaceData src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                             SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                             boolean isICM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
}