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(!ScreenDevice::isDefaultDeviceId(id)); // You cannot rese
t default profiles. |
| 40 |
| 41 RELEASE_ASSERT(profile->profile()); |
| 42 |
| 43 m_colorProfiles.set(id, profile); |
| 44 } |
| 45 |
| 46 PassRefPtr<ColorSpaceProfile> find(uintptr_t id) const |
| 47 { |
| 48 if (ScreenDevice::isSRGBDeviceId(id)) |
| 49 return sRGBColorProfile(); |
| 50 |
| 51 HashMap<uintptr_t, RefPtr<ColorSpaceProfile>>::const_iterator it = m_col
orProfiles.find(id); |
| 52 return it != m_colorProfiles.end() ? it->value : nullptr; |
| 53 } |
| 54 |
| 55 void remove(uintptr_t id) |
| 56 { |
| 57 RELEASE_ASSERT(!ScreenDevice::isDefaultDeviceId(id)); // You cannot remo
ve default profiles. |
| 58 |
| 59 m_colorProfiles.remove(id); |
| 60 } |
| 61 |
| 62 private: |
| 63 HashMap<uintptr_t, RefPtr<ColorSpaceProfile>> m_colorProfiles; |
| 64 |
| 65 RefPtr<ColorSpaceProfile> m_srgbColorProfile; |
| 66 }; |
| 67 |
| 68 static ColorProfileCache& screenColorProfileCache() |
| 69 { |
| 70 DEFINE_STATIC_LOCAL(ColorProfileCache, cache, ()); |
| 71 RELEASE_ASSERT(isMainThread()); |
| 72 return cache; |
| 73 } |
| 74 |
| 75 static bool invalidRGBColorProfile(qcms_profile* deviceProfile) |
| 76 { |
| 77 if (rgbData != qcms_profile_get_color_space(deviceProfile)) |
| 78 return true; |
| 79 |
| 80 if (qcms_profile_is_bogus(deviceProfile)) |
| 81 return true; |
| 82 |
| 83 RefPtr<ColorSpaceProfile> source = screenColorProfileCache().sRGBColorProfil
e(); |
| 84 |
| 85 qcms_transform* transform = qcms_transform_create(source->profile(), QCMS_DA
TA_RGBA_8, deviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL); |
| 86 if (!transform) |
| 87 return true; |
| 88 |
| 89 bool usable = qcms_transform_is_matrix(transform); |
| 90 qcms_transform_release(transform); |
| 91 |
| 92 return !usable; |
| 93 } |
| 94 |
| 95 void setScreenColorProfile(uintptr_t id, const char* profile, size_t size) |
| 96 { |
| 97 const size_t minimumColorProfileSize = 128; |
| 98 |
| 99 qcms_profile* deviceProfile = nullptr; |
| 100 |
| 101 if (profile && size > minimumColorProfileSize) |
| 102 deviceProfile = qcms_profile_from_memory(profile, size); |
| 103 |
| 104 if (deviceProfile && invalidRGBColorProfile(deviceProfile)) { |
| 105 qcms_profile_release(deviceProfile); |
| 106 deviceProfile = nullptr; |
| 107 } |
| 108 |
| 109 if (!deviceProfile) |
| 110 deviceProfile = qcms_profile_sRGB(); |
| 111 |
| 112 if (deviceProfile) |
| 113 qcms_profile_precache_output_transform(deviceProfile); |
| 114 |
| 115 fprintf(stderr, "setScreenColorProfile [%s] page %ld\n", deviceProfile ? qcm
s_profile_get_description(deviceProfile) : "(null profile)", (long int)id); |
| 116 |
| 117 screenColorProfileCache().set(id, ColorSpaceProfile::create(deviceProfile)); |
| 118 } |
| 119 |
| 120 PassRefPtr<ColorSpaceProfile> screenColorProfile(uintptr_t id) |
| 121 { |
| 122 if (!imageColorProfilesEnabled()) |
| 123 return nullptr; |
| 124 |
| 125 return screenColorProfileCache().find(id); |
| 126 } |
| 127 |
| 128 void removeScreenColorProfile(uintptr_t id) |
| 129 { |
| 130 screenColorProfileCache().remove(id); |
| 131 } |
| 132 |
| 133 bool imageColorProfilesEnabled() |
| 134 { |
| 135 return RuntimeEnabledFeatures::imageColorProfilesEnabled(); |
| 136 } |
| 137 |
| 138 #else |
| 139 |
| 140 void setScreenColorProfile(uintptr_t, const char*, size_t) |
| 141 { |
| 142 } |
| 143 |
| 144 PassRefPtr<ColorSpaceProfile> screenColorProfile(uintptr_t) |
| 145 { |
| 146 return nullptr; |
| 147 } |
| 148 |
| 149 void removeScreenColorProfile(uintptr_t) |
| 150 { |
| 151 } |
| 152 |
| 153 bool imageColorProfilesEnabled() |
| 154 { |
| 155 return false; |
| 156 } |
| 157 |
| 158 #endif // USE(QCMSLIB) |
| 159 |
| 160 static uintptr_t s_screenId; |
| 161 |
| 162 uintptr_t setCurrentScreenId(uintptr_t id) |
| 163 { |
| 164 uintptr_t previous = s_screenId; |
| 165 s_screenId = id; |
| 166 return previous; |
| 167 } |
| 168 |
| 169 uintptr_t currentScreenId() |
| 170 { |
| 171 return s_screenId; |
| 172 } |
| 173 |
| 174 } // namespace blink |
OLD | NEW |