Changeset 109

Show
Ignore:
Timestamp:
02/05/08 16:40:46 (1 year ago)
Author:
mike
Message:

[new] QDocumentOpenGLView: Play overlay
[new] QDocumentOpenGLView: Saved Image overlay
[fix] QDocumentOpenGLView: updateSavedImage
[fix] QControlTableViewController: updateThumbnails

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QControl/QControlTableViewController.m

    r106 r109  
    248248        NSImage *thumbnail; 
    249249        NSImage *savedImage; 
    250 //      NSBitmapImageRep *bitmapImageRep; 
    251250         
    252251        updateAll = FALSE; 
     
    262261                qDocument = [[NSDocumentController sharedDocumentController] documentForURL:[[[[qControl VMs] objectAtIndex:i] objectForKey:@"Temporary"] objectForKey:@"URL"]]; 
    263262        if (qDocument) { 
    264                         thumbnail = [[[NSImage alloc] initWithSize:NSMakeSize(100.0,  75.0)] autorelease]; 
    265 /*                      if ([[[qDocument screenView] window] isVisible]) { // can't lockfocus on hidden/offscreen view 
    266  
    267                                 [[qDocument screenView] lockFocus]; 
    268                                 bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[[qDocument screenView] bounds]]; 
    269                                 [[qDocument screenView] unlockFocus]; 
    270                                 [thumbnail lockFocus]; 
    271                                 [bitmapImageRep drawInRect:NSMakeRect(0.0, 0.0, 100.0, 75.0)]; 
    272                                 [thumbnail unlockFocus]; 
    273 */ 
    274                                 thumbnail= [(QDocumentOpenGLView *)[qDocument screenView] screenshot:NSMakeSize(100.0, 75.0)]; 
    275 //                      } 
    276                         if (updateAll) { 
    277                                 [VMsImages addObject:thumbnail]; 
    278                                 NSLog(@"UA"); 
    279                         } else {/*if ([[[qDocument screenView] window] isVisible]) { // can't lockfocus on hidden/offscreen view, so keep old image*/ 
    280                                 [VMsImages replaceObjectAtIndex:i withObject:thumbnail]; 
     263                        switch ([qDocument VMState]) { 
     264                                case QDocumentPaused: 
     265                                case QDocumentRunning: 
     266                                case QDocumentSaving: 
     267                                        thumbnail = [(QDocumentOpenGLView *)[qDocument screenView] screenshot:NSMakeSize(100.0, 75.0)]; 
     268                                        [VMsImages replaceObjectAtIndex:i withObject:thumbnail]; 
     269                                        break; 
     270                                default: 
     271                                        if (updateAll) { 
     272                                                savedImage = [[[NSImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/QuickLook/Thumbnail.png", [[[[[qControl VMs] objectAtIndex:i] objectForKey:@"Temporary"] objectForKey:@"URL"] path]]] autorelease]; 
     273                                                if (savedImage) { 
     274                                                        thumbnail = [[[NSImage alloc] initWithSize:NSMakeSize(100.0,  75.0)] autorelease]; 
     275                                                        [thumbnail lockFocus]; 
     276                                                        [savedImage drawInRect:NSMakeRect(0.0, 0.0, 100.0, 75.0) fromRect:NSMakeRect(0.0, 0.0, [savedImage size].width, [savedImage size].height) operation:NSCompositeSourceOver fraction:1.0]; 
     277                                                        [thumbnail unlockFocus]; 
     278                                                } else { 
     279                                                        [VMsImages addObject:[NSImage imageNamed: @"q_table_shutdown.png"]]; 
     280                                                } 
     281                                                [VMsImages addObject:thumbnail]; 
     282                                        } 
     283                                        break; 
    281284                        } 
    282285        } else if (updateAll) { 
  • trunk/QDocument/QDocument.m

    r106 r109  
    180180    [super windowControllerDidLoadNib:aController]; 
    181181    // Add any code here that needs to be executed once the windowController has loaded the document's window. 
    182     [screenView updateSavedImage:self]; 
    183          
     182 
     183//      [screenView updateSavedImage:self]; 
     184 
    184185        // Tiger compatible custom butoonCell 
    185186        [buttonEdit setCell:[[[QButtonCell alloc] initImageCell:[[buttonEdit cell] image] buttonType:QButtonCellAlone target:[[buttonEdit cell] target] action:[[buttonEdit cell] action]] autorelease]]; 
     
    466467                        [self setVMState:QDocumentSaving]; 
    467468            [distributedObject setCommand:'Z' arg1:0 arg2:0 arg3:0 arg4:0]; 
    468 /* 
    469                         [screenView lockFocus]; 
    470                         bitmapImageRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[screenView bounds]]; 
    471                         [screenView unlockFocus]; 
    472 */ 
    473469                        bitmapImageRep = [[[screenView screenshot:NSMakeSize(0,0)] representations] objectAtIndex:0]; 
    474470                        data =[bitmapImageRep representationUsingType: NSPNGFileType properties: nil]; 
     
    477473                                [fileManager createDirectoryAtPath: [NSString stringWithFormat: @"%@/QuickLook", [[[configuration objectForKey:@"Temporary"] objectForKey:@"URL"] path]] withIntermediateDirectories: NO attributes: nil error: NULL]; 
    478474                        [data writeToFile: [NSString stringWithFormat: @"%@/QuickLook/Thumbnail.png", [[[configuration objectForKey:@"Temporary"] objectForKey:@"URL"] path]] atomically: YES]; 
    479 //            [bitmapImageRep release]; 
    480475                        [screenView updateSavedImage:self]; 
    481476        } else if (returnCode == NSAlertOtherReturn) { // shutdown 
  • trunk/QDocument/QDocumentOpenGLView.h

    r106 r109  
    4242        int bitsPerComponent; 
    4343        int bitsPerPixel; 
     44        size_t screenBufferSize; 
    4445} QScreen; 
    4546 
     
    5455} QDisplayProperties; 
    5556 
     57typedef enum { 
     58        QDocumentOpenGLTextureScreen = 0, 
     59        QDocumentOpenGLTextureOverlay = 1, 
     60        QDocumentOpenGLTextureSavedImage = 2 
     61} QDocumentOpenGLTextures; 
     62 
    5663@interface QDocumentOpenGLView : NSOpenGLView 
    5764{ 
    5865    IBOutlet QDocument *document; 
    5966    IBOutlet NSWindow *normalWindow; 
    60         CGImageRef savedImageRef; 
    6167    NSWindow *fullScreenWindow; 
    6268    QScreen screenProperties; 
     
    6571    id fullscreenController; 
    6672 
    67         GLuint screen_tex; 
    68         GLuint overlay_tex; 
     73        GLuint textures[3]; 
    6974 
    7075    int modifiers_state[256]; 
     
    7681} 
    7782// saved image and screenshot 
     83- (GLuint) createTextureFromImagePath:(NSString *)path; 
    7884- (void) updateSavedImage:(id)sender; 
    7985- (NSImage *) screenshot:(NSSize)size; 
    80 - (void) loadOverlay; 
    8186 
    8287// QEMU 
  • trunk/QDocument/QDocumentOpenGLView.m

    r106 r109  
    247247    [self unregisterDraggedTypes]; 
    248248 
    249     if (screenBuffer) 
    250         munmap(screenBuffer, screenProperties.width * 4 * screenProperties.height); 
     249    if (screenProperties.screenBufferSize > 0) { 
     250                if (munmap(screenBuffer, screenProperties.screenBufferSize) == -1) { 
     251                        int errsv = errno; 
     252                        NSLog(@"QDocumentOpenGLView: dealloc: could not munmap:  errno(%D) - %s", errsv, strerror(errsv)); 
     253                        screenProperties.screenBufferSize; 
     254                } 
     255        } 
    251256 
    252257    [super dealloc]; 
     
    256261{ 
    257262        Q_DEBUG(@"awakeFromNib"); 
    258          
    259     // set screen properties and resize to initial value 
     263 
     264       // set screen properties and resize to initial value 
    260265    screenProperties.bitsPerComponent = 8; 
    261266    screenProperties.bitsPerPixel = 32; 
    262267        screenProperties.width = 640; 
    263268        screenProperties.height = 480; 
     269        screenProperties.screenBufferSize = 0; 
    264270         
    265271        displayProperties.zoom = 1.0; 
    266  
    267         [self resizeContentToWidth:screenProperties.width height:screenProperties.height]; 
     272         
     273        // initialize OpenGL and load play overlay 
     274        [self prepareOpenGL]; 
     275        [self updateSavedImage:self]; 
     276        textures[QDocumentOpenGLTextureOverlay] = [self createTextureFromImagePath:[NSString stringWithFormat:@"%@/q_overlay_play.png", [[NSBundle mainBundle] resourcePath]]]; 
    268277 
    269278    // enable drag'n'drop for files 
     
    273282    mouseGrabed = FALSE; // we start non grabbed 
    274283    is_graphic_console = TRUE; // we start in grafic mode 
    275          
    276         // load Texture 
    277         [self loadOverlay]; 
    278284} 
    279285 
     
    299305    onePixel[0] = 2.0 / displayProperties.width; 
    300306    onePixel[1] = 2.0 / displayProperties.height; 
    301  
    302     if ((int)screenBuffer != -1) { 
     307         
     308        if ([document VMState] == QDocumentSaved) { 
     309 
     310                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
     311                glClearColor(1.0, 1.0, 1.0, 1.0); 
     312 
     313                // draw saved image 
     314                if (textures[QDocumentOpenGLTextureSavedImage] != 0) { 
     315                        glEnable(GL_TEXTURE_RECTANGLE_ARB); 
     316                        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures[QDocumentOpenGLTextureSavedImage]); // Select the Texture 
     317                        glBegin(GL_QUADS); 
     318                        { 
     319                        glTexCoord2f((GLfloat)screenProperties.width, (GLfloat)screenProperties.height); glVertex2f(1.0f, -1.0f); 
     320                        glTexCoord2f(0.0f, (GLfloat)screenProperties.height); glVertex2f(-1.0f, -1.0f); 
     321                        glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, 1.0f); 
     322                        glTexCoord2f((GLfloat)screenProperties.width, 0.0f); glVertex2f(1.0f, 1.0f); 
     323                        } 
     324                        glEnd(); 
     325                        glDisable(GL_TEXTURE_RECTANGLE_ARB); 
     326                } 
     327 
     328    } else if ((int)screenBuffer != -1) { 
    303329 
    304330                // remove old texture 
    305                 if( screen_tex != 0) { 
    306                         glDeleteTextures(1, &screen_tex); 
     331                if( textures[QDocumentOpenGLTextureScreen] != 0) { 
     332                        glDeleteTextures(1, &textures[QDocumentOpenGLTextureScreen]); 
    307333                } 
    308334 
    309                 screen_tex = 1; 
     335                textures[QDocumentOpenGLTextureScreen] = 1; 
    310336                 
    311337                //calculate the texure rect 
     
    332358                glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Sets the byte-aligned unpacking that's needed for bitmaps that are 3 bytes per pixel. 
    333359 
    334                 glBindTexture (GL_TEXTURE_RECTANGLE_ARB, screen_tex); // Binds the texture name to the texture target. 
     360                glBindTexture (GL_TEXTURE_RECTANGLE_ARB, textures[QDocumentOpenGLTextureScreen]); // Binds the texture name to the texture target. 
    335361                glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Sets filtering so that it does not use a mipmap, which would be redundant for the texture rectangle extension 
    336362 
     
    358384                glBegin(GL_QUADS); 
    359385                { 
    360                 glTexCoord2f(0.0f, 0.0f); 
    361                 glVertex2f(-1.0f, (GLfloat)(onePixel[1] * (rect.origin.y + rect.size.height) - 1.0)); 
    362  
    363                 glTexCoord2f(0.0f, (GLfloat)clipRect.size.height); 
    364                 glVertex2f(-1.0f, (GLfloat)(onePixel[1] * rect.origin.y - 1.0)); 
    365  
    366                 glTexCoord2f((GLfloat)clipRect.size.width, (GLfloat)clipRect.size.height); 
    367                 glVertex2f(1.0f, (GLfloat)(onePixel[1] * rect.origin.y - 1.0)); 
    368  
    369                 glTexCoord2f((GLfloat)clipRect.size.width, 0.0f); 
    370                 glVertex2f(1.0f, (GLfloat)(onePixel[1] * (rect.origin.y + rect.size.height) - 1.0)); 
     386                glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, (GLfloat)(onePixel[1] * (rect.origin.y + rect.size.height) - 1.0)); 
     387                glTexCoord2f(0.0f, (GLfloat)clipRect.size.height); glVertex2f(-1.0f, (GLfloat)(onePixel[1] * rect.origin.y - 1.0)); 
     388                glTexCoord2f((GLfloat)clipRect.size.width, (GLfloat)clipRect.size.height); glVertex2f(1.0f, (GLfloat)(onePixel[1] * rect.origin.y - 1.0)); 
     389                glTexCoord2f((GLfloat)clipRect.size.width, 0.0f); glVertex2f(1.0f, (GLfloat)(onePixel[1] * (rect.origin.y + rect.size.height) - 1.0)); 
    371390                } 
    372391                glEnd(); 
     392                glDisable( GL_TEXTURE_RECTANGLE_ARB ); 
    373393 
    374394        } else { 
     
    383403 
    384404                glBegin(GL_QUAD_STRIP); 
    385  
    386                 glVertex2f(-1.0, -1.0); 
    387                 glVertex2f(3 * onePixel[0] - 1, 3 * onePixel[1] - 1); 
    388  
    389                 glVertex2f(1.0, -1.0); 
    390                 glVertex2f((rect.size.width - 3) * onePixel[0] - 1, 3 * onePixel[1] - 1); 
    391  
    392                 glVertex2f(1.0, 1.0); 
    393                 glVertex2f(([self bounds].size.width - 3) * onePixel[0] - 1, ([self bounds].size.height - 3) * onePixel[1] - 1); 
    394  
    395                 glVertex2f(-1.0, 1.0); 
    396                 glVertex2f(3 * onePixel[0] - 1, ([self bounds].size.height - 3) * onePixel[1] - 1); 
    397  
    398                 glVertex2f(-1.0, -1.0); 
    399                 glVertex2f(3 * onePixel[0] - 1, 3 * onePixel[1] - 1); 
    400  
     405                { 
     406                glVertex2f(-1.0, -1.0); glVertex2f(3 * onePixel[0] - 1, 3 * onePixel[1] - 1); 
     407                glVertex2f(1.0, -1.0); glVertex2f((rect.size.width - 3) * onePixel[0] - 1, 3 * onePixel[1] - 1); 
     408                glVertex2f(1.0, 1.0); glVertex2f(([self bounds].size.width - 3) * onePixel[0] - 1, ([self bounds].size.height - 3) * onePixel[1] - 1); 
     409                glVertex2f(-1.0, 1.0); glVertex2f(3 * onePixel[0] - 1, ([self bounds].size.height - 3) * onePixel[1] - 1); 
     410                glVertex2f(-1.0, -1.0); glVertex2f(3 * onePixel[0] - 1, 3 * onePixel[1] - 1); 
     411                } 
    401412                glEnd(); 
    402413        } 
    403 /* 
     414 
    404415        // play overlay 
    405416        if ([document VMState] != QDocumentRunning) { 
    406417 
     418                // draw background 
    407419                glEnable(GL_BLEND); 
    408                 glBlendFunc(GL_SRC_ALPHA,GL_ONE); 
     420                glBlendFunc(GL_SRC_ALPHA, GL_ONE); 
    409421                glBegin(GL_QUADS); 
    410422                { 
    411                 glColor4f(1.0f, 1.0f, 1.0f, 0.25f); 
     423                glColor4f(1.0f, 1.0f, 1.0f, .25f); 
    412424                glVertex2f(-1.0, -1.0); 
    413425                glVertex2f(1.0, -1.0); 
     
    416428                } 
    417429                glEnd(); 
    418                 glDisable(GL_BLEND); 
    419  
    420                 glBindTexture(GL_TEXTURE_2D, overlay_tex); // Select the Texture 
     430 
     431                // draw overlay 
     432                glEnable(GL_TEXTURE_RECTANGLE_ARB); 
     433                glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 
     434                glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures[QDocumentOpenGLTextureOverlay]); // Select the Texture 
    421435                glBegin(GL_QUADS); 
    422436                { 
    423                 glTexCoord2f(0.0f, 0.0f); 
    424                 glVertex2f(-onePixel[0] * 100.0f, onePixel[1] * 100.0f); 
    425  
    426                 glTexCoord2f(0.0f, 200.0f); 
    427                 glVertex2f(-onePixel[0] * 100.0f, -onePixel[1] * 100.0f); 
    428  
    429                 glTexCoord2f(200.0f, 200.0f); 
    430                 glVertex2f(onePixel[0] * 100.0f, -onePixel[1] * 100.0f); 
    431  
    432                 glTexCoord2f(200.0f, 0.0f); 
    433                 glVertex2f(onePixel[0] * 100.0f, onePixel[1] * 100.0f); 
     437                glTexCoord2f(0.0f, 200.0f); glVertex2f(-onePixel[0] * 100.0f, -onePixel[1] * 100.0f); 
     438                glTexCoord2f(200.0f, 200.0f); glVertex2f(onePixel[0] * 100.0f, -onePixel[1] * 100.0f); 
     439                glTexCoord2f(200.0f, 0.0f); glVertex2f(onePixel[0] * 100.0f, onePixel[1] * 100.0f); 
     440                glTexCoord2f(0.0f, 0.0f); glVertex2f(-onePixel[0] * 100.0f, onePixel[1] * 100.0f); 
    434441                } 
    435442                glEnd(); 
     443                glDisable(GL_BLEND); 
     444                glDisable(GL_TEXTURE_RECTANGLE_ARB); 
     445 
    436446        } 
    437 */ 
     447 
    438448    glFlush(); 
    439449} 
     
    442452 
    443453#pragma mark saved image and screenshots 
     454- (GLuint) createTextureFromImagePath:(NSString *)path 
     455{ 
     456        Q_DEBUG(@"loadTextureFromImagePath: %@", path); 
     457 
     458        GLuint texture; 
     459        CGImageSourceRef sourceRef; 
     460        CGImageRef imageRef; 
     461        CGColorSpaceRef colorSpaceRef; 
     462        CGContextRef contextRef; 
     463        void * textureData; 
     464        CGRect textureRect; 
     465        size_t textureWidth; 
     466        size_t textureHeight; 
     467 
     468        sourceRef = CGImageSourceCreateWithURL((CFURLRef)[NSURL fileURLWithPath:path], NULL); 
     469        if (!sourceRef) 
     470                return 0; 
     471 
     472        imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL); 
     473        textureWidth = CGImageGetWidth(imageRef); 
     474    textureHeight = CGImageGetHeight(imageRef); 
     475        textureRect = CGRectMake(0, 0, textureWidth, textureHeight); 
     476        textureData = calloc(textureWidth * 4, textureHeight); 
     477        colorSpaceRef = CGColorSpaceCreateDeviceRGB(); 
     478        contextRef = CGBitmapContextCreate (textureData, textureWidth, textureHeight, 8, textureWidth*4, colorSpaceRef, kCGImageAlphaPremultipliedLast); 
     479 
     480        CGContextDrawImage(contextRef, textureRect, imageRef); 
     481        CGContextRelease(contextRef); 
     482        CFRelease(imageRef); 
     483        CFRelease(sourceRef); 
     484 
     485        glPixelStorei(GL_UNPACK_ROW_LENGTH, textureWidth); 
     486        glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
     487        glGenTextures(1, &texture); 
     488        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture); 
     489        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
     490        glTexImage2D( 
     491                GL_TEXTURE_RECTANGLE_ARB, 
     492                0, 
     493                GL_RGBA8, 
     494                textureWidth, 
     495                textureHeight, 
     496                0, 
     497#if __LITTLE_ENDIAN__ 
     498                GL_RGBA, 
     499                GL_UNSIGNED_BYTE, 
     500#else 
     501                GL_BGRA, 
     502                GL_UNSIGNED_INT_8_8_8_8_REV, 
     503#endif 
     504                textureData); 
     505 
     506        free(textureData); 
     507 
     508        return texture; 
     509} 
     510 
    444511- (void) updateSavedImage:(id)sender 
    445512{ 
    446         Q_DEBUG(@"setSavedImage"); 
    447  
    448         CGImageSourceRef sourceRef; 
    449         NSURL *url; 
     513        Q_DEBUG(@"loadTextures"); 
    450514         
    451         if (savedImageRef) 
    452                 CGImageRelease(savedImageRef); 
    453  
    454         url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/QuickLook/Thumbnail.png", [[[[document configuration] objectForKey:@"Temporary"] objectForKey:@"URL"] path]]]; 
    455         sourceRef = CGImageSourceCreateWithURL((CFURLRef)url, NULL); 
    456         if (sourceRef) { 
    457                 savedImageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL); 
    458                 CFRelease(sourceRef); 
    459  
    460                 if (savedImageRef) { 
    461                         screenProperties.width = CGImageGetWidth(savedImageRef); 
    462                         screenProperties.height = CGImageGetHeight(savedImageRef); 
    463                         [self resizeContentToWidth:screenProperties.width height:screenProperties.height]; 
    464                 } 
     515         
     516        [[self openGLContext] makeCurrentContext]; 
     517         
     518        // remove old texture 
     519        if( textures[QDocumentOpenGLTextureSavedImage] != 0) { 
     520                glDeleteTextures(1, &textures[QDocumentOpenGLTextureSavedImage]); 
    465521        } 
     522 
     523        textures[QDocumentOpenGLTextureSavedImage] = [self createTextureFromImagePath:[NSString stringWithFormat:@"%@/QuickLook/Thumbnail.png", [[[[document configuration] objectForKey:@"Temporary"] objectForKey:@"URL"] path]]]; 
     524        if (textures[QDocumentOpenGLTextureSavedImage] != 0) { 
     525                glBindTexture(GL_TEXTURE_RECTANGLE_ARB, textures[QDocumentOpenGLTextureSavedImage]); 
     526                glGetTexLevelParameteriv( GL_TEXTURE_RECTANGLE_ARB, 0, GL_TEXTURE_WIDTH, (GLint*)&screenProperties.width ); 
     527                glGetTexLevelParameteriv( GL_TEXTURE_RECTANGLE_ARB, 0, GL_TEXTURE_HEIGHT, (GLint*)&screenProperties.height );    
     528        } 
     529        [self resizeContentToWidth:screenProperties.width height:screenProperties.height]; 
    466530} 
    467531 
    468532- (NSImage *) screenshot:(NSSize)size 
    469533{ 
    470 //      NSLog(@"quartzView: Thumbnail width:%d height:%d\n", (int)size.width, (int)size.height); 
    471  
    472         /* if no size is set, make fullsize shot */ 
    473         if (!size.width || !size.height) 
    474                 size = [self bounds].size; 
     534        Q_DEBUG(@"screenshot NSSize(%f,  %f)", size.width, size.height); 
    475535 
    476536        NSBitmapImageRep* sBitmapImageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL 
     
    527587} 
    528588 
    529 - (void) loadOverlay 
    530 { 
    531 /* 
    532         CGImageSourceRef sourceRef; 
    533         NSURL *url; 
    534         CGImageRef overlayImageRef; 
    535         url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/q_overlay_play.png", [[NSBundle mainBundle] resourcePath]]]; 
    536         sourceRef = CGImageSourceCreateWithURL((CFURLRef)url, NULL); 
    537         if (sourceRef) { 
    538                 overlayImageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL); 
    539                 CFRelease(sourceRef); 
    540  
    541                 size_t width = CGImageGetWidth(overlayImageRef); 
    542                 size_t height = CGImageGetHeight(overlayImageRef); 
    543                 CGRect rect = {{0, 0}, {width, height}}; 
    544                 void * myData = calloc(width * 4, height); 
    545                 CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); 
    546                 CGContextRef myBitmapContext = CGBitmapContextCreate (myData, 
    547                         width, height, 8, 
    548                         width*4, space, 
    549                         kCGImageAlphaPremultipliedFirst); 
    550                 CGContextDrawImage(myBitmapContext, rect, overlayImageRef); 
    551                 CGContextRelease(myBitmapContext); 
    552  
    553                 glPixelStorei(GL_UNPACK_ROW_LENGTH, width); 
    554                 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 
    555                 glGenTextures(1, &overlay_tex); 
    556                 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, overlay_tex); 
    557                 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    558                 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, width, height, 0, GL_BGRA_EXT, GL_UNSIGNED_INT_8_8_8_8_REV, myData); 
    559                 free(myData); 
    560         } 
    561 */ 
    562         NSImage *overlay = [NSImage imageNamed:@"q_overlay_play.png"]; 
    563         NSBitmapImageRep *bitmapImageRep = [[overlay representations] objectAtIndex:0]; 
    564  
    565         glGenTextures(1, &overlay_tex);                                 //Create The Texture 
    566         glBindTexture(GL_TEXTURE_2D, overlay_tex);              //Typical Texture Generation Using Data From The Bitmap 
    567         glTexImage2D(                                                                   //Generate The Texture 
    568                 GL_TEXTURE_2D,                                                          //kind of texture 
    569                 0,                                                                                      //Level of detail 
    570                 [bitmapImageRep samplesPerPixel],               //Number of Data Components (rgb/rgba etc) 
    571                 [bitmapImageRep bytesPerRow] / [bitmapImageRep samplesPerPixel],        //width 
    572                 [bitmapImageRep bytesPerPlane] / [bitmapImageRep bytesPerRow],  //height 
    573                 0,                                                                                      //border width 
    574                 GL_RGBA,                                                                        //color components order 
    575                 GL_UNSIGNED_BYTE,                                                       //kind of data 
    576                 [bitmapImageRep bitmapData]                     //pointer to data 
    577         ); 
    578         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //Linear Filtering 
    579         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //Linear Filtering 
    580 } 
    581  
    582589 
    583590 
     
    644651 
    645652    [[self openGLContext] makeCurrentContext]; 
    646     glViewport(0, 0, displayProperties.width, displayProperties.height); 
    647     [self update]; 
     653    glViewport(0.0, 0.0, displayProperties.width, displayProperties.height); 
     654    [self display]; 
    648655} 
    649656 
     
    751758    // screenbuffer with mmap 
    752759    int fd; 
    753     if (screenBuffer) 
    754         munmap(screenBuffer, screenProperties.width * 4 * screenProperties.height); 
     760    if (screenProperties.screenBufferSize > 0) { 
     761        if (munmap(screenBuffer, screenProperties.screenBufferSize) == -1) { 
     762                        int errsv = errno; 
     763                        NSLog(@"QDocumentOpenGLView: resizeContent: could not munmap:  errno(%D) - %s", errsv, strerror(errsv)); 
     764                        screenProperties.screenBufferSize; 
     765                        return; 
     766                } 
     767        } 
    755768    fd = open([[NSString stringWithFormat:@"/private/tmp/qDocument_%D.vga", [document uniqueDocumentID]] cString], O_RDONLY); // open file 
    756     if(fd == -1) 
    757         NSLog(@"QDocumentQuartzView: resizeContent: could not open '/private/tmp/qDocument_%D.vga'", [document uniqueDocumentID]); 
    758     screenBuffer = mmap(0, w * 4 * h, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0); 
    759     if(!screenBuffer) 
    760         NSLog(@"QDocumentQuartzView: resizeContent: could not mmap '/private/tmp/qDocument_%D.vga'", [document uniqueDocumentID]); 
    761     close(fd); 
     769    if(fd == -1) { 
     770                int errsv = errno; 
     771        NSLog(@"QDocumentOpenGLView: resizeContent: could not open '/private/tmp/qDocument_%D.vga': errno(%D) - %s", [document uniqueDocumentID], errsv, strerror(errsv)); 
     772                screenProperties.screenBufferSize = 0; 
     773                return; 
     774    } 
     775        screenProperties.screenBufferSize = w * 4 * h; 
     776        screenBuffer = mmap(0, screenProperties.screenBufferSize, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0); 
     777    if(screenBuffer == MAP_FAILED) { 
     778                int errsv = errno; 
     779        NSLog(@"QDocumentOpenGLView: resizeContent: could not mmap '/private/tmp/qDocument_%D.vga': errno(%D) - %s", [document uniqueDocumentID], errsv, strerror(errsv)); 
     780                screenProperties.screenBufferSize = 0; 
     781                close(fd); 
     782                return; 
     783    } 
     784        close(fd); 
    762785 
    763786    // update screen state