Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 96baf72

Browse files
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): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174410 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent c3555ab commit 96baf72

File tree

10 files changed

+50
-32
lines changed

10 files changed

+50
-32
lines changed

Source/WebCore/ChangeLog

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
2014-10-07 Andreas Kling <[email protected]>
2+
3+
Use more Ref and PassRef for Gradient.
4+
<https://webkit.org/b/137490>
5+
6+
Codify the fact that CanvasGradient always has an internal WebCore::Gradient
7+
and make GraphicsContext gradient setters take PassRef, exposing some
8+
unnecessary null checks.
9+
10+
Reviewed by Christophe Dumez.
11+
12+
* WebCore.exp.in:
13+
* html/canvas/CanvasGradient.h:
14+
(WebCore::CanvasGradient::gradient):
15+
* platform/graphics/Gradient.h:
16+
(WebCore::Gradient::create):
17+
* platform/graphics/GraphicsContext.cpp:
18+
(WebCore::GraphicsContext::setStrokeGradient):
19+
(WebCore::GraphicsContext::setFillGradient):
20+
* platform/graphics/GraphicsContext.h:
21+
* rendering/RenderThemeIOS.mm:
22+
(WebCore::RenderThemeIOS::paintProgressBar):
23+
* rendering/svg/RenderSVGPath.cpp:
24+
(WebCore::useStrokeStyleToFill):
25+
* rendering/svg/RenderSVGResourceGradient.cpp:
26+
(WebCore::RenderSVGResourceGradient::applyResource):
27+
128
2014-10-07 Martin Hock <[email protected]>
229

330
Defer resolution of viewport size.

Source/WebCore/WebCore.exp.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ __ZN7WebCore15GraphicsContext11clearShadowEv
526526
__ZN7WebCore15GraphicsContext12setFillColorERKNS_5ColorENS_10ColorSpaceE
527527
__ZN7WebCore15GraphicsContext14setStrokeColorERKNS_5ColorENS_10ColorSpaceE
528528
__ZN7WebCore15GraphicsContext15drawNativeImageEP7CGImageRKNS_9FloatSizeENS_10ColorSpaceERKNS_9FloatRectES9_NS_17CompositeOperatorENS_9BlendModeENS_16ImageOrientationE
529-
__ZN7WebCore15GraphicsContext15setFillGradientEN3WTF10PassRefPtrINS_8GradientEEE
529+
__ZN7WebCore15GraphicsContext15setFillGradientEN3WTF7PassRefINS_8GradientEEE
530530
__ZN7WebCore15GraphicsContext18setShouldAntialiasEb
531531
__ZN7WebCore15GraphicsContext19setIsCALayerContextEb
532532
__ZN7WebCore15GraphicsContext20endTransparencyLayerEv

Source/WebCore/html/canvas/CanvasGradient.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ namespace WebCore {
4747
return adoptRef(new CanvasGradient(p0, r0, p1, r1));
4848
}
4949

50-
Gradient* gradient() const { return m_gradient.get(); }
50+
Gradient& gradient() { return m_gradient.get(); }
51+
const Gradient& gradient() const { return m_gradient.get(); }
5152

5253
void addColorStop(float value, const String& color, ExceptionCode&);
5354

@@ -59,7 +60,7 @@ namespace WebCore {
5960
CanvasGradient(const FloatPoint& p0, const FloatPoint& p1);
6061
CanvasGradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1);
6162

62-
RefPtr<Gradient> m_gradient;
63+
Ref<Gradient> m_gradient;
6364
#if ENABLE(DASHBOARD_SUPPORT)
6465
bool m_dashbardCompatibilityMode;
6566
#endif

Source/WebCore/platform/graphics/Gradient.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ namespace WebCore {
5757

5858
class Gradient : public RefCounted<Gradient> {
5959
public:
60-
static PassRefPtr<Gradient> create(const FloatPoint& p0, const FloatPoint& p1)
60+
static PassRef<Gradient> create(const FloatPoint& p0, const FloatPoint& p1)
6161
{
62-
return adoptRef(new Gradient(p0, p1));
62+
return adoptRef(*new Gradient(p0, p1));
6363
}
64-
static PassRefPtr<Gradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio = 1)
64+
static PassRef<Gradient> create(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, float aspectRatio = 1)
6565
{
66-
return adoptRef(new Gradient(p0, r0, p1, r1, aspectRatio));
66+
return adoptRef(*new Gradient(p0, r0, p1, r1, aspectRatio));
6767
}
6868
WEBCORE_EXPORT ~Gradient();
6969

Source/WebCore/platform/graphics/GraphicsContext.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -347,25 +347,15 @@ void GraphicsContext::setFillPattern(PassRef<Pattern> pattern)
347347
m_state.fillPattern = WTF::move(pattern);
348348
}
349349

350-
void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient)
350+
void GraphicsContext::setStrokeGradient(PassRef<Gradient> gradient)
351351
{
352-
ASSERT(gradient);
353-
if (!gradient) {
354-
setStrokeColor(Color::black, ColorSpaceDeviceRGB);
355-
return;
356-
}
357-
m_state.strokeGradient = gradient;
352+
m_state.strokeGradient = WTF::move(gradient);
358353
m_state.strokePattern.clear();
359354
}
360355

361-
void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient)
356+
void GraphicsContext::setFillGradient(PassRef<Gradient> gradient)
362357
{
363-
ASSERT(gradient);
364-
if (!gradient) {
365-
setFillColor(Color::black, ColorSpaceDeviceRGB);
366-
return;
367-
}
368-
m_state.fillGradient = gradient;
358+
m_state.fillGradient = WTF::move(gradient);
369359
m_state.fillPattern.clear();
370360
}
371361

Source/WebCore/platform/graphics/GraphicsContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ namespace WebCore {
237237
void setStrokePattern(PassRef<Pattern>);
238238
Pattern* strokePattern() const;
239239

240-
void setStrokeGradient(PassRefPtr<Gradient>);
240+
void setStrokeGradient(PassRef<Gradient>);
241241
Gradient* strokeGradient() const;
242242

243243
WindRule fillRule() const;
@@ -249,7 +249,7 @@ namespace WebCore {
249249
void setFillPattern(PassRef<Pattern>);
250250
Pattern* fillPattern() const;
251251

252-
WEBCORE_EXPORT void setFillGradient(PassRefPtr<Gradient>);
252+
WEBCORE_EXPORT void setFillGradient(PassRef<Gradient>);
253253
Gradient* fillGradient() const;
254254

255255
void setShadowsIgnoreTransforms(bool);

Source/WebCore/rendering/RenderThemeIOS.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ static void adjustInputElementButtonStyle(RenderStyle& style, HTMLInputElement&
874874
strokeGradient->addColorStop(0.45, Color(0xee, 0xee, 0xee));
875875
strokeGradient->addColorStop(0.55, Color(0xee, 0xee, 0xee));
876876
strokeGradient->addColorStop(1.0, Color(0x8d, 0x8d, 0x8d));
877-
context->setStrokeGradient(strokeGradient.release());
877+
context->setStrokeGradient(strokeGradient.releaseNonNull());
878878

879879
ColorSpace colorSpace = renderer.style().colorSpace();
880880
context->setFillColor(Color(255, 255, 255), colorSpace);
@@ -893,7 +893,7 @@ static void adjustInputElementButtonStyle(RenderStyle& style, HTMLInputElement&
893893
RefPtr<Gradient> upperGradient = Gradient::create(FloatPoint(rect.x(), verticalRenderingPosition + 0.5), FloatPoint(rect.x(), verticalRenderingPosition + upperGradientHeight - 1.5));
894894
upperGradient->addColorStop(0.0, Color(133, 133, 133, 188));
895895
upperGradient->addColorStop(1.0, Color(18, 18, 18, 51));
896-
context->setFillGradient(upperGradient.release());
896+
context->setFillGradient(upperGradient.releaseNonNull());
897897

898898
context->fillRect(FloatRect(rect.x(), verticalRenderingPosition, rect.width(), upperGradientHeight));
899899

@@ -909,13 +909,13 @@ static void adjustInputElementButtonStyle(RenderStyle& style, HTMLInputElement&
909909
barGradient->addColorStop(0.51, Color(36, 114, 210));
910910
barGradient->addColorStop(0.55, Color(36, 114, 210));
911911
barGradient->addColorStop(1.0, Color(57, 142, 244));
912-
context->setFillGradient(barGradient.release());
912+
context->setFillGradient(barGradient.releaseNonNull());
913913

914914
RefPtr<Gradient> barStrokeGradient = Gradient::create(FloatPoint(rect.x(), verticalRenderingPosition), FloatPoint(rect.x(), verticalRenderingPosition + progressBarHeight - 1));
915915
barStrokeGradient->addColorStop(0.0, Color(95, 107, 183));
916916
barStrokeGradient->addColorStop(0.5, Color(66, 106, 174, 240));
917917
barStrokeGradient->addColorStop(1.0, Color(38, 104, 166));
918-
context->setStrokeGradient(barStrokeGradient.release());
918+
context->setStrokeGradient(barStrokeGradient.releaseNonNull());
919919

920920
Path barPath;
921921
int left = rect.x();

Source/WebCore/rendering/svg/RenderSVGPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ FloatRect RenderSVGPath::calculateUpdatedStrokeBoundingBox() const
6767
static void useStrokeStyleToFill(GraphicsContext* context)
6868
{
6969
if (Gradient* gradient = context->strokeGradient())
70-
context->setFillGradient(gradient);
70+
context->setFillGradient(*gradient);
7171
else if (Pattern* pattern = context->strokePattern())
7272
context->setFillPattern(*pattern);
7373
else

Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ bool RenderSVGResourceGradient::applyResource(RenderElement& renderer, const Ren
177177

178178
if (resourceMode & ApplyToFillMode) {
179179
context->setAlpha(svgStyle.fillOpacity());
180-
context->setFillGradient(gradientData->gradient);
180+
context->setFillGradient(*gradientData->gradient);
181181
context->setFillRule(svgStyle.fillRule());
182182
} else if (resourceMode & ApplyToStrokeMode) {
183183
if (svgStyle.vectorEffect() == VE_NON_SCALING_STROKE)
184184
gradientData->gradient->setGradientSpaceTransform(transformOnNonScalingStroke(&renderer, gradientData->userspaceTransform));
185185
context->setAlpha(svgStyle.strokeOpacity());
186-
context->setStrokeGradient(gradientData->gradient);
186+
context->setStrokeGradient(*gradientData->gradient);
187187
SVGRenderSupport::applyStrokeStyleToContext(context, style, renderer);
188188
}
189189

@@ -209,7 +209,7 @@ void RenderSVGResourceGradient::postApplyResource(RenderElement& renderer, Graph
209209

210210
FloatRect targetRect;
211211
gradientData->gradient->setGradientSpaceTransform(clipToTextMask(context, m_imageBuffer, targetRect, &renderer, gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX, gradientTransform));
212-
context->setFillGradient(gradientData->gradient);
212+
context->setFillGradient(*gradientData->gradient);
213213

214214
context->fillRect(targetRect);
215215
m_imageBuffer.reset();

Source/WebKit2/UIProcess/FindIndicator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void FindIndicator::draw(GraphicsContext& graphicsContext, const IntRect& /*dirt
236236
RefPtr<Gradient> gradient = Gradient::create(FloatPoint(innerPathRect.x(), innerPathRect.y()), FloatPoint(innerPathRect.x(), innerPathRect.maxY()));
237237
gradient->addColorStop(0, gradientLightColor());
238238
gradient->addColorStop(1, gradientDarkColor());
239-
graphicsContext.setFillGradient(gradient);
239+
graphicsContext.setFillGradient(gradient.releaseNonNull());
240240
graphicsContext.fillRect(outerPathRect);
241241
}
242242

0 commit comments

Comments
 (0)