diff options
author | Steve Block <steveblock@google.com> | 2011-05-25 19:08:45 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-08 13:51:31 +0100 |
commit | 2bde8e466a4451c7319e3a072d118917957d6554 (patch) | |
tree | 28f4a1b869a513e565c7760d0e6a06e7cf1fe95a /Source/WebCore/platform/graphics/cairo | |
parent | 6939c99b71d9372d14a0c74a772108052e8c48c8 (diff) | |
download | external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.zip external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.gz external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.bz2 |
Merge WebKit at r82507: Initial merge by git
Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e
Diffstat (limited to 'Source/WebCore/platform/graphics/cairo')
16 files changed, 212 insertions, 86 deletions
diff --git a/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp b/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp index b0588d6..0f90ce4 100644 --- a/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp @@ -34,6 +34,7 @@ #include "GraphicsContext.h" #include "OwnPtrCairo.h" #include "Path.h" +#include "PlatformContextCairo.h" #include "Timer.h" #include <cairo.h> @@ -88,7 +89,7 @@ PlatformContext ContextShadow::beginShadowLayer(GraphicsContext* context, const adjustBlurDistance(context); double x1, x2, y1, y2; - cairo_clip_extents(context->platformContext(), &x1, &y1, &x2, &y2); + cairo_clip_extents(context->platformContext()->cr(), &x1, &y1, &x2, &y2); IntRect layerRect = calculateLayerBoundingRect(context, layerArea, IntRect(x1, y1, x2 - x1, y2 - y1)); // Don't paint if we are totally outside the clip region. @@ -120,7 +121,7 @@ void ContextShadow::endShadowLayer(GraphicsContext* context) cairo_surface_mark_dirty(m_layerImage); } - cairo_t* cr = context->platformContext(); + cairo_t* cr = context->platformContext()->cr(); cairo_save(cr); setSourceRGBAFromColor(cr, m_color); cairo_mask_surface(cr, m_layerImage, m_layerOrigin.x(), m_layerOrigin.y()); @@ -198,7 +199,7 @@ void ContextShadow::drawRectShadow(GraphicsContext* context, const IntRect& rect int internalShadowHeight = radiusTwice + max(topLeftRadius.height(), topRightRadius.height()) + max(bottomLeftRadius.height(), bottomRightRadius.height()); - cairo_t* cr = context->platformContext(); + cairo_t* cr = context->platformContext()->cr(); // drawShadowedRect still does not work with rotations. // https://bugs.webkit.org/show_bug.cgi?id=45042 diff --git a/Source/WebCore/platform/graphics/cairo/FontCairo.cpp b/Source/WebCore/platform/graphics/cairo/FontCairo.cpp index 2d79499..58a7fd2 100644 --- a/Source/WebCore/platform/graphics/cairo/FontCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/FontCairo.cpp @@ -36,6 +36,7 @@ #include "GlyphBuffer.h" #include "Gradient.h" #include "GraphicsContext.h" +#include "PlatformContextCairo.h" #include "ImageBuffer.h" #include "Pattern.h" #include "SimpleFontData.h" @@ -64,7 +65,7 @@ static void drawGlyphsToContext(cairo_t* context, const SimpleFontData* font, Gl } } -static void drawGlyphsShadow(GraphicsContext* graphicsContext, cairo_t* context, const FloatPoint& point, const SimpleFontData* font, GlyphBufferGlyph* glyphs, int numGlyphs) +static void drawGlyphsShadow(GraphicsContext* graphicsContext, const FloatPoint& point, const SimpleFontData* font, GlyphBufferGlyph* glyphs, int numGlyphs) { ContextShadow* shadow = graphicsContext->contextShadow(); ASSERT(shadow); @@ -74,6 +75,7 @@ static void drawGlyphsShadow(GraphicsContext* graphicsContext, cairo_t* context, if (!shadow->mustUseContextShadow(graphicsContext)) { // Optimize non-blurry shadows, by just drawing text without the ContextShadow. + cairo_t* context = graphicsContext->platformContext()->cr(); cairo_save(context); cairo_translate(context, shadow->m_offset.width(), shadow->m_offset.height()); setSourceRGBAFromColor(context, shadow->m_color); @@ -106,9 +108,10 @@ void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, cons offset += glyphBuffer.advanceAt(from + i); } - cairo_t* cr = context->platformContext(); - drawGlyphsShadow(context, cr, point, font, glyphs, numGlyphs); + PlatformContextCairo* platformContext = context->platformContext(); + drawGlyphsShadow(context, point, font, glyphs, numGlyphs); + cairo_t* cr = platformContext->cr(); cairo_save(cr); prepareContextForGlyphDrawing(cr, font, point); if (context->textDrawingMode() & TextModeFill) { diff --git a/Source/WebCore/platform/graphics/cairo/FontCustomPlatformData.h b/Source/WebCore/platform/graphics/cairo/FontCustomPlatformData.h index 5807102..f8f3c99 100644 --- a/Source/WebCore/platform/graphics/cairo/FontCustomPlatformData.h +++ b/Source/WebCore/platform/graphics/cairo/FontCustomPlatformData.h @@ -25,6 +25,7 @@ #include "FontOrientation.h" #include "FontRenderingMode.h" #include "FontWidthVariant.h" +#include "TextOrientation.h" #include <wtf/Forward.h> #include <wtf/Noncopyable.h> @@ -41,7 +42,7 @@ struct FontCustomPlatformData { public: FontCustomPlatformData(FT_Face, SharedBuffer*); ~FontCustomPlatformData(); - FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, FontRenderingMode = NormalRenderingMode); + FontPlatformData fontPlatformData(int size, bool bold, bool italic, FontOrientation = Horizontal, TextOrientation = TextOrientationVerticalRight, FontWidthVariant = RegularWidth, FontRenderingMode = NormalRenderingMode); static bool supportsFormat(const String&); private: diff --git a/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp b/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp index 4e6ed07..225046a 100644 --- a/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp @@ -29,6 +29,7 @@ #include "CSSParser.h" #include "GraphicsContext.h" +#include "PlatformContextCairo.h" #include <cairo.h> namespace WebCore { @@ -87,7 +88,7 @@ void Gradient::setPlatformGradientSpaceTransform(const AffineTransform& gradient void Gradient::fill(GraphicsContext* context, const FloatRect& rect) { - cairo_t* cr = context->platformContext(); + cairo_t* cr = context->platformContext()->cr(); context->save(); cairo_set_source(cr, platformGradient()); diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp index e69a7a5..0fc94df 100644 --- a/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp @@ -47,6 +47,7 @@ #include "NotImplemented.h" #include "Path.h" #include "Pattern.h" +#include "PlatformContextCairo.h" #include "RefPtrCairo.h" #include "SimpleFontData.h" #include <cairo.h> @@ -148,7 +149,7 @@ static inline void drawPathShadow(GraphicsContext* context, PathDrawingStyle dra return; // Calculate the extents of the rendered solid paths. - cairo_t* cairoContext = context->platformContext(); + cairo_t* cairoContext = context->platformContext()->cr(); OwnPtr<cairo_path_t> path(cairo_copy_path(cairoContext)); FloatRect solidFigureExtents; @@ -199,12 +200,18 @@ static void strokeCurrentCairoPath(GraphicsContext* context, cairo_t* cairoCont cairo_new_path(cairoContext); } -void GraphicsContext::platformInit(PlatformGraphicsContext* cr) +GraphicsContext::GraphicsContext(cairo_t* cr) { - m_data = new GraphicsContextPlatformPrivate; - m_data->cr = cairo_reference(cr); - m_data->syncContext(cr); - setPaintingDisabled(!cr); + m_data = new GraphicsContextPlatformPrivate(new PlatformContextCairo(cr)); +} + +void GraphicsContext::platformInit(PlatformContextCairo* platformContext) +{ + m_data = new GraphicsContextPlatformPrivate(platformContext); + if (platformContext) + m_data->syncContext(platformContext->cr()); + else + setPaintingDisabled(true); } void GraphicsContext::platformDestroy() @@ -214,20 +221,20 @@ void GraphicsContext::platformDestroy() AffineTransform GraphicsContext::getCTM() const { - cairo_t* cr = platformContext(); + cairo_t* cr = platformContext()->cr(); cairo_matrix_t m; cairo_get_matrix(cr, &m); return AffineTransform(m.xx, m.yx, m.xy, m.yy, m.x0, m.y0); } -cairo_t* GraphicsContext::platformContext() const +PlatformContextCairo* GraphicsContext::platformContext() const { - return m_data->cr; + return m_data->platformContext; } void GraphicsContext::savePlatformState() { - cairo_save(m_data->cr); + cairo_save(platformContext()->cr()); m_data->save(); m_data->shadowStack.append(m_data->shadow); m_data->maskImageStack.append(ImageMaskInformation()); @@ -235,7 +242,8 @@ void GraphicsContext::savePlatformState() void GraphicsContext::restorePlatformState() { - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); + const ImageMaskInformation& maskInformation = m_data->maskImageStack.last(); if (maskInformation.isValid()) { const FloatRect& maskRect = maskInformation.maskRect(); @@ -251,7 +259,7 @@ void GraphicsContext::restorePlatformState() m_data->shadowStack.removeLast(); } - cairo_restore(m_data->cr); + cairo_restore(cr); m_data->restore(); } @@ -261,7 +269,7 @@ void GraphicsContext::drawRect(const IntRect& rect) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); if (fillColor().alpha()) @@ -289,7 +297,7 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) if (style == NoStroke) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); float width = strokeThickness(); @@ -376,7 +384,7 @@ void GraphicsContext::drawEllipse(const IntRect& rect) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); float yRadius = .5 * rect.height(); float xRadius = .5 * rect.width(); @@ -415,7 +423,7 @@ void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSp float fa = startAngle; float falen = fa + angleSpan; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); if (w != h) @@ -492,7 +500,7 @@ void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points if (npoints <= 1) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); cairo_set_antialias(cr, shouldAntialias ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE); @@ -522,7 +530,7 @@ void GraphicsContext::clipConvexPolygon(size_t numPoints, const FloatPoint* poin if (numPoints <= 1) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_new_path(cr); cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr); @@ -542,7 +550,7 @@ void GraphicsContext::fillPath(const Path& path) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); setPathOnCairoContext(cr, path.platformPath()->context()); fillCurrentCairoPath(this, cr); } @@ -552,7 +560,7 @@ void GraphicsContext::strokePath(const Path& path) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); setPathOnCairoContext(cr, path.platformPath()->context()); strokeCurrentCairoPath(this, cr); } @@ -562,7 +570,7 @@ void GraphicsContext::fillRect(const FloatRect& rect) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); fillCurrentCairoPath(this, cr); @@ -578,7 +586,7 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorS m_data->shadow.drawRectShadow(this, enclosingIntRect(rect)); if (color.alpha()) - fillRectSourceOver(m_data->cr, rect, color); + fillRectSourceOver(platformContext()->cr(), rect, color); } void GraphicsContext::clip(const FloatRect& rect) @@ -586,7 +594,7 @@ void GraphicsContext::clip(const FloatRect& rect) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr); cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING); @@ -600,7 +608,7 @@ void GraphicsContext::clipPath(const Path& path, WindRule clipRule) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); setPathOnCairoContext(cr, path.platformPath()->context()); cairo_set_fill_rule(cr, clipRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING); cairo_clip(cr); @@ -638,7 +646,7 @@ void GraphicsContext::drawFocusRing(const Path& path, int width, int /* offset * adjustFocusRingColor(ringColor); adjustFocusRingLineWidth(width); - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); appendWebCorePathToCairoContext(cr, path); setSourceRGBAFromColor(cr, ringColor); @@ -655,7 +663,7 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int unsigned rectCount = rects.size(); - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); cairo_push_group(cr); cairo_new_path(cr); @@ -732,7 +740,7 @@ void GraphicsContext::drawLineForTextChecking(const FloatPoint& origin, float wi if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); switch (style) { @@ -762,7 +770,7 @@ FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect) FloatRect result; double x = frect.x(); double y = frect.y(); - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_user_to_device(cr, &x, &y); x = round(x); y = round(y); @@ -799,7 +807,7 @@ void GraphicsContext::translate(float x, float y) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_translate(cr, x, y); m_data->translate(x, y); } @@ -821,7 +829,7 @@ void GraphicsContext::setPlatformStrokeThickness(float strokeThickness) if (paintingDisabled()) return; - cairo_set_line_width(m_data->cr, strokeThickness); + cairo_set_line_width(platformContext()->cr(), strokeThickness); } void GraphicsContext::setPlatformStrokeStyle(StrokeStyle strokeStyle) @@ -835,16 +843,16 @@ void GraphicsContext::setPlatformStrokeStyle(StrokeStyle strokeStyle) switch (strokeStyle) { case NoStroke: // FIXME: is it the right way to emulate NoStroke? - cairo_set_line_width(m_data->cr, 0); + cairo_set_line_width(platformContext()->cr(), 0); break; case SolidStroke: - cairo_set_dash(m_data->cr, 0, 0, 0); + cairo_set_dash(platformContext()->cr(), 0, 0, 0); break; case DottedStroke: - cairo_set_dash(m_data->cr, dotPattern, 2, 0); + cairo_set_dash(platformContext()->cr(), dotPattern, 2, 0); break; case DashedStroke: - cairo_set_dash(m_data->cr, dashPattern, 2, 0); + cairo_set_dash(platformContext()->cr(), dashPattern, 2, 0); break; } } @@ -859,7 +867,7 @@ void GraphicsContext::concatCTM(const AffineTransform& transform) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); const cairo_matrix_t matrix = cairo_matrix_t(transform); cairo_transform(cr, &matrix); m_data->concatCTM(transform); @@ -870,7 +878,7 @@ void GraphicsContext::setCTM(const AffineTransform& transform) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); const cairo_matrix_t matrix = cairo_matrix_t(transform); cairo_set_matrix(cr, &matrix); m_data->setCTM(transform); @@ -881,7 +889,7 @@ void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); clip(rect); Path p; @@ -928,7 +936,7 @@ void GraphicsContext::beginTransparencyLayer(float opacity) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_push_group(cr); m_data->layers.append(opacity); m_data->beginTransparencyLayer(); @@ -939,7 +947,7 @@ void GraphicsContext::endTransparencyLayer() if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_pop_group_to_source(cr); cairo_paint_with_alpha(cr, m_data->layers.last()); @@ -952,7 +960,7 @@ void GraphicsContext::clearRect(const FloatRect& rect) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); @@ -966,7 +974,7 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float width) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); cairo_set_line_width(cr, width); @@ -991,12 +999,12 @@ void GraphicsContext::setLineCap(LineCap lineCap) cairoCap = CAIRO_LINE_CAP_SQUARE; break; } - cairo_set_line_cap(m_data->cr, cairoCap); + cairo_set_line_cap(platformContext()->cr(), cairoCap); } void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset) { - cairo_set_dash(m_data->cr, dashes.data(), dashes.size(), dashOffset); + cairo_set_dash(platformContext()->cr(), dashes.data(), dashes.size(), dashOffset); } void GraphicsContext::setLineJoin(LineJoin lineJoin) @@ -1016,7 +1024,7 @@ void GraphicsContext::setLineJoin(LineJoin lineJoin) cairoJoin = CAIRO_LINE_JOIN_BEVEL; break; } - cairo_set_line_join(m_data->cr, cairoJoin); + cairo_set_line_join(platformContext()->cr(), cairoJoin); } void GraphicsContext::setMiterLimit(float miter) @@ -1024,7 +1032,7 @@ void GraphicsContext::setMiterLimit(float miter) if (paintingDisabled()) return; - cairo_set_miter_limit(m_data->cr, miter); + cairo_set_miter_limit(platformContext()->cr(), miter); } void GraphicsContext::setAlpha(float alpha) @@ -1042,7 +1050,7 @@ void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op) if (paintingDisabled()) return; - cairo_set_operator(m_data->cr, toCairoOperator(op)); + cairo_set_operator(platformContext()->cr(), toCairoOperator(op)); } void GraphicsContext::clip(const Path& path) @@ -1050,7 +1058,7 @@ void GraphicsContext::clip(const Path& path) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); OwnPtr<cairo_path_t> p(cairo_copy_path(path.platformPath()->context())); cairo_append_path(cr, p.get()); cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr); @@ -1070,7 +1078,7 @@ void GraphicsContext::clipOut(const Path& path) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); double x1, y1, x2, y2; cairo_clip_extents(cr, &x1, &y1, &x2, &y2); cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1); @@ -1087,7 +1095,7 @@ void GraphicsContext::rotate(float radians) if (paintingDisabled()) return; - cairo_rotate(m_data->cr, radians); + cairo_rotate(platformContext()->cr(), radians); m_data->rotate(radians); } @@ -1096,7 +1104,7 @@ void GraphicsContext::scale(const FloatSize& size) if (paintingDisabled()) return; - cairo_scale(m_data->cr, size.width(), size.height()); + cairo_scale(platformContext()->cr(), size.width(), size.height()); m_data->scale(size); } @@ -1105,7 +1113,7 @@ void GraphicsContext::clipOut(const IntRect& r) if (paintingDisabled()) return; - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); double x1, y1, x2, y2; cairo_clip_extents(cr, &x1, &y1, &x2, &y2); cairo_rectangle(cr, x1, y1, x2 - x1, y2 - y1); @@ -1132,7 +1140,7 @@ void GraphicsContext::fillRoundedRect(const IntRect& r, const IntSize& topLeft, if (hasShadow()) m_data->shadow.drawRectShadow(this, r, topLeft, topRight, bottomLeft, bottomRight); - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_save(cr); Path path; path.addRoundedRect(r, topLeft, topRight, bottomLeft, bottomRight); @@ -1170,7 +1178,7 @@ void GraphicsContext::setPlatformShouldAntialias(bool enable) // When true, use the default Cairo backend antialias mode (usually this // enables standard 'grayscale' antialiasing); false to explicitly disable // antialiasing. This is the same strategy as used in drawConvexPolygon(). - cairo_set_antialias(m_data->cr, enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE); + cairo_set_antialias(platformContext()->cr(), enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE); } void GraphicsContext::setImageInterpolationQuality(InterpolationQuality) @@ -1196,7 +1204,7 @@ void GraphicsContext::pushImageMask(cairo_surface_t* surface, const FloatRect& r // We want to allow the clipped elements to composite with the surface as it // is now, but they are isolated in another group. To make this work, we're // going to blit the current surface contents onto the new group once we push it. - cairo_t* cr = m_data->cr; + cairo_t* cr = platformContext()->cr(); cairo_surface_t* currentTarget = cairo_get_target(cr); cairo_surface_flush(currentTarget); diff --git a/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h b/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h index 924f69a..2bc290b 100644 --- a/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h +++ b/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h @@ -31,6 +31,7 @@ #include "GraphicsContext.h" #include "ContextShadow.h" +#include "PlatformContextCairo.h" #include "RefPtrCairo.h" #include <cairo.h> #include <math.h> @@ -67,8 +68,8 @@ private: class GraphicsContextPlatformPrivate { public: - GraphicsContextPlatformPrivate() - : cr(0) + GraphicsContextPlatformPrivate(PlatformContextCairo* newPlatformContext) + : platformContext(newPlatformContext) #if PLATFORM(GTK) , expose(0) #elif PLATFORM(WIN) @@ -82,7 +83,6 @@ public: ~GraphicsContextPlatformPrivate() { - cairo_destroy(cr); } #if PLATFORM(WIN) @@ -99,7 +99,7 @@ public: void setCTM(const AffineTransform&); void beginTransparencyLayer() { m_transparencyCount++; } void endTransparencyLayer() { m_transparencyCount--; } - void syncContext(PlatformGraphicsContext* cr); + void syncContext(cairo_t* cr); #else // On everything else, we do nothing. void save() {} @@ -114,12 +114,11 @@ public: void setCTM(const AffineTransform&) {} void beginTransparencyLayer() {} void endTransparencyLayer() {} - void syncContext(PlatformGraphicsContext* cr) {} + void syncContext(cairo_t* cr) {} #endif - cairo_t* cr; + PlatformContextCairo* platformContext; Vector<float> layers; - ContextShadow shadow; Vector<ContextShadow> shadowStack; Vector<ImageMaskInformation> maskImageStack; @@ -133,6 +132,23 @@ public: #endif }; +// This is a specialized private section for the Cairo GraphicsContext, which knows how +// to clean up the heap allocated PlatformContextCairo that we must use for the top-level +// GraphicsContext. +class GraphicsContextPlatformPrivateToplevel : public GraphicsContextPlatformPrivate { +public: + GraphicsContextPlatformPrivateToplevel(PlatformContextCairo* platformContext) + : GraphicsContextPlatformPrivate(platformContext) + { + } + + ~GraphicsContextPlatformPrivateToplevel() + { + delete platformContext; + } +}; + + } // namespace WebCore #endif // GraphicsContextPlatformPrivateCairo_h diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp index 9ee8a94..1d5d492 100644 --- a/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp @@ -37,7 +37,9 @@ #include "MIMETypeRegistry.h" #include "NotImplemented.h" #include "Pattern.h" +#include "PlatformContextCairo.h" #include "PlatformString.h" +#include "RefPtrCairo.h" #include <cairo.h> #include <wtf/Vector.h> @@ -66,6 +68,7 @@ namespace WebCore { ImageBufferData::ImageBufferData(const IntSize& size) : m_surface(0) + , m_platformContext(0) { } @@ -80,9 +83,9 @@ ImageBuffer::ImageBuffer(const IntSize& size, ColorSpace, RenderingMode, bool& s if (cairo_surface_status(m_data.m_surface) != CAIRO_STATUS_SUCCESS) return; // create will notice we didn't set m_initialized and fail. - cairo_t* cr = cairo_create(m_data.m_surface); - m_context.set(new GraphicsContext(cr)); - cairo_destroy(cr); // The context is now owned by the GraphicsContext. + RefPtr<cairo_t> cr = adoptRef(cairo_create(m_data.m_surface)); + m_data.m_platformContext.setCr(cr.get()); + m_context.set(new GraphicsContext(&m_data.m_platformContext)); success = true; } @@ -301,7 +304,7 @@ static cairo_status_t writeFunction(void* closure, const unsigned char* data, un String ImageBuffer::toDataURL(const String& mimeType, const double*) const { - cairo_surface_t* image = cairo_get_target(context()->platformContext()); + cairo_surface_t* image = cairo_get_target(context()->platformContext()->cr()); if (!image) return "data:,"; diff --git a/Source/WebCore/platform/graphics/cairo/ImageBufferData.h b/Source/WebCore/platform/graphics/cairo/ImageBufferData.h index 49f15df..42867d1 100644 --- a/Source/WebCore/platform/graphics/cairo/ImageBufferData.h +++ b/Source/WebCore/platform/graphics/cairo/ImageBufferData.h @@ -26,7 +26,9 @@ #ifndef ImageBufferData_h #define ImageBufferData_h -#include "cairo.h" +#include "PlatformContextCairo.h" + +typedef struct _cairo_surface cairo_surface_t; namespace WebCore { @@ -37,6 +39,7 @@ public: ImageBufferData(const IntSize&); cairo_surface_t* m_surface; + PlatformContextCairo m_platformContext; }; } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp b/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp index e51d65a..d3a52ce 100644 --- a/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp @@ -36,6 +36,7 @@ #include "ContextShadow.h" #include "FloatRect.h" #include "GraphicsContext.h" +#include "PlatformContextCairo.h" #include "ImageBuffer.h" #include "ImageObserver.h" #include "RefPtrCairo.h" @@ -114,7 +115,7 @@ void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo IntSize selfSize = size(); - cairo_t* cr = context->platformContext(); + cairo_t* cr = context->platformContext()->cr(); context->save(); // Set the compositing operation. @@ -169,8 +170,7 @@ void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, con if (!image) // If it's too early we won't have an image yet. return; - cairo_t* cr = context->platformContext(); - + cairo_t* cr = context->platformContext()->cr(); drawPatternToCairoContext(cr, image, size(), tileRect, patternTransform, phase, toCairoOperator(op), destRect); if (imageObserver()) diff --git a/Source/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp b/Source/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp index 94f6809..1594e7b 100644 --- a/Source/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/OwnPtrCairo.cpp @@ -20,7 +20,7 @@ #include "config.h" #include "OwnPtrCairo.h" -#if defined(USE_FREETYPE) +#if USE(FREETYPE) #include <cairo-ft.h> #include <fontconfig/fcfreetype.h> #endif @@ -29,7 +29,7 @@ namespace WTF { -#if defined(USE_FREETYPE) +#if USE(FREETYPE) template <> void deleteOwnedPtr<FcObjectSet>(FcObjectSet* ptr) { if (ptr) diff --git a/Source/WebCore/platform/graphics/cairo/OwnPtrCairo.h b/Source/WebCore/platform/graphics/cairo/OwnPtrCairo.h index 035d80e..e1dd370 100644 --- a/Source/WebCore/platform/graphics/cairo/OwnPtrCairo.h +++ b/Source/WebCore/platform/graphics/cairo/OwnPtrCairo.h @@ -22,7 +22,7 @@ #include "OwnPtr.h" -#if defined(USE_FREETYPE) +#if USE(FREETYPE) typedef struct _FcObjectSet FcObjectSet; typedef struct _FcFontSet FcFontSet; #endif @@ -31,7 +31,7 @@ typedef struct cairo_path cairo_path_t; namespace WTF { -#if defined(USE_FREETYPE) +#if USE(FREETYPE) template <> void deleteOwnedPtr<FcObjectSet>(FcObjectSet*); template <> void deleteOwnedPtr<FcFontSet>(FcFontSet*); #endif diff --git a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp b/Source/WebCore/platform/graphics/cairo/PathCairo.cpp index 7a09a52..533df10 100644 --- a/Source/WebCore/platform/graphics/cairo/PathCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/PathCairo.cpp @@ -281,7 +281,7 @@ FloatRect Path::boundingRect() const return FloatRect(x0, y0, x1 - x0, y1 - y0); } -FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) +FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) const { cairo_t* cr = platformPath()->context(); if (applier) { diff --git a/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp new file mode 100644 index 0000000..ba75162 --- /dev/null +++ b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "PlatformContextCairo.h" + +#include <cairo.h> + +namespace WebCore { + +PlatformContextCairo::PlatformContextCairo(cairo_t* cr) + : m_cr(cr) +{ +} + +} // namespace WebCore diff --git a/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h new file mode 100644 index 0000000..c6cceda --- /dev/null +++ b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef PlatformContextCairo_h +#define PlatformContextCairo_h + +#include "ContextShadow.h" +#include "RefPtrCairo.h" + +namespace WebCore { + +// Much like PlatformContextSkia in the Skia port, this class holds information that +// would normally be private to GraphicsContext, except that we want to allow access +// to it in Font and Image code. This allows us to separate the concerns of Cairo-specific +// code from the platform-independent GraphicsContext. + +class PlatformContextCairo { + WTF_MAKE_NONCOPYABLE(PlatformContextCairo); +public: + PlatformContextCairo(cairo_t*); + cairo_t* cr() { return m_cr.get(); } + void setCr(cairo_t* cr) { m_cr = cr; } + +private: + RefPtr<cairo_t> m_cr; +}; + +} // namespace WebCore + +#endif // PlatformContextCairo_h diff --git a/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp b/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp index c8b242c..1792002 100644 --- a/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp @@ -21,7 +21,7 @@ #include <cairo.h> -#if defined(USE_FREETYPE) +#if USE(FREETYPE) #include <cairo-ft.h> #include <fontconfig/fcfreetype.h> #endif @@ -88,7 +88,7 @@ template<> void derefIfNotNull(cairo_pattern_t* ptr) cairo_pattern_destroy(ptr); } -#if defined(USE_FREETYPE) +#if USE(FREETYPE) template<> void refIfNotNull(FcPattern* ptr) { if (LIKELY(ptr != 0)) diff --git a/Source/WebCore/platform/graphics/cairo/RefPtrCairo.h b/Source/WebCore/platform/graphics/cairo/RefPtrCairo.h index 204d1e3..540f9dc 100644 --- a/Source/WebCore/platform/graphics/cairo/RefPtrCairo.h +++ b/Source/WebCore/platform/graphics/cairo/RefPtrCairo.h @@ -28,7 +28,7 @@ typedef struct _cairo_font_face cairo_font_face_t; typedef struct _cairo_scaled_font cairo_scaled_font_t; typedef struct _cairo_pattern cairo_pattern_t; -#if defined(USE_FREETYPE) +#if USE(FREETYPE) typedef struct _FcPattern FcPattern; #endif @@ -49,7 +49,7 @@ template<> void derefIfNotNull(cairo_scaled_font_t* ptr); template<> void refIfNotNull(cairo_pattern_t*); template<> void derefIfNotNull(cairo_pattern_t*); -#if defined(USE_FREETYPE) +#if USE(FREETYPE) template<> void refIfNotNull(FcPattern* ptr); template<> void derefIfNotNull(FcPattern* ptr); #endif |