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