Changeset 82496 in webkit


Ignore:
Timestamp:
Mar 30, 2011 1:56:40 PM (13 years ago)
Author:
Martin Robinson
Message:

2011-03-30 Martin Robinson <mrobinson@igalia.com>

Reviewed by Dirk Schulze.

[Cairo] Better separate the concerns of GraphicsContextCairo
https://bugs.webkit.org/show_bug.cgi?id=55150

Add a PlatformContextCairo which right now stores the cairo_t* for a
GraphicsContextCairo. Later patches will move logic for tracking ContextShadow
and image masking layers into this PlatformContextCairo class.

No new tests. This patch is only a code cleanup.

  • GNUmakefile.am:
  • platform/graphics/GraphicsContext.h: The platform context is no longer a cairo_t, but our new class the PlatformContextCairo.
  • platform/graphics/cairo/ContextShadowCairo.cpp: Updated to reflect new class.j
  • platform/graphics/cairo/FontCairo.cpp: Ditto.
  • platform/graphics/cairo/GradientCairo.cpp: Ditto.
  • platform/graphics/cairo/GraphicsContextCairo.cpp: Mostly mechanical changes which now reference platformContext()->cr() to get the cairo_t.
  • platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h: Now hold the PlatformContextCairo instead of the cairo_t.
  • platform/graphics/cairo/ImageBufferCairo.cpp: Update to reflect new class.
  • platform/graphics/cairo/ImageCairo.cpp: Ditto.
  • platform/graphics/cairo/PathCairo.cpp: Ditto.
  • platform/graphics/cairo/PlatformContextCairo.cpp: Added.
  • platform/graphics/cairo/PlatformContextCairo.h: Added.
  • platform/graphics/gtk/FontGtk.cpp: Update to reflect new class.
  • platform/graphics/gtk/IconGtk.cpp: Ditto.
  • platform/graphics/win/GraphicsContextCairoWin.cpp: Now fill out m_data with a private section containing the platform context instead of just a cairo_t.
  • platform/gtk/RenderThemeGtk.cpp: Update to reflect new class.
  • platform/gtk/WidgetRenderingContext.cpp: Ditto. (WebCore::WidgetRenderingContext::~WidgetRenderingContext): Ditto.
  • plugins/gtk/PluginViewGtk.cpp: Ditto.

2011-03-30 Martin Robinson <mrobinson@igalia.com>

Reviewed by Dirk Schulze.

[Cairo] Better separate the concerns of GraphicsContextCairo
https://bugs.webkit.org/show_bug.cgi?id=55150

Add a PlatformContextCairo which right now stores the cairo_t* for a
GraphicsContextCairo. Later patches will move logic for tracking ContextShadow
and image masking layers into this PlatformContextCairo class.

  • webkit/webkitwebframe.cpp: (draw_page_callback):
  • webkit/webkitwebview.cpp: (webkit_web_view_expose_event): (webkit_web_view_draw):

2011-03-30 Martin Robinson <mrobinson@igalia.com>

Reviewed by Dirk Schulze.

[Cairo] Better separate the concerns of GraphicsContextCairo
https://bugs.webkit.org/show_bug.cgi?id=55150

  • WebFrame.cpp: (hdcFromContext): Modify this method to take PlatformContextCairo instead of a cairo_t. (WebFrame::spoolPage): Update to reflect new platform context. (WebFrame::spoolPages): Ditto.
  • WebFrame.h: Ditto.
Location:
trunk/Source
Files:
24 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r82494 r82496  
     12011-03-30  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        [Cairo] Better separate the concerns of GraphicsContextCairo
     6        https://bugs.webkit.org/show_bug.cgi?id=55150
     7
     8        Add a PlatformContextCairo which right now stores the cairo_t* for a
     9        GraphicsContextCairo. Later patches will move logic for tracking ContextShadow
     10        and image masking layers into this PlatformContextCairo class.
     11
     12        No new tests. This patch is only a code cleanup.
     13
     14        * GNUmakefile.am:
     15        * platform/graphics/GraphicsContext.h: The platform context is no longer a
     16        cairo_t, but our new class the PlatformContextCairo.
     17        * platform/graphics/cairo/ContextShadowCairo.cpp: Updated to reflect new class.j
     18        * platform/graphics/cairo/FontCairo.cpp: Ditto.
     19        * platform/graphics/cairo/GradientCairo.cpp: Ditto.
     20        * platform/graphics/cairo/GraphicsContextCairo.cpp: Mostly mechanical
     21        changes which now reference platformContext()->cr() to get the cairo_t.
     22        * platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h: Now hold the
     23        PlatformContextCairo instead of the cairo_t.
     24        * platform/graphics/cairo/ImageBufferCairo.cpp: Update to reflect new class.
     25        * platform/graphics/cairo/ImageCairo.cpp: Ditto.
     26        * platform/graphics/cairo/PathCairo.cpp: Ditto.
     27        * platform/graphics/cairo/PlatformContextCairo.cpp: Added.
     28        * platform/graphics/cairo/PlatformContextCairo.h: Added.
     29        * platform/graphics/gtk/FontGtk.cpp: Update to reflect new class.
     30        * platform/graphics/gtk/IconGtk.cpp: Ditto.
     31        * platform/graphics/win/GraphicsContextCairoWin.cpp: Now fill out
     32        m_data with a private section containing the platform context instead of
     33        just a cairo_t.
     34        * platform/gtk/RenderThemeGtk.cpp: Update to reflect new class.
     35        * platform/gtk/WidgetRenderingContext.cpp: Ditto.
     36        (WebCore::WidgetRenderingContext::~WidgetRenderingContext): Ditto.
     37        * plugins/gtk/PluginViewGtk.cpp: Ditto.
     38
    1392011-03-30  Patrick Gansterer  <paroga@webkit.org>
    240
  • trunk/Source/WebCore/GNUmakefile.am

    r82465 r82496  
    37613761        Source/WebCore/platform/graphics/cairo/PathCairo.cpp \
    37623762        Source/WebCore/platform/graphics/cairo/PatternCairo.cpp \
     3763        Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp \
     3764        Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h \
    37633765        Source/WebCore/platform/graphics/cairo/RefPtrCairo.cpp \
    37643766        Source/WebCore/platform/graphics/cairo/RefPtrCairo.h \
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r81161 r82496  
    4343namespace WebCore {
    4444class ContextShadow;
     45class PlatformContextCairo;
    4546}
    46 typedef struct _cairo PlatformGraphicsContext;
     47typedef WebCore::PlatformContextCairo PlatformGraphicsContext;
    4748#elif PLATFORM(OPENVG)
    4849namespace WebCore {
     
    491492
    492493#if PLATFORM(CAIRO)
     494        GraphicsContext(cairo_t*);
    493495        void pushImageMask(cairo_surface_t*, const FloatRect&);
    494496#endif
  • trunk/Source/WebCore/platform/graphics/cairo/ContextShadowCairo.cpp

    r75237 r82496  
    3535#include "OwnPtrCairo.h"
    3636#include "Path.h"
     37#include "PlatformContextCairo.h"
    3738#include "Timer.h"
    3839#include <cairo.h>
     
    8990
    9091    double x1, x2, y1, y2;
    91     cairo_clip_extents(context->platformContext(), &x1, &y1, &x2, &y2);
     92    cairo_clip_extents(context->platformContext()->cr(), &x1, &y1, &x2, &y2);
    9293    IntRect layerRect = calculateLayerBoundingRect(context, layerArea, IntRect(x1, y1, x2 - x1, y2 - y1));
    9394
     
    121122    }
    122123
    123     cairo_t* cr = context->platformContext();
     124    cairo_t* cr = context->platformContext()->cr();
    124125    cairo_save(cr);
    125126    setSourceRGBAFromColor(cr, m_color);
     
    199200        max(bottomLeftRadius.height(), bottomRightRadius.height());
    200201
    201     cairo_t* cr = context->platformContext();
     202    cairo_t* cr = context->platformContext()->cr();
    202203
    203204    // drawShadowedRect still does not work with rotations.
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp

    r74947 r82496  
    3737#include "Gradient.h"
    3838#include "GraphicsContext.h"
     39#include "PlatformContextCairo.h"
    3940#include "ImageBuffer.h"
    4041#include "Pattern.h"
     
    6566}
    6667
    67 static void drawGlyphsShadow(GraphicsContext* graphicsContext, cairo_t* context, const FloatPoint& point, const SimpleFontData* font, GlyphBufferGlyph* glyphs, int numGlyphs)
     68static void drawGlyphsShadow(GraphicsContext* graphicsContext, const FloatPoint& point, const SimpleFontData* font, GlyphBufferGlyph* glyphs, int numGlyphs)
    6869{
    6970    ContextShadow* shadow = graphicsContext->contextShadow();
     
    7576    if (!shadow->mustUseContextShadow(graphicsContext)) {
    7677        // Optimize non-blurry shadows, by just drawing text without the ContextShadow.
     78        cairo_t* context = graphicsContext->platformContext()->cr();
    7779        cairo_save(context);
    7880        cairo_translate(context, shadow->m_offset.width(), shadow->m_offset.height());
     
    107109    }
    108110
    109     cairo_t* cr = context->platformContext();
    110     drawGlyphsShadow(context, cr, point, font, glyphs, numGlyphs);
     111    PlatformContextCairo* platformContext = context->platformContext();
     112    drawGlyphsShadow(context, point, font, glyphs, numGlyphs);
    111113
     114    cairo_t* cr = platformContext->cr();
    112115    cairo_save(cr);
    113116    prepareContextForGlyphDrawing(cr, font, point);
  • trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp

    r60760 r82496  
    3030#include "CSSParser.h"
    3131#include "GraphicsContext.h"
     32#include "PlatformContextCairo.h"
    3233#include <cairo.h>
    3334
     
    8889void Gradient::fill(GraphicsContext* context, const FloatRect& rect)
    8990{
    90     cairo_t* cr = context->platformContext();
     91    cairo_t* cr = context->platformContext()->cr();
    9192
    9293    context->save();
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r79592 r82496  
    4848#include "Path.h"
    4949#include "Pattern.h"
     50#include "PlatformContextCairo.h"
    5051#include "RefPtrCairo.h"
    5152#include "SimpleFontData.h"
     
    149150
    150151    // Calculate the extents of the rendered solid paths.
    151     cairo_t* cairoContext = context->platformContext();
     152    cairo_t* cairoContext = context->platformContext()->cr();
    152153    OwnPtr<cairo_path_t> path(cairo_copy_path(cairoContext));
    153154
     
    200201}
    201202
    202 void GraphicsContext::platformInit(PlatformGraphicsContext* cr)
    203 {
    204     m_data = new GraphicsContextPlatformPrivate;
    205     m_data->cr = cairo_reference(cr);
    206     m_data->syncContext(cr);
    207     setPaintingDisabled(!cr);
     203GraphicsContext::GraphicsContext(cairo_t* cr)
     204{
     205    m_data = new GraphicsContextPlatformPrivate(new PlatformContextCairo(cr));
     206}
     207
     208void GraphicsContext::platformInit(PlatformContextCairo* platformContext)
     209{
     210    m_data = new GraphicsContextPlatformPrivate(platformContext);
     211    if (platformContext)
     212        m_data->syncContext(platformContext->cr());
     213    else
     214        setPaintingDisabled(true);
    208215}
    209216
     
    215222AffineTransform GraphicsContext::getCTM() const
    216223{
    217     cairo_t* cr = platformContext();
     224    cairo_t* cr = platformContext()->cr();
    218225    cairo_matrix_t m;
    219226    cairo_get_matrix(cr, &m);
     
    221228}
    222229
    223 cairo_t* GraphicsContext::platformContext() const
    224 {
    225     return m_data->cr;
     230PlatformContextCairo* GraphicsContext::platformContext() const
     231{
     232    return m_data->platformContext;
    226233}
    227234
    228235void GraphicsContext::savePlatformState()
    229236{
    230     cairo_save(m_data->cr);
     237    cairo_save(platformContext()->cr());
    231238    m_data->save();
    232239    m_data->shadowStack.append(m_data->shadow);
     
    236243void GraphicsContext::restorePlatformState()
    237244{
    238     cairo_t* cr = m_data->cr;
     245    cairo_t* cr = platformContext()->cr();
     246
    239247    const ImageMaskInformation& maskInformation = m_data->maskImageStack.last();
    240248    if (maskInformation.isValid()) {
     
    252260    }
    253261
    254     cairo_restore(m_data->cr);
     262    cairo_restore(cr);
    255263    m_data->restore();
    256264}
     
    262270        return;
    263271
    264     cairo_t* cr = m_data->cr;
     272    cairo_t* cr = platformContext()->cr();
    265273    cairo_save(cr);
    266274
     
    290298        return;
    291299
    292     cairo_t* cr = m_data->cr;
     300    cairo_t* cr = platformContext()->cr();
    293301    cairo_save(cr);
    294302
     
    377385        return;
    378386
    379     cairo_t* cr = m_data->cr;
     387    cairo_t* cr = platformContext()->cr();
    380388    cairo_save(cr);
    381389    float yRadius = .5 * rect.height();
     
    416424    float falen =  fa + angleSpan;
    417425
    418     cairo_t* cr = m_data->cr;
     426    cairo_t* cr = platformContext()->cr();
    419427    cairo_save(cr);
    420428
     
    493501        return;
    494502
    495     cairo_t* cr = m_data->cr;
     503    cairo_t* cr = platformContext()->cr();
    496504
    497505    cairo_save(cr);
     
    523531        return;
    524532
    525     cairo_t* cr = m_data->cr;
     533    cairo_t* cr = platformContext()->cr();
    526534
    527535    cairo_new_path(cr);
     
    543551        return;
    544552
    545     cairo_t* cr = m_data->cr;
     553    cairo_t* cr = platformContext()->cr();
    546554    setPathOnCairoContext(cr, path.platformPath()->context());
    547555    fillCurrentCairoPath(this, cr);
     
    553561        return;
    554562
    555     cairo_t* cr = m_data->cr;
     563    cairo_t* cr = platformContext()->cr();
    556564    setPathOnCairoContext(cr, path.platformPath()->context());
    557565    strokeCurrentCairoPath(this, cr);
     
    563571        return;
    564572
    565     cairo_t* cr = m_data->cr;
     573    cairo_t* cr = platformContext()->cr();
    566574    cairo_save(cr);
    567575    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
     
    579587
    580588    if (color.alpha())
    581         fillRectSourceOver(m_data->cr, rect, color);
     589        fillRectSourceOver(platformContext()->cr(), rect, color);
    582590}
    583591
     
    587595        return;
    588596
    589     cairo_t* cr = m_data->cr;
     597    cairo_t* cr = platformContext()->cr();
    590598    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
    591599    cairo_fill_rule_t savedFillRule = cairo_get_fill_rule(cr);
     
    601609        return;
    602610
    603     cairo_t* cr = m_data->cr;
     611    cairo_t* cr = platformContext()->cr();
    604612    setPathOnCairoContext(cr, path.platformPath()->context());
    605613    cairo_set_fill_rule(cr, clipRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
     
    639647    adjustFocusRingLineWidth(width);
    640648
    641     cairo_t* cr = m_data->cr;
     649    cairo_t* cr = platformContext()->cr();
    642650    cairo_save(cr);
    643651    appendWebCorePathToCairoContext(cr, path);
     
    656664    unsigned rectCount = rects.size();
    657665
    658     cairo_t* cr = m_data->cr;
     666    cairo_t* cr = platformContext()->cr();
    659667    cairo_save(cr);
    660668    cairo_push_group(cr);
     
    733741        return;
    734742
    735     cairo_t* cr = m_data->cr;
     743    cairo_t* cr = platformContext()->cr();
    736744    cairo_save(cr);
    737745
     
    763771    double x = frect.x();
    764772    double y = frect.y();
    765     cairo_t* cr = m_data->cr;
     773    cairo_t* cr = platformContext()->cr();
    766774    cairo_user_to_device(cr, &x, &y);
    767775    x = round(x);
     
    800808        return;
    801809
    802     cairo_t* cr = m_data->cr;
     810    cairo_t* cr = platformContext()->cr();
    803811    cairo_translate(cr, x, y);
    804812    m_data->translate(x, y);
     
    822830        return;
    823831
    824     cairo_set_line_width(m_data->cr, strokeThickness);
     832    cairo_set_line_width(platformContext()->cr(), strokeThickness);
    825833}
    826834
     
    836844    case NoStroke:
    837845        // FIXME: is it the right way to emulate NoStroke?
    838         cairo_set_line_width(m_data->cr, 0);
     846        cairo_set_line_width(platformContext()->cr(), 0);
    839847        break;
    840848    case SolidStroke:
    841         cairo_set_dash(m_data->cr, 0, 0, 0);
     849        cairo_set_dash(platformContext()->cr(), 0, 0, 0);
    842850        break;
    843851    case DottedStroke:
    844         cairo_set_dash(m_data->cr, dotPattern, 2, 0);
     852        cairo_set_dash(platformContext()->cr(), dotPattern, 2, 0);
    845853        break;
    846854    case DashedStroke:
    847         cairo_set_dash(m_data->cr, dashPattern, 2, 0);
     855        cairo_set_dash(platformContext()->cr(), dashPattern, 2, 0);
    848856        break;
    849857    }
     
    860868        return;
    861869
    862     cairo_t* cr = m_data->cr;
     870    cairo_t* cr = platformContext()->cr();
    863871    const cairo_matrix_t matrix = cairo_matrix_t(transform);
    864872    cairo_transform(cr, &matrix);
     
    871879        return;
    872880
    873     cairo_t* cr = m_data->cr;
     881    cairo_t* cr = platformContext()->cr();
    874882    const cairo_matrix_t matrix = cairo_matrix_t(transform);
    875883    cairo_set_matrix(cr, &matrix);
     
    882890        return;
    883891
    884     cairo_t* cr = m_data->cr;
     892    cairo_t* cr = platformContext()->cr();
    885893    clip(rect);
    886894
     
    929937        return;
    930938
    931     cairo_t* cr = m_data->cr;
     939    cairo_t* cr = platformContext()->cr();
    932940    cairo_push_group(cr);
    933941    m_data->layers.append(opacity);
     
    940948        return;
    941949
    942     cairo_t* cr = m_data->cr;
     950    cairo_t* cr = platformContext()->cr();
    943951
    944952    cairo_pop_group_to_source(cr);
     
    953961        return;
    954962
    955     cairo_t* cr = m_data->cr;
     963    cairo_t* cr = platformContext()->cr();
    956964
    957965    cairo_save(cr);
     
    967975        return;
    968976
    969     cairo_t* cr = m_data->cr;
     977    cairo_t* cr = platformContext()->cr();
    970978    cairo_save(cr);
    971979    cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
     
    9921000        break;
    9931001    }
    994     cairo_set_line_cap(m_data->cr, cairoCap);
     1002    cairo_set_line_cap(platformContext()->cr(), cairoCap);
    9951003}
    9961004
    9971005void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset)
    9981006{
    999     cairo_set_dash(m_data->cr, dashes.data(), dashes.size(), dashOffset);
     1007    cairo_set_dash(platformContext()->cr(), dashes.data(), dashes.size(), dashOffset);
    10001008}
    10011009
     
    10171025        break;
    10181026    }
    1019     cairo_set_line_join(m_data->cr, cairoJoin);
     1027    cairo_set_line_join(platformContext()->cr(), cairoJoin);
    10201028}
    10211029
     
    10251033        return;
    10261034
    1027     cairo_set_miter_limit(m_data->cr, miter);
     1035    cairo_set_miter_limit(platformContext()->cr(), miter);
    10281036}
    10291037
     
    10431051        return;
    10441052
    1045     cairo_set_operator(m_data->cr, toCairoOperator(op));
     1053    cairo_set_operator(platformContext()->cr(), toCairoOperator(op));
    10461054}
    10471055
     
    10511059        return;
    10521060
    1053     cairo_t* cr = m_data->cr;
     1061    cairo_t* cr = platformContext()->cr();
    10541062    OwnPtr<cairo_path_t> p(cairo_copy_path(path.platformPath()->context()));
    10551063    cairo_append_path(cr, p.get());
     
    10711079        return;
    10721080
    1073     cairo_t* cr = m_data->cr;
     1081    cairo_t* cr = platformContext()->cr();
    10741082    double x1, y1, x2, y2;
    10751083    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
     
    10881096        return;
    10891097
    1090     cairo_rotate(m_data->cr, radians);
     1098    cairo_rotate(platformContext()->cr(), radians);
    10911099    m_data->rotate(radians);
    10921100}
     
    10971105        return;
    10981106
    1099     cairo_scale(m_data->cr, size.width(), size.height());
     1107    cairo_scale(platformContext()->cr(), size.width(), size.height());
    11001108    m_data->scale(size);
    11011109}
     
    11061114        return;
    11071115
    1108     cairo_t* cr = m_data->cr;
     1116    cairo_t* cr = platformContext()->cr();
    11091117    double x1, y1, x2, y2;
    11101118    cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
     
    11331141        m_data->shadow.drawRectShadow(this, r, topLeft, topRight, bottomLeft, bottomRight);
    11341142
    1135     cairo_t* cr = m_data->cr;
     1143    cairo_t* cr = platformContext()->cr();
    11361144    cairo_save(cr);
    11371145    Path path;
     
    11711179    // enables standard 'grayscale' antialiasing); false to explicitly disable
    11721180    // antialiasing. This is the same strategy as used in drawConvexPolygon().
    1173     cairo_set_antialias(m_data->cr, enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
     1181    cairo_set_antialias(platformContext()->cr(), enable ? CAIRO_ANTIALIAS_DEFAULT : CAIRO_ANTIALIAS_NONE);
    11741182}
    11751183
     
    11971205    // is now, but they are isolated in another group. To make this work, we're
    11981206    // going to blit the current surface contents onto the new group once we push it.
    1199     cairo_t* cr = m_data->cr;
     1207    cairo_t* cr = platformContext()->cr();
    12001208    cairo_surface_t* currentTarget = cairo_get_target(cr);
    12011209    cairo_surface_flush(currentTarget);
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h

    r79592 r82496  
    3232
    3333#include "ContextShadow.h"
     34#include "PlatformContextCairo.h"
    3435#include "RefPtrCairo.h"
    3536#include <cairo.h>
     
    6869class GraphicsContextPlatformPrivate {
    6970public:
    70     GraphicsContextPlatformPrivate()
    71         : cr(0)
     71    GraphicsContextPlatformPrivate(PlatformContextCairo* newPlatformContext)
     72        : platformContext(newPlatformContext)
    7273#if PLATFORM(GTK)
    7374        , expose(0)
     
    8384    ~GraphicsContextPlatformPrivate()
    8485    {
    85         cairo_destroy(cr);
    8686    }
    8787
     
    100100    void beginTransparencyLayer() { m_transparencyCount++; }
    101101    void endTransparencyLayer() { m_transparencyCount--; }
    102     void syncContext(PlatformGraphicsContext* cr);
     102    void syncContext(cairo_t* cr);
    103103#else
    104104    // On everything else, we do nothing.
     
    115115    void beginTransparencyLayer() {}
    116116    void endTransparencyLayer() {}
    117     void syncContext(PlatformGraphicsContext* cr) {}
     117    void syncContext(cairo_t* cr) {}
    118118#endif
    119119
    120     cairo_t* cr;
     120    PlatformContextCairo* platformContext;
    121121    Vector<float> layers;
    122 
    123122    ContextShadow shadow;
    124123    Vector<ContextShadow> shadowStack;
     
    134133};
    135134
     135// This is a specialized private section for the Cairo GraphicsContext, which knows how
     136// to clean up the heap allocated PlatformContextCairo that we must use for the top-level
     137// GraphicsContext.
     138class GraphicsContextPlatformPrivateToplevel : public GraphicsContextPlatformPrivate {
     139public:
     140    GraphicsContextPlatformPrivateToplevel(PlatformContextCairo* platformContext)
     141        : GraphicsContextPlatformPrivate(platformContext)
     142    {
     143    }
     144
     145    ~GraphicsContextPlatformPrivateToplevel()
     146    {
     147        delete platformContext;
     148    }
     149};
     150
     151
    136152} // namespace WebCore
    137153
  • trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r79592 r82496  
    3838#include "NotImplemented.h"
    3939#include "Pattern.h"
     40#include "PlatformContextCairo.h"
    4041#include "PlatformString.h"
     42#include "RefPtrCairo.h"
    4143#include <cairo.h>
    4244#include <wtf/Vector.h>
     
    6769ImageBufferData::ImageBufferData(const IntSize& size)
    6870    : m_surface(0)
     71    , m_platformContext(0)
    6972{
    7073}
     
    8184        return;  // create will notice we didn't set m_initialized and fail.
    8285
    83     cairo_t* cr = cairo_create(m_data.m_surface);
    84     m_context.set(new GraphicsContext(cr));
    85     cairo_destroy(cr);  // The context is now owned by the GraphicsContext.
     86    RefPtr<cairo_t> cr = adoptRef(cairo_create(m_data.m_surface));
     87    m_data.m_platformContext.setCr(cr.get());
     88    m_context.set(new GraphicsContext(&m_data.m_platformContext));
    8689    success = true;
    8790}
     
    302305String ImageBuffer::toDataURL(const String& mimeType, const double*) const
    303306{
    304     cairo_surface_t* image = cairo_get_target(context()->platformContext());
     307    cairo_surface_t* image = cairo_get_target(context()->platformContext()->cr());
    305308    if (!image)
    306309        return "data:,";
  • trunk/Source/WebCore/platform/graphics/cairo/ImageBufferData.h

    r37948 r82496  
    2727#define ImageBufferData_h
    2828
    29 #include "cairo.h"
     29#include "PlatformContextCairo.h"
     30
     31typedef struct _cairo_surface cairo_surface_t;
    3032
    3133namespace WebCore {
     
    3840
    3941    cairo_surface_t* m_surface;
     42    PlatformContextCairo m_platformContext;
    4043};
    4144
  • trunk/Source/WebCore/platform/graphics/cairo/ImageCairo.cpp

    r74947 r82496  
    3737#include "FloatRect.h"
    3838#include "GraphicsContext.h"
     39#include "PlatformContextCairo.h"
    3940#include "ImageBuffer.h"
    4041#include "ImageObserver.h"
     
    115116    IntSize selfSize = size();
    116117
    117     cairo_t* cr = context->platformContext();
     118    cairo_t* cr = context->platformContext()->cr();
    118119    context->save();
    119120
     
    170171        return;
    171172
    172     cairo_t* cr = context->platformContext();
    173 
     173    cairo_t* cr = context->platformContext()->cr();
    174174    drawPatternToCairoContext(cr, image, size(), tileRect, patternTransform, phase, toCairoOperator(op), destRect);
    175175
  • trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp

    r82495 r82496  
    11/*
    2  * Copyright (C) 2008 Google Inc. All rights reserved.
     2 * Copyright (C) 2011 Igalia S.L.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    2424 */
    2525
    26 #ifndef ImageBufferData_h
    27 #define ImageBufferData_h
     26#include "config.h"
     27#include "PlatformContextCairo.h"
    2828
    29 #include "cairo.h"
     29#include <cairo.h>
    3030
    3131namespace WebCore {
    3232
    33 class IntSize;
     33PlatformContextCairo::PlatformContextCairo(cairo_t* cr)
     34    : m_cr(cr)
     35{
     36}
    3437
    35 class ImageBufferData {
    36 public:
    37     ImageBufferData(const IntSize&);
    38 
    39     cairo_surface_t* m_surface;
    40 };
    41 
    42 }  // namespace WebCore
    43 
    44 #endif  // ImageBufferData_h
     38} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h

    r82495 r82496  
    11/*
    2  * Copyright (C) 2008 Google Inc. All rights reserved.
     2 * Copyright (C) 2011 Igalia S.L.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    2424 */
    2525
    26 #ifndef ImageBufferData_h
    27 #define ImageBufferData_h
     26#ifndef PlatformContextCairo_h
     27#define PlatformContextCairo_h
    2828
    29 #include "cairo.h"
     29#include "ContextShadow.h"
     30#include "RefPtrCairo.h"
    3031
    3132namespace WebCore {
    3233
    33 class IntSize;
     34// Much like PlatformContextSkia in the Skia port, this class holds information that
     35// would normally be private to GraphicsContext, except that we want to allow access
     36// to it in Font and Image code. This allows us to separate the concerns of Cairo-specific
     37// code from the platform-independent GraphicsContext.
    3438
    35 class ImageBufferData {
     39class PlatformContextCairo {
     40    WTF_MAKE_NONCOPYABLE(PlatformContextCairo);
    3641public:
    37     ImageBufferData(const IntSize&);
     42    PlatformContextCairo(cairo_t*);
     43    cairo_t* cr() { return m_cr.get(); }
     44    void setCr(cairo_t* cr) { m_cr = cr; }
    3845
    39     cairo_surface_t* m_surface;
     46private:
     47    RefPtr<cairo_t> m_cr;
    4048};
    4149
    42 }  // namespace WebCore
     50} // namespace WebCore
    4351
    44 #endif  // ImageBufferData_h
     52#endif // PlatformContextCairo_h
  • trunk/Source/WebCore/platform/graphics/gtk/FontGtk.cpp

    r80744 r82496  
    3636#include "CairoUtilities.h"
    3737#include "ContextShadow.h"
     38#include "PlatformContextCairo.h"
    3839#include "GraphicsContext.h"
    3940#include "NotImplemented.h"
     
    221222}
    222223
    223 static void drawGlyphsShadow(GraphicsContext* graphicsContext, cairo_t* context, const FloatPoint& point, PangoLayoutLine* layoutLine, PangoRegionType renderRegion)
     224static void drawGlyphsShadow(GraphicsContext* graphicsContext, const FloatPoint& point, PangoLayoutLine* layoutLine, PangoRegionType renderRegion)
    224225{
    225226    ContextShadow* shadow = graphicsContext->contextShadow();
     
    233234    // Optimize non-blurry shadows, by just drawing text without the ContextShadow.
    234235    if (!shadow->mustUseContextShadow(graphicsContext)) {
     236        cairo_t* context = graphicsContext->platformContext()->cr();
    235237        cairo_save(context);
    236238        cairo_translate(context, totalOffset.x(), totalOffset.y());
     
    256258        // drawn. Since ContextShadow expects a consistent transform, we have to undo the
    257259        // translation before calling endShadowLayer as well.
     260        cairo_t* context = graphicsContext->platformContext()->cr();
    258261        cairo_save(context);
    259262        cairo_translate(context, totalOffset.x(), totalOffset.y());
     
    276279#endif
    277280
    278     cairo_t* cr = context->platformContext();
     281    cairo_t* cr = context->platformContext()->cr();
    279282    PangoLayout* layout = pango_cairo_create_layout(cr);
    280283    setPangoAttributes(this, run, layout);
     
    295298    partialRegion = gdk_pango_layout_line_get_clip_region(layoutLine, 0, 0, ranges, 1);
    296299
    297     drawGlyphsShadow(context, cr, point, layoutLine, partialRegion);
     300    drawGlyphsShadow(context, point, layoutLine, partialRegion);
    298301
    299302    cairo_save(cr);
  • trunk/Source/WebCore/platform/graphics/gtk/IconGtk.cpp

    r56825 r82496  
    3434#include "MIMETypeRegistry.h"
    3535#include "PassRefPtr.h"
     36#include "PlatformContextCairo.h"
     37#include <gtk/gtk.h>
    3638#include <wtf/text/CString.h>
    37 
    38 #include <gtk/gtk.h>
    3939
    4040namespace WebCore {
     
    118118
    119119    // TODO: Scale/clip the image if necessary.
    120     cairo_t* cr = context->platformContext();
     120    cairo_t* cr = context->platformContext()->cr();
    121121    cairo_save(cr);
    122122    gdk_cairo_set_source_pixbuf(cr, m_icon, rect.x(), rect.y());
  • trunk/Source/WebCore/platform/graphics/win/GraphicsContextCairoWin.cpp

    r73728 r82496  
    7373void GraphicsContext::platformInit(HDC dc, bool hasAlpha)
    7474{
    75     m_data = new GraphicsContextPlatformPrivate;
     75    cairo_t* cr = 0;
     76    if (dc)
     77        cr = createCairoContextWithHDC(dc, hasAlpha);
     78    else
     79        setPaintingDisabled(true);
    7680
    77     if (dc) {
    78         m_data->cr = createCairoContextWithHDC(dc, hasAlpha);
    79         m_data->m_hdc = dc;
    80     } else {
    81         setPaintingDisabled(true);
    82         m_data->cr = 0;
    83         m_data->m_hdc = 0;
    84     }
    85 
    86     if (m_data->cr) {
     81    m_data = new GraphicsContextPlatformPrivateTopLevel(new PlatformContextCairo(cr));
     82    m_data->m_hdc = dc;
     83    if (platformContext()->cr()) {
    8784        // Make sure the context starts in sync with our state.
    8885        setPlatformFillColor(fillColor(), fillColorSpace());
     
    132129    // so that when we set the srcImage as the surface it will draw
    133130    // right-side-up.
    134     cairo_save(m_data->cr);
    135     cairo_translate(m_data->cr, dstRect.x(), dstRect.height() + dstRect.y());
    136     cairo_scale(m_data->cr, 1.0, -1.0);
    137     cairo_set_source_surface(m_data->cr, image, 0, 0);
     131    cairo_t* cr = platformContext()->cr();
     132    cairo_save(cr);
     133    cairo_translate(cr, dstRect.x(), dstRect.height() + dstRect.y());
     134    cairo_scale(cr, 1, -1);
     135    cairo_set_source_surface(cr, image, 0, 0);
    138136
    139137    if (m_data->layers.size())
    140         cairo_paint_with_alpha(m_data->cr, m_data->layers.last());
     138        cairo_paint_with_alpha(cr, m_data->layers.last());
    141139    else
    142         cairo_paint(m_data->cr);
     140        cairo_paint(cr);
    143141     
    144142    // Delete all our junk.
     
    146144    ::DeleteDC(hdc);
    147145    ::DeleteObject(bitmap);
    148     cairo_restore(m_data->cr);
     146    cairo_restore(cr);
    149147}
    150148
    151 void GraphicsContextPlatformPrivate::syncContext(PlatformGraphicsContext* cr)
     149void GraphicsContextPlatformPrivate::syncContext(cairo_t* cr)
    152150{
    153151    if (!cr)
  • trunk/Source/WebCore/platform/gtk/RenderThemeGtk.cpp

    r77726 r82496  
    3535#include "MediaControlElements.h"
    3636#include "PaintInfo.h"
     37#include "PlatformContextCairo.h"
    3738#include "RenderBox.h"
    3839#include "RenderObject.h"
     
    235236    }
    236237
    237     cairo_t* cr = context->platformContext();
     238    cairo_t* cr = context->platformContext()->cr();
    238239    cairo_save(cr);
    239240    gdk_cairo_set_source_pixbuf(cr, icon, iconRect.x(), iconRect.y());
  • trunk/Source/WebCore/platform/gtk/WidgetRenderingContext.cpp

    r77993 r82496  
    3434#include "GraphicsContext.h"
    3535#include "GtkVersioning.h"
     36#include "PlatformContextCairo.h"
    3637#include "RefPtrCairo.h"
    3738#include "RenderThemeGtk.h"
     
    129130
    130131    // FIXME: It's unclear if it is necessary to preserve the current source here.
    131     cairo_t* cairoContext = m_graphicsContext->platformContext();
     132    cairo_t* cairoContext = m_graphicsContext->platformContext()->cr();
    132133    RefPtr<cairo_pattern_t> previousSource(cairo_get_source(cairoContext));
    133134
  • trunk/Source/WebCore/plugins/gtk/PluginViewGtk.cpp

    r80430 r82496  
    4949#include "MouseEvent.h"
    5050#include "Page.h"
     51#include "PlatformContextCairo.h"
    5152#include "PlatformKeyboardEvent.h"
    5253#include "PlatformMouseEvent.h"
     
    218219
    219220            // This Would not work without double buffering, but we always use it.
    220             cairo_set_source_surface(cr.get(), cairo_get_group_target(context->platformContext()),
     221            cairo_set_source_surface(cr.get(), cairo_get_group_target(context->platformContext()->cr()),
    221222                                     -m_windowRect.x(), -m_windowRect.y());
    222223            cairo_set_operator(cr.get(), CAIRO_OPERATOR_SOURCE);
     
    245246        XSync(m_pluginDisplay, false); // sync changes by plugin
    246247
    247     cairo_t* cr = context->platformContext();
     248    cairo_t* cr = context->platformContext()->cr();
    248249    cairo_save(cr);
    249250
  • trunk/Source/WebCore/plugins/win/PluginViewWin.cpp

    r79988 r82496  
    8484
    8585#if PLATFORM(CAIRO)
     86#include "PlatformContextCairo.h"
    8687#include <cairo-win32.h>
    8788#endif
     
    573574    // plugin region will be overwritten with any clear regions specified in the
    574575    // cairo-controlled portions of the rendering.
    575     PlatformGraphicsContext* ctx = context->platformContext();
    576     cairo_show_page(ctx);
     576    cairo_show_page(context->platformContext()->cr());
    577577#endif
    578578
  • trunk/Source/WebKit/gtk/ChangeLog

    r82219 r82496  
     12011-03-30  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        [Cairo] Better separate the concerns of GraphicsContextCairo
     6        https://bugs.webkit.org/show_bug.cgi?id=55150
     7
     8        Add a PlatformContextCairo which right now stores the cairo_t* for a
     9        GraphicsContextCairo. Later patches will move logic for tracking ContextShadow
     10        and image masking layers into this PlatformContextCairo class.
     11
     12        * webkit/webkitwebframe.cpp:
     13        (draw_page_callback):
     14        * webkit/webkitwebview.cpp:
     15        (webkit_web_view_expose_event):
     16        (webkit_web_view_draw):
     17
    1182011-03-29  Philippe Normand  <pnormand@igalia.com>
    219
  • trunk/Source/WebKit/gtk/webkit/webkitwebframe.cpp

    r77714 r82496  
    4545#include "JSDOMWindow.h"
    4646#include "JSElement.h"
     47#include "PlatformContextCairo.h"
    4748#include "PrintContext.h"
    4849#include "RenderListItem.h"
     
    766767}
    767768
    768 static void draw_page_callback(GtkPrintOperation* op, GtkPrintContext* context, gint page_nr, gpointer user_data)
    769 {
    770     PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data);
    771 
    772     if (page_nr >= static_cast<gint>(printContext->pageCount()))
     769static void draw_page_callback(GtkPrintOperation*, GtkPrintContext* gtkPrintContext, gint pageNumber, PrintContext* corePrintContext)
     770{
     771    if (pageNumber >= static_cast<gint>(corePrintContext->pageCount()))
    773772        return;
    774773
    775     cairo_t* cr = gtk_print_context_get_cairo_context(context);
    776     GraphicsContext ctx(cr);
    777     float width = gtk_print_context_get_width(context);
    778     printContext->spoolPage(ctx, page_nr, width);
     774    cairo_t* cr = gtk_print_context_get_cairo_context(gtkPrintContext);
     775    float pageWidth = gtk_print_context_get_width(gtkPrintContext);
     776
     777    PlatformContextCairo platformContext(cr);
     778    GraphicsContext graphicsContext(&platformContext);
     779    corePrintContext->spoolPage(graphicsContext, pageNumber, pageWidth);
    779780}
    780781
  • trunk/Source/WebKit/gtk/webkit/webkitwebview.cpp

    r81600 r82496  
    711711
    712712        RefPtr<cairo_t> cr = adoptRef(gdk_cairo_create(event->window));
    713         GraphicsContext ctx(cr.get());
    714         ctx.setGdkExposeEvent(event);
     713        GraphicsContext gc(cr.get());
     714        gc.setGdkExposeEvent(event);
    715715
    716716        int rectCount;
     
    721721            paintRects.append(IntRect(rects.get()[i]));
    722722
    723         paintWebView(frame, priv->transparent, ctx, static_cast<IntRect>(event->area), paintRects);
     723        paintWebView(frame, priv->transparent, gc, static_cast<IntRect>(event->area), paintRects);
    724724    }
    725725
     
    738738    Frame* frame = core(webView)->mainFrame();
    739739    if (frame->contentRenderer() && frame->view()) {
    740         GraphicsContext ctx(cr);
     740        GraphicsContext gc(cr);
    741741        IntRect rect = clipRect;
    742742        cairo_rectangle_list_t* rectList = cairo_copy_clip_rectangle_list(cr);
     
    749749                rects.append(enclosingIntRect(FloatRect(rectList->rectangles[i])));
    750750        }
    751         paintWebView(frame, priv->transparent, ctx, rect, rects);
     751        paintWebView(frame, priv->transparent, gc, rect, rects);
    752752
    753753        cairo_rectangle_list_destroy(rectList);
  • trunk/Source/WebKit/win/ChangeLog

    r82493 r82496  
     12011-03-30  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        [Cairo] Better separate the concerns of GraphicsContextCairo
     6        https://bugs.webkit.org/show_bug.cgi?id=55150
     7
     8        * WebFrame.cpp:
     9        (hdcFromContext): Modify this method to take PlatformContextCairo
     10        instead of a cairo_t.
     11        (WebFrame::spoolPage): Update to reflect new platform context.
     12        (WebFrame::spoolPages): Ditto.
     13        * WebFrame.h: Ditto.
     14
    1152011-03-30  Steve Falkenburg  <sfalken@apple.com>
    216
  • trunk/Source/WebKit/win/WebFrame.cpp

    r82294 r82496  
    108108#include <CoreGraphics/CoreGraphics.h>
    109109#elif PLATFORM(CAIRO)
     110#include "PlatformContextCairo.h"
    110111#include <cairo-win32.h>
    111112#endif
     
    21872188static HDC hdcFromContext(PlatformGraphicsContext* pctx)
    21882189{
    2189     cairo_surface_t* surface = cairo_get_target(pctx);
    2190     return cairo_win32_surface_get_dc(surface);
     2190    return cairo_win32_surface_get_dc(cairo_get_target(pctx->cr()));
    21912191}
    21922192
     
    22432243    GetWorldTransform(hdc, &original);
    22442244   
     2245    cairo_t* cr = pctx->cr();
    22452246    bool preview = (hdc != printDC);
    22462247    if (preview) {
     
    22492250        // drawing completes so that we can scale our GDI-based header/footer calls. This is a
    22502251        // workaround for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
    2251         scaled = buildXFORMFromCairo(hdc, pctx);
     2252        scaled = buildXFORMFromCairo(hdc, cr);
    22522253    }
    22532254
     
    22592260    // We cannot scale the display HDC because the print surface also scales fonts,
    22602261    // resulting in invalid printing (and print preview)
    2261     cairo_scale(pctx, scale, scale);
    2262     cairo_translate(pctx, cairoMarginRect.x(), cairoMarginRect.y() + headerHeight);
     2262    cairo_scale(cr, scale, scale);
     2263    cairo_translate(cr, cairoMarginRect.x(), cairoMarginRect.y() + headerHeight);
    22632264
    22642265    // Modify Cairo (only) to account for page position.
    2265     cairo_translate(pctx, -pageRect.x(), -pageRect.y());
     2266    cairo_translate(cr, -pageRect.x(), -pageRect.y());
    22662267    coreFrame->view()->paintContents(spoolCtx, pageRect);
    2267     cairo_translate(pctx, pageRect.x(), pageRect.y());
     2268    cairo_translate(cr, pageRect.x(), pageRect.y());
    22682269   
    22692270    if (preview) {
     
    22862287    SetWorldTransform(hdc, &original);
    22872288
    2288     cairo_show_page(pctx);
    2289     ASSERT(!cairo_status(pctx));
     2289    cairo_show_page(cr);
     2290    ASSERT(!cairo_status(cr));
    22902291    spoolCtx->restore();
    22912292}
     
    23392340        printSurface = cairo_win32_printing_surface_create(targetDC); // metafile
    23402341   
    2341     PlatformGraphicsContext* pctx = (PlatformGraphicsContext*)cairo_create(printSurface);
    2342     if (!pctx) {
     2342    cairo_t* cr = cairo_create(printSurface);
     2343    if (!cr) {
    23432344        cairo_surface_destroy(printSurface);   
    23442345        return E_FAIL;
    23452346    }
    2346    
     2347
     2348    PlatformContextCairo platformContext(cr);
     2349    PlatformGraphicsContext* pctx = &platformContext;
     2350    cairo_destroy(cr);
     2351
    23472352    if (ctx) {
    23482353        // If this is a preview, the Windows HDC was sent with scaling information.
    23492354        // Retrieve it and reset it so that it draws properly.  This is a workaround
    23502355        // for a bug in Cairo (see https://bugs.freedesktop.org/show_bug.cgi?id=28161)
    2351         setCairoTransformToPreviewHDC(pctx, targetDC);
     2356        setCairoTransformToPreviewHDC(cr, targetDC);
    23522357    }
    23532358   
     
    23932398
    23942399#if PLATFORM(CAIRO)
    2395     cairo_destroy(pctx);
    23962400    cairo_surface_finish(printSurface);
    23972401    ASSERT(!cairo_surface_status(printSurface));
  • trunk/Source/WebKit/win/WebFrame.h

    r82294 r82496  
    6363typedef struct CGContext PlatformGraphicsContext;
    6464#elif PLATFORM(CAIRO)
    65 typedef struct _cairo PlatformGraphicsContext;
     65namespace WebCore {
     66class PlatformContextCairo;
     67}
     68typedef class WebCore::PlatformContextCairo PlatformGraphicsContext;
    6669#endif
    6770
Note: See TracChangeset for help on using the changeset viewer.