Title: [126452] trunk/Source/WebCore
Revision
126452
Author
[email protected]
Date
2012-08-23 11:28:23 -0700 (Thu, 23 Aug 2012)

Log Message

Remove redundant check for negative values when using WebCore::Color::alpha()
https://bugs.webkit.org/show_bug.cgi?id=94811

Patch by Bruno de Oliveira Abinader <[email protected]> on 2012-08-23
Reviewed by Eric Seidel.

Though alpha() returns a signed value (int), its value is stored on an unsigned
typedef (RGBA32) and is safeguarded by alphaChannel() that its value never goes
beyond 255, so no integer overflow, thus we can safely remove redundant check
for negative values while using it.

This change does not affect behavior, so no new tests needed.

* platform/graphics/Image.cpp:
(WebCore::Image::fillWithSolidColor):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintFillLayerExtended):
(WebCore::RenderBoxModelObject::boxShadowShouldBeAppliedToBackground): Using hasAlpha() for readibility.
* rendering/RenderView.cpp:
(WebCore::RenderView::paintBoxDecorations):
* rendering/style/RenderStyle.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (126451 => 126452)


--- trunk/Source/WebCore/ChangeLog	2012-08-23 18:20:52 UTC (rev 126451)
+++ trunk/Source/WebCore/ChangeLog	2012-08-23 18:28:23 UTC (rev 126452)
@@ -1,3 +1,26 @@
+2012-08-23  Bruno de Oliveira Abinader  <[email protected]>
+
+        Remove redundant check for negative values when using WebCore::Color::alpha()
+        https://bugs.webkit.org/show_bug.cgi?id=94811
+
+        Reviewed by Eric Seidel.
+
+        Though alpha() returns a signed value (int), its value is stored on an unsigned
+        typedef (RGBA32) and is safeguarded by alphaChannel() that its value never goes
+        beyond 255, so no integer overflow, thus we can safely remove redundant check
+        for negative values while using it.
+
+        This change does not affect behavior, so no new tests needed.
+
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::fillWithSolidColor):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
+        (WebCore::RenderBoxModelObject::boxShadowShouldBeAppliedToBackground): Using hasAlpha() for readibility.
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::paintBoxDecorations):
+        * rendering/style/RenderStyle.h:
+
 2012-08-23  Zan Dobersek  <[email protected]>
 
         [Gtk] Move feature defines processing into a GNUmakefile that's simple to autogenerate

Modified: trunk/Source/WebCore/platform/graphics/Image.cpp (126451 => 126452)


--- trunk/Source/WebCore/platform/graphics/Image.cpp	2012-08-23 18:20:52 UTC (rev 126451)
+++ trunk/Source/WebCore/platform/graphics/Image.cpp	2012-08-23 18:28:23 UTC (rev 126452)
@@ -80,7 +80,7 @@
 
 void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, ColorSpace styleColorSpace, CompositeOperator op)
 {
-    if (color.alpha() <= 0)
+    if (!color.alpha())
         return;
     
     CompositeOperator previousOperator = ctxt->compositeOperation();

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (126451 => 126452)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2012-08-23 18:20:52 UTC (rev 126451)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2012-08-23 18:28:23 UTC (rev 126452)
@@ -745,14 +745,14 @@
     // while rendering.)
     if (forceBackgroundToWhite) {
         // Note that we can't reuse this variable below because the bgColor might be changed
-        bool shouldPaintBackgroundColor = !bgLayer->next() && bgColor.isValid() && bgColor.alpha() > 0;
+        bool shouldPaintBackgroundColor = !bgLayer->next() && bgColor.isValid() && bgColor.alpha();
         if (shouldPaintBackgroundImage || shouldPaintBackgroundColor) {
             bgColor = Color::white;
             shouldPaintBackgroundImage = false;
         }
     }
 
-    bool colorVisible = bgColor.isValid() && bgColor.alpha() > 0;
+    bool colorVisible = bgColor.isValid() && bgColor.alpha();
     
     // Fast path for drawing simple color backgrounds.
     if (!isRoot && !clippedWithLocalScrolling && !shouldPaintBackgroundImage && isBorderFill && !bgLayer->next()) {
@@ -2420,7 +2420,7 @@
         return false;
 
     Color backgroundColor = style()->visitedDependentColor(CSSPropertyBackgroundColor);
-    if (!backgroundColor.isValid() || backgroundColor.alpha() < 255)
+    if (!backgroundColor.isValid() || backgroundColor.hasAlpha())
         return false;
 
     const FillLayer* lastBackgroundLayer = style()->backgroundLayers();

Modified: trunk/Source/WebCore/rendering/RenderView.cpp (126451 => 126452)


--- trunk/Source/WebCore/rendering/RenderView.cpp	2012-08-23 18:20:52 UTC (rev 126451)
+++ trunk/Source/WebCore/rendering/RenderView.cpp	2012-08-23 18:28:23 UTC (rev 126452)
@@ -315,7 +315,7 @@
         frameView()->setCannotBlitToWindow(); // The parent must show behind the child.
     else {
         Color baseColor = frameView()->baseBackgroundColor();
-        if (baseColor.alpha() > 0) {
+        if (baseColor.alpha()) {
             CompositeOperator previousOperator = paintInfo.context->compositeOperation();
             paintInfo.context->setCompositeOperation(CompositeCopy);
             paintInfo.context->fillRect(paintInfo.rect, baseColor, style()->colorSpace());

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (126451 => 126452)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2012-08-23 18:20:52 UTC (rev 126451)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2012-08-23 18:28:23 UTC (rev 126452)
@@ -439,7 +439,7 @@
     bool hasBackground() const
     {
         Color color = visitedDependentColor(CSSPropertyBackgroundColor);
-        if (color.isValid() && color.alpha() > 0)
+        if (color.isValid() && color.alpha())
             return true;
         return hasBackgroundImage();
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to