Reimplement some PlatformCALayer methods using GraphicsContext instead of CGContextRef
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Dec 2019 01:06:49 +0000 (01:06 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Dec 2019 01:06:49 +0000 (01:06 +0000)
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:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252962 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/ca/PlatformCALayer.cpp
Source/WebCore/platform/graphics/ca/PlatformCALayer.h
Source/WebCore/platform/graphics/ca/TileGrid.cpp
Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.h
Source/WebCore/platform/graphics/ca/cocoa/PlatformCALayerCocoa.mm
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWin.cpp
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp
Source/WebCore/platform/graphics/mac/WebLayer.mm
Source/WebKit/ChangeLog
Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.h
Source/WebKit/Shared/RemoteLayerTree/RemoteLayerBackingStore.mm
Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.cpp
Source/WebKit/WebProcess/WebPage/RemoteLayerTree/PlatformCALayerRemote.h

index dfa9438..9f19875 100644 (file)
@@ -1,3 +1,39 @@
+2019-11-30  Tim Horton  <timothy_horton@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  <youenn@apple.com>
 
         Simplify CoreAudioCaptureSource suspension logic
index 0879145..209036f 100644 (file)
@@ -478,7 +478,7 @@ public:
     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.
index 2199527..d5b0327 100644 (file)
@@ -79,27 +79,37 @@ bool PlatformCALayer::canHaveBackingStore() const
         || 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));
-
-    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);
-    
+    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);
+
+    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 @@ void PlatformCALayer::drawRepaintIndicator(CGContextRef context, PlatformCALayer
         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)
index ebc100c..401172c 100644 (file)
@@ -268,7 +268,7 @@ public:
     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 @@ public:
     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();
index 496a32d..7d8b0ef 100644 (file)
@@ -729,13 +729,13 @@ void TileGrid::platformCALayerPaintContents(PlatformCALayer* platformCALayer, Gr
         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());
index 5d9669b..dd1eb46 100644 (file)
@@ -178,7 +178,7 @@ public:
 
     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;
 
index 4657428..9e6f445 100644 (file)
@@ -1119,21 +1119,21 @@ void PlatformCALayer::setAnchorPointOnMainThread(FloatPoint3D value)
 }
 #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 @@ PlatformCALayer::RepaintRectList PlatformCALayer::collectRectsToPaint(CGContextR
     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 @@ void PlatformCALayer::drawLayerContents(CGContextRef context, WebCore::PlatformC
     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 @@ void PlatformCALayer::drawLayerContents(CGContextRef context, WebCore::PlatformC
     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 @@ Ref<PlatformCALayer> PlatformCALayerCocoa::createCompatibleLayer(PlatformCALayer
     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))) {
index d6a7c16..f2fdf52 100644 (file)
@@ -101,7 +101,7 @@ PlatformCALayer* PlatformCALayer::platformCALayer(void* platformLayer)
     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 @@ PlatformCALayer::RepaintRectList PlatformCALayer::collectRectsToPaint(CGContextR
     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)
index ae2b06a..5e04c2b 100644 (file)
@@ -129,7 +129,8 @@ void PlatformCALayerWinInternal::drawRepaintCounters(CACFLayerRef caLayer, CGCon
     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)
index 808804b..65e8782 100644 (file)
@@ -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);
     }
 }
 
index 09ef444..1a473ac 100644 (file)
@@ -1,3 +1,18 @@
+2019-11-30  Tim Horton  <timothy_horton@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  <graouts@apple.com>
 
         [Web Animations] Enable WebAnimationsCSSIntegrationEnabled by default
index a99e9c5..18b5a95 100644 (file)
@@ -71,7 +71,7 @@ public:
     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
     {
index b5cadd1..62f32ad 100644 (file)
@@ -353,13 +353,13 @@ void RemoteLayerBackingStore::drawInContext(WebCore::GraphicsContext& context, C
         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 @@ void RemoteLayerBackingStore::drawInContext(WebCore::GraphicsContext& context, C
     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.
index 46e8aa0..2c4c653 100644 (file)
@@ -891,7 +891,7 @@ Ref<PlatformCALayer> PlatformCALayerRemote::createCompatibleLayer(PlatformCALaye
     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);
 }
index c3198a0..0831955 100644 (file)
@@ -184,7 +184,7 @@ public:
 
     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();