Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(713)

Unified Diff: ui/gl/init/gl_initializer_mac.cc

Issue 2024953002: Move GL one-off initialization code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split_x11
Patch Set: Delete GLInitializer class. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/init/gl_initializer_android.cc ('k') | ui/gl/init/gl_initializer_ozone.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/init/gl_initializer_mac.cc
diff --git a/ui/gl/init/gl_initializer_mac.cc b/ui/gl/init/gl_initializer_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d62a47c5b1e40b64fb55bb2c95e6513ebb65fa8e
--- /dev/null
+++ b/ui/gl/init/gl_initializer_mac.cc
@@ -0,0 +1,78 @@
+// Copyright 2016 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 "ui/gl/init/gl_initializer.h"
+
+#include <OpenGL/CGLRenderers.h>
+
+#include <vector>
+
+#include "base/logging.h"
+#include "ui/gl/gl_bindings.h"
+#include "ui/gl/gl_implementation.h"
+#include "ui/gl/gl_surface.h"
+#include "ui/gl/gpu_switching_manager.h"
+
+namespace gl {
+namespace init {
+
+namespace {
+
+bool InitializeOneOffForSandbox() {
+ static bool initialized = false;
+ if (initialized)
+ return true;
+
+ // This is called from the sandbox warmup code on Mac OS X.
+ // GPU-related stuff is very slow without this, probably because
+ // the sandbox prevents loading graphics drivers or some such.
+ std::vector<CGLPixelFormatAttribute> attribs;
+ if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) {
+ // Avoid switching to the discrete GPU just for this pixel
+ // format selection.
+ attribs.push_back(kCGLPFAAllowOfflineRenderers);
+ }
+ if (GetGLImplementation() == kGLImplementationAppleGL) {
+ attribs.push_back(kCGLPFARendererID);
+ attribs.push_back(
+ static_cast<CGLPixelFormatAttribute>(kCGLRendererGenericFloatID));
+ }
+ attribs.push_back(static_cast<CGLPixelFormatAttribute>(0));
+
+ CGLPixelFormatObj format;
+ GLint num_pixel_formats;
+ if (CGLChoosePixelFormat(&attribs.front(), &format, &num_pixel_formats) !=
+ kCGLNoError) {
+ LOG(ERROR) << "Error choosing pixel format.";
+ return false;
+ }
+ if (!format) {
+ LOG(ERROR) << "format == 0.";
+ return false;
+ }
+ CGLReleasePixelFormat(format);
+ DCHECK_NE(num_pixel_formats, 0);
+ initialized = true;
+ return true;
+}
+
+} // namespace
+
+bool InitializeGLOneOffPlatform() {
+ switch (GetGLImplementation()) {
+ case kGLImplementationDesktopGL:
+ case kGLImplementationDesktopGLCoreProfile:
+ case kGLImplementationAppleGL:
+ if (!InitializeOneOffForSandbox()) {
+ LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed.";
+ return false;
+ }
+ return true;
+ default:
+ return true;
+ }
+}
+
+} // namespace init
+} // namespace gl
« no previous file with comments | « ui/gl/init/gl_initializer_android.cc ('k') | ui/gl/init/gl_initializer_ozone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698