jdk/src/share/classes/sun/java2d/loops/CompositeType.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7745 ebd6382e93fd
child 26004 7507a1b93f67
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7745
diff changeset
     2
 * Copyright (c) 1999, 2010, 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.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.AlphaComposite;
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
    30
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A CompositeType object provides a chained description of a type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * algorithm for color compositing.  The object will provide a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * String constant descriptor which is one way of describing a particular
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * compositing algorithm as well as a pointer to another CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * which describes a more general algorithm for achieving the same result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * A description of a more specific algorithm is considered a "subtype"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * and a description of a more general algorithm is considered a "supertype".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Thus, the deriveSubType method provides a way to create a new CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * that is related to but more specific than an existing CompositeType and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the getSuperType method provides a way to ask a given CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * for a more general algorithm to achieve the same result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Note that you cannot construct a brand new root for a chain since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the constructor is private.  Every chain of types must at some point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * derive from the Any node provided here using the deriveSubType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * method.  The presence of this common Any node on every chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * ensures that all chains end with the DESC_ANY descriptor so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * a suitable General GraphicsPrimitive object can be obtained for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the indicated algorithm if all of the more specific searches fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public final class CompositeType {
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
    55
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
    56
    private static int unusedUID = 1;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
    57
    private static final HashMap<String,Integer> compositeUIDMap =
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
    58
        new HashMap<String,Integer>(100);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * CONSTANTS USED BY ALL PRIMITIVES TO DESCRIBE THE COMPOSITING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * ALGORITHMS THEY CAN PERFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * algorithm is a general algorithm that uses a CompositeContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * to do the rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final String DESC_ANY      = "Any CompositeContext";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * constant used to describe the Graphics.setXORMode() algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final String DESC_XOR      = "XOR mode";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * constants used to describe the various AlphaComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final String DESC_CLEAR     = "Porter-Duff Clear";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final String DESC_SRC       = "Porter-Duff Src";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final String DESC_DST       = "Porter-Duff Dst";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final String DESC_SRC_OVER  = "Porter-Duff Src Over Dst";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static final String DESC_DST_OVER  = "Porter-Duff Dst Over Src";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static final String DESC_SRC_IN    = "Porter-Duff Src In Dst";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final String DESC_DST_IN    = "Porter-Duff Dst In Src";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static final String DESC_SRC_OUT   = "Porter-Duff Src HeldOutBy Dst";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static final String DESC_DST_OUT   = "Porter-Duff Dst HeldOutBy Src";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final String DESC_SRC_ATOP  = "Porter-Duff Src Atop Dst";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final String DESC_DST_ATOP  = "Porter-Duff Dst Atop Src";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static final String DESC_ALPHA_XOR = "Porter-Duff Xor";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * constants used to describe the two common cases of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * AlphaComposite algorithms that are simpler if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * is not extraAlpha.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        DESC_SRC_NO_EA      = "Porter-Duff Src, No Extra Alpha";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        DESC_SRC_OVER_NO_EA = "Porter-Duff SrcOverDst, No Extra Alpha";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * constant used to describe an algorithm that implements all 8 of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * the Porter-Duff rules in one Primitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static final String DESC_ANY_ALPHA = "Any AlphaComposite Rule";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * END OF COMPOSITE ALGORITHM TYPE CONSTANTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * The root CompositeType object for all chains of algorithm descriptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Any           = new CompositeType(null, DESC_ANY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * START OF CompositeeType OBJECTS FOR THE VARIOUS CONSTANTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        General       = Any;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        AnyAlpha      = General.deriveSubType(DESC_ANY_ALPHA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Xor           = General.deriveSubType(DESC_XOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Clear         = AnyAlpha.deriveSubType(DESC_CLEAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        Src           = AnyAlpha.deriveSubType(DESC_SRC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        Dst           = AnyAlpha.deriveSubType(DESC_DST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        SrcOver       = AnyAlpha.deriveSubType(DESC_SRC_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        DstOver       = AnyAlpha.deriveSubType(DESC_DST_OVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        SrcIn         = AnyAlpha.deriveSubType(DESC_SRC_IN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        DstIn         = AnyAlpha.deriveSubType(DESC_DST_IN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        SrcOut        = AnyAlpha.deriveSubType(DESC_SRC_OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        DstOut        = AnyAlpha.deriveSubType(DESC_DST_OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        SrcAtop       = AnyAlpha.deriveSubType(DESC_SRC_ATOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        DstAtop       = AnyAlpha.deriveSubType(DESC_DST_ATOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        AlphaXor      = AnyAlpha.deriveSubType(DESC_ALPHA_XOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        SrcNoEa       = Src.deriveSubType(DESC_SRC_NO_EA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public static final CompositeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        SrcOverNoEa   = SrcOver.deriveSubType(DESC_SRC_OVER_NO_EA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /*
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   162
     * A special CompositeType for the case where we are filling in
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   163
     * SrcOverNoEa mode with an opaque color.  In that case then the
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   164
     * best loop for us to use would be a SrcNoEa loop, but what if
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   165
     * there is no such loop?  In that case then we would end up
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   166
     * backing off to a Src loop (which should still be fine) or an
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   167
     * AnyAlpha loop which would be slower than a SrcOver loop in
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   168
     * most cases.
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   169
     * The fix is to use the following chain which looks for loops
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   170
     * in the following order:
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   171
     *    SrcNoEa, Src, SrcOverNoEa, SrcOver, AnyAlpha
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   172
     */
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   173
    public static final CompositeType
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   174
        OpaqueSrcOverNoEa = SrcOverNoEa.deriveSubType(DESC_SRC)
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   175
                                       .deriveSubType(DESC_SRC_NO_EA);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   176
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   177
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * END OF CompositeType OBJECTS FOR THE VARIOUS CONSTANTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Return a new CompositeType object which uses this object as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * more general "supertype" descriptor.  If no operation can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * found that implements the algorithm described more exactly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * by desc, then this object will define the more general
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * compositing algorithm that can be used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public CompositeType deriveSubType(String desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return new CompositeType(this, desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Return a CompositeType object for the specified AlphaComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public static CompositeType forAlphaComposite(AlphaComposite ac) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        switch (ac.getRule()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        case AlphaComposite.CLEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return Clear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        case AlphaComposite.SRC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            if (ac.getAlpha() >= 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                return SrcNoEa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                return Src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        case AlphaComposite.DST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return Dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        case AlphaComposite.SRC_OVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (ac.getAlpha() >= 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                return SrcOverNoEa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                return SrcOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        case AlphaComposite.DST_OVER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return DstOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        case AlphaComposite.SRC_IN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            return SrcIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        case AlphaComposite.DST_IN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return DstIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        case AlphaComposite.SRC_OUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return SrcOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        case AlphaComposite.DST_OUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return DstOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        case AlphaComposite.SRC_ATOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return SrcAtop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        case AlphaComposite.DST_ATOP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return DstAtop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        case AlphaComposite.XOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return AlphaXor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            throw new InternalError("Unrecognized alpha rule");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private int uniqueID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private String desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private CompositeType next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private CompositeType(CompositeType parent, String desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        next = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        this.desc = desc;
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   242
        this.uniqueID = makeUniqueID(desc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   245
    public synchronized static final int makeUniqueID(String desc) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   246
        Integer i = compositeUIDMap.get(desc);
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   247
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   248
        if (i == null) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   249
            if (unusedUID > 255) {
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   250
                throw new InternalError("composite type id overflow");
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   251
            }
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   252
            i = unusedUID++;
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   253
            compositeUIDMap.put(desc, i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
7745
ebd6382e93fd 6766342: Improve performance of Ductus rasterizer
flar
parents: 5506
diff changeset
   255
        return i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public int getUniqueID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return uniqueID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public String getDescriptor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public CompositeType getSuperType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return desc.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public boolean isDerivedFrom(CompositeType other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        CompositeType comptype = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (comptype.desc == other.desc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            comptype = comptype.next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        } while (comptype != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (o instanceof CompositeType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            return (((CompositeType) o).uniqueID == this.uniqueID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return desc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}