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

Commit 63389dae authored by Jerome Gaillard's avatar Jerome Gaillard Committed by Android (Google) Code Review
Browse files

Merge "Update layoulib following changes in Android source code"

parents 0ec8a24a 39bdc174
Loading
Loading
Loading
Loading
+0 −69
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.graphics;

import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

/**
 * Delegate implementing the native methods of android.graphics.LayerRasterizer
 *
 * Through the layoutlib_create tool, the original native methods of LayerRasterizer have
 * been replaced by calls to methods of the same name in this delegate class.
 *
 * This class behaves like the original native implementation, but in Java, keeping previously
 * native data into its own objects and mapping them to int that are sent back and forth between
 * it and the original LayerRasterizer class.
 *
 * Because this extends {@link Rasterizer_Delegate}, there's no need to use a
 * {@link DelegateManager}, as all the Shader classes will be added to the manager
 * owned by {@link Rasterizer_Delegate}.
 *
 * @see Rasterizer_Delegate
 *
 */
public class LayerRasterizer_Delegate extends Rasterizer_Delegate {

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

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

    @Override
    public boolean isSupported() {
        return false;
    }

    @Override
    public String getSupportMessage() {
        return "Layer Rasterizers are not supported.";
    }

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

    @LayoutlibDelegate
    /*package*/ static long nativeConstructor() {
        LayerRasterizer_Delegate newDelegate = new LayerRasterizer_Delegate();
        return sManager.addNewDelegate(newDelegate);
    }

    @LayoutlibDelegate
    /*package*/ static void nativeAddLayer(long native_layer, long native_paint, float dx, float dy) {

    }

    // ---- Private delegate/helper methods ----
}
+0 −31
Original line number Diff line number Diff line
@@ -99,7 +99,6 @@ public class Paint_Delegate {
    private Shader_Delegate mShader;
    private PathEffect_Delegate mPathEffect;
    private MaskFilter_Delegate mMaskFilter;
    private Rasterizer_Delegate mRasterizer;

    private Locale mLocale = Locale.getDefault();

@@ -248,15 +247,6 @@ public class Paint_Delegate {
        return mMaskFilter;
    }

    /**
     * Returns the {@link Rasterizer} delegate or null if none have been set
     *
     * @return the delegate or null.
     */
    public Rasterizer_Delegate getRasterizer() {
        return mRasterizer;
    }

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

    @LayoutlibDelegate
@@ -897,25 +887,6 @@ public class Paint_Delegate {
        return typeface;
    }

    @LayoutlibDelegate
    /*package*/ static long nSetRasterizer(long native_object, long rasterizer) {
        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return rasterizer;
        }

        delegate.mRasterizer = Rasterizer_Delegate.getDelegate(rasterizer);

        // since none of those are supported, display a fidelity warning right away
        if (delegate.mRasterizer != null && !delegate.mRasterizer.isSupported()) {
            Bridge.getLog().fidelityWarning(LayoutLog.TAG_RASTERIZER,
                    delegate.mRasterizer.getSupportMessage(), null, null /*data*/);
        }

        return rasterizer;
    }

    @LayoutlibDelegate
    /*package*/ static int nGetTextAlign(long native_object) {
        // get the delegate from the native int.
@@ -1235,7 +1206,6 @@ public class Paint_Delegate {
        mShader = paint.mShader;
        mPathEffect = paint.mPathEffect;
        mMaskFilter = paint.mMaskFilter;
        mRasterizer = paint.mRasterizer;
        mHintingMode = paint.mHintingMode;

        if (needsFontUpdate) {
@@ -1262,7 +1232,6 @@ public class Paint_Delegate {
        mShader = null;
        mPathEffect = null;
        mMaskFilter = null;
        mRasterizer = null;
        updateFontObject();
        mHintingMode = Paint.HINTING_ON;
    }
+10 −10
Original line number Diff line number Diff line
@@ -56,8 +56,8 @@ public final class PathMeasure_Delegate {
        if (native_path != 0) {
            if (forceClosed) {
                // Copy the path and call close
                native_path = Path_Delegate.init2(native_path);
                Path_Delegate.native_close(native_path);
                native_path = Path_Delegate.nInit(native_path);
                Path_Delegate.nClose(native_path);
            }

            Path_Delegate pathDelegate = Path_Delegate.getDelegate(native_path);
@@ -108,8 +108,8 @@ public final class PathMeasure_Delegate {
        if (native_path != 0) {
            if (forceClosed) {
                // Copy the path and call close
                native_path = Path_Delegate.init2(native_path);
                Path_Delegate.native_close(native_path);
                native_path = Path_Delegate.nInit(native_path);
                Path_Delegate.nClose(native_path);
            }

            Path_Delegate pathDelegate = Path_Delegate.getDelegate(native_path);
@@ -184,28 +184,28 @@ public final class PathMeasure_Delegate {
                    if (type != PathIterator.SEG_MOVETO) {
                        float[] lastPoint = new float[2];
                        iterator.getCurrentSegmentEnd(lastPoint);
                        Path_Delegate.native_moveTo(native_dst_path, lastPoint[0], lastPoint[1]);
                        Path_Delegate.nMoveTo(native_dst_path, lastPoint[0], lastPoint[1]);
                    }
                }

                isZeroLength = isZeroLength && iterator.getCurrentSegmentLength() > 0;
                switch (type) {
                    case PathIterator.SEG_MOVETO:
                        Path_Delegate.native_moveTo(native_dst_path, points[0], points[1]);
                        Path_Delegate.nMoveTo(native_dst_path, points[0], points[1]);
                        break;
                    case PathIterator.SEG_LINETO:
                        Path_Delegate.native_lineTo(native_dst_path, points[0], points[1]);
                        Path_Delegate.nLineTo(native_dst_path, points[0], points[1]);
                        break;
                    case PathIterator.SEG_CLOSE:
                        Path_Delegate.native_close(native_dst_path);
                        Path_Delegate.nClose(native_dst_path);
                        break;
                    case PathIterator.SEG_CUBICTO:
                        Path_Delegate.native_cubicTo(native_dst_path, points[0], points[1],
                        Path_Delegate.nCubicTo(native_dst_path, points[0], points[1],
                                points[2], points[3],
                                points[4], points[5]);
                        break;
                    case PathIterator.SEG_QUADTO:
                        Path_Delegate.native_quadTo(native_dst_path, points[0], points[1],
                        Path_Delegate.nQuadTo(native_dst_path, points[0], points[1],
                                points[2],
                                points[3]);
                        break;
+41 −41
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public final class Path_Delegate {
    // ---- native methods ----

    @LayoutlibDelegate
    /*package*/ static long init1() {
    /*package*/ static long nInit() {
        // create the delegate
        Path_Delegate newDelegate = new Path_Delegate();

@@ -106,7 +106,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static long init2(long nPath) {
    /*package*/ static long nInit(long nPath) {
        // create the delegate
        Path_Delegate newDelegate = new Path_Delegate();

@@ -120,7 +120,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_reset(long nPath) {
    /*package*/ static void nReset(long nPath) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -130,20 +130,20 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_rewind(long nPath) {
    /*package*/ static void nRewind(long nPath) {
        // call out to reset since there's nothing to optimize in
        // terms of data structs.
        native_reset(nPath);
        nReset(nPath);
    }

    @LayoutlibDelegate
    /*package*/ static void native_set(long native_dst, long native_src) {
    /*package*/ static void nSet(long native_dst, long nSrc) {
        Path_Delegate pathDstDelegate = sManager.getDelegate(native_dst);
        if (pathDstDelegate == null) {
            return;
        }

        Path_Delegate pathSrcDelegate = sManager.getDelegate(native_src);
        Path_Delegate pathSrcDelegate = sManager.getDelegate(nSrc);
        if (pathSrcDelegate == null) {
            return;
        }
@@ -152,14 +152,14 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static boolean native_isConvex(long nPath) {
    /*package*/ static boolean nIsConvex(long nPath) {
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Path.isConvex is not supported.", null, null);
        return true;
    }

    @LayoutlibDelegate
    /*package*/ static int native_getFillType(long nPath) {
    /*package*/ static int nGetFillType(long nPath) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return 0;
@@ -169,7 +169,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    public static void native_setFillType(long nPath, int ft) {
    public static void nSetFillType(long nPath, int ft) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -179,14 +179,14 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static boolean native_isEmpty(long nPath) {
    /*package*/ static boolean nIsEmpty(long nPath) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        return pathDelegate == null || pathDelegate.isEmpty();

    }

    @LayoutlibDelegate
    /*package*/ static boolean native_isRect(long nPath, RectF rect) {
    /*package*/ static boolean nIsRect(long nPath, RectF rect) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return false;
@@ -206,7 +206,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_computeBounds(long nPath, RectF bounds) {
    /*package*/ static void nComputeBounds(long nPath, RectF bounds) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -216,13 +216,13 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_incReserve(long nPath, int extraPtCount) {
    /*package*/ static void nIncReserve(long nPath, int extraPtCount) {
        // since we use a java2D path, there's no way to pre-allocate new points,
        // so we do nothing.
    }

    @LayoutlibDelegate
    /*package*/ static void native_moveTo(long nPath, float x, float y) {
    /*package*/ static void nMoveTo(long nPath, float x, float y) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -232,7 +232,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_rMoveTo(long nPath, float dx, float dy) {
    /*package*/ static void nRMoveTo(long nPath, float dx, float dy) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -242,7 +242,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_lineTo(long nPath, float x, float y) {
    /*package*/ static void nLineTo(long nPath, float x, float y) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -252,7 +252,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_rLineTo(long nPath, float dx, float dy) {
    /*package*/ static void nRLineTo(long nPath, float dx, float dy) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -262,7 +262,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_quadTo(long nPath, float x1, float y1, float x2, float y2) {
    /*package*/ static void nQuadTo(long nPath, float x1, float y1, float x2, float y2) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -272,7 +272,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_rQuadTo(long nPath, float dx1, float dy1, float dx2, float dy2) {
    /*package*/ static void nRQuadTo(long nPath, float dx1, float dy1, float dx2, float dy2) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -282,7 +282,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_cubicTo(long nPath, float x1, float y1,
    /*package*/ static void nCubicTo(long nPath, float x1, float y1,
            float x2, float y2, float x3, float y3) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
@@ -293,7 +293,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_rCubicTo(long nPath, float x1, float y1,
    /*package*/ static void nRCubicTo(long nPath, float x1, float y1,
            float x2, float y2, float x3, float y3) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
@@ -304,7 +304,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_arcTo(long nPath, float left, float top, float right,
    /*package*/ static void nArcTo(long nPath, float left, float top, float right,
            float bottom,
                    float startAngle, float sweepAngle, boolean forceMoveTo) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
@@ -316,7 +316,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_close(long nPath) {
    /*package*/ static void nClose(long nPath) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -326,7 +326,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_addRect(long nPath,
    /*package*/ static void nAddRect(long nPath,
            float left, float top, float right, float bottom, int dir) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
@@ -337,7 +337,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_addOval(long nPath, float left, float top, float right,
    /*package*/ static void nAddOval(long nPath, float left, float top, float right,
            float bottom, int dir) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
@@ -349,7 +349,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_addCircle(long nPath, float x, float y, float radius, int dir) {
    /*package*/ static void nAddCircle(long nPath, float x, float y, float radius, int dir) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -361,7 +361,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_addArc(long nPath, float left, float top, float right,
    /*package*/ static void nAddArc(long nPath, float left, float top, float right,
            float bottom, float startAngle, float sweepAngle) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
@@ -375,7 +375,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_addRoundRect(long nPath, float left, float top, float right,
    /*package*/ static void nAddRoundRect(long nPath, float left, float top, float right,
            float bottom, float rx, float ry, int dir) {

        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
@@ -388,7 +388,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_addRoundRect(long nPath, float left, float top, float right,
    /*package*/ static void nAddRoundRect(long nPath, float left, float top, float right,
            float bottom, float[] radii, int dir) {

        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
@@ -405,17 +405,17 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_addPath(long nPath, long src, float dx, float dy) {
    /*package*/ static void nAddPath(long nPath, long src, float dx, float dy) {
        addPath(nPath, src, AffineTransform.getTranslateInstance(dx, dy));
    }

    @LayoutlibDelegate
    /*package*/ static void native_addPath(long nPath, long src) {
    /*package*/ static void nAddPath(long nPath, long src) {
        addPath(nPath, src, null /*transform*/);
    }

    @LayoutlibDelegate
    /*package*/ static void native_addPath(long nPath, long src, long matrix) {
    /*package*/ static void nAddPath(long nPath, long src, long matrix) {
        Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(matrix);
        if (matrixDelegate == null) {
            return;
@@ -425,7 +425,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_offset(long nPath, float dx, float dy) {
    /*package*/ static void nOffset(long nPath, float dx, float dy) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -435,7 +435,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_setLastPoint(long nPath, float dx, float dy) {
    /*package*/ static void nSetLastPoint(long nPath, float dx, float dy) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return;
@@ -446,7 +446,7 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_transform(long nPath, long matrix,
    /*package*/ static void nTransform(long nPath, long matrix,
                                                long dst_path) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
@@ -465,23 +465,23 @@ public final class Path_Delegate {
    }

    @LayoutlibDelegate
    /*package*/ static void native_transform(long nPath, long matrix) {
        native_transform(nPath, matrix, 0);
    /*package*/ static void nTransform(long nPath, long matrix) {
        nTransform(nPath, matrix, 0);
    }

    @LayoutlibDelegate
    /*package*/ static boolean native_op(long nPath1, long nPath2, int op, long result) {
    /*package*/ static boolean nOp(long nPath1, long nPath2, int op, long result) {
        Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED, "Path.op() not supported", null);
        return false;
    }

    @LayoutlibDelegate
    /*package*/ static void finalizer(long nPath) {
    /*package*/ static void nFinalize(long nPath) {
        sManager.removeJavaReferenceFor(nPath);
    }

    @LayoutlibDelegate
    /*package*/ static float[] native_approximate(long nPath, float error) {
    /*package*/ static float[] nApproximate(long nPath, float error) {
        Path_Delegate pathDelegate = sManager.getDelegate(nPath);
        if (pathDelegate == null) {
            return null;
+0 −64
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.graphics;

import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;

/**
 * Delegate implementing the native methods of android.graphics.Rasterizer
 *
 * Through the layoutlib_create tool, the original native methods of Rasterizer have been replaced
 * by calls to methods of the same name in this delegate class.
 *
 * This class behaves like the original native implementation, but in Java, keeping previously
 * native data into its own objects and mapping them to int that are sent back and forth between
 * it and the original Rasterizer class.
 *
 * This also serve as a base class for all Rasterizer delegate classes.
 *
 * @see DelegateManager
 *
 */
public abstract class Rasterizer_Delegate {

    // ---- delegate manager ----
    protected static final DelegateManager<Rasterizer_Delegate> sManager =
            new DelegateManager<Rasterizer_Delegate>(Rasterizer_Delegate.class);

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

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

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

    public static Rasterizer_Delegate getDelegate(long nativeShader) {
        return sManager.getDelegate(nativeShader);
    }

    public abstract boolean isSupported();
    public abstract String getSupportMessage();

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

    @LayoutlibDelegate
    /*package*/ static void finalizer(long native_instance) {
        sManager.removeJavaReferenceFor(native_instance);
    }

    // ---- Private delegate/helper methods ----
}
Loading