| 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 "config.h" | 
|  | 6 #include "platform/graphics/GraphicsScreen.h" | 
|  | 7 | 
|  | 8 #include "platform/PlatformExport.h" | 
|  | 9 #include "platform/RuntimeEnabledFeatures.h" | 
|  | 10 #include "platform/graphics/ColorSpaceProfile.h" | 
|  | 11 #include "wtf/HashMap.h" | 
|  | 12 #include "wtf/MainThread.h" | 
|  | 13 #include "wtf/text/WTFString.h" | 
|  | 14 | 
|  | 15 namespace blink { | 
|  | 16 | 
|  | 17 #if USE(QCMSLIB) | 
|  | 18 | 
|  | 19 class ColorProfileCache { | 
|  | 20 public: | 
|  | 21     ColorProfileCache() | 
|  | 22     { | 
|  | 23         qcms_profile* srgbColorProfile = qcms_profile_sRGB(); | 
|  | 24 | 
|  | 25         if (srgbColorProfile) | 
|  | 26             qcms_profile_precache_output_transform(srgbColorProfile); | 
|  | 27 | 
|  | 28         RELEASE_ASSERT(srgbColorProfile); | 
|  | 29 | 
|  | 30         m_srgbColorProfile = ColorSpaceProfile::create(srgbColorProfile); | 
|  | 31     } | 
|  | 32 | 
|  | 33     void set(int64_t id, PassRefPtr<ColorSpaceProfile> profile) | 
|  | 34     { | 
|  | 35         RELEASE_ASSERT(id && profile->profile()); | 
|  | 36 | 
|  | 37         m_colorProfiles.set(id, profile); | 
|  | 38     } | 
|  | 39 | 
|  | 40     PassRefPtr<ColorSpaceProfile> find(int64_t id) const | 
|  | 41     { | 
|  | 42         if (!id) | 
|  | 43             return m_srgbColorProfile; | 
|  | 44 | 
|  | 45         HashMap<int64_t, RefPtr<ColorSpaceProfile>>::const_iterator it = m_color
     Profiles.find(id); | 
|  | 46         return it != m_colorProfiles.end() ? it->value : nullptr; | 
|  | 47     } | 
|  | 48 | 
|  | 49     void remove(int64_t id) | 
|  | 50     { | 
|  | 51         RELEASE_ASSERT(id); | 
|  | 52 | 
|  | 53         m_colorProfiles.remove(id); | 
|  | 54     } | 
|  | 55 | 
|  | 56 private: | 
|  | 57     HashMap<int64_t, RefPtr<ColorSpaceProfile>> m_colorProfiles; | 
|  | 58 | 
|  | 59     RefPtr<ColorSpaceProfile> m_srgbColorProfile; | 
|  | 60 }; | 
|  | 61 | 
|  | 62 static ColorProfileCache& screenColorProfileCache() | 
|  | 63 { | 
|  | 64     DEFINE_STATIC_LOCAL(ColorProfileCache, cache, ()); | 
|  | 65     RELEASE_ASSERT(isMainThread()); | 
|  | 66     return cache; | 
|  | 67 } | 
|  | 68 | 
|  | 69 inline bool invalidRGBColorProfile(qcms_profile* deviceProfile) | 
|  | 70 { | 
|  | 71     return rgbData != qcms_profile_get_color_space(deviceProfile) || qcms_profil
     e_is_bogus(deviceProfile); | 
|  | 72 } | 
|  | 73 | 
|  | 74 void setScreenColorProfile(int64_t id, const char* profile, size_t size) | 
|  | 75 { | 
|  | 76     const size_t kMinimumColorProfileSize = 128; | 
|  | 77 | 
|  | 78     qcms_profile* deviceProfile = nullptr; | 
|  | 79 | 
|  | 80     if (profile && size > kMinimumColorProfileSize) | 
|  | 81         deviceProfile = qcms_profile_from_memory(profile, size); | 
|  | 82 | 
|  | 83     if (deviceProfile && invalidRGBColorProfile(deviceProfile)) { | 
|  | 84         qcms_profile_release(deviceProfile); | 
|  | 85         deviceProfile = nullptr; | 
|  | 86     } | 
|  | 87 | 
|  | 88     if (!deviceProfile) | 
|  | 89         deviceProfile = qcms_profile_sRGB(); | 
|  | 90 | 
|  | 91     if (deviceProfile) | 
|  | 92         qcms_profile_precache_output_transform(deviceProfile); | 
|  | 93 | 
|  | 94     fprintf(stderr, "setScreenColorProfile [%s] page %ld\n", deviceProfile ? qcm
     s_profile_get_description(deviceProfile) : "(null profile)", (long int)id); | 
|  | 95 | 
|  | 96     screenColorProfileCache().set(id, ColorSpaceProfile::create(deviceProfile)); | 
|  | 97 } | 
|  | 98 | 
|  | 99 PassRefPtr<ColorSpaceProfile> screenColorProfile(int64_t id) | 
|  | 100 { | 
|  | 101     if (!imageColorProfilesEnabled()) | 
|  | 102         return nullptr; | 
|  | 103 | 
|  | 104     return screenColorProfileCache().find(id); | 
|  | 105 } | 
|  | 106 | 
|  | 107 void removeScreenColorProfile(int64_t id) | 
|  | 108 { | 
|  | 109     screenColorProfileCache().remove(id); | 
|  | 110 | 
|  | 111     RELEASE_ASSERT(!screenColorProfile(id).get()); | 
|  | 112 } | 
|  | 113 | 
|  | 114 bool imageColorProfilesEnabled() | 
|  | 115 { | 
|  | 116     return RuntimeEnabledFeatures::imageColorProfilesEnabled(); | 
|  | 117 } | 
|  | 118 | 
|  | 119 #else | 
|  | 120 | 
|  | 121 void setScreenColorProfile(int64_t, const char*, size_t) | 
|  | 122 { | 
|  | 123 } | 
|  | 124 | 
|  | 125 PassRefPtr<ColorSpaceProfile> screenColorProfile(int64_t) | 
|  | 126 { | 
|  | 127     return nullptr; | 
|  | 128 } | 
|  | 129 | 
|  | 130 void removeScreenColorProfile(int64_t) | 
|  | 131 { | 
|  | 132 } | 
|  | 133 | 
|  | 134 bool imageColorProfilesEnabled() | 
|  | 135 { | 
|  | 136     return false; | 
|  | 137 } | 
|  | 138 | 
|  | 139 #endif // USE(QCMSLIB) | 
|  | 140 | 
|  | 141 static int64_t s_screenId; | 
|  | 142 | 
|  | 143 int64_t currentScreenId() | 
|  | 144 { | 
|  | 145     return s_screenId; | 
|  | 146 } | 
|  | 147 | 
|  | 148 int64_t setCurrentScreenId(int64_t id) | 
|  | 149 { | 
|  | 150     int64_t previous = s_screenId; | 
|  | 151     s_screenId = id; | 
|  | 152     return previous; | 
|  | 153 } | 
|  | 154 | 
|  | 155 } // namespace blink | 
| OLD | NEW | 
|---|