[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.19-706-ge5415e9
simon.fraser at apple.com
simon.fraser at apple.com
Thu Feb 4 21:33:30 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 83dac9df0a457405946da90cd6ce1b2c0a9de79e
Author: simon.fraser at apple.com <simon.fraser at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Sun Jan 31 06:01:22 2010 +0000
2010-01-30 Simon Fraser <simon.fraser at apple.com>
Reviewed by Dan Bernstein.
Use CGGradient on Leopard and later, since it's faster than CGShading
https://bugs.webkit.org/show_bug.cgi?id=34384
Use CGGradient on Leopard and later, rather than CGShading, for
performance.
* platform/graphics/Gradient.h:
* platform/graphics/Gradient.cpp:
(WebCore::Gradient::sortStopsIfNecessary): Utility method to sort stops.
Did not call this from getColor() to avoid overhead of a function call.
* platform/graphics/cg/GradientCG.cpp:
(WebCore::Gradient::platformDestroy): Use CGGradientRelease() post-Tiger.
(WebCore::Gradient::platformGradient): Create and return a CGGradientRef post-Tiger.
(WebCore::Gradient::fill): Call new paint() method.
(WebCore::Gradient::paint): New convenence method that avoids testing
isRadial() in a bunch of other places.
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::fillPath): Call the gradient's paint() method.
(WebCore::GraphicsContext::strokePath): Ditto
(WebCore::GraphicsContext::fillRect): Ditto
(WebCore::GraphicsContext::strokeRect): Ditto
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54107 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index aef12e8..00031c3 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,5 +1,33 @@
2010-01-30 Simon Fraser <simon.fraser at apple.com>
+ Reviewed by Dan Bernstein.
+
+ Use CGGradient on Leopard and later, since it's faster than CGShading
+ https://bugs.webkit.org/show_bug.cgi?id=34384
+
+ Use CGGradient on Leopard and later, rather than CGShading, for
+ performance.
+
+ * platform/graphics/Gradient.h:
+ * platform/graphics/Gradient.cpp:
+ (WebCore::Gradient::sortStopsIfNecessary): Utility method to sort stops.
+ Did not call this from getColor() to avoid overhead of a function call.
+
+ * platform/graphics/cg/GradientCG.cpp:
+ (WebCore::Gradient::platformDestroy): Use CGGradientRelease() post-Tiger.
+ (WebCore::Gradient::platformGradient): Create and return a CGGradientRef post-Tiger.
+ (WebCore::Gradient::fill): Call new paint() method.
+ (WebCore::Gradient::paint): New convenence method that avoids testing
+ isRadial() in a bunch of other places.
+
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::GraphicsContext::fillPath): Call the gradient's paint() method.
+ (WebCore::GraphicsContext::strokePath): Ditto
+ (WebCore::GraphicsContext::fillRect): Ditto
+ (WebCore::GraphicsContext::strokeRect): Ditto
+
+2010-01-30 Simon Fraser <simon.fraser at apple.com>
+
Reviewed by Adele Peterson.
Do color animations on premultiplied colors
diff --git a/WebCore/platform/graphics/Gradient.cpp b/WebCore/platform/graphics/Gradient.cpp
index 445c365..c3bad56 100644
--- a/WebCore/platform/graphics/Gradient.cpp
+++ b/WebCore/platform/graphics/Gradient.cpp
@@ -105,6 +105,16 @@ static inline bool compareStops(const Gradient::ColorStop& a, const Gradient::Co
return a.stop < b.stop;
}
+void Gradient::sortStopsIfNecessary()
+{
+ if (m_stopsSorted)
+ return;
+
+ if (m_stops.size())
+ std::stable_sort(m_stops.begin(), m_stops.end(), compareStops);
+ m_stopsSorted = true;
+}
+
void Gradient::getColor(float value, float* r, float* g, float* b, float* a) const
{
ASSERT(value >= 0);
diff --git a/WebCore/platform/graphics/Gradient.h b/WebCore/platform/graphics/Gradient.h
index 7546864..2e1bf4f 100644
--- a/WebCore/platform/graphics/Gradient.h
+++ b/WebCore/platform/graphics/Gradient.h
@@ -36,8 +36,15 @@
#include <wtf/Vector.h>
#if PLATFORM(CG)
+
+#ifdef BUILDING_ON_TIGER
typedef struct CGShading* CGShadingRef;
typedef CGShadingRef PlatformGradient;
+#else
+typedef struct CGGradient* CGGradientRef;
+typedef CGGradientRef PlatformGradient;
+#endif
+
#elif PLATFORM(QT)
QT_BEGIN_NAMESPACE
class QGradient;
@@ -97,7 +104,7 @@ namespace WebCore {
};
void setStopsSorted(bool s) { m_stopsSorted = s; }
-
+
void setSpreadMethod(GradientSpreadMethod);
GradientSpreadMethod spreadMethod() { return m_spreadMethod; }
void setGradientSpaceTransform(const TransformationMatrix& gradientSpaceTransformation);
@@ -109,6 +116,9 @@ namespace WebCore {
void setPlatformGradientSpaceTransform(const TransformationMatrix& gradientSpaceTransformation);
+#if PLATFORM(CG)
+ void paint(GraphicsContext*);
+#endif
private:
Gradient(const FloatPoint& p0, const FloatPoint& p1);
Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1);
@@ -117,6 +127,7 @@ namespace WebCore {
void platformDestroy();
int findStop(float value) const;
+ void sortStopsIfNecessary();
bool m_radial;
FloatPoint m_p0;
diff --git a/WebCore/platform/graphics/cg/GradientCG.cpp b/WebCore/platform/graphics/cg/GradientCG.cpp
index 05a0aad..e9b5de7 100644
--- a/WebCore/platform/graphics/cg/GradientCG.cpp
+++ b/WebCore/platform/graphics/cg/GradientCG.cpp
@@ -36,10 +36,15 @@ namespace WebCore {
void Gradient::platformDestroy()
{
+#ifdef BUILDING_ON_TIGER
CGShadingRelease(m_gradient);
+#else
+ CGGradientRelease(m_gradient);
+#endif
m_gradient = 0;
}
+#ifdef BUILDING_ON_TIGER
static void gradientCallback(void* info, const CGFloat* in, CGFloat* out)
{
float r, g, b, a;
@@ -69,11 +74,55 @@ CGShadingRef Gradient::platformGradient()
return m_gradient;
}
+#else
+CGGradientRef Gradient::platformGradient()
+{
+ if (m_gradient)
+ return m_gradient;
+
+ static CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+
+ sortStopsIfNecessary();
+
+ const int cReservedStops = 3;
+ Vector<CGFloat, 4 * cReservedStops> colorComponents;
+ colorComponents.reserveCapacity(m_stops.size() * 4); // RGBA components per stop
+
+ Vector<CGFloat, cReservedStops> locations;
+ locations.reserveCapacity(m_stops.size());
+
+ for (size_t i = 0; i < m_stops.size(); ++i) {
+ colorComponents.uncheckedAppend(m_stops[i].red);
+ colorComponents.uncheckedAppend(m_stops[i].green);
+ colorComponents.uncheckedAppend(m_stops[i].blue);
+ colorComponents.uncheckedAppend(m_stops[i].alpha);
+
+ locations.uncheckedAppend(m_stops[i].stop);
+ }
+
+ m_gradient = CGGradientCreateWithColorComponents(colorSpace, colorComponents.data(), locations.data(), m_stops.size());
+
+ return m_gradient;
+}
+#endif
void Gradient::fill(GraphicsContext* context, const FloatRect& rect)
{
context->clip(rect);
+ paint(context);
+}
+
+void Gradient::paint(GraphicsContext* context)
+{
+#ifdef BUILDING_ON_TIGER
CGContextDrawShading(context->platformContext(), platformGradient());
+#else
+ CGGradientDrawingOptions extendOptions = kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
+ if (m_radial)
+ CGContextDrawRadialGradient(context->platformContext(), platformGradient(), m_p0, m_r0, m_p1, m_r1, extendOptions);
+ else
+ CGContextDrawLinearGradient(context->platformContext(), platformGradient(), m_p0, m_p1, extendOptions);
+#endif
}
} //namespace
diff --git a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
index d35865a..b11ba66 100644
--- a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
+++ b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
@@ -555,7 +555,7 @@ void GraphicsContext::fillPath()
else
CGContextClip(context);
CGContextConcatCTM(context, m_common->state.fillGradient->gradientSpaceTransform());
- CGContextDrawShading(context, m_common->state.fillGradient->platformGradient());
+ m_common->state.fillGradient->paint(this);
CGContextRestoreGState(context);
return;
}
@@ -580,7 +580,7 @@ void GraphicsContext::strokePath()
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
CGContextConcatCTM(context, m_common->state.strokeGradient->gradientSpaceTransform());
- CGContextDrawShading(context, m_common->state.strokeGradient->platformGradient());
+ m_common->state.strokeGradient->paint(this);
CGContextRestoreGState(context);
return;
}
@@ -604,7 +604,7 @@ void GraphicsContext::fillRect(const FloatRect& rect)
CGContextSaveGState(context);
CGContextClipToRect(context, rect);
CGContextConcatCTM(context, m_common->state.fillGradient->gradientSpaceTransform());
- CGContextDrawShading(context, m_common->state.fillGradient->platformGradient());
+ m_common->state.fillGradient->paint(this);
CGContextRestoreGState(context);
return;
}
@@ -845,7 +845,7 @@ void GraphicsContext::strokeRect(const FloatRect& r, float lineWidth)
CGContextAddRect(context, r);
CGContextReplacePathWithStrokedPath(context);
CGContextClip(context);
- CGContextDrawShading(context, m_common->state.strokeGradient->platformGradient());
+ m_common->state.strokeGradient->paint(this);
CGContextRestoreGState(context);
return;
}
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list