summaryrefslogtreecommitdiffstats
path: root/ui/gl/gl_context_mac.mm
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-12 21:17:27 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-12 21:17:27 +0000
commitc9e2cbbbcad5f0ae5b9c5ccaf6a36a8a4a61e0e7 (patch)
treee33d97dc2edae8702ddb6a17ba0d89a506412693 /ui/gl/gl_context_mac.mm
parentfc25fd35147b2d5e74d5450e8586592c6a10813d (diff)
downloadchromium_src-c9e2cbbbcad5f0ae5b9c5ccaf6a36a8a4a61e0e7.zip
chromium_src-c9e2cbbbcad5f0ae5b9c5ccaf6a36a8a4a61e0e7.tar.gz
chromium_src-c9e2cbbbcad5f0ae5b9c5ccaf6a36a8a4a61e0e7.tar.bz2
ui: Move gl/ directory out of gfx/, up to ui/.
BUG=104040 R=ben@chromium.org TBR=tony@chromium.org Review URL: https://chromiumcodereview.appspot.com/10392068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136777 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gl/gl_context_mac.mm')
-rw-r--r--ui/gl/gl_context_mac.mm184
1 files changed, 184 insertions, 0 deletions
diff --git a/ui/gl/gl_context_mac.mm b/ui/gl/gl_context_mac.mm
new file mode 100644
index 0000000..06829be
--- /dev/null
+++ b/ui/gl/gl_context_mac.mm
@@ -0,0 +1,184 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/mac/mac_util.h"
+#include "base/memory/scoped_generic_obj.h"
+#include "base/memory/scoped_ptr.h"
+#include "third_party/mesa/MesaLib/include/GL/osmesa.h"
+#include "ui/gl/gl_bindings.h"
+#include "ui/gl/gl_context_cgl.h"
+#include "ui/gl/gl_context_osmesa.h"
+#include "ui/gl/gl_context_stub.h"
+#include "ui/gl/gl_implementation.h"
+#include "ui/gl/gl_surface.h"
+#include "ui/gl/gl_switches.h"
+
+#if defined(USE_AURA)
+#include "ui/gl/gl_context_nsview.h"
+#endif
+
+namespace {
+
+// ScopedGenericObj functor for CGLDestroyRendererInfo().
+class ScopedDestroyRendererInfo {
+ public:
+ void operator()(CGLRendererInfoObj x) const {
+ CGLDestroyRendererInfo(x);
+ }
+};
+
+} // namespace
+
+namespace gfx {
+
+class GLShareGroup;
+
+scoped_refptr<GLContext> GLContext::CreateGLContext(
+ GLShareGroup* share_group,
+ GLSurface* compatible_surface,
+ GpuPreference gpu_preference) {
+ switch (GetGLImplementation()) {
+ case kGLImplementationDesktopGL:
+ case kGLImplementationAppleGL: {
+ scoped_refptr<GLContext> context;
+#if defined(USE_AURA)
+ if (compatible_surface->IsOffscreen())
+ context = new GLContextCGL(share_group);
+ else
+ context = new GLContextNSView(share_group);
+#else
+ context = new GLContextCGL(share_group);
+#endif // USE_AURA
+ if (!context->Initialize(compatible_surface, gpu_preference))
+ return NULL;
+
+ return context;
+ }
+ case kGLImplementationOSMesaGL: {
+ scoped_refptr<GLContext> context(new GLContextOSMesa(share_group));
+ if (!context->Initialize(compatible_surface, gpu_preference))
+ return NULL;
+
+ return context;
+ }
+ case kGLImplementationMockGL:
+ return new GLContextStub;
+ default:
+ NOTREACHED();
+ return NULL;
+ }
+}
+
+bool GLContext::SupportsDualGpus() {
+ // We need to know the GL implementation in order to correctly
+ // answer whether dual GPUs are supported. This introduces an
+ // initialization cycle with GLSurface::InitializeOneOff() which we
+ // need to break.
+ static bool initialized = false;
+ static bool initializing = false;
+ static bool supports_dual_gpus = false;
+
+ if (initialized) {
+ return supports_dual_gpus;
+ } else {
+ if (!initializing) {
+ initializing = true;
+ if (!GLSurface::InitializeOneOff()) {
+ return false;
+ }
+ }
+ initialized = true;
+ }
+
+ if (!base::mac::IsOSLionOrLater()) {
+ return false;
+ }
+
+ if (GetGLImplementation() != kGLImplementationDesktopGL) {
+ return false;
+ }
+
+ // Enumerate all hardware-accelerated renderers. If we find one
+ // online and one offline, assume we're on a dual-GPU system.
+ GLuint display_mask = static_cast<GLuint>(-1);
+ CGLRendererInfoObj renderer_info = NULL;
+ GLint num_renderers = 0;
+
+ bool found_online = false;
+ bool found_offline = false;
+
+ if (CGLQueryRendererInfo(display_mask,
+ &renderer_info,
+ &num_renderers) != kCGLNoError) {
+ return false;
+ }
+
+ ScopedGenericObj<CGLRendererInfoObj, ScopedDestroyRendererInfo>
+ scoper(renderer_info);
+
+ for (GLint i = 0; i < num_renderers; ++i) {
+ GLint accelerated = 0;
+ if (CGLDescribeRenderer(renderer_info,
+ i,
+ kCGLRPAccelerated,
+ &accelerated) != kCGLNoError) {
+ return false;
+ }
+
+ if (!accelerated)
+ continue;
+
+ GLint online = 0;
+ if (CGLDescribeRenderer(renderer_info,
+ i,
+ kCGLRPOnline,
+ &online) != kCGLNoError) {
+ return false;
+ }
+
+ if (online) {
+ found_online = true;
+ } else {
+ found_offline = true;
+ }
+ }
+
+ if (found_online && found_offline) {
+ // Only switch GPUs dynamically on recent MacBook Pro models.
+ // Otherwise, keep the system on the discrete GPU for the lifetime
+ // of the browser process, since switching back and forth causes
+ // system stability issues. http://crbug.com/113703
+ std::string model;
+ int32 model_major, model_minor;
+ if (!base::mac::ParseModelIdentifier(base::mac::GetModelIdentifier(),
+ &model, &model_major, &model_minor)) {
+ return false;
+ }
+
+ const int kMacBookProFirstDualAMDIntelGPUModel = 8;
+
+ bool forcibly_disable =
+ ((model == "MacBookPro") &&
+ (model_major < kMacBookProFirstDualAMDIntelGPUModel)) ||
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableGpuSwitching) ||
+ // http://crbug.com/127713 : disable dynamic GPU switching on
+ // 10.8 until system stability issues are resolved by Apple.
+ base::mac::IsOSMountainLion();
+
+ if (forcibly_disable) {
+ GLContextCGL::ForceUseOfDiscreteGPU();
+ return false;
+ }
+
+ supports_dual_gpus = true;
+ }
+
+ return supports_dual_gpus;
+}
+
+} // namespace gfx