Title: [251914] trunk/Source/WebCore
Revision
251914
Author
commit-qu...@webkit.org
Date
2019-11-01 05:55:27 -0700 (Fri, 01 Nov 2019)

Log Message

CanvasRenderingContext2DBase: use CanvasBase more extensively
https://bugs.webkit.org/show_bug.cgi?id=182685

Patch by Zan Dobersek  <zdober...@igalia.com>  and  Chris Lord <cl...@igalia.com> on 2019-11-01
Reviewed by Adrian Perez de Castro.

In CanvasRenderingContext2DBase, stop downcasting the CanvasBase object
to HTMLCanvasElement where not necessary, and where necessary, do so
after testing that the CanvasBase object is indeed a HTMLCanvasElement.

All the functionality that previously required downcasting has now moved
into the CanvasBase class. Combined with these changes, this will allow
OffscreenCanvas to leverage CanvasRenderingContext2DBase for 2D
rasterization.

CanvasStyle is similarly modified to work on CanvasBase objects, only
retrieving current color value from the inline style only in case of
an HTMLCanvasElement derivative.

No new tests -- no change in behavior.

* html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::setStrokeStyle):
(WebCore::CanvasRenderingContext2DBase::setFillStyle):
(WebCore::CanvasRenderingContext2DBase::setShadowColor):
(WebCore::CanvasRenderingContext2DBase::setShadow):
(WebCore::CanvasRenderingContext2DBase::didDraw):
(WebCore::CanvasRenderingContext2DBase::getImageData const):
(WebCore::CanvasRenderingContext2DBase::putImageData):
(WebCore::CanvasRenderingContext2DBase::platformLayer const):
* html/canvas/CanvasStyle.cpp:
(WebCore::currentColor):
(WebCore::parseColorOrCurrentColor):
* html/canvas/CanvasStyle.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (251913 => 251914)


--- trunk/Source/WebCore/ChangeLog	2019-11-01 08:44:04 UTC (rev 251913)
+++ trunk/Source/WebCore/ChangeLog	2019-11-01 12:55:27 UTC (rev 251914)
@@ -1,3 +1,39 @@
+2019-11-01  Zan Dobersek  <zdober...@igalia.com>  and  Chris Lord  <cl...@igalia.com>
+
+        CanvasRenderingContext2DBase: use CanvasBase more extensively
+        https://bugs.webkit.org/show_bug.cgi?id=182685
+
+        Reviewed by Adrian Perez de Castro.
+
+        In CanvasRenderingContext2DBase, stop downcasting the CanvasBase object
+        to HTMLCanvasElement where not necessary, and where necessary, do so
+        after testing that the CanvasBase object is indeed a HTMLCanvasElement.
+
+        All the functionality that previously required downcasting has now moved
+        into the CanvasBase class. Combined with these changes, this will allow
+        OffscreenCanvas to leverage CanvasRenderingContext2DBase for 2D
+        rasterization.
+
+        CanvasStyle is similarly modified to work on CanvasBase objects, only
+        retrieving current color value from the inline style only in case of
+        an HTMLCanvasElement derivative.
+
+        No new tests -- no change in behavior.
+
+        * html/canvas/CanvasRenderingContext2DBase.cpp:
+        (WebCore::CanvasRenderingContext2DBase::setStrokeStyle):
+        (WebCore::CanvasRenderingContext2DBase::setFillStyle):
+        (WebCore::CanvasRenderingContext2DBase::setShadowColor):
+        (WebCore::CanvasRenderingContext2DBase::setShadow):
+        (WebCore::CanvasRenderingContext2DBase::didDraw):
+        (WebCore::CanvasRenderingContext2DBase::getImageData const):
+        (WebCore::CanvasRenderingContext2DBase::putImageData):
+        (WebCore::CanvasRenderingContext2DBase::platformLayer const):
+        * html/canvas/CanvasStyle.cpp:
+        (WebCore::currentColor):
+        (WebCore::parseColorOrCurrentColor):
+        * html/canvas/CanvasStyle.h:
+
 2019-10-31  Fujii Hironori  <hironori.fu...@sony.com>
 
         [WinCairo][Clang] Unreviewed build fix

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp (251913 => 251914)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2019-11-01 08:44:04 UTC (rev 251913)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp	2019-11-01 12:55:27 UTC (rev 251914)
@@ -402,14 +402,12 @@
     if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentColor(style))
         return;
 
-    if (style.isCurrentColor() && is<HTMLCanvasElement>(canvasBase())) {
-        auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
-
+    if (style.isCurrentColor()) {
         if (style.hasOverrideAlpha()) {
             // FIXME: Should not use RGBA32 here.
-            style = CanvasStyle(colorWithOverrideAlpha(currentColor(&canvas).rgb(), style.overrideAlpha()));
+            style = CanvasStyle(colorWithOverrideAlpha(currentColor(&canvasBase()).rgb(), style.overrideAlpha()));
         } else
-            style = CanvasStyle(currentColor(&canvas));
+            style = CanvasStyle(currentColor(&canvasBase()));
     } else
         checkOrigin(style.canvasPattern().get());
 
@@ -431,14 +429,12 @@
     if (state().fillStyle.isValid() && state().fillStyle.isEquivalentColor(style))
         return;
 
-    if (style.isCurrentColor() && is<HTMLCanvasElement>(canvasBase())) {
-        auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
-
+    if (style.isCurrentColor()) {
         if (style.hasOverrideAlpha()) {
             // FIXME: Should not use RGBA32 here.
-            style = CanvasStyle(colorWithOverrideAlpha(currentColor(&canvas).rgb(), style.overrideAlpha()));
+            style = CanvasStyle(colorWithOverrideAlpha(currentColor(&canvasBase()).rgb(), style.overrideAlpha()));
         } else
-            style = CanvasStyle(currentColor(&canvas));
+            style = CanvasStyle(currentColor(&canvasBase()));
     } else
         checkOrigin(style.canvasPattern().get());
 
@@ -671,8 +667,7 @@
 
 void CanvasRenderingContext2DBase::setShadowColor(const String& colorString)
 {
-    auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
-    Color color = parseColorOrCurrentColor(colorString, &canvas);
+    Color color = parseColorOrCurrentColor(colorString, &canvasBase());
     if (!color.isValid())
         return;
     if (state().shadowColor == color)
@@ -1339,8 +1334,7 @@
 {
     Color color = Color::transparent;
     if (!colorString.isNull()) {
-        auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
-        color = parseColorOrCurrentColor(colorString, &canvas);
+        color = parseColorOrCurrentColor(colorString, &canvasBase());
         if (!color.isValid())
             return;
     }
@@ -2036,7 +2030,7 @@
 
 #if ENABLE(ACCELERATED_2D_CANVAS)
     // If we are drawing to hardware and we have a composited layer, just call contentChanged().
-    if (isAccelerated()) {
+    if (isAccelerated() && is<HTMLCanvasElement>(canvasBase())) {
         auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
         RenderBox* renderBox = canvas.renderBox();
         if (renderBox && renderBox->hasAcceleratedCompositing()) {
@@ -2197,9 +2191,8 @@
         return nullptr;
 
     IntRect imageDataRect = enclosingIntRect(logicalRect);
-    auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
 
-    ImageBuffer* buffer = canvas.buffer();
+    ImageBuffer* buffer = canvasBase().buffer();
     if (!buffer)
         return createEmptyImageData(imageDataRect.size());
 
@@ -2230,9 +2223,7 @@
 
 void CanvasRenderingContext2DBase::putImageData(ImageData& data, ImageBuffer::CoordinateSystem coordinateSystem, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight)
 {
-    auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
-
-    ImageBuffer* buffer = canvas.buffer();
+    ImageBuffer* buffer = canvasBase().buffer();
     if (!buffer)
         return;
 
@@ -2285,9 +2276,10 @@
 
 PlatformLayer* CanvasRenderingContext2DBase::platformLayer() const
 {
-    auto& canvas = downcast<HTMLCanvasElement>(canvasBase());
+    if (auto* buffer = canvasBase().buffer())
+        return buffer->platformLayer();
 
-    return canvas.buffer() ? canvas.buffer()->platformLayer() : nullptr;
+    return nullptr;
 }
 
 #endif

Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.cpp (251913 => 251914)


--- trunk/Source/WebCore/html/canvas/CanvasStyle.cpp	2019-11-01 08:44:04 UTC (rev 251913)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.cpp	2019-11-01 12:55:27 UTC (rev 251914)
@@ -56,20 +56,24 @@
     return CSSParser::parseSystemColor(colorString, nullptr);
 }
 
-Color currentColor(HTMLCanvasElement* canvas)
+Color currentColor(CanvasBase* canvasBase)
 {
-    if (!canvas || !canvas->isConnected() || !canvas->inlineStyle())
+    if (!is<HTMLCanvasElement>(canvasBase))
         return Color::black;
-    Color color = CSSParser::parseColor(canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
+
+    auto& canvas = downcast<HTMLCanvasElement>(*canvasBase);
+    if (!canvas.isConnected() || !canvas.inlineStyle())
+        return Color::black;
+    Color color = CSSParser::parseColor(canvas.inlineStyle()->getPropertyValue(CSSPropertyColor));
     if (!color.isValid())
         return Color::black;
     return color;
 }
 
-Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement* canvas)
+Color parseColorOrCurrentColor(const String& colorString, CanvasBase* canvasBase)
 {
     if (isCurrentColorString(colorString))
-        return currentColor(canvas);
+        return currentColor(canvasBase);
 
     return parseColor(colorString);
 }

Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.h (251913 => 251914)


--- trunk/Source/WebCore/html/canvas/CanvasStyle.h	2019-11-01 08:44:04 UTC (rev 251913)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.h	2019-11-01 12:55:27 UTC (rev 251914)
@@ -35,7 +35,7 @@
 
 class Document;
 class GraphicsContext;
-class HTMLCanvasElement;
+class CanvasBase;
 
 class CanvasStyle {
 public:
@@ -89,8 +89,8 @@
     Variant<Invalid, Color, CMYKAColor, RefPtr<CanvasGradient>, RefPtr<CanvasPattern>, CurrentColor> m_style;
 };
 
-Color currentColor(HTMLCanvasElement*);
-Color parseColorOrCurrentColor(const String& colorString, HTMLCanvasElement*);
+Color currentColor(CanvasBase*);
+Color parseColorOrCurrentColor(const String& colorString, CanvasBase*);
 
 inline CanvasStyle::CanvasStyle()
     : m_style(Invalid { })
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to