Refactor: Move app/gfx/gl ==> ui/gfx/gl
This is the final patch in the sequence. Note that gl.gyp is introduced because dependency checking on the Mac is done on a per file (rather than per target) basis.
BUG=none
TEST=trybots
Review URL: http://codereview.chromium.org/6722026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79599 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ui/gfx/gl/gl_implementation_linux.cc b/ui/gfx/gl/gl_implementation_linux.cc
new file mode 100644
index 0000000..34069cf
--- /dev/null
+++ b/ui/gfx/gl/gl_implementation_linux.cc
@@ -0,0 +1,160 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "base/base_paths.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/logging.h"
+#include "base/native_library.h"
+#include "base/path_service.h"
+#include "ui/gfx/gl/gl_bindings.h"
+#include "ui/gfx/gl/gl_implementation.h"
+
+namespace gfx {
+namespace {
+
+// TODO(piman): it should be Desktop GL marshalling from double to float. Today
+// on native GLES, we do float->double->float.
+void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) {
+ glClearDepthf(static_cast<GLclampf>(depth));
+}
+
+void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near,
+ GLclampd z_far) {
+ glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far));
+}
+
+} // namespace anonymous
+
+bool InitializeGLBindings(GLImplementation implementation) {
+ // Prevent reinitialization with a different implementation. Once the gpu
+ // unit tests have initialized with kGLImplementationMock, we don't want to
+ // later switch to another GL implementation.
+ if (GetGLImplementation() != kGLImplementationNone)
+ return true;
+
+ switch (implementation) {
+ case kGLImplementationOSMesaGL: {
+ FilePath module_path;
+ if (!PathService::Get(base::DIR_MODULE, &module_path)) {
+ LOG(ERROR) << "PathService::Get failed.";
+ return false;
+ }
+
+ base::NativeLibrary library = base::LoadNativeLibrary(
+ module_path.Append("libosmesa.so"));
+ if (!library) {
+ VLOG(1) << "libosmesa.so not found";
+ return false;
+ }
+
+ GLGetProcAddressProc get_proc_address =
+ reinterpret_cast<GLGetProcAddressProc>(
+ base::GetFunctionPointerFromNativeLibrary(
+ library, "OSMesaGetProcAddress"));
+ if (!get_proc_address) {
+ LOG(ERROR) << "OSMesaGetProcAddress not found.";
+ base::UnloadNativeLibrary(library);
+ return false;
+ }
+
+ SetGLGetProcAddressProc(get_proc_address);
+ AddGLNativeLibrary(library);
+ SetGLImplementation(kGLImplementationOSMesaGL);
+
+ InitializeGLBindingsGL();
+ InitializeGLBindingsOSMESA();
+ break;
+ }
+ case kGLImplementationDesktopGL: {
+ base::NativeLibrary library = base::LoadNativeLibrary(
+ FilePath("libGL.so.1"));
+ if (!library) {
+ VLOG(1) << "libGL.so.1 not found.";
+ return false;
+ }
+
+ GLGetProcAddressProc get_proc_address =
+ reinterpret_cast<GLGetProcAddressProc>(
+ base::GetFunctionPointerFromNativeLibrary(
+ library, "glXGetProcAddress"));
+ if (!get_proc_address) {
+ LOG(ERROR) << "glxGetProcAddress not found.";
+ base::UnloadNativeLibrary(library);
+ return false;
+ }
+
+ SetGLGetProcAddressProc(get_proc_address);
+ AddGLNativeLibrary(library);
+ SetGLImplementation(kGLImplementationDesktopGL);
+
+ InitializeGLBindingsGL();
+ InitializeGLBindingsGLX();
+ break;
+ }
+ case kGLImplementationEGLGLES2: {
+ base::NativeLibrary gles_library = base::LoadNativeLibrary(
+ FilePath("libGLESv2.so"));
+ if (!gles_library) {
+ VLOG(1) << "libGLESv2.so not found";
+ return false;
+ }
+
+ base::NativeLibrary egl_library = base::LoadNativeLibrary(
+ FilePath("libEGL.so"));
+ if (!egl_library) {
+ VLOG(1) << "libEGL.so not found";
+ base::UnloadNativeLibrary(gles_library);
+ return false;
+ }
+
+ GLGetProcAddressProc get_proc_address =
+ reinterpret_cast<GLGetProcAddressProc>(
+ base::GetFunctionPointerFromNativeLibrary(
+ egl_library, "eglGetProcAddress"));
+ if (!get_proc_address) {
+ LOG(ERROR) << "eglGetProcAddress not found.";
+ base::UnloadNativeLibrary(egl_library);
+ base::UnloadNativeLibrary(gles_library);
+ return false;
+ }
+
+ SetGLGetProcAddressProc(get_proc_address);
+ AddGLNativeLibrary(egl_library);
+ AddGLNativeLibrary(gles_library);
+ SetGLImplementation(kGLImplementationEGLGLES2);
+
+ InitializeGLBindingsGL();
+ InitializeGLBindingsEGL();
+
+ // These two functions take single precision float rather than double
+ // precision float parameters in GLES.
+ ::gfx::g_glClearDepth = MarshalClearDepthToClearDepthf;
+ ::gfx::g_glDepthRange = MarshalDepthRangeToDepthRangef;
+ break;
+ }
+ case kGLImplementationMockGL: {
+ SetGLGetProcAddressProc(GetMockGLProcAddress);
+ SetGLImplementation(kGLImplementationMockGL);
+ InitializeGLBindingsGL();
+ break;
+ }
+ default:
+ return false;
+ }
+
+
+ return true;
+}
+
+void InitializeDebugGLBindings() {
+ InitializeDebugGLBindingsEGL();
+ InitializeDebugGLBindingsGL();
+ InitializeDebugGLBindingsGLX();
+ InitializeDebugGLBindingsOSMESA();
+}
+
+} // namespace gfx