1 /*
2 * Copyright 2011 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
8 #include "src/gpu/gl/GrGLGLSL.h"
9 #include "src/gpu/gl/GrGLUtil.h"
10
GrGLGetGLSLGeneration(const GrGLDriverInfo & info,GrGLSLGeneration * generation)11 bool GrGLGetGLSLGeneration(const GrGLDriverInfo& info, GrGLSLGeneration* generation) {
12 SkASSERT(generation);
13 // Workaround for a bug on some Adreno 308 devices with Android 9. The driver reports a GL
14 // version of 3.0, and a GLSL version of 3.1. If we use version 310 shaders, the driver reports
15 // that it's not supported. To keep things simple, we pin the GLSL version to the GL version.
16 // Note that GLSL versions have an extra digit on their minor level, so we have to scale up
17 // the GL version's minor revision to get a comparable GLSL version. This logic can easily
18 // create invalid GLSL versions (older GL didn't keep the versions in sync), but the checks
19 // below will further pin the GLSL generation correctly.
20 // https://github.com/flutter/flutter/issues/36130
21 uint32_t glMajor = GR_GL_MAJOR_VER(info.fVersion),
22 glMinor = GR_GL_MINOR_VER(info.fVersion);
23 GrGLSLVersion ver = std::min(info.fGLSLVersion, GR_GLSL_VER(glMajor, 10 * glMinor));
24 if (info.fGLSLVersion == GR_GLSL_INVALID_VER) {
25 return false;
26 }
27
28 if (GR_IS_GR_GL(info.fStandard)) {
29 SkASSERT(ver >= GR_GLSL_VER(1,10));
30 if (ver >= GR_GLSL_VER(4,20)) {
31 *generation = k420_GrGLSLGeneration;
32 } else if (ver >= GR_GLSL_VER(4,00)) {
33 *generation = k400_GrGLSLGeneration;
34 } else if (ver >= GR_GLSL_VER(3,30)) {
35 *generation = k330_GrGLSLGeneration;
36 } else if (ver >= GR_GLSL_VER(1,50)) {
37 *generation = k150_GrGLSLGeneration;
38 } else if (ver >= GR_GLSL_VER(1,40)) {
39 *generation = k140_GrGLSLGeneration;
40 } else if (ver >= GR_GLSL_VER(1,30)) {
41 *generation = k130_GrGLSLGeneration;
42 } else {
43 *generation = k110_GrGLSLGeneration;
44 }
45 return true;
46 } else if (GR_IS_GR_GL_ES(info.fStandard)) {
47 SkASSERT(ver >= GR_GL_VER(1,00));
48 if (ver >= GR_GLSL_VER(3,20)) {
49 *generation = k320es_GrGLSLGeneration;
50 } else if (ver >= GR_GLSL_VER(3,10)) {
51 *generation = k310es_GrGLSLGeneration;
52 } else if (ver >= GR_GLSL_VER(3,00)) {
53 *generation = k330_GrGLSLGeneration;
54 } else {
55 *generation = k110_GrGLSLGeneration;
56 }
57 return true;
58 } else if (GR_IS_GR_WEBGL(info.fStandard)) {
59 SkASSERT(ver >= GR_GL_VER(1,0));
60 if (ver >= GR_GLSL_VER(2,0)) {
61 *generation = k330_GrGLSLGeneration; // ES 3.0
62 } else {
63 *generation = k110_GrGLSLGeneration;
64 }
65 return true;
66 }
67 SK_ABORT("Unknown GL Standard");
68 }
69