[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx:[576] trunk/fuse/fusepb/views
Brought to you by:
fredm
From: <fr...@us...> - 2008-12-17 23:31:10
|
Revision: 576 http://fuse-for-macosx.svn.sourceforge.net/fuse-for-macosx/?rev=576&view=rev Author: fredm Date: 2008-12-17 23:31:08 +0000 (Wed, 17 Dec 2008) Log Message: ----------- Decouple texture updating and drawing and only update texture when there are changes (Roine Gustafsson). Modified Paths: -------------- trunk/fuse/fusepb/views/DisplayOpenGLView.h trunk/fuse/fusepb/views/DisplayOpenGLView.m Modified: trunk/fuse/fusepb/views/DisplayOpenGLView.h =================================================================== --- trunk/fuse/fusepb/views/DisplayOpenGLView.h 2008-12-17 22:38:04 UTC (rev 575) +++ trunk/fuse/fusepb/views/DisplayOpenGLView.h 2008-12-17 23:31:08 UTC (rev 576) @@ -61,7 +61,6 @@ ui_statusbar_state disk_state; ui_statusbar_state mdr_state; ui_statusbar_state tape_state; - BOOL statusbar_updated; NSLock *view_lock; Modified: trunk/fuse/fusepb/views/DisplayOpenGLView.m =================================================================== --- trunk/fuse/fusepb/views/DisplayOpenGLView.m 2008-12-17 22:38:04 UTC (rev 575) +++ trunk/fuse/fusepb/views/DisplayOpenGLView.m 2008-12-17 23:31:08 UTC (rev 576) @@ -119,9 +119,6 @@ [self displayLinkStart]; - [view_lock lock]; - statusbar_updated = YES; - [view_lock unlock]; [[FuseController singleton] releaseCmdKeys:@"f":QZ_f]; } @@ -195,7 +192,6 @@ instance = self; buffered_screen_lock = [[NSLock alloc] init]; - [buffered_screen_lock retain]; real_emulator = [[Emulator alloc] init]; } @@ -252,18 +248,28 @@ currentScreenTex = 0; - statusbar_updated = NO; - return self; } +-(void)dealloc +{ + if (view_lock) + [view_lock release]; + view_lock = nil; + + if (buffered_screen_lock) + [buffered_screen_lock release]; + buffered_screen_lock = nil; + + [super dealloc]; +} + -(void) awakeFromNib { /* keep the window in the standard aspect ratio if the user resizes */ [[self window] setContentAspectRatio:NSMakeSize(4.0,3.0)]; view_lock = [[NSLock alloc] init]; - [view_lock retain]; CVReturn error = kCVReturnSuccess; CGDirectDisplayID displayID = CGMainDisplayID(); @@ -308,9 +314,6 @@ [greenDisk release]; greenDisk = nil; - [buffered_screen_lock release]; - buffered_screen_lock = nil; - [self release]; } @@ -412,40 +415,17 @@ -(void) drawRect:(NSRect)aRect { - int i; - PIG_dirtytable *workdirty = NULL; + [view_lock lock]; - [view_lock lock]; - [buffered_screen_lock lock]; - if( NO == screenTexInitialised ) { - [buffered_screen_lock unlock]; + [[self openGLContext] makeCurrentContext]; + + if (!screenTexInitialised) { + glClear(GL_COLOR_BUFFER_BIT); + [view_lock unlock]; return; } - if( screenTex[currentScreenTex].dirty ) - pig_dirty_copy( &workdirty, screenTex[currentScreenTex].dirty ); - - currentScreenTex = !currentScreenTex; - - pig_dirty_copy( &screenTex[currentScreenTex].dirty, buffered_screen.dirty ); - - if( workdirty ) - pig_dirty_merge(workdirty, screenTex[currentScreenTex].dirty); - else - pig_dirty_copy(&workdirty, screenTex[currentScreenTex].dirty); - - /* Draw texture to screen */ - for(i = 0; i < workdirty->count; ++i) - copy_area( &screenTex[currentScreenTex], &buffered_screen, - workdirty->rects + i ); - - buffered_screen.dirty->count = 0; - - pig_dirty_close( workdirty ); - - [[self openGLContext] makeCurrentContext]; - int border_x_offset = 0; int border_y_offset = 0; if( settings_current.full_screen && settings_current.full_screen_panorama ) { @@ -472,15 +452,8 @@ /* Bind, update and draw new image */ glBindTexture( GL_TEXTURE_RECTANGLE_ARB, screenTexId[currentScreenTex] ); - - glTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, - screenTex[currentScreenTex].full_width, - screenTex[currentScreenTex].full_height, GL_BGRA, - GL_UNSIGNED_SHORT_1_5_5_5_REV, - screenTex[currentScreenTex].pixels ); - + glBegin( GL_QUADS ); - glTexCoord2f( (float)(screenTex[currentScreenTex].image_width + screenTex[currentScreenTex].image_xoffset + border_y_offset), (float)(screenTex[currentScreenTex].image_yoffset + border_x_offset) @@ -504,7 +477,6 @@ (float)(screenTex[currentScreenTex].image_yoffset + border_x_offset) ); glVertex2f( -1.0f, 1.0f ); - glEnd(); if ( settings_current.statusbar ) [self iconOverlay]; @@ -512,9 +484,6 @@ /* Swap buffer to screen */ [[self openGLContext] flushBuffer]; - statusbar_updated = NO; - - [buffered_screen_lock unlock]; [view_lock unlock]; } @@ -559,7 +528,6 @@ glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); - statusbar_updated = YES; [view_lock unlock]; } @@ -567,12 +535,11 @@ { GLuint i; - [view_lock lock]; - if( screenTexInitialised == NO) { - [view_lock unlock]; + if (!screenTexInitialised) return; - } + [view_lock lock]; + [self displayLinkStop]; glDeleteTextures( MAX_SCREEN_BUFFERS, screenTexId ); @@ -993,27 +960,18 @@ -(void) setDiskState:(NSNumber*)state { disk_state = [state unsignedCharValue]; - [view_lock lock]; - statusbar_updated = YES; - [view_lock unlock]; [[FuseController singleton] setDiskState:state]; } -(void) setTapeState:(NSNumber*)state { tape_state = [state unsignedCharValue]; - [view_lock lock]; - statusbar_updated = YES; - [view_lock unlock]; [[FuseController singleton] setTapeState:state]; } -(void) setMdrState:(NSNumber*)state { mdr_state = [state unsignedCharValue]; - [view_lock lock]; - statusbar_updated = YES; - [view_lock unlock]; [[FuseController singleton] setMdrState:state]; } @@ -1244,7 +1202,52 @@ -(CVReturn) displayFrame:(const CVTimeStamp *)timeStamp { + int i; + PIG_dirtytable *workdirty = NULL; + + [buffered_screen_lock lock]; + if( buffered_screen.dirty->count == 0 ) { + [buffered_screen_lock unlock]; + return kCVReturnSuccess; + } + + if (screenTex[currentScreenTex].dirty) + pig_dirty_copy( &workdirty, screenTex[currentScreenTex].dirty ); + + currentScreenTex = !currentScreenTex; + + pig_dirty_copy( &screenTex[currentScreenTex].dirty, buffered_screen.dirty ); + + if( workdirty ) + pig_dirty_merge(workdirty, screenTex[currentScreenTex].dirty); + else + pig_dirty_copy(&workdirty, screenTex[currentScreenTex].dirty); + + /* Draw texture to screen */ + for(i = 0; i < workdirty->count; ++i) + copy_area( &screenTex[currentScreenTex], &buffered_screen, + workdirty->rects + i ); + + buffered_screen.dirty->count = 0; + + pig_dirty_close( workdirty ); + + [[self openGLContext] makeCurrentContext]; + + /* Bind, update and draw new image */ + glBindTexture( GL_TEXTURE_RECTANGLE_ARB, screenTexId[currentScreenTex] ); + + glTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, + screenTex[currentScreenTex].full_width, + screenTex[currentScreenTex].full_height, GL_BGRA, + GL_UNSIGNED_SHORT_1_5_5_5_REV, + screenTex[currentScreenTex].pixels ); + + [buffered_screen_lock unlock]; + + NSAutoreleasePool *pool = [NSAutoreleasePool new]; [self drawRect:NSZeroRect]; + [pool release]; return kCVReturnSuccess; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |