renderspu_cocoa_helper.m revision 129986ce8b48d5e5973ad84edae4465788db89aa
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * VirtualBox OpenGL Cocoa Window System Helper implementation
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * available from http://www.virtualbox.org. This file is free software;
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * you can redistribute it and/or modify it under the terms of the GNU
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * General Public License (GPL) as published by the Free Software
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * additional information or have any questions.
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync#include "chromium.h" /* For the visual bits of chromium */
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync/* Debug macros */
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync#define FBO 1 /* Disable this to see how the output is without the FBO in the middle of the processing chain. */
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync//#define SHOW_WINDOW_BACKGROUND 1 /* Define this to see the window background even if the window is clipped */
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync//#define DEBUG_VERBOSE /* Define this could get some debug info about the messages flow. */
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync do {} while (0)
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync do {} while (0)
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync }while (0);
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync case GL_INVALID_ENUM: errStr = RTStrDup("GL_INVALID_ENUM"); break;
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync case GL_INVALID_VALUE: errStr = RTStrDup("GL_INVALID_VALUE"); break;
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync case GL_INVALID_OPERATION: errStr = RTStrDup("GL_INVALID_OPERATION"); break;
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync case GL_STACK_OVERFLOW: errStr = RTStrDup("GL_STACK_OVERFLOW"); break;
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync case GL_STACK_UNDERFLOW: errStr = RTStrDup("GL_STACK_UNDERFLOW"); break;
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync case GL_OUT_OF_MEMORY: errStr = RTStrDup("GL_OUT_OF_MEMORY"); break;
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync case GL_TABLE_TOO_LARGE: errStr = RTStrDup("GL_TABLE_TOO_LARGE"); break;
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync DEBUG_MSG(("%s:%d: glError %d (%s)\n", file, line, g, errStr));
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync do {} while (0)
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync/* Custom OpenGL context class. This implementation doesn't allow to set a view
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * to the context, but save the view for later use. Also it saves a copy of the
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * pixel format used to create that context for later use. */
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync/* The custom view class. This is the main class of the cocoa OpenGL
68baefc21f54007de45fdb9eea43031b771c66e4vboxsync * implementation. It manages an frame buffer object for the rendering of the
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * guest applications. The guest applications render in this frame buffer which
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * is bind to an OpenGL texture. To display the guest content, an secondary
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * shared OpenGL context of the main OpenGL context is created. The secondary
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * context is marked as non opaque & the texture is displayed on an object
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * which is composed out of the several visible region rectangles. */
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync /* FBO handling */
aa4bcf0a4b2db3ac352b56a291d49cb8d4b66d32vboxsync /* The corresponding dock tile view of this OpenGL view & all helper
5b2d32859ee0ee4f2443c3a15bc33af6e5823276vboxsync * members. */
- (void)updateViewport;
- (void)reshape;
- (void)createFBO;
- (void)deleteFBO;
- (void)updateFBO;
- (void)makeCurrentFBO;
- (void)swapFBO;
- (void)flushFBO;
- (void)finishFBO;
- (void)bindFBO;
- (void)renderFBOToView;
- (void)clearVisibleRegions;
- (void)reshapeDockTile;
@end
* fullscreen/seamless entry/exit) the overlay window is informed & can add
@class OverlayWindow;
@end
@end
- (void)dealloc;
- (void)cleanup;
- (void)lock;
- (void)unlock;
@end
if (self)
return self;
- (void)dealloc
[super dealloc];
- (void)cleanup
- (void)lock
- (void)unlock
return YES;
[m_ThumbImage drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
return m_ThumbBitmap;
return m_ThumbImage;
@end
if (self)
return self;
- (void)dealloc
[super dealloc];
return m_pView;
return [super view];
-(void)clearDrawable
[super clearDrawable];
return m_pPixelFormat;
@end;
return self;
-(void)viewDidMoveToWindow
@end
if(self = [super initWithContentRect:NSZeroRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO])
return self;
- (void)dealloc
[super dealloc];
// [m_pOverlayView performSelector:@selector(reshape) onThread:m_Thread withObject:nil waitUntilDone:YES];
// [NSTimer scheduledTimerWithTimeInterval:0.2 target:m_pOverlayView selector:@selector(reshape) userInfo:nil repeats:NO];
@end
return self;
- (void)dealloc
if (m_pGLCtx)
if (m_pSharedGLCtx)
[super dealloc];
return m_pGLCtx;
return m_Pos;
return m_Size;
- (void)updateViewport
if (m_pSharedGLCtx)
- (void)reshape
NSPoint parentPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:NSMakePoint(parentFrame.origin.x, parentFrame.origin.y + parentFrame.size.height)]];
childPos = [[m_pParentView window] convertBaseToScreen:[[m_pParentView superview] convertPointToBase:childPos]];
// printf ("sc rect: %d %d %d %d\n", (int) scrollRect.origin.x,(int) scrollRect.origin.y,(int) scrollRect.size.width,(int) scrollRect.size.height);
// printf ("bound rect: %d %d %d %d\n", (int) b.origin.x,(int) b.origin.y,(int) b.size.width,(int) b.size.height);
- (void)createFBO
if (!m_FBOId)
if (!isFBO)
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, m_FBOTexSize.width, m_FBOTexSize.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_FBOTexId, 0);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_STENCIL_EXT, m_FBOTexSize.width, m_FBOTexSize.height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_FBODepthStencilPackedId);
if (dockScreen)
if (!m_FBOThumbId)
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, m_FBOTexSize.width * m_FBOThumbScaleX, m_FBOTexSize.height * m_FBOThumbScaleY, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_FBOThumbTexId, 0);
- (void)deleteFBO
- (void)updateFBO
if (m_pGLCtx)
- (void)makeCurrentFBO
if (m_pGLCtx)
glFlush();
- (void)swapFBO
- (void)flushFBO
glFlush();
- (void)finishFBO
glFinish();
- (void)bindFBO
- (void)renderFBOToView
if (!m_pSharedGLCtx)
m_pSharedGLCtx = [[NSOpenGLContext alloc] initWithFormat:[(OverlayOpenGLContext*)m_pGLCtx openGLPixelFormat] shareContext:m_pGLCtx];
if (m_pSharedGLCtx)
glFlush();
GLint i;
glEnd();
glFinish();
[[[NSApplication sharedApplication] dockTile] performSelectorOnMainThread:@selector(display) withObject:nil waitUntilDone:NO];
GLint i;
glEnd();
- (void)clearVisibleRegions
if(m_paClipRects)
return screenContent;
- (void)reshapeDockTile
NSRect newFrame = NSMakeRect ((int)(m_Pos.x * m_FBOThumbScaleX), (int)(dockFrame.size.height - (m_Pos.y + m_Size.height - m_RootShift.y) * m_FBOThumbScaleY), (int)(m_Size.width * m_FBOThumbScaleX), (int)(m_Size.height * m_FBOThumbScaleY));
// NSRect newFrame = NSMakeRect ((int)roundf(m_Pos.x * m_FBOThumbScaleX), (int)roundf(dockFrame.size.height - (m_Pos.y + m_Size.height) * m_FBOThumbScaleY), (int)roundf(m_Size.width * m_FBOThumbScaleX), (int)roundf(m_Size.height * m_FBOThumbScaleY));
// NSRect newFrame = NSMakeRect ((m_Pos.x * m_FBOThumbScaleX), (dockFrame.size.height - (m_Pos.y + m_Size.height) * m_FBOThumbScaleY), (m_Size.width * m_FBOThumbScaleX), (m_Size.height * m_FBOThumbScaleY));
// printf ("%f %f %f %f - %f %f\n", newFrame.origin.x, newFrame.origin.y, newFrame.size.width, newFrame.size.height, m_Size.height, m_FBOThumbScaleY);
@end
if (pFmt)
OverlayView* pView = [[OverlayView alloc] initWithFrame:NSZeroRect thread:RTThreadSelf() parentView:pParentView];
if (pView)
void cocoaFlush()
if (pCtx)
if (pView)
# endif
glFlush();
void cocoaFinish()
if (pCtx)
if (pView)
glFinish();
if (pCtx)
if (pView)