jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitiveProxy.java
author michaelm
Thu, 24 Oct 2013 20:39:21 +0100
changeset 22339 e91bfaf4360d
parent 5506 202f599c92aa
child 24522 3a0bbf9f5e81
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
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2003, 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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *   GraphicsPrimitiveProxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Acts as a proxy for instances of GraphicsPrimitive, enabling lazy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * classloading of these primitives.  This leads to a substantial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * savings in start-up time and footprint.  In the typical case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * it has been found that a small number of GraphicsPrimitive instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * actually end up getting instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Note that the makePrimitive method should never be invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * a GraphicsPrimitiveProxy object since they are instantiated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * soon as they are found in the primitive list and never returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * to the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class GraphicsPrimitiveProxy extends GraphicsPrimitive {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private Class owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private String relativeClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Create a GraphicsPrimitiveProxy for a primitive with a no-argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @param owner The owner class for this primitive.  The primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *          must be in the same package as this owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @param relativeClassName  The name of the class this is a proxy for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *          This should not include the package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public GraphicsPrimitiveProxy(Class owner, String relativeClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                                  String methodSignature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                                  int primID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                  SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                  CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                                  SurfaceType dsttype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super(methodSignature, primID, srctype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.owner = owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this.relativeClassName = relativeClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public GraphicsPrimitive makePrimitive(SurfaceType srctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                           CompositeType comptype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                           SurfaceType dsttype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        // This should never happen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        throw new InternalError("makePrimitive called on a Proxy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Come up with the real instance.  Called from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // GraphicsPrimitiveMgr.locate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    GraphicsPrimitive instantiate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        String name = getPackageName(owner.getName()) + "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                        + relativeClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            Class clazz = Class.forName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            GraphicsPrimitive p = (GraphicsPrimitive) clazz.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (!satisfiesSameAs(p)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                throw new RuntimeException("Primitive " + p
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                           + " incompatible with proxy for "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                           + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        } catch (ClassNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new RuntimeException(ex.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } catch (InstantiationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw new RuntimeException(ex.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        } catch (IllegalAccessException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            throw new RuntimeException(ex.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        // A RuntimeException should never happen in a deployed JDK, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        // the regression test GraphicsPrimitiveProxyTest will catch any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        // of these errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static String getPackageName(String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        int lastDotIdx = className.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (lastDotIdx < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return className.substring(0, lastDotIdx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public GraphicsPrimitive traceWrap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return instantiate().traceWrap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
}