Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMSProfile.java
41161 views
1
/*
2
* Copyright (c) 2013, 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.cmm.lcms;
27
28
import java.util.Map;
29
import java.util.concurrent.ConcurrentHashMap;
30
import java.util.concurrent.locks.StampedLock;
31
32
import sun.java2d.cmm.Profile;
33
34
final class LCMSProfile extends Profile {
35
36
private final Object disposerReferent;
37
private final Map<Integer, byte[]> tags = new ConcurrentHashMap<>();
38
private final StampedLock lock = new StampedLock();
39
40
LCMSProfile(long ptr, Object ref) {
41
super(ptr);
42
disposerReferent = ref;
43
}
44
45
long getLcmsPtr() {
46
return getNativePtr();
47
}
48
49
byte[] getProfileData() {
50
long stamp = lock.readLock();
51
try {
52
return LCMS.getProfileDataNative(getNativePtr());
53
} finally {
54
lock.unlockRead(stamp);
55
}
56
}
57
58
byte[] getTag(int sig) {
59
byte[] t = tags.get(sig);
60
if (t != null) {
61
return t;
62
}
63
long stamp = lock.readLock();
64
try {
65
return tags.computeIfAbsent(sig, (key) -> {
66
return LCMS.getTagNative(getNativePtr(), key);
67
});
68
} finally {
69
lock.unlockRead(stamp);
70
}
71
}
72
73
void setTag(int tagSignature, byte[] data) {
74
long stamp = lock.writeLock();
75
try {
76
tags.clear();
77
// Now we are going to update the profile with new tag data
78
// In some cases, we may change the pointer to the native profile.
79
//
80
// If we fail to write tag data for any reason, the old pointer
81
// should be used.
82
LCMS.setTagDataNative(getNativePtr(), tagSignature, data);
83
} finally {
84
lock.unlockWrite(stamp);
85
}
86
}
87
}
88
89