Bug 163157 - Reduce code duplication between CG, Cairo, and Direct2D
Summary: Reduce code duplication between CG, Cairo, and Direct2D
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-07 16:23 PDT by Brent Fulgham
Modified: 2016-10-10 10:15 PDT (History)
5 users (show)

See Also:


Attachments
Patch (14.92 KB, patch)
2016-10-07 17:33 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (15.00 KB, patch)
2016-10-07 17:43 PDT, Brent Fulgham
darin: review+
simon.fraser: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2016-10-07 16:23:09 PDT
The various GraphicsContext implementations duplicate utility functions, constants, and other code. We should reduce this duplication to help ensure consistency and reduce maintenance burden.
Comment 1 Brent Fulgham 2016-10-07 17:33:28 PDT
Created attachment 290988 [details]
Patch
Comment 2 Simon Fraser (smfr) 2016-10-07 17:40:46 PDT
Comment on attachment 290988 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=290988&action=review

> Source/WebCore/platform/graphics/GraphicsContext.cpp:1132
> +    return strokeStyle() == DottedStroke ? thickness : std::min(2.0f * thickness, std::max(thickness, strokeWidth / 3.0f));

We should make a constrainedBetween<> template.

> Source/WebCore/platform/graphics/GraphicsContext.cpp:1139
> +    

Blank line.

> Source/WebCore/platform/graphics/GraphicsContext.h:624
> +    float dashedLineCornerWidthForStrokeWidth(float);
> +    float dashedLinePatternWidthForStrokeWidth(float);
> +    float dashedLinePatternOffsetForPatternAndStrokeWidth(float patternWidth, float strokeWidth);
> +    Vector<FloatPoint> centerLineAndCutOffCorners(bool isVerticalLine, FloatPoint point1, FloatPoint point2);

Can these all be static?
Comment 3 Brent Fulgham 2016-10-07 17:43:55 PDT
Created attachment 290990 [details]
Patch
Comment 4 Brent Fulgham 2016-10-07 17:46:04 PDT
Comment on attachment 290988 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=290988&action=review

>> Source/WebCore/platform/graphics/GraphicsContext.cpp:1132
>> +    return strokeStyle() == DottedStroke ? thickness : std::min(2.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
> 
> We should make a constrainedBetween<> template.

I wonder if we have one? I'll go look.

>> Source/WebCore/platform/graphics/GraphicsContext.cpp:1139
>> +    
> 
> Blank line.

Whoops!

>> Source/WebCore/platform/graphics/GraphicsContext.h:624
>> +    Vector<FloatPoint> centerLineAndCutOffCorners(bool isVerticalLine, FloatPoint point1, FloatPoint point2);
> 
> Can these all be static?

They could; I'd just need to pass the stroke style in, and maybe the stroke thickness.
Comment 5 Simon Fraser (smfr) 2016-10-07 22:51:52 PDT
Comment on attachment 290990 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=290990&action=review

> Source/WebCore/platform/graphics/GraphicsContext.cpp:1139
> +    

Blank line

> Source/WebCore/platform/graphics/GraphicsContext.h:624
> +    float dashedLineCornerWidthForStrokeWidth(float);
> +    float dashedLinePatternWidthForStrokeWidth(float);
> +    float dashedLinePatternOffsetForPatternAndStrokeWidth(float patternWidth, float strokeWidth);
> +    Vector<FloatPoint> centerLineAndCutOffCorners(bool isVerticalLine, float cornerWidth, FloatPoint point1, FloatPoint point2);

These can all be const
Comment 6 Brent Fulgham 2016-10-10 09:48:31 PDT
Comment on attachment 290990 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=290990&action=review

>> Source/WebCore/platform/graphics/GraphicsContext.cpp:1139
>> +    
> 
> Blank line

OK!
Comment 7 Brent Fulgham 2016-10-10 09:48:52 PDT
Comment on attachment 290990 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=290990&action=review

>> Source/WebCore/platform/graphics/GraphicsContext.h:624
>> +    Vector<FloatPoint> centerLineAndCutOffCorners(bool isVerticalLine, float cornerWidth, FloatPoint point1, FloatPoint point2);
> 
> These can all be const

Done.
Comment 8 Brent Fulgham 2016-10-10 10:05:27 PDT
Committed r207002: <http://trac.webkit.org/changeset/207002>
Comment 9 Darin Adler 2016-10-10 10:07:33 PDT
Comment on attachment 290990 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=290990&action=review

> Source/WebCore/platform/graphics/GraphicsContext.cpp:1167
> +    // Center line and cut off corners for pattern patining.

Noticed a typo here: patining.
Comment 10 Brent Fulgham 2016-10-10 10:15:03 PDT
Fixed typo in Committed r207003: <http://trac.webkit.org/changeset/207003>