| Index: third_party/WebKit/Source/platform/graphics/GraphicsScreen.cpp | 
| diff --git a/third_party/WebKit/Source/platform/graphics/GraphicsScreen.cpp b/third_party/WebKit/Source/platform/graphics/GraphicsScreen.cpp | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..ab7fbe3d1f459628036ed605920e6334a6818bae | 
| --- /dev/null | 
| +++ b/third_party/WebKit/Source/platform/graphics/GraphicsScreen.cpp | 
| @@ -0,0 +1,155 @@ | 
| +// Copyright 2015 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "config.h" | 
| +#include "platform/graphics/GraphicsScreen.h" | 
| + | 
| +#include "platform/PlatformExport.h" | 
| +#include "platform/RuntimeEnabledFeatures.h" | 
| +#include "platform/graphics/ColorSpaceProfile.h" | 
| +#include "wtf/HashMap.h" | 
| +#include "wtf/MainThread.h" | 
| +#include "wtf/text/WTFString.h" | 
| + | 
| +namespace blink { | 
| + | 
| +#if USE(QCMSLIB) | 
| + | 
| +class ColorProfileCache { | 
| +public: | 
| +    ColorProfileCache() | 
| +    { | 
| +        qcms_profile* srgbColorProfile = qcms_profile_sRGB(); | 
| + | 
| +        if (srgbColorProfile) | 
| +            qcms_profile_precache_output_transform(srgbColorProfile); | 
| + | 
| +        RELEASE_ASSERT(srgbColorProfile); | 
| + | 
| +        m_srgbColorProfile = ColorSpaceProfile::create(srgbColorProfile); | 
| +    } | 
| + | 
| +    void set(int64_t id, PassRefPtr<ColorSpaceProfile> profile) | 
| +    { | 
| +        RELEASE_ASSERT(id && profile->profile()); | 
| + | 
| +        m_colorProfiles.set(id, profile); | 
| +    } | 
| + | 
| +    PassRefPtr<ColorSpaceProfile> find(int64_t id) const | 
| +    { | 
| +        if (!id) | 
| +            return m_srgbColorProfile; | 
| + | 
| +        HashMap<int64_t, RefPtr<ColorSpaceProfile>>::const_iterator it = m_colorProfiles.find(id); | 
| +        return it != m_colorProfiles.end() ? it->value : nullptr; | 
| +    } | 
| + | 
| +    void remove(int64_t id) | 
| +    { | 
| +        RELEASE_ASSERT(id); | 
| + | 
| +        m_colorProfiles.remove(id); | 
| +    } | 
| + | 
| +private: | 
| +    HashMap<int64_t, RefPtr<ColorSpaceProfile>> m_colorProfiles; | 
| + | 
| +    RefPtr<ColorSpaceProfile> m_srgbColorProfile; | 
| +}; | 
| + | 
| +static ColorProfileCache& screenColorProfileCache() | 
| +{ | 
| +    DEFINE_STATIC_LOCAL(ColorProfileCache, cache, ()); | 
| +    RELEASE_ASSERT(isMainThread()); | 
| +    return cache; | 
| +} | 
| + | 
| +inline bool invalidRGBColorProfile(qcms_profile* deviceProfile) | 
| +{ | 
| +    return rgbData != qcms_profile_get_color_space(deviceProfile) || qcms_profile_is_bogus(deviceProfile); | 
| +} | 
| + | 
| +void setScreenColorProfile(int64_t id, const char* profile, size_t size) | 
| +{ | 
| +    const size_t kMinimumColorProfileSize = 128; | 
| + | 
| +    qcms_profile* deviceProfile = nullptr; | 
| + | 
| +    if (profile && size > kMinimumColorProfileSize) | 
| +        deviceProfile = qcms_profile_from_memory(profile, size); | 
| + | 
| +    if (deviceProfile && invalidRGBColorProfile(deviceProfile)) { | 
| +        qcms_profile_release(deviceProfile); | 
| +        deviceProfile = nullptr; | 
| +    } | 
| + | 
| +    if (!deviceProfile) | 
| +        deviceProfile = qcms_profile_sRGB(); | 
| + | 
| +    if (deviceProfile) | 
| +        qcms_profile_precache_output_transform(deviceProfile); | 
| + | 
| +    fprintf(stderr, "setScreenColorProfile [%s] page %ld\n", deviceProfile ? qcms_profile_get_description(deviceProfile) : "(null profile)", (long int)id); | 
| + | 
| +    screenColorProfileCache().set(id, ColorSpaceProfile::create(deviceProfile)); | 
| +} | 
| + | 
| +PassRefPtr<ColorSpaceProfile> screenColorProfile(int64_t id) | 
| +{ | 
| +    if (!imageColorProfilesEnabled()) | 
| +        return nullptr; | 
| + | 
| +    return screenColorProfileCache().find(id); | 
| +} | 
| + | 
| +void removeScreenColorProfile(int64_t id) | 
| +{ | 
| +    screenColorProfileCache().remove(id); | 
| + | 
| +    RELEASE_ASSERT(!screenColorProfile(id).get()); | 
| +} | 
| + | 
| +bool imageColorProfilesEnabled() | 
| +{ | 
| +    return RuntimeEnabledFeatures::imageColorProfilesEnabled(); | 
| +} | 
| + | 
| +#else | 
| + | 
| +void setScreenColorProfile(int64_t, const char*, size_t) | 
| +{ | 
| +} | 
| + | 
| +PassRefPtr<ColorSpaceProfile> screenColorProfile(int64_t) | 
| +{ | 
| +    return nullptr; | 
| +} | 
| + | 
| +void removeScreenColorProfile(int64_t) | 
| +{ | 
| +} | 
| + | 
| +bool imageColorProfilesEnabled() | 
| +{ | 
| +    return false; | 
| +} | 
| + | 
| +#endif // USE(QCMSLIB) | 
| + | 
| +static int64_t s_screenId; | 
| + | 
| +int64_t currentScreenId() | 
| +{ | 
| +    return s_screenId; | 
| +} | 
| + | 
| +int64_t setCurrentScreenId(int64_t id) | 
| +{ | 
| +    int64_t previous = s_screenId; | 
| +    s_screenId = id; | 
| +    return previous; | 
| +} | 
| + | 
| +} // namespace blink | 
|  |