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