summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/cg/GraphicsContextCG.cpp')
-rw-r--r--WebCore/platform/graphics/cg/GraphicsContextCG.cpp99
1 files changed, 48 insertions, 51 deletions
diff --git a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
index 8d72b85..2eb929e 100644
--- a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
+++ b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp
@@ -299,21 +299,12 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
// This method is only used to draw the little circles used in lists.
void GraphicsContext::drawEllipse(const IntRect& rect)
{
- // FIXME: CG added CGContextAddEllipseinRect in Tiger, so we should be able to quite easily draw an ellipse.
- // This code can only handle circles, not ellipses. But khtml only
- // uses it for circles.
- ASSERT(rect.width() == rect.height());
-
if (paintingDisabled())
return;
- CGContextRef context = platformContext();
- CGContextBeginPath(context);
- float r = (float)rect.width() / 2;
- CGContextAddArc(context, rect.x() + r, rect.y() + r, r, 0.0f, 2.0f * piFloat, 0);
- CGContextClosePath(context);
-
- drawPath();
+ Path path;
+ path.addEllipse(rect);
+ drawPath(path);
}
@@ -405,21 +396,22 @@ void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSp
CGContextRestoreGState(context);
}
-static void addConvexPolygonToContext(CGContextRef context, size_t numPoints, const FloatPoint* points)
+static void addConvexPolygonToPath(Path& path, size_t numberOfPoints, const FloatPoint* points)
{
- CGContextBeginPath(context);
- CGContextMoveToPoint(context, points[0].x(), points[0].y());
- for (size_t i = 1; i < numPoints; i++)
- CGContextAddLineToPoint(context, points[i].x(), points[i].y());
- CGContextClosePath(context);
+ ASSERT(numberOfPoints > 0);
+
+ path.moveTo(points[0]);
+ for (size_t i = 1; i < numberOfPoints; ++i)
+ path.addLineTo(points[i]);
+ path.closeSubpath();
}
-void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool antialiased)
+void GraphicsContext::drawConvexPolygon(size_t numberOfPoints, const FloatPoint* points, bool antialiased)
{
if (paintingDisabled())
return;
- if (npoints <= 1)
+ if (numberOfPoints <= 1)
return;
CGContextRef context = platformContext();
@@ -427,28 +419,30 @@ void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points
if (antialiased != shouldAntialias())
CGContextSetShouldAntialias(context, antialiased);
- addConvexPolygonToContext(context, npoints, points);
- drawPath();
+ Path path;
+ addConvexPolygonToPath(path, numberOfPoints, points);
+ drawPath(path);
if (antialiased != shouldAntialias())
CGContextSetShouldAntialias(context, shouldAntialias());
}
-void GraphicsContext::clipConvexPolygon(size_t numPoints, const FloatPoint* points, bool antialias)
+void GraphicsContext::clipConvexPolygon(size_t numberOfPoints, const FloatPoint* points, bool antialias)
{
if (paintingDisabled())
return;
- if (numPoints <= 1)
+ if (numberOfPoints <= 1)
return;
CGContextRef context = platformContext();
if (antialias != shouldAntialias())
CGContextSetShouldAntialias(context, antialias);
-
- addConvexPolygonToContext(context, numPoints, points);
- clipPath(RULE_NONZERO);
+
+ Path path;
+ addConvexPolygonToPath(path, numberOfPoints, points);
+ clipPath(path, RULE_NONZERO);
if (antialias != shouldAntialias())
CGContextSetShouldAntialias(context, shouldAntialias());
@@ -511,7 +505,7 @@ static inline bool calculateDrawingMode(const GraphicsContextState& state, CGPat
return shouldFill || shouldStroke;
}
-void GraphicsContext::drawPath()
+void GraphicsContext::drawPath(const Path& path)
{
if (paintingDisabled())
return;
@@ -521,11 +515,15 @@ void GraphicsContext::drawPath()
if (state.fillGradient || state.strokeGradient) {
// We don't have any optimized way to fill & stroke a path using gradients
- fillPath();
- strokePath();
+ // FIXME: Be smarter about this.
+ fillPath(path);
+ strokePath(path);
return;
}
+ CGContextBeginPath(context);
+ CGContextAddPath(context, path.platformPath());
+
if (state.fillPattern)
applyFillPattern();
if (state.strokePattern)
@@ -544,13 +542,16 @@ static inline void fillPathWithFillRule(CGContextRef context, WindRule fillRule)
CGContextFillPath(context);
}
-void GraphicsContext::fillPath()
+void GraphicsContext::fillPath(const Path& path)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
+ CGContextBeginPath(context);
+ CGContextAddPath(context, path.platformPath());
+
if (m_common->state.fillGradient) {
CGContextSaveGState(context);
if (fillRule() == RULE_EVENODD)
@@ -568,13 +569,16 @@ void GraphicsContext::fillPath()
fillPathWithFillRule(context, fillRule());
}
-void GraphicsContext::strokePath()
+void GraphicsContext::strokePath(const Path& path)
{
if (paintingDisabled())
return;
CGContextRef context = platformContext();
+ CGContextBeginPath(context);
+ CGContextAddPath(context, path.platformPath());
+
if (m_common->state.strokeGradient) {
CGContextSaveGState(context);
CGContextReplacePathWithStrokedPath(context);
@@ -643,8 +647,7 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef
Path path;
path.addRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight);
- addPath(path);
- fillPath();
+ fillPath(path);
if (oldFillColor != color || oldColorSpace != colorSpace)
setCGFillColor(context, oldFillColor, oldColorSpace);
@@ -669,19 +672,23 @@ void GraphicsContext::clipOut(const IntRect& rect)
CGContextEOClip(platformContext());
}
-void GraphicsContext::clipPath(WindRule clipRule)
+void GraphicsContext::clipPath(const Path& path, WindRule clipRule)
{
if (paintingDisabled())
return;
+ if (path.isEmpty())
+ return;
+
CGContextRef context = platformContext();
- if (!CGContextIsPathEmpty(context)) {
- if (clipRule == RULE_EVENODD)
- CGContextEOClip(context);
- else
- CGContextClip(context);
- }
+ CGContextBeginPath(platformContext());
+ CGContextAddPath(platformContext(), path.platformPath());
+
+ if (clipRule == RULE_EVENODD)
+ CGContextEOClip(context);
+ else
+ CGContextClip(context);
}
void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness)
@@ -863,16 +870,6 @@ void GraphicsContext::setLineJoin(LineJoin join)
}
}
-void GraphicsContext::beginPath()
-{
- CGContextBeginPath(platformContext());
-}
-
-void GraphicsContext::addPath(const Path& path)
-{
- CGContextAddPath(platformContext(), path.platformPath());
-}
-
void GraphicsContext::clip(const Path& path)
{
if (paintingDisabled())