jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitive.java
author michaelm
Thu, 24 Oct 2013 20:39:21 +0100
changeset 22339 e91bfaf4360d
parent 11080 7e18e343964e
child 23010 6dadb192ad81
permissions -rw-r--r--
8011786: Better applet networking Reviewed-by: alanb, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 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: 5275
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: 5275
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: 5275
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5275
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @author Charlton Innovations, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
package sun.java2d.loops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.AlphaComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.awt.image.BufImgSurfaceData;
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 java.lang.reflect.Field;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * defines interface for primitives which can be placed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the graphic component manager framework
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public abstract class GraphicsPrimitive {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected static interface GeneralBinaryOp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
         * This method allows the setupGeneralBinaryOp method to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         * the converters into the General version of the Primitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        public void setPrimitives(Blit srcconverter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                  Blit dstconverter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                  GraphicsPrimitive genericop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                  Blit resconverter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         * These 4 methods are implemented automatically for any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
         * GraphicsPrimitive.  They are used by setupGeneralBinaryOp
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
         * to retrieve the information needed to find the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
         * converter primitives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        public SurfaceType getSourceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        public CompositeType getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        public SurfaceType getDestType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        public String getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        public int getPrimTypeID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    protected static interface GeneralUnaryOp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         * This method allows the setupGeneralUnaryOp method to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         * the converters into the General version of the Primitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        public void setPrimitives(Blit dstconverter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                  GraphicsPrimitive genericop,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                  Blit resconverter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * These 3 methods are implemented automatically for any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         * GraphicsPrimitive.  They are used by setupGeneralUnaryOp
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         * to retrieve the information needed to find the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         * converter primitives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        public CompositeType getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        public SurfaceType getDestType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        public String getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        public int getPrimTypeID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    *  INSTANCE DATA MEMBERS DESCRIBING CHARACTERISTICS OF THIS PRIMITIVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    // Making these be instance data members (instead of virtual methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // overridden by subclasses) is actually cheaper, since each class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // is a singleton.  As instance data members with final accessors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // accesses can be inlined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private String methodSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private int uniqueID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static int unusedPrimID = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private SurfaceType sourceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private CompositeType compositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private SurfaceType destType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private long pNativePrim;   // Native blit loop info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public synchronized static final int makePrimTypeID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (unusedPrimID > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            throw new InternalError("primitive id overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return unusedPrimID++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public synchronized static final int makeUniqueID(int primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                                      SurfaceType src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                                      CompositeType cmp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                                      SurfaceType dst)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return (primTypeID << 24) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            (dst.getUniqueID() << 16) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            (cmp.getUniqueID() << 8)  |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            (src.getUniqueID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Create a new GraphicsPrimitive with all of the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * descriptive information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    protected GraphicsPrimitive(String methodSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                int primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                SurfaceType sourceType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                CompositeType compositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                SurfaceType destType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        this.methodSignature = methodSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        this.sourceType = sourceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        this.compositeType = compositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this.destType = destType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if(sourceType == null || compositeType == null || destType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            this.uniqueID = primTypeID << 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            this.uniqueID = GraphicsPrimitive.makeUniqueID(primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                                           sourceType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                                           compositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                                           destType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Create a new GraphicsPrimitive for native invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * with all of the required descriptive information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    protected GraphicsPrimitive(long pNativePrim,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                String methodSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                int primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                SurfaceType sourceType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                CompositeType compositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                SurfaceType destType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        this.pNativePrim = pNativePrim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        this.methodSignature = methodSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        this.sourceType = sourceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this.compositeType = compositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        this.destType = destType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if(sourceType == null || compositeType == null || destType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            this.uniqueID = primTypeID << 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            this.uniqueID = GraphicsPrimitive.makeUniqueID(primTypeID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                                           sourceType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                                           compositeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                                           destType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    *   METHODS TO DESCRIBE THE SURFACES PRIMITIVES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    *   CAN OPERATE ON AND THE FUNCTIONALITY THEY IMPLEMENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Gets instance ID of this graphics primitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Instance ID is comprised of four distinct ids (ORed together)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * that uniquely identify each instance of a GraphicsPrimitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * object. The four ids making up instance ID are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * 1. primitive id - identifier shared by all primitives of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * same type (eg. all Blits have the same primitive id)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * 2. sourcetype id - identifies source surface type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * 3. desttype id - identifies destination surface type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * 4. compositetype id - identifies composite used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @return instance ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public final int getUniqueID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return uniqueID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public final String getSignature() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return methodSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Gets unique id for this GraphicsPrimitive type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * This id is used to identify the TYPE of primitive (Blit vs. BlitBg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * as opposed to INSTANCE of primitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @return primitive ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public final int getPrimTypeID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return uniqueID >>> 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public final long getNativePrim() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return pNativePrim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public final SurfaceType getSourceType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return sourceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public final CompositeType getCompositeType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return compositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public final SurfaceType getDestType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return destType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Return true if this primitive can be used for the given signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * surfaces, and composite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param signature The signature of the given operation.  Must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *          == (not just .equals) the signature string given by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *          abstract class that declares the operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param srctype The surface type for the source of the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @param comptype The composite type for the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param dsttype The surface type for the destination of the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public final boolean satisfies(String signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                   SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                   CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                   SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (signature != methodSignature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            if (srctype == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (srctype.equals(sourceType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            srctype = srctype.getSuperType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (comptype == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            if (comptype.equals(compositeType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            comptype = comptype.getSuperType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (dsttype == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (dsttype.equals(destType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            dsttype = dsttype.getSuperType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return true;
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
    // A version of satisfies used for regression testing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    final boolean satisfiesSameAs(GraphicsPrimitive other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return (methodSignature == other.methodSignature &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                sourceType.equals(other.sourceType) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                compositeType.equals(other.compositeType) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                destType.equals(other.destType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public abstract GraphicsPrimitive makePrimitive(SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                                    CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                                    SurfaceType dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public abstract GraphicsPrimitive traceWrap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    static HashMap traceMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public static int traceflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public static String tracefile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public static PrintStream traceout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public static final int TRACELOG = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public static final int TRACETIMESTAMP = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public static final int TRACECOUNTS = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        GetPropertyAction gpa = new GetPropertyAction("sun.java2d.trace");
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 7668
diff changeset
   331
        String trace = AccessController.doPrivileged(gpa);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (trace != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            boolean verbose = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            int traceflags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            StringTokenizer st = new StringTokenizer(trace, ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                String tok = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                if (tok.equalsIgnoreCase("count")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    traceflags |= GraphicsPrimitive.TRACECOUNTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                } else if (tok.equalsIgnoreCase("log")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    traceflags |= GraphicsPrimitive.TRACELOG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                } else if (tok.equalsIgnoreCase("timestamp")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    traceflags |= GraphicsPrimitive.TRACETIMESTAMP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                } else if (tok.equalsIgnoreCase("verbose")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    verbose = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                } else if (tok.regionMatches(true, 0, "out:", 0, 4)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    tracefile = tok.substring(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    if (!tok.equalsIgnoreCase("help")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                        System.err.println("unrecognized token: "+tok);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    System.err.println("usage: -Dsun.java2d.trace="+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                       "[log[,timestamp]],[count],"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                       "[out:<filename>],[help],[verbose]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                System.err.print("GraphicsPrimitive logging ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                if ((traceflags & GraphicsPrimitive.TRACELOG) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    System.err.println("enabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    System.err.print("GraphicsPrimitive timetamps ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    if ((traceflags & GraphicsPrimitive.TRACETIMESTAMP) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                        System.err.println("enabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                        System.err.println("disabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    System.err.println("[and timestamps] disabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                System.err.print("GraphicsPrimitive invocation counts ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                if ((traceflags & GraphicsPrimitive.TRACECOUNTS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    System.err.println("enabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    System.err.println("disabled");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                System.err.print("GraphicsPrimitive trace output to ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                if (tracefile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    System.err.println("System.err");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    System.err.println("file '"+tracefile+"'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            GraphicsPrimitive.traceflags = traceflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public static boolean tracingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return (traceflags != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    private static PrintStream getTraceOutputFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (traceout == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            if (tracefile != null) {
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 7668
diff changeset
   394
                FileOutputStream o = AccessController.doPrivileged(
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 7668
diff changeset
   395
                    new PrivilegedAction<FileOutputStream>() {
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 7668
diff changeset
   396
                        public FileOutputStream run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                return new FileOutputStream(tracefile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                            } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                if (o != null) {
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 7668
diff changeset
   405
                    traceout = new PrintStream(o);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    traceout = System.err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                traceout = System.err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return traceout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public static class TraceReporter extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        public static void setShutdownHook() {
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 7668
diff changeset
   418
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 7668
diff changeset
   419
                public Void run() {
5275
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 2
diff changeset
   420
                    TraceReporter t = new TraceReporter();
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 2
diff changeset
   421
                    t.setContextClassLoader(null);
fa9f5ce2006e 6936389: FontManager.fileCloser may cause memory leak in applets
bae
parents: 2
diff changeset
   422
                    Runtime.getRuntime().addShutdownHook(t);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            PrintStream ps = getTraceOutputFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            Iterator iterator = traceMap.entrySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            long total = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            int numprims = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            while (iterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                Map.Entry me = (Map.Entry) iterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                Object prim = me.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                int[] count = (int[]) me.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                if (count[0] == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    ps.print("1 call to ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    ps.print(count[0]+" calls to ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                ps.println(prim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                numprims++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                total += count[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (numprims == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                ps.println("No graphics primitives executed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            } else if (numprims > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                ps.println(total+" total calls to "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                           numprims+" different primitives");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public synchronized static void tracePrimitive(Object prim) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if ((traceflags & TRACECOUNTS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (traceMap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                traceMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                TraceReporter.setShutdownHook();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            Object o = traceMap.get(prim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                o = new int[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                traceMap.put(prim, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            ((int[]) o)[0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if ((traceflags & TRACELOG) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            PrintStream ps = getTraceOutputFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if ((traceflags & TRACETIMESTAMP) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                ps.print(System.currentTimeMillis()+": ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            ps.println(prim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    protected void setupGeneralBinaryOp(GeneralBinaryOp gbo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        int primID = gbo.getPrimTypeID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        String methodSignature = gbo.getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        SurfaceType srctype = gbo.getSourceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        CompositeType comptype = gbo.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        SurfaceType dsttype = gbo.getDestType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        Blit convertsrc, convertdst, convertres;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        GraphicsPrimitive performop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        convertsrc = createConverter(srctype, SurfaceType.IntArgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        performop = GraphicsPrimitiveMgr.locatePrim(primID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                                    SurfaceType.IntArgb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                                    comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (performop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            convertdst = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            convertres = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            performop = getGeneralOp(primID, comptype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            if (performop == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                throw new InternalError("Cannot construct general op for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                        methodSignature+" "+comptype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            convertdst = createConverter(dsttype, SurfaceType.IntArgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            convertres = createConverter(SurfaceType.IntArgb, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        gbo.setPrimitives(convertsrc, convertdst, performop, convertres);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    protected void setupGeneralUnaryOp(GeneralUnaryOp guo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        int primID = guo.getPrimTypeID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        String methodSignature = guo.getSignature();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        CompositeType comptype = guo.getCompositeType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        SurfaceType dsttype = guo.getDestType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        Blit convertdst = createConverter(dsttype, SurfaceType.IntArgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        GraphicsPrimitive performop = getGeneralOp(primID, comptype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        Blit convertres = createConverter(SurfaceType.IntArgb, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (convertdst == null || performop == null || convertres == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            throw new InternalError("Cannot construct binary op for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                    comptype+" "+dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        guo.setPrimitives(convertdst, performop, convertres);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    protected static Blit createConverter(SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                                          SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        if (srctype.equals(dsttype)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        Blit cv = Blit.getFromCache(srctype, CompositeType.SrcNoEa, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (cv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            throw new InternalError("Cannot construct converter for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                                    srctype+"=>"+dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        return cv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                             int srcX, int srcY, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                             SurfaceData dstData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        return convertFrom(ob, srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                           srcX, srcY, w, h, dstData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                           BufferedImage.TYPE_INT_ARGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    protected static SurfaceData convertFrom(Blit ob, SurfaceData srcData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                             int srcX, int srcY, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                             SurfaceData dstData, int type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (dstData != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            Rectangle r = dstData.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            if (w > r.width || h > r.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                dstData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (dstData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            BufferedImage dstBI = new BufferedImage(w, h, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            dstData = BufImgSurfaceData.createData(dstBI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        ob.Blit(srcData, dstData, AlphaComposite.Src, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                srcX, srcY, 0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return dstData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    protected static void convertTo(Blit ob,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                    SurfaceData srcImg, SurfaceData dstImg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                    Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                    int dstX, int dstY, int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        if (ob != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            ob.Blit(srcImg, dstImg, AlphaComposite.Src, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    0, 0, dstX, dstY, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    protected static GraphicsPrimitive getGeneralOp(int primID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                                    CompositeType comptype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        return GraphicsPrimitiveMgr.locatePrim(primID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                               SurfaceType.IntArgb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                               comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                               SurfaceType.IntArgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    public static String simplename(Field[] fields, Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        for (int i = 0; i < fields.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            Field f = fields[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                if (o == f.get(null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    return f.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        return "\""+o.toString()+"\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    public static String simplename(SurfaceType st) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        return simplename(SurfaceType.class.getDeclaredFields(), st);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public static String simplename(CompositeType ct) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return simplename(CompositeType.class.getDeclaredFields(), ct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    private String cachedname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (cachedname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            String sig = methodSignature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            int index = sig.indexOf('(');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            if (index >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                sig = sig.substring(0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            cachedname = (getClass().getName()+"::"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                          sig+"("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                          simplename(sourceType)+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                          simplename(compositeType)+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                          simplename(destType)+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        return cachedname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
}