LayoutLib: don't render when shader's local matrix is set to 0 scale.

Change-Id: I7726d87f3dd0475ac662f535a08c6435b8b9ed1f
This commit is contained in:
Xavier Ducrohet
2011-04-06 17:03:31 -07:00
parent 8a18dba48c
commit 59aad78eae
2 changed files with 35 additions and 18 deletions

View File

@ -73,6 +73,14 @@ public abstract class Shader_Delegate {
public abstract boolean isSupported(); public abstract boolean isSupported();
public abstract String getSupportMessage(); public abstract String getSupportMessage();
public boolean isValid() {
if (mLocalMatrix != null && mLocalMatrix.getAffineTransform().getDeterminant() == 0) {
return false;
}
return true;
}
// ---- native methods ---- // ---- native methods ----
@LayoutlibDelegate @LayoutlibDelegate
@ -126,5 +134,4 @@ public abstract class Shader_Delegate {
return new java.awt.geom.AffineTransform(); return new java.awt.geom.AffineTransform();
} }
} }

View File

@ -603,11 +603,13 @@ public class GcSnapshot {
createCustomGraphics(originalGraphics, paint, compositeOnly, forceSrcMode) : createCustomGraphics(originalGraphics, paint, compositeOnly, forceSrcMode) :
(Graphics2D) originalGraphics.create(); (Graphics2D) originalGraphics.create();
try { if (configuredGraphics2D != null) {
drawable.draw(configuredGraphics2D, paint); try {
} finally { drawable.draw(configuredGraphics2D, paint);
// dispose Graphics2D object } finally {
configuredGraphics2D.dispose(); // dispose Graphics2D object
configuredGraphics2D.dispose();
}
} }
} }
@ -680,11 +682,13 @@ public class GcSnapshot {
Graphics2D g = createCustomGraphics(baseGfx, mLocalLayerPaint, Graphics2D g = createCustomGraphics(baseGfx, mLocalLayerPaint,
true /*alphaOnly*/, false /*forceSrcMode*/); true /*alphaOnly*/, false /*forceSrcMode*/);
g.drawImage(mLocalLayer.getImage(), if (g != null) {
mLayerBounds.left, mLayerBounds.top, mLayerBounds.right, mLayerBounds.bottom, g.drawImage(mLocalLayer.getImage(),
mLayerBounds.left, mLayerBounds.top, mLayerBounds.right, mLayerBounds.bottom, mLayerBounds.left, mLayerBounds.top, mLayerBounds.right, mLayerBounds.bottom,
null); mLayerBounds.left, mLayerBounds.top, mLayerBounds.right, mLayerBounds.bottom,
g.dispose(); null);
g.dispose();
}
baseGfx.dispose(); baseGfx.dispose();
} }
@ -714,11 +718,17 @@ public class GcSnapshot {
Shader_Delegate shaderDelegate = paint.getShader(); Shader_Delegate shaderDelegate = paint.getShader();
if (shaderDelegate != null) { if (shaderDelegate != null) {
if (shaderDelegate.isSupported()) { if (shaderDelegate.isSupported()) {
java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint(); // shader could have a local matrix that's not valid (for instance 0 scaling).
assert shaderPaint != null; if (shaderDelegate.isValid()) {
if (shaderPaint != null) { java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint();
g.setPaint(shaderPaint); assert shaderPaint != null;
customShader = true; if (shaderPaint != null) {
g.setPaint(shaderPaint);
customShader = true;
}
} else {
g.dispose();
return null;
} }
} else { } else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_SHADER, Bridge.getLog().fidelityWarning(LayoutLog.TAG_SHADER,
@ -742,7 +752,7 @@ public class GcSnapshot {
if (forceSrcMode) { if (forceSrcMode) {
g.setComposite(AlphaComposite.getInstance( g.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC, (float) alpha / 255.f)); AlphaComposite.SRC, alpha / 255.f));
} else { } else {
boolean customXfermode = false; boolean customXfermode = false;
Xfermode_Delegate xfermodeDelegate = paint.getXfermode(); Xfermode_Delegate xfermodeDelegate = paint.getXfermode();
@ -766,7 +776,7 @@ public class GcSnapshot {
// that will handle the alpha. // that will handle the alpha.
if (customXfermode == false && alpha != 0xFF) { if (customXfermode == false && alpha != 0xFF) {
g.setComposite(AlphaComposite.getInstance( g.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, (float) alpha / 255.f)); AlphaComposite.SRC_OVER, alpha / 255.f));
} }
} }