Chromium Code Reviews| Index: ui/accelerated_widget_mac/io_surface_ns_gl_surface.mm |
| diff --git a/ui/accelerated_widget_mac/io_surface_ns_gl_surface.mm b/ui/accelerated_widget_mac/io_surface_ns_gl_surface.mm |
| index 46132a1eac2720c0f24d7628839a4800aca1ee16..7e1f77c9345fc7ae7b2e5d254671afea88519a3e 100644 |
| --- a/ui/accelerated_widget_mac/io_surface_ns_gl_surface.mm |
| +++ b/ui/accelerated_widget_mac/io_surface_ns_gl_surface.mm |
| @@ -4,14 +4,18 @@ |
| #include "ui/accelerated_widget_mac/io_surface_ns_gl_surface.h" |
| +#include <OpenGL/CGLRenderers.h> |
| #include <OpenGL/GL.h> |
| #include "base/callback_helpers.h" |
| +#include "base/command_line.h" |
| #include "base/mac/bind_objc_block.h" |
| +#include "base/mac/mac_util.h" |
| #include "base/mac/sdk_forward_declarations.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/trace_event/trace_event.h" |
| #include "ui/base/cocoa/animation_utils.h" |
| +#include "ui/base/ui_base_switches.h" |
| #include "ui/gfx/geometry/dip_util.h" |
| #include "ui/gfx/geometry/rect.h" |
| #include "ui/gl/gpu_switching_manager.h" |
| @@ -19,8 +23,11 @@ |
| namespace ui { |
| IOSurfaceNSGLSurface* IOSurfaceNSGLSurface::Create( |
| - IOSurfaceNSGLSurfaceClient* client, NSView* view) { |
| - scoped_refptr<IOSurfaceTexture> iosurface = IOSurfaceTexture::Create(false); |
| + IOSurfaceNSGLSurfaceClient* client, |
| + NSView* view, |
| + bool needs_gl_finish_workaround) { |
| + scoped_refptr<IOSurfaceTexture> iosurface = |
| + IOSurfaceTexture::Create(needs_gl_finish_workaround, true); |
| if (!iosurface) |
| return NULL; |
| @@ -47,12 +54,14 @@ IOSurfaceNSGLSurface* IOSurfaceNSGLSurface::Create( |
| return NULL; |
| } |
| - return new IOSurfaceNSGLSurface(client, view, ns_gl_context, iosurface); |
| + return new IOSurfaceNSGLSurface( |
| + client, view, needs_gl_finish_workaround, ns_gl_context, iosurface); |
| } |
| IOSurfaceNSGLSurface::IOSurfaceNSGLSurface( |
| IOSurfaceNSGLSurfaceClient* client, |
| NSView* view, |
| + bool needs_gl_finish_workaround, |
| base::scoped_nsobject<NSOpenGLContext> ns_gl_context, |
| scoped_refptr<ui::IOSurfaceTexture> iosurface) |
| : client_(client), view_(view), iosurface_(iosurface), |
| @@ -76,6 +85,7 @@ bool IOSurfaceNSGLSurface::GotFrame(IOSurfaceID io_surface_id, |
| gfx::Size frame_pixel_size, |
| float frame_scale_factor, |
| gfx::Rect pixel_damage_rect) { |
| + TRACE_EVENT0("ui", "IOSurfaceNSGLSurface::GotFrame"); |
| pending_draw_exists_ = true; |
| pending_draw_damage_rect_.Union(pixel_damage_rect); |
| @@ -138,4 +148,44 @@ void IOSurfaceNSGLSurface::DoPendingDrawIfNeeded() { |
| client_->IOSurfaceNSGLSurfaceDidDrawFrame(); |
| } |
| -}; |
| +int IOSurfaceNSGLSurface::GetRendererID() { |
| + GLint current_renderer_id = -1; |
| + CGLContextObj cgl_context = static_cast<CGLContextObj>( |
|
Andre
2015/06/10 05:23:39
Why do you need this cast?
ccameron
2015/06/10 21:39:51
-[NSOpenGLContext CGLContextObj] returns a void*,
|
| + [ns_gl_context_ CGLContextObj]); |
| + if (CGLGetParameter(cgl_context, |
| + kCGLCPCurrentRendererID, |
| + ¤t_renderer_id) == kCGLNoError) { |
| + return current_renderer_id & kCGLRendererIDMatchingMask; |
| + } |
| + return -1; |
| +} |
| + |
| +// static |
| +bool IOSurfaceNSGLSurface::CanUseNSGLSurfaceForView(NSView* view) { |
| + // This must be explicitly enabled at the command line. |
| + static bool use_ns_gl_surfaces = |
| + base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableNSGLSurfaces); |
| + if (!use_ns_gl_surfaces) |
| + return false; |
| + |
| + // Do not attempt this before 10.9. The power savings are not worth the |
| + // stability risk and testing burden. |
| + if (!base::mac::IsOSMavericksOrLater()) |
| + return false; |
| + |
| + // If the NSView being attached to the NSOpenGLContext is not on the main |
| + // monitor, then, due to an OS X bug, the IOSurface will be thrashed, |
| + // resulting in hangs of 50 msec or more. |
| + CGDirectDisplayID main_display = CGMainDisplayID(); |
| + NSScreen* screen = [[view window] screen]; |
| + NSDictionary* screen_description = [screen deviceDescription]; |
| + NSNumber* screen_number = [screen_description objectForKey:@"NSScreenNumber"]; |
| + CGDirectDisplayID display_id = [screen_number unsignedIntValue]; |
| + if (display_id != main_display) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +} // namespace ui |