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

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

Issue 2024953002: Move GL one-off initialization code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split_x11
Patch Set: Fix windows compile. Created 4 years, 7 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
Index: ui/gl/init/gl_initializer.cc
diff --git a/ui/gl/init/gl_initializer.cc b/ui/gl/init/gl_initializer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3164891cff6f7ac7df1a730d0efe577589741613
--- /dev/null
+++ b/ui/gl/init/gl_initializer.cc
@@ -0,0 +1,87 @@
+// 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 <string>
+#include <vector>
+
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/trace_event/trace_event.h"
+#include "ui/gl/gl_surface.h"
+#include "ui/gl/init/gl_factory.h"
+
+namespace gl {
+namespace init {
+
+bool InitializeGLOneOff() {
+ TRACE_EVENT0("gpu,startup", "gl::init::InitializeOneOff");
+
+ DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
+
+ std::vector<GLImplementation> allowed_impls;
+ GetAllowedGLImplementations(&allowed_impls);
+ DCHECK(!allowed_impls.empty());
+
+ base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
+
+ // The default implementation is always the first one in list.
+ GLImplementation impl = allowed_impls[0];
+ bool fallback_to_osmesa = false;
+ if (cmd->HasSwitch(switches::kOverrideUseGLWithOSMesaForTests)) {
+ impl = kGLImplementationOSMesaGL;
+ } else if (cmd->HasSwitch(switches::kUseGL)) {
+ std::string requested_implementation_name =
+ cmd->GetSwitchValueASCII(switches::kUseGL);
+ if (requested_implementation_name == "any") {
+ fallback_to_osmesa = true;
+ } else if (requested_implementation_name ==
+ kGLImplementationSwiftShaderName ||
+ requested_implementation_name == kGLImplementationANGLEName) {
+ impl = kGLImplementationEGLGLES2;
+ } else {
+ impl = GetNamedGLImplementation(requested_implementation_name);
+ if (!ContainsValue(allowed_impls, impl)) {
+ LOG(ERROR) << "Requested GL implementation is not available.";
+ return false;
+ }
+ }
+ }
+
+ bool gpu_service_logging = cmd->HasSwitch(switches::kEnableGPUServiceLogging);
+ bool disable_gl_drawing = cmd->HasSwitch(switches::kDisableGLDrawingForTests);
+
+ return GLInitializer::InitializeOneOffImplementation(
+ impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing);
+}
+
+// static
+bool GLInitializer::InitializeOneOffImplementation(GLImplementation impl,
+ bool fallback_to_osmesa,
+ bool gpu_service_logging,
+ bool disable_gl_drawing) {
+ bool initialized =
+ InitializeStaticGLBindings(impl) && InitializeOneOffPlatform();
+ if (!initialized && fallback_to_osmesa) {
+ ClearGLBindings();
+ initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) &&
+ InitializeOneOffPlatform();
+ }
+ if (!initialized)
+ ClearGLBindings();
+
+ if (initialized) {
+ DVLOG(1) << "Using " << GetGLImplementationName(GetGLImplementation())
+ << " GL implementation.";
+ if (gpu_service_logging)
+ InitializeDebugGLBindings();
+ if (disable_gl_drawing)
+ InitializeNullDrawGLBindings();
+ }
+ return initialized;
+}
+
+} // namespace init
+} // namespace gl

Powered by Google App Engine
This is Rietveld 408576698