Use an OptionSet for compositing reasons bitmask
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Apr 2017 21:15:16 +0000 (21:15 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Apr 2017 21:15:16 +0000 (21:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171153

Reviewed by Simon Fraser.

We should make use of OptionSet to represent the bitmask of the reasons a layer
was composited instead of using an integer and bitwise operations.

* inspector/InspectorLayerTreeAgent.cpp:
(WebCore::InspectorLayerTreeAgent::reasonsForCompositingLayer):
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::reasonsForCompositing):
(WebCore::RenderLayerCompositor::logReasonsForCompositing): Also fix code style issues;
an else-if statement should be written as an if-statement when the prior if-statement
concludes with a return statement.
* rendering/RenderLayerCompositor.h:

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

Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorLayerTreeAgent.cpp
Source/WebCore/rendering/RenderLayerCompositor.cpp
Source/WebCore/rendering/RenderLayerCompositor.h

index 32acf2e..80e36f0 100644 (file)
@@ -1,3 +1,22 @@
+2017-04-25  Daniel Bates  <dabates@apple.com>
+
+        Use an OptionSet for compositing reasons bitmask
+        https://bugs.webkit.org/show_bug.cgi?id=171153
+
+        Reviewed by Simon Fraser.
+
+        We should make use of OptionSet to represent the bitmask of the reasons a layer
+        was composited instead of using an integer and bitwise operations.
+
+        * inspector/InspectorLayerTreeAgent.cpp:
+        (WebCore::InspectorLayerTreeAgent::reasonsForCompositingLayer):
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::reasonsForCompositing):
+        (WebCore::RenderLayerCompositor::logReasonsForCompositing): Also fix code style issues;
+        an else-if statement should be written as an if-statement when the prior if-statement
+        concludes with a return statement.
+        * rendering/RenderLayerCompositor.h:
+
 2017-04-25  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Supplementary Multilingual Plane Complex Scripts Rendered Incorrectly
index d96e04e..33b8718 100644 (file)
@@ -233,84 +233,84 @@ void InspectorLayerTreeAgent::reasonsForCompositingLayer(ErrorString& errorStrin
         return;
     }
 
-    CompositingReasons reasonsBitmask = renderLayer->compositor().reasonsForCompositing(*renderLayer);
+    OptionSet<CompositingReason> reasons = renderLayer->compositor().reasonsForCompositing(*renderLayer);
     auto compositingReasons = Inspector::Protocol::LayerTree::CompositingReasons::create().release();
 
-    if (reasonsBitmask & CompositingReason3DTransform)
+    if (reasons.contains(CompositingReason::Transform3D))
         compositingReasons->setTransform3D(true);
 
-    if (reasonsBitmask & CompositingReasonVideo)
+    if (reasons.contains(CompositingReason::Video))
         compositingReasons->setVideo(true);
-    else if (reasonsBitmask & CompositingReasonCanvas)
+    else if (reasons.contains(CompositingReason::Canvas))
         compositingReasons->setCanvas(true);
-    else if (reasonsBitmask & CompositingReasonPlugin)
+    else if (reasons.contains(CompositingReason::Plugin))
         compositingReasons->setPlugin(true);
-    else if (reasonsBitmask & CompositingReasonIFrame)
+    else if (reasons.contains(CompositingReason::IFrame))
         compositingReasons->setIFrame(true);
-    
-    if (reasonsBitmask & CompositingReasonBackfaceVisibilityHidden)
+
+    if (reasons.contains(CompositingReason::BackfaceVisibilityHidden))
         compositingReasons->setBackfaceVisibilityHidden(true);
 
-    if (reasonsBitmask & CompositingReasonClipsCompositingDescendants)
+    if (reasons.contains(CompositingReason::ClipsCompositingDescendants))
         compositingReasons->setClipsCompositingDescendants(true);
 
-    if (reasonsBitmask & CompositingReasonAnimation)
+    if (reasons.contains(CompositingReason::Animation))
         compositingReasons->setAnimation(true);
 
-    if (reasonsBitmask & CompositingReasonFilters)
+    if (reasons.contains(CompositingReason::Filters))
         compositingReasons->setFilters(true);
 
-    if (reasonsBitmask & CompositingReasonPositionFixed)
+    if (reasons.contains(CompositingReason::PositionFixed))
         compositingReasons->setPositionFixed(true);
 
-    if (reasonsBitmask & CompositingReasonPositionSticky)
+    if (reasons.contains(CompositingReason::PositionSticky))
         compositingReasons->setPositionSticky(true);
 
-    if (reasonsBitmask & CompositingReasonOverflowScrollingTouch)
+    if (reasons.contains(CompositingReason::OverflowScrollingTouch))
         compositingReasons->setOverflowScrollingTouch(true);
 
-    if (reasonsBitmask & CompositingReasonStacking)
+    if (reasons.contains(CompositingReason::Stacking))
         compositingReasons->setStacking(true);
 
-    if (reasonsBitmask & CompositingReasonOverlap)
+    if (reasons.contains(CompositingReason::Overlap))
         compositingReasons->setOverlap(true);
 
-    if (reasonsBitmask & CompositingReasonNegativeZIndexChildren)
+    if (reasons.contains(CompositingReason::NegativeZIndexChildren))
         compositingReasons->setNegativeZIndexChildren(true);
 
-    if (reasonsBitmask & CompositingReasonTransformWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::TransformWithCompositedDescendants))
         compositingReasons->setTransformWithCompositedDescendants(true);
 
-    if (reasonsBitmask & CompositingReasonOpacityWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::OpacityWithCompositedDescendants))
         compositingReasons->setOpacityWithCompositedDescendants(true);
 
-    if (reasonsBitmask & CompositingReasonMaskWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::MaskWithCompositedDescendants))
         compositingReasons->setMaskWithCompositedDescendants(true);
 
-    if (reasonsBitmask & CompositingReasonReflectionWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::ReflectionWithCompositedDescendants))
         compositingReasons->setReflectionWithCompositedDescendants(true);
 
-    if (reasonsBitmask & CompositingReasonFilterWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::FilterWithCompositedDescendants))
         compositingReasons->setFilterWithCompositedDescendants(true);
 
-    if (reasonsBitmask & CompositingReasonBlendingWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::BlendingWithCompositedDescendants))
         compositingReasons->setBlendingWithCompositedDescendants(true);
 
-    if (reasonsBitmask & CompositingReasonIsolatesCompositedBlendingDescendants)
+    if (reasons.contains(CompositingReason::IsolatesCompositedBlendingDescendants))
         compositingReasons->setIsolatesCompositedBlendingDescendants(true);
 
-    if (reasonsBitmask & CompositingReasonPerspective)
+    if (reasons.contains(CompositingReason::Perspective))
         compositingReasons->setPerspective(true);
 
-    if (reasonsBitmask & CompositingReasonPreserve3D)
+    if (reasons.contains(CompositingReason::Preserve3D))
         compositingReasons->setPreserve3D(true);
 
-    if (reasonsBitmask & CompositingReasonWillChange)
+    if (reasons.contains(CompositingReason::WillChange))
         compositingReasons->setWillChange(true);
 
-    if (reasonsBitmask & CompositingReasonRoot)
+    if (reasons.contains(CompositingReason::Root))
         compositingReasons->setRoot(true);
-    
+
     compositingReasonsResult = WTFMove(compositingReasons);
 }
 
index 6401ee4..1efbb8c 100644 (file)
@@ -2232,9 +2232,9 @@ bool RenderLayerCompositor::requiresOwnBackingStore(const RenderLayer& layer, co
     return false;
 }
 
-CompositingReasons RenderLayerCompositor::reasonsForCompositing(const RenderLayer& layer) const
+OptionSet<CompositingReason> RenderLayerCompositor::reasonsForCompositing(const RenderLayer& layer) const
 {
-    CompositingReasons reasons = CompositingReasonNone;
+    OptionSet<CompositingReason> reasons;
 
     if (!layer.isComposited())
         return reasons;
@@ -2242,89 +2242,89 @@ CompositingReasons RenderLayerCompositor::reasonsForCompositing(const RenderLaye
     auto& renderer = rendererForCompositingTests(layer);
 
     if (requiresCompositingForTransform(renderer))
-        reasons |= CompositingReason3DTransform;
+        reasons |= CompositingReason::Transform3D;
 
     if (requiresCompositingForVideo(renderer))
-        reasons |= CompositingReasonVideo;
+        reasons |= CompositingReason::Video;
     else if (requiresCompositingForCanvas(renderer))
-        reasons |= CompositingReasonCanvas;
+        reasons |= CompositingReason::Canvas;
     else if (requiresCompositingForPlugin(renderer))
-        reasons |= CompositingReasonPlugin;
+        reasons |= CompositingReason::Plugin;
     else if (requiresCompositingForFrame(renderer))
-        reasons |= CompositingReasonIFrame;
-    
+        reasons |= CompositingReason::IFrame;
+
     if ((canRender3DTransforms() && renderer.style().backfaceVisibility() == BackfaceVisibilityHidden))
-        reasons |= CompositingReasonBackfaceVisibilityHidden;
+        reasons |= CompositingReason::BackfaceVisibilityHidden;
 
     if (clipsCompositingDescendants(*renderer.layer()))
-        reasons |= CompositingReasonClipsCompositingDescendants;
+        reasons |= CompositingReason::ClipsCompositingDescendants;
 
     if (requiresCompositingForAnimation(renderer))
-        reasons |= CompositingReasonAnimation;
+        reasons |= CompositingReason::Animation;
 
     if (requiresCompositingForFilters(renderer))
-        reasons |= CompositingReasonFilters;
+        reasons |= CompositingReason::Filters;
 
     if (requiresCompositingForWillChange(renderer))
-        reasons |= CompositingReasonWillChange;
+        reasons |= CompositingReason::WillChange;
 
     if (requiresCompositingForPosition(renderer, *renderer.layer()))
-        reasons |= renderer.style().position() == FixedPosition ? CompositingReasonPositionFixed : CompositingReasonPositionSticky;
+        reasons |= renderer.style().position() == FixedPosition ? CompositingReason::PositionFixed : CompositingReason::PositionSticky;
 
 #if PLATFORM(IOS)
     if (requiresCompositingForScrolling(*renderer.layer()))
-        reasons |= CompositingReasonOverflowScrollingTouch;
+        reasons |= CompositingReason::OverflowScrollingTouch;
 #endif
 
     if (requiresCompositingForOverflowScrolling(*renderer.layer()))
-        reasons |= CompositingReasonOverflowScrollingTouch;
+        reasons |= CompositingReason::OverflowScrollingTouch;
 
     switch (renderer.layer()->indirectCompositingReason()) {
     case RenderLayer::IndirectCompositingReason::None:
         break;
     case RenderLayer::IndirectCompositingReason::Stacking:
-        reasons |= CompositingReasonStacking;
+        reasons |= CompositingReason::Stacking;
         break;
     case RenderLayer::IndirectCompositingReason::Overlap:
-        reasons |= CompositingReasonOverlap;
+        reasons |= CompositingReason::Overlap;
         break;
     case RenderLayer::IndirectCompositingReason::BackgroundLayer:
-        reasons |= CompositingReasonNegativeZIndexChildren;
+        reasons |= CompositingReason::NegativeZIndexChildren;
         break;
     case RenderLayer::IndirectCompositingReason::GraphicalEffect:
         if (renderer.hasTransform())
-            reasons |= CompositingReasonTransformWithCompositedDescendants;
+            reasons |= CompositingReason::TransformWithCompositedDescendants;
 
         if (renderer.isTransparent())
-            reasons |= CompositingReasonOpacityWithCompositedDescendants;
+            reasons |= CompositingReason::OpacityWithCompositedDescendants;
 
         if (renderer.hasMask())
-            reasons |= CompositingReasonMaskWithCompositedDescendants;
+            reasons |= CompositingReason::MaskWithCompositedDescendants;
 
         if (renderer.hasReflection())
-            reasons |= CompositingReasonReflectionWithCompositedDescendants;
+            reasons |= CompositingReason::ReflectionWithCompositedDescendants;
 
         if (renderer.hasFilter() || renderer.hasBackdropFilter())
-            reasons |= CompositingReasonFilterWithCompositedDescendants;
+            reasons |= CompositingReason::FilterWithCompositedDescendants;
 
 #if ENABLE(CSS_COMPOSITING)
         if (layer.isolatesCompositedBlending())
-            reasons |= CompositingReasonIsolatesCompositedBlendingDescendants;
+            reasons |= CompositingReason::IsolatesCompositedBlendingDescendants;
 
         if (layer.hasBlendMode())
-            reasons |= CompositingReasonBlendingWithCompositedDescendants;
+            reasons |= CompositingReason::BlendingWithCompositedDescendants;
 #endif
         break;
     case RenderLayer::IndirectCompositingReason::Perspective:
-        reasons |= CompositingReasonPerspective;
+        reasons |= CompositingReason::Perspective;
         break;
     case RenderLayer::IndirectCompositingReason::Preserve3D:
-        reasons |= CompositingReasonPreserve3D;
+        reasons |= CompositingReason::Preserve3D;
         break;
     }
 
     if (inCompositingMode() && renderer.layer()->isRootLayer())
-        reasons |= CompositingReasonRoot;
+        reasons |= CompositingReason::Root;
 
     return reasons;
 }
@@ -2332,80 +2332,83 @@ CompositingReasons RenderLayerCompositor::reasonsForCompositing(const RenderLaye
 #if !LOG_DISABLED
 const char* RenderLayerCompositor::logReasonsForCompositing(const RenderLayer& layer)
 {
-    CompositingReasons reasons = reasonsForCompositing(layer);
+    OptionSet<CompositingReason> reasons = reasonsForCompositing(layer);
 
-    if (reasons & CompositingReason3DTransform)
+    if (reasons.contains(CompositingReason::Transform3D))
         return "3D transform";
 
-    if (reasons & CompositingReasonVideo)
+    if (reasons.contains(CompositingReason::Video))
         return "video";
-    else if (reasons & CompositingReasonCanvas)
+
+    if (reasons.contains(CompositingReason::Canvas))
         return "canvas";
-    else if (reasons & CompositingReasonPlugin)
+
+    if (reasons.contains(CompositingReason::Plugin))
         return "plugin";
-    else if (reasons & CompositingReasonIFrame)
+
+    if (reasons.contains(CompositingReason::IFrame))
         return "iframe";
-    
-    if (reasons & CompositingReasonBackfaceVisibilityHidden)
+
+    if (reasons.contains(CompositingReason::BackfaceVisibilityHidden))
         return "backface-visibility: hidden";
 
-    if (reasons & CompositingReasonClipsCompositingDescendants)
+    if (reasons.contains(CompositingReason::ClipsCompositingDescendants))
         return "clips compositing descendants";
 
-    if (reasons & CompositingReasonAnimation)
+    if (reasons.contains(CompositingReason::Animation))
         return "animation";
 
-    if (reasons & CompositingReasonFilters)
+    if (reasons.contains(CompositingReason::Filters))
         return "filters";
 
-    if (reasons & CompositingReasonPositionFixed)
+    if (reasons.contains(CompositingReason::PositionFixed))
         return "position: fixed";
 
-    if (reasons & CompositingReasonPositionSticky)
+    if (reasons.contains(CompositingReason::PositionSticky))
         return "position: sticky";
 
-    if (reasons & CompositingReasonOverflowScrollingTouch)
+    if (reasons.contains(CompositingReason::OverflowScrollingTouch))
         return "-webkit-overflow-scrolling: touch";
 
-    if (reasons & CompositingReasonStacking)
+    if (reasons.contains(CompositingReason::Stacking))
         return "stacking";
 
-    if (reasons & CompositingReasonOverlap)
+    if (reasons.contains(CompositingReason::Overlap))
         return "overlap";
 
-    if (reasons & CompositingReasonNegativeZIndexChildren)
+    if (reasons.contains(CompositingReason::NegativeZIndexChildren))
         return "negative z-index children";
 
-    if (reasons & CompositingReasonTransformWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::TransformWithCompositedDescendants))
         return "transform with composited descendants";
 
-    if (reasons & CompositingReasonOpacityWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::OpacityWithCompositedDescendants))
         return "opacity with composited descendants";
 
-    if (reasons & CompositingReasonMaskWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::MaskWithCompositedDescendants))
         return "mask with composited descendants";
 
-    if (reasons & CompositingReasonReflectionWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::ReflectionWithCompositedDescendants))
         return "reflection with composited descendants";
 
-    if (reasons & CompositingReasonFilterWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::FilterWithCompositedDescendants))
         return "filter with composited descendants";
 
 #if ENABLE(CSS_COMPOSITING)
-    if (reasons & CompositingReasonBlendingWithCompositedDescendants)
+    if (reasons.contains(CompositingReason::BlendingWithCompositedDescendants))
         return "blending with composited descendants";
 
-    if (reasons & CompositingReasonIsolatesCompositedBlendingDescendants)
+    if (reasons.contains(CompositingReason::IsolatesCompositedBlendingDescendants))
         return "isolates composited blending descendants";
 #endif
 
-    if (reasons & CompositingReasonPerspective)
+    if (reasons.contains(CompositingReason::Perspective))
         return "perspective";
 
-    if (reasons & CompositingReasonPreserve3D)
+    if (reasons.contains(CompositingReason::Preserve3D))
         return "preserve-3d";
 
-    if (reasons & CompositingReasonRoot)
+    if (reasons.contains(CompositingReason::Root))
         return "root";
 
     return "";
index 8afcd5d..c9d48b1 100644 (file)
@@ -30,6 +30,7 @@
 #include "GraphicsLayerUpdater.h"
 #include "RenderLayer.h"
 #include <wtf/HashMap.h>
+#include <wtf/OptionSet.h>
 
 namespace WebCore {
 
@@ -54,36 +55,34 @@ enum CompositingUpdateType {
     CompositingUpdateOnCompositedScroll
 };
 
-enum {
-    CompositingReasonNone                                   = 0,
-    CompositingReason3DTransform                            = 1 << 0,
-    CompositingReasonVideo                                  = 1 << 1,
-    CompositingReasonCanvas                                 = 1 << 2,
-    CompositingReasonPlugin                                 = 1 << 3,
-    CompositingReasonIFrame                                 = 1 << 4,
-    CompositingReasonBackfaceVisibilityHidden               = 1 << 5,
-    CompositingReasonClipsCompositingDescendants            = 1 << 6,
-    CompositingReasonAnimation                              = 1 << 7,
-    CompositingReasonFilters                                = 1 << 8,
-    CompositingReasonPositionFixed                          = 1 << 9,
-    CompositingReasonPositionSticky                         = 1 << 10,
-    CompositingReasonOverflowScrollingTouch                 = 1 << 11,
-    CompositingReasonStacking                               = 1 << 12,
-    CompositingReasonOverlap                                = 1 << 13,
-    CompositingReasonNegativeZIndexChildren                 = 1 << 14,
-    CompositingReasonTransformWithCompositedDescendants     = 1 << 15,
-    CompositingReasonOpacityWithCompositedDescendants       = 1 << 16,
-    CompositingReasonMaskWithCompositedDescendants          = 1 << 17,
-    CompositingReasonReflectionWithCompositedDescendants    = 1 << 18,
-    CompositingReasonFilterWithCompositedDescendants        = 1 << 19,
-    CompositingReasonBlendingWithCompositedDescendants      = 1 << 20,
-    CompositingReasonPerspective                            = 1 << 21,
-    CompositingReasonPreserve3D                             = 1 << 22,
-    CompositingReasonWillChange                             = 1 << 23,
-    CompositingReasonRoot                                   = 1 << 24,
-    CompositingReasonIsolatesCompositedBlendingDescendants  = 1 << 25,
+enum class CompositingReason {
+    Transform3D                            = 1 << 0,
+    Video                                  = 1 << 1,
+    Canvas                                 = 1 << 2,
+    Plugin                                 = 1 << 3,
+    IFrame                                 = 1 << 4,
+    BackfaceVisibilityHidden               = 1 << 5,
+    ClipsCompositingDescendants            = 1 << 6,
+    Animation                              = 1 << 7,
+    Filters                                = 1 << 8,
+    PositionFixed                          = 1 << 9,
+    PositionSticky                         = 1 << 10,
+    OverflowScrollingTouch                 = 1 << 11,
+    Stacking                               = 1 << 12,
+    Overlap                                = 1 << 13,
+    NegativeZIndexChildren                 = 1 << 14,
+    TransformWithCompositedDescendants     = 1 << 15,
+    OpacityWithCompositedDescendants       = 1 << 16,
+    MaskWithCompositedDescendants          = 1 << 17,
+    ReflectionWithCompositedDescendants    = 1 << 18,
+    FilterWithCompositedDescendants        = 1 << 19,
+    BlendingWithCompositedDescendants      = 1 << 20,
+    Perspective                            = 1 << 21,
+    Preserve3D                             = 1 << 22,
+    WillChange                             = 1 << 23,
+    Root                                   = 1 << 24,
+    IsolatesCompositedBlendingDescendants  = 1 << 25,
 };
-typedef unsigned CompositingReasons;
 
 // RenderLayerCompositor manages the hierarchy of
 // composited RenderLayers. It determines which RenderLayers
@@ -303,7 +302,7 @@ public:
 
     bool hasNonMainLayersWithTiledBacking() const { return m_layersWithTiledBackingCount; }
 
-    CompositingReasons reasonsForCompositing(const RenderLayer&) const;
+    OptionSet<CompositingReason> reasonsForCompositing(const RenderLayer&) const;
 
     void setLayerFlushThrottlingEnabled(bool);
     void disableLayerFlushThrottlingTemporarilyForInteraction();