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

Commit be447435 authored by Pat Manning's avatar Pat Manning Committed by Android (Google) Code Review
Browse files

Merge changes from topic "vector-cursors" into main

* changes:
  Add support for drawing drop shadow for PointerIcons in native code.
  Add support for ImageFilters to paint in APEX.
  Replace bitmap pointer icons with vector versions.
  Add support for VectorDrawables into PointerIcon.
parents f12aa38b f919b6db
Loading
Loading
Loading
Loading
+28 −3
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.graphics.RectF;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.VectorDrawable;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
@@ -173,6 +174,8 @@ public final class PointerIcon implements Parcelable {
    private Bitmap mBitmapFrames[];
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private int mDurationPerFrame;
    @SuppressWarnings("unused")
    private boolean mDrawNativeDropShadow;

    private PointerIcon(int type) {
        mType = type;
@@ -231,9 +234,15 @@ public final class PointerIcon implements Parcelable {
            typeIndex = getSystemIconTypeIndex(TYPE_DEFAULT);
        }

        final int defStyle = useLargeIcons
                ? com.android.internal.R.style.LargePointer
                : com.android.internal.R.style.Pointer;
        final int defStyle;
        // TODO(b/305193969): Use scaled vectors when large icons are requested.
        if (useLargeIcons) {
            defStyle = com.android.internal.R.style.LargePointer;
        } else if (android.view.flags.Flags.enableVectorCursors()) {
            defStyle = com.android.internal.R.style.VectorPointer;
        } else {
            defStyle = com.android.internal.R.style.Pointer;
        }
        TypedArray a = context.obtainStyledAttributes(null,
                com.android.internal.R.styleable.Pointer,
                0, defStyle);
@@ -333,6 +342,7 @@ public final class PointerIcon implements Parcelable {
                                    Bitmap.CREATOR.createFromParcel(in),
                                    in.readFloat(),
                                    in.readFloat());
                    icon.mDrawNativeDropShadow = in.readBoolean();
                    return icon;
                }

@@ -362,6 +372,7 @@ public final class PointerIcon implements Parcelable {
        mBitmap.writeToParcel(out, flags);
        out.writeFloat(mHotSpotX);
        out.writeFloat(mHotSpotY);
        out.writeBoolean(mDrawNativeDropShadow);
    }

    @Override
@@ -415,6 +426,16 @@ public final class PointerIcon implements Parcelable {
        return scaled;
    }

    private BitmapDrawable getBitmapDrawableFromVectorDrawable(Resources resources,
            VectorDrawable vectorDrawable) {
        Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
                vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        vectorDrawable.draw(canvas);
        return new BitmapDrawable(resources, bitmap);
    }

    private void loadResource(Context context, Resources resources, @XmlRes int resourceId) {
        final XmlResourceParser parser = resources.getXml(resourceId);
        final int bitmapRes;
@@ -476,6 +497,10 @@ public final class PointerIcon implements Parcelable {
                }
            }
        }
        if (drawable instanceof VectorDrawable) {
            mDrawNativeDropShadow = true;
            drawable = getBitmapDrawableFromVectorDrawable(resources, (VectorDrawable) drawable);
        }
        if (!(drawable instanceof BitmapDrawable)) {
            throw new IllegalArgumentException("<pointer-icon> bitmap attribute must "
                    + "refer to a bitmap drawable.");
+8 −0
Original line number Diff line number Diff line
@@ -17,3 +17,11 @@ flag {
    bug: "316170253"
    is_fixed_read_only: true
}

flag {
    name: "enable_vector_cursors"
    namespace: "systemui"
    description: "Feature flag to enable vector drawables in addition to bitmaps for PointerIcon."
    bug: "305193969"
    is_fixed_read_only: true
}
+6 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ static struct {
    jfieldID mHotSpotY;
    jfieldID mBitmapFrames;
    jfieldID mDurationPerFrame;
    jfieldID mDrawNativeDropShadow;
} gPointerIconClassInfo;


@@ -51,6 +52,8 @@ PointerIcon android_view_PointerIcon_toNative(JNIEnv* env, jobject pointerIconOb
            env->GetIntField(pointerIconObj, gPointerIconClassInfo.mType));
    icon.hotSpotX = env->GetFloatField(pointerIconObj, gPointerIconClassInfo.mHotSpotX);
    icon.hotSpotY = env->GetFloatField(pointerIconObj, gPointerIconClassInfo.mHotSpotY);
    icon.drawNativeDropShadow =
            env->GetBooleanField(pointerIconObj, gPointerIconClassInfo.mDrawNativeDropShadow);

    ScopedLocalRef<jobject> bitmapObj(
            env, env->GetObjectField(pointerIconObj, gPointerIconClassInfo.mBitmap));
@@ -95,6 +98,9 @@ int register_android_view_PointerIcon(JNIEnv* env) {
    gPointerIconClassInfo.mBitmapFrames = GetFieldIDOrDie(env, gPointerIconClassInfo.clazz,
            "mBitmapFrames", "[Landroid/graphics/Bitmap;");

    gPointerIconClassInfo.mDrawNativeDropShadow =
            GetFieldIDOrDie(env, gPointerIconClassInfo.clazz, "mDrawNativeDropShadow", "Z");

    gPointerIconClassInfo.mDurationPerFrame = GetFieldIDOrDie(env, gPointerIconClassInfo.clazz,
            "mDurationPerFrame", "I");

+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ struct PointerIcon {
    float hotSpotY;
    std::vector<graphics::Bitmap> bitmapFrames;
    int32_t durationPerFrame;
    bool drawNativeDropShadow;

    inline bool isNullIcon() { return style == PointerIconStyle::TYPE_NULL; }

@@ -49,6 +50,7 @@ struct PointerIcon {
        hotSpotY = 0;
        bitmapFrames.clear();
        durationPerFrame = 0;
        drawNativeDropShadow = false;
    }
};

+33 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright 2024 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.
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24"
    android:viewportWidth="24">
    <path
        android:fillColor="#00FFFFFF"
        android:pathData="M14.494 12.779a5.2 5.2 0 0 1-1.771 1.414 5.2 5.2 0 0 1-1.68.489l.81 1.658a1.968 1.968 0 0 0 3.536-1.728zM12.03 8.291l-.81-1.658a1.968 1.968 0 0 0-3.536 1.728l.896 1.833a5.2 5.2 0 0 1 1.77-1.414 5.2 5.2 0 0 1 1.68-.489" />
    <path
        android:fillColor="#FFFFFF"
        android:pathData="m18.323 13.178-.975-1.995a5.2 5.2 0 0 0-1.704-1.978 5.2 5.2 0 0 0-.517-2.01L14.152 5.2a5.232 5.232 0 0 0-9.401 4.594l.975 1.995a5.2 5.2 0 0 0 1.704 1.978 5.2 5.2 0 0 0 .517 2.01l.975 1.995a5.233 5.233 0 0 0 9.401-4.594m-2.843 6.1a4.23 4.23 0 0 1-5.66-1.944l-.975-1.995a4.2 4.2 0 0 1-.431-1.838l-.001-.276-.234-.146a4.2 4.2 0 0 1-1.555-1.729L5.65 9.355a4.232 4.232 0 1 1 7.604-3.716l.975 1.995c.29.594.428 1.22.431 1.838l.001.276.234.146c.648.405 1.194.99 1.555 1.728l.975 1.995a4.234 4.234 0 0 1-1.945 5.661" />
    <path
        android:fillColor="#FFFFFF"
        android:pathData="M15.313 12.177a3 3 0 0 0-.416-.633l-.459-.534-.353.609a4.2 4.2 0 0 1-1.801 1.675 4.2 4.2 0 0 1-1.977.429l-.704-.02.213.671q.066.208.164.409l.975 1.995a2.967 2.967 0 1 0 5.332-2.606zm-.827 5.066a1.97 1.97 0 0 1-2.632-.904l-.81-1.658a5.2 5.2 0 0 0 1.68-.489 5.2 5.2 0 0 0 1.771-1.414l.896 1.833a1.97 1.97 0 0 1-.905 2.632m-3.697-7.565a4.2 4.2 0 0 1 1.977-.429l.704.02-.213-.671a3 3 0 0 0-.164-.409l-.975-1.995A2.967 2.967 0 1 0 6.785 8.8l.975 1.995q.172.35.416.633l.459.534.353-.609a4.2 4.2 0 0 1 1.801-1.675m-2.21.516-.895-1.833a1.968 1.968 0 1 1 3.536-1.728l.81 1.658a5.2 5.2 0 0 0-1.68.489 5.2 5.2 0 0 0-1.771 1.414m3.151 1.965a3 3 0 0 0 1.02-.818l.755-.95-1.205.142a2.97 2.97 0 0 0-1.975 1.1l-.755.95 1.205-.142c.324-.039.646-.132.955-.282" />
    <path
        android:fillColor="#000000"
        android:pathData="M16.449 11.622a4.2 4.2 0 0 0-1.555-1.728l-.234-.146-.001-.276a4.2 4.2 0 0 0-.431-1.838l-.975-1.995a4.232 4.232 0 1 0-7.604 3.716l.975 1.995a4.2 4.2 0 0 0 1.555 1.729l.234.146.001.276c.002.617.141 1.244.431 1.838l.975 1.995a4.232 4.232 0 1 0 7.604-3.716zm-7.814.34-.459-.534a3 3 0 0 1-.416-.633L6.785 8.8a2.967 2.967 0 1 1 5.332-2.606l.975 1.995q.098.202.164.409l.214.672-.704-.02a4.2 4.2 0 0 0-1.977.429 4.2 4.2 0 0 0-1.801 1.675zm1.689-.33a2.97 2.97 0 0 1 1.975-1.1l1.205-.142-.755.95a2.95 2.95 0 0 1-1.02.818 3 3 0 0 1-.955.281l-1.204.143zm4.601 6.51a2.967 2.967 0 0 1-3.969-1.363l-.975-1.995a3 3 0 0 1-.164-.409l-.213-.671.704.02a4.2 4.2 0 0 0 1.977-.429 4.2 4.2 0 0 0 1.801-1.675l.353-.609.459.534q.245.284.416.633l.975 1.995a2.97 2.97 0 0 1-1.364 3.969" />
</vector>
 No newline at end of file
Loading