gl_implementation_ozone.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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.
4
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/base/ozone/surface_factory_ozone.h"
12#include "ui/gl/gl_bindings.h"
13#include "ui/gl/gl_egl_api_implementation.h"
14#include "ui/gl/gl_gl_api_implementation.h"
15#include "ui/gl/gl_implementation.h"
16#include "ui/gl/gl_osmesa_api_implementation.h"
17
18namespace gfx {
19
20namespace {
21
22void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) {
23  glClearDepthf(static_cast<GLclampf>(depth));
24}
25
26void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near,
27                                                    GLclampd z_far) {
28  glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far));
29}
30
31}  // namespace
32
33void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
34  impls->push_back(kGLImplementationEGLGLES2);
35}
36
37bool InitializeGLBindings(GLImplementation implementation) {
38  // Prevent reinitialization with a different implementation. Once the gpu
39  // unit tests have initialized with kGLImplementationMock, we don't want to
40  // later switch to another GL implementation.
41  if (GetGLImplementation() != kGLImplementationNone)
42    return true;
43
44  switch (implementation) {
45    case kGLImplementationEGLGLES2:
46      if (!ui::SurfaceFactoryOzone::GetInstance()->LoadEGLGLES2Bindings())
47        return false;
48      SetGLImplementation(kGLImplementationEGLGLES2);
49      InitializeGLBindingsGL();
50      InitializeGLBindingsEGL();
51
52      // These two functions take single precision float rather than double
53      // precision float parameters in GLES.
54      ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf;
55      ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef;
56      break;
57    case kGLImplementationMockGL: {
58      SetGLGetProcAddressProc(GetMockGLProcAddress);
59      SetGLImplementation(kGLImplementationMockGL);
60      InitializeGLBindingsGL();
61      break;
62    }
63    default:
64      NOTIMPLEMENTED()
65          << "Unsupported GL type for NativeSurfaceLinux GL implementation";
66      return false;
67  }
68
69  return true;
70}
71
72bool InitializeGLExtensionBindings(GLImplementation implementation,
73                                   GLContext* context) {
74  switch (implementation) {
75    case kGLImplementationEGLGLES2:
76      InitializeGLExtensionBindingsGL(context);
77      InitializeGLExtensionBindingsEGL(context);
78      break;
79    case kGLImplementationMockGL:
80      InitializeGLExtensionBindingsGL(context);
81      break;
82    default:
83      return false;
84  }
85
86  return true;
87}
88
89void InitializeDebugGLBindings() {
90}
91
92void ClearGLBindings() {
93  ClearGLBindingsEGL();
94  ClearGLBindingsGL();
95  SetGLImplementation(kGLImplementationNone);
96  UnloadGLNativeLibraries();
97}
98
99bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
100  switch (GetGLImplementation()) {
101    case kGLImplementationEGLGLES2:
102      return GetGLWindowSystemBindingInfoEGL(info);
103    default:
104      return false;
105  }
106  return false;
107}
108
109}  // namespace gfx
110