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

Side by Side Diff: app/gfx/gl/gl_implementation.cc

Issue 6314005: Revert 71472 - Use GL rather than EGL by default on linux.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app/gfx/gl/gl_implementation.h ('k') | app/gfx/gl/gl_implementation_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/gfx/gl/gl_implementation.h" 5 #include "app/gfx/gl/gl_implementation.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "app/app_switches.h" 10 #include "app/app_switches.h"
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 14
15 namespace gfx { 15 namespace gfx {
16 16
17 const char kGLImplementationDesktopName[] = "desktop"; 17 const char kGLImplementationDesktopName[] = "desktop";
18 const char kGLImplementationOSMesaName[] = "osmesa"; 18 const char kGLImplementationOSMesaName[] = "osmesa";
19 const char kGLImplementationEGLName[] = "egl"; 19 const char kGLImplementationEGLName[] = "egl";
20 const char kGLImplementationMockName[] = "mock"; 20 const char kGLImplementationMockName[] = "mock";
21 21
22 namespace { 22 namespace {
23 23
24 const struct {
25 const char* name;
26 GLImplementation implementation;
27 } kGLImplementationNamePairs[] = {
28 { kGLImplementationDesktopName, kGLImplementationDesktopGL },
29 { kGLImplementationOSMesaName, kGLImplementationOSMesaGL },
30 { kGLImplementationEGLName, kGLImplementationEGLGLES2 },
31 { kGLImplementationMockName, kGLImplementationMockGL }
32 };
33
34 typedef std::vector<base::NativeLibrary> LibraryArray; 24 typedef std::vector<base::NativeLibrary> LibraryArray;
35 25
36 GLImplementation g_gl_implementation = kGLImplementationNone; 26 GLImplementation g_gl_implementation = kGLImplementationNone;
37 LibraryArray* g_libraries; 27 LibraryArray* g_libraries;
38 GLGetProcAddressProc g_get_proc_address; 28 GLGetProcAddressProc g_get_proc_address;
39 29
40 void CleanupNativeLibraries(void* unused) { 30 void CleanupNativeLibraries(void* unused) {
41 if (g_libraries) { 31 if (g_libraries) {
42 for (LibraryArray::iterator it = g_libraries->begin(); 32 for (LibraryArray::iterator it = g_libraries->begin();
43 it != g_libraries->end(); ++it) { 33 it != g_libraries->end(); ++it) {
44 base::UnloadNativeLibrary(*it); 34 base::UnloadNativeLibrary(*it);
45 } 35 }
46 delete g_libraries; 36 delete g_libraries;
47 g_libraries = NULL; 37 g_libraries = NULL;
48 } 38 }
49 } 39 }
50 } 40 }
51 41
52 GLImplementation GetNamedGLImplementation(const std::string& name) { 42 GLImplementation GetNamedGLImplementation(const std::string& name) {
53 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGLImplementationNamePairs); ++i) { 43 static const struct {
54 if (name == kGLImplementationNamePairs[i].name) 44 const char* name;
55 return kGLImplementationNamePairs[i].implementation; 45 GLImplementation implemention;
46 } name_pairs[] = {
47 { kGLImplementationDesktopName, kGLImplementationDesktopGL },
48 { kGLImplementationOSMesaName, kGLImplementationOSMesaGL },
49 { kGLImplementationEGLName, kGLImplementationEGLGLES2 },
50 { kGLImplementationMockName, kGLImplementationMockGL }
51 };
52
53 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(name_pairs); ++i) {
54 if (name == name_pairs[i].name)
55 return name_pairs[i].implemention;
56 } 56 }
57 57
58 return kGLImplementationNone; 58 return kGLImplementationNone;
59 } 59 }
60 60
61 const char* GetGLImplementationName(GLImplementation implementation) {
62 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGLImplementationNamePairs); ++i) {
63 if (implementation == kGLImplementationNamePairs[i].implementation)
64 return kGLImplementationNamePairs[i].name;
65 }
66
67 return "unknown";
68 }
69
70 bool InitializeBestGLBindings( 61 bool InitializeBestGLBindings(
71 const GLImplementation* allowed_implementations_begin, 62 const GLImplementation* allowed_implementations_begin,
72 const GLImplementation* allowed_implementations_end) { 63 const GLImplementation* allowed_implementations_end) {
73 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { 64 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
74 std::string requested_implementation_name = 65 std::string requested_implementation_name =
75 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); 66 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
76 GLImplementation requested_implementation = 67 GLImplementation requested_implementation =
77 GetNamedGLImplementation(requested_implementation_name); 68 GetNamedGLImplementation(requested_implementation_name);
78 if (std::find(allowed_implementations_begin, 69 if (std::find(allowed_implementations_begin,
79 allowed_implementations_end, 70 allowed_implementations_end,
80 requested_implementation) == allowed_implementations_end) { 71 requested_implementation) == allowed_implementations_end) {
81 LOG(ERROR) << "Requested GL implementation is not available."; 72 LOG(ERROR) << "Requested GL implementation is not allowed.";
82 return false; 73 return false;
83 } 74 }
84 75
85 InitializeGLBindings(requested_implementation); 76 if (InitializeGLBindings(requested_implementation))
77 return true;
86 } else { 78 } else {
87 for (const GLImplementation* p = allowed_implementations_begin; 79 for (const GLImplementation* p = allowed_implementations_begin;
88 p < allowed_implementations_end; 80 p < allowed_implementations_end;
89 ++p) { 81 ++p) {
90 if (InitializeGLBindings(*p)) 82 if (InitializeGLBindings(*p))
91 break; 83 return true;
92 } 84 }
93 } 85 }
94 86
95 if (GetGLImplementation() == kGLImplementationNone) { 87 LOG(ERROR) << "Could not initialize GL.";
96 LOG(ERROR) << "Could not initialize GL."; 88 return false;
97 return false;
98 } else {
99 LOG(INFO) << "Using "
100 << GetGLImplementationName(GetGLImplementation())
101 << " GL implementation.";
102 return true;
103 }
104 } 89 }
105 90
106 void SetGLImplementation(GLImplementation implementation) { 91 void SetGLImplementation(GLImplementation implementation) {
107 g_gl_implementation = implementation; 92 g_gl_implementation = implementation;
108 } 93 }
109 94
110 GLImplementation GetGLImplementation() { 95 GLImplementation GetGLImplementation() {
111 return g_gl_implementation; 96 return g_gl_implementation;
112 } 97 }
113 98
(...skipping 28 matching lines...) Expand all
142 if (g_get_proc_address) { 127 if (g_get_proc_address) {
143 void* proc = g_get_proc_address(name); 128 void* proc = g_get_proc_address(name);
144 if (proc) 129 if (proc)
145 return proc; 130 return proc;
146 } 131 }
147 132
148 return NULL; 133 return NULL;
149 } 134 }
150 135
151 } // namespace gfx 136 } // namespace gfx
OLDNEW
« no previous file with comments | « app/gfx/gl/gl_implementation.h ('k') | app/gfx/gl/gl_implementation_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698