GrGLContext.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/gl/GrGLContext.h"
  8. #include "src/gpu/gl/GrGLGLSL.h"
  9. #include "src/sksl/SkSLCompiler.h"
  10. #ifdef SK_BUILD_FOR_ANDROID
  11. #include <sys/system_properties.h>
  12. #endif
  13. ////////////////////////////////////////////////////////////////////////////////
  14. std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface,
  15. const GrContextOptions& options) {
  16. if (!interface->validate()) {
  17. return nullptr;
  18. }
  19. const GrGLubyte* verUByte;
  20. GR_GL_CALL_RET(interface.get(), verUByte, GetString(GR_GL_VERSION));
  21. const char* ver = reinterpret_cast<const char*>(verUByte);
  22. const GrGLubyte* rendererUByte;
  23. GR_GL_CALL_RET(interface.get(), rendererUByte, GetString(GR_GL_RENDERER));
  24. const char* renderer = reinterpret_cast<const char*>(rendererUByte);
  25. ConstructorArgs args;
  26. args.fGLVersion = GrGLGetVersionFromString(ver);
  27. if (GR_GL_INVALID_VER == args.fGLVersion) {
  28. return nullptr;
  29. }
  30. if (!GrGLGetGLSLGeneration(interface.get(), &args.fGLSLGeneration)) {
  31. return nullptr;
  32. }
  33. args.fVendor = GrGLGetVendor(interface.get());
  34. args.fRenderer = GrGLGetRendererFromStrings(renderer, interface->fExtensions);
  35. GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor,
  36. &args.fANGLERenderer);
  37. /*
  38. * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they
  39. * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
  40. * #version 100, and will fail to compile with #version 300 es. In the long term, we
  41. * need to lock this down to a specific driver version.
  42. * ?????/2019 - Qualcomm has fixed this for Android O+ devices (API 26+)
  43. * ?????/2015 - This bug is still present in Lollipop pre-mr1
  44. * 06/18/2015 - This bug does not affect the nexus 6 (which has an Adreno 4xx).
  45. */
  46. #ifdef SK_BUILD_FOR_ANDROID
  47. if (!options.fDisableDriverCorrectnessWorkarounds &&
  48. kAdreno3xx_GrGLRenderer == args.fRenderer) {
  49. char androidAPIVersion[PROP_VALUE_MAX];
  50. int strLength = __system_property_get("ro.build.version.sdk", androidAPIVersion);
  51. if (strLength == 0 || atoi(androidAPIVersion) < 26) {
  52. args.fGLSLGeneration = k110_GrGLSLGeneration;
  53. }
  54. }
  55. #endif
  56. // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
  57. // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
  58. // extension to be enabled, even when using ESSL3. Some devices appear to only support the ES2
  59. // extension. As an extreme (optional) solution, we can fallback to using ES2 shading language
  60. // if we want to prioritize external texture support. skbug.com/7713
  61. if (GR_IS_GR_GL_ES(interface->fStandard) &&
  62. options.fPreferExternalImagesOverES3 &&
  63. !options.fDisableDriverCorrectnessWorkarounds &&
  64. interface->hasExtension("GL_OES_EGL_image_external") &&
  65. args.fGLSLGeneration >= k330_GrGLSLGeneration &&
  66. !interface->hasExtension("GL_OES_EGL_image_external_essl3") &&
  67. !interface->hasExtension("OES_EGL_image_external_essl3")) {
  68. args.fGLSLGeneration = k110_GrGLSLGeneration;
  69. }
  70. GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
  71. &args.fDriver, &args.fDriverVersion);
  72. args.fContextOptions = &options;
  73. args.fInterface = std::move(interface);
  74. return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
  75. }
  76. GrGLContext::~GrGLContext() {
  77. delete fCompiler;
  78. }
  79. SkSL::Compiler* GrGLContext::compiler() const {
  80. if (!fCompiler) {
  81. fCompiler = new SkSL::Compiler();
  82. }
  83. return fCompiler;
  84. }
  85. GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
  86. fInterface = std::move(args.fInterface);
  87. fGLVersion = args.fGLVersion;
  88. fGLSLGeneration = args.fGLSLGeneration;
  89. fVendor = args.fVendor;
  90. fRenderer = args.fRenderer;
  91. fDriver = args.fDriver;
  92. fDriverVersion = args.fDriverVersion;
  93. fANGLEBackend = args.fANGLEBackend;
  94. fANGLEVendor = args.fANGLEVendor;
  95. fANGLERenderer = args.fANGLERenderer;
  96. fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
  97. }