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

Commit bdadc6d2 authored by John Reck's avatar John Reck
Browse files

Fix backdrop effect for prerotation

When doing prerotation the matrix math didn't work out due
to makeImageSnapshot() being rotated already, but then drawn
again into a rotating matrix. Fix this by having BackdropFilterDrawable
do everything in post-rotation space.

Bug: 353827335
Test: SilkFX view blur behind demo
Flag: EXEMPT bugfix
Change-Id: I7b41d95e7e5f15434f9c6481534c74ee998a83ef
parent b6924395
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -86,9 +86,17 @@ void BackdropFilterDrawable::onDraw(SkCanvas* canvas) {
        backdropImage = SkImages::MakeWithFilter(backdropImage, backdropFilter, imageSubset,
                                                 imageSubset, &mOutSubset, &mOutOffset);
    }
    canvas->drawImageRect(backdropImage, SkRect::Make(mOutSubset), mDstBounds,

    // backdropImage & mOutSubset are in post-pre-rotation space, whereas mDstBounds is in
    // prerotation space. So map dst bounds to post-pre-rotation space & draw there
    SkRect dst;
    canvas->getTotalMatrix().mapRect(&dst, mDstBounds);
    canvas->save();
    canvas->resetMatrix();
    canvas->drawImageRect(backdropImage, SkRect::Make(mOutSubset), dst,
                          SkSamplingOptions(SkFilterMode::kLinear), &mPaint,
                          SkCanvas::kStrict_SrcRectConstraint);
                          SkCanvas::kFast_SrcRectConstraint);
    canvas->restore();
}

}  // namespace skiapipeline
+1 −1
Original line number Diff line number Diff line
@@ -1280,7 +1280,7 @@ RENDERTHREAD_TEST(BackdropFilterDrawable, drawing) {
    canvas->drawDrawable(&backdropDrawable);
    // the drawable is still visible, ok to draw.
    EXPECT_EQ(2, canvas->mDrawCounter);
    EXPECT_EQ(SkRect::MakeLTRB(0, 0, CANVAS_WIDTH - 30, CANVAS_HEIGHT - 30), canvas->mDstBounds);
    EXPECT_EQ(SkRect::MakeLTRB(30, 30, CANVAS_WIDTH, CANVAS_HEIGHT), canvas->mDstBounds);

    canvas->translate(CANVAS_WIDTH, CANVAS_HEIGHT);
    canvas->drawDrawable(&drawable);
+148 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 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.
  -->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="wowwowwowwowwowwowwowwowwowwowwowwowwowwowwow" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="I'm a little teapot" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="Something. Something." />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="/\\/\\/\\/\\/\\/\\/\\/\\/\\/" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="wowwowwowwowwowwowwowwowwowwowwowwowwowwowwow" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="I'm a little teapot" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="Something. Something." />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="/\\/\\/\\/\\/\\/\\/\\/\\/\\/" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:textSize="24dp"
            android:text="^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^.^" />

    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <View
                android:layout_width="match_parent"
                android:layout_height="300dp" />

            <com.android.test.silkfx.materials.BlurBehindContainer
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#33AAAAAA"
                android:padding="32dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="48dp"
                    android:text="Blur!" />

            </com.android.test.silkfx.materials.BlurBehindContainer>

            <View
                android:layout_width="match_parent"
                android:layout_height="1024dp" />

        </LinearLayout>

    </ScrollView>

</FrameLayout>
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -61,7 +61,8 @@ private val AllDemos = listOf(
        )),
        DemoGroup("Materials", listOf(
                Demo("Glass", GlassActivity::class),
                Demo("Background Blur", BackgroundBlurActivity::class)
                Demo("Background Blur", BackgroundBlurActivity::class),
                Demo("View blur behind", R.layout.view_blur_behind, commonControls = false)
        ))
)

+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.
 */
package com.android.test.silkfx.materials

import android.content.Context
import android.graphics.RenderEffect
import android.graphics.Shader
import android.util.AttributeSet
import android.widget.FrameLayout

class BlurBehindContainer(context: Context, attributeSet: AttributeSet) : FrameLayout(context, attributeSet) {
    override fun onFinishInflate() {
        super.onFinishInflate()
        setBackdropRenderEffect(
            RenderEffect.createBlurEffect(16.0f, 16.0f, Shader.TileMode.CLAMP))
    }
}
 No newline at end of file