- Revision
- 224743
- Author
- [email protected]
- Date
- 2017-11-12 23:32:03 -0800 (Sun, 12 Nov 2017)
Log Message
[Cairo] Move line, miter operations in GraphicsContextCairo to CairoOperations
https://bugs.webkit.org/show_bug.cgi?id=179597
Reviewed by Carlos Garcia Campos.
Move operations that adjust line cap, line dash, line join and miter
limit to the CairoOperations file. This limits operations to only work
with a PlatformContextCairo object, along with any required parameter,
and will help with future work in this area.
No new tests -- no change in behavior.
* platform/graphics/cairo/CairoOperations.cpp:
(WebCore::Cairo::setLineCap):
(WebCore::Cairo::setLineDash):
(WebCore::Cairo::setLineJoin):
(WebCore::Cairo::setMiterLimit):
* platform/graphics/cairo/CairoOperations.h:
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::setLineCap):
(WebCore::GraphicsContext::setLineDash):
(WebCore::GraphicsContext::setLineJoin):
(WebCore::GraphicsContext::setMiterLimit):
(WebCore::isDashArrayAllZero): Deleted.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (224742 => 224743)
--- trunk/Source/WebCore/ChangeLog 2017-11-13 06:54:44 UTC (rev 224742)
+++ trunk/Source/WebCore/ChangeLog 2017-11-13 07:32:03 UTC (rev 224743)
@@ -1,3 +1,30 @@
+2017-11-12 Zan Dobersek <[email protected]>
+
+ [Cairo] Move line, miter operations in GraphicsContextCairo to CairoOperations
+ https://bugs.webkit.org/show_bug.cgi?id=179597
+
+ Reviewed by Carlos Garcia Campos.
+
+ Move operations that adjust line cap, line dash, line join and miter
+ limit to the CairoOperations file. This limits operations to only work
+ with a PlatformContextCairo object, along with any required parameter,
+ and will help with future work in this area.
+
+ No new tests -- no change in behavior.
+
+ * platform/graphics/cairo/CairoOperations.cpp:
+ (WebCore::Cairo::setLineCap):
+ (WebCore::Cairo::setLineDash):
+ (WebCore::Cairo::setLineJoin):
+ (WebCore::Cairo::setMiterLimit):
+ * platform/graphics/cairo/CairoOperations.h:
+ * platform/graphics/cairo/GraphicsContextCairo.cpp:
+ (WebCore::GraphicsContext::setLineCap):
+ (WebCore::GraphicsContext::setLineDash):
+ (WebCore::GraphicsContext::setLineJoin):
+ (WebCore::GraphicsContext::setMiterLimit):
+ (WebCore::isDashArrayAllZero): Deleted.
+
2017-11-12 Chris Dumez <[email protected]>
[Service Workers] Activate algorithm says terminate the active worker if it exists
Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (224742 => 224743)
--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2017-11-13 06:54:44 UTC (rev 224742)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2017-11-13 07:32:03 UTC (rev 224743)
@@ -45,6 +45,53 @@
namespace WebCore {
namespace Cairo {
+void setLineCap(PlatformContextCairo& platformContext, LineCap lineCap)
+{
+ cairo_line_cap_t cairoCap;
+ switch (lineCap) {
+ case ButtCap:
+ cairoCap = CAIRO_LINE_CAP_BUTT;
+ break;
+ case RoundCap:
+ cairoCap = CAIRO_LINE_CAP_ROUND;
+ break;
+ case SquareCap:
+ cairoCap = CAIRO_LINE_CAP_SQUARE;
+ break;
+ }
+ cairo_set_line_cap(platformContext.cr(), cairoCap);
+}
+
+void setLineDash(PlatformContextCairo& platformContext, const DashArray& dashes, float dashOffset)
+{
+ if (std::all_of(dashes.begin(), dashes.end(), [](auto& dash) { return !dash; }))
+ cairo_set_dash(platformContext.cr(), 0, 0, 0);
+ else
+ cairo_set_dash(platformContext.cr(), dashes.data(), dashes.size(), dashOffset);
+}
+
+void setLineJoin(PlatformContextCairo& platformContext, LineJoin lineJoin)
+{
+ cairo_line_join_t cairoJoin;
+ switch (lineJoin) {
+ case MiterJoin:
+ cairoJoin = CAIRO_LINE_JOIN_MITER;
+ break;
+ case RoundJoin:
+ cairoJoin = CAIRO_LINE_JOIN_ROUND;
+ break;
+ case BevelJoin:
+ cairoJoin = CAIRO_LINE_JOIN_BEVEL;
+ break;
+ }
+ cairo_set_line_join(platformContext.cr(), cairoJoin);
+}
+
+void setMiterLimit(PlatformContextCairo& platformContext, float miterLimit)
+{
+ cairo_set_miter_limit(platformContext.cr(), miterLimit);
+}
+
void clip(PlatformContextCairo& platformContext, const FloatRect& rect)
{
cairo_t* cr = platformContext.cr();
Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h (224742 => 224743)
--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h 2017-11-13 06:54:44 UTC (rev 224742)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.h 2017-11-13 07:32:03 UTC (rev 224743)
@@ -34,6 +34,7 @@
#if USE(CAIRO)
+#include "DashArray.h"
#include "GraphicsTypes.h"
namespace WebCore {
@@ -45,6 +46,11 @@
namespace Cairo {
+void setLineCap(PlatformContextCairo&, LineCap);
+void setLineDash(PlatformContextCairo&, const DashArray&, float);
+void setLineJoin(PlatformContextCairo&, LineJoin);
+void setMiterLimit(PlatformContextCairo&, float);
+
void clip(PlatformContextCairo&, const FloatRect&);
void clipOut(PlatformContextCairo&, const FloatRect&);
void clipOut(PlatformContextCairo&, const Path&);
Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (224742 => 224743)
--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp 2017-11-13 06:54:44 UTC (rev 224742)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp 2017-11-13 07:32:03 UTC (rev 224743)
@@ -930,30 +930,10 @@
return;
}
- cairo_line_cap_t cairoCap = CAIRO_LINE_CAP_BUTT;
- switch (lineCap) {
- case ButtCap:
- // no-op
- break;
- case RoundCap:
- cairoCap = CAIRO_LINE_CAP_ROUND;
- break;
- case SquareCap:
- cairoCap = CAIRO_LINE_CAP_SQUARE;
- break;
- }
- cairo_set_line_cap(platformContext()->cr(), cairoCap);
+ ASSERT(hasPlatformContext());
+ Cairo::setLineCap(*platformContext(), lineCap);
}
-static inline bool isDashArrayAllZero(const DashArray& dashes)
-{
- for (auto& dash : dashes) {
- if (dash)
- return false;
- }
- return true;
-}
-
void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
{
if (paintingDisabled())
@@ -964,10 +944,8 @@
return;
}
- if (isDashArrayAllZero(dashes))
- cairo_set_dash(platformContext()->cr(), 0, 0, 0);
- else
- cairo_set_dash(platformContext()->cr(), dashes.data(), dashes.size(), dashOffset);
+ ASSERT(hasPlatformContext());
+ Cairo::setLineDash(*platformContext(), dashes, dashOffset);
}
void GraphicsContext::setLineJoin(LineJoin lineJoin)
@@ -980,19 +958,8 @@
return;
}
- cairo_line_join_t cairoJoin = CAIRO_LINE_JOIN_MITER;
- switch (lineJoin) {
- case MiterJoin:
- // no-op
- break;
- case RoundJoin:
- cairoJoin = CAIRO_LINE_JOIN_ROUND;
- break;
- case BevelJoin:
- cairoJoin = CAIRO_LINE_JOIN_BEVEL;
- break;
- }
- cairo_set_line_join(platformContext()->cr(), cairoJoin);
+ ASSERT(hasPlatformContext());
+ Cairo::setLineJoin(*platformContext(), lineJoin);
}
void GraphicsContext::setMiterLimit(float miter)
@@ -1006,7 +973,8 @@
return;
}
- cairo_set_miter_limit(platformContext()->cr(), miter);
+ ASSERT(hasPlatformContext());
+ Cairo::setMiterLimit(*platformContext(), miter);
}
void GraphicsContext::setPlatformAlpha(float alpha)