Diff
Modified: trunk/Source/WebCore/CMakeLists.txt (287305 => 287306)
--- trunk/Source/WebCore/CMakeLists.txt 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/CMakeLists.txt 2021-12-21 10:06:10 UTC (rev 287306)
@@ -1966,6 +1966,14 @@
endif ()
if (USE_LCMS)
+ list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES
+ "${WEBCORE_DIR}/platform/graphics/lcms"
+ )
+
+ list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
+ platform/graphics/lcms/LCMSUniquePtr.h
+ )
+
list(APPEND WebCore_LIBRARIES LCMS2::LCMS2)
endif ()
Modified: trunk/Source/WebCore/ChangeLog (287305 => 287306)
--- trunk/Source/WebCore/ChangeLog 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/ChangeLog 2021-12-21 10:06:10 UTC (rev 287306)
@@ -1,3 +1,34 @@
+2021-12-21 Yoshiaki Jitsukawa <[email protected]>
+
+ [LCMS] Use std::unqiue_ptr to retain LCMS objects
+ https://bugs.webkit.org/show_bug.cgi?id=234506
+
+ Reviewed by Michael Catanzaro.
+
+ * platform/graphics/lcms/LCMSUniquePtr.h: Added.
+ Add LCMSUniquePtr.h and specialize std::unique_ptr with deleters.
+ LCMSProfilePtr is for cmsHPROFILE with cmsCloseProfile() as the deleter.
+ LCMSTransformPtr is for cmsHTRANSFORM with cmsDeleteTransform() as the deleter.
+
+ * CMakeLists.txt:
+ Add WebCore/platform/graphics/lcms to WebCore_PRIVATE_INCLUDE_DIRECTORIES.
+ Add LCMSUniquePtr.h to WebCore_PRIVATE_FRAMEWORK_HEADERS.
+
+ * platform/graphics/PlatformDisplay.cpp:
+ * platform/graphics/PlatformDisplay.h:
+ * platform/graphics/x11/PlatformDisplayX11.cpp:
+ Use LCMSProfilePtr to retain ICC Profile.
+
+ * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
+ * platform/image-decoders/jpeg/JPEGImageDecoder.h:
+ * platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp:
+ * platform/image-decoders/jpegxl/JPEGXLImageDecoder.h:
+ * platform/image-decoders/png/PNGImageDecoder.cpp:
+ * platform/image-decoders/png/PNGImageDecoder.h:
+ Use LCMSProfilePtr to retain color transform.
+ Remove the m_iccProfile class member because m_iccTransform also retains a
+ reference to the LCMS's profile and m_iccProfile can be removed.
+
2021-12-21 Carlos Garcia Campos <[email protected]>
[GTK][a11y] Implement list markers when building with ATSPI
Modified: trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp (287305 => 287306)
--- trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/graphics/PlatformDisplay.cpp 2021-12-21 10:06:10 UTC (rev 287306)
@@ -80,10 +80,6 @@
#include <wtf/NeverDestroyed.h>
#endif
-#if USE(LCMS)
-#include <lcms2.h>
-#endif
-
#if USE(ATSPI)
#include <wtf/glib/GUniquePtr.h>
#endif
@@ -189,10 +185,6 @@
#endif
if (s_sharedDisplayForCompositing == this)
s_sharedDisplayForCompositing = nullptr;
-#if USE(LCMS)
- if (m_iccProfile)
- cmsCloseProfile(m_iccProfile);
-#endif
}
#if USE(EGL) || USE(GLX)
@@ -292,8 +284,8 @@
cmsHPROFILE PlatformDisplay::colorProfile() const
{
if (!m_iccProfile)
- m_iccProfile = cmsCreate_sRGBProfile();
- return m_iccProfile;
+ m_iccProfile = LCMSProfilePtr(cmsCreate_sRGBProfile());
+ return m_iccProfile.get();
}
#endif
Modified: trunk/Source/WebCore/platform/graphics/PlatformDisplay.h (287305 => 287306)
--- trunk/Source/WebCore/platform/graphics/PlatformDisplay.h 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/graphics/PlatformDisplay.h 2021-12-21 10:06:10 UTC (rev 287306)
@@ -41,7 +41,7 @@
#endif // ENABLE(VIDEO) && USE(GSTREAMER_GL)
#if USE(LCMS)
-typedef void* cmsHPROFILE;
+#include "LCMSUniquePtr.h"
#endif
namespace WebCore {
@@ -114,7 +114,7 @@
#endif
#if USE(LCMS)
- mutable cmsHPROFILE m_iccProfile { nullptr };
+ mutable LCMSProfilePtr m_iccProfile;
#endif
#if USE(ATSPI)
Added: trunk/Source/WebCore/platform/graphics/lcms/LCMSUniquePtr.h (0 => 287306)
--- trunk/Source/WebCore/platform/graphics/lcms/LCMSUniquePtr.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/lcms/LCMSUniquePtr.h 2021-12-21 10:06:10 UTC (rev 287306)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2021 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <lcms2.h>
+#include <memory>
+
+namespace WebCore {
+
+// Specializing unique_ptr for:
+// typedef void* cmsHPROFILE;
+// typedef void* cmsHTRANSFORM;
+
+struct LCMSProfileDeleter {
+ void operator() (cmsHPROFILE ptr) const
+ {
+ if (ptr)
+ cmsCloseProfile(ptr);
+ }
+};
+using LCMSProfilePtr = std::unique_ptr<void, LCMSProfileDeleter>;
+
+struct LCMSTransformDeleter {
+ void operator() (cmsHTRANSFORM ptr) const
+ {
+ if (ptr)
+ cmsDeleteTransform(ptr);
+ }
+};
+using LCMSTransformPtr = std::unique_ptr<void, LCMSTransformDeleter>;
+
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp (287305 => 287306)
--- trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/graphics/x11/PlatformDisplayX11.cpp 2021-12-21 10:06:10 UTC (rev 287306)
@@ -47,10 +47,6 @@
#include <GL/glx.h>
#endif
-#if USE(LCMS)
-#include <lcms2.h>
-#endif
-
namespace WebCore {
std::unique_ptr<PlatformDisplay> PlatformDisplayX11::create()
@@ -185,7 +181,7 @@
cmsHPROFILE PlatformDisplayX11::colorProfile() const
{
if (m_iccProfile)
- return m_iccProfile;
+ return m_iccProfile.get();
Atom iccAtom = XInternAtom(m_display, "_ICC_PROFILE", False);
Atom type;
@@ -211,13 +207,13 @@
}
if (dataSize)
- m_iccProfile = cmsOpenProfileFromMem(data, dataSize);
+ m_iccProfile = LCMSProfilePtr(cmsOpenProfileFromMem(data, dataSize));
}
if (data)
XFree(data);
- return m_iccProfile ? m_iccProfile : PlatformDisplay::colorProfile();
+ return m_iccProfile ? m_iccProfile.get() : PlatformDisplay::colorProfile();
}
#endif
Modified: trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp (287305 => 287306)
--- trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp 2021-12-21 10:06:10 UTC (rev 287306)
@@ -41,9 +41,6 @@
#include "JPEGImageDecoder.h"
#include "PlatformDisplay.h"
-#if USE(LCMS)
-#include <lcms2.h>
-#endif
extern "C" {
#include <setjmp.h>
@@ -571,14 +568,7 @@
{
m_reader = nullptr;
#if USE(LCMS)
- if (m_iccTransform) {
- cmsDeleteTransform(m_iccTransform);
- m_iccTransform = nullptr;
- }
- if (m_iccProfile) {
- cmsCloseProfile(m_iccProfile);
- m_iccProfile = nullptr;
- }
+ m_iccTransform.reset();
#endif
}
@@ -637,7 +627,7 @@
#if USE(LCMS)
if (m_iccTransform)
- cmsDoTransform(m_iccTransform, row, row, info->output_width);
+ cmsDoTransform(m_iccTransform.get(), row, row, info->output_width);
#endif
}
return true;
@@ -670,7 +660,7 @@
#if USE(LCMS)
if (m_iccTransform)
- cmsDoTransform(m_iccTransform, row, row, info->output_width);
+ cmsDoTransform(m_iccTransform.get(), row, row, info->output_width);
#endif
}
return true;
@@ -731,15 +721,15 @@
if (!buffer)
return;
- m_iccProfile = cmsOpenProfileFromMem(buffer->data(), buffer->size());
- if (!m_iccProfile)
+ auto iccProfile = LCMSProfilePtr(cmsOpenProfileFromMem(buffer->data(), buffer->size()));
+ if (!iccProfile)
return;
auto* displayProfile = PlatformDisplay::sharedDisplay().colorProfile();
- if (cmsGetColorSpace(m_iccProfile) != cmsSigRgbData || cmsGetColorSpace(displayProfile) != cmsSigRgbData)
+ if (cmsGetColorSpace(iccProfile.get()) != cmsSigRgbData || cmsGetColorSpace(displayProfile) != cmsSigRgbData)
return;
- m_iccTransform = cmsCreateTransform(m_iccProfile, TYPE_BGRA_8, displayProfile, TYPE_BGRA_8, INTENT_RELATIVE_COLORIMETRIC, 0);
+ m_iccTransform = LCMSTransformPtr(cmsCreateTransform(iccProfile.get(), TYPE_BGRA_8, displayProfile, TYPE_BGRA_8, INTENT_RELATIVE_COLORIMETRIC, 0));
}
#endif
Modified: trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h (287305 => 287306)
--- trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h 2021-12-21 10:06:10 UTC (rev 287306)
@@ -37,8 +37,7 @@
}
#if USE(LCMS)
-typedef void* cmsHPROFILE;
-typedef void* cmsHTRANSFORM;
+#include "LCMSUniquePtr.h"
#endif
namespace WebCore {
@@ -90,8 +89,7 @@
std::unique_ptr<JPEGImageReader> m_reader;
#if USE(LCMS)
- cmsHPROFILE m_iccProfile { nullptr };
- cmsHTRANSFORM m_iccTransform { nullptr };
+ LCMSTransformPtr m_iccTransform;
#endif
};
Modified: trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp (287305 => 287306)
--- trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp 2021-12-21 10:06:10 UTC (rev 287306)
@@ -30,7 +30,6 @@
#if USE(LCMS)
#include "PlatformDisplay.h"
-#include <lcms2.h>
#endif
namespace WebCore {
@@ -373,7 +372,7 @@
#if USE(LCMS)
if (m_iccTransform)
- cmsDoTransform(m_iccTransform, row, row, numPixels);
+ cmsDoTransform(m_iccTransform.get(), row, row, numPixels);
#endif
}
@@ -380,10 +379,7 @@
#if USE(LCMS)
void JPEGXLImageDecoder::clearColorTransform()
{
- if (m_iccTransform) {
- cmsDeleteTransform(m_iccTransform);
- m_iccTransform = nullptr;
- }
+ m_iccTransform.reset();
}
void JPEGXLImageDecoder::prepareColorTransform()
@@ -395,21 +391,17 @@
if (!displayProfile)
return;
- cmsHPROFILE profile = ""
+ auto profile = ""
if (!profile)
return; // TODO(bugs.webkit.org/show_bug.cgi?id=234222): We should try to use encoded color profile if ICC profile is not available.
// TODO(bugs.webkit.org/show_bug.cgi?id=234221): We should handle CMYK color but it may require two extra channels (Alpha and K)
// and libjxl has yet to support it.
- if (cmsGetColorSpace(profile) == cmsSigRgbData && cmsGetColorSpace(displayProfile) == cmsSigRgbData)
- m_iccTransform = cmsCreateTransform(profile, TYPE_BGRA_8, displayProfile, TYPE_BGRA_8, INTENT_RELATIVE_COLORIMETRIC, 0);
-
- // We close the profile here. The profile may still be alive if m_iccTransform holds a reference to it.
- if (profile)
- cmsCloseProfile(profile);
+ if (cmsGetColorSpace(profile.get()) == cmsSigRgbData && cmsGetColorSpace(displayProfile) == cmsSigRgbData)
+ m_iccTransform = LCMSTransformPtr(cmsCreateTransform(profile.get(), TYPE_BGRA_8, displayProfile, TYPE_BGRA_8, INTENT_RELATIVE_COLORIMETRIC, 0));
}
-cmsHPROFILE JPEGXLImageDecoder::tryDecodeICCColorProfile()
+LCMSProfilePtr JPEGXLImageDecoder::tryDecodeICCColorProfile()
{
size_t profileSize;
if (JxlDecoderGetICCProfileSize(m_decoder.get(), &s_pixelFormat, JXL_COLOR_PROFILE_TARGET_DATA, &profileSize) != JXL_DEC_SUCCESS)
@@ -419,7 +411,7 @@
if (JxlDecoderGetColorAsICCProfile(m_decoder.get(), &s_pixelFormat, JXL_COLOR_PROFILE_TARGET_DATA, profileData.data(), profileData.size()) != JXL_DEC_SUCCESS)
return nullptr;
- return cmsOpenProfileFromMem(profileData.data(), profileData.size());
+ return LCMSProfilePtr(cmsOpenProfileFromMem(profileData.data(), profileData.size()));
}
#endif // USE(LCMS)
Modified: trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.h (287305 => 287306)
--- trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.h 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.h 2021-12-21 10:06:10 UTC (rev 287306)
@@ -32,8 +32,7 @@
#include <jxl/decode_cxx.h>
#if USE(LCMS)
-typedef void* cmsHPROFILE;
-typedef void* cmsHTRANSFORM;
+#include "LCMSUniquePtr.h"
#endif
namespace WebCore {
@@ -91,7 +90,7 @@
#if USE(LCMS)
void clearColorTransform();
void prepareColorTransform();
- cmsHPROFILE tryDecodeICCColorProfile();
+ LCMSProfilePtr tryDecodeICCColorProfile();
#endif
JxlDecoderPtr m_decoder;
@@ -105,7 +104,7 @@
bool m_isLastFrameHeaderReceived { false }; // If this is true, we know we don't need to update m_frameCount.
#if USE(LCMS)
- cmsHTRANSFORM m_iccTransform { nullptr };
+ LCMSTransformPtr m_iccTransform;
#endif
};
Modified: trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp (287305 => 287306)
--- trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp 2021-12-21 10:06:10 UTC (rev 287306)
@@ -47,10 +47,6 @@
#include <wtf/StdLibExtras.h>
#include <wtf/UniqueArray.h>
-#if USE(LCMS)
-#include <lcms2.h>
-#endif
-
#if defined(PNG_LIBPNG_VER_MAJOR) && defined(PNG_LIBPNG_VER_MINOR) && (PNG_LIBPNG_VER_MAJOR > 1 || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4))
#define JMPBUF(png_ptr) png_jmpbuf(png_ptr)
#else
@@ -274,14 +270,7 @@
{
m_reader = nullptr;
#if USE(LCMS)
- if (m_iccTransform) {
- cmsDeleteTransform(m_iccTransform);
- m_iccTransform = nullptr;
- }
- if (m_iccProfile) {
- cmsCloseProfile(m_iccProfile);
- m_iccProfile = nullptr;
- }
+ m_iccTransform.reset();
#endif
}
@@ -412,11 +401,11 @@
png_uint_32 iccProfileDataSize;
int compressionType;
if (png_get_iCCP(png, info, &iccProfileTitle, &compressionType, &iccProfileData, &iccProfileDataSize)) {
- m_iccProfile = cmsOpenProfileFromMem(iccProfileData, iccProfileDataSize);
- if (m_iccProfile) {
+ auto iccProfile = LCMSProfilePtr(cmsOpenProfileFromMem(iccProfileData, iccProfileDataSize));
+ if (iccProfile) {
auto* displayProfile = PlatformDisplay::sharedDisplay().colorProfile();
- if (cmsGetColorSpace(m_iccProfile) == cmsSigRgbData && cmsGetColorSpace(displayProfile) == cmsSigRgbData)
- m_iccTransform = cmsCreateTransform(m_iccProfile, TYPE_BGRA_8, displayProfile, TYPE_BGRA_8, INTENT_RELATIVE_COLORIMETRIC, 0);
+ if (cmsGetColorSpace(iccProfile.get()) == cmsSigRgbData && cmsGetColorSpace(displayProfile) == cmsSigRgbData)
+ m_iccTransform = LCMSTransformPtr(cmsCreateTransform(iccProfile.get(), TYPE_BGRA_8, displayProfile, TYPE_BGRA_8, INTENT_RELATIVE_COLORIMETRIC, 0));
}
}
}
@@ -557,7 +546,7 @@
#if USE(LCMS)
if (m_iccTransform)
- cmsDoTransform(m_iccTransform, destRow, destRow, width);
+ cmsDoTransform(m_iccTransform.get(), destRow, destRow, width);
#endif
if (nonTrivialAlphaMask && !buffer.hasAlpha())
@@ -867,7 +856,7 @@
}
#if USE(LCMS)
if (m_iccTransform)
- cmsDoTransform(m_iccTransform, destRow, destRow, rect.maxX());
+ cmsDoTransform(m_iccTransform.get(), destRow, destRow, rect.maxX());
#endif
}
Modified: trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h (287305 => 287306)
--- trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h 2021-12-21 08:54:28 UTC (rev 287305)
+++ trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h 2021-12-21 10:06:10 UTC (rev 287306)
@@ -31,8 +31,7 @@
#endif
#if USE(LCMS)
-typedef void* cmsHPROFILE;
-typedef void* cmsHTRANSFORM;
+#include "LCMSUniquePtr.h"
#endif
namespace WebCore {
@@ -139,8 +138,7 @@
png_byte m_datatRNS[12 + 256];
#endif
#if USE(LCMS)
- cmsHPROFILE m_iccProfile { nullptr };
- cmsHTRANSFORM m_iccTransform { nullptr };
+ LCMSTransformPtr m_iccTransform;
#endif
};