##// END OF EJS Templates
Further fixes to threaded rendering...
Miikka Heikkinen -
r2506:59c477efbea1
parent child
Show More
@@ -46,6 +46,7
46 46 #include <QGraphicsSceneHoverEvent>
47 47 #include <QApplication>
48 48 #include <QTimer>
49 #include <QThread>
49 50 #endif
50 51
51 52 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -265,6 +266,8 void DeclarativeChart::initChart(QChart::ChartType type)
265 266 {
266 267 #ifdef CHARTS_FOR_QUICK2
267 268 m_currentSceneImage = 0;
269 m_guiThreadId = QThread::currentThreadId();
270 m_paintThreadId = 0;
268 271
269 272 if (type == QChart::ChartTypePolar)
270 273 m_chart = new QPolarChart();
@@ -429,12 +432,18 void DeclarativeChart::sceneChanged(QList<QRectF> region)
429 432 {
430 433 Q_UNUSED(region);
431 434
435 if (m_guiThreadId == m_paintThreadId) {
436 // Rendering in gui thread, no need for shenannigans, just update
437 update();
438 } else {
439 // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread
432 440 if (!m_updatePending) {
433 441 m_updatePending = true;
434 442 // Do async render to avoid some unnecessary renders.
435 443 QTimer::singleShot(0, this, SLOT(renderScene()));
436 444 }
437 445 }
446 }
438 447
439 448 void DeclarativeChart::renderScene()
440 449 {
@@ -444,6 +453,8 void DeclarativeChart::renderScene()
444 453 m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32);
445 454 m_currentSceneImage->fill(Qt::transparent);
446 455 QPainter painter(m_currentSceneImage);
456 if (antialiasing())
457 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
447 458 QRect renderRect(QPoint(0, 0), m_chart->size().toSize());
448 459 m_scene->render(&painter, renderRect, renderRect);
449 460 m_sceneImageLock.unlock();
@@ -453,6 +464,21 void DeclarativeChart::renderScene()
453 464
454 465 void DeclarativeChart::paint(QPainter *painter)
455 466 {
467 if (!m_paintThreadId) {
468 m_paintThreadId = QThread::currentThreadId();
469 if (m_guiThreadId == m_paintThreadId) {
470 // No need for scene image in single threaded rendering, so delete
471 // the one that got made by default before the rendering type was
472 // detected.
473 delete m_currentSceneImage;
474 m_currentSceneImage = 0;
475 }
476 }
477
478 if (m_guiThreadId == m_paintThreadId) {
479 QRectF renderRect(QPointF(0, 0), m_chart->size());
480 m_scene->render(painter, renderRect, renderRect);
481 } else {
456 482 m_sceneImageLock.lock();
457 483 if (m_currentSceneImage) {
458 484 QRect imageRect(QPoint(0, 0), m_currentSceneImage->size());
@@ -461,6 +487,7 void DeclarativeChart::paint(QPainter *painter)
461 487 }
462 488 m_sceneImageLock.unlock();
463 489 }
490 }
464 491
465 492 void DeclarativeChart::mousePressEvent(QMouseEvent *event)
466 493 {
@@ -218,6 +218,8 private:
218 218 QMutex m_sceneImageLock;
219 219 QImage *m_currentSceneImage;
220 220 bool m_updatePending;
221 Qt::HANDLE m_paintThreadId;
222 Qt::HANDLE m_guiThreadId;
221 223 #endif
222 224 DeclarativeMargins *m_margins;
223 225 };
General Comments 0
You need to be logged in to leave comments. Login now