Changeset 83044 in webkit


Ignore:
Timestamp:
Apr 6, 2011 7:16:03 AM (13 years ago)
Author:
Martin Robinson
Message:

2011-04-06 Martin Robinson <mrobinson@igalia.com>

Reviewed by Xan Lopez.

[Cairo] Hide the details of image masking in PlatformContextCairo
https://bugs.webkit.org/show_bug.cgi?id=57878

No new tests. This is just a refactor.

  • platform/graphics/GraphicsContext.h:
  • platform/graphics/cairo/GraphicsContextCairo.cpp: (WebCore::GraphicsContext::savePlatformState): Call into PlatformContextCairo now to do the actual cairo_save. Remove information about image masking. (WebCore::GraphicsContext::restorePlatformState): Call into PlatformContextCairo now to do the actual cairo_restore. Remove information about image masking.
  • platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h:
  • platform/graphics/cairo/ImageBufferCairo.cpp: (WebCore::ImageBuffer::clip): Use PlatformContextCairo here now.
  • platform/graphics/cairo/PlatformContextCairo.cpp: (WebCore::PlatformContextCairo::restore): Added. (WebCore::PlatformContextCairo::save): Added. (WebCore::PlatformContextCairo::pushImageMask): Added.
  • platform/graphics/cairo/PlatformContextCairo.h: (WebCore::ImageMaskInformation::update): Moved from GraphicsContextPlatformPrivateCairo.h. (WebCore::ImageMaskInformation::isValid): Ditto. (WebCore::ImageMaskInformation::maskSurface): Ditto. (WebCore::ImageMaskInformation::maskRect): Ditto.
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r83043 r83044  
     12011-04-06  Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [Cairo] Hide the details of image masking in PlatformContextCairo
     6        https://bugs.webkit.org/show_bug.cgi?id=57878
     7
     8        No new tests. This is just a refactor.
     9
     10        * platform/graphics/GraphicsContext.h:
     11        * platform/graphics/cairo/GraphicsContextCairo.cpp:
     12        (WebCore::GraphicsContext::savePlatformState): Call into PlatformContextCairo now to
     13        do the actual cairo_save. Remove information about image masking.
     14        (WebCore::GraphicsContext::restorePlatformState): Call into PlatformContextCairo now to
     15        do the actual cairo_restore. Remove information about image masking.
     16        * platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h:
     17        * platform/graphics/cairo/ImageBufferCairo.cpp:
     18        (WebCore::ImageBuffer::clip): Use PlatformContextCairo here now.
     19        * platform/graphics/cairo/PlatformContextCairo.cpp:
     20        (WebCore::PlatformContextCairo::restore): Added.
     21        (WebCore::PlatformContextCairo::save): Added.
     22        (WebCore::PlatformContextCairo::pushImageMask): Added.
     23        * platform/graphics/cairo/PlatformContextCairo.h:
     24        (WebCore::ImageMaskInformation::update): Moved from GraphicsContextPlatformPrivateCairo.h.
     25        (WebCore::ImageMaskInformation::isValid): Ditto.
     26        (WebCore::ImageMaskInformation::maskSurface): Ditto.
     27        (WebCore::ImageMaskInformation::maskRect): Ditto.
     28
    1292011-04-02  Diego Gonzalez  <diegohcg@webkit.org>
    230
  • trunk/Source/WebCore/platform/graphics/GraphicsContext.h

    r82962 r83044  
    493493#if PLATFORM(CAIRO)
    494494        GraphicsContext(cairo_t*);
    495         void pushImageMask(cairo_surface_t*, const FloatRect&);
    496495#endif
    497496
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp

    r82962 r83044  
    236236void GraphicsContext::savePlatformState()
    237237{
    238     cairo_save(platformContext()->cr());
     238    platformContext()->save();
    239239    m_data->save();
    240240    m_data->shadowStack.append(m_data->shadow);
    241     m_data->maskImageStack.append(ImageMaskInformation());
    242241}
    243242
    244243void GraphicsContext::restorePlatformState()
    245244{
    246     cairo_t* cr = platformContext()->cr();
    247 
    248     const ImageMaskInformation& maskInformation = m_data->maskImageStack.last();
    249     if (maskInformation.isValid()) {
    250         const FloatRect& maskRect = maskInformation.maskRect();
    251         cairo_pop_group_to_source(cr);
    252         cairo_mask_surface(cr, maskInformation.maskSurface(), maskRect.x(), maskRect.y());
    253     }
    254     m_data->maskImageStack.removeLast();
    255 
    256245    if (m_data->shadowStack.isEmpty())
    257246        m_data->shadow = ContextShadow();
     
    261250    }
    262251
    263     cairo_restore(cr);
     252    platformContext()->restore();
    264253    m_data->restore();
    265254}
     
    11921181}
    11931182
    1194 void GraphicsContext::pushImageMask(cairo_surface_t* surface, const FloatRect& rect)
    1195 {
    1196     // We must call savePlatformState at least once before we can use image masking,
    1197     // since we actually apply the mask in restorePlatformState.
    1198     ASSERT(!m_data->maskImageStack.isEmpty());
    1199     m_data->maskImageStack.last().update(surface, rect);
    1200 
    1201     // Cairo doesn't support the notion of an image clip, so we push a group here
    1202     // and then paint it to the surface with an image mask (which is an immediate
    1203     // operation) during restorePlatformState.
    1204 
    1205     // We want to allow the clipped elements to composite with the surface as it
    1206     // is now, but they are isolated in another group. To make this work, we're
    1207     // going to blit the current surface contents onto the new group once we push it.
    1208     cairo_t* cr = platformContext()->cr();
    1209     cairo_surface_t* currentTarget = cairo_get_target(cr);
    1210     cairo_surface_flush(currentTarget);
    1211 
    1212     // Pushing a new group ensures that only things painted after this point are clipped.
    1213     cairo_push_group(cr);
    1214     cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
    1215 
    1216     cairo_set_source_surface(cr, currentTarget, 0, 0);
    1217     cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height());
    1218     cairo_fill(cr);
    1219 }
    1220 
    12211183} // namespace WebCore
    12221184
  • trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h

    r82962 r83044  
    4747
    4848namespace WebCore {
    49 
    50 // In Cairo image masking is immediate, so to emulate image clipping we must save masking
    51 // details as part of the context state and apply it during platform restore.
    52 class ImageMaskInformation {
    53 public:
    54     void update(cairo_surface_t* maskSurface, const FloatRect& maskRect)
    55     {
    56         m_maskSurface = maskSurface;
    57         m_maskRect = maskRect;
    58     }
    59 
    60     bool isValid() const { return m_maskSurface; }
    61     cairo_surface_t* maskSurface() const { return m_maskSurface.get(); }
    62     const FloatRect& maskRect() const { return m_maskRect; }
    63 
    64 private:
    65     RefPtr<cairo_surface_t> m_maskSurface;
    66     FloatRect m_maskRect;
    67 };
    6849
    6950class GraphicsContextPlatformPrivate {
     
    122103    ContextShadow shadow;
    123104    Vector<ContextShadow> shadowStack;
    124     Vector<ImageMaskInformation> maskImageStack;
    125105
    126106#if PLATFORM(GTK)
  • trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r82962 r83044  
    118118void ImageBuffer::clip(GraphicsContext* context, const FloatRect& maskRect) const
    119119{
    120     context->pushImageMask(m_data.m_surface, maskRect);
     120    context->platformContext()->pushImageMask(m_data.m_surface, maskRect);
    121121}
    122122
  • trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp

    r82962 r83044  
    3636}
    3737
     38void PlatformContextCairo::restore()
     39{
     40    const ImageMaskInformation& maskInformation = m_maskImageStack.last();
     41    if (maskInformation.isValid()) {
     42        const FloatRect& maskRect = maskInformation.maskRect();
     43        cairo_pop_group_to_source(m_cr.get());
     44        cairo_mask_surface(m_cr.get(), maskInformation.maskSurface(), maskRect.x(), maskRect.y());
     45    }
     46    m_maskImageStack.removeLast();
     47
     48    cairo_restore(m_cr.get());
     49}
     50
     51void PlatformContextCairo::save()
     52{
     53    m_maskImageStack.append(ImageMaskInformation());
     54
     55    cairo_save(m_cr.get());
     56}
     57
     58void PlatformContextCairo::pushImageMask(cairo_surface_t* surface, const FloatRect& rect)
     59{
     60    // We must call savePlatformState at least once before we can use image masking,
     61    // since we actually apply the mask in restorePlatformState.
     62    ASSERT(!m_data->maskImageStack.isEmpty());
     63    m_maskImageStack.last().update(surface, rect);
     64
     65    // Cairo doesn't support the notion of an image clip, so we push a group here
     66    // and then paint it to the surface with an image mask (which is an immediate
     67    // operation) during restorePlatformState.
     68
     69    // We want to allow the clipped elements to composite with the surface as it
     70    // is now, but they are isolated in another group. To make this work, we're
     71    // going to blit the current surface contents onto the new group once we push it.
     72    cairo_surface_t* currentTarget = cairo_get_target(m_cr.get());
     73    cairo_surface_flush(currentTarget);
     74
     75    // Pushing a new group ensures that only things painted after this point are clipped.
     76    cairo_push_group(m_cr.get());
     77    cairo_set_operator(m_cr.get(), CAIRO_OPERATOR_SOURCE);
     78
     79    cairo_set_source_surface(m_cr.get(), currentTarget, 0, 0);
     80    cairo_rectangle(m_cr.get(), rect.x(), rect.y(), rect.width(), rect.height());
     81    cairo_fill(m_cr.get());
     82}
     83
     84
    3885} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h

    r82962 r83044  
    3232namespace WebCore {
    3333
     34// In Cairo image masking is immediate, so to emulate image clipping we must save masking
     35// details as part of the context state and apply them during platform restore.
     36class ImageMaskInformation {
     37public:
     38    void update(cairo_surface_t* maskSurface, const FloatRect& maskRect)
     39    {
     40        m_maskSurface = maskSurface;
     41        m_maskRect = maskRect;
     42    }
     43
     44    bool isValid() const { return m_maskSurface; }
     45    cairo_surface_t* maskSurface() const { return m_maskSurface.get(); }
     46    const FloatRect& maskRect() const { return m_maskRect; }
     47
     48private:
     49    RefPtr<cairo_surface_t> m_maskSurface;
     50    FloatRect m_maskRect;
     51};
     52
    3453// Much like PlatformContextSkia in the Skia port, this class holds information that
    3554// would normally be private to GraphicsContext, except that we want to allow access
     
    4160public:
    4261    PlatformContextCairo(cairo_t*);
     62
    4363    cairo_t* cr() { return m_cr.get(); }
    4464    void setCr(cairo_t* cr) { m_cr = cr; }
    4565
     66    void save();
     67    void restore();
     68    void pushImageMask(cairo_surface_t*, const FloatRect&);
     69
    4670private:
    4771    RefPtr<cairo_t> m_cr;
     72    Vector<ImageMaskInformation> m_maskImageStack;
    4873};
    4974
Note: See TracChangeset for help on using the changeset viewer.