jdk/src/share/classes/sun/java2d/loops/Blit.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 10042 987fd92d0413
child 24522 3a0bbf9f5e81
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 10042
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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.loops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.CompositeContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.RenderingHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.image.WritableRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.java2d.loops.GraphicsPrimitive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.java2d.pipe.SpanIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Blit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * 1) copies rectangle of pixels from one surface to another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * 2) performs compositing of colors based upon a Composite
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *    parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * precise behavior is undefined if the source surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * and the destination surface are the same surface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * with overlapping regions of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public class Blit extends GraphicsPrimitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final String methodSignature = "Blit(...)".toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final int primTypeID = makePrimTypeID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static RenderCache blitcache = new RenderCache(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static Blit locate(SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                              CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                              SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        return (Blit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            GraphicsPrimitiveMgr.locate(primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                        srctype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static Blit getFromCache(SurfaceType src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                    CompositeType comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                    SurfaceType dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        Object o = blitcache.get(src, comp, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            return (Blit) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        Blit blit = locate(src, comp, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (blit == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            System.out.println("blit loop not found for:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            System.out.println("src:  "+src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            System.out.println("comp: "+comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            System.out.println("dst:  "+dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            blitcache.put(src, comp, dst, blit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return blit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected Blit(SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                   CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                   SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        super(methodSignature, primTypeID, srctype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public Blit(long pNativePrim,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        super(pNativePrim, methodSignature, primTypeID, srctype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * All Blit implementors must have this invoker method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public native void Blit(SurfaceData src, SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                            Composite comp, Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                            int srcx, int srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                            int dstx, int dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                            int width, int height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        GraphicsPrimitiveMgr.registerGeneral(new Blit(null, null, null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public GraphicsPrimitive makePrimitive(SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                           CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                           SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        System.out.println("Constructing general blit for:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        System.out.println("src:  "+srctype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        System.out.println("comp: "+comptype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        System.out.println("dst:  "+dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (comptype.isDerivedFrom(CompositeType.Xor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            GeneralXorBlit gxb = new GeneralXorBlit(srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                                    comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                                    dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            setupGeneralBinaryOp(gxb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return gxb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } else if (comptype.isDerivedFrom(CompositeType.AnyAlpha)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return new GeneralMaskBlit(srctype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return AnyBlit.instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static class AnyBlit extends Blit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        public static AnyBlit instance = new AnyBlit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        public AnyBlit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            super(SurfaceType.Any, CompositeType.Any, SurfaceType.Any);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        public void Blit(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                         SurfaceData dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                         Composite comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                         Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                         int srcx, int srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                         int dstx, int dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                         int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            ColorModel srcCM = srcData.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            ColorModel dstCM = dstData.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            // REMIND: Should get RenderingHints from sg2d
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            CompositeContext ctx = comp.createContext(srcCM, dstCM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                                      new RenderingHints(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            WritableRaster dstRas =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                (WritableRaster) dstData.getRaster(dstx, dsty, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if (clip == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                clip = Region.getInstanceXYWH(dstx, dsty, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            int span[] = {dstx, dsty, dstx+width, dsty+height};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            SpanIterator si = clip.getSpanIterator(span);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            srcx -= dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            srcy -= dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            while (si.nextSpan(span)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                int w = span[2] - span[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                int h = span[3] - span[1];
10042
987fd92d0413 7049339: AnyBlit is broken with non-rectangular clips.
dlila
parents: 5506
diff changeset
   175
                Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
987fd92d0413 7049339: AnyBlit is broken with non-rectangular clips.
dlila
parents: 5506
diff changeset
   176
                                                      w, h, 0, 0, null);
987fd92d0413 7049339: AnyBlit is broken with non-rectangular clips.
dlila
parents: 5506
diff changeset
   177
                WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
987fd92d0413 7049339: AnyBlit is broken with non-rectangular clips.
dlila
parents: 5506
diff changeset
   178
                                                                      w, h, 0, 0, null);
987fd92d0413 7049339: AnyBlit is broken with non-rectangular clips.
dlila
parents: 5506
diff changeset
   179
                ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            ctx.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private static class GeneralMaskBlit extends Blit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        MaskBlit performop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        public GeneralMaskBlit(SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                               CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                               SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            super(srctype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            performop = MaskBlit.locate(srctype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        public void Blit(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                         SurfaceData dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                         Composite comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                         Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                         int srcx, int srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                         int dstx, int dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                         int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            performop.MaskBlit(srcData, dstData, comp, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                               srcx, srcy, dstx, dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                               width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                               null, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private static class GeneralXorBlit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        extends Blit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        implements GeneralBinaryOp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        Blit convertsrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        Blit convertdst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        Blit performop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Blit convertresult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        WeakReference srcTmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        WeakReference dstTmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        public GeneralXorBlit(SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                              CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                              SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            super(srctype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        public void setPrimitives(Blit srcconverter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                                  Blit dstconverter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                  GraphicsPrimitive genericop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                  Blit resconverter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            this.convertsrc = srcconverter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            this.convertdst = dstconverter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            this.performop = (Blit) genericop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            this.convertresult = resconverter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        public synchronized void Blit(SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                      SurfaceData dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                      Composite comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                      Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                      int srcx, int srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                      int dstx, int dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                      int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            SurfaceData src, dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            Region opclip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            int sx, sy, dx, dy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (convertsrc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                src = srcData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                sx = srcx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                sy = srcy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                SurfaceData cachedSrc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                if (srcTmp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    cachedSrc = (SurfaceData) srcTmp.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                src = convertFrom(convertsrc, srcData, srcx, srcy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                  width, height, cachedSrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                sx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                sy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                if (src != cachedSrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    srcTmp = new WeakReference(src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (convertdst == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                dst = dstData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                dx = dstx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                dy = dsty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                opclip = clip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                // assert: convertresult != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                SurfaceData cachedDst = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                if (dstTmp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    cachedDst = (SurfaceData) dstTmp.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                dst = convertFrom(convertdst, dstData, dstx, dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                  width, height, cachedDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                dx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                dy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                opclip = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                if (dst != cachedDst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    dstTmp = new WeakReference(dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            performop.Blit(src, dst, comp, opclip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                           sx, sy, dx, dy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                           width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (convertresult != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                // assert: convertdst != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                convertTo(convertresult, dst, dstData, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                          dstx, dsty, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public GraphicsPrimitive traceWrap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return new TraceBlit(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    private static class TraceBlit extends Blit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        Blit target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        public TraceBlit(Blit target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            super(target.getSourceType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                  target.getCompositeType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                  target.getDestType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        public GraphicsPrimitive traceWrap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        public void Blit(SurfaceData src, SurfaceData dst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                         Composite comp, Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                         int srcx, int srcy, int dstx, int dsty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                         int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            tracePrimitive(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            target.Blit(src, dst, comp, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        srcx, srcy, dstx, dsty, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
}