aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-05-17 07:27:38 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-05-17 07:27:38 +0000
commit92744064860c30211426812f984ea370ddd71470 (patch)
tree209a4c5e122c836015ce3a333a8806fe6b10a5c1
parent569bdf4a3c734a1b3812b1a25008075ee2d913e9 (diff)
parentcc22a7af8b2dbeeec9db7962a2652c1331e83d18 (diff)
downloaddevice_generic_goldfish-opengl-92744064860c30211426812f984ea370ddd71470.tar.gz
device_generic_goldfish-opengl-92744064860c30211426812f984ea370ddd71470.tar.bz2
device_generic_goldfish-opengl-92744064860c30211426812f984ea370ddd71470.zip
Snap for 4787078 from cc22a7af8b2dbeeec9db7962a2652c1331e83d18 to pi-release
Change-Id: I874c084a64496a17b343015da779eab1dacc7be1
-rwxr-xr-xsystem/GLESv2_enc/GL2Encoder.cpp135
1 files changed, 104 insertions, 31 deletions
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index dd4f6580..cbc0c329 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -1331,50 +1331,73 @@ GLint * GL2Encoder::getCompressedTextureFormats()
// #define SAMPLER(TYPE, NAME) uniform sampler#TYPE NAME
// SAMPLER(ExternalOES, mySampler);
//
-static bool replaceSamplerExternalWith2D(char* const str, ShaderData* const data)
-{
- static const char STR_HASH_EXTENSION[] = "#extension";
- static const char STR_GL_OES_EGL_IMAGE_EXTERNAL[] = "GL_OES_EGL_image_external";
- static const char STR_GL_OES_EGL_IMAGE_EXTERNAL_ESSL3[] = "GL_OES_EGL_image_external_essl3";
- static const char STR_SAMPLER_EXTERNAL_OES[] = "samplerExternalOES";
- static const char STR_SAMPLER2D_SPACE[] = "sampler2D ";
- // -- overwrite all "#extension GL_OES_EGL_image_external : xxx" statements
+static const char STR_SAMPLER_EXTERNAL_OES[] = "samplerExternalOES";
+static const char STR_SAMPLER2D_SPACE[] = "sampler2D ";
+static const char STR_DEFINE[] = "#define";
+
+static std::vector<std::string> getSamplerExternalAliases(char* str) {
+ std::vector<std::string> res;
+
+ res.push_back(STR_SAMPLER_EXTERNAL_OES);
+
+ // -- capture #define x samplerExternalOES
char* c = str;
- while ((c = strstr(c, STR_HASH_EXTENSION))) {
- char* start = c;
- c += sizeof(STR_HASH_EXTENSION)-1;
- while (isspace(*c) && *c != '\0') {
- c++;
- }
+ while ((c = strstr(c, STR_DEFINE))) {
+ // Don't push it if samplerExternalOES is not even there.
+ char* samplerExternalOES_next = strstr(c, STR_SAMPLER_EXTERNAL_OES);
+ if (!samplerExternalOES_next) break;
- bool hasBaseImageExternal =
- !strncmp(c, STR_GL_OES_EGL_IMAGE_EXTERNAL,
- sizeof(STR_GL_OES_EGL_IMAGE_EXTERNAL) - 1);
- bool hasEssl3ImageExternal =
- !strncmp(c, STR_GL_OES_EGL_IMAGE_EXTERNAL_ESSL3,
- sizeof(STR_GL_OES_EGL_IMAGE_EXTERNAL_ESSL3) - 1);
+ bool prevIdent = false;
- if (hasBaseImageExternal || hasEssl3ImageExternal)
- {
- // #extension statements are terminated by end of line
- c = start;
- while (*c != '\0' && *c != '\r' && *c != '\n') {
- *c++ = ' ';
+ std::vector<std::string> idents;
+ std::string curr;
+
+ while (*c != '\0') {
+
+ if (isspace(*c)) {
+ if (prevIdent) {
+ idents.push_back(curr);
+ curr = "";
+ }
}
+
+ if (*c == '\n' || idents.size() == 3) break;
+
+ if (isalpha(*c) || *c == '_') {
+ curr.push_back(*c);
+ prevIdent = true;
+ }
+
+ ++c;
+ }
+
+ if (idents.size() != 3) continue;
+
+ const std::string& defineLhs = idents[1];
+ const std::string& defineRhs = idents[2];
+
+ if (defineRhs == STR_SAMPLER_EXTERNAL_OES) {
+ res.push_back(defineLhs);
}
+
+ if (*c == '\0') break;
}
+ return res;
+}
+
+static bool replaceExternalSamplerUniformDefinition(char* str, const std::string& samplerExternalType, ShaderData* data) {
// -- replace "samplerExternalOES" with "sampler2D" and record name
- c = str;
- while ((c = strstr(c, STR_SAMPLER_EXTERNAL_OES))) {
+ char* c = str;
+ while ((c = strstr(c, samplerExternalType.c_str()))) {
// Make sure "samplerExternalOES" isn't a substring of a larger token
if (c == str || !isspace(*(c-1))) {
c++;
continue;
}
char* sampler_start = c;
- c += sizeof(STR_SAMPLER_EXTERNAL_OES)-1;
+ c += samplerExternalType.size();
if (!isspace(*c) && *c != '\0') {
continue;
}
@@ -1394,8 +1417,58 @@ static bool replaceSamplerExternalWith2D(char* const str, ShaderData* const data
data->samplerExternalNames.push_back(
android::String8(name_start, c - name_start));
- // memcpy instead of strcpy since we don't want the NUL terminator
- memcpy(sampler_start, STR_SAMPLER2D_SPACE, sizeof(STR_SAMPLER2D_SPACE)-1);
+ // We only need to perform a string replacement for the original
+ // occurrence of samplerExternalOES if a #define was used.
+ //
+ // The important part was to record the name in
+ // |data->samplerExternalNames|.
+ if (samplerExternalType == STR_SAMPLER_EXTERNAL_OES) {
+ memcpy(sampler_start, STR_SAMPLER2D_SPACE, sizeof(STR_SAMPLER2D_SPACE)-1);
+ }
+ }
+
+ return true;
+}
+
+static bool replaceSamplerExternalWith2D(char* const str, ShaderData* const data)
+{
+ static const char STR_HASH_EXTENSION[] = "#extension";
+ static const char STR_GL_OES_EGL_IMAGE_EXTERNAL[] = "GL_OES_EGL_image_external";
+ static const char STR_GL_OES_EGL_IMAGE_EXTERNAL_ESSL3[] = "GL_OES_EGL_image_external_essl3";
+
+ // -- overwrite all "#extension GL_OES_EGL_image_external : xxx" statements
+ char* c = str;
+ while ((c = strstr(c, STR_HASH_EXTENSION))) {
+ char* start = c;
+ c += sizeof(STR_HASH_EXTENSION)-1;
+ while (isspace(*c) && *c != '\0') {
+ c++;
+ }
+
+ bool hasBaseImageExternal =
+ !strncmp(c, STR_GL_OES_EGL_IMAGE_EXTERNAL,
+ sizeof(STR_GL_OES_EGL_IMAGE_EXTERNAL) - 1);
+ bool hasEssl3ImageExternal =
+ !strncmp(c, STR_GL_OES_EGL_IMAGE_EXTERNAL_ESSL3,
+ sizeof(STR_GL_OES_EGL_IMAGE_EXTERNAL_ESSL3) - 1);
+
+ if (hasBaseImageExternal || hasEssl3ImageExternal)
+ {
+ // #extension statements are terminated by end of line
+ c = start;
+ while (*c != '\0' && *c != '\r' && *c != '\n') {
+ *c++ = ' ';
+ }
+ }
+ }
+
+ std::vector<std::string> samplerExternalAliases =
+ getSamplerExternalAliases(str);
+
+ for (size_t i = 0; i < samplerExternalAliases.size(); i++) {
+ if (!replaceExternalSamplerUniformDefinition(
+ str, samplerExternalAliases[i], data))
+ return false;
}
return true;