Path: blob/master/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitiveProxy.java
41159 views
/*1* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.loops;2627/**28* GraphicsPrimitiveProxy29*30* Acts as a proxy for instances of GraphicsPrimitive, enabling lazy31* classloading of these primitives. This leads to a substantial32* savings in start-up time and footprint. In the typical case,33* it has been found that a small number of GraphicsPrimitive instance34* actually end up getting instantiated.35* <p>36* Note that the makePrimitive method should never be invoked on37* a GraphicsPrimitiveProxy object since they are instantiated as38* soon as they are found in the primitive list and never returned39* to the caller.40*/41public class GraphicsPrimitiveProxy extends GraphicsPrimitive {4243private Class<?> owner;44private String relativeClassName;4546/**47* Create a GraphicsPrimitiveProxy for a primitive with a no-argument48* constructor.49*50* @param owner The owner class for this primitive. The primitive51* must be in the same package as this owner.52* @param relativeClassName The name of the class this is a proxy for.53* This should not include the package.54*/55public GraphicsPrimitiveProxy(Class<?> owner, String relativeClassName,56String methodSignature,57int primID,58SurfaceType srctype,59CompositeType comptype,60SurfaceType dsttype)61{62super(methodSignature, primID, srctype, comptype, dsttype);63this.owner = owner;64this.relativeClassName = relativeClassName;65}6667//68// Come up with the real instance. Called from69// GraphicsPrimitiveMgr.locate()70//71GraphicsPrimitive instantiate() {72String name = getPackageName(owner.getName()) + "."73+ relativeClassName;74try {75Class<?> clazz = Class.forName(name);76GraphicsPrimitive p =77(GraphicsPrimitive) clazz.getDeclaredConstructor().newInstance();78if (!satisfiesSameAs(p)) {79throw new RuntimeException("Primitive " + p80+ " incompatible with proxy for "81+ name);82}83return p;84} catch (ReflectiveOperationException ex) {85throw new RuntimeException(ex.toString());86}87// A RuntimeException should never happen in a deployed JDK, because88// the regression test GraphicsPrimitiveProxyTest will catch any89// of these errors.90}9192private static String getPackageName(String className) {93int lastDotIdx = className.lastIndexOf('.');94if (lastDotIdx < 0) {95return className;96}97return className.substring(0, lastDotIdx);98}99100public GraphicsPrimitive traceWrap() {101return instantiate().traceWrap();102}103}104105106