diff options
author | Diego Perez <diegoperez@google.com> | 2015-03-12 13:11:07 +0000 |
---|---|---|
committer | Diego Perez <diegoperez@google.com> | 2015-04-15 14:23:09 +0000 |
commit | 2d3449f982f9f4b9f4370142bb846d2dbab5a38e (patch) | |
tree | a3f90766b91eb3facb2a50394d54f4070d8742ac | |
parent | 5b6e91a6717c4d6aa34adbbb2f2b5d6625c0802d (diff) | |
download | frameworks_base-2d3449f982f9f4b9f4370142bb846d2dbab5a38e.zip frameworks_base-2d3449f982f9f4b9f4370142bb846d2dbab5a38e.tar.gz frameworks_base-2d3449f982f9f4b9f4370142bb846d2dbab5a38e.tar.bz2 |
Make sure shaders use a color model compatible with the destination.
Change-Id: Iaf6e14bb86835c36a5b0c37519ac2ee794d10081
(cherry picked from commit 158ac454073a460375123d7d05152a7c6490efb6)
4 files changed, 19 insertions, 8 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java index 610c867..e9b5d6e 100644 --- a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java @@ -23,6 +23,8 @@ import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import android.graphics.Shader.TileMode; +import java.awt.image.ColorModel; + /** * Delegate implementing the native methods of android.graphics.BitmapShader * @@ -124,6 +126,11 @@ public class BitmapShader_Delegate extends Shader_Delegate { localMatrix = new java.awt.geom.AffineTransform(); } + if (!colorModel.isCompatibleRaster(mImage.getRaster())) { + // Fallback to the default ARGB color model + colorModel = ColorModel.getRGBdefault(); + } + return new BitmapShaderContext(canvasMatrix, localMatrix, colorModel); } @@ -153,8 +160,9 @@ public class BitmapShader_Delegate extends Shader_Delegate { @Override public java.awt.image.Raster getRaster(int x, int y, int w, int h) { - java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h, - java.awt.image.BufferedImage.TYPE_INT_ARGB); + java.awt.image.BufferedImage image = new java.awt.image.BufferedImage( + mColorModel, mColorModel.createCompatibleWritableRaster(w, h), + mColorModel.isAlphaPremultiplied(), null); int[] data = new int[w*h]; diff --git a/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java index 55c4b98..703719c 100644 --- a/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java @@ -172,8 +172,9 @@ public final class LinearGradient_Delegate extends Gradient_Delegate { @Override public java.awt.image.Raster getRaster(int x, int y, int w, int h) { - java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h, - java.awt.image.BufferedImage.TYPE_INT_ARGB); + java.awt.image.BufferedImage image = new java.awt.image.BufferedImage( + mColorModel, mColorModel.createCompatibleWritableRaster(w, h), + mColorModel.isAlphaPremultiplied(), null); int[] data = new int[w*h]; diff --git a/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java index 80179ee..6edb140 100644 --- a/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java @@ -160,8 +160,9 @@ public class RadialGradient_Delegate extends Gradient_Delegate { @Override public java.awt.image.Raster getRaster(int x, int y, int w, int h) { - java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h, - java.awt.image.BufferedImage.TYPE_INT_ARGB); + java.awt.image.BufferedImage image = new java.awt.image.BufferedImage( + mColorModel, mColorModel.createCompatibleWritableRaster(w, h), + mColorModel.isAlphaPremultiplied(), null); int[] data = new int[w*h]; diff --git a/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java index 95a57a9..544ba98 100644 --- a/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java @@ -152,8 +152,9 @@ public class SweepGradient_Delegate extends Gradient_Delegate { @Override public java.awt.image.Raster getRaster(int x, int y, int w, int h) { - java.awt.image.BufferedImage image = new java.awt.image.BufferedImage(w, h, - java.awt.image.BufferedImage.TYPE_INT_ARGB); + java.awt.image.BufferedImage image = new java.awt.image.BufferedImage( + mColorModel, mColorModel.createCompatibleWritableRaster(w, h), + mColorModel.isAlphaPremultiplied(), null); int[] data = new int[w*h]; |