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

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

Issue 10392068: ui: Move gl/ directory out of gfx/, up to ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac_rel Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/gl/gl_implementation.h ('k') | ui/gfx/gl/gl_implementation_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/gfx/gl/gl_implementation.h"
6
7 #include <algorithm>
8 #include <string>
9
10 #include "base/at_exit.h"
11 #include "base/command_line.h"
12 #include "base/logging.h"
13
14 namespace gfx {
15
16 namespace {
17
18 const struct {
19 const char* name;
20 GLImplementation implementation;
21 } kGLImplementationNamePairs[] = {
22 { kGLImplementationDesktopName, kGLImplementationDesktopGL },
23 { kGLImplementationOSMesaName, kGLImplementationOSMesaGL },
24 #if defined(OS_MACOSX)
25 { kGLImplementationAppleName, kGLImplementationAppleGL },
26 #endif
27 { kGLImplementationEGLName, kGLImplementationEGLGLES2 },
28 { kGLImplementationMockName, kGLImplementationMockGL }
29 };
30
31 typedef std::vector<base::NativeLibrary> LibraryArray;
32
33 GLImplementation g_gl_implementation = kGLImplementationNone;
34 LibraryArray* g_libraries;
35 GLGetProcAddressProc g_get_proc_address;
36
37 void CleanupNativeLibraries(void* unused) {
38 if (g_libraries) {
39 for (LibraryArray::iterator it = g_libraries->begin();
40 it != g_libraries->end(); ++it) {
41 base::UnloadNativeLibrary(*it);
42 }
43 delete g_libraries;
44 g_libraries = NULL;
45 }
46 }
47
48 bool ExportsCoreFunctionsFromGetProcAddress(GLImplementation implementation) {
49 switch (GetGLImplementation()) {
50 case kGLImplementationDesktopGL:
51 case kGLImplementationOSMesaGL:
52 case kGLImplementationAppleGL:
53 case kGLImplementationMockGL:
54 return true;
55 case kGLImplementationEGLGLES2:
56 return false;
57 default:
58 NOTREACHED();
59 return true;
60 }
61 }
62
63 }
64
65 GLImplementation GetNamedGLImplementation(const std::string& name) {
66 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGLImplementationNamePairs); ++i) {
67 if (name == kGLImplementationNamePairs[i].name)
68 return kGLImplementationNamePairs[i].implementation;
69 }
70
71 return kGLImplementationNone;
72 }
73
74 const char* GetGLImplementationName(GLImplementation implementation) {
75 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kGLImplementationNamePairs); ++i) {
76 if (implementation == kGLImplementationNamePairs[i].implementation)
77 return kGLImplementationNamePairs[i].name;
78 }
79
80 return "unknown";
81 }
82
83 void SetGLImplementation(GLImplementation implementation) {
84 g_gl_implementation = implementation;
85 }
86
87 GLImplementation GetGLImplementation() {
88 return g_gl_implementation;
89 }
90
91 bool HasDesktopGLFeatures() {
92 return kGLImplementationDesktopGL == g_gl_implementation ||
93 kGLImplementationOSMesaGL == g_gl_implementation ||
94 kGLImplementationAppleGL == g_gl_implementation;
95 }
96
97 void AddGLNativeLibrary(base::NativeLibrary library) {
98 DCHECK(library);
99
100 if (!g_libraries) {
101 g_libraries = new LibraryArray;
102 base::AtExitManager::RegisterCallback(CleanupNativeLibraries, NULL);
103 }
104
105 g_libraries->push_back(library);
106 }
107
108 void UnloadGLNativeLibraries() {
109 CleanupNativeLibraries(NULL);
110 }
111
112 void SetGLGetProcAddressProc(GLGetProcAddressProc proc) {
113 DCHECK(proc);
114 g_get_proc_address = proc;
115 }
116
117 void* GetGLCoreProcAddress(const char* name) {
118 DCHECK(g_gl_implementation != kGLImplementationNone);
119
120 if (g_libraries) {
121 for (size_t i = 0; i < g_libraries->size(); ++i) {
122 void* proc = base::GetFunctionPointerFromNativeLibrary((*g_libraries)[i],
123 name);
124 if (proc)
125 return proc;
126 }
127 }
128 if (ExportsCoreFunctionsFromGetProcAddress(g_gl_implementation) &&
129 g_get_proc_address) {
130 void* proc = g_get_proc_address(name);
131 if (proc)
132 return proc;
133 }
134
135 return NULL;
136 }
137
138 void* GetGLProcAddress(const char* name) {
139 DCHECK(g_gl_implementation != kGLImplementationNone);
140
141 void* proc = GetGLCoreProcAddress(name);
142 if (!proc && g_get_proc_address) {
143 proc = g_get_proc_address(name);
144 if (proc)
145 return proc;
146 }
147
148 return proc;
149 }
150
151 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/gl/gl_implementation.h ('k') | ui/gfx/gl/gl_implementation_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698