Title: [270221] trunk/Source/WebCore
Revision
270221
Author
[email protected]
Date
2020-11-28 16:19:33 -0800 (Sat, 28 Nov 2020)

Log Message

[LFC Display] Add basic opacity support.
https://bugs.webkit.org/show_bug.cgi?id=219312

Reviewed by Zalan Bujtas.

Add a TransparencyLayerScope helper that can lazily begin, and end a transparency layer.

Add display tree support for opacity via applyEffects(), which begins a transparency
layer at the start of stacking context painting when alpha is < 1.

* display/css/DisplayBoxDecorationPainter.cpp:
(WebCore::Display::BorderPainter::paintTranslucentBorderSides const):
* display/css/DisplayCSSPainter.cpp:
(WebCore::Display::applyEffects):
(WebCore::Display::CSSPainter::paintAtomicallyPaintedBox):
* display/css/DisplayStyle.cpp:
(WebCore::Display::Style::Style):
* display/css/DisplayStyle.h:
(WebCore::Display::Style::opacity const):
* platform/graphics/GraphicsContext.h:
(WebCore::TransparencyLayerScope::TransparencyLayerScope):
(WebCore::TransparencyLayerScope::beginLayer):
(WebCore::TransparencyLayerScope::~TransparencyLayerScope):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (270220 => 270221)


--- trunk/Source/WebCore/ChangeLog	2020-11-28 19:37:32 UTC (rev 270220)
+++ trunk/Source/WebCore/ChangeLog	2020-11-29 00:19:33 UTC (rev 270221)
@@ -1,3 +1,29 @@
+2020-11-28  Simon Fraser  <[email protected]>
+
+        [LFC Display] Add basic opacity support.
+        https://bugs.webkit.org/show_bug.cgi?id=219312
+
+        Reviewed by Zalan Bujtas.
+
+        Add a TransparencyLayerScope helper that can lazily begin, and end a transparency layer.
+
+        Add display tree support for opacity via applyEffects(), which begins a transparency
+        layer at the start of stacking context painting when alpha is < 1.
+
+        * display/css/DisplayBoxDecorationPainter.cpp:
+        (WebCore::Display::BorderPainter::paintTranslucentBorderSides const):
+        * display/css/DisplayCSSPainter.cpp:
+        (WebCore::Display::applyEffects):
+        (WebCore::Display::CSSPainter::paintAtomicallyPaintedBox):
+        * display/css/DisplayStyle.cpp:
+        (WebCore::Display::Style::Style):
+        * display/css/DisplayStyle.h:
+        (WebCore::Display::Style::opacity const):
+        * platform/graphics/GraphicsContext.h:
+        (WebCore::TransparencyLayerScope::TransparencyLayerScope):
+        (WebCore::TransparencyLayerScope::beginLayer):
+        (WebCore::TransparencyLayerScope::~TransparencyLayerScope):
+
 2020-11-28  Antti Koivisto  <[email protected]>
 
         Move caret rect computation out of render tree

Modified: trunk/Source/WebCore/display/css/DisplayBoxDecorationPainter.cpp (270220 => 270221)


--- trunk/Source/WebCore/display/css/DisplayBoxDecorationPainter.cpp	2020-11-28 19:37:32 UTC (rev 270220)
+++ trunk/Source/WebCore/display/css/DisplayBoxDecorationPainter.cpp	2020-11-29 00:19:33 UTC (rev 270221)
@@ -962,15 +962,13 @@
         }
 
         bool useTransparencyLayer = includesAdjacentEdges(commonColorEdgeSet) && !commonColor.isOpaque();
-        if (useTransparencyLayer) {
-            paintingContext.context.beginTransparencyLayer(commonColor.alphaAsFloat());
-            commonColor = commonColor.opaqueColor();
+        {
+            auto transparencyScope = TransparencyLayerScope { paintingContext.context, commonColor.alphaAsFloat(), useTransparencyLayer };
+            if (useTransparencyLayer)
+                commonColor = commonColor.opaqueColor();
+
+            paintBorderSides(paintingContext, outerBorder, innerBorder, innerBorderBleedAdjustment, commonColorEdgeSet, antialias, &commonColor);
         }
-
-        paintBorderSides(paintingContext, outerBorder, innerBorder, innerBorderBleedAdjustment, commonColorEdgeSet, antialias, &commonColor);
-            
-        if (useTransparencyLayer)
-            paintingContext.context.endTransparencyLayer();
         
         edgesToDraw.remove(commonColorEdgeSet);
     }

Modified: trunk/Source/WebCore/display/css/DisplayCSSPainter.cpp (270220 => 270221)


--- trunk/Source/WebCore/display/css/DisplayCSSPainter.cpp	2020-11-28 19:37:32 UTC (rev 270220)
+++ trunk/Source/WebCore/display/css/DisplayCSSPainter.cpp	2020-11-29 00:19:33 UTC (rev 270221)
@@ -65,6 +65,14 @@
         paintingContext.context.clipRoundedRect(roundedRect);
 }
 
+static void applyEffects(const Box& box, PaintingContext&, GraphicsContextStateSaver&, TransparencyLayerScope& transparencyScope)
+{
+    if (box.style().opacity() < 1) {
+        // FIXME: Compute and set a clip to avoid creating large transparency layers.
+        transparencyScope.beginLayer(box.style().opacity());
+    }
+}
+
 // FIXME: Make this an iterator.
 void CSSPainter::recursivePaintDescendantsForPhase(const ContainerBox& containerBox, PaintingContext& paintingContext, PaintPhase paintPhase)
 {
@@ -124,6 +132,9 @@
     if (is<BoxModelBox>(box))
         applyAncestorClip(downcast<BoxModelBox>(box), paintingContext, stateSaver);
 
+    auto transparencyScope = TransparencyLayerScope { paintingContext.context, 1, false };
+    applyEffects(box, paintingContext, stateSaver, transparencyScope);
+
     BoxPainter::paintBox(box, paintingContext, dirtyRect);
     if (!is<ContainerBox>(box))
         return;

Modified: trunk/Source/WebCore/display/css/DisplayStyle.cpp (270220 => 270221)


--- trunk/Source/WebCore/display/css/DisplayStyle.cpp	2020-11-28 19:37:32 UTC (rev 270220)
+++ trunk/Source/WebCore/display/css/DisplayStyle.cpp	2020-11-29 00:19:33 UTC (rev 270221)
@@ -84,9 +84,12 @@
 }
 
 Style::Style(const RenderStyle& style, const RenderStyle* styleForBackground)
-    : m_fontCascade(style.fontCascade())
+    : m_overflowX(style.overflowX())
+    , m_overflowY(style.overflowY())
+    , m_fontCascade(style.fontCascade())
     , m_whiteSpace(style.whiteSpace())
     , m_tabSize(style.tabSize())
+    , m_opacity(style.opacity())
 {
     // FIXME: Is currentColor resolved here?
     m_color = style.visitedDependentColorWithColorFilter(CSSPropertyColor);
@@ -95,9 +98,6 @@
         setupBackground(*styleForBackground);
 
     m_boxShadow = deepCopy(style.boxShadow(), style);
-    
-    m_overflowX = style.overflowX();
-    m_overflowY = style.overflowY();
 
     if (!style.hasAutoUsedZIndex())
         m_zIndex = style.usedZIndex();

Modified: trunk/Source/WebCore/display/css/DisplayStyle.h (270220 => 270221)


--- trunk/Source/WebCore/display/css/DisplayStyle.h	2020-11-28 19:37:32 UTC (rev 270220)
+++ trunk/Source/WebCore/display/css/DisplayStyle.h	2020-11-29 00:19:33 UTC (rev 270221)
@@ -83,6 +83,8 @@
     const FontCascade& fontCascade() const { return m_fontCascade; }
     const FontMetrics& fontMetrics() const { return m_fontCascade.fontMetrics(); }
     
+    float opacity() const { return m_opacity; }
+
     Overflow overflowX() const;
     Overflow overflowY() const;
     bool hasClippedOverflow() const { return m_overflowX != Overflow::Visible || m_overflowY != Overflow::Visible; }
@@ -112,6 +114,8 @@
     FontCascade m_fontCascade;
     WhiteSpace m_whiteSpace;
     TabSize m_tabSize;
+    
+    float m_opacity;
 
     Optional<int> m_zIndex;
     OptionSet<Flags> m_flags;

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (270220 => 270221)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2020-11-28 19:37:32 UTC (rev 270220)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2020-11-29 00:19:33 UTC (rev 270221)
@@ -709,7 +709,36 @@
     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)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to