Move fragCoord workaround declaration

This ensures that all extension directives occur before any
non-preprocessor tokens, as required by the spec (§ 3.4).

This was found by Qualcomm, and originally submitted as
https://github.com/google/skia/pull/21

Bug: b/111525079
Change-Id: I24357e4d3654e76c2dfbc067aca3088948dfa5a8
Reviewed-on: https://skia-review.googlesource.com/142697
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2018-07-20 13:09:45 -04:00 committed by Skia Commit-Bot
parent 8e9b4c4757
commit cc10d790df

View File

@ -1264,25 +1264,6 @@ void GLSLCodeGenerator::writeHeader() {
this->writeExtension((Extension&) e);
}
}
if (!fProgram.fSettings.fCaps->canUseFragCoord()) {
Layout layout;
switch (fProgram.fKind) {
case Program::kVertex_Kind: {
Modifiers modifiers(layout, Modifiers::kOut_Flag | Modifiers::kHighp_Flag);
this->writeModifiers(modifiers, true);
this->write("vec4 sk_FragCoord_Workaround;\n");
break;
}
case Program::kFragment_Kind: {
Modifiers modifiers(layout, Modifiers::kIn_Flag | Modifiers::kHighp_Flag);
this->writeModifiers(modifiers, true);
this->write("vec4 sk_FragCoord_Workaround;\n");
break;
}
default:
break;
}
}
}
void GLSLCodeGenerator::writeProgramElement(const ProgramElement& e) {
@ -1359,6 +1340,27 @@ bool GLSLCodeGenerator::generateCode() {
fOut = rawOut;
write_stringstream(fHeader, *rawOut);
if (!fProgram.fSettings.fCaps->canUseFragCoord()) {
Layout layout;
switch (fProgram.fKind) {
case Program::kVertex_Kind: {
Modifiers modifiers(layout, Modifiers::kOut_Flag | Modifiers::kHighp_Flag);
this->writeModifiers(modifiers, true);
this->write("vec4 sk_FragCoord_Workaround;\n");
break;
}
case Program::kFragment_Kind: {
Modifiers modifiers(layout, Modifiers::kIn_Flag | Modifiers::kHighp_Flag);
this->writeModifiers(modifiers, true);
this->write("vec4 sk_FragCoord_Workaround;\n");
break;
}
default:
break;
}
}
if (this->usesPrecisionModifiers()) {
this->writeLine("precision mediump float;");
}