Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-38790

QT Transform / Scale bigger than 1 gets slow

    XMLWordPrintable

Details

    Description

      When rendering > 200 Lines on a canvas, zooming out (scale / a,d < 1) is fluid and fast as expected.

      Zooming in (scale > 1) somehow gets incredibly slow (noticeable lag ~ 4 secs for rerendering) on a i7 machine with NVIDIA GPU etc.

      Transforming the path by "hand" is no problem.

      import QtQuick 2.0
      
      Rectangle {
          width: 480
          height: 480
      
          Canvas {
              id: canvas
              anchors.fill: parent
              property double scale: 1
              property var ctx;
              onAvailableChanged: {
                  if(available) {
                      console.log("canvas available")
                      ctx = canvas.getContext('2d');
                      console.log(ctx)
                  }
              }
              MouseArea {
                 id: mousearea
                 property int hitrad: 5;
                 anchors.fill: parent
                 onWheel: {
                     if(wheel.angleDelta.y > 0) {
                         canvas.scale += canvas.scale * 0.2;
                     } else {
                         canvas.scale -= canvas.scale * 0.2;
                     }
                     canvas.ctx.clearRect(0, 0, width, height);
                     canvas.requestPaint();
                 }
              }
              onPaint: {
                  ctx.reset();
                  var distance = ctx.lineWidth * 4;
                  ctx.scale(scale,scale);
      
                  // Using connected paths is slow:
                  ctx.beginPath();
                  ctx.moveTo(0, i * distance);
                  for (var i = 0; i < 200; ++i) {
                      ctx.lineTo(300 + Math.random() * 100, i * distance + 100);
                      ctx.lineTo(0 + Math.random() * 100, i * distance);
                  }
                  ctx.stroke();
      
                  // While creating individual paths isn't:
      //            for (var i = 0; i < 200; ++i) {
      //                ctx.beginPath();
      //                ctx.moveTo(300 + Math.random() * 100, i * distance + 100);
      //                ctx.lineTo(0 + Math.random() * 100, i * distance);
      //                ctx.stroke();
      //            }
              }
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            wolfv Wolf Vollprecht
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes