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

Commit 0d61d78e authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Support custom crop in weather effects

Replace centerCropMatrix with customCropMatrix

To avoid creating a very large FrameBuffer caused by scaling up the bitmap too much, instead, we change the FrameBuffer size from bitmapScale * bitmapSize to bitmap, and only create new FrameBuffer when bitmap changes.

Bug: 435215686
Bug: 417165168
Test: manual test on flag on and off
Flag: com.android.systemui.shared.pan_and_zoom_in_extended_wallpaper_effects

Change-Id: I8cfa40b0717b50e69ea79b507583443054fe1594
parent af469e17
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -209,3 +209,9 @@ flag {
  bug: "381897614"
}

flag {
    name: "pan_and_zoom_in_extended_wallpaper_effects"
    namespace: "systemui"
    description: "Support pan & zoom for extended wallpaper effects"
    bug: "417165168"
}
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ android_library {
        // Do not add Torus dependency here, since this package is only for rendering. The host app
        // will include Torus or Livewallpaper frameworks.
        "androidx.appcompat_appcompat",
        "//frameworks/libs/systemui:com_android_systemui_shared_flags_lib",
    ],
    srcs: [
        "graphics/src/**/*.java",
+3 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ uniform float2 screenSize;
uniform float cellAspectRatio;
uniform mat3 transformMatrixBitmap;
uniform mat3 transformMatrixWeather;
uniform mat3 transformMatrixAccumulation;
uniform shader snowFlakeSamples;

#include "shaders/constants.agsl"
@@ -57,6 +58,7 @@ vec4 main(float2 fragCoord) {
    float2 adjustedUv = transformPoint(transformMatrixBitmap, fragCoord);
    // Calculate uv for snow based on transformed coordinates
    float2 weatherUv = transformPoint(transformMatrixWeather, fragCoord);
    float2 accumulationUv = transformPoint(transformMatrixAccumulation, fragCoord);
    float2 uv = weatherUv / screenSize;
    float2 uvAdjusted = vec2(uv.x, uv.y / screenAspectRatio);

@@ -97,7 +99,7 @@ vec4 main(float2 fragCoord) {
    color.rgb = normalBlend(color.rgb, colorForeground.rgb, colorForeground.a);

    // 4. Add accumulated snow layer.
    vec3 accSnow = accumulatedSnow.eval(weatherUv).rgb;
    vec3 accSnow = accumulatedSnow.eval(accumulationUv).rgb;
    float accSnowMask = smoothstep( (1.-intensity), 1.0, /* mask= */accSnow.r);
    accSnowMask = map(accSnowMask, accSnow.g, 1., 0., 1.);
    accSnowMask = map(accSnowMask, 0., 1., 0., accSnow.b);
+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ android {
}

dependencies {
    implementation project(":frameworks:base:packages:SystemUI:SystemUISharedFlags")
    implementation 'androidx.core:core-ktx:1.12.0'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.11.0'
+11 −4
Original line number Diff line number Diff line
@@ -73,11 +73,18 @@ interface WeatherEffect {
    fun setBitmaps(foreground: Bitmap?, background: Bitmap): Boolean

    /**
     * Apply matrix to transform coordinates in shaders. In Editor and preview, it's a center crop
     * matrix to center the bitmap in surface size; in applied wallpaper, the matrix is the parallax
     * matrix due to the pagination in homescreen
     * Applies a transformation matrix for parallax and cropping. In the editor and preview, this
     * matrix handles custom cropping. When the wallpaper is applied on the home screen, this matrix
     * combines both custom cropping and parallax-based transformations.
     */
    fun setMatrix(matrix: Matrix) {}
    fun setPositionMatrix(matrix: Matrix) {}

    /**
     * Sets the custom cropping matrix. This is used in the editor and preview to handle
     * user-defined pan and zoom. The matrix is later incorporated into the parallax matrix for the
     * final rendering.
     */
    fun setCustomCropMatrix(matrix: Matrix) {}

    companion object {
        val DEFAULT_INTENSITY = 1f
Loading