Title: [194798] trunk/Source/WebCore
Revision
194798
Author
simon.fra...@apple.com
Date
2016-01-08 15:26:48 -0800 (Fri, 08 Jan 2016)

Log Message

Consider painting to be disabled on a GraphicsContext with no platform data, and make updatingControlTints() immutable state
https://bugs.webkit.org/show_bug.cgi?id=152927

Reviewed by Tim Horton.

GraphicsContext had setters for paintingDisabled and updatingControlTints, but neither
were changed dynamically.

We can eliminate paintingDisabled by simply considering a GraphicsContext that was
created with no platform context to be paint-disabled.

We make updatingControlTints immutable state by providing a constructor that takes
a "NonPaintingReasons" enum, and doesn't create platform data.

More functions in platform code were protected by if (paintingDisabled())...

* page/FrameView.cpp:
(WebCore::FrameView::paintControlTints):
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::GraphicsContext):
(WebCore::GraphicsContext::fillRoundedRect):
(WebCore::GraphicsContext::setUpdatingControlTints): Deleted.
(WebCore::GraphicsContext::clip): Deleted.
* platform/graphics/GraphicsContext.h:
(WebCore::GraphicsContext::paintingDisabled):
(WebCore::GraphicsContext::updatingControlTints):
(WebCore::GraphicsContextState::GraphicsContextState): Deleted.
(WebCore::GraphicsContext::setPaintingDisabled): Deleted.
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::GraphicsContext):
(WebCore::GraphicsContext::platformInit):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::savePlatformState):
(WebCore::GraphicsContext::restorePlatformState):
(WebCore::GraphicsContext::drawNativeImage):
(WebCore::GraphicsContext::drawPattern):
(WebCore::GraphicsContext::drawRect):
(WebCore::GraphicsContext::applyStrokePattern):
(WebCore::GraphicsContext::applyFillPattern):
(WebCore::GraphicsContext::clip):
(WebCore::GraphicsContext::clipBounds):
(WebCore::GraphicsContext::setLineDash):
(WebCore::GraphicsContext::roundToDevicePixels):
(WebCore::GraphicsContext::setPlatformImageInterpolationQuality):
(WebCore::GraphicsContext::setIsCALayerContext):
(WebCore::GraphicsContext::isCALayerContext):
(WebCore::GraphicsContext::setIsAcceleratedContext):
(WebCore::GraphicsContext::isAcceleratedContext):
(WebCore::GraphicsContext::platformApplyDeviceScaleFactor):
* platform/graphics/win/GraphicsContextCGWin.cpp:
(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::GraphicsContext): Deleted.
* platform/graphics/win/GraphicsContextCairoWin.cpp:
(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::GraphicsContext): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (194797 => 194798)


--- trunk/Source/WebCore/ChangeLog	2016-01-08 23:25:15 UTC (rev 194797)
+++ trunk/Source/WebCore/ChangeLog	2016-01-08 23:26:48 UTC (rev 194798)
@@ -1,3 +1,62 @@
+2016-01-08  Simon Fraser  <simon.fra...@apple.com>
+
+        Consider painting to be disabled on a GraphicsContext with no platform data, and make updatingControlTints() immutable state
+        https://bugs.webkit.org/show_bug.cgi?id=152927
+
+        Reviewed by Tim Horton.
+
+        GraphicsContext had setters for paintingDisabled and updatingControlTints, but neither
+        were changed dynamically.
+        
+        We can eliminate paintingDisabled by simply considering a GraphicsContext that was
+        created with no platform context to be paint-disabled.
+        
+        We make updatingControlTints immutable state by providing a constructor that takes
+        a "NonPaintingReasons" enum, and doesn't create platform data.
+        
+        More functions in platform code were protected by if (paintingDisabled())...
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::paintControlTints):
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::GraphicsContext):
+        (WebCore::GraphicsContext::fillRoundedRect):
+        (WebCore::GraphicsContext::setUpdatingControlTints): Deleted.
+        (WebCore::GraphicsContext::clip): Deleted.
+        * platform/graphics/GraphicsContext.h:
+        (WebCore::GraphicsContext::paintingDisabled):
+        (WebCore::GraphicsContext::updatingControlTints):
+        (WebCore::GraphicsContextState::GraphicsContextState): Deleted.
+        (WebCore::GraphicsContext::setPaintingDisabled): Deleted.
+        * platform/graphics/cairo/GraphicsContextCairo.cpp:
+        (WebCore::GraphicsContext::GraphicsContext):
+        (WebCore::GraphicsContext::platformInit):
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::platformInit):
+        (WebCore::GraphicsContext::savePlatformState):
+        (WebCore::GraphicsContext::restorePlatformState):
+        (WebCore::GraphicsContext::drawNativeImage):
+        (WebCore::GraphicsContext::drawPattern):
+        (WebCore::GraphicsContext::drawRect):
+        (WebCore::GraphicsContext::applyStrokePattern):
+        (WebCore::GraphicsContext::applyFillPattern):
+        (WebCore::GraphicsContext::clip):
+        (WebCore::GraphicsContext::clipBounds):
+        (WebCore::GraphicsContext::setLineDash):
+        (WebCore::GraphicsContext::roundToDevicePixels):
+        (WebCore::GraphicsContext::setPlatformImageInterpolationQuality):
+        (WebCore::GraphicsContext::setIsCALayerContext):
+        (WebCore::GraphicsContext::isCALayerContext):
+        (WebCore::GraphicsContext::setIsAcceleratedContext):
+        (WebCore::GraphicsContext::isAcceleratedContext):
+        (WebCore::GraphicsContext::platformApplyDeviceScaleFactor):
+        * platform/graphics/win/GraphicsContextCGWin.cpp:
+        (WebCore::GraphicsContext::platformInit):
+        (WebCore::GraphicsContext::GraphicsContext): Deleted.
+        * platform/graphics/win/GraphicsContextCairoWin.cpp:
+        (WebCore::GraphicsContext::platformInit):
+        (WebCore::GraphicsContext::GraphicsContext): Deleted.
+
 2016-01-08  Anders Carlsson  <ander...@apple.com>
 
         InputType::findClosestTickMarkValue should return an Optional<Decimal>

Modified: trunk/Source/WebCore/page/FrameView.cpp (194797 => 194798)


--- trunk/Source/WebCore/page/FrameView.cpp	2016-01-08 23:25:15 UTC (rev 194797)
+++ trunk/Source/WebCore/page/FrameView.cpp	2016-01-08 23:26:48 UTC (rev 194798)
@@ -3897,8 +3897,7 @@
     if (needsLayout())
         layout();
 
-    GraphicsContext context((PlatformGraphicsContext*)nullptr);
-    context.setUpdatingControlTints(true);
+    GraphicsContext context(GraphicsContext::NonPaintingReasons::UpdatingControlTints);
     if (platformWidget()) {
         // FIXME: consult paintsEntireContents().
         paintContents(context, visibleContentRect(LegacyIOSDocumentVisibleRect));

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (194797 => 194798)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2016-01-08 23:25:15 UTC (rev 194797)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2016-01-08 23:26:48 UTC (rev 194798)
@@ -359,10 +359,12 @@
     return ts;
 }
 
+GraphicsContext::GraphicsContext(NonPaintingReasons nonPaintingReasons)
+    : m_nonPaintingReasons(nonPaintingReasons)
+{
+}
 
 GraphicsContext::GraphicsContext(PlatformGraphicsContext* platformGraphicsContext)
-    : m_updatingControlTints(false)
-    , m_transparencyCount(0)
 {
     platformInit(platformGraphicsContext);
 }
@@ -570,12 +572,6 @@
     --m_transparencyCount;
 }
 
-void GraphicsContext::setUpdatingControlTints(bool b)
-{
-    setPaintingDisabled(b);
-    m_updatingControlTints = b;
-}
-
 float GraphicsContext::drawText(const FontCascade& font, const TextRun& run, const FloatPoint& point, int from, int to)
 {
     if (paintingDisabled())
@@ -732,11 +728,6 @@
     ImageBuffer::drawConsuming(WTFMove(image), *this, destination, source, imagePaintingOptions.m_compositeOperator, imagePaintingOptions.m_blendMode, imagePaintingOptions.m_useLowQualityScale);
 }
 
-void GraphicsContext::clip(const IntRect& rect)
-{
-    clip(FloatRect(rect));
-}
-
 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect)
 {
     if (paintingDisabled())
@@ -798,6 +789,9 @@
 
 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color& color, BlendMode blendMode)
 {
+    if (paintingDisabled())
+        return;
+
     if (rect.isRounded()) {
         setCompositeOperation(compositeOperation(), blendMode);
         platformFillRoundedRect(rect, color);

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (194797 => 194798)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2016-01-08 23:25:15 UTC (rev 194797)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2016-01-08 23:26:48 UTC (rev 194798)
@@ -116,7 +116,6 @@
         , shouldSmoothFonts(true)
         , antialiasedFontDilationEnabled(true)
         , shouldSubpixelQuantizeFonts(true)
-        , paintingDisabled(false)
         , shadowsIgnoreTransforms(false)
 #if USE(CG)
         // Core Graphics incorrectly renders shadows with radius > 8px (<rdar://problem/8103442>),
@@ -183,7 +182,6 @@
     bool shouldSmoothFonts : 1;
     bool antialiasedFontDilationEnabled : 1;
     bool shouldSubpixelQuantizeFonts : 1;
-    bool paintingDisabled : 1;
     bool shadowsIgnoreTransforms : 1;
 #if USE(CG)
     bool shadowsUseLegacyRadius : 1;
@@ -249,9 +247,18 @@
 public:
     WEBCORE_EXPORT GraphicsContext(PlatformGraphicsContext*);
     WEBCORE_EXPORT ~GraphicsContext();
+    
+    enum class NonPaintingReasons {
+        NoReasons,
+        UpdatingControlTints
+    };
+    GraphicsContext(NonPaintingReasons);
 
     WEBCORE_EXPORT PlatformGraphicsContext* platformContext() const;
 
+    bool paintingDisabled() const { return !m_data; }
+    bool updatingControlTints() const { return m_nonPaintingReasons == NonPaintingReasons::UpdatingControlTints; }
+
     void setStrokeThickness(float);
     float strokeThickness() const { return m_state.strokeThickness; }
 
@@ -367,7 +374,6 @@
     WEBCORE_EXPORT void setImageInterpolationQuality(InterpolationQuality);
     InterpolationQuality imageInterpolationQuality() const { return m_state.imageInterpolationQuality; }
 
-    WEBCORE_EXPORT void clip(const IntRect&);
     WEBCORE_EXPORT void clip(const FloatRect&);
     void clipRoundedRect(const FloatRoundedRect&);
 
@@ -408,12 +414,6 @@
     static void updateDocumentMarkerResources();
     void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle);
 
-    void setPaintingDisabled(bool paintingDisabled) { m_state.paintingDisabled = paintingDisabled; }
-    bool paintingDisabled() const { return m_state.paintingDisabled; }
-
-    void setUpdatingControlTints(bool);
-    bool updatingControlTints() const { return m_updatingControlTints; }
-
     WEBCORE_EXPORT void beginTransparencyLayer(float opacity);
     WEBCORE_EXPORT void endTransparencyLayer();
     bool isInTransparencyLayer() const { return (m_transparencyCount > 0) && supportsTransparencyLayers(); }
@@ -601,12 +601,13 @@
 
     FloatRect computeLineBoundsAndAntialiasingModeForText(const FloatPoint&, float width, bool printing,  Color&);
 
-    GraphicsContextPlatformPrivate* m_data;
+    GraphicsContextPlatformPrivate* m_data { nullptr };
 
     GraphicsContextState m_state;
     Vector<GraphicsContextState, 1> m_stack;
-    bool m_updatingControlTints;
-    unsigned m_transparencyCount;
+
+    const NonPaintingReasons m_nonPaintingReasons { NonPaintingReasons::NoReasons };
+    unsigned m_transparencyCount { 0 };
 };
 
 class GraphicsContextStateSaver {

Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (194797 => 194798)


--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2016-01-08 23:25:15 UTC (rev 194797)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp	2016-01-08 23:26:48 UTC (rev 194798)
@@ -175,19 +175,20 @@
 }
 
 GraphicsContext::GraphicsContext(cairo_t* cr)
-    : m_updatingControlTints(false)
-    , m_transparencyCount(0)
 {
+    if (!cr)
+        return;
+
     m_data = new GraphicsContextPlatformPrivateToplevel(new PlatformContextCairo(cr));
 }
 
 void GraphicsContext::platformInit(PlatformContextCairo* platformContext)
 {
+    if (!platformContext)
+        return;
+
     m_data = new GraphicsContextPlatformPrivate(platformContext);
-    if (platformContext)
-        m_data->syncContext(platformContext->cr());
-    else
-        setPaintingDisabled(true);
+    m_data->syncContext(platformContext->cr());
 }
 
 void GraphicsContext::platformDestroy()

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (194797 => 194798)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2016-01-08 23:25:15 UTC (rev 194797)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2016-01-08 23:26:48 UTC (rev 194798)
@@ -115,15 +115,15 @@
 
 void GraphicsContext::platformInit(CGContextRef cgContext)
 {
+    if (!cgContext)
+        return;
+
     m_data = new GraphicsContextPlatformPrivate(cgContext);
-    setPaintingDisabled(!cgContext);
-    if (cgContext) {
-        // Make sure the context starts in sync with our state.
-        setPlatformFillColor(fillColor());
-        setPlatformStrokeColor(strokeColor());
-        setPlatformStrokeThickness(strokeThickness());
-        m_state.imageInterpolationQuality = convertInterpolationQuality(CGContextGetInterpolationQuality(platformContext()));
-    }
+    // Make sure the context starts in sync with our state.
+    setPlatformFillColor(fillColor());
+    setPlatformStrokeColor(strokeColor());
+    setPlatformStrokeThickness(strokeThickness());
+    m_state.imageInterpolationQuality = convertInterpolationQuality(CGContextGetInterpolationQuality(platformContext()));
 }
 
 void GraphicsContext::platformDestroy()
@@ -140,6 +140,7 @@
 
 void GraphicsContext::savePlatformState()
 {
+    ASSERT(!paintingDisabled());
     // Note: Do not use this function within this class implementation, since we want to avoid the extra
     // save of the secondary context (in GraphicsContextPlatformPrivateCG.h).
     CGContextSaveGState(platformContext());
@@ -148,6 +149,7 @@
 
 void GraphicsContext::restorePlatformState()
 {
+    ASSERT(!paintingDisabled());
     // Note: Do not use this function within this class implementation, since we want to avoid the extra
     // restore of the secondary context (in GraphicsContextPlatformPrivateCG.h).
     CGContextRestoreGState(platformContext());
@@ -157,6 +159,9 @@
 
 void GraphicsContext::drawNativeImage(PassNativeImagePtr imagePtr, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator op, BlendMode blendMode, ImageOrientation orientation)
 {
+    if (paintingDisabled())
+        return;
+
     RetainPtr<CGImageRef> image(imagePtr);
 
     float currHeight = orientation.usesWidthAsHeight() ? CGImageGetWidth(image.get()) : CGImageGetHeight(image.get());
@@ -271,7 +276,7 @@
 
 void GraphicsContext::drawPattern(Image& image, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator op, const FloatRect& destRect, BlendMode blendMode)
 {
-    if (!patternTransform.isInvertible())
+    if (paintingDisabled() || !patternTransform.isInvertible())
         return;
 
     CGContextRef context = platformContext();
@@ -371,11 +376,10 @@
 // Draws a filled rectangle with a stroked border.
 void GraphicsContext::drawRect(const FloatRect& rect, float borderThickness)
 {
-    // FIXME: this function does not handle patterns and gradients
-    // like drawPath does, it probably should.
     if (paintingDisabled())
         return;
 
+    // FIXME: this function does not handle patterns and gradients like drawPath does, it probably should.
     ASSERT(!rect.isEmpty());
 
     CGContextRef context = platformContext();
@@ -552,6 +556,9 @@
 
 void GraphicsContext::applyStrokePattern()
 {
+    if (paintingDisabled())
+        return;
+
     CGContextRef cgContext = platformContext();
     AffineTransform userToBaseCTM = AffineTransform(getUserToBaseCTM(cgContext));
 
@@ -568,6 +575,9 @@
 
 void GraphicsContext::applyFillPattern()
 {
+    if (paintingDisabled())
+        return;
+
     CGContextRef cgContext = platformContext();
     AffineTransform userToBaseCTM = AffineTransform(getUserToBaseCTM(cgContext));
 
@@ -921,6 +931,7 @@
 {
     if (paintingDisabled())
         return;
+
     CGContextClipToRect(platformContext(), rect);
     m_data->clip(rect);
 }
@@ -965,6 +976,9 @@
 
 IntRect GraphicsContext::clipBounds() const
 {
+    if (paintingDisabled())
+        return IntRect();
+
     return enclosingIntRect(CGContextGetClipBoundingBox(platformContext()));
 }
 
@@ -1172,6 +1186,9 @@
 
 void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
 {
+    if (paintingDisabled())
+        return;
+
     if (dashOffset < 0) {
         float length = 0;
         for (size_t i = 0; i < dashes.size(); ++i)
@@ -1277,6 +1294,9 @@
 
 FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect, RoundingMode roundingMode)
 {
+    if (paintingDisabled())
+        return rect;
+
     // It is not enough just to round to pixels in device space. The rotation part of the
     // affine transform matrix to device space can mess with this conversion if we have a
     // rotating image like the hands of the world clock widget. We just need the scale, so
@@ -1390,6 +1410,8 @@
 
 void GraphicsContext::setPlatformImageInterpolationQuality(InterpolationQuality mode)
 {
+    ASSERT(!paintingDisabled());
+
     CGInterpolationQuality quality = kCGInterpolationDefault;
     switch (mode) {
     case InterpolationDefault:
@@ -1413,6 +1435,9 @@
 
 void GraphicsContext::setIsCALayerContext(bool isLayerContext)
 {
+    if (paintingDisabled())
+        return;
+
     if (isLayerContext)
         m_data->m_contextFlags |= IsLayerCGContext;
     else
@@ -1421,11 +1446,17 @@
 
 bool GraphicsContext::isCALayerContext() const
 {
+    if (paintingDisabled())
+        return false;
+
     return m_data->m_contextFlags & IsLayerCGContext;
 }
 
 void GraphicsContext::setIsAcceleratedContext(bool isAccelerated)
 {
+    if (paintingDisabled())
+        return;
+
     if (isAccelerated)
         m_data->m_contextFlags |= IsAcceleratedCGContext;
     else
@@ -1434,6 +1465,9 @@
 
 bool GraphicsContext::isAcceleratedContext() const
 {
+    if (paintingDisabled())
+        return false;
+
     return m_data->m_contextFlags & IsAcceleratedCGContext;
 }
 
@@ -1613,6 +1647,9 @@
 
 void GraphicsContext::platformApplyDeviceScaleFactor(float deviceScaleFactor)
 {
+    if (paintingDisabled())
+        return;
+
     // CoreGraphics expects the base CTM of a HiDPI context to have the scale factor applied to it.
     // Failing to change the base level CTM will cause certain CG features, such as focus rings,
     // to draw with a scale factor of 1 rather than the actual scale factor.

Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp (194797 => 194798)


--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp	2016-01-08 23:25:15 UTC (rev 194797)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextCGWin.cpp	2016-01-08 23:26:48 UTC (rev 194798)
@@ -68,18 +68,18 @@
 }
 
 GraphicsContext::GraphicsContext(HDC hdc, bool hasAlpha)
-    : m_updatingControlTints(false),
-      m_transparencyCount(0)
 {
     platformInit(hdc, hasAlpha);
 }
 
 void GraphicsContext::platformInit(HDC hdc, bool hasAlpha)
 {
+    if (!hdc)
+        return;
+
     m_data = new GraphicsContextPlatformPrivate(CGContextWithHDC(hdc, hasAlpha));
     CGContextRelease(m_data->m_cgContext.get());
     m_data->m_hdc = hdc;
-    setPaintingDisabled(!m_data->m_cgContext);
     if (m_data->m_cgContext) {
         // Make sure the context starts in sync with our state.
         setPlatformFillColor(fillColor());

Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp (194797 => 194798)


--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp	2016-01-08 23:25:15 UTC (rev 194797)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp	2016-01-08 23:26:48 UTC (rev 194798)
@@ -67,20 +67,17 @@
 }
 
 GraphicsContext::GraphicsContext(HDC dc, bool hasAlpha)
-    : m_updatingControlTints(false),
-      m_transparencyCount(0)
 {
     platformInit(dc, hasAlpha);
 }
 
 void GraphicsContext::platformInit(HDC dc, bool hasAlpha)
 {
-    cairo_t* cr = 0;
-    if (dc)
-        cr = createCairoContextWithHDC(dc, hasAlpha);
-    else
-        setPaintingDisabled(true);
+    if (!dc)
+        return;
 
+    cairo_t* cr = createCairoContextWithHDC(dc, hasAlpha);
+
     m_data = new GraphicsContextPlatformPrivateToplevel(new PlatformContextCairo(cr));
     m_data->m_hdc = dc;
     if (platformContext()->cr()) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to