- Revision
- 224809
- Author
- zandober...@gmail.com
- Date
- 2017-11-14 00:56:15 -0800 (Tue, 14 Nov 2017)
Log Message
[Cairo] Perform GraphicsContextPlatformPrivate method calls from CairoOperations
https://bugs.webkit.org/show_bug.cgi?id=179657
Reviewed by Carlos Garcia Campos.
To enable encapsulating remaining Cairo operations in static functions
inside the WebCore::Cairo namespace, we have to work around the
GraphicsContextPlatformPrivate methods that are invoked in the current
GraphicsContext implementation for Cairo.
A pointer to the GraphicsContextPlatformPrivate object is now kept on
the PlatformContextCairo instance, and we take care of setting it up
and clearing it out appropriate to the GraphicsContextPlatformPrivate
lifetime (as managed in Cairo-specific GraphicsContext implementation).
The GraphicsContextPlatformPrivate method invocations are then moved
to the appropriate CairoOperations functions.
No new tests -- no change in behavior.
* platform/graphics/cairo/CairoOperations.cpp:
(WebCore::Cairo::State::setCTM):
(WebCore::Cairo::save):
(WebCore::Cairo::restore):
(WebCore::Cairo::translate):
(WebCore::Cairo::rotate):
(WebCore::Cairo::scale):
(WebCore::Cairo::concatCTM):
(WebCore::Cairo::clip):
(WebCore::Cairo::clipPath):
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::GraphicsContext):
(WebCore::GraphicsContext::platformInit):
(WebCore::GraphicsContext::platformDestroy):
(WebCore::GraphicsContext::savePlatformState):
(WebCore::GraphicsContext::restorePlatformState):
(WebCore::GraphicsContext::clip):
(WebCore::GraphicsContext::clipPath):
(WebCore::GraphicsContext::translate):
(WebCore::GraphicsContext::concatCTM):
(WebCore::GraphicsContext::setCTM):
(WebCore::GraphicsContext::rotate):
(WebCore::GraphicsContext::scale):
* platform/graphics/cairo/PlatformContextCairo.h:
(WebCore::PlatformContextCairo::graphicsContextPrivate):
(WebCore::PlatformContextCairo::setGraphicsContextPrivate):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (224808 => 224809)
--- trunk/Source/WebCore/ChangeLog 2017-11-14 08:50:12 UTC (rev 224808)
+++ trunk/Source/WebCore/ChangeLog 2017-11-14 08:56:15 UTC (rev 224809)
@@ -1,5 +1,53 @@
2017-11-14 Zan Dobersek <zdober...@igalia.com>
+ [Cairo] Perform GraphicsContextPlatformPrivate method calls from CairoOperations
+ https://bugs.webkit.org/show_bug.cgi?id=179657
+
+ Reviewed by Carlos Garcia Campos.
+
+ To enable encapsulating remaining Cairo operations in static functions
+ inside the WebCore::Cairo namespace, we have to work around the
+ GraphicsContextPlatformPrivate methods that are invoked in the current
+ GraphicsContext implementation for Cairo.
+
+ A pointer to the GraphicsContextPlatformPrivate object is now kept on
+ the PlatformContextCairo instance, and we take care of setting it up
+ and clearing it out appropriate to the GraphicsContextPlatformPrivate
+ lifetime (as managed in Cairo-specific GraphicsContext implementation).
+ The GraphicsContextPlatformPrivate method invocations are then moved
+ to the appropriate CairoOperations functions.
+
+ No new tests -- no change in behavior.
+
+ * platform/graphics/cairo/CairoOperations.cpp:
+ (WebCore::Cairo::State::setCTM):
+ (WebCore::Cairo::save):
+ (WebCore::Cairo::restore):
+ (WebCore::Cairo::translate):
+ (WebCore::Cairo::rotate):
+ (WebCore::Cairo::scale):
+ (WebCore::Cairo::concatCTM):
+ (WebCore::Cairo::clip):
+ (WebCore::Cairo::clipPath):
+ * platform/graphics/cairo/GraphicsContextCairo.cpp:
+ (WebCore::GraphicsContext::GraphicsContext):
+ (WebCore::GraphicsContext::platformInit):
+ (WebCore::GraphicsContext::platformDestroy):
+ (WebCore::GraphicsContext::savePlatformState):
+ (WebCore::GraphicsContext::restorePlatformState):
+ (WebCore::GraphicsContext::clip):
+ (WebCore::GraphicsContext::clipPath):
+ (WebCore::GraphicsContext::translate):
+ (WebCore::GraphicsContext::concatCTM):
+ (WebCore::GraphicsContext::setCTM):
+ (WebCore::GraphicsContext::rotate):
+ (WebCore::GraphicsContext::scale):
+ * platform/graphics/cairo/PlatformContextCairo.h:
+ (WebCore::PlatformContextCairo::graphicsContextPrivate):
+ (WebCore::PlatformContextCairo::setGraphicsContextPrivate):
+
+2017-11-14 Zan Dobersek <zdober...@igalia.com>
+
[Cairo] Move simpler draw operations from GraphicsContextCairo to CairoOperations
https://bugs.webkit.org/show_bug.cgi?id=179614
Modified: trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp (224808 => 224809)
--- trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2017-11-14 08:50:12 UTC (rev 224808)
+++ trunk/Source/WebCore/platform/graphics/cairo/CairoOperations.cpp 2017-11-14 08:56:15 UTC (rev 224809)
@@ -39,6 +39,7 @@
#include "FloatConversion.h"
#include "FloatRect.h"
#include "GraphicsContext.h"
+#include "GraphicsContextPlatformPrivateCairo.h"
#include "Image.h"
#include "Path.h"
#include "PlatformContextCairo.h"
@@ -290,6 +291,9 @@
{
const cairo_matrix_t matrix = toCairoMatrix(transform);
cairo_set_matrix(platformContext.cr(), &matrix);
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->setCTM(transform);
}
AffineTransform getCTM(PlatformContextCairo& platformContext)
@@ -679,26 +683,41 @@
void save(PlatformContextCairo& platformContext)
{
platformContext.save();
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->save();
}
void restore(PlatformContextCairo& platformContext)
{
platformContext.restore();
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->restore();
}
void translate(PlatformContextCairo& platformContext, float x, float y)
{
cairo_translate(platformContext.cr(), x, y);
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->translate(x, y);
}
void rotate(PlatformContextCairo& platformContext, float angleInRadians)
{
cairo_rotate(platformContext.cr(), angleInRadians);
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->rotate(angleInRadians);
}
void scale(PlatformContextCairo& platformContext, const FloatSize& size)
{
cairo_scale(platformContext.cr(), size.width(), size.height());
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->scale(size);
}
void concatCTM(PlatformContextCairo& platformContext, const AffineTransform& transform)
@@ -705,6 +724,9 @@
{
const cairo_matrix_t matrix = toCairoMatrix(transform);
cairo_transform(platformContext.cr(), &matrix);
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->concatCTM(transform);
}
void beginTransparencyLayer(PlatformContextCairo& platformContext, float opacity)
@@ -736,6 +758,9 @@
cairo_clip(cr);
cairo_set_fill_rule(cr, savedFillRule);
cairo_set_antialias(cr, savedAntialiasRule);
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->clip(rect);
}
void clipOut(PlatformContextCairo& platformContext, const FloatRect& rect)
@@ -776,6 +801,9 @@
cairo_set_fill_rule(cr, clipRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
cairo_clip(cr);
cairo_set_fill_rule(cr, savedFillRule);
+
+ if (auto* graphicsContextPrivate = platformContext.graphicsContextPrivate())
+ graphicsContextPrivate->clip(path);
}
void clipToImageBuffer(PlatformContextCairo& platformContext, Image& image, const FloatRect& destRect)
Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (224808 => 224809)
--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp 2017-11-14 08:50:12 UTC (rev 224808)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp 2017-11-14 08:56:15 UTC (rev 224809)
@@ -173,6 +173,7 @@
return;
m_data = new GraphicsContextPlatformPrivate(std::make_unique<PlatformContextCairo>(cr));
+ m_data->platformContext.setGraphicsContextPrivate(m_data);
}
void GraphicsContext::platformInit(PlatformContextCairo* platformContext)
@@ -181,12 +182,16 @@
return;
m_data = new GraphicsContextPlatformPrivate(*platformContext);
+ m_data->platformContext.setGraphicsContextPrivate(m_data);
m_data->syncContext(platformContext->cr());
}
void GraphicsContext::platformDestroy()
{
- delete m_data;
+ if (m_data) {
+ m_data->platformContext.setGraphicsContextPrivate(nullptr);
+ delete m_data;
+ }
}
AffineTransform GraphicsContext::getCTM(IncludeDeviceScale) const
@@ -212,7 +217,6 @@
{
ASSERT(hasPlatformContext());
Cairo::save(*platformContext());
- m_data->save();
}
void GraphicsContext::restorePlatformState()
@@ -219,7 +223,6 @@
{
ASSERT(hasPlatformContext());
Cairo::restore(*platformContext());
- m_data->restore();
Cairo::State::setShadowValues(*platformContext(), FloatSize { m_state.shadowBlur, m_state.shadowBlur },
m_state.shadowOffset, m_state.shadowColor, m_state.shadowsIgnoreTransforms);
@@ -432,7 +435,6 @@
ASSERT(hasPlatformContext());
Cairo::clip(*platformContext(), rect);
- m_data->clip(rect);
}
void GraphicsContext::clipPath(const Path& path, WindRule clipRule)
@@ -447,7 +449,6 @@
ASSERT(hasPlatformContext());
Cairo::clipPath(*platformContext(), path, clipRule);
- m_data->clip(path);
}
void GraphicsContext::clipToImageBuffer(ImageBuffer& buffer, const FloatRect& destRect)
@@ -593,7 +594,6 @@
ASSERT(hasPlatformContext());
Cairo::translate(*platformContext(), x, y);
- m_data->translate(x, y);
}
void GraphicsContext::setPlatformFillColor(const Color&)
@@ -643,7 +643,6 @@
ASSERT(hasPlatformContext());
Cairo::concatCTM(*platformContext(), transform);
- m_data->concatCTM(transform);
}
void GraphicsContext::setCTM(const AffineTransform& transform)
@@ -658,7 +657,6 @@
ASSERT(hasPlatformContext());
Cairo::State::setCTM(*platformContext(), transform);
- m_data->setCTM(transform);
}
void GraphicsContext::setPlatformShadow(const FloatSize& offset, float blur, const Color& color)
@@ -833,7 +831,6 @@
ASSERT(hasPlatformContext());
Cairo::rotate(*platformContext(), radians);
- m_data->rotate(radians);
}
void GraphicsContext::scale(const FloatSize& size)
@@ -848,7 +845,6 @@
ASSERT(hasPlatformContext());
Cairo::scale(*platformContext(), size);
- m_data->scale(size);
}
void GraphicsContext::clipOut(const FloatRect& rect)
Modified: trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h (224808 => 224809)
--- trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h 2017-11-14 08:50:12 UTC (rev 224808)
+++ trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h 2017-11-14 08:56:15 UTC (rev 224809)
@@ -34,6 +34,7 @@
namespace WebCore {
+class GraphicsContextPlatformPrivate;
struct GraphicsContextState;
// Much like PlatformContextSkia in the Skia port, this class holds information that
@@ -50,6 +51,9 @@
cairo_t* cr() { return m_cr.get(); }
void setCr(cairo_t* cr) { m_cr = cr; }
+ GraphicsContextPlatformPrivate* graphicsContextPrivate() { return m_graphicsContextPrivate; }
+ void setGraphicsContextPrivate(GraphicsContextPlatformPrivate* graphicsContextPrivate) { m_graphicsContextPrivate = graphicsContextPrivate; }
+
ShadowBlur& shadowBlur() { return m_shadowBlur; }
Vector<float>& layers() { return m_layers; }
@@ -75,6 +79,11 @@
RefPtr<cairo_t> m_cr;
+ // Keeping a pointer to GraphicsContextPlatformPrivate here enables calling
+ // Windows-specific methods from CairoOperations (where only PlatformContextCairo
+ // can be leveraged).
+ GraphicsContextPlatformPrivate* m_graphicsContextPrivate { nullptr };
+
class State;
State* m_state;
WTF::Vector<State> m_stateStack;