1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <SkBlendMode.h> 18 19 #include "SkImageFilter.h" 20 #include "SkImageFilters.h" 21 #include "TestSceneBase.h" 22 #include "utils/Blur.h" 23 24 class BackdropBlurAnimation : public TestScene { 25 private: 26 std::unique_ptr<TestScene> listView; 27 28 public: BackdropBlurAnimation(const TestScene::Options & opts)29 explicit BackdropBlurAnimation(const TestScene::Options& opts) { 30 listView.reset(TestScene::testMap()["listview"].createScene(opts)); 31 } 32 createContent(int width,int height,Canvas & canvas)33 void createContent(int width, int height, Canvas& canvas) override { 34 sp<RenderNode> list = TestUtils::createNode( 35 0, 0, width, height, 36 [this, width, height](RenderProperties& props, Canvas& canvas) { 37 props.setClipToBounds(false); 38 listView->createContent(width, height, canvas); 39 }); 40 41 canvas.drawRenderNode(list.get()); 42 43 int x = width / 8; 44 int y = height / 4; 45 sp<RenderNode> blurNode = TestUtils::createNode( 46 x, y, width - x, height - y, [](RenderProperties& props, Canvas& canvas) { 47 props.mutableOutline().setRoundRect(0, 0, props.getWidth(), props.getHeight(), 48 dp(16), 1); 49 props.mutableOutline().setShouldClip(true); 50 sk_sp<SkImageFilter> blurFilter = SkImageFilters::Blur( 51 Blur::convertRadiusToSigma(dp(8)), Blur::convertRadiusToSigma(dp(8)), 52 SkTileMode::kClamp, nullptr, nullptr); 53 props.mutateLayerProperties().setBackdropImageFilter(blurFilter.get()); 54 canvas.drawColor(0x33000000, SkBlendMode::kSrcOver); 55 }); 56 57 canvas.drawRenderNode(blurNode.get()); 58 } 59 doFrame(int frameNr)60 void doFrame(int frameNr) override { listView->doFrame(frameNr); } 61 }; 62 63 static TestScene::Registrar _BackdropBlur(TestScene::Info{ 64 "backdropblur", "A rounded rect that does a blur-behind of a sky animation.", __anonfc4f780a0302(const TestScene::Options& opts) 65 [](const TestScene::Options& opts) -> test::TestScene* { 66 return new BackdropBlurAnimation(opts); 67 }}); 68