| 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..78fbc38ff4969218b5c3074a257f2f0ac901d4f3
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/platform/graphics/GraphicsScreen.cpp
|
| @@ -0,0 +1,174 @@
|
| +// 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 "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);
|
| + }
|
| +
|
| + PassRefPtr<ColorSpaceProfile> sRGBColorProfile() const
|
| + {
|
| + return m_srgbColorProfile;
|
| + }
|
| +
|
| + void set(uintptr_t id, PassRefPtr<ColorSpaceProfile> profile)
|
| + {
|
| + RELEASE_ASSERT(!ScreenDevice::isDefaultDeviceId(id)); // You cannot reset default profiles.
|
| +
|
| + RELEASE_ASSERT(profile->profile());
|
| +
|
| + m_colorProfiles.set(id, profile);
|
| + }
|
| +
|
| + PassRefPtr<ColorSpaceProfile> find(uintptr_t id) const
|
| + {
|
| + if (ScreenDevice::isSRGBDeviceId(id))
|
| + return sRGBColorProfile();
|
| +
|
| + HashMap<uintptr_t, RefPtr<ColorSpaceProfile>>::const_iterator it = m_colorProfiles.find(id);
|
| + return it != m_colorProfiles.end() ? it->value : nullptr;
|
| + }
|
| +
|
| + void remove(uintptr_t id)
|
| + {
|
| + RELEASE_ASSERT(!ScreenDevice::isDefaultDeviceId(id)); // You cannot remove default profiles.
|
| +
|
| + m_colorProfiles.remove(id);
|
| + }
|
| +
|
| +private:
|
| + HashMap<uintptr_t, RefPtr<ColorSpaceProfile>> m_colorProfiles;
|
| +
|
| + RefPtr<ColorSpaceProfile> m_srgbColorProfile;
|
| +};
|
| +
|
| +static ColorProfileCache& screenColorProfileCache()
|
| +{
|
| + DEFINE_STATIC_LOCAL(ColorProfileCache, cache, ());
|
| + RELEASE_ASSERT(isMainThread());
|
| + return cache;
|
| +}
|
| +
|
| +static bool invalidRGBColorProfile(qcms_profile* deviceProfile)
|
| +{
|
| + if (rgbData != qcms_profile_get_color_space(deviceProfile))
|
| + return true;
|
| +
|
| + if (qcms_profile_is_bogus(deviceProfile))
|
| + return true;
|
| +
|
| + RefPtr<ColorSpaceProfile> source = screenColorProfileCache().sRGBColorProfile();
|
| +
|
| + qcms_transform* transform = qcms_transform_create(source->profile(), QCMS_DATA_RGBA_8, deviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL);
|
| + if (!transform)
|
| + return true;
|
| +
|
| + bool usable = qcms_transform_is_matrix(transform);
|
| + qcms_transform_release(transform);
|
| +
|
| + return !usable;
|
| +}
|
| +
|
| +void setScreenColorProfile(uintptr_t id, const char* profile, size_t size)
|
| +{
|
| + const size_t minimumColorProfileSize = 128;
|
| +
|
| + qcms_profile* deviceProfile = nullptr;
|
| +
|
| + if (profile && size > minimumColorProfileSize)
|
| + 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(uintptr_t id)
|
| +{
|
| + if (!imageColorProfilesEnabled())
|
| + return nullptr;
|
| +
|
| + return screenColorProfileCache().find(id);
|
| +}
|
| +
|
| +void removeScreenColorProfile(uintptr_t id)
|
| +{
|
| + screenColorProfileCache().remove(id);
|
| +}
|
| +
|
| +bool imageColorProfilesEnabled()
|
| +{
|
| + return RuntimeEnabledFeatures::imageColorProfilesEnabled();
|
| +}
|
| +
|
| +#else
|
| +
|
| +void setScreenColorProfile(uintptr_t, const char*, size_t)
|
| +{
|
| +}
|
| +
|
| +PassRefPtr<ColorSpaceProfile> screenColorProfile(uintptr_t)
|
| +{
|
| + return nullptr;
|
| +}
|
| +
|
| +void removeScreenColorProfile(uintptr_t)
|
| +{
|
| +}
|
| +
|
| +bool imageColorProfilesEnabled()
|
| +{
|
| + return false;
|
| +}
|
| +
|
| +#endif // USE(QCMSLIB)
|
| +
|
| +static uintptr_t s_screenId;
|
| +
|
| +uintptr_t setCurrentScreenId(uintptr_t id)
|
| +{
|
| + uintptr_t previous = s_screenId;
|
| + s_screenId = id;
|
| + return previous;
|
| +}
|
| +
|
| +uintptr_t currentScreenId()
|
| +{
|
| + return s_screenId;
|
| +}
|
| +
|
| +} // namespace blink
|
|
|