0

カスタム GraphicsItem のペイント関数が CPU を 100% 消費することを発見しました (最悪の場合)。

私はそれがこれであることがわかりました:setTransformOriginPoint

他のすべての関数 (drawRect、Hight Quality アンチエイリアスの設定など) に対して。

面白いことに、私はそれを削除しましたが、すべて正常に機能しました。移動後に配置したので、おそらくその新しい変換原点に関連して回転します。しかし、とにかくうまくいきました...なぜだろう...

しかし、主な問題は、なぜ 100% なのかということです。

CPU使用率が高いアイテムのペイントのコードを提供します。

// Translate all to the center of the ruler calculated in the itemChange method.
  painter->translate(rulerCenter_);
  // rotate with the center where the ruler center is
  //setTransformOriginPoint(rulerCenter_); <-- BRINGS 100% USAGE, NO SENSE WHY IT WORKS WITHOUT THIS.

  painter->rotate(rulerRotation_);

  // Set the color for the lines and quality of the lines
  painter->setRenderHint(QPainter::Antialiasing, true);
  painter->setPen(linesColor_);

  // Draw long line of the ruler next to the wall
  painter->drawLine(-length_/2,0,length_/2,0);

  // Lines in the sides
  painter->drawLine(-length_/2, 0, -length_/2, -sideLinesSize_); 
  painter->drawLine(length_/2, 0, length_/2, -sideLinesSize_); 

  // if we should flip the text for the user to read it properly...
  if (flippedText_)
    painter->rotate(180);

  // Prepare for the text box, moving it to be centered
  painter->translate(-textBox_.width()/2,-textBox_.height()/2);

  // draw a box under the text so it hides whatever is under it
  painter->setBrush(textBackgroundColor_);
  painter->setPen(Qt::NoPen);
  painter->drawRect(textBox_);

  // Draw the text
  painter->setPen(pen_);
  painter->setFont(font_);
  painter->setRenderHint(QPainter::HighQualityAntialiasing, true);
  painter->drawText(textBox_, Qt::AlignCenter, meassureString_ );
4

1 に答える 1

1

レンダリングを他のすべての処理タスクから分離する必要があります。

ペイント機能はアイテムをペイントするためのものであり、オブジェクトを移動または回転させるためのものではありません。ペイント関数でレンダリング以外のことをしようとすると、グラフィック パイプラインが遅延するか停止します。これは、setTransformOriginPoint を呼び出したときに発生している可能性があります。

レンダリングの前にグラフィックス パイプラインを設定するには、かなりの量の処理が必要です。パイプラインを停止すると、再度実行する必要があり、100% のプロセッサ時間が費やされます。

ARM プロセッサで何が起こっているかを説明していますが、説明されている理論はここでも同じです

于 2013-10-08T09:59:38.737 に答える