[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: extragear/multimedia/amarok/src/contextview
From:       "Maximilian Kossick" <maximilian.kossick () googlemail ! com>
Date:       2007-07-13 10:17:46
Message-ID: c3d78d90707130317w78cd7f83h8f9923c73462221 () mail ! gmail ! com
[Download RAW message or body]

Are you sure it's safe to update a GUI component from another thread? And it
might be useful to stop the thread if Amarok is minimised to prevent the
thread from waking up the CPU 50 times a second.

On 7/13/07, Mark Kretschmann <kretschmann@kde.org> wrote:
>
> SVN commit 687330 by markey:
>
> Use a separate QThread with its own event loop to update the view. My hope
> was that this would allow to keep a constant frame rate even when Amarok is
> busy.
>
> Seems to improve things somewhat, but I'm not 100% happy with the result
> yet. Animation still hickups when you e.g. open the settings dialog.
>
>
> M  +30 -3     CoverBling.cpp
> M  +13 -0     CoverBling.h
>
>
> --- trunk/extragear/multimedia/amarok/src/contextview/CoverBling.cpp
> #687329:687330
> @@ -17,6 +17,8 @@
>   *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
> USA.          *
>
>   ***************************************************************************/
>
> +#define DEBUG_PREFIX "CoverBling"
> +
> #include "debug.h"
> #include "CoverBling.h"
>
> @@ -35,9 +37,8 @@
>
>      setFixedHeight( 200 );
>
> -    QTimer* timer = new QTimer( this );
> -    connect( timer, SIGNAL( timeout() ), this, SLOT( updateGL() ) );
> -    timer->start( 20 ); //50fps
> +    UpdateThread* thread = new UpdateThread( this );
> +    thread->start( QThread::TimeCriticalPriority );
> }
>
> void
> @@ -174,5 +175,31 @@
> }
>
>
> +UpdateThread::UpdateThread( QObject* parent )
> +        : QThread( parent )
> +{
> +    DEBUG_BLOCK
> +}
> +
> +void
> +UpdateThread::run()
> +{
> +    DEBUG_BLOCK
> +
> +    CoverBling* cb = static_cast<CoverBling*>( parent() );
> +
> +//    while( true ) {
> +//        cb->updateGL();
> +//        msleep( 20 );
> +//    }
> +
> +    QTimer* timer = new QTimer( this );
> +    connect( timer, SIGNAL( timeout() ), cb, SLOT( updateGL() ) );
> +    timer->start( 20 ); //50fps
> +
> +    exec();
> +}
> +
> +
> #include "CoverBling.moc"
>
> --- trunk/extragear/multimedia/amarok/src/contextview/CoverBling.h
> #687329:687330
> @@ -21,6 +21,7 @@
> #define AMAROK_COVERBLING_H
>
> #include <QGLWidget>
> +#include <QThread>
>
>
> class CoverBling : public QGLWidget
> @@ -48,6 +49,18 @@
> };
>
>
> +class UpdateThread : public QThread
> +{
> +    Q_OBJECT
> +
> +    public:
> +        UpdateThread( QObject* parent );
> +
> +    protected:
> +        void run();
> +};
> +
> +
> #endif /* AMAROK_COVERBLING_H */
>
>
>

[Attachment #3 (text/html)]

Are you sure it&#39;s safe to update a GUI component from another thread? And it \
might be useful to stop the thread if Amarok is minimised to prevent the thread from \
waking up the CPU 50 times a second.<br><br><div><span class="gmail_quote"> On \
7/13/07, <b class="gmail_sendername">Mark Kretschmann</b> &lt;<a \
href="mailto:kretschmann@kde.org">kretschmann@kde.org</a>&gt; \
wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, \
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> SVN commit 687330 by \
markey:<br><br>Use a separate QThread with its own event loop to update the view. My \
hope was that this would allow to keep a constant frame rate even when Amarok is \
busy.<br><br>Seems to improve things somewhat, but I&#39;m not 100% happy with the \
result yet. Animation still hickups when you  e.g. open the settings \
dialog.<br><br><br> M&nbsp;&nbsp;+30 -3&nbsp;&nbsp;&nbsp;&nbsp; CoverBling.cpp<br> \
M&nbsp;&nbsp;+13 -0&nbsp;&nbsp;&nbsp;&nbsp; CoverBling.h<br><br><br>--- \
trunk/extragear/multimedia/amarok/src/contextview/CoverBling.cpp #687329:687330<br>@@ \
-17,6 +17,8 @@<br> &nbsp;&nbsp;*&nbsp;&nbsp; 51 Franklin Street, Fifth Floor, Boston, \
MA&nbsp;&nbsp;02110-1301, \
USA.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br>&nbsp;&nbsp;***** \
**********************************************************************/<br><br>+#define \
DEBUG_PREFIX &quot;CoverBling&quot;<br>+<br>  #include &quot;debug.h&quot;<br> \
#include &quot;CoverBling.h&quot;<br><br>@@ -35,9 +37,8 \
@@<br><br>&nbsp;&nbsp;&nbsp;&nbsp; setFixedHeight( 200 \
);<br><br>-&nbsp;&nbsp;&nbsp;&nbsp;QTimer* timer = new QTimer( this \
);<br>-&nbsp;&nbsp;&nbsp;&nbsp;connect( timer, SIGNAL( timeout() ), this, SLOT( \
updateGL() ) ); <br>-&nbsp;&nbsp;&nbsp;&nbsp;timer-&gt;start( 20 ); \
//50fps<br>+&nbsp;&nbsp;&nbsp;&nbsp;UpdateThread* thread = new UpdateThread( this \
);<br>+&nbsp;&nbsp;&nbsp;&nbsp;thread-&gt;start( QThread::TimeCriticalPriority );<br> \
}<br><br> void<br>@@ -174,5 +175,31 @@<br> }<br><br><br>+UpdateThread::UpdateThread( \
QObject* parent ) <br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: QThread( \
parent )<br>+{<br>+&nbsp;&nbsp;&nbsp;&nbsp;DEBUG_BLOCK<br>+}<br>+<br>+void<br>+UpdateT \
hread::run()<br>+{<br>+&nbsp;&nbsp;&nbsp;&nbsp;DEBUG_BLOCK<br>+<br>+&nbsp;&nbsp;&nbsp;&nbsp;CoverBling* \
cb = static_cast&lt;CoverBling*&gt;( parent() \
);<br>+<br>+//&nbsp;&nbsp;&nbsp;&nbsp;while( true ) { \
<br>+//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cb-&gt;updateGL();<br>+//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msleep( \
20 );<br>+//&nbsp;&nbsp;&nbsp;&nbsp;}<br>+<br>+&nbsp;&nbsp;&nbsp;&nbsp;QTimer* timer \
= new QTimer( this );<br>+&nbsp;&nbsp;&nbsp;&nbsp;connect( timer, SIGNAL( timeout() \
), cb, SLOT( updateGL() ) );<br>+&nbsp;&nbsp;&nbsp;&nbsp;timer-&gt;start( 20 ); \
//50fps <br>+<br>+&nbsp;&nbsp;&nbsp;&nbsp;exec();<br>+}<br>+<br>+<br> #include \
&quot;CoverBling.moc&quot;<br><br>--- \
trunk/extragear/multimedia/amarok/src/contextview/CoverBling.h #687329:687330<br>@@ \
-21,6 +21,7 @@<br> #define AMAROK_COVERBLING_H<br> <br> #include \
&lt;QGLWidget&gt;<br>+#include &lt;QThread&gt;<br><br><br> class CoverBling : public \
QGLWidget<br>@@ -48,6 +49,18 @@<br> };<br><br><br>+class UpdateThread : public \
QThread<br>+{<br>+&nbsp;&nbsp;&nbsp;&nbsp;Q_OBJECT<br>+<br>+&nbsp;&nbsp;&nbsp;&nbsp;public:
 <br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateThread( QObject* parent \
);<br>+<br>+&nbsp;&nbsp;&nbsp;&nbsp;protected:<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;void \
run();<br>+};<br>+<br>+<br> #endif /* AMAROK_COVERBLING_H \
*/<br><br><br></blockquote></div><br>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic