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
3 // found in the LICENSE file.
5 #include "base/base_paths.h"
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/native_library.h"
10 #include "base/path_service.h"
11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_egl_api_implementation.h"
13 #include "ui/gl/gl_gl_api_implementation.h"
14 #include "ui/gl/gl_implementation.h"
15 #include "ui/gl/gl_osmesa_api_implementation.h"
21 void GL_BINDING_CALL
MarshalClearDepthToClearDepthf(GLclampd depth
) {
22 glClearDepthf(static_cast<GLclampf
>(depth
));
25 void GL_BINDING_CALL
MarshalDepthRangeToDepthRangef(GLclampd z_near
,
27 glDepthRangef(static_cast<GLclampf
>(z_near
), static_cast<GLclampf
>(z_far
));
30 base::NativeLibrary
LoadLibrary(const base::FilePath
& filename
) {
32 base::NativeLibrary library
= base::LoadNativeLibrary(filename
, &error
);
34 DVLOG(1) << "Failed to load " << filename
.MaybeAsASCII() << ": " << error
;
40 base::NativeLibrary
LoadLibrary(const char* filename
) {
41 return LoadLibrary(base::FilePath(filename
));
46 void GetAllowedGLImplementations(std::vector
<GLImplementation
>* impls
) {
47 impls
->push_back(kGLImplementationEGLGLES2
);
50 bool InitializeGLBindings(GLImplementation implementation
) {
51 // Prevent reinitialization with a different implementation. Once the gpu
52 // unit tests have initialized with kGLImplementationMock, we don't want to
53 // later switch to another GL implementation.
54 if (GetGLImplementation() != kGLImplementationNone
)
57 switch (implementation
) {
58 case kGLImplementationEGLGLES2
: {
59 base::NativeLibrary gles_library
= LoadLibrary("libGLESv2.so");
62 base::NativeLibrary egl_library
= LoadLibrary("libEGL.so");
64 base::UnloadNativeLibrary(gles_library
);
68 GLGetProcAddressProc get_proc_address
=
69 reinterpret_cast<GLGetProcAddressProc
>(
70 base::GetFunctionPointerFromNativeLibrary(
71 egl_library
, "eglGetProcAddress"));
72 if (!get_proc_address
) {
73 LOG(ERROR
) << "eglGetProcAddress not found.";
74 base::UnloadNativeLibrary(egl_library
);
75 base::UnloadNativeLibrary(gles_library
);
79 SetGLGetProcAddressProc(get_proc_address
);
80 AddGLNativeLibrary(egl_library
);
81 AddGLNativeLibrary(gles_library
);
82 SetGLImplementation(kGLImplementationEGLGLES2
);
84 InitializeGLBindingsGL();
85 InitializeGLBindingsEGL();
87 // These two functions take single precision float rather than double
88 // precision float parameters in GLES.
89 ::gfx::g_driver_gl
.fn
.glClearDepthFn
= MarshalClearDepthToClearDepthf
;
90 ::gfx::g_driver_gl
.fn
.glDepthRangeFn
= MarshalDepthRangeToDepthRangef
;
93 case kGLImplementationMockGL
: {
94 SetGLGetProcAddressProc(GetMockGLProcAddress
);
95 SetGLImplementation(kGLImplementationMockGL
);
96 InitializeGLBindingsGL();
100 NOTIMPLEMENTED() << "InitializeGLBindings on Android";
107 bool InitializeGLExtensionBindings(GLImplementation implementation
,
108 GLContext
* context
) {
109 switch (implementation
) {
110 case kGLImplementationEGLGLES2
:
111 InitializeGLExtensionBindingsGL(context
);
112 InitializeGLExtensionBindingsEGL(context
);
114 case kGLImplementationMockGL
:
115 InitializeGLExtensionBindingsGL(context
);
124 void InitializeDebugGLBindings() {
127 void ClearGLBindings() {
128 ClearGLBindingsEGL();
130 SetGLImplementation(kGLImplementationNone
);
132 UnloadGLNativeLibraries();
135 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo
* info
) {
136 switch (GetGLImplementation()) {
137 case kGLImplementationEGLGLES2
:
138 return GetGLWindowSystemBindingInfoEGL(info
);