| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import "chrome/browser/renderer_host/accelerated_plugin_view_mac.h" | 5 #import "chrome/browser/renderer_host/accelerated_plugin_view_mac.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #import "base/mac/scoped_nsautorelease_pool.h" | 8 #import "base/mac/scoped_nsautorelease_pool.h" |
| 9 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 9 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 [self setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin]; | 67 [self setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin]; |
| 68 | 68 |
| 69 NSOpenGLPixelFormatAttribute attributes[] = | 69 NSOpenGLPixelFormatAttribute attributes[] = |
| 70 { NSOpenGLPFAAccelerated, NSOpenGLPFADoubleBuffer, 0}; | 70 { NSOpenGLPFAAccelerated, NSOpenGLPFADoubleBuffer, 0}; |
| 71 | 71 |
| 72 glPixelFormat_.reset([[NSOpenGLPixelFormat alloc] | 72 glPixelFormat_.reset([[NSOpenGLPixelFormat alloc] |
| 73 initWithAttributes:attributes]); | 73 initWithAttributes:attributes]); |
| 74 glContext_.reset([[NSOpenGLContext alloc] initWithFormat:glPixelFormat_ | 74 glContext_.reset([[NSOpenGLContext alloc] initWithFormat:glPixelFormat_ |
| 75 shareContext:nil]); | 75 shareContext:nil]); |
| 76 | 76 |
| 77 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 77 // We "punch a hole" in the window, and have the WindowServer render the |
| 78 switches::kDisableHolePunching)) { | 78 // OpenGL surface underneath so we can draw over it. |
| 79 // We "punch a hole" in the window, and have the WindowServer render the | 79 GLint belowWindow = -1; |
| 80 // OpenGL surface underneath so we can draw over it. | 80 [glContext_ setValues:&belowWindow forParameter:NSOpenGLCPSurfaceOrder]; |
| 81 GLint belowWindow = -1; | |
| 82 [glContext_ setValues:&belowWindow forParameter:NSOpenGLCPSurfaceOrder]; | |
| 83 } | |
| 84 | 81 |
| 85 cglContext_ = (CGLContextObj)[glContext_ CGLContextObj]; | 82 cglContext_ = (CGLContextObj)[glContext_ CGLContextObj]; |
| 86 cglPixelFormat_ = (CGLPixelFormatObj)[glPixelFormat_ CGLPixelFormatObj]; | 83 cglPixelFormat_ = (CGLPixelFormatObj)[glPixelFormat_ CGLPixelFormatObj]; |
| 87 | 84 |
| 88 // Draw at beam vsync. | 85 // Draw at beam vsync. |
| 89 GLint swapInterval; | 86 GLint swapInterval; |
| 90 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) | 87 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync)) |
| 91 swapInterval = 0; | 88 swapInterval = 0; |
| 92 else | 89 else |
| 93 swapInterval = 1; | 90 swapInterval = 1; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 return; | 145 return; |
| 149 | 146 |
| 150 CGLLockContext(cglContext_); | 147 CGLLockContext(cglContext_); |
| 151 // Deallocate the plugin handle while we still can. | 148 // Deallocate the plugin handle while we still can. |
| 152 renderWidgetHostView_->DeallocFakePluginWindowHandle(pluginHandle_); | 149 renderWidgetHostView_->DeallocFakePluginWindowHandle(pluginHandle_); |
| 153 renderWidgetHostView_ = NULL; | 150 renderWidgetHostView_ = NULL; |
| 154 CGLUnlockContext(cglContext_); | 151 CGLUnlockContext(cglContext_); |
| 155 } | 152 } |
| 156 | 153 |
| 157 - (void)drawRect:(NSRect)rect { | 154 - (void)drawRect:(NSRect)rect { |
| 158 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 155 const NSRect* dirtyRects; |
| 159 switches::kDisableHolePunching)) { | 156 int dirtyRectCount; |
| 160 const NSRect* dirtyRects; | 157 [self getRectsBeingDrawn:&dirtyRects count:&dirtyRectCount]; |
| 161 int dirtyRectCount; | |
| 162 [self getRectsBeingDrawn:&dirtyRects count:&dirtyRectCount]; | |
| 163 | 158 |
| 164 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 159 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| 165 | 160 |
| 166 // Mask out any cutout rects--somewhat counterintuitively cutout rects are | 161 // Mask out any cutout rects--somewhat counterintuitively cutout rects are |
| 167 // places where clearColor is *not* drawn. The trick is that drawing nothing | 162 // places where clearColor is *not* drawn. The trick is that drawing nothing |
| 168 // lets the parent view (i.e., the web page) show through, whereas drawing | 163 // lets the parent view (i.e., the web page) show through, whereas drawing |
| 169 // clearColor punches a hole in the window (letting OpenGL show through). | 164 // clearColor punches a hole in the window (letting OpenGL show through). |
| 170 if ([cutoutRects_.get() count] > 0) { | 165 if ([cutoutRects_.get() count] > 0) { |
| 171 NSBezierPath* path = [NSBezierPath bezierPath]; | 166 NSBezierPath* path = [NSBezierPath bezierPath]; |
| 172 // Trace the bounds clockwise to give a base clip rect of the whole view. | 167 // Trace the bounds clockwise to give a base clip rect of the whole view. |
| 173 NSRect bounds = [self bounds]; | 168 NSRect bounds = [self bounds]; |
| 174 [path moveToPoint:bounds.origin]; | 169 [path moveToPoint:bounds.origin]; |
| 175 [path lineToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; | 170 [path lineToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))]; |
| 176 [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; | 171 [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))]; |
| 177 [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; | 172 [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))]; |
| 178 [path closePath]; | 173 [path closePath]; |
| 179 | 174 |
| 180 // Then trace each cutout rect counterclockwise to remove that region from | 175 // Then trace each cutout rect counterclockwise to remove that region from |
| 181 // the clip region. | 176 // the clip region. |
| 182 for (NSValue* rectWrapper in cutoutRects_.get()) { | 177 for (NSValue* rectWrapper in cutoutRects_.get()) { |
| 183 [path appendBezierPathWithRect:[rectWrapper rectValue]]; | 178 [path appendBezierPathWithRect:[rectWrapper rectValue]]; |
| 184 } | |
| 185 | |
| 186 [path addClip]; | |
| 187 } | 179 } |
| 188 | 180 |
| 189 // Punch a hole so that the OpenGL view shows through. | 181 [path addClip]; |
| 190 [[NSColor clearColor] set]; | |
| 191 NSRectFillList(dirtyRects, dirtyRectCount); | |
| 192 } | 182 } |
| 193 | 183 |
| 184 // Punch a hole so that the OpenGL view shows through. |
| 185 [[NSColor clearColor] set]; |
| 186 NSRectFillList(dirtyRects, dirtyRectCount); |
| 187 |
| 194 [self drawView]; | 188 [self drawView]; |
| 195 } | 189 } |
| 196 | 190 |
| 197 - (void)rightMouseDown:(NSEvent*)event { | 191 - (void)rightMouseDown:(NSEvent*)event { |
| 198 // The NSResponder documentation: "Note: The NSView implementation of this | 192 // The NSResponder documentation: "Note: The NSView implementation of this |
| 199 // method does not pass the message up the responder chain, it handles it | 193 // method does not pass the message up the responder chain, it handles it |
| 200 // directly." | 194 // directly." |
| 201 // That's bad, we want the next responder (RWHVMac) to handle this event to | 195 // That's bad, we want the next responder (RWHVMac) to handle this event to |
| 202 // dispatch it to the renderer. | 196 // dispatch it to the renderer. |
| 203 [[self nextResponder] rightMouseDown:event]; | 197 [[self nextResponder] rightMouseDown:event]; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { | 252 - (void)viewWillMoveToWindow:(NSWindow*)newWindow { |
| 259 // Stop the display link thread while the view is not visible. | 253 // Stop the display link thread while the view is not visible. |
| 260 if (newWindow) { | 254 if (newWindow) { |
| 261 if (displayLink_ && !CVDisplayLinkIsRunning(displayLink_)) | 255 if (displayLink_ && !CVDisplayLinkIsRunning(displayLink_)) |
| 262 CVDisplayLinkStart(displayLink_); | 256 CVDisplayLinkStart(displayLink_); |
| 263 } else { | 257 } else { |
| 264 if (displayLink_ && CVDisplayLinkIsRunning(displayLink_)) | 258 if (displayLink_ && CVDisplayLinkIsRunning(displayLink_)) |
| 265 CVDisplayLinkStop(displayLink_); | 259 CVDisplayLinkStop(displayLink_); |
| 266 } | 260 } |
| 267 | 261 |
| 268 // If hole punching is enabled, inform the window hosting this accelerated | 262 // Inform the window hosting this accelerated view that it needs to be |
| 269 // view that it needs to be opaque. | 263 // transparent. |
| 270 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 264 if ([[self window] respondsToSelector:@selector(underlaySurfaceRemoved)]) { |
| 271 switches::kDisableHolePunching)) { | 265 [static_cast<id>([self window]) underlaySurfaceRemoved]; |
| 272 if ([[self window] respondsToSelector:@selector(underlaySurfaceRemoved)]) { | 266 } |
| 273 [static_cast<id>([self window]) underlaySurfaceRemoved]; | 267 if ([newWindow respondsToSelector:@selector(underlaySurfaceAdded)]) { |
| 274 } | 268 [static_cast<id>(newWindow) underlaySurfaceAdded]; |
| 275 | |
| 276 if ([newWindow respondsToSelector:@selector(underlaySurfaceAdded)]) { | |
| 277 [static_cast<id>(newWindow) underlaySurfaceAdded]; | |
| 278 } | |
| 279 } | 269 } |
| 280 } | 270 } |
| 281 | 271 |
| 282 - (void)setFrame:(NSRect)frameRect { | 272 - (void)setFrame:(NSRect)frameRect { |
| 283 [self setCachedSize:frameRect.size]; | 273 [self setCachedSize:frameRect.size]; |
| 284 [super setFrame:frameRect]; | 274 [super setFrame:frameRect]; |
| 285 } | 275 } |
| 286 | 276 |
| 287 - (void)setFrameSize:(NSSize)newSize { | 277 - (void)setFrameSize:(NSSize)newSize { |
| 288 [self setCachedSize:newSize]; | 278 [self setCachedSize:newSize]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 302 [[self window] makeFirstResponder:[self superview]]; | 292 [[self window] makeFirstResponder:[self superview]]; |
| 303 return YES; | 293 return YES; |
| 304 } | 294 } |
| 305 | 295 |
| 306 - (void)viewDidMoveToSuperview { | 296 - (void)viewDidMoveToSuperview { |
| 307 if (![self superview]) | 297 if (![self superview]) |
| 308 [self onRenderWidgetHostViewGone]; | 298 [self onRenderWidgetHostViewGone]; |
| 309 } | 299 } |
| 310 @end | 300 @end |
| 311 | 301 |
| OLD | NEW |