Use more Ref and PassRef for Gradient.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Oct 2014 22:26:25 +0000 (22:26 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Oct 2014 22:26:25 +0000 (22:26 +0000)
<https://webkit.org/b/137490>

Codify the fact that CanvasGradient always has an internal WebCore::Gradient
and make GraphicsContext gradient setters take PassRef, exposing some
unnecessary null checks.

Reviewed by Christophe Dumez.

* WebCore.exp.in:
* html/canvas/CanvasGradient.h:
(WebCore::CanvasGradient::gradient):
* platform/graphics/Gradient.h:
(WebCore::Gradient::create):
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::setStrokeGradient):
(WebCore::GraphicsContext::setFillGradient):
* platform/graphics/GraphicsContext.h:
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::paintProgressBar):
* rendering/svg/RenderSVGPath.cpp:
(WebCore::useStrokeStyleToFill):
* rendering/svg/RenderSVGResourceGradient.cpp:
(WebCore::RenderSVGResourceGradient::applyResource):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174410 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/html/canvas/CanvasGradient.h
Source/WebCore/platform/graphics/Gradient.h
Source/WebCore/platform/graphics/GraphicsContext.cpp
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/rendering/svg/RenderSVGPath.cpp
Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp
Source/WebKit2/UIProcess/FindIndicator.cpp

index 4514a4c..988f38a 100644 (file)
@@ -1,3 +1,30 @@
+2014-10-07  Andreas Kling  <akling@apple.com>
+
+        Use more Ref and PassRef for Gradient.
+        <https://webkit.org/b/137490>
+
+        Codify the fact that CanvasGradient always has an internal WebCore::Gradient
+        and make GraphicsContext gradient setters take PassRef, exposing some
+        unnecessary null checks.
+
+        Reviewed by Christophe Dumez.
+
+        * WebCore.exp.in:
+        * html/canvas/CanvasGradient.h:
+        (WebCore::CanvasGradient::gradient):
+        * platform/graphics/Gradient.h:
+        (WebCore::Gradient::create):
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::setStrokeGradient):
+        (WebCore::GraphicsContext::setFillGradient):
+        * platform/graphics/GraphicsContext.h:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::paintProgressBar):
+        * rendering/svg/RenderSVGPath.cpp:
+        (WebCore::useStrokeStyleToFill):
+        * rendering/svg/RenderSVGResourceGradient.cpp:
+        (WebCore::RenderSVGResourceGradient::applyResource):
+
 2014-10-07  Martin Hock  <mhock@apple.com>
 
         Defer resolution of viewport size.
index 4b16510..a5aae4d 100644 (file)
@@ -526,7 +526,7 @@ __ZN7WebCore15GraphicsContext11clearShadowEv
 __ZN7WebCore15GraphicsContext12setFillColorERKNS_5ColorENS_10ColorSpaceE
 __ZN7WebCore15GraphicsContext14setStrokeColorERKNS_5ColorENS_10ColorSpaceE
 __ZN7WebCore15GraphicsContext15drawNativeImageEP7CGImageRKNS_9FloatSizeENS_10ColorSpaceERKNS_9FloatRectES9_NS_17CompositeOperatorENS_9BlendModeENS_16ImageOrientationE
-__ZN7WebCore15GraphicsContext15setFillGradientEN3WTF10PassRefPtrINS_8GradientEEE
+__ZN7WebCore15GraphicsContext15setFillGradientEN3WTF7PassRefINS_8GradientEEE
 __ZN7WebCore15GraphicsContext18setShouldAntialiasEb
 __ZN7WebCore15GraphicsContext19setIsCALayerContextEb
 __ZN7WebCore15GraphicsContext20endTransparencyLayerEv
index 997f266..a4a77aa 100644 (file)
@@ -47,7 +47,8 @@ namespace WebCore {
             return adoptRef(new CanvasGradient(p0, r0, p1, r1));
         }
         
-        Gradient* gradient() const { return m_gradient.get(); }
+        Gradient& gradient() { return m_gradient.get(); }
+        const Gradient& gradient() const { return m_gradient.get(); }
 
         void addColorStop(float value, const String& color, ExceptionCode&);
 
@@ -59,7 +60,7 @@ namespace WebCore {
         CanvasGradient(const FloatPoint& p0, const FloatPoint& p1);
         CanvasGradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1);
         
-        RefPtr<Gradient> m_gradient;
+        Ref<Gradient> m_gradient;
 #if ENABLE(DASHBOARD_SUPPORT)
         bool m_dashbardCompatibilityMode;
 #endif
index 6b3880b..484d604 100644 (file)
@@ -57,13 +57,13 @@ namespace WebCore {
 
     class Gradient : public RefCounted<Gradient> {
     public:
-        static PassRefPtr<Gradient> create(const FloatPoint& p0, const FloatPoint& p1)
+        static PassRef<Gradient> create(const FloatPoint& p0, const FloatPoint& p1)
         {
-            return adoptRef(new Gradient(p0, p1));
+            return adoptRef(*new Gradient(p0, p1));
         }
-        static PassRefPtr<Gradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio = 1)
+        static PassRef<Gradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio = 1)
         {
-            return adoptRef(new Gradient(p0, r0, p1, r1, aspectRatio));
+            return adoptRef(*new Gradient(p0, r0, p1, r1, aspectRatio));
         }
         WEBCORE_EXPORT ~Gradient();
 
index c6a0bfd..736b8fd 100644 (file)
@@ -347,25 +347,15 @@ void GraphicsContext::setFillPattern(PassRef<Pattern> pattern)
     m_state.fillPattern = WTF::move(pattern);
 }
 
-void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient)
+void GraphicsContext::setStrokeGradient(PassRef<Gradient> gradient)
 {
-    ASSERT(gradient);
-    if (!gradient) {
-        setStrokeColor(Color::black, ColorSpaceDeviceRGB);
-        return;
-    }
-    m_state.strokeGradient = gradient;
+    m_state.strokeGradient = WTF::move(gradient);
     m_state.strokePattern.clear();
 }
 
-void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient)
+void GraphicsContext::setFillGradient(PassRef<Gradient> gradient)
 {
-    ASSERT(gradient);
-    if (!gradient) {
-        setFillColor(Color::black, ColorSpaceDeviceRGB);
-        return;
-    }
-    m_state.fillGradient = gradient;
+    m_state.fillGradient = WTF::move(gradient);
     m_state.fillPattern.clear();
 }
 
index b771720..13e3a5d 100644 (file)
@@ -237,7 +237,7 @@ namespace WebCore {
         void setStrokePattern(PassRef<Pattern>);
         Pattern* strokePattern() const;
 
-        void setStrokeGradient(PassRefPtr<Gradient>);
+        void setStrokeGradient(PassRef<Gradient>);
         Gradient* strokeGradient() const;
 
         WindRule fillRule() const;
@@ -249,7 +249,7 @@ namespace WebCore {
         void setFillPattern(PassRef<Pattern>);
         Pattern* fillPattern() const;
 
-        WEBCORE_EXPORT void setFillGradient(PassRefPtr<Gradient>);
+        WEBCORE_EXPORT void setFillGradient(PassRef<Gradient>);
         Gradient* fillGradient() const;
 
         void setShadowsIgnoreTransforms(bool);
index 789bef5..3a03574 100644 (file)
@@ -874,7 +874,7 @@ bool RenderThemeIOS::paintProgressBar(const RenderObject& renderer, const PaintI
     strokeGradient->addColorStop(0.45, Color(0xee, 0xee, 0xee));
     strokeGradient->addColorStop(0.55, Color(0xee, 0xee, 0xee));
     strokeGradient->addColorStop(1.0, Color(0x8d, 0x8d, 0x8d));
-    context->setStrokeGradient(strokeGradient.release());
+    context->setStrokeGradient(strokeGradient.releaseNonNull());
 
     ColorSpace colorSpace = renderer.style().colorSpace();
     context->setFillColor(Color(255, 255, 255), colorSpace);
@@ -893,7 +893,7 @@ bool RenderThemeIOS::paintProgressBar(const RenderObject& renderer, const PaintI
     RefPtr<Gradient> upperGradient = Gradient::create(FloatPoint(rect.x(), verticalRenderingPosition + 0.5), FloatPoint(rect.x(), verticalRenderingPosition + upperGradientHeight - 1.5));
     upperGradient->addColorStop(0.0, Color(133, 133, 133, 188));
     upperGradient->addColorStop(1.0, Color(18, 18, 18, 51));
-    context->setFillGradient(upperGradient.release());
+    context->setFillGradient(upperGradient.releaseNonNull());
 
     context->fillRect(FloatRect(rect.x(), verticalRenderingPosition, rect.width(), upperGradientHeight));
 
@@ -909,13 +909,13 @@ bool RenderThemeIOS::paintProgressBar(const RenderObject& renderer, const PaintI
         barGradient->addColorStop(0.51, Color(36, 114, 210));
         barGradient->addColorStop(0.55, Color(36, 114, 210));
         barGradient->addColorStop(1.0, Color(57, 142, 244));
-        context->setFillGradient(barGradient.release());
+        context->setFillGradient(barGradient.releaseNonNull());
 
         RefPtr<Gradient> barStrokeGradient = Gradient::create(FloatPoint(rect.x(), verticalRenderingPosition), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1));
         barStrokeGradient->addColorStop(0.0, Color(95, 107, 183));
         barStrokeGradient->addColorStop(0.5, Color(66, 106, 174, 240));
         barStrokeGradient->addColorStop(1.0, Color(38, 104, 166));
-        context->setStrokeGradient(barStrokeGradient.release());
+        context->setStrokeGradient(barStrokeGradient.releaseNonNull());
 
         Path barPath;
         int left = rect.x();
index ced0fea..6244570 100644 (file)
@@ -67,7 +67,7 @@ FloatRect RenderSVGPath::calculateUpdatedStrokeBoundingBox() const
 static void useStrokeStyleToFill(GraphicsContext* context)
 {
     if (Gradient* gradient = context->strokeGradient())
-        context->setFillGradient(gradient);
+        context->setFillGradient(*gradient);
     else if (Pattern* pattern = context->strokePattern())
         context->setFillPattern(*pattern);
     else
index dcb3c24..17c68cb 100644 (file)
@@ -177,13 +177,13 @@ bool RenderSVGResourceGradient::applyResource(RenderElement& renderer, const Ren
 
     if (resourceMode & ApplyToFillMode) {
         context->setAlpha(svgStyle.fillOpacity());
-        context->setFillGradient(gradientData->gradient);
+        context->setFillGradient(*gradientData->gradient);
         context->setFillRule(svgStyle.fillRule());
     } else if (resourceMode & ApplyToStrokeMode) {
         if (svgStyle.vectorEffect() == VE_NON_SCALING_STROKE)
             gradientData->gradient->setGradientSpaceTransform(transformOnNonScalingStroke(&renderer, gradientData->userspaceTransform));
         context->setAlpha(svgStyle.strokeOpacity());
-        context->setStrokeGradient(gradientData->gradient);
+        context->setStrokeGradient(*gradientData->gradient);
         SVGRenderSupport::applyStrokeStyleToContext(context, style, renderer);
     }
 
@@ -209,7 +209,7 @@ void RenderSVGResourceGradient::postApplyResource(RenderElement& renderer, Graph
 
             FloatRect targetRect;
             gradientData->gradient->setGradientSpaceTransform(clipToTextMask(context, m_imageBuffer, targetRect, &renderer, gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX, gradientTransform));
-            context->setFillGradient(gradientData->gradient);
+            context->setFillGradient(*gradientData->gradient);
 
             context->fillRect(targetRect);
             m_imageBuffer.reset();
index c845422..71e206b 100644 (file)
@@ -236,7 +236,7 @@ void FindIndicator::draw(GraphicsContext& graphicsContext, const IntRect& /*dirt
             RefPtr<Gradient> gradient = Gradient::create(FloatPoint(innerPathRect.x(), innerPathRect.y()), FloatPoint(innerPathRect.x(), innerPathRect.maxY()));
             gradient->addColorStop(0, gradientLightColor());
             gradient->addColorStop(1, gradientDarkColor());
-            graphicsContext.setFillGradient(gradient);
+            graphicsContext.setFillGradient(gradient.releaseNonNull());
             graphicsContext.fillRect(outerPathRect);
         }