Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/java2d/loops/GraphicsPrimitiveProxy.java
41159 views
1
/*
2
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.java2d.loops;
27
28
/**
29
* GraphicsPrimitiveProxy
30
*
31
* Acts as a proxy for instances of GraphicsPrimitive, enabling lazy
32
* classloading of these primitives. This leads to a substantial
33
* savings in start-up time and footprint. In the typical case,
34
* it has been found that a small number of GraphicsPrimitive instance
35
* actually end up getting instantiated.
36
* <p>
37
* Note that the makePrimitive method should never be invoked on
38
* a GraphicsPrimitiveProxy object since they are instantiated as
39
* soon as they are found in the primitive list and never returned
40
* to the caller.
41
*/
42
public class GraphicsPrimitiveProxy extends GraphicsPrimitive {
43
44
private Class<?> owner;
45
private String relativeClassName;
46
47
/**
48
* Create a GraphicsPrimitiveProxy for a primitive with a no-argument
49
* constructor.
50
*
51
* @param owner The owner class for this primitive. The primitive
52
* must be in the same package as this owner.
53
* @param relativeClassName The name of the class this is a proxy for.
54
* This should not include the package.
55
*/
56
public GraphicsPrimitiveProxy(Class<?> owner, String relativeClassName,
57
String methodSignature,
58
int primID,
59
SurfaceType srctype,
60
CompositeType comptype,
61
SurfaceType dsttype)
62
{
63
super(methodSignature, primID, srctype, comptype, dsttype);
64
this.owner = owner;
65
this.relativeClassName = relativeClassName;
66
}
67
68
//
69
// Come up with the real instance. Called from
70
// GraphicsPrimitiveMgr.locate()
71
//
72
GraphicsPrimitive instantiate() {
73
String name = getPackageName(owner.getName()) + "."
74
+ relativeClassName;
75
try {
76
Class<?> clazz = Class.forName(name);
77
GraphicsPrimitive p =
78
(GraphicsPrimitive) clazz.getDeclaredConstructor().newInstance();
79
if (!satisfiesSameAs(p)) {
80
throw new RuntimeException("Primitive " + p
81
+ " incompatible with proxy for "
82
+ name);
83
}
84
return p;
85
} catch (ReflectiveOperationException ex) {
86
throw new RuntimeException(ex.toString());
87
}
88
// A RuntimeException should never happen in a deployed JDK, because
89
// the regression test GraphicsPrimitiveProxyTest will catch any
90
// of these errors.
91
}
92
93
private static String getPackageName(String className) {
94
int lastDotIdx = className.lastIndexOf('.');
95
if (lastDotIdx < 0) {
96
return className;
97
}
98
return className.substring(0, lastDotIdx);
99
}
100
101
public GraphicsPrimitive traceWrap() {
102
return instantiate().traceWrap();
103
}
104
}
105
106