Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/gl/gl_implementation.h" | 5 #include "ui/gfx/gl/gl_implementation.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 | 13 |
| 14 namespace gfx { | 14 namespace gfx { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const struct { | 18 const struct { |
| 19 const char* name; | 19 const char* name; |
| 20 GLImplementation implementation; | 20 GLImplementation implementation; |
| 21 } kGLImplementationNamePairs[] = { | 21 } kGLImplementationNamePairs[] = { |
| 22 { kGLImplementationDesktopName, kGLImplementationDesktopGL }, | 22 { kGLImplementationDesktopName, kGLImplementationDesktopGL }, |
| 23 { kGLImplementationOSMesaName, kGLImplementationOSMesaGL }, | 23 { kGLImplementationOSMesaName, kGLImplementationOSMesaGL }, |
| 24 { kGLImplementationEGLName, kGLImplementationEGLGLES2 }, | 24 { kGLImplementationEGLName, kGLImplementationEGLGLES2 }, |
| 25 { kGLImplementationMockName, kGLImplementationMockGL } | 25 { kGLImplementationMockName, kGLImplementationMockGL }, |
| 26 { kGLImplementationAnyName, kGLImplementationAny } | |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 typedef std::vector<base::NativeLibrary> LibraryArray; | 29 typedef std::vector<base::NativeLibrary> LibraryArray; |
| 29 | 30 |
| 30 GLImplementation g_gl_implementation = kGLImplementationNone; | 31 GLImplementation g_gl_implementation = kGLImplementationNone; |
| 31 LibraryArray* g_libraries; | 32 LibraryArray* g_libraries; |
| 32 GLGetProcAddressProc g_get_proc_address; | 33 GLGetProcAddressProc g_get_proc_address; |
| 33 | 34 |
| 34 void CleanupNativeLibraries(void* unused) { | 35 void CleanupNativeLibraries(void* unused) { |
| 35 if (g_libraries) { | 36 if (g_libraries) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 58 return kGLImplementationNamePairs[i].name; | 59 return kGLImplementationNamePairs[i].name; |
| 59 } | 60 } |
| 60 | 61 |
| 61 return "unknown"; | 62 return "unknown"; |
| 62 } | 63 } |
| 63 | 64 |
| 64 bool InitializeRequestedGLBindings( | 65 bool InitializeRequestedGLBindings( |
| 65 const GLImplementation* allowed_implementations_begin, | 66 const GLImplementation* allowed_implementations_begin, |
| 66 const GLImplementation* allowed_implementations_end, | 67 const GLImplementation* allowed_implementations_end, |
| 67 GLImplementation default_implementation) { | 68 GLImplementation default_implementation) { |
| 69 bool fallback_to_osmesa = false; | |
| 68 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { | 70 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { |
| 69 std::string requested_implementation_name = | 71 std::string requested_implementation_name = |
| 70 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); | 72 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); |
| 71 GLImplementation requested_implementation = | 73 GLImplementation requested_implementation = |
| 72 GetNamedGLImplementation(requested_implementation_name); | 74 GetNamedGLImplementation(requested_implementation_name); |
| 75 if (requested_implementation == kGLImplementationAny) { | |
|
alokp
2011/09/27 15:55:48
I do not think "use-gl=any" means fallback to osme
Zhenyao Mo
2011/09/27 17:17:31
Go through the list means on Windows we will try D
alokp
2011/09/27 17:22:25
If DesktopGL is not supported on windows, it shoul
Zhenyao Mo
2011/09/27 17:36:22
Currently we have only one list: allowed bindings.
| |
| 76 requested_implementation = default_implementation; | |
| 77 fallback_to_osmesa = true; | |
| 78 } | |
| 73 if (std::find(allowed_implementations_begin, | 79 if (std::find(allowed_implementations_begin, |
| 74 allowed_implementations_end, | 80 allowed_implementations_end, |
| 75 requested_implementation) == allowed_implementations_end) { | 81 requested_implementation) == allowed_implementations_end) { |
| 76 LOG(ERROR) << "Requested GL implementation is not available."; | 82 LOG(ERROR) << "Requested GL implementation is not available."; |
| 77 return false; | 83 return false; |
| 78 } | 84 } |
| 79 | 85 |
| 80 InitializeGLBindings(requested_implementation); | 86 InitializeGLBindings(requested_implementation); |
| 81 } else { | 87 } else { |
| 82 InitializeGLBindings(default_implementation); | 88 InitializeGLBindings(default_implementation); |
| 83 } | 89 } |
| 84 | 90 |
| 91 if (GetGLImplementation() == kGLImplementationNone && fallback_to_osmesa) | |
| 92 InitializeGLBindings(kGLImplementationOSMesaGL); | |
| 93 | |
| 85 if (CommandLine::ForCurrentProcess()->HasSwitch( | 94 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 86 switches::kEnableGPUServiceLogging)) { | 95 switches::kEnableGPUServiceLogging)) { |
| 87 InitializeDebugGLBindings(); | 96 InitializeDebugGLBindings(); |
| 88 } | 97 } |
| 89 | 98 |
| 90 if (GetGLImplementation() == kGLImplementationNone) { | 99 if (GetGLImplementation() == kGLImplementationNone) { |
| 91 LOG(ERROR) << "Could not initialize GL."; | 100 LOG(ERROR) << "Could not initialize GL."; |
| 92 return false; | 101 return false; |
| 93 } else { | 102 } else { |
| 94 LOG(INFO) << "Using " | 103 LOG(INFO) << "Using " |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 if (g_get_proc_address) { | 151 if (g_get_proc_address) { |
| 143 void* proc = g_get_proc_address(name); | 152 void* proc = g_get_proc_address(name); |
| 144 if (proc) | 153 if (proc) |
| 145 return proc; | 154 return proc; |
| 146 } | 155 } |
| 147 | 156 |
| 148 return NULL; | 157 return NULL; |
| 149 } | 158 } |
| 150 | 159 |
| 151 } // namespace gfx | 160 } // namespace gfx |
| OLD | NEW |