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

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

Issue 17932004: Support ozone=1 compositor_unittests with OSMesa (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: include order version Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/gl/gl_implementation_ozone.cc ('k') | ui/gl/gl_surface_egl.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) 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 <vector> 5 #include <vector>
6 6
7 #include "base/base_paths.h"
8 #include "base/command_line.h" 7 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/logging.h" 8 #include "base/logging.h"
11 #include "base/native_library.h"
12 #include "base/path_service.h"
13 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
14 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
15 #include "ui/gl/gl_egl_api_implementation.h" 11 #include "ui/gl/gl_egl_api_implementation.h"
16 #include "ui/gl/gl_gl_api_implementation.h" 12 #include "ui/gl/gl_gl_api_implementation.h"
17 #include "ui/gl/gl_glx_api_implementation.h" 13 #include "ui/gl/gl_glx_api_implementation.h"
18 #include "ui/gl/gl_implementation.h" 14 #include "ui/gl/gl_implementation.h"
15 #include "ui/gl/gl_implementation_linux.h"
19 #include "ui/gl/gl_osmesa_api_implementation.h" 16 #include "ui/gl/gl_osmesa_api_implementation.h"
20 #include "ui/gl/gl_switches.h" 17 #include "ui/gl/gl_switches.h"
21 18
22 namespace gfx { 19 namespace gfx {
23 namespace { 20 namespace {
24 21
25 // TODO(piman): it should be Desktop GL marshalling from double to float. Today 22 // TODO(piman): it should be Desktop GL marshalling from double to float. Today
26 // on native GLES, we do float->double->float. 23 // on native GLES, we do float->double->float.
27 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { 24 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) {
28 glClearDepthf(static_cast<GLclampf>(depth)); 25 glClearDepthf(static_cast<GLclampf>(depth));
29 } 26 }
30 27
31 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, 28 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near,
32 GLclampd z_far) { 29 GLclampd z_far) {
33 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); 30 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far));
34 } 31 }
35 32
36 // Load a library, printing an error message on failure.
37 base::NativeLibrary LoadLibrary(const base::FilePath& filename) {
38 std::string error;
39 base::NativeLibrary library = base::LoadNativeLibrary(filename,
40 &error);
41 if (!library) {
42 DVLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error;
43 return NULL;
44 }
45 return library;
46 }
47
48 base::NativeLibrary LoadLibrary(const char* filename) {
49 return LoadLibrary(base::FilePath(filename));
50 }
51
52 } // namespace 33 } // namespace
53 34
54 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { 35 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
55 impls->push_back(kGLImplementationDesktopGL); 36 impls->push_back(kGLImplementationDesktopGL);
56 impls->push_back(kGLImplementationEGLGLES2); 37 impls->push_back(kGLImplementationEGLGLES2);
57 impls->push_back(kGLImplementationOSMesaGL); 38 impls->push_back(kGLImplementationOSMesaGL);
58 } 39 }
59 40
60 bool InitializeGLBindings(GLImplementation implementation) { 41 bool InitializeGLBindings(GLImplementation implementation) {
61 // Prevent reinitialization with a different implementation. Once the gpu 42 // Prevent reinitialization with a different implementation. Once the gpu
62 // unit tests have initialized with kGLImplementationMock, we don't want to 43 // unit tests have initialized with kGLImplementationMock, we don't want to
63 // later switch to another GL implementation. 44 // later switch to another GL implementation.
64 if (GetGLImplementation() != kGLImplementationNone) 45 if (GetGLImplementation() != kGLImplementationNone)
65 return true; 46 return true;
66 47
67 // Allow the main thread or another to initialize these bindings 48 // Allow the main thread or another to initialize these bindings
68 // after instituting restrictions on I/O. Going forward they will 49 // after instituting restrictions on I/O. Going forward they will
69 // likely be used in the browser process on most platforms. The 50 // likely be used in the browser process on most platforms. The
70 // one-time initialization cost is small, between 2 and 5 ms. 51 // one-time initialization cost is small, between 2 and 5 ms.
71 base::ThreadRestrictions::ScopedAllowIO allow_io; 52 base::ThreadRestrictions::ScopedAllowIO allow_io;
72 53
73 switch (implementation) { 54 switch (implementation) {
74 case kGLImplementationOSMesaGL: { 55 case kGLImplementationOSMesaGL:
75 base::FilePath module_path; 56 return InitializeGLBindingsOSMesaGL();
76 if (!PathService::Get(base::DIR_MODULE, &module_path)) {
77 LOG(ERROR) << "PathService::Get failed.";
78 return false;
79 }
80
81 base::NativeLibrary library = LoadLibrary(
82 module_path.Append("libosmesa.so"));
83 if (!library)
84 return false;
85
86 GLGetProcAddressProc get_proc_address =
87 reinterpret_cast<GLGetProcAddressProc>(
88 base::GetFunctionPointerFromNativeLibrary(
89 library, "OSMesaGetProcAddress"));
90 if (!get_proc_address) {
91 LOG(ERROR) << "OSMesaGetProcAddress not found.";
92 base::UnloadNativeLibrary(library);
93 return false;
94 }
95
96 SetGLGetProcAddressProc(get_proc_address);
97 AddGLNativeLibrary(library);
98 SetGLImplementation(kGLImplementationOSMesaGL);
99
100 InitializeGLBindingsGL();
101 InitializeGLBindingsOSMESA();
102 break;
103 }
104 case kGLImplementationDesktopGL: { 57 case kGLImplementationDesktopGL: {
105 base::NativeLibrary library = NULL; 58 base::NativeLibrary library = NULL;
106 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 59 const CommandLine* command_line = CommandLine::ForCurrentProcess();
107 60
108 if (command_line->HasSwitch(switches::kTestGLLib)) 61 if (command_line->HasSwitch(switches::kTestGLLib))
109 library = LoadLibrary(command_line->GetSwitchValueASCII( 62 library = LoadLibrary(command_line->GetSwitchValueASCII(
110 switches::kTestGLLib).c_str()); 63 switches::kTestGLLib).c_str());
111 64
112 if (!library) { 65 if (!library) {
113 #if defined(OS_OPENBSD) 66 #if defined(OS_OPENBSD)
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return GetGLWindowSystemBindingInfoGLX(info); 188 return GetGLWindowSystemBindingInfoGLX(info);
236 case kGLImplementationEGLGLES2: 189 case kGLImplementationEGLGLES2:
237 return GetGLWindowSystemBindingInfoEGL(info); 190 return GetGLWindowSystemBindingInfoEGL(info);
238 default: 191 default:
239 return false; 192 return false;
240 } 193 }
241 return false; 194 return false;
242 } 195 }
243 196
244 } // namespace gfx 197 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_implementation_ozone.cc ('k') | ui/gl/gl_surface_egl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698