OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "platform/graphics/GraphicsScreen.h" |
| 33 |
| 34 #include "platform/graphics/ColorSpaceProfile.h" |
| 35 #include "wtf/HashMap.h" |
| 36 #include "wtf/ThreadingPrimitives.h" |
| 37 |
| 38 namespace WebCore { |
| 39 |
| 40 #if USE(QCMSLIB) |
| 41 |
| 42 class ColorProfileCache { |
| 43 public: |
| 44 void set(long long id, PassRefPtr<ColorSpaceProfile> profile) |
| 45 { |
| 46 MutexLocker locker(m_lock); |
| 47 m_colorProfiles.set(id, profile); |
| 48 } |
| 49 |
| 50 PassRefPtr<ColorSpaceProfile> find(long long id) |
| 51 { |
| 52 MutexLocker locker(m_lock); |
| 53 HashMap<long long, RefPtr<ColorSpaceProfile> >::iterator it = m_colorPro
files.find(id); |
| 54 return it != m_colorProfiles.end() ? it->value : nullptr; |
| 55 } |
| 56 |
| 57 void remove(long long id) |
| 58 { |
| 59 MutexLocker locker(m_lock); |
| 60 m_colorProfiles.remove(id); |
| 61 } |
| 62 |
| 63 private: |
| 64 HashMap<long long, RefPtr<ColorSpaceProfile> > m_colorProfiles; |
| 65 Mutex m_lock; |
| 66 }; |
| 67 |
| 68 static ColorProfileCache& screenColorProfiles() |
| 69 { |
| 70 static ColorProfileCache* cache = new ColorProfileCache(); |
| 71 return *cache; |
| 72 } |
| 73 |
| 74 inline bool invalidRGBColorSpaceProfile(qcms_profile* deviceProfile) |
| 75 { |
| 76 return icSigRgbData != qcms_profile_get_color_space(deviceProfile) || qcms_p
rofile_is_bogus(deviceProfile); |
| 77 } |
| 78 |
| 79 void setScreenColorProfile(long long id, const char* profile, size_t size) |
| 80 { |
| 81 const size_t kMinimumColorProfileSize = 128; |
| 82 |
| 83 qcms_profile* deviceProfile = 0; |
| 84 |
| 85 if (profile && size > kMinimumColorProfileSize) |
| 86 deviceProfile = qcms_profile_from_memory(profile, size); |
| 87 |
| 88 if (deviceProfile && invalidRGBColorSpaceProfile(deviceProfile)) { |
| 89 qcms_profile_release(deviceProfile); |
| 90 deviceProfile = 0; |
| 91 } |
| 92 |
| 93 if (!deviceProfile) |
| 94 deviceProfile = qcms_profile_sRGB(); |
| 95 |
| 96 if (deviceProfile) |
| 97 qcms_profile_precache_output_transform(deviceProfile); |
| 98 |
| 99 screenColorProfiles().set(id, ColorSpaceProfile::create(deviceProfile)); |
| 100 } |
| 101 |
| 102 PassRefPtr<ColorSpaceProfile> screenColorProfile(long long id) |
| 103 { |
| 104 return screenColorProfiles().find(id); |
| 105 } |
| 106 |
| 107 void removeScreenColorProfile(long long id) |
| 108 { |
| 109 screenColorProfiles().remove(id); |
| 110 } |
| 111 |
| 112 #else |
| 113 |
| 114 void setScreenColorProfile(long long, const char*, size_t) |
| 115 { |
| 116 } |
| 117 |
| 118 PassRefPtr<ColorSpaceProfile> screenColorProfile(long long) |
| 119 { |
| 120 return nullptr; |
| 121 } |
| 122 |
| 123 void removeScreenColorProfile(long long) |
| 124 { |
| 125 } |
| 126 |
| 127 #endif // USE(QCMSLIB) |
| 128 |
| 129 static long long gScreenId = 0; |
| 130 |
| 131 void setCurrentScreenId(long long id) |
| 132 { |
| 133 gScreenId = id; |
| 134 } |
| 135 |
| 136 long long currentScreenId() |
| 137 { |
| 138 return gScreenId; |
| 139 } |
| 140 |
| 141 } // namespace WebCore |
OLD | NEW |