Bug 201534 - PathDirect2D Cleanups
Summary: PathDirect2D Cleanups
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-09-05 21:13 PDT by Brent Fulgham
Modified: 2019-09-06 19:40 PDT (History)
7 users (show)

See Also:


Attachments
Patch (22.25 KB, patch)
2019-09-05 21:28 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (22.28 KB, patch)
2019-09-05 21:35 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (22.52 KB, patch)
2019-09-06 10:43 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (21.90 KB, patch)
2019-09-06 16:19 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2019-09-05 21:13:49 PDT
The initial PathDirect2D implementation had a few shortcomings:

1. COMPtr<> had no move operator, therefore the Path implementation couldn't move content.
2. Paths (ID2D1GeometryGroups) are frequently built up of ID2D1Geometry elements. But the append operation required retrieving the existing geometries, adding the new item, then loading back into an overall path object. By keeping track of the elements ourselves, we can avoid copying the elements into a temporary vector before building the appended ID2D1GeometryGroup.
3. There are rules about using ID2D1GeometrySink and ID2D1PathGeometry. After calling 'Close' on an ID2D1GeometrySink supplied by a ID2D1PathGeometry, neither should be reused. Nothing prevented this mistake in the PathDirect2D implementation.

This patch cleans up these issues.
Comment 1 Brent Fulgham 2019-09-05 21:28:00 PDT
Created attachment 378158 [details]
Patch
Comment 2 Brent Fulgham 2019-09-05 21:35:26 PDT
Created attachment 378159 [details]
Patch
Comment 3 Fujii Hironori 2019-09-06 00:13:09 PDT
Comment on attachment 378159 [details]
Patch

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

> Source/WebCore/platform/graphics/Path.h:199
>          void drawDidComplete();

Path::drawDidComplete is not used anywhere in WebKit. It should be removed.

> Source/WebCore/platform/graphics/Path.h:215
>          COMPtr<ID2D1PathGeometry> m_activePathGeometry;

m_activePathGeometry is not needed because it is stored in m_geometries and the active path sync is stored in m_activePath.

> Source/WebCore/platform/graphics/win/Direct2DOperations.cpp:498
> +    const_cast<Path&>(path).closeAnyOpenGeometries(D2D1_FIGURE_END_OPEN);

Can you remove `const_cast` by making closeAnyOpenGeometries a mutable method?

> Source/WebCore/platform/graphics/win/PathDirect2D.cpp:118
> +    HRESULT hr = GraphicsContext::systemFactory()->CreateGeometryGroup(fillMode, m_geometries.data(), m_geometries.size(), &m_path);

Path::appendGeometry always create a GeometryGroup by calling CreateGeometryGroup.
Can it be done in Path::closeAnyOpenGeometries?

> Source/WebCore/platform/graphics/win/PathDirect2D.cpp:311
> +        while (m_openFigureCount) {

m_openFigureCount can be 1 or 0. m_openFigureCount can be bool m_isFigureOpened.
Comment 4 Fujii Hironori 2019-09-06 00:27:37 PDT
Comment on attachment 378159 [details]
Patch

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

> Source/WebCore/platform/graphics/win/PathDirect2D.cpp:343
> +        closeAnyOpenGeometries(D2D1_FIGURE_END_OPEN);

You are trying to keep a active path still active even after transforming.
Is this really needed? If so, this is not a right way to do it.
You close the active path with D2D1_FIGURE_END_OPEN, and create a new one.
Comment 5 Brent Fulgham 2019-09-06 10:43:34 PDT
Created attachment 378205 [details]
Patch
Comment 6 Fujii Hironori 2019-09-06 15:48:48 PDT
Comment on attachment 378205 [details]
Patch

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

> Source/WebCore/platform/graphics/win/PathDirect2D.cpp:-220
> -    HRESULT hr = const_cast<Path*>(this)->initializePathState();

Path::initializePathState becomes unused. Remove it.

> Source/WebCore/platform/win/COMPtr.h:175
> +        ptr->Release();

There is no reason to defer calling Release after assignment. Call Release before the assignment.
Comment 7 Brent Fulgham 2019-09-06 16:15:59 PDT
Comment on attachment 378205 [details]
Patch

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

>> Source/WebCore/platform/graphics/win/PathDirect2D.cpp:-220
>> -    HRESULT hr = const_cast<Path*>(this)->initializePathState();
> 
> Path::initializePathState becomes unused. Remove it.

Oh, so it does! Removed.

>> Source/WebCore/platform/win/COMPtr.h:175
>> +        ptr->Release();
> 
> There is no reason to defer calling Release after assignment. Call Release before the assignment.

Will do.
Comment 8 Brent Fulgham 2019-09-06 16:19:11 PDT
Created attachment 378250 [details]
Patch
Comment 9 WebKit Commit Bot 2019-09-06 19:39:31 PDT
Comment on attachment 378250 [details]
Patch

Clearing flags on attachment: 378250

Committed r249604: <https://trac.webkit.org/changeset/249604>
Comment 10 WebKit Commit Bot 2019-09-06 19:39:32 PDT
All reviewed patches have been landed.  Closing bug.
Comment 11 Radar WebKit Bug Importer 2019-09-06 19:40:17 PDT
<rdar://problem/55137930>
Comment 12 Radar WebKit Bug Importer 2019-09-06 19:40:17 PDT
<rdar://problem/55137931>