summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/qt/GraphicsContextQt.cpp')
-rw-r--r--WebCore/platform/graphics/qt/GraphicsContextQt.cpp57
1 files changed, 47 insertions, 10 deletions
diff --git a/WebCore/platform/graphics/qt/GraphicsContextQt.cpp b/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
index 0100b72..69121c8 100644
--- a/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
+++ b/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
@@ -167,10 +167,13 @@ static inline Qt::FillRule toQtFillRule(WindRule rule)
}
struct TransparencyLayer : FastAllocBase {
- TransparencyLayer(const QPainter* p, const QRect &rect)
+ TransparencyLayer(const QPainter* p, const QRect &rect, qreal opacity, QPixmap& alphaMask)
: pixmap(rect.width(), rect.height())
+ , opacity(opacity)
+ , alphaMask(alphaMask)
+ , saveCounter(1) // see the comment for saveCounter
{
- offset = rect.topLeft();
+ offset = p->transform().mapRect(rect).topLeft();
pixmap.fill(Qt::transparent);
painter.begin(&pixmap);
painter.setRenderHint(QPainter::Antialiasing, p->testRenderHint(QPainter::Antialiasing));
@@ -182,7 +185,9 @@ struct TransparencyLayer : FastAllocBase {
painter.setFont(p->font());
if (painter.paintEngine()->hasFeature(QPaintEngine::PorterDuff))
painter.setCompositionMode(p->compositionMode());
- painter.setClipPath(p->clipPath());
+ // if the path is an empty region, this assignment disables all painting
+ if (!p->clipPath().isEmpty())
+ painter.setClipPath(p->clipPath());
}
TransparencyLayer()
@@ -193,6 +198,11 @@ struct TransparencyLayer : FastAllocBase {
QPoint offset;
QPainter painter;
qreal opacity;
+ // for clipToImageBuffer
+ QPixmap alphaMask;
+ // saveCounter is only used in combination with alphaMask
+ // otherwise, its value is unspecified
+ int saveCounter;
private:
TransparencyLayer(const TransparencyLayer &) {}
TransparencyLayer & operator=(const TransparencyLayer &) { return *this; }
@@ -217,6 +227,9 @@ public:
bool antiAliasingForRectsAndLines;
QStack<TransparencyLayer*> layers;
+ // Counting real layers. Required by inTransparencyLayer() calls
+ // For example, layers with valid alphaMask are not real layers
+ int layerCount;
QPainter* redirect;
// reuse this brush for solid color (to prevent expensive QBrush construction)
@@ -235,6 +248,7 @@ private:
GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate(QPainter* p)
{
painter = p;
+ layerCount = 0;
redirect = 0;
solidColor = QBrush(Qt::black);
@@ -289,11 +303,17 @@ AffineTransform GraphicsContext::getCTM() const
void GraphicsContext::savePlatformState()
{
+ if (!m_data->layers.isEmpty() && !m_data->layers.top()->alphaMask.isNull())
+ ++m_data->layers.top()->saveCounter;
m_data->p()->save();
}
void GraphicsContext::restorePlatformState()
{
+ if (!m_data->layers.isEmpty() && !m_data->layers.top()->alphaMask.isNull())
+ if (!--m_data->layers.top()->saveCounter)
+ endTransparencyLayer();
+
m_data->p()->restore();
if (!m_data->currentPath.isEmpty() && m_common->state.pathTransform.isInvertible()) {
@@ -678,7 +698,7 @@ void GraphicsContext::addPath(const Path& path)
bool GraphicsContext::inTransparencyLayer() const
{
- return !m_data->layers.isEmpty();
+ return m_data->layerCount;
}
PlatformPath* GraphicsContext::currentPath()
@@ -837,10 +857,9 @@ void GraphicsContext::beginTransparencyLayer(float opacity)
w = int(qBound(qreal(0), deviceClip.width(), (qreal)w) + 2);
h = int(qBound(qreal(0), deviceClip.height(), (qreal)h) + 2);
- TransparencyLayer * layer = new TransparencyLayer(m_data->p(), QRect(x, y, w, h));
-
- layer->opacity = opacity;
- m_data->layers.push(layer);
+ QPixmap emptyAlphaMask;
+ m_data->layers.push(new TransparencyLayer(m_data->p(), QRect(x, y, w, h), opacity, emptyAlphaMask));
+ ++m_data->layerCount;
}
void GraphicsContext::endTransparencyLayer()
@@ -849,6 +868,12 @@ void GraphicsContext::endTransparencyLayer()
return;
TransparencyLayer* layer = m_data->layers.pop();
+ if (!layer->alphaMask.isNull()) {
+ layer->painter.resetTransform();
+ layer->painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
+ layer->painter.drawPixmap(QPoint(), layer->alphaMask);
+ } else
+ --m_data->layerCount; // see the comment for layerCount
layer->painter.end();
QPainter* p = m_data->p();
@@ -1086,9 +1111,21 @@ void GraphicsContext::clipOutEllipseInRect(const IntRect& rect)
}
}
-void GraphicsContext::clipToImageBuffer(const FloatRect&, const ImageBuffer*)
+void GraphicsContext::clipToImageBuffer(const FloatRect& floatRect, const ImageBuffer* image)
{
- notImplemented();
+ if (paintingDisabled())
+ return;
+
+ QPixmap* nativeImage = image->image()->nativeImageForCurrentFrame();
+ if (!nativeImage)
+ return;
+
+ IntRect rect(floatRect);
+ QPixmap alphaMask = *nativeImage;
+ if (alphaMask.width() != rect.width() || alphaMask.height() != rect.height())
+ alphaMask = alphaMask.scaled(rect.width(), rect.height());
+
+ m_data->layers.push(new TransparencyLayer(m_data->p(), rect, 1.0, alphaMask));
}
void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect,