Changeset 207863 in webkit


Ignore:
Timestamp:
Oct 25, 2016 6:57:44 PM (7 years ago)
Author:
Brent Fulgham
Message:

[Win][Direct2D] Use smart pointers for Direct2D Path types
https://bugs.webkit.org/show_bug.cgi?id=163994

Reviewed by Alex Christensen.

Tested by existing path tests.

  • platform/graphics/Path.h:

(WebCore::Path::platformPath): Use a COMPtr for m_path.

  • platform/graphics/win/GraphicsContextDirect2D.cpp:

(WebCore::GraphicsContext::systemFactory): Present better D2D debug output
when running a debug build.
(WebCore::GraphicsContext::platformInit): Initialize a D2D device from a
native GDI device context.
(WebCore::GraphicsContext::platformStrokeStyle): Added.
(WebCore::GraphicsContext::clipBounds): Simplify clip boundary calculations and
avoid doing math on infinities.

  • platform/graphics/win/PathDirect2D.cpp:

(WebCore::scratchRenderTarget): Added.
(WebCore::Path::~Path): Switch to COMPtr implementation.
(WebCore::Path::ensurePlatformPath): Ditto.
(WebCore::Path::appendGeometry): Ditto.
(WebCore::Path::operator=): Ditto.
(WebCore::Path::initializePathState): Ditto.
(WebCore::Path::strokeContains): Provide an implementation.
(WebCore::Path::transform): Ditto.
(WebCore::Path::addEllipse): No need for explicit construction of the
D2D1::Point2F object.
(WebCore::Path::clear): Switch to COMPtr implementation.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207860 r207863  
     12016-10-25  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [Win][Direct2D] Use smart pointers for Direct2D Path types
     4        https://bugs.webkit.org/show_bug.cgi?id=163994
     5
     6        Reviewed by Alex Christensen.
     7
     8        Tested by existing path tests.
     9
     10        * platform/graphics/Path.h:
     11        (WebCore::Path::platformPath): Use a COMPtr for m_path.
     12        * platform/graphics/win/GraphicsContextDirect2D.cpp:
     13        (WebCore::GraphicsContext::systemFactory): Present better D2D debug output
     14        when running a debug build.
     15        (WebCore::GraphicsContext::platformInit): Initialize a D2D device from a
     16        native GDI device context.
     17        (WebCore::GraphicsContext::platformStrokeStyle): Added.
     18        (WebCore::GraphicsContext::clipBounds): Simplify clip boundary calculations and
     19        avoid doing math on infinities.
     20        * platform/graphics/win/PathDirect2D.cpp:
     21        (WebCore::scratchRenderTarget): Added.
     22        (WebCore::Path::~Path): Switch to COMPtr implementation.
     23        (WebCore::Path::ensurePlatformPath): Ditto.
     24        (WebCore::Path::appendGeometry): Ditto.
     25        (WebCore::Path::operator=): Ditto.
     26        (WebCore::Path::initializePathState): Ditto.
     27        (WebCore::Path::strokeContains): Provide an implementation.
     28        (WebCore::Path::transform): Ditto.
     29        (WebCore::Path::addEllipse): No need for explicit construction of the
     30        D2D1::Point2F object.
     31        (WebCore::Path::clear): Switch to COMPtr implementation.
     32
    1332016-10-25  Nan Wang  <n_wang@apple.com>
    234
  • trunk/Source/WebCore/platform/graphics/Path.h

    r206815 r207863  
    166166        // To keep Path() cheap, it does not allocate a PlatformPath immediately
    167167        // meaning Path::platformPath() can return null.
     168#if USE(DIRECT2D)
     169        PlatformPathPtr platformPath() const { return m_path.get(); }
     170#else
    168171        PlatformPathPtr platformPath() const { return m_path; }
     172#endif
    169173        // ensurePlatformPath() will allocate a PlatformPath if it has not yet been and will never return null.
    170174        WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath();
     
    200204
    201205    private:
    202         PlatformPathPtr m_path { nullptr };
    203206#if USE(DIRECT2D)
     207        COMPtr<ID2D1GeometryGroup> m_path;
    204208        COMPtr<ID2D1PathGeometry> m_activePathGeometry;
    205209        COMPtr<ID2D1GeometrySink> m_activePath;
     210#else
     211        PlatformPathPtr m_path { nullptr };
    206212#endif
    207213    };
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp

    r207681 r207863  
    7272    static ID2D1Factory* direct2DFactory = nullptr;
    7373    if (!direct2DFactory) {
     74#ifndef NDEBUG
     75        D2D1_FACTORY_OPTIONS options = { };
     76        options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
     77        HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, options, &direct2DFactory);
     78#else
    7479        HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &direct2DFactory);
     80#endif
    7581        RELEASE_ASSERT(SUCCEEDED(hr));
    7682    }
     
    109115        return;
    110116
    111     COMPtr<ID2D1RenderTarget> renderTarget;
     117    HBITMAP bitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP));
     118
     119    DIBPixelData pixelData(bitmap);
     120
     121    auto targetProperties = D2D1::RenderTargetProperties();
     122    targetProperties.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE);
     123
     124    COMPtr<ID2D1DCRenderTarget> renderTarget;
     125    HRESULT hr = systemFactory()->CreateDCRenderTarget(&targetProperties, &renderTarget);
     126    if (!SUCCEEDED(hr))
     127        return;
     128
     129    RECT clientRect = IntRect(IntPoint(), pixelData.size());
     130    hr = renderTarget->BindDC(hdc, &clientRect);
     131    if (!SUCCEEDED(hr))
     132        return;
     133
    112134    m_data = new GraphicsContextPlatformPrivate(renderTarget.get());
    113135    m_data->m_hdc = hdc;
     
    672694}
    673695
     696ID2D1StrokeStyle* GraphicsContext::platformStrokeStyle() const
     697{
     698    return m_data->strokeStyle();
     699}
     700
    674701// This is only used to draw borders.
    675702void GraphicsContext::drawLine(const FloatPoint& point1, const FloatPoint& point2)
     
    12491276    }
    12501277
    1251     D2D1_RECT_F d2dClipBounds = D2D1::InfiniteRect();
    1252     FloatRect clipBounds(d2dClipBounds.left, d2dClipBounds.top, d2dClipBounds.right - d2dClipBounds.left, d2dClipBounds.bottom - d2dClipBounds.top);
    1253 
    1254     if (m_data->clipLayer()) {
    1255         auto clipSize = m_data->clipLayer()->GetSize();
    1256         clipBounds.setWidth(clipSize.width);
    1257         clipBounds.setHeight(clipSize.height);
    1258     }
     1278    D2D1_SIZE_F clipSize;
     1279    if (auto clipLayer = m_data->clipLayer())
     1280        clipSize = clipLayer->GetSize();
     1281    else
     1282        clipSize = platformContext()->GetSize();
     1283
     1284    FloatRect clipBounds(IntPoint(), clipSize);
    12591285
    12601286    return enclosingIntRect(clipBounds);
  • trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp

    r207681 r207863  
    4343namespace WebCore {
    4444
     45static inline ID2D1RenderTarget* scratchRenderTarget()
     46{
     47    static COMPtr<ID2D1RenderTarget> renderTarget = adoptCOM(GraphicsContext::defaultRenderTarget());
     48    return renderTarget.get();
     49}
    4550
    4651Path Path::polygonPathFromPoints(const Vector<FloatPoint>& points)
     
    7176Path::~Path()
    7277{
    73     if (m_path)
    74         m_path->Release();
    7578}
    7679
     
    8487    }
    8588
    86     return m_path;
     89    return m_path.get();
    8790}
    8891
     
    102105    auto fillMode = m_path ? m_path->GetFillMode() : D2D1_FILL_MODE_WINDING;
    103106
    104     COMPtr<ID2D1GeometryGroup> protectedPath = adoptCOM(m_path);
     107    COMPtr<ID2D1GeometryGroup> protectedPath = m_path;
    105108    m_path = nullptr;
    106109
     
    163166Path& Path::operator=(const Path& other)
    164167{
    165     if (m_path)
    166         m_path->Release();
    167 
    168168    m_path = other.m_path;
    169     if (m_path)
    170         m_path->AddRef();
    171 
    172169    m_activePath = other.m_activePath;
    173170    m_activePathGeometry = other.m_activePathGeometry;
     
    178175HRESULT Path::initializePathState()
    179176{
    180     if (m_path)
    181         m_path->Release();
    182177    m_path = nullptr;
    183178    m_activePath = nullptr;
     
    232227        return false;
    233228
    234     UNUSED_PARAM(applier);
    235     UNUSED_PARAM(point);
    236     notImplemented();
    237     return false;
     229    ASSERT(applier);
     230
     231    GraphicsContext scratchContext(scratchRenderTarget());
     232    applier->strokeStyle(&scratchContext);
     233
     234    BOOL containsPoint = false;
     235    HRESULT hr = m_path->StrokeContainsPoint(point, scratchContext.strokeThickness(), scratchContext.platformStrokeStyle(), nullptr, 1.0f, &containsPoint);
     236    if (!SUCCEEDED(hr))
     237        return false;
     238
     239    return containsPoint;
    238240}
    239241
     
    258260    const D2D1_MATRIX_3X2_F& d2dTransform = static_cast<const D2D1_MATRIX_3X2_F>(transform);
    259261    COMPtr<ID2D1TransformedGeometry> transformedPath;
    260     if (!SUCCEEDED(GraphicsContext::systemFactory()->CreateTransformedGeometry(m_path, d2dTransform, &transformedPath)))
     262    if (!SUCCEEDED(GraphicsContext::systemFactory()->CreateTransformedGeometry(m_path.get(), d2dTransform, &transformedPath)))
    261263        return;
    262264
     
    272274    auto fillMode = m_path->GetFillMode();
    273275
    274     m_path->Release();
    275276    m_path = nullptr;
    276277
     
    477478{
    478479    COMPtr<ID2D1EllipseGeometry> ellipse;
    479     HRESULT hr = GraphicsContext::systemFactory()->CreateEllipseGeometry(D2D1::Ellipse(D2D1::Point2F(r.center().x(), r.center().y()), r.width(), r.height()), &ellipse);
     480    HRESULT hr = GraphicsContext::systemFactory()->CreateEllipseGeometry(D2D1::Ellipse(r.center(), r.width(), r.height()), &ellipse);
    480481    RELEASE_ASSERT(SUCCEEDED(hr));
    481482    appendGeometry(ellipse.get());
     
    498499    if (isNull())
    499500        return;
    500 
    501     if (m_path)
    502         m_path->Release();
    503501
    504502    m_path = nullptr;
Note: See TracChangeset for help on using the changeset viewer.