Changeset 207140 in webkit


Ignore:
Timestamp:
Oct 11, 2016 8:57:39 AM (7 years ago)
Author:
Brent Fulgham
Message:

[Win][Direct2D] Add initial Pattern handling implementation
https://bugs.webkit.org/show_bug.cgi?id=163270

Reviewed by Simon Fraser.

Provide an implemenation of Patterns for Direct2D.

No new tests. Covered by fast/borders/border-image-01.html and others.

  • platform/graphics/GraphicsContext.h:
  • platform/graphics/Pattern.h: Add D2D definitions.
  • platform/graphics/win/GraphicsContextDirect2D.cpp:

(WebCore::GraphicsContext::solidStrokeBrush): Use a more generic return type.
(WebCore::GraphicsContext::solidFillBrush): Ditto.
(WebCore::GraphicsContext::patternStrokeBrush): Added.
(WebCore::GraphicsContext::patternFillBrush): Added.
(WebCore::GraphicsContext::drawPattern): Provide D2D implementation.
(WebCore::GraphicsContext::applyStrokePattern): Ditto.
(WebCore::GraphicsContext::applyFillPattern): Ditto.
(WebCore::GraphicsContext::drawPath): Use stroke pattern if available.
(WebCore::GraphicsContext::fillPath): Use fill pattern if available.
(WebCore::GraphicsContext::strokePath): Use stroke pattern if available.
(WebCore::GraphicsContext::fillRect): Use fill pattern if available.

  • platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h:
  • platform/graphics/win/PatternDirect2D.cpp: Added.
Location:
trunk/Source/WebCore
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207136 r207140  
     12016-10-10  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [Win][Direct2D] Add initial Pattern handling implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=163270
     5
     6        Reviewed by Simon Fraser.
     7
     8        Provide an implemenation of Patterns for Direct2D.
     9
     10        No new tests. Covered by fast/borders/border-image-01.html and others.
     11
     12        * platform/graphics/GraphicsContext.h:
     13        * platform/graphics/Pattern.h: Add D2D definitions.
     14        * platform/graphics/win/GraphicsContextDirect2D.cpp:
     15        (WebCore::GraphicsContext::solidStrokeBrush): Use a more generic return type.
     16        (WebCore::GraphicsContext::solidFillBrush): Ditto.
     17        (WebCore::GraphicsContext::patternStrokeBrush): Added.
     18        (WebCore::GraphicsContext::patternFillBrush): Added.
     19        (WebCore::GraphicsContext::drawPattern): Provide D2D implementation.
     20        (WebCore::GraphicsContext::applyStrokePattern): Ditto.
     21        (WebCore::GraphicsContext::applyFillPattern): Ditto.
     22        (WebCore::GraphicsContext::drawPath): Use stroke pattern if available.
     23        (WebCore::GraphicsContext::fillPath): Use fill pattern if available.
     24        (WebCore::GraphicsContext::strokePath): Use stroke pattern if available.
     25        (WebCore::GraphicsContext::fillRect): Use fill pattern if available.
     26        * platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h:
     27        * platform/graphics/win/PatternDirect2D.cpp: Added.
     28
    1292016-10-11  Per Arne Vollan  <pvollan@apple.com>
    230
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r207002 r207140  
    556556    D2D1_COLOR_F colorWithGlobalAlpha(const Color&) const;
    557557
    558     ID2D1SolidColorBrush* solidStrokeBrush();
    559     ID2D1SolidColorBrush* solidFillBrush();
     558    ID2D1Brush* solidStrokeBrush() const;
     559    ID2D1Brush* solidFillBrush() const;
     560    ID2D1Brush* patternStrokeBrush() const;
     561    ID2D1Brush* patternFillBrush() const;
    560562#endif
    561563#else // PLATFORM(WIN)
  • trunk/Source/WebCore/platform/graphics/Pattern.h

    r207002 r207140  
    3939typedef CGPatternRef PlatformPatternPtr;
    4040#elif USE(DIRECT2D)
    41 typedef void* PlatformPatternPtr;
     41interface ID2D1BitmapBrush;
     42interface ID2D1RenderTarget;
     43typedef ID2D1BitmapBrush* PlatformPatternPtr;
    4244#elif USE(CAIRO)
    4345#include <cairo.h>
     
    6163    void platformDestroy();
    6264
    63     // Pattern space is an abstract space that maps to the default user space by the transformation 'userSpaceTransformation'
     65    // Pattern space is an abstract space that maps to the default user space by the transformation 'userSpaceTransformation'
     66#if !USE(DIRECT2D)
    6467    PlatformPatternPtr createPlatformPattern(const AffineTransform& userSpaceTransformation) const;
     68#else
     69    PlatformPatternPtr createPlatformPattern(ID2D1RenderTarget*, float alpha, const AffineTransform& userSpaceTransformation) const;
     70#endif
    6571    void setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation);
    6672    const AffineTransform& getPatternSpaceTransform() { return m_patternSpaceTransformation; };
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp

    r207020 r207140  
    416416}
    417417
    418 ID2D1SolidColorBrush* GraphicsContext::solidStrokeBrush()
     418ID2D1Brush* GraphicsContext::solidStrokeBrush() const
    419419{
    420420    return m_data->m_solidStrokeBrush.get();
    421421}
    422422
    423 ID2D1SolidColorBrush* GraphicsContext::solidFillBrush()
     423ID2D1Brush* GraphicsContext::solidFillBrush() const
    424424{
    425425    return m_data->m_solidFillBrush.get();
    426426}
    427427
     428ID2D1Brush* GraphicsContext::patternStrokeBrush() const
     429{
     430    return m_data->m_patternStrokeBrush.get();
     431}
     432
     433ID2D1Brush* GraphicsContext::patternFillBrush() const
     434{
     435    return m_data->m_patternFillBrush.get();
     436}
     437
    428438void GraphicsContext::drawPattern(Image& image, const FloatRect& destRect, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, BlendMode blendMode)
    429439{
     
    436446    }
    437447
    438     notImplemented();
     448    auto context = platformContext();
     449    D2DContextStateSaver stateSaver(*m_data);
     450
     451    m_data->clip(destRect);
     452
     453    setPlatformCompositeOperation(op, blendMode);
     454
     455    auto bitmapBrushProperties = D2D1::BitmapBrushProperties();
     456    bitmapBrushProperties.extendModeX = D2D1_EXTEND_MODE_WRAP;
     457    bitmapBrushProperties.extendModeY = D2D1_EXTEND_MODE_WRAP;
     458
     459    // Create a brush transformation so we paint using the section of the image we care about.
     460    AffineTransform transformation = patternTransform;
     461    transformation.translate(destRect.location());
     462
     463    auto brushProperties = D2D1::BrushProperties();
     464    brushProperties.transform = transformation;
     465    brushProperties.opacity = 1.0f;
     466
     467    auto tileImage = image.nativeImageForCurrentFrame();
     468
     469    // If we only want a subset of the bitmap, we need to create a cropped bitmap image. According to the documentation,
     470    // this does not allocate new bitmap memory.
     471    if (image.width() > destRect.width() || image.height() > destRect.height()) {
     472        float dpiX = 0;
     473        float dpiY = 0;
     474        tileImage->GetDpi(&dpiX, &dpiY);
     475        auto bitmapProperties = D2D1::BitmapProperties(tileImage->GetPixelFormat(), dpiX, dpiY);
     476        COMPtr<ID2D1Bitmap> subImage;
     477        HRESULT hr = context->CreateBitmap(IntSize(tileRect.size()), bitmapProperties, &subImage);
     478        if (SUCCEEDED(hr)) {
     479            D2D1_RECT_U finishRect = IntRect(tileRect);
     480            hr = subImage->CopyFromBitmap(nullptr, tileImage.get(), &finishRect);
     481            if (SUCCEEDED(hr))
     482                tileImage = subImage;
     483        }
     484    }
     485
     486    COMPtr<ID2D1BitmapBrush> patternBrush;
     487    HRESULT hr = context->CreateBitmapBrush(tileImage.get(), &bitmapBrushProperties, &brushProperties, &patternBrush);
     488
     489    drawWithoutShadow(destRect, [this, destRect, patternBrush](ID2D1RenderTarget* renderTarget) {
     490        const D2D1_RECT_F d2dRect = destRect;
     491        renderTarget->FillRectangle(&d2dRect, patternBrush.get());
     492    });
    439493}
    440494
     
    701755        return;
    702756
    703     // Note: Because of the way Direct2D draws, we may not need this explicit context 'set stroke pattern' logic.
    704     notImplemented();
     757    auto context = platformContext();
     758    AffineTransform userToBaseCTM; // FIXME: This isn't really needed on Windows
     759
     760    const float patternAlpha = 1;
     761    m_data->m_patternStrokeBrush = adoptCOM(m_state.strokePattern->createPlatformPattern(context, patternAlpha, userToBaseCTM));
    705762}
    706763
     
    710767        return;
    711768
    712     // Note: Because of the way Direct2D draws, we may not need this explicit context 'set fill pattern' logic.
    713     notImplemented();
     769    auto context = platformContext();
     770    AffineTransform userToBaseCTM; // FIXME: This isn't really needed on Windows
     771
     772    const float patternAlpha = 1;
     773    m_data->m_patternFillBrush = adoptCOM(m_state.fillPattern->createPlatformPattern(context, patternAlpha, userToBaseCTM));
    714774}
    715775
     
    748808    auto rect = path.fastBoundingRect();
    749809    drawWithoutShadow(rect, [this, &path](ID2D1RenderTarget* renderTarget) {
    750         renderTarget->DrawGeometry(path.platformPath(), solidStrokeBrush(), strokeThickness(), m_data->strokeStyle());
     810        auto brush = m_state.strokePattern ? patternStrokeBrush() : solidStrokeBrush();
     811        renderTarget->DrawGeometry(path.platformPath(), brush, strokeThickness(), m_data->strokeStyle());
    751812    });
    752813}
     
    871932    FloatRect contextRect(FloatPoint(), context->GetSize());
    872933    drawWithoutShadow(contextRect, [this, &pathToFill](ID2D1RenderTarget* renderTarget) {
    873         renderTarget->FillGeometry(pathToFill.get(), solidFillBrush());
     934        auto brush = m_state.fillPattern ? patternFillBrush() : solidFillBrush();
     935        renderTarget->FillGeometry(pathToFill.get(), brush);
    874936    });
    875937}
     
    913975    FloatRect contextRect(FloatPoint(), context->GetSize());
    914976    drawWithoutShadow(contextRect, [this, &path](ID2D1RenderTarget* renderTarget) {
    915         renderTarget->DrawGeometry(path.platformPath(), solidStrokeBrush(), strokeThickness(), m_data->strokeStyle());
     977        auto brush = m_state.strokePattern ? patternStrokeBrush() : solidStrokeBrush();
     978        renderTarget->DrawGeometry(path.platformPath(), brush, strokeThickness(), m_data->strokeStyle());
    916979    });
    917980}
     
    9591022    drawWithoutShadow(rect, [this, rect](ID2D1RenderTarget* renderTarget) {
    9601023        const D2D1_RECT_F d2dRect = rect;
    961         renderTarget->FillRectangle(&d2dRect, solidFillBrush());
     1024        auto brush = m_state.fillPattern ? patternFillBrush() : solidFillBrush();
     1025        renderTarget->FillRectangle(&d2dRect, brush);
    9621026    });
    9631027}
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h

    r207020 r207140  
    8585    COMPtr<ID2D1SolidColorBrush> m_solidStrokeBrush;
    8686    COMPtr<ID2D1SolidColorBrush> m_solidFillBrush;
     87    COMPtr<ID2D1BitmapBrush> m_patternStrokeBrush;
     88    COMPtr<ID2D1BitmapBrush> m_patternFillBrush;
    8789
    8890private:
Note: See TracChangeset for help on using the changeset viewer.