Title: [277994] trunk/Source/WebCore
- Revision
- 277994
- Author
- wei...@apple.com
- Date
- 2021-05-24 20:36:09 -0700 (Mon, 24 May 2021)
Log Message
DestinationColorSpace's well known color space accessors cause unnecessary retain count churn
https://bugs.webkit.org/show_bug.cgi?id=226160
Reviewed by Darin Adler.
While unlikely to be hot, we can avoid unnecessary retain count churn of
the well known color spaces on DestinationColorSpace by switching their
signature to return a const-reference and storing/returning a static instance.
* platform/graphics/DestinationColorSpace.cpp:
(WebCore::knownColorSpace):
(WebCore::DestinationColorSpace::SRGB):
(WebCore::DestinationColorSpace::LinearSRGB):
(WebCore::DestinationColorSpace::DisplayP3):
* platform/graphics/DestinationColorSpace.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (277993 => 277994)
--- trunk/Source/WebCore/ChangeLog 2021-05-25 03:23:50 UTC (rev 277993)
+++ trunk/Source/WebCore/ChangeLog 2021-05-25 03:36:09 UTC (rev 277994)
@@ -1,3 +1,21 @@
+2021-05-24 Sam Weinig <wei...@apple.com>
+
+ DestinationColorSpace's well known color space accessors cause unnecessary retain count churn
+ https://bugs.webkit.org/show_bug.cgi?id=226160
+
+ Reviewed by Darin Adler.
+
+ While unlikely to be hot, we can avoid unnecessary retain count churn of
+ the well known color spaces on DestinationColorSpace by switching their
+ signature to return a const-reference and storing/returning a static instance.
+
+ * platform/graphics/DestinationColorSpace.cpp:
+ (WebCore::knownColorSpace):
+ (WebCore::DestinationColorSpace::SRGB):
+ (WebCore::DestinationColorSpace::LinearSRGB):
+ (WebCore::DestinationColorSpace::DisplayP3):
+ * platform/graphics/DestinationColorSpace.h:
+
2021-05-24 Chris Dumez <cdu...@apple.com>
[GStreamer] Stop using UncheckedLock in VideoRenderRequestScheduler
Modified: trunk/Source/WebCore/platform/graphics/DestinationColorSpace.cpp (277993 => 277994)
--- trunk/Source/WebCore/platform/graphics/DestinationColorSpace.cpp 2021-05-25 03:23:50 UTC (rev 277993)
+++ trunk/Source/WebCore/platform/graphics/DestinationColorSpace.cpp 2021-05-25 03:36:09 UTC (rev 277994)
@@ -26,6 +26,7 @@
#include "config.h"
#include "DestinationColorSpace.h"
+#include <wtf/NeverDestroyed.h>
#include <wtf/text/TextStream.h>
#if USE(CG)
@@ -35,33 +36,52 @@
namespace WebCore {
-DestinationColorSpace DestinationColorSpace::SRGB()
+#if USE(CG)
+using KnownColorSpaceAccessor = CGColorSpaceRef();
+template<KnownColorSpaceAccessor accessor> static const DestinationColorSpace& knownColorSpace()
{
+ static LazyNeverDestroyed<DestinationColorSpace> colorSpace;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+ colorSpace.construct(accessor());
+ });
+ return colorSpace.get();
+}
+#else
+template<PlatformColorSpace::Name name> static const DestinationColorSpace& knownColorSpace()
+{
+ static NeverDestroyed<DestinationColorSpace> colorSpace { name };
+ return colorSpace.get();
+}
+#endif
+
+const DestinationColorSpace& DestinationColorSpace::SRGB()
+{
#if USE(CG)
- return DestinationColorSpace(sRGBColorSpaceRef());
+ return knownColorSpace<sRGBColorSpaceRef>();
#else
- return DestinationColorSpace(PlatformColorSpace::Name::SRGB);
+ return knownColorSpace<PlatformColorSpace::Name::SRGB>();
#endif
}
#if ENABLE(DESTINATION_COLOR_SPACE_LINEAR_SRGB)
-DestinationColorSpace DestinationColorSpace::LinearSRGB()
+const DestinationColorSpace& DestinationColorSpace::LinearSRGB()
{
#if USE(CG)
- return DestinationColorSpace(linearSRGBColorSpaceRef());
+ return knownColorSpace<linearSRGBColorSpaceRef>();
#else
- return DestinationColorSpace(PlatformColorSpace::Name::LinearSRGB);
+ return knownColorSpace<PlatformColorSpace::Name::LinearSRGB>();
#endif
}
#endif
#if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3)
-DestinationColorSpace DestinationColorSpace::DisplayP3()
+const DestinationColorSpace& DestinationColorSpace::DisplayP3()
{
#if USE(CG)
- return DestinationColorSpace(displayP3ColorSpaceRef());
+ return knownColorSpace<displayP3ColorSpaceRef>();
#else
- return DestinationColorSpace(PlatformColorSpace::Name::DisplayP3);
+ return knownColorSpace<PlatformColorSpace::Name::DisplayP3>();
#endif
}
#endif
Modified: trunk/Source/WebCore/platform/graphics/DestinationColorSpace.h (277993 => 277994)
--- trunk/Source/WebCore/platform/graphics/DestinationColorSpace.h 2021-05-25 03:23:50 UTC (rev 277993)
+++ trunk/Source/WebCore/platform/graphics/DestinationColorSpace.h 2021-05-25 03:36:09 UTC (rev 277994)
@@ -33,12 +33,12 @@
class DestinationColorSpace {
public:
- WEBCORE_EXPORT static DestinationColorSpace SRGB();
+ WEBCORE_EXPORT static const DestinationColorSpace& SRGB();
#if ENABLE(DESTINATION_COLOR_SPACE_LINEAR_SRGB)
- WEBCORE_EXPORT static DestinationColorSpace LinearSRGB();
+ WEBCORE_EXPORT static const DestinationColorSpace& LinearSRGB();
#endif
#if ENABLE(DESTINATION_COLOR_SPACE_DISPLAY_P3)
- WEBCORE_EXPORT static DestinationColorSpace DisplayP3();
+ WEBCORE_EXPORT static const DestinationColorSpace& DisplayP3();
#endif
WEBCORE_EXPORT explicit DestinationColorSpace(PlatformColorSpace);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes