Path: blob/master/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMSProfile.java
41161 views
/*1* Copyright (c) 2013, 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.cmm.lcms;2627import java.util.Map;28import java.util.concurrent.ConcurrentHashMap;29import java.util.concurrent.locks.StampedLock;3031import sun.java2d.cmm.Profile;3233final class LCMSProfile extends Profile {3435private final Object disposerReferent;36private final Map<Integer, byte[]> tags = new ConcurrentHashMap<>();37private final StampedLock lock = new StampedLock();3839LCMSProfile(long ptr, Object ref) {40super(ptr);41disposerReferent = ref;42}4344long getLcmsPtr() {45return getNativePtr();46}4748byte[] getProfileData() {49long stamp = lock.readLock();50try {51return LCMS.getProfileDataNative(getNativePtr());52} finally {53lock.unlockRead(stamp);54}55}5657byte[] getTag(int sig) {58byte[] t = tags.get(sig);59if (t != null) {60return t;61}62long stamp = lock.readLock();63try {64return tags.computeIfAbsent(sig, (key) -> {65return LCMS.getTagNative(getNativePtr(), key);66});67} finally {68lock.unlockRead(stamp);69}70}7172void setTag(int tagSignature, byte[] data) {73long stamp = lock.writeLock();74try {75tags.clear();76// Now we are going to update the profile with new tag data77// In some cases, we may change the pointer to the native profile.78//79// If we fail to write tag data for any reason, the old pointer80// should be used.81LCMS.setTagDataNative(getNativePtr(), tagSignature, data);82} finally {83lock.unlockWrite(stamp);84}85}86}878889