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 "content/browser/renderer_host/accelerated_plugin_view_mac.h" | 5 #import "content/browser/renderer_host/accelerated_plugin_view_mac.h" |
6 | 6 |
| 7 #include <vector> |
| 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
9 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
10 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 12 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 13 #include "ui/gfx/gl/gl_context.h" |
11 #include "ui/gfx/gl/gl_switches.h" | 14 #include "ui/gfx/gl/gl_switches.h" |
12 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 15 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
13 | 16 |
14 @implementation AcceleratedPluginView | 17 @implementation AcceleratedPluginView |
15 | 18 |
16 - (void)drawView { | 19 - (void)drawView { |
17 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 20 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
18 TRACE_EVENT0("browser", "AcceleratedPluginViewMac::drawView"); | 21 TRACE_EVENT0("browser", "AcceleratedPluginViewMac::drawView"); |
19 | 22 |
20 if (renderWidgetHostView_) { | 23 if (renderWidgetHostView_) { |
21 // TODO(thakis): Pixel or view coordinates for size? | 24 // TODO(thakis): Pixel or view coordinates for size? |
22 renderWidgetHostView_->DrawAcceleratedSurfaceInstance( | 25 renderWidgetHostView_->DrawAcceleratedSurfaceInstance( |
23 cglContext_, pluginHandle_, [super frame].size); | 26 cglContext_, pluginHandle_, [super frame].size); |
24 } | 27 } |
25 | 28 |
26 CGLFlushDrawable(cglContext_); | 29 CGLFlushDrawable(cglContext_); |
27 CGLSetCurrentContext(0); | 30 CGLSetCurrentContext(0); |
28 } | 31 } |
29 | 32 |
30 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r | 33 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r |
31 pluginHandle:(gfx::PluginWindowHandle)pluginHandle { | 34 pluginHandle:(gfx::PluginWindowHandle)pluginHandle { |
32 if ((self = [super initWithFrame:NSZeroRect])) { | 35 if ((self = [super initWithFrame:NSZeroRect])) { |
33 renderWidgetHostView_ = r; | 36 renderWidgetHostView_ = r; |
34 pluginHandle_ = pluginHandle; | 37 pluginHandle_ = pluginHandle; |
35 | 38 |
36 [self setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin]; | 39 [self setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin]; |
37 | 40 |
38 NSOpenGLPixelFormatAttribute attributes[] = | 41 std::vector<NSOpenGLPixelFormatAttribute> attributes; |
39 { NSOpenGLPFAAccelerated, NSOpenGLPFADoubleBuffer, 0}; | 42 attributes.push_back(NSOpenGLPFAAccelerated); |
| 43 attributes.push_back(NSOpenGLPFADoubleBuffer); |
| 44 if (gfx::GLContext::SupportsDualGpus()) |
| 45 attributes.push_back(NSOpenGLPFAAllowOfflineRenderers); |
| 46 attributes.push_back(0); |
40 | 47 |
41 // TODO(zmo): remove the diagnostic error messages once we figure out the | 48 // TODO(zmo): remove the diagnostic error messages once we figure out the |
42 // cause of the failure and a fix. | 49 // cause of the failure and a fix. |
43 | 50 |
44 glPixelFormat_.reset([[NSOpenGLPixelFormat alloc] | 51 glPixelFormat_.reset([[NSOpenGLPixelFormat alloc] |
45 initWithAttributes:attributes]); | 52 initWithAttributes:&attributes.front()]); |
46 if (!glPixelFormat_) | 53 if (!glPixelFormat_) |
47 LOG(ERROR) << "NSOpenGLPixelFormat initWithAttributes failed"; | 54 LOG(ERROR) << "NSOpenGLPixelFormat initWithAttributes failed"; |
48 | 55 |
49 glContext_.reset([[NSOpenGLContext alloc] initWithFormat:glPixelFormat_ | 56 glContext_.reset([[NSOpenGLContext alloc] initWithFormat:glPixelFormat_ |
50 shareContext:nil]); | 57 shareContext:nil]); |
51 if (!glContext_) | 58 if (!glContext_) |
52 LOG(ERROR) << "NSOpenGLContext initWithFormat failed"; | 59 LOG(ERROR) << "NSOpenGLContext initWithFormat failed"; |
53 | 60 |
54 // We "punch a hole" in the window, and have the WindowServer render the | 61 // We "punch a hole" in the window, and have the WindowServer render the |
55 // OpenGL surface underneath so we can draw over it. | 62 // OpenGL surface underneath so we can draw over it. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return YES; | 254 return YES; |
248 } | 255 } |
249 | 256 |
250 - (void)viewDidMoveToSuperview { | 257 - (void)viewDidMoveToSuperview { |
251 TRACE_EVENT0("browser", "AcceleratedPluginView::viewDidMoveToSuperview"); | 258 TRACE_EVENT0("browser", "AcceleratedPluginView::viewDidMoveToSuperview"); |
252 if (![self superview]) | 259 if (![self superview]) |
253 [self onRenderWidgetHostViewGone]; | 260 [self onRenderWidgetHostViewGone]; |
254 } | 261 } |
255 @end | 262 @end |
256 | 263 |
OLD | NEW |