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 #ifndef UI_GL_GL_IMPLEMENTATION_H_
      6 #define UI_GL_GL_IMPLEMENTATION_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/native_library.h"
     12 #include "build/build_config.h"
     13 #include "ui/gl/gl_export.h"
     14 #include "ui/gl/gl_switches.h"
     15 
     16 namespace gfx {
     17 
     18 class GLContext;
     19 
     20 // The GL implementation currently in use.
     21 enum GLImplementation {
     22   kGLImplementationNone,
     23   kGLImplementationDesktopGL,
     24   kGLImplementationOSMesaGL,
     25   kGLImplementationAppleGL,
     26   kGLImplementationEGLGLES2,
     27   kGLImplementationMockGL
     28 };
     29 
     30 struct GL_EXPORT GLWindowSystemBindingInfo {
     31   GLWindowSystemBindingInfo();
     32   std::string vendor;
     33   std::string version;
     34   std::string extensions;
     35   bool direct_rendering;
     36 };
     37 
     38 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls);
     39 
     40 #if defined(OS_WIN)
     41 typedef void* (WINAPI *GLGetProcAddressProc)(const char* name);
     42 #else
     43 typedef void* (*GLGetProcAddressProc)(const char* name);
     44 #endif
     45 
     46 // Initialize a particular GL implementation.
     47 GL_EXPORT bool InitializeStaticGLBindings(GLImplementation implementation);
     48 
     49 // Initialize function bindings that depend on the context for a GL
     50 // implementation.
     51 GL_EXPORT bool InitializeDynamicGLBindings(GLImplementation implementation,
     52                                            GLContext* context);
     53 
     54 // Initialize Debug logging wrappers for GL bindings.
     55 void InitializeDebugGLBindings();
     56 
     57 // Initialize stub methods for drawing operations in the GL bindings. The
     58 // null draw bindings default to enabled, so that draw operations do nothing.
     59 void InitializeNullDrawGLBindings();
     60 
     61 // TODO(danakj): Remove this when all test suites are using null-draw.
     62 GL_EXPORT bool HasInitializedNullDrawGLBindings();
     63 
     64 // Once initialized, instantiating this turns the stub methods for drawing
     65 // operations off allowing drawing will occur while the object is alive.
     66 class GL_EXPORT DisableNullDrawGLBindings {
     67  public:
     68   DisableNullDrawGLBindings();
     69   ~DisableNullDrawGLBindings();
     70 
     71  private:
     72   bool initial_enabled_;
     73 };
     74 
     75 GL_EXPORT void ClearGLBindings();
     76 
     77 // Set the current GL implementation.
     78 GL_EXPORT void SetGLImplementation(GLImplementation implementation);
     79 
     80 // Get the current GL implementation.
     81 GL_EXPORT GLImplementation GetGLImplementation();
     82 
     83 // Does the underlying GL support all features from Desktop GL 2.0 that were
     84 // removed from the ES 2.0 spec without requiring specific extension strings.
     85 GL_EXPORT bool HasDesktopGLFeatures();
     86 
     87 // Get the GL implementation with a given name.
     88 GLImplementation GetNamedGLImplementation(const std::string& name);
     89 
     90 // Get the name of a GL implementation.
     91 const char* GetGLImplementationName(GLImplementation implementation);
     92 
     93 // Add a native library to those searched for GL entry points.
     94 void AddGLNativeLibrary(base::NativeLibrary library);
     95 
     96 // Unloads all native libraries.
     97 void UnloadGLNativeLibraries();
     98 
     99 // Set an additional function that will be called to find GL entry points.
    100 // Exported so that tests may set the function used in the mock implementation.
    101 GL_EXPORT void SetGLGetProcAddressProc(GLGetProcAddressProc proc);
    102 
    103 // Find an entry point in the current GL implementation. Note that the function
    104 // may return a non-null pointer to something else than the GL function if an
    105 // unsupported function is queried. Spec-compliant eglGetProcAddress and
    106 // glxGetProcAddress are allowed to return garbage for unsupported functions,
    107 // and when querying functions from the EGL library supplied by Android, it may
    108 // return a function that prints a log message about the function being
    109 // unsupported.
    110 void* GetGLProcAddress(const char* name);
    111 
    112 // Return information about the GL window system binding implementation (e.g.,
    113 // EGL, GLX, WGL). Returns true if the information was retrieved successfully.
    114 GL_EXPORT bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info);
    115 
    116 }  // namespace gfx
    117 
    118 #endif  // UI_GL_GL_IMPLEMENTATION_H_
    119