Changeset 190894 in webkit
- Timestamp:
- Oct 12, 2015, 3:36:03 PM (10 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
platform/graphics/cg/GraphicsContextCG.cpp (modified) (23 diffs)
-
platform/graphics/cg/GraphicsContextCG.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r190893 r190894 1 2015-10-12 Simon Fraser <simon.fraser@apple.com> 2 3 Add a CGContextStateSaver and use it 4 https://bugs.webkit.org/show_bug.cgi?id=150049 5 6 Reviewed by Tim Horton. 7 8 Add a stack-based graphics state save/restore class for CGContext, 9 like the one we have for GraphicsContext, and use it in GraphicsContextCG. 10 11 * platform/graphics/cg/GraphicsContextCG.cpp: 12 (WebCore::GraphicsContext::drawNativeImage): 13 (WebCore::GraphicsContext::drawLine): 14 (WebCore::GraphicsContext::drawJoinedLines): 15 (WebCore::GraphicsContext::fillPath): 16 (WebCore::GraphicsContext::strokePath): 17 (WebCore::GraphicsContext::fillRect): 18 (WebCore::GraphicsContext::platformFillRoundedRect): 19 (WebCore::GraphicsContext::fillRectWithRoundedHole): 20 (WebCore::GraphicsContext::strokeRect): 21 * platform/graphics/cg/GraphicsContextCG.h: 22 (WebCore::CGContextStateSaver::CGContextStateSaver): 23 (WebCore::CGContextStateSaver::~CGContextStateSaver): 24 (WebCore::CGContextStateSaver::save): 25 (WebCore::CGContextStateSaver::restore): 26 1 27 2015-10-12 Zalan Bujtas <zalan@apple.com> 2 28 -
trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
r189144 r190894 155 155 156 156 CGContextRef context = platformContext(); 157 CGContextS aveGState(context);157 CGContextStateSaver stateSaver(context); 158 158 159 159 #if PLATFORM(IOS) … … 242 242 // Draw the image. 243 243 CGContextDrawImage(context, adjustedDestRect, image.get()); 244 245 CGContextRestoreGState(context);246 244 } 247 245 … … 293 291 294 292 CGContextRef context = platformContext(); 293 295 294 StrokeStyle strokeStyle = this->strokeStyle(); 296 295 float cornerWidth = 0; 297 296 bool drawsDashedLine = strokeStyle == DottedStroke || strokeStyle == DashedStroke; 298 297 298 CGContextStateSaver stateSaver(context, drawsDashedLine); 299 299 if (drawsDashedLine) { 300 CGContextSaveGState(context);301 300 // Figure out end points to ensure we always paint corners. 302 301 cornerWidth = strokeStyle == DottedStroke ? thickness : std::min(2 * thickness, std::max(thickness, strokeWidth / 3)); … … 312 311 float patternWidth = strokeStyle == DottedStroke ? thickness : std::min(3 * thickness, std::max(thickness, strokeWidth / 3)); 313 312 // Check if corner drawing sufficiently covers the line. 314 if (strokeWidth <= patternWidth + 1) { 315 CGContextRestoreGState(context); 313 if (strokeWidth <= patternWidth + 1) 316 314 return; 317 }318 315 319 316 // Pattern starts with full fill and ends with the empty fill. … … 363 360 CGContextAddLineToPoint(context, p2.x(), p2.y()); 364 361 CGContextStrokePath(context); 365 if (drawsDashedLine)366 CGContextRestoreGState(context);367 362 if (shouldAntialias()) 368 363 CGContextSetShouldAntialias(context, true); … … 378 373 float width = CGContextGetLineWidth(context); 379 374 380 CGContextS aveGState(context);375 CGContextStateSaver stateSaver(context); 381 376 382 377 CGContextSetShouldAntialias(context, antialias); 383 384 378 CGContextSetLineWidth(context, width < 1 ? 1 : width); 385 386 379 CGContextBeginPath(context); 387 388 380 CGContextSetLineCap(context, lineCap); 389 390 381 CGContextMoveToPoint(context, points[0].x, points[0].y); 391 382 … … 394 385 395 386 CGContextStrokePath(context); 396 397 CGContextRestoreGState(context);398 387 } 399 388 #endif … … 589 578 CGContextBeginPath(context); 590 579 CGContextAddPath(context, path.platformPath()); 591 CGContextS aveGState(context);580 CGContextStateSaver stateSaver(context); 592 581 CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform()); 593 582 … … 598 587 599 588 m_state.fillGradient->paint(this); 600 CGContextRestoreGState(context);601 589 } 602 590 … … 655 643 CGLayerRelease(layer); 656 644 } else { 657 CGContextS aveGState(context);645 CGContextStateSaver stateSaver(context); 658 646 CGContextReplacePathWithStrokedPath(context); 659 647 CGContextClip(context); 660 648 CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform()); 661 649 m_state.strokeGradient->paint(this); 662 CGContextRestoreGState(context);663 650 } 664 651 return; … … 678 665 679 666 if (m_state.fillGradient) { 680 CGContextS aveGState(context);667 CGContextStateSaver stateSaver(context); 681 668 if (hasShadow()) { 682 669 FloatSize layerSize = getCTM().mapSize(rect.size()); … … 699 686 m_state.fillGradient->paint(this); 700 687 } 701 CGContextRestoreGState(context);702 688 return; 703 689 } … … 707 693 708 694 bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow() && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. 695 CGContextStateSaver stateSaver(context, drawOwnShadow); 709 696 if (drawOwnShadow) { 710 697 // Turn off CG shadows. 711 CGContextSaveGState(context);712 698 CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0); 713 699 … … 717 703 718 704 CGContextFillRect(context, rect); 719 720 if (drawOwnShadow)721 CGContextRestoreGState(context);722 705 } 723 706 … … 735 718 736 719 bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow() && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. 720 CGContextStateSaver stateSaver(context, drawOwnShadow); 737 721 if (drawOwnShadow) { 738 722 // Turn off CG shadows. 739 CGContextSaveGState(context);740 723 CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0); 741 724 … … 747 730 748 731 if (drawOwnShadow) 749 CGContextRestoreGState(context);732 stateSaver.restore(); 750 733 751 734 if (oldFillColor != color || oldColorSpace != colorSpace) … … 766 749 767 750 bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow() && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet. 751 CGContextStateSaver stateSaver(context, drawOwnShadow); 768 752 if (drawOwnShadow) { 769 753 // Turn off CG shadows. 770 CGContextSaveGState(context);771 754 CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0); 772 755 … … 789 772 790 773 if (drawOwnShadow) 791 CGContextRestoreGState(context);774 stateSaver.restore(); 792 775 793 776 if (oldFillColor != color || oldColorSpace != colorSpace) … … 819 802 // fillRectWithRoundedHole() assumes that the edges of rect are clipped out, so we only care about shadows cast around inside the hole. 820 803 bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow() && !m_state.shadowsIgnoreTransforms; 804 CGContextStateSaver stateSaver(context, drawOwnShadow); 821 805 if (drawOwnShadow) { 822 806 // Turn off CG shadows. 823 CGContextSaveGState(context);824 807 CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0); 825 808 … … 831 814 832 815 if (drawOwnShadow) 833 CGContextRestoreGState(context);816 stateSaver.restore(); 834 817 835 818 setFillRule(oldFillRule); … … 1047 1030 CGLayerRelease(layer); 1048 1031 } else { 1049 CGContextS aveGState(context);1032 CGContextStateSaver stateSaver(context); 1050 1033 setStrokeThickness(lineWidth); 1051 1034 CGContextAddRect(context, rect); … … 1054 1037 CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform()); 1055 1038 m_state.strokeGradient->paint(this); 1056 CGContextRestoreGState(context);1057 1039 } 1058 1040 return; … … 1067 1049 // apply some attributes of the graphics state in certain cases 1068 1050 // (as identified in https://bugs.webkit.org/show_bug.cgi?id=132948) 1069 CGContextS aveGState(context);1051 CGContextStateSaver stateSaver(context); 1070 1052 setStrokeThickness(lineWidth); 1071 1053 1072 1054 CGContextAddRect(context, rect); 1073 1055 CGContextStrokePath(context); 1074 1075 CGContextRestoreGState(context);1076 1056 } 1077 1057 -
trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h
r172849 r190894 51 51 } 52 52 53 class CGContextStateSaver { 54 public: 55 CGContextStateSaver(CGContextRef context, bool saveAndRestore = true) 56 : m_context(context) 57 , m_saveAndRestore(saveAndRestore) 58 { 59 if (m_saveAndRestore) 60 CGContextSaveGState(m_context); 61 } 62 63 ~CGContextStateSaver() 64 { 65 if (m_saveAndRestore) 66 CGContextRestoreGState(m_context); 67 } 68 69 void save() 70 { 71 ASSERT(!m_saveAndRestore); 72 CGContextSaveGState(m_context); 73 m_saveAndRestore = true; 74 } 75 76 void restore() 77 { 78 ASSERT(m_saveAndRestore); 79 CGContextRestoreGState(m_context); 80 m_saveAndRestore = false; 81 } 82 83 private: 84 CGContextRef m_context; 85 bool m_saveAndRestore; 86 }; 87 53 88 } 54 89
Note:
See TracChangeset
for help on using the changeset viewer.