gl_gl_api_implementation.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. #ifndef UI_GL_GL_GL_API_IMPLEMENTATION_H_
  5. #define UI_GL_GL_GL_API_IMPLEMENTATION_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/memory/raw_ptr.h"
  9. #include "ui/gl/gl_bindings.h"
  10. #include "ui/gl/gl_export.h"
  11. #include "ui/gl/gl_workarounds.h"
  12. namespace gl {
  13. struct GLVersionInfo;
  14. GL_EXPORT GLenum GetInternalFormat(const GLVersionInfo* version,
  15. GLenum internal_format);
  16. GL_EXPORT void InitializeStaticGLBindingsGL();
  17. GL_EXPORT void ClearBindingsGL();
  18. bool SetNullDrawGLBindingsEnabled(bool enabled);
  19. bool GetNullDrawBindingsEnabled();
  20. void SetCurrentGL(CurrentGL* current);
  21. class GL_EXPORT GLApiBase : public GLApi {
  22. public:
  23. // Include the auto-generated part of this class. We split this because
  24. // it means we can easily edit the non-auto generated parts right here in
  25. // this file instead of having to edit some template or the code generator.
  26. #include "gl_bindings_api_autogen_gl.h"
  27. protected:
  28. GLApiBase();
  29. ~GLApiBase() override;
  30. void InitializeBase(DriverGL* driver);
  31. raw_ptr<DriverGL> driver_;
  32. };
  33. // Implemenents the GL API by calling directly into the driver.
  34. class GL_EXPORT RealGLApi : public GLApiBase {
  35. public:
  36. RealGLApi();
  37. ~RealGLApi() override;
  38. void Initialize(DriverGL* driver);
  39. void SetDisabledExtensions(const std::string& disabled_extensions) override;
  40. void glGetIntegervFn(GLenum pname, GLint* params) override;
  41. const GLubyte* glGetStringFn(GLenum name) override;
  42. const GLubyte* glGetStringiFn(GLenum name, GLuint index) override;
  43. void glTexImage2DFn(GLenum target,
  44. GLint level,
  45. GLint internalformat,
  46. GLsizei width,
  47. GLsizei height,
  48. GLint border,
  49. GLenum format,
  50. GLenum type,
  51. const void* pixels) override;
  52. void glTexSubImage2DFn(GLenum target,
  53. GLint level,
  54. GLint xoffset,
  55. GLint yoffset,
  56. GLsizei width,
  57. GLsizei height,
  58. GLenum format,
  59. GLenum type,
  60. const void* pixels) override;
  61. void glTexStorage2DEXTFn(GLenum target,
  62. GLsizei levels,
  63. GLenum internalformat,
  64. GLsizei width,
  65. GLsizei height) override;
  66. void glTexStorageMem2DEXTFn(GLenum target,
  67. GLsizei levels,
  68. GLenum internalformat,
  69. GLsizei width,
  70. GLsizei height,
  71. GLuint memory,
  72. GLuint64 offset) override;
  73. void glTexStorageMemFlags2DANGLEFn(GLenum target,
  74. GLsizei levels,
  75. GLenum internalformat,
  76. GLsizei width,
  77. GLsizei height,
  78. GLuint memory,
  79. GLuint64 offset,
  80. GLbitfield createFlags,
  81. GLbitfield usageFlags,
  82. const void* imageCreateInfoPNext) override;
  83. void glRenderbufferStorageEXTFn(GLenum target,
  84. GLenum internalformat,
  85. GLsizei width,
  86. GLsizei height) override;
  87. void glRenderbufferStorageMultisampleEXTFn(GLenum target,
  88. GLsizei samples,
  89. GLenum internalformat,
  90. GLsizei width,
  91. GLsizei height) override;
  92. void glRenderbufferStorageMultisampleFn(GLenum target,
  93. GLsizei samples,
  94. GLenum internalformat,
  95. GLsizei width,
  96. GLsizei height) override;
  97. void glReadPixelsFn(GLint x,
  98. GLint y,
  99. GLsizei width,
  100. GLsizei height,
  101. GLenum format,
  102. GLenum type,
  103. void* pixels) override;
  104. void glClearFn(GLbitfield mask) override;
  105. void glClearColorFn(GLclampf red,
  106. GLclampf green,
  107. GLclampf blue,
  108. GLclampf alpha) override;
  109. void glDrawArraysFn(GLenum mode, GLint first, GLsizei count) override;
  110. void glDrawElementsFn(GLenum mode,
  111. GLsizei count,
  112. GLenum type,
  113. const void* indices) override;
  114. void glClearDepthFn(GLclampd depth) override;
  115. void glDepthRangeFn(GLclampd z_near, GLclampd z_far) override;
  116. void glUseProgramFn(GLuint program) override;
  117. void set_gl_workarounds(const GLWorkarounds& workarounds);
  118. void set_version(std::unique_ptr<GLVersionInfo> version);
  119. void ClearCachedGLExtensions();
  120. private:
  121. // Compute |filtered_exts_| & |filtered_exts_str_| from |disabled_ext_|.
  122. void InitializeFilteredExtensionsIfNeeded();
  123. const bool logging_enabled_;
  124. std::vector<std::string> disabled_exts_;
  125. // Filtered GL_EXTENSIONS we return to glGetString(i) calls.
  126. std::vector<std::string> filtered_exts_;
  127. std::string filtered_exts_str_;
  128. GLWorkarounds gl_workarounds_;
  129. std::unique_ptr<GLVersionInfo> version_;
  130. };
  131. // Inserts a TRACE for every GL call.
  132. class TraceGLApi : public GLApi {
  133. public:
  134. TraceGLApi(GLApi* gl_api) : gl_api_(gl_api) { }
  135. ~TraceGLApi() override;
  136. // Include the auto-generated part of this class. We split this because
  137. // it means we can easily edit the non-auto generated parts right here in
  138. // this file instead of having to edit some template or the code generator.
  139. #include "gl_bindings_api_autogen_gl.h"
  140. private:
  141. raw_ptr<GLApi> gl_api_;
  142. };
  143. // Logs debug information for every GL call.
  144. class LogGLApi : public GLApi {
  145. public:
  146. LogGLApi(GLApi* gl_api);
  147. ~LogGLApi() override;
  148. // Include the auto-generated part of this class. We split this because
  149. // it means we can easily edit the non-auto generated parts right here in
  150. // this file instead of having to edit some template or the code generator.
  151. #include "gl_bindings_api_autogen_gl.h"
  152. private:
  153. raw_ptr<GLApi> gl_api_;
  154. };
  155. // Catches incorrect usage when GL calls are made without a current context.
  156. class NoContextGLApi : public GLApi {
  157. public:
  158. NoContextGLApi();
  159. ~NoContextGLApi() override;
  160. // Include the auto-generated part of this class. We split this because
  161. // it means we can easily edit the non-auto generated parts right here in
  162. // this file instead of having to edit some template or the code generator.
  163. #include "gl_bindings_api_autogen_gl.h"
  164. };
  165. } // namespace gl
  166. #endif // UI_GL_GL_GL_API_IMPLEMENTATION_H_