Title: [252962] trunk/Source
Revision
252962
Author
timothy_hor...@apple.com
Date
2019-11-30 17:06:49 -0800 (Sat, 30 Nov 2019)

Log Message

Reimplement some PlatformCALayer methods using GraphicsContext instead of CGContextRef
https://bugs.webkit.org/show_bug.cgi?id=204698

Reviewed by Sam Weinig.

Source/WebCore:

In order to make PlatformCALayer-level DisplayList recording possible,
reimplement a few methods in terms of WebCore::GraphicsContext instead
of CGContextRef directly. Namely, collectRectsToPaint, drawLayerContents,
and drawRepaintIndicator.

In the drawLayerContents case, there are operations (like setting the
AppKit global graphics context) that cannot be done without a platform
context. In those cases, we skip that operation if we don't have a
platform context.

Anything depending on this downstream will break and need to be
implemented a different way in the DisplayList case.

* platform/graphics/GraphicsContext.h:
* platform/graphics/ca/PlatformCALayer.cpp:
(WebCore::PlatformCALayer::drawRepaintIndicator):
* platform/graphics/ca/PlatformCALayer.h:
* platform/graphics/ca/TileGrid.cpp:
(WebCore::TileGrid::platformCALayerPaintContents):
* platform/graphics/ca/cocoa/PlatformCALayerCocoa.h:
* platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
(WebCore::PlatformCALayer::collectRectsToPaint):
(WebCore::PlatformCALayer::drawLayerContents):
(WebCore::PlatformCALayerCocoa::enumerateRectsBeingDrawn):
* platform/graphics/ca/win/PlatformCALayerWin.cpp:
(PlatformCALayer::collectRectsToPaint):
* platform/graphics/mac/WebLayer.mm:
(-[WebLayer drawInContext:]):

Source/WebKit:

* Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
* Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
(WebKit::RemoteLayerBackingStore::drawInContext):
(WebKit::RemoteLayerBackingStore::enumerateRectsBeingDrawn):
* WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp:
(WebKit::PlatformCALayerRemote::enumerateRectsBeingDrawn):
* WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (252961 => 252962)


--- trunk/Source/WebCore/ChangeLog	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/ChangeLog	2019-12-01 01:06:49 UTC (rev 252962)
@@ -1,3 +1,39 @@
+2019-11-30  Tim Horton  <timothy_hor...@apple.com>
+
+        Reimplement some PlatformCALayer methods using GraphicsContext instead of CGContextRef
+        https://bugs.webkit.org/show_bug.cgi?id=204698
+
+        Reviewed by Sam Weinig.
+
+        In order to make PlatformCALayer-level DisplayList recording possible,
+        reimplement a few methods in terms of WebCore::GraphicsContext instead
+        of CGContextRef directly. Namely, collectRectsToPaint, drawLayerContents,
+        and drawRepaintIndicator.
+
+        In the drawLayerContents case, there are operations (like setting the
+        AppKit global graphics context) that cannot be done without a platform
+        context. In those cases, we skip that operation if we don't have a
+        platform context.
+
+        Anything depending on this downstream will break and need to be
+        implemented a different way in the DisplayList case.
+
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/ca/PlatformCALayer.cpp:
+        (WebCore::PlatformCALayer::drawRepaintIndicator):
+        * platform/graphics/ca/PlatformCALayer.h:
+        * platform/graphics/ca/TileGrid.cpp:
+        (WebCore::TileGrid::platformCALayerPaintContents):
+        * platform/graphics/ca/cocoa/PlatformCALayerCocoa.h:
+        * platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm:
+        (WebCore::PlatformCALayer::collectRectsToPaint):
+        (WebCore::PlatformCALayer::drawLayerContents):
+        (WebCore::PlatformCALayerCocoa::enumerateRectsBeingDrawn):
+        * platform/graphics/ca/win/PlatformCALayerWin.cpp:
+        (PlatformCALayer::collectRectsToPaint):
+        * platform/graphics/mac/WebLayer.mm:
+        (-[WebLayer drawInContext:]):
+
 2019-11-30  youenn fablet  <you...@apple.com>
 
         Simplify CoreAudioCaptureSource suspension logic

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2019-12-01 01:06:49 UTC (rev 252962)
@@ -478,7 +478,7 @@
     void setCTM(const AffineTransform&);
 
     enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale };
-    AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
+    WEBCORE_EXPORT AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const;
 
     // This function applies the device scale factor to the context, making the context capable of
     // acting as a base-level context for a HiDPI environment.

Modified: trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp	2019-12-01 01:06:49 UTC (rev 252962)
@@ -79,27 +79,37 @@
         || m_layerType == LayerType::LayerTypeTiledBackingTileLayer;
 }
 
-void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer* platformCALayer, int repaintCount, CGColorRef customBackgroundColor)
+void PlatformCALayer::drawRepaintIndicator(GraphicsContext& graphicsContext, PlatformCALayer* platformCALayer, int repaintCount, Color customBackgroundColor)
 {
-    char text[16]; // that's a lot of repaints
-    snprintf(text, sizeof(text), "%d", repaintCount);
-    
-    FloatRect indicatorBox = platformCALayer->bounds();\
-    indicatorBox.setLocation( { 1, 1 } );
-    indicatorBox.setSize(FloatSize(12 + 10 * strlen(text), 27));
+    const float verticalMargin = 2.5;
+    const float horizontalMargin = 5;
+    const unsigned fontSize = 22;
+    const Color backgroundColor(0.5f, 0.25f, 1.0f, 1.0f);
+    const Color acceleratedContextLabelColor(1.0f, 0.f, 0.f, 1.0f);
+    const Color unacceleratedContextLabelColor(1.0f, 1.0f, 1.0f, 1.0f);
+    const Color linearGlyphMaskOutlineColor(0.f, 0.f, 0.f, 0.75f);
+    const Color displayListBorderColor(0.f, 0.f, 0.f, 0.65f);
 
-    CGContextStateSaver stateSaver(context);
-    
-    CGContextSetAlpha(context, 0.5f);
-    CGContextBeginTransparencyLayerWithRect(context, indicatorBox, 0);
-    
-    if (customBackgroundColor)
-        CGContextSetFillColorWithColor(context, customBackgroundColor);
-    else
-        CGContextSetRGBFillColor(context, 0, 0.5f, 0.25f, 1);
-    
+    TextRun textRun(String::number(repaintCount));
+
+    FontCascadeDescription fontDescription;
+    fontDescription.setOneFamily("Helvetica");
+    fontDescription.setSpecifiedSize(fontSize);
+    fontDescription.setComputedSize(fontSize);
+
+    FontCascade cascade(WTFMove(fontDescription));
+    cascade.update(nullptr);
+
+    float textWidth = cascade.width(textRun);
+
+    GraphicsContextStateSaver stateSaver(graphicsContext);
+
+    graphicsContext.beginTransparencyLayer(0.5f);
+
+    graphicsContext.setFillColor(customBackgroundColor.isValid() ? customBackgroundColor : backgroundColor);
+    FloatRect indicatorBox(1, 1, horizontalMargin * 2 + textWidth, verticalMargin * 2 + fontSize);
     if (platformCALayer->isOpaque())
-        CGContextFillRect(context, indicatorBox);
+        graphicsContext.fillRect(indicatorBox);
     else {
         Path boundsPath;
         boundsPath.moveTo(indicatorBox.maxXMinYCorner());
@@ -111,32 +121,24 @@
         boundsPath.addLineTo(FloatPoint(indicatorBox.x() + cornerChunk, indicatorBox.y()));
         boundsPath.closeSubpath();
 
-        CGContextAddPath(context, boundsPath.platformPath());
-        CGContextFillPath(context);
+        graphicsContext.fillPath(boundsPath);
     }
 
     if (platformCALayer->owner()->isUsingDisplayListDrawing(platformCALayer)) {
-        CGContextSetRGBStrokeColor(context, 0, 0, 0, 0.65);
-        CGContextSetLineWidth(context, 2);
-        CGContextStrokeRect(context, indicatorBox);
+        graphicsContext.setStrokeColor(displayListBorderColor);
+        graphicsContext.strokeRect(indicatorBox, 2);
     }
 
-    CGFloat strokeWidthAsPercentageOfFontSize = 0;
-    Color strokeColor;
-
     if (!platformCALayer->isOpaque() && platformCALayer->supportsSubpixelAntialiasedText() && platformCALayer->acceleratesDrawing()) {
-        strokeColor = Color(0, 0, 0, 200);
-        strokeWidthAsPercentageOfFontSize = -4.5; // Negative means "stroke and fill"; see docs for kCTStrokeWidthAttributeName.
+        graphicsContext.setStrokeColor(linearGlyphMaskOutlineColor);
+        graphicsContext.setStrokeThickness(4.5);
+        graphicsContext.setTextDrawingMode(TextModeFill | TextModeStroke);
     }
 
-    if (platformCALayer->acceleratesDrawing())
-        CGContextSetRGBFillColor(context, 1, 0, 0, 1);
-    else
-        CGContextSetRGBFillColor(context, 1, 1, 1, 1);
-    
-    platformCALayer->drawTextAtPoint(context, indicatorBox.x() + 5, indicatorBox.y() + 22, CGSizeMake(1, -1), 22, text, strlen(text), strokeWidthAsPercentageOfFontSize, strokeColor);
-    
-    CGContextEndTransparencyLayer(context);
+    graphicsContext.setFillColor(platformCALayer->acceleratesDrawing() ? acceleratedContextLabelColor : unacceleratedContextLabelColor);
+
+    graphicsContext.drawText(cascade, textRun, FloatPoint(indicatorBox.x() + horizontalMargin, indicatorBox.y() + fontSize));
+    graphicsContext.endTransparencyLayer();
 }
 
 void PlatformCALayer::flipContext(CGContextRef context, CGFloat height)

Modified: trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.h (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.h	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/ca/PlatformCALayer.h	2019-12-01 01:06:49 UTC (rev 252962)
@@ -268,7 +268,7 @@
     Ref<PlatformCALayer> createCompatibleLayerOrTakeFromPool(LayerType, PlatformCALayerClient*, IntSize);
 
 #if PLATFORM(COCOA)
-    virtual void enumerateRectsBeingDrawn(CGContextRef, void (^block)(CGRect)) = 0;
+    virtual void enumerateRectsBeingDrawn(GraphicsContext&, void (^block)(FloatRect)) = 0;
 #endif
 
     static const unsigned webLayerMaxRectsToPaint = 5;
@@ -281,9 +281,9 @@
     typedef Vector<FloatRect, webLayerMaxRectsToPaint> RepaintRectList;
         
     // Functions allows us to share implementation across WebTiledLayer and WebLayer
-    static RepaintRectList collectRectsToPaint(CGContextRef, PlatformCALayer*);
-    static void drawLayerContents(CGContextRef, PlatformCALayer*, RepaintRectList& dirtyRects, GraphicsLayerPaintBehavior);
-    static void drawRepaintIndicator(CGContextRef, PlatformCALayer*, int repaintCount, CGColorRef customBackgroundColor);
+    static RepaintRectList collectRectsToPaint(GraphicsContext&, PlatformCALayer*);
+    static void drawLayerContents(GraphicsContext&, PlatformCALayer*, RepaintRectList&, GraphicsLayerPaintBehavior);
+    static void drawRepaintIndicator(GraphicsContext&, PlatformCALayer*, int repaintCount, Color customBackgroundColor = { });
     static CGRect frameForLayer(const PlatformLayer*);
 
     void moveToLayerPool();

Modified: trunk/Source/WebCore/platform/graphics/ca/TileGrid.cpp (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/ca/TileGrid.cpp	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/ca/TileGrid.cpp	2019-12-01 01:06:49 UTC (rev 252962)
@@ -729,13 +729,13 @@
         context.translate(-layerOrigin.x(), -layerOrigin.y());
         context.scale(m_scale);
 
-        PlatformCALayer::RepaintRectList dirtyRects = PlatformCALayer::collectRectsToPaint(context.platformContext(), platformCALayer);
-        PlatformCALayer::drawLayerContents(context.platformContext(), &m_controller.rootLayer(), dirtyRects, layerPaintBehavior);
+        PlatformCALayer::RepaintRectList dirtyRects = PlatformCALayer::collectRectsToPaint(context, platformCALayer);
+        PlatformCALayer::drawLayerContents(context, &m_controller.rootLayer(), dirtyRects, layerPaintBehavior);
     }
 
     int repaintCount = platformCALayerIncrementRepaintCount(platformCALayer);
     if (m_controller.rootLayer().owner()->platformCALayerShowRepaintCounter(0))
-        PlatformCALayer::drawRepaintIndicator(context.platformContext(), platformCALayer, repaintCount, cachedCGColor(m_controller.tileDebugBorderColor()));
+        PlatformCALayer::drawRepaintIndicator(context, platformCALayer, repaintCount, m_controller.tileDebugBorderColor());
 
     if (m_controller.scrollingPerformanceLoggingEnabled()) {
         FloatRect visiblePart(platformCALayer->position().x(), platformCALayer->position().y(), platformCALayer->bounds().size().width(), platformCALayer->bounds().size().height());

Modified: trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h	2019-12-01 01:06:49 UTC (rev 252962)
@@ -178,7 +178,7 @@
 
     Ref<PlatformCALayer> createCompatibleLayer(PlatformCALayer::LayerType, PlatformCALayerClient*) const override;
 
-    void enumerateRectsBeingDrawn(CGContextRef, void (^block)(CGRect)) override;
+    void enumerateRectsBeingDrawn(GraphicsContext&, void (^block)(FloatRect)) override;
 
     unsigned backingStoreBytesPerPixel() const override;
 

Modified: trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm	2019-12-01 01:06:49 UTC (rev 252962)
@@ -1119,21 +1119,21 @@
 }
 #endif // PLATFORM(IOS_FAMILY)
 
-PlatformCALayer::RepaintRectList PlatformCALayer::collectRectsToPaint(CGContextRef context, PlatformCALayer* platformCALayer)
+PlatformCALayer::RepaintRectList PlatformCALayer::collectRectsToPaint(GraphicsContext& context, PlatformCALayer* platformCALayer)
 {
     __block double totalRectArea = 0;
     __block unsigned rectCount = 0;
     __block RepaintRectList dirtyRects;
     
-    platformCALayer->enumerateRectsBeingDrawn(context, ^(CGRect rect) {
+    platformCALayer->enumerateRectsBeingDrawn(context, ^(FloatRect rect) {
         if (++rectCount > webLayerMaxRectsToPaint)
             return;
         
-        totalRectArea += rect.size.width * rect.size.height;
+        totalRectArea += rect.area();
         dirtyRects.append(rect);
     });
     
-    FloatRect clipBounds = CGContextGetClipBoundingBox(context);
+    FloatRect clipBounds = context.clipBounds();
     double clipArea = clipBounds.width() * clipBounds.height();
     
     if (rectCount >= webLayerMaxRectsToPaint || totalRectArea >= clipArea * webLayerWastedSpaceThreshold) {
@@ -1144,7 +1144,7 @@
     return dirtyRects;
 }
 
-void PlatformCALayer::drawLayerContents(CGContextRef context, WebCore::PlatformCALayer* platformCALayer, RepaintRectList& dirtyRects, GraphicsLayerPaintBehavior layerPaintBehavior)
+void PlatformCALayer::drawLayerContents(GraphicsContext& graphicsContext, WebCore::PlatformCALayer* platformCALayer, RepaintRectList& dirtyRects, GraphicsLayerPaintBehavior layerPaintBehavior)
 {
     WebCore::PlatformCALayerClient* layerContents = platformCALayer->owner();
     if (!layerContents)
@@ -1153,62 +1153,66 @@
     if (!layerContents->platformCALayerRepaintCount(platformCALayer))
         layerPaintBehavior |= GraphicsLayerPaintFirstTilePaint;
 
-#if PLATFORM(IOS_FAMILY)
-    WKSetCurrentGraphicsContext(context);
-#endif
-    
-    CGContextSaveGState(context);
-    
+    GraphicsContextStateSaver saver(graphicsContext);
+
     // We never use CompositingCoordinatesOrientation::BottomUp on Mac.
     ASSERT(layerContents->platformCALayerContentsOrientation() == GraphicsLayer::CompositingCoordinatesOrientation::TopDown);
-    
+
 #if PLATFORM(IOS_FAMILY)
-    FontAntialiasingStateSaver fontAntialiasingState(context, [platformCALayer->platformLayer() isOpaque]);
-    fontAntialiasingState.setup([WAKWindow hasLandscapeOrientation]);
+    WTF::Optional<FontAntialiasingStateSaver> fontAntialiasingState;
+#endif
+    if (graphicsContext.hasPlatformContext()) {
+        CGContextRef context = graphicsContext.platformContext();
+#if PLATFORM(IOS_FAMILY)
+        WKSetCurrentGraphicsContext(context);
+
+        fontAntialiasingState = FontAntialiasingStateSaver { context, [platformCALayer->platformLayer() isOpaque] };
+        fontAntialiasingState->setup([WAKWindow hasLandscapeOrientation]);
 #else
-    [NSGraphicsContext saveGraphicsState];
-    
-    // Set up an NSGraphicsContext for the context, so that parts of AppKit that rely on
-    // the current NSGraphicsContext (e.g. NSCell drawing) get the right one.
-    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-    NSGraphicsContext* layerContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES];
-    ALLOW_DEPRECATED_DECLARATIONS_END
-    [NSGraphicsContext setCurrentContext:layerContext];
+        [NSGraphicsContext saveGraphicsState];
+
+        // Set up an NSGraphicsContext for the context, so that parts of AppKit that rely on
+        // the current NSGraphicsContext (e.g. NSCell drawing) get the right one.
+        ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+        NSGraphicsContext* layerContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES];
+        ALLOW_DEPRECATED_DECLARATIONS_END
+        [NSGraphicsContext setCurrentContext:layerContext];
 #endif
+    }
     
     {
-        GraphicsContext graphicsContext(context);
         graphicsContext.setIsCALayerContext(true);
         graphicsContext.setIsAcceleratedContext(platformCALayer->acceleratesDrawing());
-        
+
         if (!layerContents->platformCALayerContentsOpaque() && !platformCALayer->supportsSubpixelAntialiasedText() && FontCascade::isSubpixelAntialiasingAvailable()) {
             // Turn off font smoothing to improve the appearance of text rendered onto a transparent background.
             graphicsContext.setShouldSmoothFonts(false);
         }
-        
+
 #if PLATFORM(MAC)
         // It's important to get the clip from the context, because it may be significantly
         // smaller than the layer bounds (e.g. tiled layers)
-        ThemeMac::setFocusRingClipRect(CGContextGetClipBoundingBox(context));
+        ThemeMac::setFocusRingClipRect(graphicsContext.clipBounds());
 #endif
-        
+
         for (const auto& rect : dirtyRects) {
             GraphicsContextStateSaver stateSaver(graphicsContext);
             graphicsContext.clip(rect);
-            
+
             layerContents->platformCALayerPaintContents(platformCALayer, graphicsContext, rect, layerPaintBehavior);
         }
-        
+
 #if PLATFORM(IOS_FAMILY)
-        fontAntialiasingState.restore();
+        if (fontAntialiasingState)
+            fontAntialiasingState->restore();
 #else
         ThemeMac::setFocusRingClipRect(FloatRect());
-        
+
         [NSGraphicsContext restoreGraphicsState];
 #endif
     }
 
-    CGContextRestoreGState(context);
+    saver.restore();
 
     // Re-fetch the layer owner, since <rdar://problem/9125151> indicates that it might have been destroyed during painting.
     layerContents = platformCALayer->owner();
@@ -1219,7 +1223,7 @@
     int repaintCount = layerContents->platformCALayerIncrementRepaintCount(platformCALayer);
 
     if (!platformCALayer->usesTiledBackingLayer() && layerContents && layerContents->platformCALayerShowRepaintCounter(platformCALayer))
-        drawRepaintIndicator(context, platformCALayer, repaintCount, nullptr);
+        drawRepaintIndicator(graphicsContext, platformCALayer, repaintCount);
 }
 
 CGRect PlatformCALayer::frameForLayer(const PlatformLayer* tileLayer)
@@ -1232,15 +1236,15 @@
     return PlatformCALayerCocoa::create(layerType, client);
 }
 
-void PlatformCALayerCocoa::enumerateRectsBeingDrawn(CGContextRef context, void (^block)(CGRect))
+void PlatformCALayerCocoa::enumerateRectsBeingDrawn(GraphicsContext& context, void (^block)(FloatRect))
 {
     CGSRegionObj region = (CGSRegionObj)[m_layer regionBeingDrawn];
     if (!region) {
-        block(CGContextGetClipBoundingBox(context));
+        block(context.clipBounds());
         return;
     }
 
-    CGAffineTransform inverseTransform = CGAffineTransformInvert(CGContextGetCTM(context));
+    CGAffineTransform inverseTransform = CGAffineTransformInvert(context.getCTM());
     CGSRegionEnumeratorObj enumerator = CGSRegionEnumerator(region);
     const CGRect* nextRect;
     while ((nextRect = CGSNextRect(enumerator))) {

Modified: trunk/Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.cpp (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.cpp	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.cpp	2019-12-01 01:06:49 UTC (rev 252962)
@@ -101,7 +101,7 @@
     return layerIntern ? layerIntern->owner() : nullptr;
 }
 
-PlatformCALayer::RepaintRectList PlatformCALayer::collectRectsToPaint(CGContextRef, PlatformCALayer*)
+PlatformCALayer::RepaintRectList PlatformCALayer::collectRectsToPaint(GraphicsContext&, PlatformCALayer*)
 {
     // FIXME: We should actually collect rects to use instead of defaulting to Windows'
     // normal drawing path.
@@ -109,9 +109,9 @@
     return dirtyRects;
 }
 
-void PlatformCALayer::drawLayerContents(CGContextRef context, WebCore::PlatformCALayer* platformCALayer, RepaintRectList&, GraphicsLayerPaintBehavior)
+void PlatformCALayer::drawLayerContents(GraphicsContext& context, WebCore::PlatformCALayer* platformCALayer, RepaintRectList&, GraphicsLayerPaintBehavior)
 {
-    intern(platformCALayer)->displayCallback(platformCALayer->platformLayer(), context);
+    intern(platformCALayer)->displayCallback(platformCALayer->platformLayer(), context.platformContext());
 }
 
 CGRect PlatformCALayer::frameForLayer(const PlatformLayer* tileLayer)

Modified: trunk/Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp	2019-12-01 01:06:49 UTC (rev 252962)
@@ -129,7 +129,8 @@
     else
         backgroundColor = cachedCGColor(Color(255, 0, 0));
 
-    PlatformCALayer::drawRepaintIndicator(context, owner(), drawCount, backgroundColor);
+    GraphicsContext graphicsContext(context);
+    PlatformCALayer::drawRepaintIndicator(graphicsContext, owner(), drawCount, backgroundColor);
 }
 
 void PlatformCALayerWinInternal::internalSetNeedsDisplay(const FloatRect* dirtyRect)

Modified: trunk/Source/WebCore/platform/graphics/mac/WebLayer.mm (252961 => 252962)


--- trunk/Source/WebCore/platform/graphics/mac/WebLayer.mm	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebCore/platform/graphics/mac/WebLayer.mm	2019-12-01 01:06:49 UTC (rev 252962)
@@ -51,8 +51,9 @@
 {
     WebCore::PlatformCALayer* layer = WebCore::PlatformCALayer::platformCALayer((__bridge void*)self);
     if (layer) {
-        WebCore::PlatformCALayer::RepaintRectList rectsToPaint = WebCore::PlatformCALayer::collectRectsToPaint(context, layer);
-        WebCore::PlatformCALayer::drawLayerContents(context, layer, rectsToPaint, self.isRenderingInContext ? WebCore::GraphicsLayerPaintSnapshotting : WebCore::GraphicsLayerPaintNormal);
+        WebCore::GraphicsContext graphicsContext(context);
+        WebCore::PlatformCALayer::RepaintRectList rectsToPaint = WebCore::PlatformCALayer::collectRectsToPaint(graphicsContext, layer);
+        WebCore::PlatformCALayer::drawLayerContents(graphicsContext, layer, rectsToPaint, self.isRenderingInContext ? WebCore::GraphicsLayerPaintSnapshotting : WebCore::GraphicsLayerPaintNormal);
     }
 }
 

Modified: trunk/Source/WebKit/ChangeLog (252961 => 252962)


--- trunk/Source/WebKit/ChangeLog	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebKit/ChangeLog	2019-12-01 01:06:49 UTC (rev 252962)
@@ -1,3 +1,18 @@
+2019-11-30  Tim Horton  <timothy_hor...@apple.com>
+
+        Reimplement some PlatformCALayer methods using GraphicsContext instead of CGContextRef
+        https://bugs.webkit.org/show_bug.cgi?id=204698
+
+        Reviewed by Sam Weinig.
+
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.h:
+        * Shared/RemoteLayerTree/RemoteLayerBackingStore.mm:
+        (WebKit::RemoteLayerBackingStore::drawInContext):
+        (WebKit::RemoteLayerBackingStore::enumerateRectsBeingDrawn):
+        * WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp:
+        (WebKit::PlatformCALayerRemote::enumerateRectsBeingDrawn):
+        * WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.h:
+
 2019-11-27  Antoine Quint  <grao...@apple.com>
 
         [Web Animations] Enable WebAnimationsCSSIntegrationEnabled by default

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h (252961 => 252962)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h	2019-12-01 01:06:49 UTC (rev 252962)
@@ -71,7 +71,7 @@
     void encode(IPC::Encoder&) const;
     static bool decode(IPC::Decoder&, RemoteLayerBackingStore&);
 
-    void enumerateRectsBeingDrawn(CGContextRef, void (^)(CGRect));
+    void enumerateRectsBeingDrawn(WebCore::GraphicsContext&, void (^)(WebCore::FloatRect));
 
     bool hasFrontBuffer() const
     {

Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm (252961 => 252962)


--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm	2019-12-01 01:06:49 UTC (rev 252962)
@@ -353,13 +353,13 @@
         break;
     case WebCore::PlatformCALayer::LayerTypeWebLayer:
     case WebCore::PlatformCALayer::LayerTypeBackdropLayer:
-        WebCore::PlatformCALayer::drawLayerContents(cgContext, m_layer, m_paintingRects, flags);
+        WebCore::PlatformCALayer::drawLayerContents(context, m_layer, m_paintingRects, flags);
         break;
     case WebCore::PlatformCALayer::LayerTypeDarkSystemBackdropLayer:
     case WebCore::PlatformCALayer::LayerTypeLightSystemBackdropLayer:
         // FIXME: These have a more complicated layer hierarchy. We need to paint into
         // a child layer in order to see the rendered results.
-        WebCore::PlatformCALayer::drawLayerContents(cgContext, m_layer, m_paintingRects, flags);
+        WebCore::PlatformCALayer::drawLayerContents(context, m_layer, m_paintingRects, flags);
         break;
     case WebCore::PlatformCALayer::LayerTypeLayer:
     case WebCore::PlatformCALayer::LayerTypeTransformLayer:
@@ -382,9 +382,9 @@
     m_frontContextPendingFlush = context.platformContext();
 }
 
-void RemoteLayerBackingStore::enumerateRectsBeingDrawn(CGContextRef context, void (^block)(CGRect))
+void RemoteLayerBackingStore::enumerateRectsBeingDrawn(WebCore::GraphicsContext& context, void (^block)(WebCore::FloatRect))
 {
-    CGAffineTransform inverseTransform = CGAffineTransformInvert(CGContextGetCTM(context));
+    CGAffineTransform inverseTransform = CGAffineTransformInvert(context.getCTM());
 
     // We don't want to un-apply the flipping or contentsScale,
     // because they're not applied to repaint rects.

Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp (252961 => 252962)


--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp	2019-12-01 01:06:49 UTC (rev 252962)
@@ -891,7 +891,7 @@
     return PlatformCALayerRemote::create(layerType, client, *m_context);
 }
 
-void PlatformCALayerRemote::enumerateRectsBeingDrawn(CGContextRef context, void (^block)(CGRect))
+void PlatformCALayerRemote::enumerateRectsBeingDrawn(WebCore::GraphicsContext& context, void (^block)(WebCore::FloatRect))
 {
     m_properties.backingStore->enumerateRectsBeingDrawn(context, block);
 }

Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.h (252961 => 252962)


--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.h	2019-11-30 19:08:09 UTC (rev 252961)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.h	2019-12-01 01:06:49 UTC (rev 252962)
@@ -184,7 +184,7 @@
 
     Ref<PlatformCALayer> createCompatibleLayer(WebCore::PlatformCALayer::LayerType, WebCore::PlatformCALayerClient*) const override;
 
-    void enumerateRectsBeingDrawn(CGContextRef, void (^block)(CGRect)) override;
+    void enumerateRectsBeingDrawn(WebCore::GraphicsContext&, void (^block)(WebCore::FloatRect)) override;
 
     virtual uint32_t hostingContextID();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to