Roll src/third_party/WebKit 37b70da:e3be828 (svn 200645:200646)
[chromium-blink-merge.git] / ui / gl / gl_implementation.h
blobeab70dc35989579cc2d56998024fc568c0d222ab
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_
8 #include <string>
9 #include <vector>
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"
16 namespace gfx {
18 class GLContext;
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();
33 std::string vendor;
34 std::string version;
35 std::string extensions;
36 bool direct_rendering;
39 void GL_EXPORT
40 GetAllowedGLImplementations(std::vector<GLImplementation>* impls);
42 #if defined(OS_WIN)
43 typedef void* (WINAPI *GLGetProcAddressProc)(const char* name);
44 #else
45 typedef void* (*GLGetProcAddressProc)(const char* name);
46 #endif
48 // Initialize a particular GL implementation.
49 GL_EXPORT bool InitializeStaticGLBindings(GLImplementation implementation);
51 // Initialize function bindings that depend on the context for a GL
52 // implementation.
53 GL_EXPORT bool InitializeDynamicGLBindings(GLImplementation implementation,
54 GLContext* context);
56 // Initialize Debug logging wrappers for GL bindings.
57 void InitializeDebugGLBindings();
59 // Initialize stub methods for drawing operations in the GL bindings. The
60 // null draw bindings default to enabled, so that draw operations do nothing.
61 void InitializeNullDrawGLBindings();
63 // TODO(danakj): Remove this when all test suites are using null-draw.
64 GL_EXPORT bool HasInitializedNullDrawGLBindings();
66 // Filter a list of disabled_extensions from GL style space-separated
67 // extension_list, returning a space separated list of filtered extensions, in
68 // the same order as the input.
69 GL_EXPORT std::string FilterGLExtensionList(
70 const char* extension_list,
71 const std::vector<std::string>& disabled_extensions);
73 // Once initialized, instantiating this turns the stub methods for drawing
74 // operations off allowing drawing will occur while the object is alive.
75 class GL_EXPORT DisableNullDrawGLBindings {
76 public:
77 DisableNullDrawGLBindings();
78 ~DisableNullDrawGLBindings();
80 private:
81 bool initial_enabled_;
84 GL_EXPORT void ClearGLBindings();
86 // Set the current GL implementation.
87 GL_EXPORT void SetGLImplementation(GLImplementation implementation);
89 // Get the current GL implementation.
90 GL_EXPORT GLImplementation GetGLImplementation();
92 // Does the underlying GL support all features from Desktop GL 2.0 that were
93 // removed from the ES 2.0 spec without requiring specific extension strings.
94 GL_EXPORT bool HasDesktopGLFeatures();
96 // Get the GL implementation with a given name.
97 GLImplementation GetNamedGLImplementation(const std::string& name);
99 // Get the name of a GL implementation.
100 const char* GetGLImplementationName(GLImplementation implementation);
102 // Add a native library to those searched for GL entry points.
103 void AddGLNativeLibrary(base::NativeLibrary library);
105 // Unloads all native libraries.
106 void UnloadGLNativeLibraries();
108 // Set an additional function that will be called to find GL entry points.
109 // Exported so that tests may set the function used in the mock implementation.
110 GL_EXPORT void SetGLGetProcAddressProc(GLGetProcAddressProc proc);
112 // Find an entry point in the current GL implementation. Note that the function
113 // may return a non-null pointer to something else than the GL function if an
114 // unsupported function is queried. Spec-compliant eglGetProcAddress and
115 // glxGetProcAddress are allowed to return garbage for unsupported functions,
116 // and when querying functions from the EGL library supplied by Android, it may
117 // return a function that prints a log message about the function being
118 // unsupported.
119 void* GetGLProcAddress(const char* name);
121 // Return information about the GL window system binding implementation (e.g.,
122 // EGL, GLX, WGL). Returns true if the information was retrieved successfully.
123 GL_EXPORT bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info);
125 // Helper for fetching the OpenGL extensions from the current context.
126 // This helper abstracts over differences between the desktop OpenGL
127 // core profile, and OpenGL ES and the compatibility profile. It's
128 // intended for users of the bindings, not the implementation of the
129 // bindings themselves. This is a relatively expensive call, so
130 // callers should cache the result.
131 GL_EXPORT std::string GetGLExtensionsFromCurrentContext();
133 // Helper for the GL bindings implementation to understand whether
134 // glGetString(GL_EXTENSIONS) or glGetStringi(GL_EXTENSIONS, i) will
135 // be used in the function above.
136 GL_EXPORT bool WillUseGLGetStringForExtensions();
138 } // namespace gfx
140 #endif // UI_GL_GL_IMPLEMENTATION_H_