OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/graphics/GraphicsScreen.h" |
| 6 |
| 7 #include "platform/PlatformExport.h" |
| 8 #include "platform/RuntimeEnabledFeatures.h" |
| 9 #include "platform/graphics/ColorSpaceProfile.h" |
| 10 #include "wtf/HashMap.h" |
| 11 #include "wtf/MainThread.h" |
| 12 #include "wtf/text/WTFString.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 #if USE(QCMSLIB) |
| 17 |
| 18 class ColorProfileCache { |
| 19 public: |
| 20 ColorProfileCache() |
| 21 { |
| 22 qcms_profile* srgbColorProfile = qcms_profile_sRGB(); |
| 23 |
| 24 if (srgbColorProfile) |
| 25 qcms_profile_precache_output_transform(srgbColorProfile); |
| 26 |
| 27 RELEASE_ASSERT(srgbColorProfile); |
| 28 |
| 29 m_srgbColorProfile = ColorSpaceProfile::create(srgbColorProfile); |
| 30 } |
| 31 |
| 32 PassRefPtr<ColorSpaceProfile> sRGBColorProfile() const |
| 33 { |
| 34 return m_srgbColorProfile; |
| 35 } |
| 36 |
| 37 void set(uintptr_t id, PassRefPtr<ColorSpaceProfile> profile) |
| 38 { |
| 39 RELEASE_ASSERT(id && profile->profile()); |
| 40 |
| 41 m_colorProfiles.set(id, profile); |
| 42 } |
| 43 |
| 44 PassRefPtr<ColorSpaceProfile> find(uintptr_t id) const |
| 45 { |
| 46 if (!id) |
| 47 return sRGBColorProfile(); |
| 48 |
| 49 HashMap<uintptr_t, RefPtr<ColorSpaceProfile>>::const_iterator it = m_col
orProfiles.find(id); |
| 50 return it != m_colorProfiles.end() ? it->value : nullptr; |
| 51 } |
| 52 |
| 53 void remove(uintptr_t id) |
| 54 { |
| 55 RELEASE_ASSERT(id); // You cannot remove the default sRGB color profile. |
| 56 |
| 57 m_colorProfiles.remove(id); |
| 58 } |
| 59 |
| 60 private: |
| 61 HashMap<uintptr_t, RefPtr<ColorSpaceProfile>> m_colorProfiles; |
| 62 |
| 63 RefPtr<ColorSpaceProfile> m_srgbColorProfile; |
| 64 }; |
| 65 |
| 66 static ColorProfileCache& screenColorProfileCache() |
| 67 { |
| 68 DEFINE_STATIC_LOCAL(ColorProfileCache, cache, ()); |
| 69 RELEASE_ASSERT(isMainThread()); |
| 70 return cache; |
| 71 } |
| 72 |
| 73 static bool invalidRGBColorProfile(qcms_profile* deviceProfile) |
| 74 { |
| 75 if (rgbData != qcms_profile_get_color_space(deviceProfile)) |
| 76 return true; |
| 77 |
| 78 if (qcms_profile_is_bogus(deviceProfile)) |
| 79 return true; |
| 80 |
| 81 RefPtr<ColorSpaceProfile> source = screenColorProfileCache().sRGBColorProfil
e(); |
| 82 |
| 83 qcms_transform* transform = qcms_transform_create(source->profile(), QCMS_DA
TA_RGBA_8, deviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL); |
| 84 if (!transform) |
| 85 return true; |
| 86 |
| 87 bool usable = qcms_transform_is_matrix(transform); |
| 88 qcms_transform_release(transform); |
| 89 |
| 90 return !usable; |
| 91 } |
| 92 |
| 93 void setScreenColorProfile(uintptr_t id, const char* profile, size_t size) |
| 94 { |
| 95 const size_t minimumColorProfileSize = 128; |
| 96 |
| 97 qcms_profile* deviceProfile = nullptr; |
| 98 |
| 99 if (profile && size > minimumColorProfileSize) |
| 100 deviceProfile = qcms_profile_from_memory(profile, size); |
| 101 |
| 102 if (deviceProfile && invalidRGBColorProfile(deviceProfile)) { |
| 103 qcms_profile_release(deviceProfile); |
| 104 deviceProfile = nullptr; |
| 105 } |
| 106 |
| 107 if (!deviceProfile) |
| 108 deviceProfile = qcms_profile_sRGB(); |
| 109 |
| 110 if (deviceProfile) |
| 111 qcms_profile_precache_output_transform(deviceProfile); |
| 112 |
| 113 fprintf(stderr, "setScreenColorProfile [%s] page %ld\n", deviceProfile ? qcm
s_profile_get_description(deviceProfile) : "(null profile)", (long int)id); |
| 114 |
| 115 screenColorProfileCache().set(id, ColorSpaceProfile::create(deviceProfile)); |
| 116 } |
| 117 |
| 118 PassRefPtr<ColorSpaceProfile> screenColorProfile(uintptr_t id) |
| 119 { |
| 120 if (!imageColorProfilesEnabled()) |
| 121 return nullptr; |
| 122 |
| 123 return screenColorProfileCache().find(id); |
| 124 } |
| 125 |
| 126 void removeScreenColorProfile(uintptr_t id) |
| 127 { |
| 128 screenColorProfileCache().remove(id); |
| 129 } |
| 130 |
| 131 bool imageColorProfilesEnabled() |
| 132 { |
| 133 return RuntimeEnabledFeatures::imageColorProfilesEnabled(); |
| 134 } |
| 135 |
| 136 #else |
| 137 |
| 138 void setScreenColorProfile(uintptr_t, const char*, size_t) |
| 139 { |
| 140 } |
| 141 |
| 142 PassRefPtr<ColorSpaceProfile> screenColorProfile(uintptr_t) |
| 143 { |
| 144 return nullptr; |
| 145 } |
| 146 |
| 147 void removeScreenColorProfile(uintptr_t) |
| 148 { |
| 149 } |
| 150 |
| 151 bool imageColorProfilesEnabled() |
| 152 { |
| 153 return false; |
| 154 } |
| 155 |
| 156 #endif // USE(QCMSLIB) |
| 157 |
| 158 static uintptr_t s_screenId; |
| 159 |
| 160 uintptr_t setCurrentScreenId(uintptr_t id) |
| 161 { |
| 162 uintptr_t previous = s_screenId; |
| 163 s_screenId = id; |
| 164 return previous; |
| 165 } |
| 166 |
| 167 uintptr_t currentScreenId() |
| 168 { |
| 169 return s_screenId; |
| 170 } |
| 171 |
| 172 } // namespace blink |
OLD | NEW |