Diff
Modified: trunk/Source/WebCore/ChangeLog (291363 => 291364)
--- trunk/Source/WebCore/ChangeLog 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/ChangeLog 2022-03-16 20:52:19 UTC (rev 291364)
@@ -1,3 +1,99 @@
+2022-03-16 Said Abou-Hallawa <[email protected]>
+
+ [GPU Process] Move other classes out of GraphicsContext.h
+ https://bugs.webkit.org/show_bug.cgi?id=237944
+
+ Reviewed by Simon Fraser.
+
+ This is a step towards making GraphicsContextState a class and move
+ more functionalities to it.
+
+ * Headers.cmake:
+ * PlatformAppleWin.cmake:
+ * PlatformMac.cmake:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/GraphicsContext.cpp:
+ (WebCore::TextBoxIterator::TextBoxIterator): Deleted.
+ (WebCore::TextBoxIterator::offset const): Deleted.
+ (WebCore::TextBoxIterator::increment): Deleted.
+ (WebCore::TextBoxIterator::atEnd const): Deleted.
+ (WebCore::TextBoxIterator::current const): Deleted.
+ (WebCore::TextBoxIterator::direction const): Deleted.
+ (WebCore::TextBoxIterator::operator== const): Deleted.
+ (WebCore::TextBoxIterator::operator!= const): Deleted.
+ (WebCore::GraphicsContextState::GraphicsContextState): Deleted.
+ (WebCore::GraphicsContextState::mergeChanges): Deleted.
+ (WebCore::GraphicsContextStateChange::changesFromState const): Deleted.
+ (WebCore::GraphicsContextStateChange::accumulate): Deleted.
+ (WebCore::GraphicsContextStateChange::apply const): Deleted.
+ (WebCore::GraphicsContextStateChange::dump const): Deleted.
+ (WebCore::operator<<): Deleted.
+ * platform/graphics/GraphicsContext.h:
+ (WebCore::DocumentMarkerLineStyle::encode const): Deleted.
+ (WebCore::DocumentMarkerLineStyle::decode): Deleted.
+ (WebCore::GraphicsContextStateChange::GraphicsContextStateChange): Deleted.
+ (WebCore::GraphicsContextStateSaver::GraphicsContextStateSaver): Deleted.
+ (WebCore::GraphicsContextStateSaver::~GraphicsContextStateSaver): Deleted.
+ (WebCore::GraphicsContextStateSaver::save): Deleted.
+ (WebCore::GraphicsContextStateSaver::restore): Deleted.
+ (WebCore::GraphicsContextStateSaver::context const): Deleted.
+ (WebCore::TransparencyLayerScope::TransparencyLayerScope): Deleted.
+ (WebCore::TransparencyLayerScope::beginLayer): Deleted.
+ (WebCore::TransparencyLayerScope::~TransparencyLayerScope): Deleted.
+ (WebCore::GraphicsContextStateStackChecker::GraphicsContextStateStackChecker): Deleted.
+ (WebCore::GraphicsContextStateStackChecker::~GraphicsContextStateStackChecker): Deleted.
+ (WebCore::InterpolationQualityMaintainer::InterpolationQualityMaintainer): Deleted.
+ (WebCore::InterpolationQualityMaintainer::~InterpolationQualityMaintainer): Deleted.
+ * platform/graphics/GraphicsContextState.cpp: Added.
+ (WebCore::GraphicsContextState::GraphicsContextState):
+ (WebCore::GraphicsContextState::mergeChanges):
+ (WebCore::GraphicsContextStateChange::changesFromState const):
+ (WebCore::GraphicsContextStateChange::accumulate):
+ (WebCore::GraphicsContextStateChange::apply const):
+ (WebCore::GraphicsContextStateChange::dump const):
+ (WebCore::operator<<):
+ * platform/graphics/GraphicsContextState.h: Added.
+ (WebCore::GraphicsContextStateChange::GraphicsContextStateChange):
+ * platform/graphics/GraphicsContextStateSaver.h: Added.
+ (WebCore::GraphicsContextStateSaver::GraphicsContextStateSaver):
+ (WebCore::GraphicsContextStateSaver::~GraphicsContextStateSaver):
+ (WebCore::GraphicsContextStateSaver::save):
+ (WebCore::GraphicsContextStateSaver::restore):
+ (WebCore::GraphicsContextStateSaver::context const):
+ (WebCore::TransparencyLayerScope::TransparencyLayerScope):
+ (WebCore::TransparencyLayerScope::beginLayer):
+ (WebCore::TransparencyLayerScope::~TransparencyLayerScope):
+ (WebCore::GraphicsContextStateStackChecker::GraphicsContextStateStackChecker):
+ (WebCore::GraphicsContextStateStackChecker::~GraphicsContextStateStackChecker):
+ (WebCore::InterpolationQualityMaintainer::InterpolationQualityMaintainer):
+ (WebCore::InterpolationQualityMaintainer::~InterpolationQualityMaintainer):
+ * platform/graphics/GraphicsTypes.h:
+ (WebCore::DocumentMarkerLineStyle::encode const):
+ (WebCore::DocumentMarkerLineStyle::decode):
+ * platform/graphics/PlatformGraphicsContext.h: Added.
+ * platform/graphics/TextBoxIterator.h: Added.
+ (WebCore::TextBoxIterator::TextBoxIterator):
+ (WebCore::TextBoxIterator::offset const):
+ (WebCore::TextBoxIterator::increment):
+ (WebCore::TextBoxIterator::atEnd const):
+ (WebCore::TextBoxIterator::current const):
+ (WebCore::TextBoxIterator::direction const):
+ (WebCore::TextBoxIterator::operator== const):
+ (WebCore::TextBoxIterator::operator!= const):
+ * platform/graphics/cg/CGContextStateSaver.h: Added.
+ (WebCore::CGContextStateSaver::CGContextStateSaver):
+ (WebCore::CGContextStateSaver::~CGContextStateSaver):
+ (WebCore::CGContextStateSaver::save):
+ (WebCore::CGContextStateSaver::restore):
+ (WebCore::CGContextStateSaver::didSave const):
+ * platform/graphics/cg/GraphicsContextCG.h:
+ (WebCore::CGContextStateSaver::CGContextStateSaver): Deleted.
+ (WebCore::CGContextStateSaver::~CGContextStateSaver): Deleted.
+ (WebCore::CGContextStateSaver::save): Deleted.
+ (WebCore::CGContextStateSaver::restore): Deleted.
+ (WebCore::CGContextStateSaver::didSave const): Deleted.
+
2022-03-16 Eric Carlson <[email protected]>
[iOS] WebAVMediaSelectionOption should implement -mediaType
Modified: trunk/Source/WebCore/Headers.cmake (291363 => 291364)
--- trunk/Source/WebCore/Headers.cmake 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/Headers.cmake 2022-03-16 20:52:19 UTC (rev 291364)
@@ -1491,6 +1491,8 @@
platform/graphics/GraphicsContextGL.h
platform/graphics/GraphicsContextGLAttributes.h
platform/graphics/GraphicsContextGLState.h
+ platform/graphics/GraphicsContextState.h
+ platform/graphics/GraphicsContextStateSaver.h
platform/graphics/GraphicsLayer.h
platform/graphics/GraphicsLayerContentsDisplayDelegate.h
platform/graphics/GraphicsLayerClient.h
@@ -1550,6 +1552,7 @@
platform/graphics/PlatformAudioTrackConfiguration.h
platform/graphics/PlatformColorSpace.h
platform/graphics/PlatformDisplay.h
+ platform/graphics/PlatformGraphicsContext.h
platform/graphics/PlatformImage.h
platform/graphics/PlatformImageBuffer.h
platform/graphics/PlatformImageBufferBackend.h
Modified: trunk/Source/WebCore/PlatformAppleWin.cmake (291363 => 291364)
--- trunk/Source/WebCore/PlatformAppleWin.cmake 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/PlatformAppleWin.cmake 2022-03-16 20:52:19 UTC (rev 291364)
@@ -156,6 +156,7 @@
platform/graphics/ca/win/CACFLayerTreeHostClient.h
platform/graphics/ca/win/PlatformCALayerWin.h
+ platform/graphics/cg/CGContextStateSaver.h
platform/graphics/cg/ColorSpaceCG.h
platform/graphics/cg/GradientRendererCG.h
platform/graphics/cg/GraphicsContextCG.h
Modified: trunk/Source/WebCore/PlatformMac.cmake (291363 => 291364)
--- trunk/Source/WebCore/PlatformMac.cmake 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/PlatformMac.cmake 2022-03-16 20:52:19 UTC (rev 291364)
@@ -640,6 +640,7 @@
platform/graphics/ca/cocoa/PlatformCALayerCocoa.h
platform/graphics/ca/cocoa/WebVideoContainerLayer.h
+ platform/graphics/cg/CGContextStateSaver.h
platform/graphics/cg/ColorSpaceCG.h
platform/graphics/cg/GraphicsContextCG.h
platform/graphics/cg/IOSurfacePool.h
Modified: trunk/Source/WebCore/Sources.txt (291363 => 291364)
--- trunk/Source/WebCore/Sources.txt 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/Sources.txt 2022-03-16 20:52:19 UTC (rev 291364)
@@ -2045,6 +2045,7 @@
platform/graphics/GraphicsContext.cpp
platform/graphics/GraphicsContextGL.cpp
platform/graphics/GraphicsContextGLImageExtractor.cpp
+platform/graphics/GraphicsContextState.cpp
platform/graphics/GraphicsLayer.cpp
platform/graphics/GraphicsLayerContentsDisplayDelegate.cpp
platform/graphics/GraphicsLayerTransform.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (291363 => 291364)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2022-03-16 20:52:19 UTC (rev 291364)
@@ -2334,6 +2334,11 @@
72144334223EC91600F12FF7 /* SVGPropertyOwner.h in Headers */ = {isa = PBXBuildFile; fileRef = 55EE5360223B2A2100FBA944 /* SVGPropertyOwner.h */; settings = {ATTRIBUTES = (Private, ); }; };
721B49742512BA3B00FE9D3B /* ImageBitmapBacking.h in Headers */ = {isa = PBXBuildFile; fileRef = 721B49702512AC0400FE9D3B /* ImageBitmapBacking.h */; settings = {ATTRIBUTES = (Private, ); }; };
72283F0E230B268C00F5D828 /* ImagePaintingOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 72C18A3F230B04B7006847C7 /* ImagePaintingOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 722AF2DE27E1C2060078D997 /* GraphicsContextStateSaver.h in Headers */ = {isa = PBXBuildFile; fileRef = 722AF2DB27E1C2040078D997 /* GraphicsContextStateSaver.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 722AF2DF27E1C2060078D997 /* GraphicsContextState.h in Headers */ = {isa = PBXBuildFile; fileRef = 722AF2DC27E1C2050078D997 /* GraphicsContextState.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 722AF2E227E1C4050078D997 /* PlatformGraphicsContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 722AF2E127E1C4030078D997 /* PlatformGraphicsContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 722AF2E427E1CF130078D997 /* TextBoxIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 722AF2E327E1CF110078D997 /* TextBoxIterator.h */; };
+ 722AF2E627E1D0A10078D997 /* CGContextStateSaver.h in Headers */ = {isa = PBXBuildFile; fileRef = 722AF2E527E1D09E0078D997 /* CGContextStateSaver.h */; settings = {ATTRIBUTES = (Private, ); }; };
7246963B275C5FA600A9156A /* CSSFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F53FB83213B1BB800C40D34 /* CSSFilter.h */; settings = {ATTRIBUTES = (Private, ); }; };
7246963D275C614400A9156A /* FilterEffectVector.h in Headers */ = {isa = PBXBuildFile; fileRef = 7214B9B7274458FA003BE6DF /* FilterEffectVector.h */; settings = {ATTRIBUTES = (Private, ); }; };
7246963E275C616700A9156A /* FilterImageVector.h in Headers */ = {isa = PBXBuildFile; fileRef = 72B4EF7C274EE37F00293C2F /* FilterImageVector.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11308,6 +11313,12 @@
721B496F2512AC0400FE9D3B /* ImageBitmapBacking.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ImageBitmapBacking.cpp; sourceTree = "<group>"; };
721B49702512AC0400FE9D3B /* ImageBitmapBacking.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageBitmapBacking.h; sourceTree = "<group>"; };
722A815C238FD50500C00583 /* AnimationFrameRate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AnimationFrameRate.h; sourceTree = "<group>"; };
+ 722AF2DB27E1C2040078D997 /* GraphicsContextStateSaver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextStateSaver.h; sourceTree = "<group>"; };
+ 722AF2DC27E1C2050078D997 /* GraphicsContextState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextState.h; sourceTree = "<group>"; };
+ 722AF2DD27E1C2050078D997 /* GraphicsContextState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContextState.cpp; sourceTree = "<group>"; };
+ 722AF2E127E1C4030078D997 /* PlatformGraphicsContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformGraphicsContext.h; sourceTree = "<group>"; };
+ 722AF2E327E1CF110078D997 /* TextBoxIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextBoxIterator.h; sourceTree = "<group>"; };
+ 722AF2E527E1D09E0078D997 /* CGContextStateSaver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGContextStateSaver.h; sourceTree = "<group>"; };
72435EF4273D07670005E7EE /* FilterImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FilterImage.h; sourceTree = "<group>"; };
72435EF5273D07670005E7EE /* FilterImage.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FilterImage.cpp; sourceTree = "<group>"; };
724ED3291A3A7E5400F5F13C /* EXTBlendMinMax.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EXTBlendMinMax.cpp; sourceTree = "<group>"; };
@@ -28778,6 +28789,7 @@
B27535290B053814002CE64F /* cg */ = {
isa = PBXGroup;
children = (
+ 722AF2E527E1D09E0078D997 /* CGContextStateSaver.h */,
0FCF33230F2B9715004B6795 /* ColorCG.cpp */,
BCAFEDB325968D0B0030E6AA /* ColorSpaceCG.cpp */,
BCAFEDB225968D0B0030E6AA /* ColorSpaceCG.h */,
@@ -29011,6 +29023,9 @@
7BB34A47253776C700029D08 /* GraphicsContextGLImageExtractor.cpp */,
7BB34A45253776C600029D08 /* GraphicsContextGLImageExtractor.h */,
7B95CFE92754FF6E000060CE /* GraphicsContextGLState.h */,
+ 722AF2DD27E1C2050078D997 /* GraphicsContextState.cpp */,
+ 722AF2DC27E1C2050078D997 /* GraphicsContextState.h */,
+ 722AF2DB27E1C2040078D997 /* GraphicsContextStateSaver.h */,
0F580B090F12A2690051D689 /* GraphicsLayer.cpp */,
0F580B0A0F12A2690051D689 /* GraphicsLayer.h */,
0F580B0B0F12A2690051D689 /* GraphicsLayerClient.h */,
@@ -29111,6 +29126,7 @@
BCA55912263DBD79007F19B3 /* PixelFormat.h */,
CDD08ABF277E54F000EA3755 /* PlatformAudioTrackConfiguration.h */,
BC3E62422659791700548ACD /* PlatformColorSpace.h */,
+ 722AF2E127E1C4030078D997 /* PlatformGraphicsContext.h */,
726D56E1253AE0430002EF90 /* PlatformImage.h */,
72BAC3A623E17328008D741C /* PlatformImageBuffer.h */,
550640AD240756DA00AAE045 /* PlatformImageBufferBackend.h */,
@@ -29145,6 +29161,7 @@
087558C413B4A57D00F49307 /* SurrogatePairAwareTextIterator.h */,
95E9F44427C9A39B00945337 /* SystemImage.h */,
3BB6B80F22A7D311003A2A69 /* TabSize.h */,
+ 722AF2E327E1CF110078D997 /* TextBoxIterator.h */,
376DCCE013B4F966002EBEFC /* TextRun.cpp */,
A824B4640E2EF2EA0081A7B7 /* TextRun.h */,
CD1E7346167BC78E009A885D /* TextTrackRepresentation.cpp */,
@@ -33841,6 +33858,7 @@
CDE3AE1224B4916A00128E7E /* CDMUtilities.h in Headers */,
5FA904CA178E61F5004C8A2D /* CertificateInfo.h in Headers */,
91B8F0B521953D65000C2B00 /* CertificateSummary.h in Headers */,
+ 722AF2E627E1D0A10078D997 /* CGContextStateSaver.h in Headers */,
FE36FD1516C7826500F887C1 /* ChangeVersionData.h in Headers */,
97BC69DD1505F076001B74AC /* ChangeVersionWrapper.h in Headers */,
E785D91524B4D1CA0014DB21 /* ChannelCountMode.h in Headers */,
@@ -34765,6 +34783,8 @@
49C7B9FC1042D3650009D447 /* GraphicsContextGLOpenGL.h in Headers */,
7B95CFEB2754FF6E000060CE /* GraphicsContextGLState.h in Headers */,
A80D67080E9E9DEB00E420F0 /* GraphicsContextPlatformPrivateCG.h in Headers */,
+ 722AF2DF27E1C2060078D997 /* GraphicsContextState.h in Headers */,
+ 722AF2DE27E1C2060078D997 /* GraphicsContextStateSaver.h in Headers */,
0F580B0D0F12A2690051D689 /* GraphicsLayer.h in Headers */,
499B3ED7128CD31400E726C2 /* GraphicsLayerCA.h in Headers */,
0F580B0E0F12A2690051D689 /* GraphicsLayerClient.h in Headers */,
@@ -36672,6 +36692,7 @@
BCAA487014A052530088FAC4 /* PlatformEventFactoryMac.h in Headers */,
A723F77B1484CA4C008C6DBE /* PlatformExportMacros.h in Headers */,
515BE1951D54F5FB00DD7C68 /* PlatformGamepad.h in Headers */,
+ 722AF2E227E1C4050078D997 /* PlatformGraphicsContext.h in Headers */,
726D56E2253AE28D0002EF90 /* PlatformImage.h in Headers */,
2D7705C7255276CD001D0C94 /* PlatformImageBuffer.h in Headers */,
550640AF2407582D00AAE045 /* PlatformImageBufferBackend.h in Headers */,
@@ -37752,6 +37773,7 @@
CE7B2DB51586ABAD0098B3FA /* TextAlternativeWithRange.h in Headers */,
0F54DCE61881051D003EEDBB /* TextAutoSizing.h in Headers */,
B2C3DA340D006C1D00EF6F26 /* TextBoundaries.h in Headers */,
+ 722AF2E427E1CF130078D997 /* TextBoxIterator.h in Headers */,
E440DF5626EB53E0004AF06B /* TextBoxPainter.h in Headers */,
E447F5B3266CF63D00133F00 /* TextBoxSelectableRange.h in Headers */,
A7151BD812F1558F005A0F64 /* TextCheckerClient.h in Headers */,
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (291363 => 291364)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp 2022-03-16 20:52:19 UTC (rev 291364)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2021 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,7 +27,6 @@
#include "GraphicsContext.h"
#include "BidiResolver.h"
-#include "BitmapImage.h"
#include "Filter.h"
#include "FilterImage.h"
#include "FloatRoundedRect.h"
@@ -39,333 +38,11 @@
#include "NullGraphicsContext.h"
#include "RoundedRect.h"
#include "SystemImage.h"
-#include "TextRun.h"
+#include "TextBoxIterator.h"
#include <wtf/text/TextStream.h>
namespace WebCore {
-class TextBoxIterator {
-public:
- TextBoxIterator()
- : m_textRun(0)
- , m_offset(0)
- {
- }
-
- TextBoxIterator(const TextRun* textRun, unsigned offset)
- : m_textRun(textRun)
- , m_offset(offset)
- {
- }
-
- unsigned offset() const { return m_offset; }
- void increment() { m_offset++; }
- bool atEnd() const { return !m_textRun || m_offset >= m_textRun->length(); }
- UChar current() const { return (*m_textRun)[m_offset]; }
- UCharDirection direction() const { return atEnd() ? U_OTHER_NEUTRAL : u_charDirection(current()); }
-
- bool operator==(const TextBoxIterator& other) const
- {
- return m_offset == other.m_offset && m_textRun == other.m_textRun;
- }
-
- bool operator!=(const TextBoxIterator& other) const { return !operator==(other); }
-
-private:
- const TextRun* m_textRun;
- unsigned m_offset;
-};
-
-#define CHECK_FOR_CHANGED_PROPERTY(flag, property) \
- if (m_changeFlags.contains(GraphicsContextState::flag) && (m_state.property != state.property)) \
- changeFlags.add(GraphicsContextState::flag);
-
-GraphicsContextState::GraphicsContextState()
- : shouldAntialias(true)
- , shouldSmoothFonts(true)
- , shouldSubpixelQuantizeFonts(true)
- , shadowsIgnoreTransforms(false)
- , drawLuminanceMask(false)
-{
-}
-
-GraphicsContextState::~GraphicsContextState() = default;
-GraphicsContextState::GraphicsContextState(const GraphicsContextState&) = default;
-GraphicsContextState::GraphicsContextState(GraphicsContextState&&) = default;
-GraphicsContextState& GraphicsContextState::operator=(const GraphicsContextState&) = default;
-GraphicsContextState& GraphicsContextState::operator=(GraphicsContextState&&) = default;
-
-void GraphicsContextState::mergeChanges(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
-{
- auto strokeFlags = { GraphicsContextState::StrokeColorChange, GraphicsContextState::StrokeGradientChange, GraphicsContextState::StrokePatternChange };
- if (flags.containsAny(strokeFlags)) {
- strokeColor = state.strokeColor;
- strokeGradient = state.strokeGradient;
- strokePattern = state.strokePattern;
- }
-
- auto fillFlags = { GraphicsContextState::FillColorChange, GraphicsContextState::FillGradientChange, GraphicsContextState::FillPatternChange };
- if (flags.containsAny(fillFlags)) {
- fillColor = state.fillColor;
- fillGradient = state.fillGradient;
- fillPattern = state.fillPattern;
- }
-
- if (flags.contains(GraphicsContextState::ShadowChange)) {
- shadowOffset = state.shadowOffset;
- shadowBlur = state.shadowBlur;
- shadowColor = state.shadowColor;
- shadowRadiusMode = state.shadowRadiusMode;
- }
-
- if (flags.contains(GraphicsContextState::StrokeThicknessChange))
- strokeThickness = state.strokeThickness;
-
- if (flags.contains(GraphicsContextState::TextDrawingModeChange))
- textDrawingMode = state.textDrawingMode;
-
- if (flags.contains(GraphicsContextState::StrokeStyleChange))
- strokeStyle = state.strokeStyle;
-
- if (flags.contains(GraphicsContextState::FillRuleChange))
- fillRule = state.fillRule;
-
- if (flags.contains(GraphicsContextState::AlphaChange))
- alpha = state.alpha;
-
- if (flags.containsAny({ GraphicsContextState::CompositeOperationChange, GraphicsContextState::BlendModeChange })) {
- compositeOperator = state.compositeOperator;
- blendMode = state.blendMode;
- }
-
- if (flags.contains(GraphicsContextState::ShouldAntialiasChange))
- shouldAntialias = state.shouldAntialias;
-
- if (flags.contains(GraphicsContextState::ShouldSmoothFontsChange))
- shouldSmoothFonts = state.shouldSmoothFonts;
-
- if (flags.contains(GraphicsContextState::ShouldSubpixelQuantizeFontsChange))
- shouldSubpixelQuantizeFonts = state.shouldSubpixelQuantizeFonts;
-
- if (flags.contains(GraphicsContextState::ShadowsIgnoreTransformsChange))
- shadowsIgnoreTransforms = state.shadowsIgnoreTransforms;
-
- if (flags.contains(GraphicsContextState::DrawLuminanceMaskChange))
- drawLuminanceMask = state.drawLuminanceMask;
-
- if (flags.contains(GraphicsContextState::ImageInterpolationQualityChange))
- imageInterpolationQuality = state.imageInterpolationQuality;
-
-#if HAVE(OS_DARK_MODE_SUPPORT)
- if (flags.contains(GraphicsContextState::UseDarkAppearanceChange))
- useDarkAppearance = state.useDarkAppearance;
-#endif
-}
-
-GraphicsContextState::StateChangeFlags GraphicsContextStateChange::changesFromState(const GraphicsContextState& state) const
-{
- GraphicsContextState::StateChangeFlags changeFlags;
-
- CHECK_FOR_CHANGED_PROPERTY(StrokeGradientChange, strokeGradient);
- CHECK_FOR_CHANGED_PROPERTY(StrokePatternChange, strokePattern);
- CHECK_FOR_CHANGED_PROPERTY(FillGradientChange, fillGradient);
- CHECK_FOR_CHANGED_PROPERTY(FillPatternChange, fillPattern);
-
- if (m_changeFlags.contains(GraphicsContextState::ShadowChange)
- && (m_state.shadowOffset != state.shadowOffset
- || m_state.shadowBlur != state.shadowBlur
- || m_state.shadowColor != state.shadowColor))
- changeFlags.add(GraphicsContextState::ShadowChange);
-
- CHECK_FOR_CHANGED_PROPERTY(StrokeThicknessChange, strokeThickness);
- CHECK_FOR_CHANGED_PROPERTY(TextDrawingModeChange, textDrawingMode);
- CHECK_FOR_CHANGED_PROPERTY(StrokeColorChange, strokeColor);
- CHECK_FOR_CHANGED_PROPERTY(FillColorChange, fillColor);
- CHECK_FOR_CHANGED_PROPERTY(StrokeStyleChange, strokeStyle);
- CHECK_FOR_CHANGED_PROPERTY(FillRuleChange, fillRule);
- CHECK_FOR_CHANGED_PROPERTY(AlphaChange, alpha);
-
- if (m_changeFlags.containsAny({ GraphicsContextState::CompositeOperationChange, GraphicsContextState::BlendModeChange })
- && (m_state.compositeOperator != state.compositeOperator || m_state.blendMode != state.blendMode)) {
- changeFlags.add(GraphicsContextState::CompositeOperationChange);
- changeFlags.add(GraphicsContextState::BlendModeChange);
- }
-
- CHECK_FOR_CHANGED_PROPERTY(ShouldAntialiasChange, shouldAntialias);
- CHECK_FOR_CHANGED_PROPERTY(ShouldSmoothFontsChange, shouldSmoothFonts);
- CHECK_FOR_CHANGED_PROPERTY(ShouldSubpixelQuantizeFontsChange, shouldSubpixelQuantizeFonts);
- CHECK_FOR_CHANGED_PROPERTY(ShadowsIgnoreTransformsChange, shadowsIgnoreTransforms);
- CHECK_FOR_CHANGED_PROPERTY(DrawLuminanceMaskChange, drawLuminanceMask);
- CHECK_FOR_CHANGED_PROPERTY(ImageInterpolationQualityChange, imageInterpolationQuality);
-
-#if HAVE(OS_DARK_MODE_SUPPORT)
- CHECK_FOR_CHANGED_PROPERTY(UseDarkAppearanceChange, useDarkAppearance);
-#endif
-
- return changeFlags;
-}
-
-void GraphicsContextStateChange::accumulate(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
-{
- m_state.mergeChanges(state, flags);
-
- auto strokeFlags = { GraphicsContextState::StrokeColorChange, GraphicsContextState::StrokeGradientChange, GraphicsContextState::StrokePatternChange };
- if (flags.containsAny(strokeFlags))
- m_changeFlags.remove(strokeFlags);
-
- auto fillFlags = { GraphicsContextState::FillColorChange, GraphicsContextState::FillGradientChange, GraphicsContextState::FillPatternChange };
- if (flags.containsAny(fillFlags))
- m_changeFlags.remove(fillFlags);
-
- auto compositeOperatorFlags = { GraphicsContextState::CompositeOperationChange, GraphicsContextState::BlendModeChange };
- if (flags.containsAny(compositeOperatorFlags))
- m_changeFlags.remove(compositeOperatorFlags);
-
- m_changeFlags.add(flags);
-}
-
-void GraphicsContextStateChange::apply(GraphicsContext& context) const
-{
- if (m_changeFlags.contains(GraphicsContextState::StrokeGradientChange))
- context.setStrokeGradient(*m_state.strokeGradient, m_state.strokeGradientSpaceTransform);
-
- if (m_changeFlags.contains(GraphicsContextState::StrokePatternChange))
- context.setStrokePattern(*m_state.strokePattern);
-
- if (m_changeFlags.contains(GraphicsContextState::FillGradientChange))
- context.setFillGradient(*m_state.fillGradient, m_state.fillGradientSpaceTransform);
-
- if (m_changeFlags.contains(GraphicsContextState::FillPatternChange))
- context.setFillPattern(*m_state.fillPattern);
-
- if (m_changeFlags.contains(GraphicsContextState::ShadowsIgnoreTransformsChange))
- context.setShadowsIgnoreTransforms(m_state.shadowsIgnoreTransforms);
-
- if (m_changeFlags.contains(GraphicsContextState::ShadowChange))
- context.setShadow(m_state.shadowOffset, m_state.shadowBlur, m_state.shadowColor, m_state.shadowRadiusMode);
-
- if (m_changeFlags.contains(GraphicsContextState::StrokeThicknessChange))
- context.setStrokeThickness(m_state.strokeThickness);
-
- if (m_changeFlags.contains(GraphicsContextState::TextDrawingModeChange))
- context.setTextDrawingMode(m_state.textDrawingMode);
-
- if (m_changeFlags.contains(GraphicsContextState::StrokeColorChange))
- context.setStrokeColor(m_state.strokeColor);
-
- if (m_changeFlags.contains(GraphicsContextState::FillColorChange))
- context.setFillColor(m_state.fillColor);
-
- if (m_changeFlags.contains(GraphicsContextState::StrokeStyleChange))
- context.setStrokeStyle(m_state.strokeStyle);
-
- if (m_changeFlags.contains(GraphicsContextState::FillRuleChange))
- context.setFillRule(m_state.fillRule);
-
- if (m_changeFlags.contains(GraphicsContextState::AlphaChange))
- context.setAlpha(m_state.alpha);
-
- if (m_changeFlags.containsAny({ GraphicsContextState::CompositeOperationChange, GraphicsContextState::BlendModeChange }))
- context.setCompositeOperation(m_state.compositeOperator, m_state.blendMode);
-
- if (m_changeFlags.contains(GraphicsContextState::ShouldAntialiasChange))
- context.setShouldAntialias(m_state.shouldAntialias);
-
- if (m_changeFlags.contains(GraphicsContextState::ShouldSmoothFontsChange))
- context.setShouldSmoothFonts(m_state.shouldSmoothFonts);
-
- if (m_changeFlags.contains(GraphicsContextState::ShouldSubpixelQuantizeFontsChange))
- context.setShouldSubpixelQuantizeFonts(m_state.shouldSubpixelQuantizeFonts);
-
- if (m_changeFlags.contains(GraphicsContextState::DrawLuminanceMaskChange))
- context.setDrawLuminanceMask(m_state.drawLuminanceMask);
-
- if (m_changeFlags.contains(GraphicsContextState::ImageInterpolationQualityChange))
- context.setImageInterpolationQuality(m_state.imageInterpolationQuality);
-
-#if HAVE(OS_DARK_MODE_SUPPORT)
- if (m_changeFlags.contains(GraphicsContextState::UseDarkAppearanceChange))
- context.setUseDarkAppearance(m_state.useDarkAppearance);
-#endif
-}
-
-void GraphicsContextStateChange::dump(TextStream& ts) const
-{
- ts.dumpProperty("change-flags", m_changeFlags.toRaw());
-
- if (m_changeFlags.contains(GraphicsContextState::StrokeGradientChange))
- ts.dumpProperty("stroke-gradient", m_state.strokeGradient.get());
-
- if (m_changeFlags.contains(GraphicsContextState::StrokePatternChange))
- ts.dumpProperty("stroke-pattern", m_state.strokePattern.get());
-
- if (m_changeFlags.contains(GraphicsContextState::FillGradientChange))
- ts.dumpProperty("fill-gradient", m_state.fillGradient.get());
-
- if (m_changeFlags.contains(GraphicsContextState::FillPatternChange))
- ts.dumpProperty("fill-pattern", m_state.fillPattern.get());
-
- if (m_changeFlags.contains(GraphicsContextState::ShadowChange)) {
- ts.dumpProperty("shadow-blur", m_state.shadowBlur);
- ts.dumpProperty("shadow-offset", m_state.shadowOffset);
- ts.dumpProperty("shadow-color", m_state.shadowColor);
- ts.dumpProperty("shadows-use-legacy-radius", m_state.shadowRadiusMode == ShadowRadiusMode::Legacy);
- }
-
- if (m_changeFlags.contains(GraphicsContextState::StrokeThicknessChange))
- ts.dumpProperty("stroke-thickness", m_state.strokeThickness);
-
- if (m_changeFlags.contains(GraphicsContextState::TextDrawingModeChange))
- ts.dumpProperty("text-drawing-mode", m_state.textDrawingMode.toRaw());
-
- if (m_changeFlags.contains(GraphicsContextState::StrokeColorChange))
- ts.dumpProperty("stroke-color", m_state.strokeColor);
-
- if (m_changeFlags.contains(GraphicsContextState::FillColorChange))
- ts.dumpProperty("fill-color", m_state.fillColor);
-
- if (m_changeFlags.contains(GraphicsContextState::StrokeStyleChange))
- ts.dumpProperty("stroke-style", m_state.strokeStyle);
-
- if (m_changeFlags.contains(GraphicsContextState::FillRuleChange))
- ts.dumpProperty("fill-rule", m_state.fillRule);
-
- if (m_changeFlags.contains(GraphicsContextState::AlphaChange))
- ts.dumpProperty("alpha", m_state.alpha);
-
- if (m_changeFlags.contains(GraphicsContextState::CompositeOperationChange))
- ts.dumpProperty("composite-operator", m_state.compositeOperator);
-
- if (m_changeFlags.contains(GraphicsContextState::BlendModeChange))
- ts.dumpProperty("blend-mode", m_state.blendMode);
-
- if (m_changeFlags.contains(GraphicsContextState::ShouldAntialiasChange))
- ts.dumpProperty("should-antialias", m_state.shouldAntialias);
-
- if (m_changeFlags.contains(GraphicsContextState::ShouldSmoothFontsChange))
- ts.dumpProperty("should-smooth-fonts", m_state.shouldSmoothFonts);
-
- if (m_changeFlags.contains(GraphicsContextState::ShouldSubpixelQuantizeFontsChange))
- ts.dumpProperty("should-subpixel-quantize-fonts", m_state.shouldSubpixelQuantizeFonts);
-
- if (m_changeFlags.contains(GraphicsContextState::ShadowsIgnoreTransformsChange))
- ts.dumpProperty("shadows-ignore-transforms", m_state.shadowsIgnoreTransforms);
-
- if (m_changeFlags.contains(GraphicsContextState::DrawLuminanceMaskChange))
- ts.dumpProperty("draw-luminance-mask", m_state.drawLuminanceMask);
-
-#if HAVE(OS_DARK_MODE_SUPPORT)
- if (m_changeFlags.contains(GraphicsContextState::UseDarkAppearanceChange))
- ts.dumpProperty("use-dark-appearance", m_state.useDarkAppearance);
-#endif
-}
-
-TextStream& operator<<(TextStream& ts, const GraphicsContextStateChange& stateChange)
-{
- stateChange.dump(ts);
- return ts;
-}
-
GraphicsContext::~GraphicsContext()
{
ASSERT(m_stack.isEmpty());
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (291363 => 291364)
--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h 2022-03-16 20:52:19 UTC (rev 291364)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2021 Apple Inc. All rights reserved.
+ * Copyright (C) 2003-2022 Apple Inc. All rights reserved.
* Copyright (C) 2008-2009 Torch Mobile, Inc.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,51 +30,20 @@
#include "DestinationColorSpace.h"
#include "FloatRect.h"
#include "FontCascade.h"
-#include "GraphicsTypes.h"
+#include "GraphicsContextState.h"
#include "Image.h"
#include "ImageOrientation.h"
#include "ImagePaintingOptions.h"
#include "IntRect.h"
#include "Pattern.h"
+#include "PlatformGraphicsContext.h"
#include "RenderingMode.h"
#include <wtf/Function.h>
#include <wtf/Noncopyable.h>
#include <wtf/OptionSet.h>
-#if USE(CG)
-typedef struct CGContext PlatformGraphicsContext;
-#elif USE(CAIRO)
namespace WebCore {
-class GraphicsContextCairo;
-}
-typedef WebCore::GraphicsContextCairo PlatformGraphicsContext;
-#else
-typedef void PlatformGraphicsContext;
-#endif
-#if PLATFORM(WIN)
-#include "DIBPixelData.h"
-typedef struct HDC__* HDC;
-#if !USE(CG)
-// UInt8 is defined in CoreFoundation/CFBase.h
-typedef unsigned char UInt8;
-#endif
-#endif
-
-// X11 headers define a bunch of macros with common terms, interfering with WebCore and WTF enum values.
-// As a workaround, we explicitly undef them here.
-#if defined(None)
-#undef None
-#endif
-#if defined(Below)
-#undef Below
-#endif
-#if defined(Success)
-#undef Success
-#endif
-
-namespace WebCore {
-
class AffineTransform;
class Filter;
class FilterResults;
@@ -91,169 +60,8 @@
class TextRun;
class TransformationMatrix;
-namespace DisplayList {
-class Recorder;
-}
-
-enum class TextDrawingMode : uint8_t {
- Fill = 1 << 0,
- Stroke = 1 << 1,
-};
-using TextDrawingModeFlags = OptionSet<TextDrawingMode>;
-
-// Legacy shadow blur radius is used for canvas, and -webkit-box-shadow.
-// It has different treatment of radii > 8px.
-enum class ShadowRadiusMode : bool {
- Default,
- Legacy
-};
-
-enum StrokeStyle {
- NoStroke,
- SolidStroke,
- DottedStroke,
- DashedStroke,
- DoubleStroke,
- WavyStroke,
-};
-
-struct DocumentMarkerLineStyle {
- enum class Mode : uint8_t {
- TextCheckingDictationPhraseWithAlternatives,
- Spelling,
- Grammar,
- AutocorrectionReplacement,
- DictationAlternatives
- } mode;
- bool shouldUseDarkAppearance { false };
-
- template<class Encoder> void encode(Encoder&) const;
- template<class Decoder> static std::optional<DocumentMarkerLineStyle> decode(Decoder&);
-};
-
-template<class Encoder>
-void DocumentMarkerLineStyle::encode(Encoder& encoder) const
-{
- encoder << mode;
- encoder << shouldUseDarkAppearance;
-}
-
-template<class Decoder>
-std::optional<DocumentMarkerLineStyle> DocumentMarkerLineStyle::decode(Decoder& decoder)
-{
- std::optional<Mode> mode;
- decoder >> mode;
- if (!mode)
- return std::nullopt;
-
- std::optional<bool> shouldUseDarkAppearance;
- decoder >> shouldUseDarkAppearance;
- if (!shouldUseDarkAppearance)
- return std::nullopt;
-
- return {{ *mode, *shouldUseDarkAppearance }};
-}
-
struct GraphicsContextStateChange;
-struct GraphicsContextState {
- WEBCORE_EXPORT GraphicsContextState();
- WEBCORE_EXPORT ~GraphicsContextState();
-
- GraphicsContextState(const GraphicsContextState&);
- WEBCORE_EXPORT GraphicsContextState(GraphicsContextState&&);
-
- GraphicsContextState& operator=(const GraphicsContextState&);
- WEBCORE_EXPORT GraphicsContextState& operator=(GraphicsContextState&&);
-
- enum Change : uint32_t {
- StrokeGradientChange = 1 << 0,
- StrokePatternChange = 1 << 1,
- FillGradientChange = 1 << 2,
- FillPatternChange = 1 << 3,
- StrokeThicknessChange = 1 << 4,
- StrokeColorChange = 1 << 5,
- StrokeStyleChange = 1 << 6,
- FillColorChange = 1 << 7,
- FillRuleChange = 1 << 8,
- ShadowChange = 1 << 9,
- ShadowsIgnoreTransformsChange = 1 << 10,
- AlphaChange = 1 << 11,
- CompositeOperationChange = 1 << 12,
- BlendModeChange = 1 << 13,
- TextDrawingModeChange = 1 << 14,
- ShouldAntialiasChange = 1 << 15,
- ShouldSmoothFontsChange = 1 << 16,
- ShouldSubpixelQuantizeFontsChange = 1 << 17,
- DrawLuminanceMaskChange = 1 << 18,
- ImageInterpolationQualityChange = 1 << 19,
-#if HAVE(OS_DARK_MODE_SUPPORT)
- UseDarkAppearanceChange = 1 << 20,
-#endif
- };
- using StateChangeFlags = OptionSet<Change>;
-
- void mergeChanges(const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
-
- RefPtr<Gradient> strokeGradient;
- RefPtr<Pattern> strokePattern;
-
- RefPtr<Gradient> fillGradient;
- RefPtr<Pattern> fillPattern;
-
- FloatSize shadowOffset;
-
- Color strokeColor { Color::black };
- Color fillColor { Color::black };
- Color shadowColor;
-
- AffineTransform strokeGradientSpaceTransform;
- AffineTransform fillGradientSpaceTransform;
-
- float strokeThickness { 0 };
- float shadowBlur { 0 };
- float alpha { 1 };
-
- StrokeStyle strokeStyle { SolidStroke };
- WindRule fillRule { WindRule::NonZero };
-
- TextDrawingModeFlags textDrawingMode { TextDrawingMode::Fill };
- CompositeOperator compositeOperator { CompositeOperator::SourceOver };
- BlendMode blendMode { BlendMode::Normal };
- InterpolationQuality imageInterpolationQuality { InterpolationQuality::Default };
- ShadowRadiusMode shadowRadiusMode { ShadowRadiusMode::Default };
-
- bool shouldAntialias : 1;
- bool shouldSmoothFonts : 1;
- bool shouldSubpixelQuantizeFonts : 1;
- bool shadowsIgnoreTransforms : 1;
- bool drawLuminanceMask : 1;
-#if HAVE(OS_DARK_MODE_SUPPORT)
- bool useDarkAppearance : 1;
-#endif
-};
-
-struct GraphicsContextStateChange {
- GraphicsContextStateChange() = default;
- GraphicsContextStateChange(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
- : m_state(state)
- , m_changeFlags(flags)
- {
- }
-
- GraphicsContextState::StateChangeFlags changesFromState(const GraphicsContextState&) const;
-
- void accumulate(const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
- void apply(GraphicsContext&) const;
-
- void dump(WTF::TextStream&) const;
-
- GraphicsContextState m_state;
- GraphicsContextState::StateChangeFlags m_changeFlags;
-};
-
-WTF::TextStream& operator<<(WTF::TextStream&, const GraphicsContextStateChange&);
-
class GraphicsContext {
WTF_MAKE_NONCOPYABLE(GraphicsContext); WTF_MAKE_FAST_ALLOCATED;
public:
@@ -570,182 +378,6 @@
bool m_contentfulPaintDetected { false };
};
-class GraphicsContextStateSaver {
- WTF_MAKE_FAST_ALLOCATED;
-public:
- GraphicsContextStateSaver(GraphicsContext& context, bool saveAndRestore = true)
- : m_context(context)
- , m_saveAndRestore(saveAndRestore)
- {
- if (m_saveAndRestore)
- m_context.save();
- }
-
- ~GraphicsContextStateSaver()
- {
- if (m_saveAndRestore)
- m_context.restore();
- }
-
- void save()
- {
- ASSERT(!m_saveAndRestore);
- m_context.save();
- m_saveAndRestore = true;
- }
-
- void restore()
- {
- ASSERT(m_saveAndRestore);
- m_context.restore();
- m_saveAndRestore = false;
- }
-
- GraphicsContext* context() const { return &m_context; }
-
-private:
- GraphicsContext& m_context;
- bool m_saveAndRestore;
-};
-
-class TransparencyLayerScope {
-public:
- TransparencyLayerScope(GraphicsContext& context, float alpha, bool beginLayer = true)
- : m_context(context)
- , m_alpha(alpha)
- , m_beganLayer(beginLayer)
- {
- if (beginLayer)
- m_context.beginTransparencyLayer(m_alpha);
- }
-
- void beginLayer(float alpha)
- {
- m_alpha = alpha;
- m_context.beginTransparencyLayer(m_alpha);
- m_beganLayer = true;
- }
-
- ~TransparencyLayerScope()
- {
- if (m_beganLayer)
- m_context.endTransparencyLayer();
- }
-
-private:
- GraphicsContext& m_context;
- float m_alpha;
- bool m_beganLayer;
-};
-
-class GraphicsContextStateStackChecker {
-public:
- GraphicsContextStateStackChecker(GraphicsContext& context)
- : m_context(context)
- , m_stackSize(context.stackSize())
- { }
-
- ~GraphicsContextStateStackChecker()
- {
- if (m_context.stackSize() != m_stackSize)
- WTFLogAlways("GraphicsContext %p stack changed by %d", &m_context, (int)m_context.stackSize() - (int)m_stackSize);
- }
-
-private:
- GraphicsContext& m_context;
- unsigned m_stackSize;
-};
-
-class InterpolationQualityMaintainer {
-public:
- explicit InterpolationQualityMaintainer(GraphicsContext& graphicsContext, InterpolationQuality interpolationQualityToUse)
- : m_graphicsContext(graphicsContext)
- , m_currentInterpolationQuality(graphicsContext.imageInterpolationQuality())
- , m_interpolationQualityChanged(interpolationQualityToUse != InterpolationQuality::Default && m_currentInterpolationQuality != interpolationQualityToUse)
- {
- if (m_interpolationQualityChanged)
- m_graphicsContext.setImageInterpolationQuality(interpolationQualityToUse);
- }
-
- explicit InterpolationQualityMaintainer(GraphicsContext& graphicsContext, std::optional<InterpolationQuality> interpolationQuality)
- : InterpolationQualityMaintainer(graphicsContext, interpolationQuality ? interpolationQuality.value() : graphicsContext.imageInterpolationQuality())
- {
- }
-
- ~InterpolationQualityMaintainer()
- {
- if (m_interpolationQualityChanged)
- m_graphicsContext.setImageInterpolationQuality(m_currentInterpolationQuality);
- }
-
-private:
- GraphicsContext& m_graphicsContext;
- InterpolationQuality m_currentInterpolationQuality;
- bool m_interpolationQualityChanged;
-};
-
} // namespace WebCore
-namespace WTF {
-
-template<> struct EnumTraits<WebCore::DocumentMarkerLineStyle::Mode> {
- using values = EnumValues<
- WebCore::DocumentMarkerLineStyle::Mode,
- WebCore::DocumentMarkerLineStyle::Mode::TextCheckingDictationPhraseWithAlternatives,
- WebCore::DocumentMarkerLineStyle::Mode::Spelling,
- WebCore::DocumentMarkerLineStyle::Mode::Grammar,
- WebCore::DocumentMarkerLineStyle::Mode::AutocorrectionReplacement,
- WebCore::DocumentMarkerLineStyle::Mode::DictationAlternatives
- >;
-};
-
-template<> struct EnumTraits<WebCore::GraphicsContextState::Change> {
- using values = EnumValues<
- WebCore::GraphicsContextState::Change,
- WebCore::GraphicsContextState::Change::StrokeGradientChange,
- WebCore::GraphicsContextState::Change::StrokePatternChange,
- WebCore::GraphicsContextState::Change::FillGradientChange,
- WebCore::GraphicsContextState::Change::FillPatternChange,
- WebCore::GraphicsContextState::Change::StrokeThicknessChange,
- WebCore::GraphicsContextState::Change::StrokeColorChange,
- WebCore::GraphicsContextState::Change::StrokeStyleChange,
- WebCore::GraphicsContextState::Change::FillColorChange,
- WebCore::GraphicsContextState::Change::FillRuleChange,
- WebCore::GraphicsContextState::Change::ShadowChange,
- WebCore::GraphicsContextState::Change::ShadowsIgnoreTransformsChange,
- WebCore::GraphicsContextState::Change::AlphaChange,
- WebCore::GraphicsContextState::Change::CompositeOperationChange,
- WebCore::GraphicsContextState::Change::BlendModeChange,
- WebCore::GraphicsContextState::Change::TextDrawingModeChange,
- WebCore::GraphicsContextState::Change::ShouldAntialiasChange,
- WebCore::GraphicsContextState::Change::ShouldSmoothFontsChange,
- WebCore::GraphicsContextState::Change::ShouldSubpixelQuantizeFontsChange,
- WebCore::GraphicsContextState::Change::DrawLuminanceMaskChange,
- WebCore::GraphicsContextState::Change::ImageInterpolationQualityChange
-#if HAVE(OS_DARK_MODE_SUPPORT)
- , WebCore::GraphicsContextState::Change::UseDarkAppearanceChange
-#endif
- >;
-};
-
-template<> struct EnumTraits<WebCore::StrokeStyle> {
- using values = EnumValues<
- WebCore::StrokeStyle,
- WebCore::StrokeStyle::NoStroke,
- WebCore::StrokeStyle::SolidStroke,
- WebCore::StrokeStyle::DottedStroke,
- WebCore::StrokeStyle::DashedStroke,
- WebCore::StrokeStyle::DoubleStroke,
- WebCore::StrokeStyle::WavyStroke
- >;
-};
-
-template<> struct EnumTraits<WebCore::TextDrawingMode> {
- using values = EnumValues<
- WebCore::TextDrawingMode,
- WebCore::TextDrawingMode::Fill,
- WebCore::TextDrawingMode::Stroke
- >;
-};
-
-} // namespace WTF
+#include "GraphicsContextStateSaver.h"
Added: trunk/Source/WebCore/platform/graphics/GraphicsContextState.cpp (0 => 291364)
--- trunk/Source/WebCore/platform/graphics/GraphicsContextState.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextState.cpp 2022-03-16 20:52:19 UTC (rev 291364)
@@ -0,0 +1,326 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GraphicsContextState.h"
+
+#include "Gradient.h"
+#include "GraphicsContext.h"
+#include "Pattern.h"
+#include <wtf/text/TextStream.h>
+
+namespace WebCore {
+
+#define CHECK_FOR_CHANGED_PROPERTY(flag, property) \
+ if (m_changeFlags.contains(GraphicsContextState::flag) && (m_state.property != state.property)) \
+ changeFlags.add(GraphicsContextState::flag);
+
+GraphicsContextState::GraphicsContextState()
+ : shouldAntialias(true)
+ , shouldSmoothFonts(true)
+ , shouldSubpixelQuantizeFonts(true)
+ , shadowsIgnoreTransforms(false)
+ , drawLuminanceMask(false)
+{
+}
+
+GraphicsContextState::~GraphicsContextState() = default;
+GraphicsContextState::GraphicsContextState(const GraphicsContextState&) = default;
+GraphicsContextState::GraphicsContextState(GraphicsContextState&&) = default;
+GraphicsContextState& GraphicsContextState::operator=(const GraphicsContextState&) = default;
+GraphicsContextState& GraphicsContextState::operator=(GraphicsContextState&&) = default;
+
+void GraphicsContextState::mergeChanges(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
+{
+ auto strokeFlags = { GraphicsContextState::StrokeColorChange, GraphicsContextState::StrokeGradientChange, GraphicsContextState::StrokePatternChange };
+ if (flags.containsAny(strokeFlags)) {
+ strokeColor = state.strokeColor;
+ strokeGradient = state.strokeGradient;
+ strokePattern = state.strokePattern;
+ }
+
+ auto fillFlags = { GraphicsContextState::FillColorChange, GraphicsContextState::FillGradientChange, GraphicsContextState::FillPatternChange };
+ if (flags.containsAny(fillFlags)) {
+ fillColor = state.fillColor;
+ fillGradient = state.fillGradient;
+ fillPattern = state.fillPattern;
+ }
+
+ if (flags.contains(GraphicsContextState::ShadowChange)) {
+ shadowOffset = state.shadowOffset;
+ shadowBlur = state.shadowBlur;
+ shadowColor = state.shadowColor;
+ shadowRadiusMode = state.shadowRadiusMode;
+ }
+
+ if (flags.contains(GraphicsContextState::StrokeThicknessChange))
+ strokeThickness = state.strokeThickness;
+
+ if (flags.contains(GraphicsContextState::TextDrawingModeChange))
+ textDrawingMode = state.textDrawingMode;
+
+ if (flags.contains(GraphicsContextState::StrokeStyleChange))
+ strokeStyle = state.strokeStyle;
+
+ if (flags.contains(GraphicsContextState::FillRuleChange))
+ fillRule = state.fillRule;
+
+ if (flags.contains(GraphicsContextState::AlphaChange))
+ alpha = state.alpha;
+
+ if (flags.containsAny({ GraphicsContextState::CompositeOperationChange, GraphicsContextState::BlendModeChange })) {
+ compositeOperator = state.compositeOperator;
+ blendMode = state.blendMode;
+ }
+
+ if (flags.contains(GraphicsContextState::ShouldAntialiasChange))
+ shouldAntialias = state.shouldAntialias;
+
+ if (flags.contains(GraphicsContextState::ShouldSmoothFontsChange))
+ shouldSmoothFonts = state.shouldSmoothFonts;
+
+ if (flags.contains(GraphicsContextState::ShouldSubpixelQuantizeFontsChange))
+ shouldSubpixelQuantizeFonts = state.shouldSubpixelQuantizeFonts;
+
+ if (flags.contains(GraphicsContextState::ShadowsIgnoreTransformsChange))
+ shadowsIgnoreTransforms = state.shadowsIgnoreTransforms;
+
+ if (flags.contains(GraphicsContextState::DrawLuminanceMaskChange))
+ drawLuminanceMask = state.drawLuminanceMask;
+
+ if (flags.contains(GraphicsContextState::ImageInterpolationQualityChange))
+ imageInterpolationQuality = state.imageInterpolationQuality;
+
+#if HAVE(OS_DARK_MODE_SUPPORT)
+ if (flags.contains(GraphicsContextState::UseDarkAppearanceChange))
+ useDarkAppearance = state.useDarkAppearance;
+#endif
+}
+
+GraphicsContextState::StateChangeFlags GraphicsContextStateChange::changesFromState(const GraphicsContextState& state) const
+{
+ GraphicsContextState::StateChangeFlags changeFlags;
+
+ CHECK_FOR_CHANGED_PROPERTY(StrokeGradientChange, strokeGradient);
+ CHECK_FOR_CHANGED_PROPERTY(StrokePatternChange, strokePattern);
+ CHECK_FOR_CHANGED_PROPERTY(FillGradientChange, fillGradient);
+ CHECK_FOR_CHANGED_PROPERTY(FillPatternChange, fillPattern);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShadowChange)
+ && (m_state.shadowOffset != state.shadowOffset
+ || m_state.shadowBlur != state.shadowBlur
+ || m_state.shadowColor != state.shadowColor))
+ changeFlags.add(GraphicsContextState::ShadowChange);
+
+ CHECK_FOR_CHANGED_PROPERTY(StrokeThicknessChange, strokeThickness);
+ CHECK_FOR_CHANGED_PROPERTY(TextDrawingModeChange, textDrawingMode);
+ CHECK_FOR_CHANGED_PROPERTY(StrokeColorChange, strokeColor);
+ CHECK_FOR_CHANGED_PROPERTY(FillColorChange, fillColor);
+ CHECK_FOR_CHANGED_PROPERTY(StrokeStyleChange, strokeStyle);
+ CHECK_FOR_CHANGED_PROPERTY(FillRuleChange, fillRule);
+ CHECK_FOR_CHANGED_PROPERTY(AlphaChange, alpha);
+
+ if (m_changeFlags.containsAny({ GraphicsContextState::CompositeOperationChange, GraphicsContextState::BlendModeChange })
+ && (m_state.compositeOperator != state.compositeOperator || m_state.blendMode != state.blendMode)) {
+ changeFlags.add(GraphicsContextState::CompositeOperationChange);
+ changeFlags.add(GraphicsContextState::BlendModeChange);
+ }
+
+ CHECK_FOR_CHANGED_PROPERTY(ShouldAntialiasChange, shouldAntialias);
+ CHECK_FOR_CHANGED_PROPERTY(ShouldSmoothFontsChange, shouldSmoothFonts);
+ CHECK_FOR_CHANGED_PROPERTY(ShouldSubpixelQuantizeFontsChange, shouldSubpixelQuantizeFonts);
+ CHECK_FOR_CHANGED_PROPERTY(ShadowsIgnoreTransformsChange, shadowsIgnoreTransforms);
+ CHECK_FOR_CHANGED_PROPERTY(DrawLuminanceMaskChange, drawLuminanceMask);
+ CHECK_FOR_CHANGED_PROPERTY(ImageInterpolationQualityChange, imageInterpolationQuality);
+
+#if HAVE(OS_DARK_MODE_SUPPORT)
+ CHECK_FOR_CHANGED_PROPERTY(UseDarkAppearanceChange, useDarkAppearance);
+#endif
+
+ return changeFlags;
+}
+
+void GraphicsContextStateChange::accumulate(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
+{
+ m_state.mergeChanges(state, flags);
+
+ auto strokeFlags = { GraphicsContextState::StrokeColorChange, GraphicsContextState::StrokeGradientChange, GraphicsContextState::StrokePatternChange };
+ if (flags.containsAny(strokeFlags))
+ m_changeFlags.remove(strokeFlags);
+
+ auto fillFlags = { GraphicsContextState::FillColorChange, GraphicsContextState::FillGradientChange, GraphicsContextState::FillPatternChange };
+ if (flags.containsAny(fillFlags))
+ m_changeFlags.remove(fillFlags);
+
+ auto compositeOperatorFlags = { GraphicsContextState::CompositeOperationChange, GraphicsContextState::BlendModeChange };
+ if (flags.containsAny(compositeOperatorFlags))
+ m_changeFlags.remove(compositeOperatorFlags);
+
+ m_changeFlags.add(flags);
+}
+
+void GraphicsContextStateChange::apply(GraphicsContext& context) const
+{
+ if (m_changeFlags.contains(GraphicsContextState::StrokeGradientChange))
+ context.setStrokeGradient(*m_state.strokeGradient, m_state.strokeGradientSpaceTransform);
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokePatternChange))
+ context.setStrokePattern(*m_state.strokePattern);
+
+ if (m_changeFlags.contains(GraphicsContextState::FillGradientChange))
+ context.setFillGradient(*m_state.fillGradient, m_state.fillGradientSpaceTransform);
+
+ if (m_changeFlags.contains(GraphicsContextState::FillPatternChange))
+ context.setFillPattern(*m_state.fillPattern);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShadowsIgnoreTransformsChange))
+ context.setShadowsIgnoreTransforms(m_state.shadowsIgnoreTransforms);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShadowChange))
+ context.setShadow(m_state.shadowOffset, m_state.shadowBlur, m_state.shadowColor, m_state.shadowRadiusMode);
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokeThicknessChange))
+ context.setStrokeThickness(m_state.strokeThickness);
+
+ if (m_changeFlags.contains(GraphicsContextState::TextDrawingModeChange))
+ context.setTextDrawingMode(m_state.textDrawingMode);
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokeColorChange))
+ context.setStrokeColor(m_state.strokeColor);
+
+ if (m_changeFlags.contains(GraphicsContextState::FillColorChange))
+ context.setFillColor(m_state.fillColor);
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokeStyleChange))
+ context.setStrokeStyle(m_state.strokeStyle);
+
+ if (m_changeFlags.contains(GraphicsContextState::FillRuleChange))
+ context.setFillRule(m_state.fillRule);
+
+ if (m_changeFlags.contains(GraphicsContextState::AlphaChange))
+ context.setAlpha(m_state.alpha);
+
+ if (m_changeFlags.containsAny({ GraphicsContextState::CompositeOperationChange, GraphicsContextState::BlendModeChange }))
+ context.setCompositeOperation(m_state.compositeOperator, m_state.blendMode);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShouldAntialiasChange))
+ context.setShouldAntialias(m_state.shouldAntialias);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShouldSmoothFontsChange))
+ context.setShouldSmoothFonts(m_state.shouldSmoothFonts);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShouldSubpixelQuantizeFontsChange))
+ context.setShouldSubpixelQuantizeFonts(m_state.shouldSubpixelQuantizeFonts);
+
+ if (m_changeFlags.contains(GraphicsContextState::DrawLuminanceMaskChange))
+ context.setDrawLuminanceMask(m_state.drawLuminanceMask);
+
+ if (m_changeFlags.contains(GraphicsContextState::ImageInterpolationQualityChange))
+ context.setImageInterpolationQuality(m_state.imageInterpolationQuality);
+
+#if HAVE(OS_DARK_MODE_SUPPORT)
+ if (m_changeFlags.contains(GraphicsContextState::UseDarkAppearanceChange))
+ context.setUseDarkAppearance(m_state.useDarkAppearance);
+#endif
+}
+
+void GraphicsContextStateChange::dump(TextStream& ts) const
+{
+ ts.dumpProperty("change-flags", m_changeFlags.toRaw());
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokeGradientChange))
+ ts.dumpProperty("stroke-gradient", m_state.strokeGradient.get());
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokePatternChange))
+ ts.dumpProperty("stroke-pattern", m_state.strokePattern.get());
+
+ if (m_changeFlags.contains(GraphicsContextState::FillGradientChange))
+ ts.dumpProperty("fill-gradient", m_state.fillGradient.get());
+
+ if (m_changeFlags.contains(GraphicsContextState::FillPatternChange))
+ ts.dumpProperty("fill-pattern", m_state.fillPattern.get());
+
+ if (m_changeFlags.contains(GraphicsContextState::ShadowChange)) {
+ ts.dumpProperty("shadow-blur", m_state.shadowBlur);
+ ts.dumpProperty("shadow-offset", m_state.shadowOffset);
+ ts.dumpProperty("shadow-color", m_state.shadowColor);
+ ts.dumpProperty("shadows-use-legacy-radius", m_state.shadowRadiusMode == ShadowRadiusMode::Legacy);
+ }
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokeThicknessChange))
+ ts.dumpProperty("stroke-thickness", m_state.strokeThickness);
+
+ if (m_changeFlags.contains(GraphicsContextState::TextDrawingModeChange))
+ ts.dumpProperty("text-drawing-mode", m_state.textDrawingMode.toRaw());
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokeColorChange))
+ ts.dumpProperty("stroke-color", m_state.strokeColor);
+
+ if (m_changeFlags.contains(GraphicsContextState::FillColorChange))
+ ts.dumpProperty("fill-color", m_state.fillColor);
+
+ if (m_changeFlags.contains(GraphicsContextState::StrokeStyleChange))
+ ts.dumpProperty("stroke-style", m_state.strokeStyle);
+
+ if (m_changeFlags.contains(GraphicsContextState::FillRuleChange))
+ ts.dumpProperty("fill-rule", m_state.fillRule);
+
+ if (m_changeFlags.contains(GraphicsContextState::AlphaChange))
+ ts.dumpProperty("alpha", m_state.alpha);
+
+ if (m_changeFlags.contains(GraphicsContextState::CompositeOperationChange))
+ ts.dumpProperty("composite-operator", m_state.compositeOperator);
+
+ if (m_changeFlags.contains(GraphicsContextState::BlendModeChange))
+ ts.dumpProperty("blend-mode", m_state.blendMode);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShouldAntialiasChange))
+ ts.dumpProperty("should-antialias", m_state.shouldAntialias);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShouldSmoothFontsChange))
+ ts.dumpProperty("should-smooth-fonts", m_state.shouldSmoothFonts);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShouldSubpixelQuantizeFontsChange))
+ ts.dumpProperty("should-subpixel-quantize-fonts", m_state.shouldSubpixelQuantizeFonts);
+
+ if (m_changeFlags.contains(GraphicsContextState::ShadowsIgnoreTransformsChange))
+ ts.dumpProperty("shadows-ignore-transforms", m_state.shadowsIgnoreTransforms);
+
+ if (m_changeFlags.contains(GraphicsContextState::DrawLuminanceMaskChange))
+ ts.dumpProperty("draw-luminance-mask", m_state.drawLuminanceMask);
+
+#if HAVE(OS_DARK_MODE_SUPPORT)
+ if (m_changeFlags.contains(GraphicsContextState::UseDarkAppearanceChange))
+ ts.dumpProperty("use-dark-appearance", m_state.useDarkAppearance);
+#endif
+}
+
+TextStream& operator<<(TextStream& ts, const GraphicsContextStateChange& stateChange)
+{
+ stateChange.dump(ts);
+ return ts;
+}
+
+} // namespace WebCore
Added: trunk/Source/WebCore/platform/graphics/GraphicsContextState.h (0 => 291364)
--- trunk/Source/WebCore/platform/graphics/GraphicsContextState.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextState.h 2022-03-16 20:52:19 UTC (rev 291364)
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "AffineTransform.h"
+#include "Color.h"
+#include "FloatSize.h"
+#include "GraphicsTypes.h"
+#include "WindRule.h"
+#include <wtf/OptionSet.h>
+
+namespace WebCore {
+
+class GraphicsContext;
+class Gradient;
+class Pattern;
+
+struct GraphicsContextState {
+ WEBCORE_EXPORT GraphicsContextState();
+ WEBCORE_EXPORT ~GraphicsContextState();
+
+ GraphicsContextState(const GraphicsContextState&);
+ WEBCORE_EXPORT GraphicsContextState(GraphicsContextState&&);
+
+ GraphicsContextState& operator=(const GraphicsContextState&);
+ WEBCORE_EXPORT GraphicsContextState& operator=(GraphicsContextState&&);
+
+ enum Change : uint32_t {
+ StrokeGradientChange = 1 << 0,
+ StrokePatternChange = 1 << 1,
+ FillGradientChange = 1 << 2,
+ FillPatternChange = 1 << 3,
+ StrokeThicknessChange = 1 << 4,
+ StrokeColorChange = 1 << 5,
+ StrokeStyleChange = 1 << 6,
+ FillColorChange = 1 << 7,
+ FillRuleChange = 1 << 8,
+ ShadowChange = 1 << 9,
+ ShadowsIgnoreTransformsChange = 1 << 10,
+ AlphaChange = 1 << 11,
+ CompositeOperationChange = 1 << 12,
+ BlendModeChange = 1 << 13,
+ TextDrawingModeChange = 1 << 14,
+ ShouldAntialiasChange = 1 << 15,
+ ShouldSmoothFontsChange = 1 << 16,
+ ShouldSubpixelQuantizeFontsChange = 1 << 17,
+ DrawLuminanceMaskChange = 1 << 18,
+ ImageInterpolationQualityChange = 1 << 19,
+#if HAVE(OS_DARK_MODE_SUPPORT)
+ UseDarkAppearanceChange = 1 << 20,
+#endif
+ };
+ using StateChangeFlags = OptionSet<Change>;
+
+ void mergeChanges(const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
+
+ RefPtr<Gradient> strokeGradient;
+ RefPtr<Pattern> strokePattern;
+
+ RefPtr<Gradient> fillGradient;
+ RefPtr<Pattern> fillPattern;
+
+ FloatSize shadowOffset;
+
+ Color strokeColor { Color::black };
+ Color fillColor { Color::black };
+ Color shadowColor;
+
+ AffineTransform strokeGradientSpaceTransform;
+ AffineTransform fillGradientSpaceTransform;
+
+ float strokeThickness { 0 };
+ float shadowBlur { 0 };
+ float alpha { 1 };
+
+ StrokeStyle strokeStyle { SolidStroke };
+ WindRule fillRule { WindRule::NonZero };
+
+ TextDrawingModeFlags textDrawingMode { TextDrawingMode::Fill };
+ CompositeOperator compositeOperator { CompositeOperator::SourceOver };
+ BlendMode blendMode { BlendMode::Normal };
+ InterpolationQuality imageInterpolationQuality { InterpolationQuality::Default };
+ ShadowRadiusMode shadowRadiusMode { ShadowRadiusMode::Default };
+
+ bool shouldAntialias : 1;
+ bool shouldSmoothFonts : 1;
+ bool shouldSubpixelQuantizeFonts : 1;
+ bool shadowsIgnoreTransforms : 1;
+ bool drawLuminanceMask : 1;
+#if HAVE(OS_DARK_MODE_SUPPORT)
+ bool useDarkAppearance : 1;
+#endif
+};
+
+struct GraphicsContextStateChange {
+ GraphicsContextStateChange() = default;
+ GraphicsContextStateChange(const GraphicsContextState& state, GraphicsContextState::StateChangeFlags flags)
+ : m_state(state)
+ , m_changeFlags(flags)
+ {
+ }
+
+ GraphicsContextState::StateChangeFlags changesFromState(const GraphicsContextState&) const;
+
+ void accumulate(const GraphicsContextState&, GraphicsContextState::StateChangeFlags);
+ void apply(GraphicsContext&) const;
+
+ void dump(WTF::TextStream&) const;
+
+ GraphicsContextState m_state;
+ GraphicsContextState::StateChangeFlags m_changeFlags;
+};
+
+WTF::TextStream& operator<<(WTF::TextStream&, const GraphicsContextStateChange&);
+
+} // namespace WebCore
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::GraphicsContextState::Change> {
+ using values = EnumValues<
+ WebCore::GraphicsContextState::Change,
+ WebCore::GraphicsContextState::Change::StrokeGradientChange,
+ WebCore::GraphicsContextState::Change::StrokePatternChange,
+ WebCore::GraphicsContextState::Change::FillGradientChange,
+ WebCore::GraphicsContextState::Change::FillPatternChange,
+ WebCore::GraphicsContextState::Change::StrokeThicknessChange,
+ WebCore::GraphicsContextState::Change::StrokeColorChange,
+ WebCore::GraphicsContextState::Change::StrokeStyleChange,
+ WebCore::GraphicsContextState::Change::FillColorChange,
+ WebCore::GraphicsContextState::Change::FillRuleChange,
+ WebCore::GraphicsContextState::Change::ShadowChange,
+ WebCore::GraphicsContextState::Change::ShadowsIgnoreTransformsChange,
+ WebCore::GraphicsContextState::Change::AlphaChange,
+ WebCore::GraphicsContextState::Change::CompositeOperationChange,
+ WebCore::GraphicsContextState::Change::BlendModeChange,
+ WebCore::GraphicsContextState::Change::TextDrawingModeChange,
+ WebCore::GraphicsContextState::Change::ShouldAntialiasChange,
+ WebCore::GraphicsContextState::Change::ShouldSmoothFontsChange,
+ WebCore::GraphicsContextState::Change::ShouldSubpixelQuantizeFontsChange,
+ WebCore::GraphicsContextState::Change::DrawLuminanceMaskChange,
+ WebCore::GraphicsContextState::Change::ImageInterpolationQualityChange
+#if HAVE(OS_DARK_MODE_SUPPORT)
+ , WebCore::GraphicsContextState::Change::UseDarkAppearanceChange
+#endif
+ >;
+};
+
+} // namespace WTF
Added: trunk/Source/WebCore/platform/graphics/GraphicsContextStateSaver.h (0 => 291364)
--- trunk/Source/WebCore/platform/graphics/GraphicsContextStateSaver.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextStateSaver.h 2022-03-16 20:52:19 UTC (rev 291364)
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+namespace WebCore {
+
+class GraphicsContextStateSaver {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ GraphicsContextStateSaver(GraphicsContext& context, bool saveAndRestore = true)
+ : m_context(context)
+ , m_saveAndRestore(saveAndRestore)
+ {
+ if (m_saveAndRestore)
+ m_context.save();
+ }
+
+ ~GraphicsContextStateSaver()
+ {
+ if (m_saveAndRestore)
+ m_context.restore();
+ }
+
+ void save()
+ {
+ ASSERT(!m_saveAndRestore);
+ m_context.save();
+ m_saveAndRestore = true;
+ }
+
+ void restore()
+ {
+ ASSERT(m_saveAndRestore);
+ m_context.restore();
+ m_saveAndRestore = false;
+ }
+
+ GraphicsContext* context() const { return &m_context; }
+
+private:
+ GraphicsContext& m_context;
+ bool m_saveAndRestore;
+};
+
+class TransparencyLayerScope {
+public:
+ TransparencyLayerScope(GraphicsContext& context, float alpha, bool beginLayer = true)
+ : m_context(context)
+ , m_alpha(alpha)
+ , m_beganLayer(beginLayer)
+ {
+ if (beginLayer)
+ m_context.beginTransparencyLayer(m_alpha);
+ }
+
+ void beginLayer(float alpha)
+ {
+ m_alpha = alpha;
+ m_context.beginTransparencyLayer(m_alpha);
+ m_beganLayer = true;
+ }
+
+ ~TransparencyLayerScope()
+ {
+ if (m_beganLayer)
+ m_context.endTransparencyLayer();
+ }
+
+private:
+ GraphicsContext& m_context;
+ float m_alpha;
+ bool m_beganLayer;
+};
+
+class GraphicsContextStateStackChecker {
+public:
+ GraphicsContextStateStackChecker(GraphicsContext& context)
+ : m_context(context)
+ , m_stackSize(context.stackSize())
+ { }
+
+ ~GraphicsContextStateStackChecker()
+ {
+ if (m_context.stackSize() != m_stackSize)
+ WTFLogAlways("GraphicsContext %p stack changed by %d", &m_context, (int)m_context.stackSize() - (int)m_stackSize);
+ }
+
+private:
+ GraphicsContext& m_context;
+ unsigned m_stackSize;
+};
+
+class InterpolationQualityMaintainer {
+public:
+ explicit InterpolationQualityMaintainer(GraphicsContext& graphicsContext, InterpolationQuality interpolationQualityToUse)
+ : m_graphicsContext(graphicsContext)
+ , m_currentInterpolationQuality(graphicsContext.imageInterpolationQuality())
+ , m_interpolationQualityChanged(interpolationQualityToUse != InterpolationQuality::Default && m_currentInterpolationQuality != interpolationQualityToUse)
+ {
+ if (m_interpolationQualityChanged)
+ m_graphicsContext.setImageInterpolationQuality(interpolationQualityToUse);
+ }
+
+ explicit InterpolationQualityMaintainer(GraphicsContext& graphicsContext, std::optional<InterpolationQuality> interpolationQuality)
+ : InterpolationQualityMaintainer(graphicsContext, interpolationQuality ? interpolationQuality.value() : graphicsContext.imageInterpolationQuality())
+ {
+ }
+
+ ~InterpolationQualityMaintainer()
+ {
+ if (m_interpolationQualityChanged)
+ m_graphicsContext.setImageInterpolationQuality(m_currentInterpolationQuality);
+ }
+
+private:
+ GraphicsContext& m_graphicsContext;
+ InterpolationQuality m_currentInterpolationQuality;
+ bool m_interpolationQualityChanged;
+};
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/GraphicsTypes.h (291363 => 291364)
--- trunk/Source/WebCore/platform/graphics/GraphicsTypes.h 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/platform/graphics/GraphicsTypes.h 2022-03-16 20:52:19 UTC (rev 291364)
@@ -26,6 +26,7 @@
#pragma once
#include "WindRule.h"
+#include <optional>
#include <wtf/EnumTraits.h>
#include <wtf/Forward.h>
@@ -73,6 +74,43 @@
PlusLighter
};
+struct DocumentMarkerLineStyle {
+ enum class Mode : uint8_t {
+ TextCheckingDictationPhraseWithAlternatives,
+ Spelling,
+ Grammar,
+ AutocorrectionReplacement,
+ DictationAlternatives
+ } mode;
+ bool shouldUseDarkAppearance { false };
+
+ template<class Encoder> void encode(Encoder&) const;
+ template<class Decoder> static std::optional<DocumentMarkerLineStyle> decode(Decoder&);
+};
+
+template<class Encoder>
+void DocumentMarkerLineStyle::encode(Encoder& encoder) const
+{
+ encoder << mode;
+ encoder << shouldUseDarkAppearance;
+}
+
+template<class Decoder>
+std::optional<DocumentMarkerLineStyle> DocumentMarkerLineStyle::decode(Decoder& decoder)
+{
+ std::optional<Mode> mode;
+ decoder >> mode;
+ if (!mode)
+ return std::nullopt;
+
+ std::optional<bool> shouldUseDarkAppearance;
+ decoder >> shouldUseDarkAppearance;
+ if (!shouldUseDarkAppearance)
+ return std::nullopt;
+
+ return { { *mode, *shouldUseDarkAppearance } };
+}
+
enum class GradientSpreadMethod : uint8_t {
Pad,
Reflect,
@@ -105,6 +143,28 @@
AlignHCenter
};
+enum StrokeStyle {
+ NoStroke,
+ SolidStroke,
+ DottedStroke,
+ DashedStroke,
+ DoubleStroke,
+ WavyStroke,
+};
+
+enum class TextDrawingMode : uint8_t {
+ Fill = 1 << 0,
+ Stroke = 1 << 1,
+};
+using TextDrawingModeFlags = OptionSet<TextDrawingMode>;
+
+// Legacy shadow blur radius is used for canvas, and -webkit-box-shadow.
+// It has different treatment of radii > 8px.
+enum class ShadowRadiusMode : bool {
+ Default,
+ Legacy
+};
+
enum TextBaseline {
AlphabeticTextBaseline,
TopTextBaseline,
@@ -219,4 +279,35 @@
>;
};
+template<> struct EnumTraits<WebCore::DocumentMarkerLineStyle::Mode> {
+ using values = EnumValues<
+ WebCore::DocumentMarkerLineStyle::Mode,
+ WebCore::DocumentMarkerLineStyle::Mode::TextCheckingDictationPhraseWithAlternatives,
+ WebCore::DocumentMarkerLineStyle::Mode::Spelling,
+ WebCore::DocumentMarkerLineStyle::Mode::Grammar,
+ WebCore::DocumentMarkerLineStyle::Mode::AutocorrectionReplacement,
+ WebCore::DocumentMarkerLineStyle::Mode::DictationAlternatives
+ >;
+};
+
+template<> struct EnumTraits<WebCore::StrokeStyle> {
+ using values = EnumValues<
+ WebCore::StrokeStyle,
+ WebCore::StrokeStyle::NoStroke,
+ WebCore::StrokeStyle::SolidStroke,
+ WebCore::StrokeStyle::DottedStroke,
+ WebCore::StrokeStyle::DashedStroke,
+ WebCore::StrokeStyle::DoubleStroke,
+ WebCore::StrokeStyle::WavyStroke
+ >;
+};
+
+template<> struct EnumTraits<WebCore::TextDrawingMode> {
+ using values = EnumValues<
+ WebCore::TextDrawingMode,
+ WebCore::TextDrawingMode::Fill,
+ WebCore::TextDrawingMode::Stroke
+ >;
+};
+
} // namespace WTF
Added: trunk/Source/WebCore/platform/graphics/PlatformGraphicsContext.h (0 => 291364)
--- trunk/Source/WebCore/platform/graphics/PlatformGraphicsContext.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/PlatformGraphicsContext.h 2022-03-16 20:52:19 UTC (rev 291364)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(WIN)
+#include "DIBPixelData.h"
+typedef struct HDC__* HDC;
+#if !USE(CG)
+// UInt8 is defined in CoreFoundation/CFBase.h
+typedef unsigned char UInt8;
+#endif
+#endif
+
+#if USE(CG)
+using PlatformGraphicsContext = struct CGContext;
+#elif USE(CAIRO)
+namespace WebCore {
+class GraphicsContextCairo;
+}
+using PlatformGraphicsContext = WebCore::GraphicsContextCairo;
+#else
+using PlatformGraphicsContext = void;
+#endif
Added: trunk/Source/WebCore/platform/graphics/TextBoxIterator.h (0 => 291364)
--- trunk/Source/WebCore/platform/graphics/TextBoxIterator.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/TextBoxIterator.h 2022-03-16 20:52:19 UTC (rev 291364)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "TextRun.h"
+
+namespace WebCore {
+
+class TextBoxIterator {
+public:
+ TextBoxIterator() = default;
+
+ TextBoxIterator(const TextRun* textRun, unsigned offset)
+ : m_textRun(textRun)
+ , m_offset(offset)
+ {
+ }
+
+ unsigned offset() const { return m_offset; }
+ void increment() { m_offset++; }
+ bool atEnd() const { return !m_textRun || m_offset >= m_textRun->length(); }
+ UChar current() const { return (*m_textRun)[m_offset]; }
+ UCharDirection direction() const { return atEnd() ? U_OTHER_NEUTRAL : u_charDirection(current()); }
+
+ bool operator==(const TextBoxIterator& other) const
+ {
+ return m_offset == other.m_offset && m_textRun == other.m_textRun;
+ }
+
+ bool operator!=(const TextBoxIterator& other) const { return !operator==(other); }
+
+private:
+ const TextRun* m_textRun { nullptr };
+ unsigned m_offset { 0 };
+};
+
+} // namespace WebCore
Added: trunk/Source/WebCore/platform/graphics/cg/CGContextStateSaver.h (0 => 291364)
--- trunk/Source/WebCore/platform/graphics/cg/CGContextStateSaver.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cg/CGContextStateSaver.h 2022-03-16 20:52:19 UTC (rev 291364)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2006-2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(CG)
+
+namespace WebCore {
+
+class CGContextStateSaver {
+public:
+ CGContextStateSaver(CGContextRef context, bool saveAndRestore = true)
+ : m_context(context)
+ , m_saveAndRestore(saveAndRestore)
+ {
+ if (m_saveAndRestore)
+ CGContextSaveGState(m_context);
+ }
+
+ ~CGContextStateSaver()
+ {
+ if (m_saveAndRestore)
+ CGContextRestoreGState(m_context);
+ }
+
+ void save()
+ {
+ ASSERT(!m_saveAndRestore);
+ CGContextSaveGState(m_context);
+ m_saveAndRestore = true;
+ }
+
+ void restore()
+ {
+ ASSERT(m_saveAndRestore);
+ CGContextRestoreGState(m_context);
+ m_saveAndRestore = false;
+ }
+
+ bool didSave() const
+ {
+ return m_saveAndRestore;
+ }
+
+private:
+ CGContextRef m_context;
+ bool m_saveAndRestore;
+};
+
+} // namespace WebCore
+
+#endif // USE(CG)
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h (291363 => 291364)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h 2022-03-16 20:50:30 UTC (rev 291363)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h 2022-03-16 20:52:19 UTC (rev 291364)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2010, 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,53 +25,13 @@
#pragma once
+#if USE(CG)
+
#include "ColorSpaceCG.h"
#include "GraphicsContext.h"
namespace WebCore {
-CGAffineTransform getUserToBaseCTM(CGContextRef);
-
-class CGContextStateSaver {
-public:
- CGContextStateSaver(CGContextRef context, bool saveAndRestore = true)
- : m_context(context)
- , m_saveAndRestore(saveAndRestore)
- {
- if (m_saveAndRestore)
- CGContextSaveGState(m_context);
- }
-
- ~CGContextStateSaver()
- {
- if (m_saveAndRestore)
- CGContextRestoreGState(m_context);
- }
-
- void save()
- {
- ASSERT(!m_saveAndRestore);
- CGContextSaveGState(m_context);
- m_saveAndRestore = true;
- }
-
- void restore()
- {
- ASSERT(m_saveAndRestore);
- CGContextRestoreGState(m_context);
- m_saveAndRestore = false;
- }
-
- bool didSave() const
- {
- return m_saveAndRestore;
- }
-
-private:
- CGContextRef m_context;
- bool m_saveAndRestore;
-};
-
class WEBCORE_EXPORT GraphicsContextCG : public GraphicsContext {
public:
GraphicsContextCG(CGContextRef);
@@ -179,5 +139,10 @@
GraphicsContextPlatformPrivate* m_data { nullptr };
};
-}
+CGAffineTransform getUserToBaseCTM(CGContextRef);
+} // namespace WebCore
+
+#include "CGContextStateSaver.h"
+
+#endif // USE(CG)