--- old/src/java.desktop/share/native/common/java2d/opengl/OGLPaints.c 2017-10-16 13:03:46.381455900 -0700 +++ new/src/java.desktop/share/native/common/java2d/opengl/OGLPaints.c 2017-10-16 13:03:46.221456372 -0700 @@ -382,57 +382,6 @@ static GLuint multiGradientTexID = 0; /** - * This is essentially a template of the shader source code that can be used - * for either LinearGradientPaint or RadialGradientPaint. It includes the - * structure and some variables that are common to each; the remaining - * code snippets (for CycleMethod, ColorSpaceType, and mask modulation) - * are filled in prior to compiling the shader at runtime depending on the - * paint parameters. See OGLPaints_CreateMultiGradProgram() for more details. - */ -static const char *multiGradientShaderSource = - // gradient texture size (in texels) - "const int TEXTURE_SIZE = %d;" - // maximum number of fractions/colors supported by this shader - "const int MAX_FRACTIONS = %d;" - // size of a single texel - "const float FULL_TEXEL = (1.0 / float(TEXTURE_SIZE));" - // size of half of a single texel - "const float HALF_TEXEL = (FULL_TEXEL / 2.0);" - // texture containing the gradient colors - "uniform sampler1D colors;" - // array of gradient stops/fractions - "uniform float fractions[MAX_FRACTIONS];" - // array of scale factors (one for each interval) - "uniform float scaleFactors[MAX_FRACTIONS-1];" - // (placeholder for mask variable) - "%s" - // (placeholder for Linear/RadialGP-specific variables) - "%s" - "" - "void main(void)" - "{" - " float dist;" - // (placeholder for Linear/RadialGradientPaint-specific code) - " %s" - "" - " float tc;" - // (placeholder for CycleMethod-specific code) - " %s" - "" - // calculate interpolated color - " vec4 result = texture1D(colors, tc);" - "" - // (placeholder for ColorSpace conversion code) - " %s" - "" - // (placeholder for mask modulation code) - " %s" - "" - // modulate with gl_Color in order to apply extra alpha - " gl_FragColor = result * gl_Color;" - "}"; - -/** * This code takes a "dist" value as input (as calculated earlier by the * LGP/RGP-specific code) in the range [0,1] and produces a texture * coordinate value "tc" that represents the position of the chosen color @@ -476,29 +425,6 @@ // color between the two texel centers of interest "tc = HALF_TEXEL + (FULL_TEXEL * relFraction);"; -/** Code for NO_CYCLE that gets plugged into the CycleMethod placeholder. */ -static const char *noCycleCode = - "if (dist <= 0.0) {" - " tc = 0.0;" - "} else if (dist >= 1.0) {" - " tc = 1.0;" - "} else {" - // (placeholder for texcoord calculation) - " %s" - "}"; - -/** Code for REFLECT that gets plugged into the CycleMethod placeholder. */ -static const char *reflectCode = - "dist = 1.0 - (abs(fract(dist * 0.5) - 0.5) * 2.0);" - // (placeholder for texcoord calculation) - "%s"; - -/** Code for REPEAT that gets plugged into the CycleMethod placeholder. */ -static const char *repeatCode = - "dist = fract(dist);" - // (placeholder for texcoord calculation) - "%s"; - static void OGLPaints_InitMultiGradientTexture() { @@ -578,16 +504,81 @@ } if (cycleMethod == CYCLE_NONE) { - sprintf(cycleCode, noCycleCode, texCoordCalcCode); + sprintf(cycleCode, + /** Code for NO_CYCLE that gets plugged into the CycleMethod placeholder. */ + "if (dist <= 0.0) {" + " tc = 0.0;" + "} else if (dist >= 1.0) {" + " tc = 1.0;" + "} else {" + // (placeholder for texcoord calculation) + " %s" + "}", texCoordCalcCode); } else if (cycleMethod == CYCLE_REFLECT) { - sprintf(cycleCode, reflectCode, texCoordCalcCode); + sprintf(cycleCode, + /** Code for REFLECT that gets plugged into the CycleMethod placeholder. */ + "dist = 1.0 - (abs(fract(dist * 0.5) - 0.5) * 2.0);" + // (placeholder for texcoord calculation) + "%s", texCoordCalcCode); } else { // (cycleMethod == CYCLE_REPEAT) - sprintf(cycleCode, repeatCode, texCoordCalcCode); + sprintf(cycleCode, + /** Code for REPEAT that gets plugged into the CycleMethod placeholder. */ + "dist = fract(dist);" + // (placeholder for texcoord calculation) + "%s", texCoordCalcCode); } // compose the final source code string from the various pieces - sprintf(finalSource, multiGradientShaderSource, - MAX_COLORS, maxFractions, + sprintf(finalSource, +/** + * This is essentially a template of the shader source code that can be used + * for either LinearGradientPaint or RadialGradientPaint. It includes the + * structure and some variables that are common to each; the remaining + * code snippets (for CycleMethod, ColorSpaceType, and mask modulation) + * are filled in prior to compiling the shader at runtime depending on the + * paint parameters. See OGLPaints_CreateMultiGradProgram() for more details. + */ + // gradient texture size (in texels) + "const int TEXTURE_SIZE = %d;" + // maximum number of fractions/colors supported by this shader + "const int MAX_FRACTIONS = %d;" + // size of a single texel + "const float FULL_TEXEL = (1.0 / float(TEXTURE_SIZE));" + // size of half of a single texel + "const float HALF_TEXEL = (FULL_TEXEL / 2.0);" + // texture containing the gradient colors + "uniform sampler1D colors;" + // array of gradient stops/fractions + "uniform float fractions[MAX_FRACTIONS];" + // array of scale factors (one for each interval) + "uniform float scaleFactors[MAX_FRACTIONS-1];" + // (placeholder for mask variable) + "%s" + // (placeholder for Linear/RadialGP-specific variables) + "%s" + "" + "void main(void)" + "{" + " float dist;" + // (placeholder for Linear/RadialGradientPaint-specific code) + " %s" + "" + " float tc;" + // (placeholder for CycleMethod-specific code) + " %s" + "" + // calculate interpolated color + " vec4 result = texture1D(colors, tc);" + "" + // (placeholder for ColorSpace conversion code) + " %s" + "" + // (placeholder for mask modulation code) + " %s" + "" + // modulate with gl_Color in order to apply extra alpha + " gl_FragColor = result * gl_Color;" + "}", MAX_COLORS, maxFractions, maskVars, paintVars, distCode, cycleCode, colorSpaceCode, maskCode);