Skip to content

Commit

Permalink
xevents now handles repaints directly, can advance frames in display win
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed May 6, 2010
1 parent a793f42 commit 2631b35
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 56 deletions.
3 changes: 2 additions & 1 deletion ahab.cpp
Expand Up @@ -69,7 +69,8 @@ int main( int argc, char *argv[] )
xevents = new XEventLoop( display );

controller->get_queue()->hookup( decoder->get_queue() );
xevents->get_queue()->hookup( decoder->get_queue() );
xevents->get_key_queue()->hookup( decoder->get_queue() );
xevents->get_repaint_queue()->hookup( display->get_queue() );

try {
decoder->wait_shutdown();
Expand Down
11 changes: 0 additions & 11 deletions decoder.cpp
Expand Up @@ -36,7 +36,6 @@ void Decoder::decode_and_display( void )
Picture *pic = stream->get_picture_displayed( state.current_picture );
pic->start_parallel_decode( &engine, true );
pic->get_framehandle()->wait_rendered();
// pic->lock_and_decodeall();
DrawAndUnlockFrame *op = new DrawAndUnlockFrame( pic->get_framehandle() );
state.oglq->flush_type( op );
state.oglq->enqueue( op );
Expand All @@ -57,16 +56,6 @@ void Decoder::loop( void )

if ( state.current_picture != picture_displayed ) {
decode_and_display();

/* Also decode a window around current location
for ( int i = state.current_picture - 4;
i < state.current_picture + 4;
i++ ) {
if ( i >= 0 && i < stream->get_num_pictures() && i != state.current_picture ) {
stream->get_picture_displayed( i )->start_parallel_decode( false );
}
}
*/
}

picture_displayed = state.current_picture;
Expand Down
15 changes: 9 additions & 6 deletions decoderop.cpp
Expand Up @@ -6,12 +6,6 @@
void XKey::execute( DecoderState &state )
{
switch ( key ) {
case '@':
{
Repaint *op = new Repaint();
state.oglq->enqueue( op );
}
break;
case 'f':
state.fullscreen = !state.fullscreen;
{
Expand All @@ -22,6 +16,15 @@ void XKey::execute( DecoderState &state )
case 'q':
state.live = false;
break;
case XK_Left:
state.current_picture--;
break;
case XK_Right:
state.current_picture++;
break;
default:
fprintf( stderr, "key %d hit\n", key );
break;
}
}

Expand Down
5 changes: 3 additions & 2 deletions decoderop.hpp
Expand Up @@ -4,6 +4,7 @@
class DecoderOperation;
class DecoderState;

#include <X11/Xlib.h>
#include "decoder.hpp"

class DecoderOperation {
Expand All @@ -24,10 +25,10 @@ class SetPictureNumber : public DecoderOperation {

class XKey : public DecoderOperation {
private:
int key;
KeySym key;

public:
XKey( int s_key ) : key( s_key ) {}
XKey( KeySym s_key ) : key( s_key ) {}
~XKey() {}
void execute ( DecoderState &state );
};
Expand Down
23 changes: 5 additions & 18 deletions ogl.cpp
Expand Up @@ -356,27 +356,14 @@ void OpenGLDisplay::makeevent( void )
XFlush( state.display );
}

char OpenGLDisplay::getevent( bool block )
bool OpenGLDisplay::getevent( bool block, XEvent *ev )
{
XEvent myevent;
XExposeEvent *myexpose = (XExposeEvent *)&myevent;
XKeyEvent *mykey = (XKeyEvent *)&myevent;

if ( block || XPending( state.display ) ) {
XNextEvent( state.display, &myevent );

if ( myevent.type == Expose && myexpose->count == 0 ) {
return '@';
} else if ( myevent.type == KeyPress ) {
char key;
KeySym keysym;
if ( XLookupString( mykey, &key, 1, &keysym, NULL ) == 1 ) {
return key;
}
}
XNextEvent( state.display, ev );
return true;
} else {
return false;
}

return 0;
}

void OpcodeState::load_matrix_coefficients( double green[ 3 ],
Expand Down
2 changes: 1 addition & 1 deletion ogl.hpp
Expand Up @@ -58,7 +58,7 @@ class OpenGLDisplay {
uint s_framewidth, uint s_frameheight,
uint s_dispwidth, uint s_dispheight );
~OpenGLDisplay();
char getevent( bool block );
bool getevent( bool block, XEvent *ev );
void makeevent( void );

void loop( void );
Expand Down
29 changes: 14 additions & 15 deletions xeventloop.cpp
@@ -1,6 +1,7 @@
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <X11/Xlib.h>

#include "exceptions.hpp"
#include "xeventloop.hpp"
Expand All @@ -14,7 +15,8 @@ static void *thread_helper( void *xeventloop )
}

XEventLoop::XEventLoop( OpenGLDisplay *s_display )
: opq( 0 ),
: keys( 0 ),
repaints( 0 ),
display( s_display ),
live( true )
{
Expand All @@ -24,23 +26,20 @@ XEventLoop::XEventLoop( OpenGLDisplay *s_display )

void XEventLoop::loop( void )
{
XEvent ev;
XExposeEvent *expose = (XExposeEvent *)&ev;
XKeyEvent *key = (XKeyEvent *)&ev;

while ( 1 ) {
int key = display->getevent( true );
display->getevent( true, &ev );

{
MutexLock x( &mutex );
if ( !live ) {
return;
}
}
{ MutexLock x( &mutex ); if ( !live ) return; }

if ( key ) {
XKey *op = new XKey( key );
try {
opq.enqueue( op );
} catch ( UnixAssertError *e ) {
return;
}
if ( ev.type == Expose && expose->count == 0 ) {
repaints.enqueue( new Repaint() );
} else if ( ev.type == KeyPress ) {
KeySym keysym = XLookupKeysym( key, 0 );
keys.enqueue( new XKey( keysym ) );
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions xeventloop.hpp
Expand Up @@ -6,7 +6,9 @@

class XEventLoop {
private:
Queue<DecoderOperation> opq;
Queue<DecoderOperation> keys;
Queue<DisplayOperation> repaints;

OpenGLDisplay *display;

pthread_t thread_handle;
Expand All @@ -19,7 +21,8 @@ class XEventLoop {
~XEventLoop();

void loop( void );
Queue<DecoderOperation> *get_queue() { return &opq; }
Queue<DecoderOperation> *get_key_queue() { return &keys; }
Queue<DisplayOperation> *get_repaint_queue() { return &repaints; }
};

#endif

0 comments on commit 2631b35

Please sign in to comment.