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