jdk/src/java.desktop/share/classes/sun/java2d/SunCompositeContext.java
author serb
Fri, 22 May 2015 23:26:00 +0300
changeset 30948 0a0972d3b58d
parent 25859 3317bb8137f4
permissions -rw-r--r--
6587235: Incorrect javadoc: "no parameter" in 2d source code Reviewed-by: azvegint, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2002, 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;
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.AlphaComposite;
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.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.image.WritableRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.awt.image.BufImgSurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.java2d.loops.XORComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.java2d.loops.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.java2d.loops.Blit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class SunCompositeContext implements CompositeContext {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    ColorModel srcCM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    ColorModel dstCM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    Composite composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    CompositeType comptype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public SunCompositeContext(AlphaComposite ac,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                               ColorModel s, ColorModel d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            throw new NullPointerException("Source color model cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        if (d == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            throw new NullPointerException("Destination color model cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        srcCM = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        dstCM = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.composite = ac;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.comptype = CompositeType.forAlphaComposite(ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public SunCompositeContext(XORComposite xc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                               ColorModel s, ColorModel d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            throw new NullPointerException("Source color model cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (d == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            throw new NullPointerException("Destination color model cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        srcCM = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        dstCM = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        this.composite = xc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        this.comptype = CompositeType.Xor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Release resources allocated for context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * This method composes the two source tiles
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * and places the result in the destination tile. Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * the destination can be the same object as either
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * the first or second source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param src1 The first source tile for the compositing operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param src2 The second source tile for the compositing operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param dst The tile where the result of the operation is stored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
    91
    public void compose(Raster src1, Raster src2, WritableRaster dst) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        WritableRaster src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        int w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        int h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
    96
        if (src2 != dst) {
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
    97
            dst.setDataElements(0, 0, src2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // REMIND: We should be able to create a SurfaceData from just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // a non-writable Raster and a ColorModel.  Since we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // create a SurfaceData from a BufferedImage then we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // make a WritableRaster since it is needed to construct a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // BufferedImage.
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
   105
        if (src1 instanceof WritableRaster) {
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
   106
            src = (WritableRaster) src1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } else {
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
   108
            src = src1.createCompatibleWritableRaster();
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
   109
            src.setDataElements(0, 0, src1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
   112
        w = Math.min(src.getWidth(), src2.getWidth());
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
   113
        h = Math.min(src.getHeight(), src2.getHeight());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        BufferedImage srcImg = new BufferedImage(srcCM, src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                                 srcCM.isAlphaPremultiplied(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                 null);
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 25859
diff changeset
   118
        BufferedImage dstImg = new BufferedImage(dstCM, dst,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                                 dstCM.isAlphaPremultiplied(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                                 null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        SurfaceData srcData = BufImgSurfaceData.createData(srcImg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        SurfaceData dstData = BufImgSurfaceData.createData(dstImg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        Blit blit = Blit.getFromCache(srcData.getSurfaceType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                      comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                      dstData.getSurfaceType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        blit.Blit(srcData, dstData, composite, null, 0, 0, 0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
}