Skip to content
Permalink
Browse files

8243508: Update alpha blending and compositing functions

  • Loading branch information
Alexey Ushakov committed Apr 27, 2020
1 parent 923bd0b commit 7c59839250f8059ee083bcef2129d10ff4f5cd32
@@ -5,23 +5,11 @@

#include <jni.h>

/* FIXME: the FLT_LT and FLT_GE macros don't do what the names imply.
* Correct macros would be more like this:
*
* #define FLT_EPSILON (0.001f)
* #define FLT_LT(x,y) ((x) < (y) - FLT_EPSILON)
* #define FLT_GE(x,y) ((x) >= (y) - FLT_EPSILON)
*
* and maybe for completeness, if needed:
*
* #define FLT_LE(x,y) ((x) <= (y) + FLT_EPSILON)
* #define FLT_GT(x,y) ((x) > (y) + FLT_EPSILON)
*
* When these macros are fixed all usages should be double-checked.
*/
#define FLT_ACCURACY (0.99f)
#define FLT_LT(x,y) ((x) < (y) - FLT_ACCURACY)
#define FLT_GE(x,y) ((x) >= (y) - FLT_ACCURACY)
#define FLT_EPS (0.001f)
#define FLT_LT(x,y) ((x) < (y) - FLT_EPS)
#define FLT_GE(x,y) ((x) >= (y) - FLT_EPS)
#define FLT_LE(x,y) ((x) <= (y) + FLT_EPS)
#define FLT_GT(x,y) ((x) > (y) + FLT_EPS)

/**
* The MTLComposite class represents composite mode
@@ -142,20 +142,14 @@ - (NSString *)getDescription {

- (jboolean)isBlendingDisabled:(jboolean)isSrcOpaque {

// FIXME: This function needs to be re-examined.
// Depending on the composite mode, I think it needs to either look
// at both or neither of the extra alpha value and isSrcOpaque.
// For example, I don't think SRC or CLEAR mode needs blending at all
// (but maybe that is handled elsewhere).

// FIXME: Use FLT_GE macro or similar once fixed
const jfloat epsilon = 0.001f;
BOOL extraAlphaIsOne = fabs(_extraAlpha - 1.0f) < epsilon;
if (_compositeRule == java_awt_AlphaComposite_SRC) {
return extraAlphaIsOne;
}
else if (_compositeRule == java_awt_AlphaComposite_SRC_OVER) {
return extraAlphaIsOne && isSrcOpaque;
// We need to check both extra alpha and isSrcOpaque for
// SRC mode for correct handling TRANSLUCENT images.
// See test/jdk/java/awt/image/DrawImage/IncorrectUnmanagedImageRotatedClip.java
// for example
if (_compositeRule == java_awt_AlphaComposite_SRC ||
_compositeRule == java_awt_AlphaComposite_SRC_OVER)
{
return FLT_GE(_extraAlpha, 1.0f) && isSrcOpaque;
}
return isSrcOpaque;
}
@@ -167,8 +167,6 @@ - (NSPointerArray * ) getSubStates:(NSString *)vertexShaderId fragmentShader:(NS
subIndex |= 1 << 5;
}

// FIXME: the FLT_LT macro doesn't do what the name implies.
// When the macro is fixed this usage should be double-checked (although it might be OK)
if ((composite != nil && FLT_LT([composite getExtraAlpha], 1.0f))) {
subIndex |= 1 << 6;
}
@@ -197,10 +195,7 @@ - (NSPointerArray * ) getSubStates:(NSString *)vertexShaderId fragmentShader:(NS

} else if (useComposite ||
(composite != nil &&
// FIXME: the FLT_GE macro doesn't do what the name implies.
// When the macro is fixed this usage should be double-checked, since
// it looks backwards to me.
FLT_GE([composite getExtraAlpha], 1.0f)))
FLT_LT([composite getExtraAlpha], 1.0f)))
{
setBlendingFactors(
pipelineDesc.colorAttachments[0],
@@ -270,8 +265,6 @@ static void setBlendingFactors(
const SurfaceRasterFlags * srcFlags,
const SurfaceRasterFlags * dstFlags
) {
// FIXME: the FLT_GE macro doesn't do what the name implies.
// When the macro is fixed this usage should be double-checked (although it might be OK)
if (compositeRule == RULE_Src &&
(composite == nil || FLT_GE([composite getExtraAlpha], 1.0f))) {
J2dTraceLn(J2D_TRACE_VERBOSE, "set RULE_Src but blending is disabled because src is opaque");
@@ -297,8 +290,6 @@ static void setBlendingFactors(
case RULE_SrcOver: {
// Ar = As + Ad*(1-As)
// Cr = Cs + Cd*(1-As)
// FIXME: the FLT_GE macro doesn't do what the name implies.
// When the macro is fixed this usage should be double-checked (although it might be OK)
if (srcFlags->isOpaque &&
(composite == nil ||
FLT_GE([composite getExtraAlpha], 1.0f)))
@@ -318,8 +309,6 @@ static void setBlendingFactors(
if (!srcFlags->isPremultiplied) {
cad.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
}
// FIXME: the FLT_LT macro doesn't do what the name implies.
// When the macro is fixed this usage should be double-checked (although it might be OK)
if (composite != nil && FLT_LT([composite getExtraAlpha], 1.0f)) {
cad.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
}

0 comments on commit 7c59839

Please sign in to comment.