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