RenderThread.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   RenderThread.h
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Intermediary for communicating/blocking between Gui and non-Gui threads 
00009    in Qt
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #include "RenderThread.h"
00013 #include "ImageCanvas.h"
00014 
00015 #include <renderers/Renderer.h>
00016 #include <QApplication>
00017 
00018 RenderThread::RenderThread(Renderer *renderer)
00019    : QThread(), m_renderer(renderer)
00020 { }
00021 
00022 RenderThread::~RenderThread()
00023 { }
00024 
00025 void RenderThread::run() {
00026    if (m_renderer)
00027       m_renderer->render();
00028 }
00029 
00030 /* Implementation of LocalSyscallProxy */
00031 LocalSyscallProxy::LocalSyscallProxy(ImageCanvas *canvas, QObject *mainProxy)
00032    : m_canvas(canvas)
00033 {
00034    if (mainProxy) // auto-connect to mainProxy
00035       connectTo(mainProxy);
00036 }
00037 
00038 void LocalSyscallProxy::repaint(int x1, int y1, int w, int h) {
00039    emit sig_repaint((void*)m_canvas, x1, y1, w, h);
00040 }
00041 
00042 void LocalSyscallProxy::connectTo(QObject *mainProxy) {
00043    Qt::ConnectionType connectionKind;
00044    
00045    if (this->thread() != mainProxy->thread()) {
00046       connectionKind = Qt::BlockingQueuedConnection;
00047    } else {
00048       connectionKind = Qt::DirectConnection;
00049    }
00050    
00051    // make the connections between this and the main thread proxy
00052    connect(this, SIGNAL(sig_repaint(void*,int, int, int, int)),
00053            mainProxy, SLOT(slot_repaint(void*,int, int, int, int)),
00054            connectionKind);
00055 }
00056 
00057 MainSyscallProxy::MainSyscallProxy() {
00058    // push myself to the main thread
00059    moveToThread(qApp->thread());
00060 }
00061 
00062 // the following method just relays the call to the handler
00063 void MainSyscallProxy::slot_repaint(void *t, int x1, int y1, int w, int h) {
00064    ImageCanvas *target = (ImageCanvas *) t;
00065    target->_repaintPrivate(x1, y1, w, h);
00066 }
00067 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6