Changeset 207140 in webkit
- Timestamp:
- Oct 11, 2016 8:57:39 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207136 r207140 1 2016-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 1 29 2016-10-11 Per Arne Vollan <pvollan@apple.com> 2 30 -
trunk/Source/WebCore/platform/graphics/GraphicsContext.h
r207002 r207140 556 556 D2D1_COLOR_F colorWithGlobalAlpha(const Color&) const; 557 557 558 ID2D1SolidColorBrush* solidStrokeBrush(); 559 ID2D1SolidColorBrush* solidFillBrush(); 558 ID2D1Brush* solidStrokeBrush() const; 559 ID2D1Brush* solidFillBrush() const; 560 ID2D1Brush* patternStrokeBrush() const; 561 ID2D1Brush* patternFillBrush() const; 560 562 #endif 561 563 #else // PLATFORM(WIN) -
trunk/Source/WebCore/platform/graphics/Pattern.h
r207002 r207140 39 39 typedef CGPatternRef PlatformPatternPtr; 40 40 #elif USE(DIRECT2D) 41 typedef void* PlatformPatternPtr; 41 interface ID2D1BitmapBrush; 42 interface ID2D1RenderTarget; 43 typedef ID2D1BitmapBrush* PlatformPatternPtr; 42 44 #elif USE(CAIRO) 43 45 #include <cairo.h> … … 61 63 void platformDestroy(); 62 64 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) 64 67 PlatformPatternPtr createPlatformPattern(const AffineTransform& userSpaceTransformation) const; 68 #else 69 PlatformPatternPtr createPlatformPattern(ID2D1RenderTarget*, float alpha, const AffineTransform& userSpaceTransformation) const; 70 #endif 65 71 void setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation); 66 72 const AffineTransform& getPatternSpaceTransform() { return m_patternSpaceTransformation; }; -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp
r207020 r207140 416 416 } 417 417 418 ID2D1 SolidColorBrush* GraphicsContext::solidStrokeBrush()418 ID2D1Brush* GraphicsContext::solidStrokeBrush() const 419 419 { 420 420 return m_data->m_solidStrokeBrush.get(); 421 421 } 422 422 423 ID2D1 SolidColorBrush* GraphicsContext::solidFillBrush()423 ID2D1Brush* GraphicsContext::solidFillBrush() const 424 424 { 425 425 return m_data->m_solidFillBrush.get(); 426 426 } 427 427 428 ID2D1Brush* GraphicsContext::patternStrokeBrush() const 429 { 430 return m_data->m_patternStrokeBrush.get(); 431 } 432 433 ID2D1Brush* GraphicsContext::patternFillBrush() const 434 { 435 return m_data->m_patternFillBrush.get(); 436 } 437 428 438 void GraphicsContext::drawPattern(Image& image, const FloatRect& destRect, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, BlendMode blendMode) 429 439 { … … 436 446 } 437 447 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 }); 439 493 } 440 494 … … 701 755 return; 702 756 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)); 705 762 } 706 763 … … 710 767 return; 711 768 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)); 714 774 } 715 775 … … 748 808 auto rect = path.fastBoundingRect(); 749 809 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()); 751 812 }); 752 813 } … … 871 932 FloatRect contextRect(FloatPoint(), context->GetSize()); 872 933 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); 874 936 }); 875 937 } … … 913 975 FloatRect contextRect(FloatPoint(), context->GetSize()); 914 976 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()); 916 979 }); 917 980 } … … 959 1022 drawWithoutShadow(rect, [this, rect](ID2D1RenderTarget* renderTarget) { 960 1023 const D2D1_RECT_F d2dRect = rect; 961 renderTarget->FillRectangle(&d2dRect, solidFillBrush()); 1024 auto brush = m_state.fillPattern ? patternFillBrush() : solidFillBrush(); 1025 renderTarget->FillRectangle(&d2dRect, brush); 962 1026 }); 963 1027 } -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextPlatformPrivateDirect2D.h
r207020 r207140 85 85 COMPtr<ID2D1SolidColorBrush> m_solidStrokeBrush; 86 86 COMPtr<ID2D1SolidColorBrush> m_solidFillBrush; 87 COMPtr<ID2D1BitmapBrush> m_patternStrokeBrush; 88 COMPtr<ID2D1BitmapBrush> m_patternFillBrush; 87 89 88 90 private:
Note: See TracChangeset
for help on using the changeset viewer.