--- old/src/java.desktop/share/native/common/java2d/opengl/OGLBufImgOps.c 2017-10-16 13:03:45.981457082 -0700 +++ new/src/java.desktop/share/native/common/java2d/opengl/OGLBufImgOps.c 2017-10-16 13:03:45.829457532 -0700 @@ -60,44 +60,6 @@ * don't know of any simple way to find out, other than to compile * the shader at runtime and see if the drivers complain). */ -static const char *convolveShaderSource = - // maximum size supported by this shader - "const int MAX_KERNEL_SIZE = %s;" - // image to be convolved - "uniform sampler%s baseImage;" - // image edge limits: - // imgEdge.xy = imgMin.xy (anything < will be treated as edge case) - // imgEdge.zw = imgMax.xy (anything > will be treated as edge case) - "uniform vec4 imgEdge;" - // value for each location in the convolution kernel: - // kernelVals[i].x = offsetX[i] - // kernelVals[i].y = offsetY[i] - // kernelVals[i].z = kernel[i] - "uniform vec3 kernelVals[MAX_KERNEL_SIZE];" - "" - "void main(void)" - "{" - " int i;" - " vec4 sum;" - "" - " if (any(lessThan(gl_TexCoord[0].st, imgEdge.xy)) ||" - " any(greaterThan(gl_TexCoord[0].st, imgEdge.zw)))" - " {" - // (placeholder for edge condition code) - " %s" - " } else {" - " sum = vec4(0.0);" - " for (i = 0; i < MAX_KERNEL_SIZE; i++) {" - " sum +=" - " kernelVals[i].z *" - " texture%s(baseImage," - " gl_TexCoord[0].st + kernelVals[i].xy);" - " }" - " }" - "" - // modulate with gl_Color in order to apply extra alpha - " gl_FragColor = sum * gl_Color;" - "}"; /** * Flags that can be bitwise-or'ed together to control how the shader @@ -150,8 +112,44 @@ } // compose the final source code string from the various pieces - sprintf(finalSource, convolveShaderSource, - kernelMax, target, edge, target); + sprintf(finalSource, + // maximum size supported by this shader + "const int MAX_KERNEL_SIZE = %s;" + // image to be convolved + "uniform sampler%s baseImage;" + // image edge limits: + // imgEdge.xy = imgMin.xy (anything < will be treated as edge case) + // imgEdge.zw = imgMax.xy (anything > will be treated as edge case) + "uniform vec4 imgEdge;" + // value for each location in the convolution kernel: + // kernelVals[i].x = offsetX[i] + // kernelVals[i].y = offsetY[i] + // kernelVals[i].z = kernel[i] + "uniform vec3 kernelVals[MAX_KERNEL_SIZE];" + "" + "void main(void)" + "{" + " int i;" + " vec4 sum;" + "" + " if (any(lessThan(gl_TexCoord[0].st, imgEdge.xy)) ||" + " any(greaterThan(gl_TexCoord[0].st, imgEdge.zw)))" + " {" + // (placeholder for edge condition code) + " %s" + " } else {" + " sum = vec4(0.0);" + " for (i = 0; i < MAX_KERNEL_SIZE; i++) {" + " sum +=" + " kernelVals[i].z *" + " texture%s(baseImage," + " gl_TexCoord[0].st + kernelVals[i].xy);" + " }" + " }" + "" + // modulate with gl_Color in order to apply extra alpha + " gl_FragColor = sum * gl_Color;" + "}", kernelMax, target, edge, target); convolveProgram = OGLContext_CreateFragmentProgram(finalSource); if (convolveProgram == 0) { @@ -299,26 +297,6 @@ * simply by filling in these "holes" with a call to sprintf(). See the * OGLBufImgOps_CreateRescaleProgram() method for more details. */ -static const char *rescaleShaderSource = - // image to be rescaled - "uniform sampler%s baseImage;" - // vector containing scale factors - "uniform vec4 scaleFactors;" - // vector containing offsets - "uniform vec4 offsets;" - "" - "void main(void)" - "{" - " vec4 srcColor = texture%s(baseImage, gl_TexCoord[0].st);" - // (placeholder for un-premult code) - " %s" - // rescale source value - " vec4 result = (srcColor * scaleFactors) + offsets;" - // (placeholder for re-premult code) - " %s" - // modulate with gl_Color in order to apply extra alpha - " gl_FragColor = result * gl_Color;" - "}"; /** * Flags that can be bitwise-or'ed together to control how the shader @@ -360,8 +338,26 @@ } // compose the final source code string from the various pieces - sprintf(finalSource, rescaleShaderSource, - target, target, preRescale, postRescale); + sprintf(finalSource, + // image to be rescaled + "uniform sampler%s baseImage;" + // vector containing scale factors + "uniform vec4 scaleFactors;" + // vector containing offsets + "uniform vec4 offsets;" + "" + "void main(void)" + "{" + " vec4 srcColor = texture%s(baseImage, gl_TexCoord[0].st);" + // (placeholder for un-premult code) + " %s" + // rescale source value + " vec4 result = (srcColor * scaleFactors) + offsets;" + // (placeholder for re-premult code) + " %s" + // modulate with gl_Color in order to apply extra alpha + " gl_FragColor = result * gl_Color;" + "}", target, target, preRescale, postRescale); rescaleProgram = OGLContext_CreateFragmentProgram(finalSource); if (rescaleProgram == 0) { @@ -505,35 +501,6 @@ * simply by filling in these "holes" with a call to sprintf(). See the * OGLBufImgOps_CreateLookupProgram() method for more details. */ -static const char *lookupShaderSource = - // source image (bound to texture unit 0) - "uniform sampler%s baseImage;" - // lookup table (bound to texture unit 1) - "uniform sampler2D lookupTable;" - // offset subtracted from source index prior to lookup step - "uniform vec4 offset;" - "" - "void main(void)" - "{" - " vec4 srcColor = texture%s(baseImage, gl_TexCoord[0].st);" - // (placeholder for un-premult code) - " %s" - // subtract offset from original index - " vec4 srcIndex = srcColor - offset;" - // use source value as input to lookup table (note that - // "v" texcoords are hardcoded to hit texel centers of - // each row/band in texture) - " vec4 result;" - " result.r = texture2D(lookupTable, vec2(srcIndex.r, 0.125)).r;" - " result.g = texture2D(lookupTable, vec2(srcIndex.g, 0.375)).r;" - " result.b = texture2D(lookupTable, vec2(srcIndex.b, 0.625)).r;" - // (placeholder for alpha store code) - " %s" - // (placeholder for re-premult code) - " %s" - // modulate with gl_Color in order to apply extra alpha - " gl_FragColor = result * gl_Color;" - "}"; /** * Flags that can be bitwise-or'ed together to control how the shader @@ -592,8 +559,35 @@ } // compose the final source code string from the various pieces - sprintf(finalSource, lookupShaderSource, - target, target, preLookup, alpha, postLookup); + sprintf(finalSource, + // source image (bound to texture unit 0) + "uniform sampler%s baseImage;" + // lookup table (bound to texture unit 1) + "uniform sampler2D lookupTable;" + // offset subtracted from source index prior to lookup step + "uniform vec4 offset;" + "" + "void main(void)" + "{" + " vec4 srcColor = texture%s(baseImage, gl_TexCoord[0].st);" + // (placeholder for un-premult code) + " %s" + // subtract offset from original index + " vec4 srcIndex = srcColor - offset;" + // use source value as input to lookup table (note that + // "v" texcoords are hardcoded to hit texel centers of + // each row/band in texture) + " vec4 result;" + " result.r = texture2D(lookupTable, vec2(srcIndex.r, 0.125)).r;" + " result.g = texture2D(lookupTable, vec2(srcIndex.g, 0.375)).r;" + " result.b = texture2D(lookupTable, vec2(srcIndex.b, 0.625)).r;" + // (placeholder for alpha store code) + " %s" + // (placeholder for re-premult code) + " %s" + // modulate with gl_Color in order to apply extra alpha + " gl_FragColor = result * gl_Color;" + "}", target, target, preLookup, alpha, postLookup); lookupProgram = OGLContext_CreateFragmentProgram(finalSource); if (lookupProgram == 0) {