Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <QuartzCore/QuartzCore.h> | 5 #include <QuartzCore/QuartzCore.h> |
| 6 | 6 |
| 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 8 | 8 |
| 9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "app/surface/io_surface_support_mac.h" | 10 #include "app/surface/io_surface_support_mac.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 | 153 |
| 154 RenderWidgetHostViewMac* renderWidgetHostView_; // weak | 154 RenderWidgetHostViewMac* renderWidgetHostView_; // weak |
| 155 gfx::PluginWindowHandle pluginHandle_; // weak | 155 gfx::PluginWindowHandle pluginHandle_; // weak |
| 156 | 156 |
| 157 // True if the backing IO surface was updated since we last painted. | 157 // True if the backing IO surface was updated since we last painted. |
| 158 BOOL surfaceWasSwapped_; | 158 BOOL surfaceWasSwapped_; |
| 159 | 159 |
| 160 // Cocoa methods can only be called on the main thread, so have a copy of the | 160 // Cocoa methods can only be called on the main thread, so have a copy of the |
| 161 // view's size, since it's required on the displaylink thread. | 161 // view's size, since it's required on the displaylink thread. |
| 162 NSSize cachedSize_; | 162 NSSize cachedSize_; |
| 163 | |
| 164 // -globalFrameDidChange: can be called recursively, this counts how often it | |
| 165 // holds the CGL lock. | |
| 166 int globalFrameDidChangeCGLLockCount_; | |
| 163 } | 167 } |
| 164 | 168 |
| 165 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r | 169 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r |
| 166 pluginHandle:(gfx::PluginWindowHandle)pluginHandle; | 170 pluginHandle:(gfx::PluginWindowHandle)pluginHandle; |
| 167 - (void)drawView; | 171 - (void)drawView; |
| 168 | 172 |
| 169 // This _must_ be atomic, since it's accessed from several threads. | 173 // This _must_ be atomic, since it's accessed from several threads. |
| 170 @property BOOL surfaceWasSwapped; | 174 @property BOOL surfaceWasSwapped; |
| 171 | 175 |
| 172 // This _must_ be atomic, since it's accessed from several threads. | 176 // This _must_ be atomic, since it's accessed from several threads. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 - (void)rightMouseDown:(NSEvent*)event { | 281 - (void)rightMouseDown:(NSEvent*)event { |
| 278 // The NSResponder documentation: "Note: The NSView implementation of this | 282 // The NSResponder documentation: "Note: The NSView implementation of this |
| 279 // method does not pass the message up the responder chain, it handles it | 283 // method does not pass the message up the responder chain, it handles it |
| 280 // directly." | 284 // directly." |
| 281 // That's bad, we want the next responder (RWHVMac) to handle this event to | 285 // That's bad, we want the next responder (RWHVMac) to handle this event to |
| 282 // dispatch it to the renderer. | 286 // dispatch it to the renderer. |
| 283 [[self nextResponder] rightMouseDown:event]; | 287 [[self nextResponder] rightMouseDown:event]; |
| 284 } | 288 } |
| 285 | 289 |
| 286 - (void)globalFrameDidChange:(NSNotification*)notification { | 290 - (void)globalFrameDidChange:(NSNotification*)notification { |
| 291 globalFrameDidChangeCGLLockCount_++; | |
|
pink (ping after 24hrs)
2010/09/29 21:08:54
can you add a comment here as to where globalFrame
| |
| 287 CGLLockContext(cglContext_); | 292 CGLLockContext(cglContext_); |
| 288 [glContext_ update]; | 293 [glContext_ update]; |
| 289 | 294 |
| 290 // You would think that -update updates the viewport. You would be wrong. | 295 // You would think that -update updates the viewport. You would be wrong. |
| 291 CGLSetCurrentContext(cglContext_); | 296 CGLSetCurrentContext(cglContext_); |
| 292 NSSize size = [self frame].size; | 297 NSSize size = [self frame].size; |
| 293 glViewport(0, 0, size.width, size.height); | 298 glViewport(0, 0, size.width, size.height); |
| 294 | 299 |
| 295 CGLUnlockContext(cglContext_); | 300 CGLUnlockContext(cglContext_); |
| 301 globalFrameDidChangeCGLLockCount_--; | |
| 296 | 302 |
| 297 // Make sure the view is synchronized with the correct display. | 303 if (globalFrameDidChangeCGLLockCount_ == 0) { |
| 298 CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext( | 304 // Make sure the view is synchronized with the correct display. |
| 305 CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext( | |
| 299 displayLink_, cglContext_, cglPixelFormat_); | 306 displayLink_, cglContext_, cglPixelFormat_); |
| 307 } | |
| 300 } | 308 } |
| 301 | 309 |
| 302 - (void)renewGState { | 310 - (void)renewGState { |
| 303 // Synchronize with window server to avoid flashes or corrupt drawing. | 311 // Synchronize with window server to avoid flashes or corrupt drawing. |
| 304 [[self window] disableScreenUpdatesUntilFlush]; | 312 [[self window] disableScreenUpdatesUntilFlush]; |
| 305 [self globalFrameDidChange:nil]; | 313 [self globalFrameDidChange:nil]; |
| 306 [super renewGState]; | 314 [super renewGState]; |
| 307 } | 315 } |
| 308 | 316 |
| 309 - (void)lockFocus { | 317 - (void)lockFocus { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 322 CVDisplayLinkSetOutputCallback( | 330 CVDisplayLinkSetOutputCallback( |
| 323 displayLink_, &DrawOneAcceleratedPluginCallback, self); | 331 displayLink_, &DrawOneAcceleratedPluginCallback, self); |
| 324 CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext( | 332 CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext( |
| 325 displayLink_, cglContext_, cglPixelFormat_); | 333 displayLink_, cglContext_, cglPixelFormat_); |
| 326 CVDisplayLinkStart(displayLink_); | 334 CVDisplayLinkStart(displayLink_); |
| 327 } | 335 } |
| 328 [glContext_ makeCurrentContext]; | 336 [glContext_ makeCurrentContext]; |
| 329 } | 337 } |
| 330 | 338 |
| 331 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { | 339 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
| 332 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 333 switches::kDisableHolePunching)) { | |
| 334 return; | |
| 335 } | |
| 336 | |
| 337 if ([[self window] respondsToSelector:@selector(underlaySurfaceRemoved)]) { | |
| 338 [static_cast<id>([self window]) underlaySurfaceRemoved]; | |
| 339 } | |
| 340 | |
| 341 if ([newWindow respondsToSelector:@selector(underlaySurfaceAdded)]) { | |
| 342 [static_cast<id>(newWindow) underlaySurfaceAdded]; | |
| 343 } | |
| 344 | |
| 345 // Stop the display link thread while the view is not visible. | 340 // Stop the display link thread while the view is not visible. |
| 346 if (newWindow) { | 341 if (newWindow) { |
| 347 if (displayLink_ && !CVDisplayLinkIsRunning(displayLink_)) | 342 if (displayLink_ && !CVDisplayLinkIsRunning(displayLink_)) |
| 348 CVDisplayLinkStart(displayLink_); | 343 CVDisplayLinkStart(displayLink_); |
| 349 } else { | 344 } else { |
| 350 if (displayLink_ && CVDisplayLinkIsRunning(displayLink_)) | 345 if (displayLink_ && CVDisplayLinkIsRunning(displayLink_)) |
| 351 CVDisplayLinkStop(displayLink_); | 346 CVDisplayLinkStop(displayLink_); |
| 352 } | 347 } |
| 348 | |
| 349 // If hole pushing is enabled, inform the window hosing this accelerated view | |
|
pink (ping after 24hrs)
2010/09/29 21:08:11
hole pushing or hole punching? hosing or hosting?
Nico
2010/09/29 21:14:02
freud strikes again
| |
| 350 // that it needs to be opaque. | |
| 351 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 352 switches::kDisableHolePunching)) { | |
| 353 if ([[self window] respondsToSelector:@selector(underlaySurfaceRemoved)]) { | |
| 354 [static_cast<id>([self window]) underlaySurfaceRemoved]; | |
| 355 } | |
| 356 | |
| 357 if ([newWindow respondsToSelector:@selector(underlaySurfaceAdded)]) { | |
| 358 [static_cast<id>(newWindow) underlaySurfaceAdded]; | |
| 359 } | |
| 360 } | |
| 353 } | 361 } |
| 354 | 362 |
| 355 - (void)setFrame:(NSRect)frameRect { | 363 - (void)setFrame:(NSRect)frameRect { |
| 356 [self setCachedSize:frameRect.size]; | 364 [self setCachedSize:frameRect.size]; |
| 357 [super setFrame:frameRect]; | 365 [super setFrame:frameRect]; |
| 358 } | 366 } |
| 359 | 367 |
| 360 - (void)setFrameSize:(NSSize)newSize { | 368 - (void)setFrameSize:(NSSize)newSize { |
| 361 [self setCachedSize:newSize]; | 369 [self setCachedSize:newSize]; |
| 362 [super setFrameSize:newSize]; | 370 [super setFrameSize:newSize]; |
| (...skipping 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2439 if (!string) return NO; | 2447 if (!string) return NO; |
| 2440 | 2448 |
| 2441 // If the user is currently using an IME, confirm the IME input, | 2449 // If the user is currently using an IME, confirm the IME input, |
| 2442 // and then insert the text from the service, the same as TextEdit and Safari. | 2450 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2443 [self confirmComposition]; | 2451 [self confirmComposition]; |
| 2444 [self insertText:string]; | 2452 [self insertText:string]; |
| 2445 return YES; | 2453 return YES; |
| 2446 } | 2454 } |
| 2447 | 2455 |
| 2448 @end | 2456 @end |
| OLD | NEW |