Changeset 59668 in webkit


Ignore:
Timestamp:
May 18, 2010 6:25:04 AM (14 years ago)
Author:
zherczeg@webkit.org
Message:

[Qt] Implementing clipToImageBuffer for Qt port.
https://bugs.webkit.org/show_bug.cgi?id=24289

Reviewed by Kenneth Rohde Christiansen.

The implementation combines pixmap layers and destinationIn
composition mode.

  • platform/graphics/qt/GraphicsContextQt.cpp:

(WebCore::TransparencyLayer::TransparencyLayer):
(WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
(WebCore::GraphicsContext::savePlatformState):
(WebCore::GraphicsContext::restorePlatformState):
(WebCore::GraphicsContext::inTransparencyLayer):
(WebCore::GraphicsContext::beginTransparencyLayer):
(WebCore::GraphicsContext::endTransparencyLayer):
(WebCore::GraphicsContext::clipToImageBuffer):

Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r59667 r59668  
     12010-05-18  Zoltan Herczeg  <zherczeg@webkit.org>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] Implementing clipToImageBuffer for Qt port.
     6        https://bugs.webkit.org/show_bug.cgi?id=24289
     7
     8        The implementation combines pixmap layers and destinationIn
     9        composition mode.
     10
     11        * platform/graphics/qt/GraphicsContextQt.cpp:
     12        (WebCore::TransparencyLayer::TransparencyLayer):
     13        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
     14        (WebCore::GraphicsContext::savePlatformState):
     15        (WebCore::GraphicsContext::restorePlatformState):
     16        (WebCore::GraphicsContext::inTransparencyLayer):
     17        (WebCore::GraphicsContext::beginTransparencyLayer):
     18        (WebCore::GraphicsContext::endTransparencyLayer):
     19        (WebCore::GraphicsContext::clipToImageBuffer):
     20
    1212010-05-18  Eric Seidel  <eric@webkit.org>
    222
  • trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

    r58949 r59668  
    168168
    169169struct TransparencyLayer : FastAllocBase {
    170     TransparencyLayer(const QPainter* p, const QRect &rect)
     170    TransparencyLayer(const QPainter* p, const QRect &rect, qreal opacity, QPixmap& alphaMask)
    171171        : pixmap(rect.width(), rect.height())
     172        , opacity(opacity)
     173        , alphaMask(alphaMask)
     174        , saveCounter(1) // see the comment for saveCounter
    172175    {
    173176        offset = rect.topLeft();
     
    183186        if (painter.paintEngine()->hasFeature(QPaintEngine::PorterDuff))
    184187            painter.setCompositionMode(p->compositionMode());
    185         painter.setClipPath(p->clipPath());
     188        // if the path is an empty region, this assignment disables all painting
     189        if (!p->clipPath().isEmpty())
     190            painter.setClipPath(p->clipPath());
    186191    }
    187192
     
    194199    QPainter painter;
    195200    qreal opacity;
     201    // for clipToImageBuffer
     202    QPixmap alphaMask;
     203    // saveCounter is only used in combination with alphaMask
     204    // otherwise, its value is unspecified
     205    int saveCounter;
    196206private:
    197207    TransparencyLayer(const TransparencyLayer &) {}
     
    218228
    219229    QStack<TransparencyLayer*> layers;
     230    // Counting real layers. Required by inTransparencyLayer() calls
     231    // For example, layers with valid alphaMask are not real layers
     232    int layerCount;
    220233    QPainter* redirect;
    221234
     
    236249{
    237250    painter = p;
     251    layerCount = 0;
    238252    redirect = 0;
    239253
     
    290304void GraphicsContext::savePlatformState()
    291305{
     306    if (!m_data->layers.isEmpty() && !m_data->layers.top()->alphaMask.isNull())
     307        ++m_data->layers.top()->saveCounter;
    292308    m_data->p()->save();
    293309}
     
    295311void GraphicsContext::restorePlatformState()
    296312{
     313    if (!m_data->layers.isEmpty() && !m_data->layers.top()->alphaMask.isNull())
     314        if (!--m_data->layers.top()->saveCounter)
     315            endTransparencyLayer();
     316
    297317    m_data->p()->restore();
    298318
     
    679699bool GraphicsContext::inTransparencyLayer() const
    680700{
    681     return !m_data->layers.isEmpty();
     701    return m_data->layerCount;
    682702}
    683703
     
    838858    h = int(qBound(qreal(0), deviceClip.height(), (qreal)h) + 2);
    839859
    840     TransparencyLayer * layer = new TransparencyLayer(m_data->p(), QRect(x, y, w, h));
    841 
    842     layer->opacity = opacity;
    843     m_data->layers.push(layer);
     860    QPixmap emptyAlphaMask;
     861    m_data->layers.push(new TransparencyLayer(m_data->p(), QRect(x, y, w, h), opacity, emptyAlphaMask));
     862    ++m_data->layerCount;
    844863}
    845864
     
    850869
    851870    TransparencyLayer* layer = m_data->layers.pop();
     871    if (!layer->alphaMask.isNull()) {
     872        layer->painter.resetTransform();
     873        layer->painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
     874        layer->painter.drawPixmap(QPoint(), layer->alphaMask);
     875    } else
     876        --m_data->layerCount; // see the comment for layerCount
    852877    layer->painter.end();
    853878
     
    10871112}
    10881113
    1089 void GraphicsContext::clipToImageBuffer(const FloatRect&, const ImageBuffer*)
    1090 {
    1091     notImplemented();
     1114void GraphicsContext::clipToImageBuffer(const FloatRect& floatRect, const ImageBuffer* image)
     1115{
     1116    if (paintingDisabled())
     1117        return;
     1118
     1119    QPixmap* nativeImage = image->image()->nativeImageForCurrentFrame();
     1120    if (!nativeImage)
     1121        return;
     1122
     1123    IntRect rect(floatRect);
     1124    QPixmap alphaMask = *nativeImage;
     1125    if (alphaMask.width() != rect.width() || alphaMask.height() != rect.height())
     1126        alphaMask = alphaMask.scaled(rect.width(), rect.height());
     1127
     1128    m_data->layers.push(new TransparencyLayer(m_data->p(), rect, 1.0, alphaMask));
    10921129}
    10931130
Note: See TracChangeset for help on using the changeset viewer.