Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63fd8711 authored by Xavier Ducrohet's avatar Xavier Ducrohet
Browse files

LayoutLib: Misc rendering fixes.

- always set up the stroke. Paint may not have the proper
  style when drawing lines. stroke should still be setup.

- Fixed vertical linear gradient. Old code generated
  a gradient ratio of NaN

- Fixed alpha rendering when using shaders. In that
  case the alpha channel from the paint color should be
  used in conjunction with the shader.

- Fixed miter limit. Java expects the value to be multiplied
  by the stroke width

- Fixed support for drawing ALPHA_8 bitmaps. Java2D doesn't
  have bitmaps with only alpha channels, so we keep using
  ARGB bitmaps but when drawing them into a bitmap we erase
  the color information.

Change-Id: I4f04341fc843e3f7dadd1fdbf709b11a4f1e24b9
parent d348b6ea
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<com.android.test.hwui.LinesActivity.LinesView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
</com.android.test.hwui.LinesActivity.LinesView>
+8 −8
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ public class LinesActivity extends Activity {
        setContentView(view);
    }

    static class LinesView extends View {
    public static class LinesView extends View {
        private static final boolean LINE_AA = false;

        private final Bitmap mBitmap1;
@@ -47,7 +47,7 @@ public class LinesActivity extends Activity {
        private final Paint mAlphaPaint;
        private final Paint mHairLinePaint;

        LinesView(Context c) {
        public LinesView(Context c) {
            super(c);

            mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
+15 −12
Original line number Diff line number Diff line
@@ -52,6 +52,9 @@ public class ShadersActivity extends Activity {
        private LinearGradient mDiagGradient;
        private LinearGradient mVertGradient;
        private Bitmap mTexture;
        private Matrix mMtx1;
        private Matrix mMtx2;
        private Matrix mMtx3;

        public ShadersView(Context c) {
            super(c);
@@ -67,24 +70,24 @@ public class ShadersActivity extends Activity {

            mTranslatedShader = new BitmapShader(mTexture, Shader.TileMode.REPEAT,
                    Shader.TileMode.REPEAT);
            Matrix m1 = new Matrix();
            m1.setTranslate(mTexWidth / 2.0f, mTexHeight / 2.0f);
            m1.postRotate(45, 0, 0);
            mTranslatedShader.setLocalMatrix(m1);
            mMtx1 = new Matrix();
            mMtx1.setTranslate(mTexWidth / 2.0f, mTexHeight / 2.0f);
            mMtx1.postRotate(45, 0, 0);
            mTranslatedShader.setLocalMatrix(mMtx1);

            mScaledShader = new BitmapShader(mTexture, Shader.TileMode.MIRROR,
                    Shader.TileMode.MIRROR);
            Matrix m2 = new Matrix();
            m2.setScale(0.5f, 0.5f);
            mScaledShader.setLocalMatrix(m2);
            mMtx2 = new Matrix();
            mMtx2.setScale(0.5f, 0.5f);
            mScaledShader.setLocalMatrix(mMtx2);

            mHorGradient = new LinearGradient(0.0f, 0.0f, 1.0f, 0.0f,
                    Color.RED, Color.GREEN, Shader.TileMode.CLAMP);
            Matrix m3 = new Matrix();
            m3.setScale(mDrawHeight, 1.0f);
            m3.postRotate(-90.0f);
            m3.postTranslate(0.0f, mDrawHeight);
            mHorGradient.setLocalMatrix(m3);
            mMtx3 = new Matrix();
            mMtx3.setScale(mDrawHeight, 1.0f);
            mMtx3.postRotate(-90.0f);
            mMtx3.postTranslate(0.0f, mDrawHeight);
            mHorGradient.setLocalMatrix(mMtx3);

            mDiagGradient = new LinearGradient(0.0f, 0.0f, mDrawWidth / 1.5f, mDrawHeight,
                    Color.BLUE, Color.MAGENTA, Shader.TileMode.CLAMP);
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ public class AvoidXfermode_Delegate extends Xfermode_Delegate {
    // ---- Public Helper methods ----

    @Override
    public Composite getComposite() {
    public Composite getComposite(int alpha) {
        // FIXME
        return null;
    }
+26 −10
Original line number Diff line number Diff line
@@ -54,9 +54,11 @@ public final class Bitmap_Delegate {
    // ---- delegate helper data ----

    // ---- delegate data ----
    private final Config mConfig;
    private BufferedImage mImage;
    private boolean mHasAlpha = true;


    // ---- Public Helper methods ----

    /**
@@ -86,7 +88,7 @@ public final class Bitmap_Delegate {
    public static Bitmap createBitmap(File input, boolean isMutable, ResourceDensity density)
            throws IOException {
        // create a delegate with the content of the file.
        Bitmap_Delegate delegate = new Bitmap_Delegate(ImageIO.read(input));
        Bitmap_Delegate delegate = new Bitmap_Delegate(ImageIO.read(input), Config.ARGB_8888);

        return createBitmap(delegate, isMutable, density.getDpi());
    }
@@ -104,7 +106,7 @@ public final class Bitmap_Delegate {
    public static Bitmap createBitmap(InputStream input, boolean isMutable, ResourceDensity density)
            throws IOException {
        // create a delegate with the content of the stream.
        Bitmap_Delegate delegate = new Bitmap_Delegate(ImageIO.read(input));
        Bitmap_Delegate delegate = new Bitmap_Delegate(ImageIO.read(input), Config.ARGB_8888);

        return createBitmap(delegate, isMutable, density.getDpi());
    }
@@ -122,7 +124,7 @@ public final class Bitmap_Delegate {
    public static Bitmap createBitmap(BufferedImage image, boolean isMutable,
            ResourceDensity density) throws IOException {
        // create a delegate with the given image.
        Bitmap_Delegate delegate = new Bitmap_Delegate(image);
        Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.ARGB_8888);

        return createBitmap(delegate, isMutable, density.getDpi());
    }
@@ -163,6 +165,15 @@ public final class Bitmap_Delegate {
        return mImage;
    }

    /**
     * Returns the Android bitmap config. Note that this not the config of the underlying
     * Java2D bitmap.
     */
    public Config getConfig() {
        return mConfig;
    }


    // ---- native methods ----

    /*package*/ static Bitmap nativeCreate(int[] colors, int offset, int stride, int width,
@@ -175,7 +186,7 @@ public final class Bitmap_Delegate {
        // FIXME fill the bitmap!

        // create a delegate with the content of the stream.
        Bitmap_Delegate delegate = new Bitmap_Delegate(image);
        Bitmap_Delegate delegate = new Bitmap_Delegate(image, Config.sConfigs[nativeConfig]);

        return createBitmap(delegate, mutable, Bitmap.getDefaultDensity());
    }
@@ -211,10 +222,7 @@ public final class Bitmap_Delegate {

        Graphics2D g = image.createGraphics();
        try {
            if (delegate.mHasAlpha == false) {
                color |= color & 0xFF000000;
            }
            g.setColor(new java.awt.Color(color));
            g.setColor(new java.awt.Color(color, delegate.mHasAlpha));

            g.fillRect(0, 0, image.getWidth(), image.getHeight());
        } finally {
@@ -256,7 +264,14 @@ public final class Bitmap_Delegate {
    }

    /*package*/ static int nativeConfig(int nativeBitmap) {
        return Config.ARGB_8888.nativeInt;
        // get the delegate from the native int.
        Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
        if (delegate == null) {
            assert false;
            return 0;
        }

        return delegate.mConfig.nativeInt;
    }

    /*package*/ static boolean nativeHasAlpha(int nativeBitmap) {
@@ -355,8 +370,9 @@ public final class Bitmap_Delegate {

    // ---- Private delegate/helper methods ----

    private Bitmap_Delegate(BufferedImage image) {
    private Bitmap_Delegate(BufferedImage image, Config config) {
        mImage = image;
        mConfig = config;
    }

    private static Bitmap createBitmap(Bitmap_Delegate delegate, boolean isMutable, int density) {
Loading