Use scissor clip if element is rotated a multiple of 90 degrees.
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>
Wed, 17 Aug 2011 09:56:05 +0000 (11:56 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 17 Aug 2011 11:19:47 +0000 (13:19 +0200)
Change-Id: I16706049f0ff5a371b5fa95430ca6c2d2f1add96
Reviewed-on: http://codereview.qt.nokia.com/3086
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
src/declarative/scenegraph/coreapi/qsgrenderer.cpp

index 73d660b..6757559 100644 (file)
@@ -397,17 +397,32 @@ QSGRenderer::ClipType QSGRenderer::updateStencilClip(const QSGClipNode *clip)
             m *= *clip->matrix();
 
         // TODO: Check for multisampling and pixel grid alignment.
-        bool canUseScissor = clip->isRectangular()
-                           && qFuzzyIsNull(m(0, 1)) && qFuzzyIsNull(m(1, 0))
-                           && qFuzzyIsNull(m(3, 0)) && qFuzzyIsNull(m(3, 1));
+        bool isRectangleWithNoPerspective = clip->isRectangular()
+                && qFuzzyIsNull(m(3, 0)) && qFuzzyIsNull(m(3, 1));
+        bool noRotate = qFuzzyIsNull(m(0, 1)) && qFuzzyIsNull(m(1, 0));
+        bool isRotate90 = qFuzzyIsNull(m(0, 0)) && qFuzzyIsNull(m(1, 1));
 
-        if (canUseScissor) {
+        if (isRectangleWithNoPerspective && (noRotate || isRotate90)) {
             QRectF bbox = clip->clipRect();
             qreal invW = 1 / m(3, 3);
-            qreal fx1 = (bbox.left() * m(0, 0) + m(0, 3)) * invW;
-            qreal fy1 = (bbox.bottom() * m(1, 1) + m(1, 3)) * invW;
-            qreal fx2 = (bbox.right() * m(0, 0) + m(0, 3)) * invW;
-            qreal fy2 = (bbox.top() * m(1, 1) + m(1, 3)) * invW;
+            qreal fx1, fy1, fx2, fy2;
+            if (noRotate) {
+                fx1 = (bbox.left() * m(0, 0) + m(0, 3)) * invW;
+                fy1 = (bbox.bottom() * m(1, 1) + m(1, 3)) * invW;
+                fx2 = (bbox.right() * m(0, 0) + m(0, 3)) * invW;
+                fy2 = (bbox.top() * m(1, 1) + m(1, 3)) * invW;
+            } else {
+                Q_ASSERT(isRotate90);
+                fx1 = (bbox.bottom() * m(0, 1) + m(0, 3)) * invW;
+                fy1 = (bbox.left() * m(1, 0) + m(1, 3)) * invW;
+                fx2 = (bbox.top() * m(0, 1) + m(0, 3)) * invW;
+                fy2 = (bbox.right() * m(1, 0) + m(1, 3)) * invW;
+            }
+
+            if (fx1 > fx2)
+                qSwap(fx1, fx2);
+            if (fy1 > fy2)
+                qSwap(fy1, fy2);
 
             GLint ix1 = qRound((fx1 + 1) * m_device_rect.width() * qreal(0.5));
             GLint iy1 = qRound((fy1 + 1) * m_device_rect.height() * qreal(0.5));
@@ -422,7 +437,6 @@ QSGRenderer::ClipType QSGRenderer::updateStencilClip(const QSGClipNode *clip)
                 clipRect &= QRect(ix1, iy1, ix2 - ix1, iy2 - iy1);
             }
 
-            clipRect = clipRect.normalized();
             glScissor(clipRect.x(), clipRect.y(), clipRect.width(), clipRect.height());
         } else {
             if (!stencilEnabled) {