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

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

Issue 6325005: Relanding r71472.... Base URL: svn://chrome-svn/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
24 typedef std::vector<base::NativeLibrary> LibraryArray; 34 typedef std::vector<base::NativeLibrary> LibraryArray;
25 35
26 GLImplementation g_gl_implementation = kGLImplementationNone; 36 GLImplementation g_gl_implementation = kGLImplementationNone;
27 LibraryArray* g_libraries; 37 LibraryArray* g_libraries;
28 GLGetProcAddressProc g_get_proc_address; 38 GLGetProcAddressProc g_get_proc_address;
29 39
30 void CleanupNativeLibraries(void* unused) { 40 void CleanupNativeLibraries(void* unused) {
31 if (g_libraries) { 41 if (g_libraries) {
32 for (LibraryArray::iterator it = g_libraries->begin(); 42 for (LibraryArray::iterator it = g_libraries->begin();
33 it != g_libraries->end(); ++it) { 43 it != g_libraries->end(); ++it) {
34 base::UnloadNativeLibrary(*it); 44 base::UnloadNativeLibrary(*it);
35 } 45 }
36 delete g_libraries; 46 delete g_libraries;
37 g_libraries = NULL; 47 g_libraries = NULL;
38 } 48 }
39 } 49 }
40 } 50 }
41 51
42 GLImplementation GetNamedGLImplementation(const std::string& name) { 52 GLImplementation GetNamedGLImplementation(const std::string& name) {
43 static const struct { 53 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGLImplementationNamePairs); ++i) {
44 const char* name; 54 if (name == kGLImplementationNamePairs[i].name)
45 GLImplementation implemention; 55 return kGLImplementationNamePairs[i].implementation;
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
61 bool InitializeBestGLBindings( 70 bool InitializeBestGLBindings(
62 const GLImplementation* allowed_implementations_begin, 71 const GLImplementation* allowed_implementations_begin,
63 const GLImplementation* allowed_implementations_end) { 72 const GLImplementation* allowed_implementations_end) {
64 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) { 73 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
65 std::string requested_implementation_name = 74 std::string requested_implementation_name =
66 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL); 75 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
67 GLImplementation requested_implementation = 76 GLImplementation requested_implementation =
68 GetNamedGLImplementation(requested_implementation_name); 77 GetNamedGLImplementation(requested_implementation_name);
69 if (std::find(allowed_implementations_begin, 78 if (std::find(allowed_implementations_begin,
70 allowed_implementations_end, 79 allowed_implementations_end,
71 requested_implementation) == allowed_implementations_end) { 80 requested_implementation) == allowed_implementations_end) {
72 LOG(ERROR) << "Requested GL implementation is not allowed."; 81 LOG(ERROR) << "Requested GL implementation is not available.";
73 return false; 82 return false;
74 } 83 }
75 84
76 if (InitializeGLBindings(requested_implementation)) 85 InitializeGLBindings(requested_implementation);
77 return true;
78 } else { 86 } else {
79 for (const GLImplementation* p = allowed_implementations_begin; 87 for (const GLImplementation* p = allowed_implementations_begin;
80 p < allowed_implementations_end; 88 p < allowed_implementations_end;
81 ++p) { 89 ++p) {
82 if (InitializeGLBindings(*p)) 90 if (InitializeGLBindings(*p))
83 return true; 91 break;
84 } 92 }
85 } 93 }
86 94
87 LOG(ERROR) << "Could not initialize GL."; 95 if (GetGLImplementation() == kGLImplementationNone) {
88 return false; 96 LOG(ERROR) << "Could not initialize GL.";
97 return false;
98 } else {
99 LOG(INFO) << "Using "
100 << GetGLImplementationName(GetGLImplementation())
101 << " GL implementation.";
102 return true;
103 }
89 } 104 }
90 105
91 void SetGLImplementation(GLImplementation implementation) { 106 void SetGLImplementation(GLImplementation implementation) {
92 g_gl_implementation = implementation; 107 g_gl_implementation = implementation;
93 } 108 }
94 109
95 GLImplementation GetGLImplementation() { 110 GLImplementation GetGLImplementation() {
96 return g_gl_implementation; 111 return g_gl_implementation;
97 } 112 }
98 113
(...skipping 28 matching lines...) Expand all
127 if (g_get_proc_address) { 142 if (g_get_proc_address) {
128 void* proc = g_get_proc_address(name); 143 void* proc = g_get_proc_address(name);
129 if (proc) 144 if (proc)
130 return proc; 145 return proc;
131 } 146 }
132 147
133 return NULL; 148 return NULL;
134 } 149 }
135 150
136 } // namespace gfx 151 } // 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