[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/khtml/html
From:       Fredrik Höglund <fredrik () kde ! org>
Date:       2008-01-21 19:21:21
Message-ID: 1200943281.764454.7976.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 764432 by fredrik:

Simplify and likely improve the correctness of the path and shadow bounding
rect computations in CanvasContext2DImpl::drawPathWithShadow().
Don't generate the shadow image when the shadow is completely outside the
canvas.


 M  +27 -21    html_canvasimpl.cpp  


--- trunk/KDE/kdelibs/khtml/html/html_canvasimpl.cpp #764431:764432
@@ -1089,8 +1089,7 @@
     if (radius > 7)
         radius = qMin(7 + std::pow(float(radius - 7.0), float(.7)), float(127.0));
 
-    qreal xoffset = radius * 2;
-    qreal yoffset = radius * 2;
+    qreal offset = radius * 2;
 
     bool honorRepeat = !(flags & NotUsingCanvasPattern);
     QRectF repeatClip = clipForRepeat(p, op);
@@ -1099,7 +1098,8 @@
     if (honorRepeat && !repeatClip.isEmpty()) {
         QPainterPath clipPath;
         clipPath.addRect(repeatClip);
-        shapeBounds = path.intersected(clipPath * state.transform).controlPointRect().toAlignedRect();
+        shapeBounds = path.intersected(clipPath * state.transform)
+	                        .controlPointRect().toAlignedRect();
     } else
         shapeBounds = path.controlPointRect().toAlignedRect();
 
@@ -1110,16 +1110,16 @@
     } else
         clipRect = QRect(QPoint(), canvasImage->size());
 
-    // We need the clip rect to be large enough so that items that are partially or
-    // completely outside the canvas will still cast shadows into it when they should.
-    clipRect.adjust(qMin(-shadowOffsetX(), float(0)), qMin(-shadowOffsetY(), float(0)),
-                    qMax(-shadowOffsetX(), float(0)), qMax(-shadowOffsetY(), float(0)));
-    clipRect.adjust(-xoffset, -yoffset, xoffset, yoffset);
+    QRect shadowRect = shapeBounds.translated(shadowOffsetX(), shadowOffsetY())
+                        .adjusted(-offset, -offset, offset, offset) &
+                        clipRect.adjusted(-offset, -offset, offset, offset);
 
-    QRect shapeRect  = shapeBounds & clipRect;
-    QRect shadowRect = shapeRect.translated(shadowOffsetX(), shadowOffsetY());
-    shadowRect.adjust(-xoffset, -yoffset, xoffset, yoffset);
+    QRect shapeRect = QRect(shapeBounds & clipRect) | shadowRect
+                        .translated(-shadowOffsetX(), -shadowOffsetY()) & shapeBounds;
 
+    if (!shapeRect.isValid())
+        return;
+
     QPainter painter;
 
     // Create the image for the original shape
@@ -1139,19 +1139,25 @@
     painter.end();
 
     // Create the shadow image and draw the original image on it
-    QImage shadow(shadowRect.size(), QImage::Format_ARGB32_Premultiplied);
-    shadow.fill(0);
+    if (shadowRect.isValid()) {
+        QImage shadow(shadowRect.size(), QImage::Format_ARGB32_Premultiplied);
+        shadow.fill(0);
 
-    painter.begin(&shadow);
-    painter.setCompositionMode(QPainter::CompositionMode_Source);
-    painter.drawImage(xoffset, yoffset, shape);
-    painter.end();
+        painter.begin(&shadow);
+        painter.setCompositionMode(QPainter::CompositionMode_Source);
+        painter.translate(-shadowRect.x(), -shadowRect.y());
+        painter.drawImage(shapeRect.x() + shadowOffsetX(),
+                          shapeRect.y() + shadowOffsetY(), shape);
+        painter.end();
 
-    // Blur the alpha channel
-    ImageFilter::shadowBlur(shadow, radius, state.shadowColor);
+        // Blur the alpha channel
+        ImageFilter::shadowBlur(shadow, radius, state.shadowColor);
 
-    // Draw the shadow on the canvas first, then composite the original image over it.
-    p->drawImage(shadowRect.topLeft(), shadow);
+        // Draw the shadow on the canvas
+        p->drawImage(shadowRect.topLeft(), shadow);
+    }
+
+    // Composite the original image over the shadow.
     p->drawImage(shapeRect.topLeft(), shape);
 }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic