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

Side by Side Diff: ui/gl/gl_implementation_mac.cc

Issue 2099163003: Revert of Move static GL binding initialization to //ui/gl/init. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « ui/gl/gl_implementation_android.cc ('k') | ui/gl/gl_implementation_osmesa.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gl/gl_implementation.h" 5 #include "base/base_paths.h"
6
7 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/mac/foundation_util.h"
10 #include "base/native_library.h"
11 #include "base/path_service.h"
12 #include "base/threading/thread_restrictions.h"
13 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/gl_context_stub_with_extensions.h" 14 #include "ui/gl/gl_context_stub_with_extensions.h"
10 #include "ui/gl/gl_gl_api_implementation.h" 15 #include "ui/gl/gl_gl_api_implementation.h"
16 #include "ui/gl/gl_implementation.h"
11 #include "ui/gl/gl_osmesa_api_implementation.h" 17 #include "ui/gl/gl_osmesa_api_implementation.h"
12 18
13 namespace gl { 19 namespace gl {
20 namespace {
21 const char kOpenGLFrameworkPath[] =
22 "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL";
23 } // namespace
14 24
15 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { 25 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
16 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 26 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
17 switches::kEnableUnsafeES3APIs)) { 27 switches::kEnableUnsafeES3APIs)) {
18 impls->push_back(kGLImplementationDesktopGLCoreProfile); 28 impls->push_back(kGLImplementationDesktopGLCoreProfile);
19 } 29 }
20 impls->push_back(kGLImplementationDesktopGL); 30 impls->push_back(kGLImplementationDesktopGL);
21 impls->push_back(kGLImplementationAppleGL); 31 impls->push_back(kGLImplementationAppleGL);
22 impls->push_back(kGLImplementationOSMesaGL); 32 impls->push_back(kGLImplementationOSMesaGL);
23 } 33 }
24 34
35 bool InitializeStaticGLBindings(GLImplementation implementation) {
36 // Prevent reinitialization with a different implementation. Once the gpu
37 // unit tests have initialized with kGLImplementationMock, we don't want to
38 // later switch to another GL implementation.
39 DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
40
41 // Allow the main thread or another to initialize these bindings
42 // after instituting restrictions on I/O. Going forward they will
43 // likely be used in the browser process on most platforms. The
44 // one-time initialization cost is small, between 2 and 5 ms.
45 base::ThreadRestrictions::ScopedAllowIO allow_io;
46
47 switch (implementation) {
48 case kGLImplementationOSMesaGL: {
49 // osmesa.so is located in the build directory. This code path is only
50 // valid in a developer build environment.
51 base::FilePath exe_path;
52 if (!PathService::Get(base::FILE_EXE, &exe_path)) {
53 LOG(ERROR) << "PathService::Get failed.";
54 return false;
55 }
56 base::FilePath bundle_path = base::mac::GetAppBundlePath(exe_path);
57 // Some unit test targets depend on osmesa but aren't built as app
58 // bundles. In that case, the .so is next to the executable.
59 if (bundle_path.empty())
60 bundle_path = exe_path;
61 base::FilePath build_dir_path = bundle_path.DirName();
62 base::FilePath osmesa_path = build_dir_path.Append("osmesa.so");
63
64 // When using OSMesa, just use OSMesaGetProcAddress to find entry points.
65 base::NativeLibrary library = base::LoadNativeLibrary(osmesa_path, NULL);
66 if (!library) {
67 LOG(ERROR) << "osmesa.so not found at " << osmesa_path.value();
68 return false;
69 }
70
71 GLGetProcAddressProc get_proc_address =
72 reinterpret_cast<GLGetProcAddressProc>(
73 base::GetFunctionPointerFromNativeLibrary(
74 library, "OSMesaGetProcAddress"));
75 if (!get_proc_address) {
76 LOG(ERROR) << "OSMesaGetProcAddress not found.";
77 base::UnloadNativeLibrary(library);
78 return false;
79 }
80
81 SetGLGetProcAddressProc(get_proc_address);
82 AddGLNativeLibrary(library);
83 SetGLImplementation(kGLImplementationOSMesaGL);
84
85 InitializeStaticGLBindingsGL();
86 InitializeStaticGLBindingsOSMESA();
87 break;
88 }
89 case kGLImplementationDesktopGL:
90 case kGLImplementationDesktopGLCoreProfile:
91 case kGLImplementationAppleGL: {
92 base::NativeLibrary library = base::LoadNativeLibrary(
93 base::FilePath(kOpenGLFrameworkPath), NULL);
94 if (!library) {
95 LOG(ERROR) << "OpenGL framework not found";
96 return false;
97 }
98
99 AddGLNativeLibrary(library);
100 SetGLImplementation(implementation);
101
102 InitializeStaticGLBindingsGL();
103 break;
104 }
105 case kGLImplementationMockGL: {
106 SetGLImplementation(kGLImplementationMockGL);
107 InitializeStaticGLBindingsGL();
108 break;
109 }
110 default:
111 return false;
112 }
113
114 return true;
115 }
116
25 bool InitializeDynamicGLBindings(GLImplementation implementation, 117 bool InitializeDynamicGLBindings(GLImplementation implementation,
26 GLContext* context) { 118 GLContext* context) {
27 switch (implementation) { 119 switch (implementation) {
28 case kGLImplementationOSMesaGL: 120 case kGLImplementationOSMesaGL:
29 case kGLImplementationDesktopGL: 121 case kGLImplementationDesktopGL:
30 case kGLImplementationDesktopGLCoreProfile: 122 case kGLImplementationDesktopGLCoreProfile:
31 case kGLImplementationAppleGL: 123 case kGLImplementationAppleGL:
32 InitializeDynamicGLBindingsGL(context); 124 InitializeDynamicGLBindingsGL(context);
33 break; 125 break;
34 case kGLImplementationMockGL: 126 case kGLImplementationMockGL:
35 if (!context) { 127 if (!context) {
36 scoped_refptr<GLContextStubWithExtensions> mock_context( 128 scoped_refptr<GLContextStubWithExtensions> mock_context(
37 new GLContextStubWithExtensions()); 129 new GLContextStubWithExtensions());
38 mock_context->SetGLVersionString("3.0"); 130 mock_context->SetGLVersionString("3.0");
39 InitializeDynamicGLBindingsGL(mock_context.get()); 131 InitializeDynamicGLBindingsGL(mock_context.get());
40 } else { 132 } else
41 InitializeDynamicGLBindingsGL(context); 133 InitializeDynamicGLBindingsGL(context);
42 }
43 break; 134 break;
44 default: 135 default:
45 return false; 136 return false;
46 } 137 }
47 138
48 return true; 139 return true;
49 } 140 }
50 141
142 void InitializeDebugGLBindings() {
143 InitializeDebugGLBindingsGL();
144 InitializeDebugGLBindingsOSMESA();
145 }
146
147 void ClearGLBindings() {
148 ClearGLBindingsGL();
149 ClearGLBindingsOSMESA();
150 SetGLImplementation(kGLImplementationNone);
151
152 UnloadGLNativeLibraries();
153 }
154
51 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { 155 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
52 return false; 156 return false;
53 } 157 }
54 158
55 } // namespace gl 159 } // namespace gl
OLDNEW
« no previous file with comments | « ui/gl/gl_implementation_android.cc ('k') | ui/gl/gl_implementation_osmesa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698