gl_version_info.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2014 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_VERSION_INFO_H_
  5. #define UI_GL_GL_VERSION_INFO_H_
  6. #include <set>
  7. #include <string>
  8. #include "build/build_config.h"
  9. #include "ui/gfx/extension_set.h"
  10. #include "ui/gl/gl_export.h"
  11. namespace gl {
  12. struct GL_EXPORT GLVersionInfo {
  13. GLVersionInfo(const char* version_str,
  14. const char* renderer_str,
  15. const gfx::ExtensionSet& exts);
  16. GLVersionInfo(const GLVersionInfo&) = delete;
  17. GLVersionInfo& operator=(const GLVersionInfo&) = delete;
  18. bool IsAtLeastGL(unsigned major, unsigned minor) const {
  19. return !is_es && (major_version > major ||
  20. (major_version == major && minor_version >= minor));
  21. }
  22. bool IsLowerThanGL(unsigned major, unsigned minor) const {
  23. return !is_es && (major_version < major ||
  24. (major_version == major && minor_version < minor));
  25. }
  26. bool IsAtLeastGLES(unsigned major, unsigned minor) const {
  27. return is_es && (major_version > major ||
  28. (major_version == major && minor_version >= minor));
  29. }
  30. bool BehavesLikeGLES() const {
  31. return is_es || is_desktop_core_profile;
  32. }
  33. bool SupportsFixedType() const {
  34. return is_es || IsAtLeastGL(4, 1);
  35. }
  36. struct VersionStrings {
  37. const char* gl_version;
  38. const char* glsl_version;
  39. };
  40. // Returns version strings for GL and GLSL (similar to glGetString(GL_VERSION)
  41. // and glGetString(GL_SHADING_LANGUAGE_VERSION) matching major/minor versions
  42. VersionStrings GetFakeVersionStrings(unsigned major, unsigned minor) const;
  43. // Returns true if the major/minor version was changed for any reasons and we
  44. // might need to propagate changes further, e.g. to Skia
  45. bool IsVersionSubstituted() const;
  46. // We need to emulate GL_ALPHA and GL_LUMINANCE and GL_LUMINANCE_ALPHA
  47. // texture formats on core profile and ES3, except for ANGLE and Swiftshader.
  48. bool NeedsLuminanceAlphaEmulation() const {
  49. return !is_angle && !is_swiftshader && (is_es3 || is_desktop_core_profile);
  50. }
  51. bool is_es = false;
  52. bool is_angle = false;
  53. bool is_d3d = false;
  54. bool is_mesa = false;
  55. bool is_swiftshader = false;
  56. bool is_angle_metal = false;
  57. bool is_angle_swiftshader = false;
  58. bool is_angle_vulkan = false;
  59. unsigned major_version = 0;
  60. unsigned minor_version = 0;
  61. bool is_es2 = false;
  62. bool is_es3 = false;
  63. bool is_desktop_core_profile = false;
  64. bool is_es3_capable = false;
  65. std::string driver_vendor;
  66. std::string driver_version;
  67. static void DisableES3ForTesting();
  68. private:
  69. void Initialize(const char* version_str,
  70. const char* renderer_str,
  71. const gfx::ExtensionSet& extensions);
  72. void ParseVersionString(const char* version_str);
  73. void ParseDriverInfo(const char* version_str);
  74. void ExtractDriverVendorANGLE(const char* renderer_str);
  75. bool IsES3Capable(const gfx::ExtensionSet& extensions) const;
  76. };
  77. } // namespace gl
  78. #endif // UI_GL_GL_VERSION_INFO_H_