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

Commit 509d8609 authored by Deepanshu Gupta's avatar Deepanshu Gupta
Browse files

Sort delegates in Canvas_Delegate

The order of the methods match the order of the declaration in the
Canvas file. This makes searching for the methods easier.

Change-Id: I230621d3999024cb2ff42a1aacd60908c7f0b161
parent bb5d0cc4
Loading
Loading
Loading
Loading
+140 −143
Original line number Diff line number Diff line
@@ -55,16 +55,19 @@ public final class Canvas_Delegate {
    private static final DelegateManager<Canvas_Delegate> sManager =
            new DelegateManager<Canvas_Delegate>(Canvas_Delegate.class);


    // ---- delegate helper data ----

    private final static boolean[] sBoolOut = new boolean[1];


    // ---- delegate data ----
    private Bitmap_Delegate mBitmap;
    private GcSnapshot mSnapshot;

    private DrawFilter_Delegate mDrawFilter = null;


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

    /**
@@ -100,93 +103,90 @@ public final class Canvas_Delegate {
    // ---- native methods ----

    @LayoutlibDelegate
    /*package*/ static boolean native_isOpaque(long nativeCanvas) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return false;
    /*package*/ static void freeCaches() {
        // nothing to be done here.
    }

        return canvasDelegate.mBitmap.getConfig() == Config.RGB_565;
    @LayoutlibDelegate
    /*package*/ static void freeTextLayoutCaches() {
        // nothing to be done here yet.
    }

    @LayoutlibDelegate
    /*package*/ static int native_getWidth(long nativeCanvas) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return 0;
    /*package*/ static long initRaster(long nativeBitmapOrZero) {
        if (nativeBitmapOrZero > 0) {
            // get the Bitmap from the int
            Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmapOrZero);

            // create a new Canvas_Delegate with the given bitmap and return its new native int.
            Canvas_Delegate newDelegate = new Canvas_Delegate(bitmapDelegate);

            return sManager.addNewDelegate(newDelegate);
        }

        return canvasDelegate.mBitmap.getImage().getWidth();
        // create a new Canvas_Delegate and return its new native int.
        Canvas_Delegate newDelegate = new Canvas_Delegate();

        return sManager.addNewDelegate(newDelegate);
    }

    @LayoutlibDelegate
    /*package*/ static int native_getHeight(long nativeCanvas) {
    /*package*/ static long initCanvas(long nativeCanvas) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
        Canvas_Delegate nativeCanvasDelegate = sManager.getDelegate(nativeCanvas);
        if (nativeCanvasDelegate == null) {
            return 0;
        }

        return canvasDelegate.mBitmap.getImage().getHeight();
        Canvas_Delegate newDelegate = new Canvas_Delegate();

        // TODO: actually copy the canvas state.
        return sManager.addNewDelegate(newDelegate);
    }

    @LayoutlibDelegate
   /*package*/ static void native_translate(long nativeCanvas, float dx, float dy) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
    /*package*/
    static void native_setBitmap(long canvas, long bitmap, boolean copyState) {
        Canvas_Delegate canvasDelegate = sManager.getDelegate(canvas);
        Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
        if (canvasDelegate == null || bitmapDelegate==null) {
            return;
        }

        canvasDelegate.getSnapshot().translate(dx, dy);
        canvasDelegate.mBitmap = bitmapDelegate;
        canvasDelegate.mSnapshot = GcSnapshot.createDefaultSnapshot(bitmapDelegate);
    }

    @LayoutlibDelegate
    /*package*/ static void native_rotate(long nativeCanvas, float degrees) {
    /*package*/ static boolean native_isOpaque(long nativeCanvas) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return;
            return false;
        }

        canvasDelegate.getSnapshot().rotate(Math.toRadians(degrees));
        return canvasDelegate.mBitmap.getConfig() == Config.RGB_565;
    }

    @LayoutlibDelegate
   /*package*/ static void native_scale(long nativeCanvas, float sx, float sy) {
    /*package*/ static int native_getWidth(long nativeCanvas) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return;
            return 0;
        }

        canvasDelegate.getSnapshot().scale(sx, sy);
        return canvasDelegate.mBitmap.getImage().getWidth();
    }

    @LayoutlibDelegate
   /*package*/ static void native_skew(long nativeCanvas, float kx, float ky) {
    /*package*/ static int native_getHeight(long nativeCanvas) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return;
            return 0;
        }

        // get the current top graphics2D object.
        GcSnapshot g = canvasDelegate.getSnapshot();

        // get its current matrix
        AffineTransform currentTx = g.getTransform();
        // get the AffineTransform for the given skew.
        float[] mtx = Matrix_Delegate.getSkew(kx, ky);
        AffineTransform matrixTx = Matrix_Delegate.getAffineTransform(mtx);

        // combine them so that the given matrix is applied after.
        currentTx.preConcatenate(matrixTx);

        // give it to the graphics2D as a new matrix replacing all previous transform
        g.setTransform(currentTx);
        return canvasDelegate.mBitmap.getImage().getHeight();
    }

    @LayoutlibDelegate
@@ -201,157 +201,126 @@ public final class Canvas_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_restore(long nativeCanvas) {
    /*package*/ static int native_saveLayer(long nativeCanvas, float l,
                                               float t, float r, float b,
                                               long paint, int layerFlags) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return;
            return 0;
        }

        canvasDelegate.restore();
        Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint);
        if (paintDelegate == null) {
            return 0;
        }

        return canvasDelegate.saveLayer(new RectF(l, t, r, b),
                paintDelegate, layerFlags);
    }

    @LayoutlibDelegate
    /*package*/ static int native_getSaveCount(long nativeCanvas) {
    /*package*/ static int native_saveLayerAlpha(long nativeCanvas, float l,
                                                    float t, float r, float b,
                                                    int alpha, int layerFlags) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return 0;
        }

        return canvasDelegate.getSnapshot().size();
        return canvasDelegate.saveLayerAlpha(new RectF(l, t, r, b), alpha, layerFlags);
    }

    @LayoutlibDelegate
    /*package*/ static void native_restoreToCount(long nativeCanvas, int saveCount) {
    /*package*/ static void native_restore(long nativeCanvas) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return;
        }

        canvasDelegate.restoreTo(saveCount);
    }

    @LayoutlibDelegate
    /*package*/ static void native_drawPoints(long nativeCanvas, float[] pts, int offset, int count,
            long nativePaint) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Canvas.drawPoint is not supported.", null, null /*data*/);
    }

    @LayoutlibDelegate
    /*package*/ static void native_drawPoint(long nativeCanvas, float x, float y,
            long nativePaint) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Canvas.drawPoint is not supported.", null, null /*data*/);
    }

    @LayoutlibDelegate
    /*package*/ static void native_drawLines(long nativeCanvas,
            final float[] pts, final int offset, final int count,
            long nativePaint) {

        draw(nativeCanvas, nativePaint, false /*compositeOnly*/,
                false /*forceSrcMode*/, new GcSnapshot.Drawable() {
                    @Override
                    public void draw(Graphics2D graphics, Paint_Delegate paintDelegate) {
                        for (int i = 0; i < count; i += 4) {
                            graphics.drawLine((int) pts[i + offset], (int) pts[i + offset + 1],
                                    (int) pts[i + offset + 2], (int) pts[i + offset + 3]);
                        }
                    }
                });
        canvasDelegate.restore();
    }

    @LayoutlibDelegate
    /*package*/ static void freeCaches() {
        // nothing to be done here.
    /*package*/ static void native_restoreToCount(long nativeCanvas, int saveCount) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return;
        }

    @LayoutlibDelegate
    /*package*/ static void freeTextLayoutCaches() {
        // nothing to be done here yet.
        canvasDelegate.restoreTo(saveCount);
    }

    @LayoutlibDelegate
    /*package*/ static long initRaster(long nativeBitmapOrZero) {
        if (nativeBitmapOrZero > 0) {
            // get the Bitmap from the int
            Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmapOrZero);

            // create a new Canvas_Delegate with the given bitmap and return its new native int.
            Canvas_Delegate newDelegate = new Canvas_Delegate(bitmapDelegate);

            return sManager.addNewDelegate(newDelegate);
    /*package*/ static int native_getSaveCount(long nativeCanvas) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return 0;
        }

        // create a new Canvas_Delegate and return its new native int.
        Canvas_Delegate newDelegate = new Canvas_Delegate();

        return sManager.addNewDelegate(newDelegate);
        return canvasDelegate.getSnapshot().size();
    }

    @LayoutlibDelegate
    /*package*/ static long initCanvas(long nativeCanvas) {
   /*package*/ static void native_translate(long nativeCanvas, float dx, float dy) {
        // get the delegate from the native int.
        Canvas_Delegate nativeCanvasDelegate = sManager.getDelegate(nativeCanvas);
        if (nativeCanvasDelegate == null) {
            return 0;
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return;
        }

        Canvas_Delegate newDelegate = new Canvas_Delegate();

        // TODO: actually copy the canvas state.
        return sManager.addNewDelegate(newDelegate);
        canvasDelegate.getSnapshot().translate(dx, dy);
    }

    @LayoutlibDelegate
    /*package*/
    static void native_setBitmap(long canvas, long bitmap, boolean copyState) {
        Canvas_Delegate canvasDelegate = sManager.getDelegate(canvas);
        Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
        if (canvasDelegate == null || bitmapDelegate==null) {
       /*package*/ static void native_scale(long nativeCanvas, float sx, float sy) {
            // get the delegate from the native int.
            Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
            if (canvasDelegate == null) {
                return;
            }
        canvasDelegate.mBitmap = bitmapDelegate;
        canvasDelegate.mSnapshot = GcSnapshot.createDefaultSnapshot(bitmapDelegate);

            canvasDelegate.getSnapshot().scale(sx, sy);
        }

    @LayoutlibDelegate
    /*package*/ static int native_saveLayer(long nativeCanvas, float l,
                                               float t, float r, float b,
                                               long paint, int layerFlags) {
    /*package*/ static void native_rotate(long nativeCanvas, float degrees) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return 0;
        }

        Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint);
        if (paintDelegate == null) {
            return 0;
            return;
        }

        return canvasDelegate.saveLayer(new RectF(l, t, r, b),
                paintDelegate, layerFlags);
        canvasDelegate.getSnapshot().rotate(Math.toRadians(degrees));
    }

    @LayoutlibDelegate
    /*package*/ static int native_saveLayerAlpha(long nativeCanvas, float l,
                                                    float t, float r, float b,
                                                    int alpha, int layerFlags) {
   /*package*/ static void native_skew(long nativeCanvas, float kx, float ky) {
        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
        if (canvasDelegate == null) {
            return 0;
            return;
        }

        return canvasDelegate.saveLayerAlpha(new RectF(l, t, r, b), alpha, layerFlags);
    }
        // get the current top graphics2D object.
        GcSnapshot g = canvasDelegate.getSnapshot();

        // get its current matrix
        AffineTransform currentTx = g.getTransform();
        // get the AffineTransform for the given skew.
        float[] mtx = Matrix_Delegate.getSkew(kx, ky);
        AffineTransform matrixTx = Matrix_Delegate.getAffineTransform(mtx);

        // combine them so that the given matrix is applied after.
        currentTx.preConcatenate(matrixTx);

        // give it to the graphics2D as a new matrix replacing all previous transform
        g.setTransform(currentTx);
    }

    @LayoutlibDelegate
    /*package*/ static void native_concat(long nCanvas, long nMatrix) {
@@ -416,7 +385,6 @@ public final class Canvas_Delegate {
                                                  float left, float top,
                                                  float right, float bottom,
                                                  int regionOp) {

        // get the delegate from the native int.
        Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
        if (canvasDelegate == null) {
@@ -515,8 +483,7 @@ public final class Canvas_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static boolean native_quickReject(long nativeCanvas,
                                                     long path) {
    /*package*/ static boolean native_quickReject(long nativeCanvas, long path) {
        // FIXME properly implement quickReject
        return false;
    }
@@ -584,11 +551,26 @@ public final class Canvas_Delegate {
                "Canvas.drawPaint is not supported.", null, null /*data*/);
    }

    @LayoutlibDelegate
    /*package*/ static void native_drawPoint(long nativeCanvas, float x, float y,
            long nativePaint) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Canvas.drawPoint is not supported.", null, null /*data*/);
    }

    @LayoutlibDelegate
    /*package*/ static void native_drawPoints(long nativeCanvas, float[] pts, int offset, int count,
            long nativePaint) {
        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Canvas.drawPoint is not supported.", null, null /*data*/);
    }

    @LayoutlibDelegate
    /*package*/ static void native_drawLine(long nativeCanvas,
            final float startX, final float startY, final float stopX, final float stopY,
            long paint) {

        draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                new GcSnapshot.Drawable() {
                    @Override
@@ -598,6 +580,22 @@ public final class Canvas_Delegate {
        });
    }

    @LayoutlibDelegate
    /*package*/ static void native_drawLines(long nativeCanvas,
            final float[] pts, final int offset, final int count,
            long nativePaint) {
        draw(nativeCanvas, nativePaint, false /*compositeOnly*/,
                false /*forceSrcMode*/, new GcSnapshot.Drawable() {
                    @Override
                    public void draw(Graphics2D graphics, Paint_Delegate paintDelegate) {
                        for (int i = 0; i < count; i += 4) {
                            graphics.drawLine((int) pts[i + offset], (int) pts[i + offset + 1],
                                    (int) pts[i + offset + 2], (int) pts[i + offset + 3]);
                        }
                    }
                });
    }

    @LayoutlibDelegate
    /*package*/ static void native_drawRect(long nativeCanvas,
            final float left, final float top, final float right, final float bottom, long paint) {
@@ -695,7 +693,6 @@ public final class Canvas_Delegate {
    /*package*/ static void native_drawRoundRect(long nativeCanvas,
            final float left, final float top, final float right, final float bottom,
            final float rx, final float ry, long paint) {

        draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                new GcSnapshot.Drawable() {
                    @Override
@@ -827,7 +824,6 @@ public final class Canvas_Delegate {
                                                 final float y, int width, int height,
                                                 boolean hasAlpha,
                                                 long nativePaintOrZero) {

        // create a temp BufferedImage containing the content.
        final BufferedImage image = new BufferedImage(width, height,
                hasAlpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
@@ -1013,6 +1009,7 @@ public final class Canvas_Delegate {
        sManager.removeJavaReferenceFor(nativeCanvas);
    }


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

    /**