summaryrefslogtreecommitdiffstats
path: root/ui/gfx/surface
diff options
context:
space:
mode:
authorkbr@chromium.org <kbr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-13 22:55:50 +0000
committerkbr@chromium.org <kbr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-13 22:55:50 +0000
commit276f89060fa4b38582dcd76ebdf9454bb7d42c8e (patch)
tree0ff1c47fed812c196ae491a6c7295164d557e813 /ui/gfx/surface
parent91701aec11f289e96ce92b588b858b26179cb89c (diff)
downloadchromium_src-276f89060fa4b38582dcd76ebdf9454bb7d42c8e.zip
chromium_src-276f89060fa4b38582dcd76ebdf9454bb7d42c8e.tar.gz
chromium_src-276f89060fa4b38582dcd76ebdf9454bb7d42c8e.tar.bz2
Support dynamic switching between integrated and discrete GPUs on Mac OS X.
Change Chrome to allocate most OpenGL contexts with the kCGLPFAAllowOfflineRenderers flag, and specify NSSupportsAutomaticGraphicsSwitching in the Info.plist for the main executable and helper apps. This keeps Chrome on the integrated GPU except when using WebGL, accelerated 2D Canvas, Pepper 3D, and Core Animation-based plugins (except Flash). Chrome shares resources between OpenGL contexts in order to display WebGL and other content in the compositor, and resource sharing doesn't work between contexts allocated on different GPUs. Therefore, when the first context for a given renderer requests the discrete GPU, the channel is dropped and all contexts are reallocated on the discrete GPU. Similarly, when the last context requesting the discrete GPU for a given renderer is shut down, all contexts are dropped and reallocated on the integrated GPU. Currently dynamic GPU switching is only supported on the latest Mac OS X 10.7 update and MacBook Pros with dual AMD / Intel GPUs, though this will improve in future OS updates. Tested with WebGL, CSS 3D, Flash and Unity3D content and observed desired GPU switching behavior. Also added a layout test to WebKit under https://bugs.webkit.org/show_bug.cgi?id=69776 which when run in Chrome catches an assertion failure related to the destruction of contexts. The intent is to add it as a UI layout test on the GPU bots. BUG=88788 TEST=none Review URL: http://codereview.chromium.org/8233027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105399 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/surface')
-rw-r--r--ui/gfx/surface/accelerated_surface_mac.cc12
-rw-r--r--ui/gfx/surface/accelerated_surface_mac.h14
2 files changed, 18 insertions, 8 deletions
diff --git a/ui/gfx/surface/accelerated_surface_mac.cc b/ui/gfx/surface/accelerated_surface_mac.cc
index d6b63cd..759ae81 100644
--- a/ui/gfx/surface/accelerated_surface_mac.cc
+++ b/ui/gfx/surface/accelerated_surface_mac.cc
@@ -24,8 +24,10 @@ AcceleratedSurface::AcceleratedSurface()
AcceleratedSurface::~AcceleratedSurface() {}
-bool AcceleratedSurface::Initialize(gfx::GLContext* share_context,
- bool allocate_fbo) {
+bool AcceleratedSurface::Initialize(
+ gfx::GLContext* share_context,
+ bool allocate_fbo,
+ gfx::GpuPreference gpu_preference) {
allocate_fbo_ = allocate_fbo;
// Ensure GL is initialized before trying to create an offscreen GL context.
@@ -47,8 +49,10 @@ bool AcceleratedSurface::Initialize(gfx::GLContext* share_context,
gfx::GLShareGroup* share_group =
share_context ? share_context->share_group() : NULL;
- gl_context_ = gfx::GLContext::CreateGLContext(share_group,
- gl_surface_.get());
+ gl_context_ = gfx::GLContext::CreateGLContext(
+ share_group,
+ gl_surface_.get(),
+ gpu_preference);
if (!gl_context_.get()) {
Destroy();
return false;
diff --git a/ui/gfx/surface/accelerated_surface_mac.h b/ui/gfx/surface/accelerated_surface_mac.h
index 5163a57..0e29ae5 100644
--- a/ui/gfx/surface/accelerated_surface_mac.h
+++ b/ui/gfx/surface/accelerated_surface_mac.h
@@ -11,10 +11,11 @@
#include "base/callback_old.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/scoped_ptr.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/size.h"
#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_surface.h"
+#include "ui/gfx/gl/gpu_preference.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/size.h"
#include "ui/gfx/surface/surface_export.h"
#include "ui/gfx/surface/transport_dib.h"
@@ -46,9 +47,14 @@ class SURFACE_EXPORT AcceleratedSurface {
// an FBO internally does NOT work properly with client code which uses
// OpenGL (i.e., via GLES2 command buffers), because the GLES2
// implementation does not know to bind the accelerated surface's
- // internal FBO when the default FBO is bound. Returns false upon
+ // internal FBO when the default FBO is bound. |gpu_preference| indicates
+ // the GPU preference for the internally allocated GLContext. If
+ // |share_context| is non-NULL, then on platforms supporting dual GPUs,
+ // its GPU preference must match the passed one. Returns false upon
// failure.
- bool Initialize(gfx::GLContext* share_context, bool allocate_fbo);
+ bool Initialize(gfx::GLContext* share_context,
+ bool allocate_fbo,
+ gfx::GpuPreference gpu_preference);
// Tear down. Must be called before destructor to prevent leaks.
void Destroy();