| |
Changeset 109
- 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
| r106 |
r109 |
|
| 248 | 248 | NSImage *thumbnail; |
|---|
| 249 | 249 | NSImage *savedImage; |
|---|
| 250 | | // NSBitmapImageRep *bitmapImageRep; |
|---|
| 251 | 250 | |
|---|
| 252 | 251 | updateAll = FALSE; |
|---|
| … | … | |
| 262 | 261 | qDocument = [[NSDocumentController sharedDocumentController] documentForURL:[[[[qControl VMs] objectAtIndex:i] objectForKey:@"Temporary"] objectForKey:@"URL"]]; |
|---|
| 263 | 262 | 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; |
|---|
| 281 | 284 | } |
|---|
| 282 | 285 | } else if (updateAll) { |
|---|
| r106 |
r109 |
|
| 180 | 180 | [super windowControllerDidLoadNib:aController]; |
|---|
| 181 | 181 | // 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 | |
|---|
| 184 | 185 | // Tiger compatible custom butoonCell |
|---|
| 185 | 186 | [buttonEdit setCell:[[[QButtonCell alloc] initImageCell:[[buttonEdit cell] image] buttonType:QButtonCellAlone target:[[buttonEdit cell] target] action:[[buttonEdit cell] action]] autorelease]]; |
|---|
| … | … | |
| 466 | 467 | [self setVMState:QDocumentSaving]; |
|---|
| 467 | 468 | [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 | | */ |
|---|
| 473 | 469 | bitmapImageRep = [[[screenView screenshot:NSMakeSize(0,0)] representations] objectAtIndex:0]; |
|---|
| 474 | 470 | data =[bitmapImageRep representationUsingType: NSPNGFileType properties: nil]; |
|---|
| … | … | |
| 477 | 473 | [fileManager createDirectoryAtPath: [NSString stringWithFormat: @"%@/QuickLook", [[[configuration objectForKey:@"Temporary"] objectForKey:@"URL"] path]] withIntermediateDirectories: NO attributes: nil error: NULL]; |
|---|
| 478 | 474 | [data writeToFile: [NSString stringWithFormat: @"%@/QuickLook/Thumbnail.png", [[[configuration objectForKey:@"Temporary"] objectForKey:@"URL"] path]] atomically: YES]; |
|---|
| 479 | | // [bitmapImageRep release]; |
|---|
| 480 | 475 | [screenView updateSavedImage:self]; |
|---|
| 481 | 476 | } else if (returnCode == NSAlertOtherReturn) { // shutdown |
|---|
| r106 |
r109 |
|
| 42 | 42 | int bitsPerComponent; |
|---|
| 43 | 43 | int bitsPerPixel; |
|---|
| | 44 | size_t screenBufferSize; |
|---|
| 44 | 45 | } QScreen; |
|---|
| 45 | 46 | |
|---|
| … | … | |
| 54 | 55 | } QDisplayProperties; |
|---|
| 55 | 56 | |
|---|
| | 57 | typedef enum { |
|---|
| | 58 | QDocumentOpenGLTextureScreen = 0, |
|---|
| | 59 | QDocumentOpenGLTextureOverlay = 1, |
|---|
| | 60 | QDocumentOpenGLTextureSavedImage = 2 |
|---|
| | 61 | } QDocumentOpenGLTextures; |
|---|
| | 62 | |
|---|
| 56 | 63 | @interface QDocumentOpenGLView : NSOpenGLView |
|---|
| 57 | 64 | { |
|---|
| 58 | 65 | IBOutlet QDocument *document; |
|---|
| 59 | 66 | IBOutlet NSWindow *normalWindow; |
|---|
| 60 | | CGImageRef savedImageRef; |
|---|
| 61 | 67 | NSWindow *fullScreenWindow; |
|---|
| 62 | 68 | QScreen screenProperties; |
|---|
| … | … | |
| 65 | 71 | id fullscreenController; |
|---|
| 66 | 72 | |
|---|
| 67 | | GLuint screen_tex; |
|---|
| 68 | | GLuint overlay_tex; |
|---|
| | 73 | GLuint textures[3]; |
|---|
| 69 | 74 | |
|---|
| 70 | 75 | int modifiers_state[256]; |
|---|
| … | … | |
| 76 | 81 | } |
|---|
| 77 | 82 | // saved image and screenshot |
|---|
| | 83 | - (GLuint) createTextureFromImagePath:(NSString *)path; |
|---|
| 78 | 84 | - (void) updateSavedImage:(id)sender; |
|---|
| 79 | 85 | - (NSImage *) screenshot:(NSSize)size; |
|---|
| 80 | | - (void) loadOverlay; |
|---|
| 81 | 86 | |
|---|
| 82 | 87 | // QEMU |
|---|
| r106 |
r109 |
|
| 247 | 247 | [self unregisterDraggedTypes]; |
|---|
| 248 | 248 | |
|---|
| 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 | } |
|---|
| 251 | 256 | |
|---|
| 252 | 257 | [super dealloc]; |
|---|
| … | … | |
| 256 | 261 | { |
|---|
| 257 | 262 | Q_DEBUG(@"awakeFromNib"); |
|---|
| 258 | | |
|---|
| 259 | | // set screen properties and resize to initial value |
|---|
| | 263 | |
|---|
| | 264 | // set screen properties and resize to initial value |
|---|
| 260 | 265 | screenProperties.bitsPerComponent = 8; |
|---|
| 261 | 266 | screenProperties.bitsPerPixel = 32; |
|---|
| 262 | 267 | screenProperties.width = 640; |
|---|
| 263 | 268 | screenProperties.height = 480; |
|---|
| | 269 | screenProperties.screenBufferSize = 0; |
|---|
| 264 | 270 | |
|---|
| 265 | 271 | 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]]]; |
|---|
| 268 | 277 | |
|---|
| 269 | 278 | // enable drag'n'drop for files |
|---|
| … | … | |
| 273 | 282 | mouseGrabed = FALSE; // we start non grabbed |
|---|
| 274 | 283 | is_graphic_console = TRUE; // we start in grafic mode |
|---|
| 275 | | |
|---|
| 276 | | // load Texture |
|---|
| 277 | | [self loadOverlay]; |
|---|
| 278 | 284 | } |
|---|
| 279 | 285 | |
|---|
| … | … | |
| 299 | 305 | onePixel[0] = 2.0 / displayProperties.width; |
|---|
| 300 | 306 | 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) { |
|---|
| 303 | 329 | |
|---|
| 304 | 330 | // remove old texture |
|---|
| 305 | | if( screen_tex != 0) { |
|---|
| 306 | | glDeleteTextures(1, &screen_tex); |
|---|
| | 331 | if( textures[QDocumentOpenGLTextureScreen] != 0) { |
|---|
| | 332 | glDeleteTextures(1, &textures[QDocumentOpenGLTextureScreen]); |
|---|
| 307 | 333 | } |
|---|
| 308 | 334 | |
|---|
| 309 | | screen_tex = 1; |
|---|
| | 335 | textures[QDocumentOpenGLTextureScreen] = 1; |
|---|
| 310 | 336 | |
|---|
| 311 | 337 | //calculate the texure rect |
|---|
| … | … | |
| 332 | 358 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Sets the byte-aligned unpacking that's needed for bitmaps that are 3 bytes per pixel. |
|---|
| 333 | 359 | |
|---|
| 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. |
|---|
| 335 | 361 | 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 |
|---|
| 336 | 362 | |
|---|
| … | … | |
| 358 | 384 | glBegin(GL_QUADS); |
|---|
| 359 | 385 | { |
|---|
| 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)); |
|---|
| 371 | 390 | } |
|---|
| 372 | 391 | glEnd(); |
|---|
| | 392 | glDisable( GL_TEXTURE_RECTANGLE_ARB ); |
|---|
| 373 | 393 | |
|---|
| 374 | 394 | } else { |
|---|
| … | … | |
| 383 | 403 | |
|---|
| 384 | 404 | 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 | } |
|---|
| 401 | 412 | glEnd(); |
|---|
| 402 | 413 | } |
|---|
| 403 | | /* |
|---|
| | 414 | |
|---|
| 404 | 415 | // play overlay |
|---|
| 405 | 416 | if ([document VMState] != QDocumentRunning) { |
|---|
| 406 | 417 | |
|---|
| | 418 | // draw background |
|---|
| 407 | 419 | glEnable(GL_BLEND); |
|---|
| 408 | | glBlendFunc(GL_SRC_ALPHA,GL_ONE); |
|---|
| | 420 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); |
|---|
| 409 | 421 | glBegin(GL_QUADS); |
|---|
| 410 | 422 | { |
|---|
| 411 | | glColor4f(1.0f, 1.0f, 1.0f, 0.25f); |
|---|
| | 423 | glColor4f(1.0f, 1.0f, 1.0f, .25f); |
|---|
| 412 | 424 | glVertex2f(-1.0, -1.0); |
|---|
| 413 | 425 | glVertex2f(1.0, -1.0); |
|---|
| … | … | |
| 416 | 428 | } |
|---|
| 417 | 429 | 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 |
|---|
| 421 | 435 | glBegin(GL_QUADS); |
|---|
| 422 | 436 | { |
|---|
| 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); |
|---|
| 434 | 441 | } |
|---|
| 435 | 442 | glEnd(); |
|---|
| | 443 | glDisable(GL_BLEND); |
|---|
| | 444 | glDisable(GL_TEXTURE_RECTANGLE_ARB); |
|---|
| | 445 | |
|---|
| 436 | 446 | } |
|---|
| 437 | | */ |
|---|
| | 447 | |
|---|
| 438 | 448 | glFlush(); |
|---|
| 439 | 449 | } |
|---|
| … | … | |
| 442 | 452 | |
|---|
| 443 | 453 | #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 | |
|---|
| 444 | 511 | - (void) updateSavedImage:(id)sender |
|---|
| 445 | 512 | { |
|---|
| 446 | | Q_DEBUG(@"setSavedImage"); |
|---|
| 447 | | |
|---|
| 448 | | CGImageSourceRef sourceRef; |
|---|
| 449 | | NSURL *url; |
|---|
| | 513 | Q_DEBUG(@"loadTextures"); |
|---|
| 450 | 514 | |
|---|
| 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]); |
|---|
| 465 | 521 | } |
|---|
| | 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]; |
|---|
| 466 | 530 | } |
|---|
| 467 | 531 | |
|---|
| 468 | 532 | - (NSImage *) screenshot:(NSSize)size |
|---|
| 469 | 533 | { |
|---|
| 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); |
|---|
| 475 | 535 | |
|---|
| 476 | 536 | NSBitmapImageRep* sBitmapImageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL |
|---|
| … | … | |
| 527 | 587 | } |
|---|
| 528 | 588 | |
|---|
| 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 | | |
|---|
| 582 | 589 | |
|---|
| 583 | 590 | |
|---|
| … | … | |
| 644 | 651 | |
|---|
| 645 | 652 | [[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]; |
|---|
| 648 | 655 | } |
|---|
| 649 | 656 | |
|---|
| … | … | |
| 751 | 758 | // screenbuffer with mmap |
|---|
| 752 | 759 | 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 | } |
|---|
| 755 | 768 | 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); |
|---|
| 762 | 785 | |
|---|
| 763 | 786 | // update screen state |
|---|
Download in other formats:
| |