Expose GL built-in output variables in ShGetOutputVariables

Expose GL built-in output variables in ShGetOutputVariables.
Currently gl_FragColor, gl_FragData and gl_FragDepthEXT are exposed.

The output variable names in the returned array are the input shader names,
not the output shader names.

This is needed in future features in which the emulation layer (command
buffer/libANGLE) needs to know which output variables caller used.

Example of such a feature is EXT_blend_func_extended, where
gl_SecondaryFragColorEXT and gl_SecondaryFragDataEXT cause the need
to bind the emulated output variables to their respective color
indices.

BUG=angleproject:1085
TEST=angle_unittests

Change-Id: I7ca3e0fe6bdd3e3c66113518aa771cbb013fc014
Reviewed-on: https://chromium-review.googlesource.com/287230
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Kimmo Kinnunen <kkinnunen@nvidia.com>
diff --git a/src/compiler/translator/VariableInfo.cpp b/src/compiler/translator/VariableInfo.cpp
index 1075f36..c1c4c2d 100644
--- a/src/compiler/translator/VariableInfo.cpp
+++ b/src/compiler/translator/VariableInfo.cpp
@@ -148,6 +148,9 @@
       mPositionAdded(false),
       mPointSizeAdded(false),
       mLastFragDataAdded(false),
+      mFragColorAdded(false),
+      mFragDataAdded(false),
+      mFragDepthAdded(false),
       mHashFunction(hashFunction),
       mSymbolTable(symbolTable)
 {
@@ -366,6 +369,57 @@
                 mLastFragDataAdded = true;
             }
             return;
+          case EvqFragColor:
+              if (!mFragColorAdded)
+              {
+                  Attribute info;
+                  const char kName[] = "gl_FragColor";
+                  info.name          = kName;
+                  info.mappedName    = kName;
+                  info.type          = GL_FLOAT_VEC4;
+                  info.arraySize     = 0;
+                  info.precision     = GL_MEDIUM_FLOAT;  // Defined by spec.
+                  info.staticUse = true;
+                  mOutputVariables->push_back(info);
+                  mFragColorAdded = true;
+              }
+              return;
+          case EvqFragData:
+              if (!mFragDataAdded)
+              {
+                  Attribute info;
+                  const char kName[] = "gl_FragData";
+                  info.name          = kName;
+                  info.mappedName    = kName;
+                  info.type          = GL_FLOAT_VEC4;
+                  info.arraySize = static_cast<const TVariable *>(
+                                       mSymbolTable.findBuiltIn("gl_MaxDrawBuffers", 100))
+                                       ->getConstPointer()
+                                       ->getIConst();
+                  info.precision = GL_MEDIUM_FLOAT;  // Defined by spec.
+                  info.staticUse = true;
+                  mOutputVariables->push_back(info);
+                  mFragDataAdded = true;
+              }
+              return;
+          case EvqFragDepth:
+              if (!mFragDepthAdded)
+              {
+                  Attribute info;
+                  const char kName[] = "gl_FragDepthEXT";
+                  info.name          = kName;
+                  info.mappedName    = kName;
+                  info.type          = GL_FLOAT;
+                  info.arraySize = 0;
+                  info.precision =
+                      GLVariablePrecision(static_cast<const TVariable *>(
+                                              mSymbolTable.findBuiltIn("gl_FragDepthEXT", 100))
+                                              ->getType());
+                  info.staticUse = true;
+                  mOutputVariables->push_back(info);
+                  mFragDepthAdded = true;
+              }
+              return;
           default:
             break;
         }