Chromium Code Reviews| Index: chrome/browser/renderer_host/accelerated_plugin_view_mac.mm |
| diff --git a/chrome/browser/renderer_host/accelerated_plugin_view_mac.mm b/chrome/browser/renderer_host/accelerated_plugin_view_mac.mm |
| index 82638b6ba48ace0e12344a09a76e4b2034a0f8c4..d4a59365b2988f7280d24f34150af39e2a393ef6 100644 |
| --- a/chrome/browser/renderer_host/accelerated_plugin_view_mac.mm |
| +++ b/chrome/browser/renderer_host/accelerated_plugin_view_mac.mm |
| @@ -6,64 +6,22 @@ |
| #include "base/command_line.h" |
| #include "base/debug/trace_event.h" |
| -#import "base/mac/scoped_nsautorelease_pool.h" |
| #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "content/browser/browser_thread.h" |
| #include "ui/gfx/gl/gl_switches.h" |
| #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| @implementation AcceleratedPluginView |
| -@synthesize cachedSize = cachedSize_; |
| - |
| -- (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime { |
| - // There is no autorelease pool when this method is called because it will be |
| - // called from a background thread. |
| - base::mac::ScopedNSAutoreleasePool pool; |
| - |
| - bool sendAck = (rendererId_ != 0 || routeId_ != 0); |
| - uint64 currentSwapBuffersCount = swapBuffersCount_; |
| - if (currentSwapBuffersCount == acknowledgedSwapBuffersCount_) { |
| - return kCVReturnSuccess; |
| - } |
| - |
| - [self drawView]; |
| - |
| - acknowledgedSwapBuffersCount_ = currentSwapBuffersCount; |
| - if (sendAck && renderWidgetHostView_) { |
| - renderWidgetHostView_->AcknowledgeSwapBuffers( |
| - rendererId_, |
| - routeId_, |
| - gpuHostId_, |
| - acknowledgedSwapBuffersCount_); |
| - } |
| - |
| - return kCVReturnSuccess; |
| -} |
| - |
| -// This is the renderer output callback function |
| -static CVReturn DrawOneAcceleratedPluginCallback( |
| - CVDisplayLinkRef displayLink, |
| - const CVTimeStamp* now, |
| - const CVTimeStamp* outputTime, |
| - CVOptionFlags flagsIn, |
| - CVOptionFlags* flagsOut, |
| - void* displayLinkContext) { |
| - CVReturn result = |
| - [(AcceleratedPluginView*)displayLinkContext getFrameForTime:outputTime]; |
| - return result; |
| -} |
| - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r |
| pluginHandle:(gfx::PluginWindowHandle)pluginHandle { |
| + CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if ((self = [super initWithFrame:NSZeroRect])) { |
| + TRACE_EVENT0("browser", |
| + "AcceleratedPluginView::initWithRenderWidgetHostViewMac"); |
| renderWidgetHostView_ = r; |
| pluginHandle_ = pluginHandle; |
| - cachedSize_ = NSZeroSize; |
| - swapBuffersCount_ = 0; |
| - acknowledgedSwapBuffersCount_ = 0; |
| - rendererId_ = 0; |
| - routeId_ = 0; |
| - gpuHostId_ = 0; |
| [self setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin]; |
| @@ -90,15 +48,11 @@ static CVReturn DrawOneAcceleratedPluginCallback( |
| else |
| swapInterval = 1; |
| [glContext_ setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; |
| - |
| - // Set up a display link to do OpenGL rendering on a background thread. |
| - CVDisplayLinkCreateWithActiveCGDisplays(&displayLink_); |
| } |
| return self; |
| } |
| - (void)dealloc { |
| - CVDisplayLinkRelease(displayLink_); |
| if (renderWidgetHostView_) |
| renderWidgetHostView_->DeallocFakePluginWindowHandle(pluginHandle_); |
| [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| @@ -106,55 +60,36 @@ static CVReturn DrawOneAcceleratedPluginCallback( |
| } |
| - (void)drawView { |
| - TRACE_EVENT1("browser", "AcceleratedPluginViewMac::drawView", |
| - "frameNum", swapBuffersCount_); |
| - // Called on a background thread. Synchronized via the CGL context lock. |
| - CGLLockContext(cglContext_); |
| - |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + TRACE_EVENT0("browser", "AcceleratedPluginViewMac::drawView"); |
| + // Called on the UI thread. |
| if (renderWidgetHostView_) { |
| // TODO(thakis): Pixel or view coordinates for size? |
| + NSRect frame = [self frame]; |
|
Nico
2011/06/08 16:52:46
no need for a variable
jbates
2011/06/08 17:54:42
Done.
|
| renderWidgetHostView_->DrawAcceleratedSurfaceInstance( |
| - cglContext_, pluginHandle_, [self cachedSize]); |
| + cglContext_, pluginHandle_, frame.size); |
| } |
| CGLFlushDrawable(cglContext_); |
| CGLSetCurrentContext(0); |
| - CGLUnlockContext(cglContext_); |
| } |
| - (void)setCutoutRects:(NSArray*)cutout_rects { |
| cutoutRects_.reset([cutout_rects copy]); |
| } |
| -- (void)updateSwapBuffersCount:(uint64)count |
| - fromRenderer:(int)rendererId |
| - routeId:(int32)routeId |
| - gpuHostId:(int)gpuHostId { |
| - if (rendererId == 0 && routeId == 0) { |
| - // This notification is coming from a plugin process, for which we |
| - // don't have flow control implemented right now. Fake up a swap |
| - // buffers count so that we can at least skip useless renders. |
| - ++swapBuffersCount_; |
| - } else { |
| - rendererId_ = rendererId; |
| - routeId_ = routeId; |
| - gpuHostId_ = gpuHostId; |
| - swapBuffersCount_ = count; |
| - } |
| -} |
| - |
| - (void)onRenderWidgetHostViewGone { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| if (!renderWidgetHostView_) |
| return; |
| - CGLLockContext(cglContext_); |
| // Deallocate the plugin handle while we still can. |
| renderWidgetHostView_->DeallocFakePluginWindowHandle(pluginHandle_); |
| renderWidgetHostView_ = NULL; |
| - CGLUnlockContext(cglContext_); |
| } |
| - (void)drawRect:(NSRect)rect { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| const NSRect* dirtyRects; |
| int dirtyRectCount; |
| [self getRectsBeingDrawn:&dirtyRects count:&dirtyRectCount]; |
| @@ -203,8 +138,8 @@ static CVReturn DrawOneAcceleratedPluginCallback( |
| } |
| - (void)globalFrameDidChange:(NSNotification*)notification { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| globalFrameDidChangeCGLLockCount_++; |
| - CGLLockContext(cglContext_); |
| // This call to -update can call -globalFrameDidChange: again, see |
| // http://crbug.com/55754 comments 22 and 24. |
| [glContext_ update]; |
| @@ -215,14 +150,7 @@ static CVReturn DrawOneAcceleratedPluginCallback( |
| glViewport(0, 0, size.width, size.height); |
| CGLSetCurrentContext(0); |
| - CGLUnlockContext(cglContext_); |
| globalFrameDidChangeCGLLockCount_--; |
| - |
| - if (globalFrameDidChangeCGLLockCount_ == 0) { |
| - // Make sure the view is synchronized with the correct display. |
| - CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext( |
| - displayLink_, cglContext_, cglPixelFormat_); |
| - } |
| } |
| - (void)renewGState { |
| @@ -235,8 +163,7 @@ static CVReturn DrawOneAcceleratedPluginCallback( |
| - (void)lockFocus { |
| [super lockFocus]; |
| - // If we're using OpenGL, make sure it is connected and that the display link |
| - // is running. |
| + // If we're using OpenGL, make sure it is connected. |
| if ([glContext_ view] != self) { |
| [glContext_ setView:self]; |
| @@ -245,25 +172,12 @@ static CVReturn DrawOneAcceleratedPluginCallback( |
| selector:@selector(globalFrameDidChange:) |
| name:NSViewGlobalFrameDidChangeNotification |
| object:self]; |
| - CVDisplayLinkSetOutputCallback( |
| - displayLink_, &DrawOneAcceleratedPluginCallback, self); |
| - CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext( |
| - displayLink_, cglContext_, cglPixelFormat_); |
| - CVDisplayLinkStart(displayLink_); |
| } |
| [glContext_ makeCurrentContext]; |
| } |
| - (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
| - // Stop the display link thread while the view is not visible. |
| - if (newWindow) { |
| - if (displayLink_ && !CVDisplayLinkIsRunning(displayLink_)) |
| - CVDisplayLinkStart(displayLink_); |
| - } else { |
| - if (displayLink_ && CVDisplayLinkIsRunning(displayLink_)) |
| - CVDisplayLinkStop(displayLink_); |
| - } |
| - |
| + TRACE_EVENT0("renderer", "viewWillMoveToWindow"); |
| // Inform the window hosting this accelerated view that it needs to be |
| // transparent. |
| if (![self isHiddenOrHasHiddenAncestor]) { |
| @@ -292,12 +206,10 @@ static CVReturn DrawOneAcceleratedPluginCallback( |
| - (void)setFrame:(NSRect)frameRect { |
| TRACE_EVENT0("browser", "AcceleratedPluginViewMac::setFrame"); |
| - [self setCachedSize:frameRect.size]; |
| [super setFrame:frameRect]; |
| } |
|
Nico
2011/06/08 16:52:46
If you don't need the trace output, remove this me
jbates
2011/06/08 17:54:42
Done.
|
| - (void)setFrameSize:(NSSize)newSize { |
| - [self setCachedSize:newSize]; |
| [super setFrameSize:newSize]; |
| } |
|
Nico
2011/06/08 16:52:46
Remove this method?
jbates
2011/06/08 17:54:42
Done.
|