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

Side by Side Diff: ui/gfx/gl/gl_implementation_mac.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_linux.cc ('k') | ui/gfx/gl/gl_implementation_win.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 "base/base_paths.h"
6 #include "base/file_path.h"
7 #include "base/logging.h"
8 #include "base/threading/thread_restrictions.h"
9 #include "base/mac/foundation_util.h"
10 #include "base/native_library.h"
11 #include "base/path_service.h"
12 #include "ui/gfx/gl/gl_bindings.h"
13 #include "ui/gfx/gl/gl_implementation.h"
14
15 namespace gfx {
16 namespace {
17 const char kOpenGLFrameworkPath[] =
18 "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL";
19 } // namespace anonymous
20
21 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
22 impls->push_back(kGLImplementationDesktopGL);
23 impls->push_back(kGLImplementationAppleGL);
24 impls->push_back(kGLImplementationOSMesaGL);
25 }
26
27 bool InitializeGLBindings(GLImplementation implementation) {
28 // Prevent reinitialization with a different implementation. Once the gpu
29 // unit tests have initialized with kGLImplementationMock, we don't want to
30 // later switch to another GL implementation.
31 if (GetGLImplementation() != kGLImplementationNone)
32 return true;
33
34 // Allow the main thread or another to initialize these bindings
35 // after instituting restrictions on I/O. Going forward they will
36 // likely be used in the browser process on most platforms. The
37 // one-time initialization cost is small, between 2 and 5 ms.
38 base::ThreadRestrictions::ScopedAllowIO allow_io;
39
40 switch (implementation) {
41 case kGLImplementationOSMesaGL: {
42 // osmesa.so is located in the build directory. This code path is only
43 // valid in a developer build environment.
44 FilePath exe_path;
45 if (!PathService::Get(base::FILE_EXE, &exe_path)) {
46 LOG(ERROR) << "PathService::Get failed.";
47 return false;
48 }
49 FilePath bundle_path = base::mac::GetAppBundlePath(exe_path);
50 FilePath build_dir_path = bundle_path.DirName();
51 FilePath osmesa_path = build_dir_path.Append("osmesa.so");
52
53 // When using OSMesa, just use OSMesaGetProcAddress to find entry points.
54 base::NativeLibrary library = base::LoadNativeLibrary(osmesa_path, NULL);
55 if (!library) {
56 LOG(ERROR) << "osmesa.so not found at " << osmesa_path.value();
57 return false;
58 }
59
60 GLGetProcAddressProc get_proc_address =
61 reinterpret_cast<GLGetProcAddressProc>(
62 base::GetFunctionPointerFromNativeLibrary(
63 library, "OSMesaGetProcAddress"));
64 if (!get_proc_address) {
65 LOG(ERROR) << "OSMesaGetProcAddress not found.";
66 base::UnloadNativeLibrary(library);
67 return false;
68 }
69
70 SetGLGetProcAddressProc(get_proc_address);
71 AddGLNativeLibrary(library);
72 SetGLImplementation(kGLImplementationOSMesaGL);
73
74 InitializeGLBindingsGL();
75 InitializeGLBindingsOSMESA();
76 break;
77 }
78 case kGLImplementationDesktopGL:
79 case kGLImplementationAppleGL: {
80 base::NativeLibrary library = base::LoadNativeLibrary(
81 FilePath(kOpenGLFrameworkPath), NULL);
82 if (!library) {
83 LOG(ERROR) << "OpenGL framework not found";
84 return false;
85 }
86
87 AddGLNativeLibrary(library);
88 SetGLImplementation(implementation);
89
90 InitializeGLBindingsGL();
91 break;
92 }
93 case kGLImplementationMockGL: {
94 SetGLGetProcAddressProc(GetMockGLProcAddress);
95 SetGLImplementation(kGLImplementationMockGL);
96 InitializeGLBindingsGL();
97 break;
98 }
99 default:
100 return false;
101 }
102
103 return true;
104 }
105
106 bool InitializeGLExtensionBindings(GLImplementation implementation,
107 GLContext* context) {
108 switch (implementation) {
109 case kGLImplementationOSMesaGL:
110 InitializeGLExtensionBindingsGL(context);
111 InitializeGLExtensionBindingsOSMESA(context);
112 break;
113 case kGLImplementationDesktopGL:
114 case kGLImplementationAppleGL:
115 InitializeGLExtensionBindingsGL(context);
116 break;
117 case kGLImplementationMockGL:
118 InitializeGLExtensionBindingsGL(context);
119 break;
120 default:
121 return false;
122 }
123
124 return true;
125 }
126
127 void InitializeDebugGLBindings() {
128 InitializeDebugGLBindingsGL();
129 InitializeDebugGLBindingsOSMESA();
130 }
131
132 void ClearGLBindings() {
133 ClearGLBindingsGL();
134 ClearGLBindingsOSMESA();
135 SetGLImplementation(kGLImplementationNone);
136
137 UnloadGLNativeLibraries();
138 }
139
140 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/gl/gl_implementation_linux.cc ('k') | ui/gfx/gl/gl_implementation_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698