backdrop_filter_layer only pushes to the leaf_nodes_canvas (flutter/engine#28500)

This commit is contained in:
Chris Yang
2021-09-27 11:33:01 -07:00
committed by GitHub
parent 00ca12c712
commit c9f351741d
16 changed files with 408 additions and 34 deletions

View File

@@ -165,6 +165,7 @@ if (enable_unittests) {
"raster_cache_unittests.cc",
"rtree_unittests.cc",
"skia_gpu_object_unittests.cc",
"testing/auto_save_layer_unittests.cc",
"testing/mock_layer_unittests.cc",
"testing/mock_texture_unittests.cc",
"texture_unittests.cc",

View File

@@ -62,7 +62,10 @@ void BackdropFilterLayer::Paint(PaintContext& context) const {
paint.setBlendMode(blend_mode_);
Layer::AutoSaveLayer save = Layer::AutoSaveLayer::Create(
context,
SkCanvas::SaveLayerRec{&paint_bounds(), &paint, filter_.get(), 0});
SkCanvas::SaveLayerRec{&paint_bounds(), &paint, filter_.get(), 0},
// BackdropFilter should only happen on the leaf nodes canvas.
// See https:://flutter.dev/go/backdrop-filter-with-overlay-canvas
AutoSaveLayer::SaveMode::kLeafNodesCanvas);
PaintChildren(context);
}

View File

@@ -58,35 +58,47 @@ Layer::AutoPrerollSaveLayerState::~AutoPrerollSaveLayerState() {
Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context,
const SkRect& bounds,
const SkPaint* paint)
: paint_context_(paint_context), bounds_(bounds) {
paint_context_.internal_nodes_canvas->saveLayer(bounds_, paint);
const SkPaint* paint,
SaveMode save_mode)
: paint_context_(paint_context),
bounds_(bounds),
canvas_(save_mode == SaveMode::kInternalNodesCanvas
? *(paint_context.internal_nodes_canvas)
: *(paint_context.leaf_nodes_canvas)) {
canvas_.saveLayer(bounds_, paint);
}
Layer::AutoSaveLayer::AutoSaveLayer(const PaintContext& paint_context,
const SkCanvas::SaveLayerRec& layer_rec)
: paint_context_(paint_context), bounds_(*layer_rec.fBounds) {
paint_context_.internal_nodes_canvas->saveLayer(layer_rec);
const SkCanvas::SaveLayerRec& layer_rec,
SaveMode save_mode)
: paint_context_(paint_context),
bounds_(*layer_rec.fBounds),
canvas_(save_mode == SaveMode::kInternalNodesCanvas
? *(paint_context.internal_nodes_canvas)
: *(paint_context.leaf_nodes_canvas)) {
canvas_.saveLayer(layer_rec);
}
Layer::AutoSaveLayer Layer::AutoSaveLayer::Create(
const PaintContext& paint_context,
const SkRect& bounds,
const SkPaint* paint) {
return Layer::AutoSaveLayer(paint_context, bounds, paint);
const SkPaint* paint,
SaveMode save_mode) {
return Layer::AutoSaveLayer(paint_context, bounds, paint, save_mode);
}
Layer::AutoSaveLayer Layer::AutoSaveLayer::Create(
const PaintContext& paint_context,
const SkCanvas::SaveLayerRec& layer_rec) {
return Layer::AutoSaveLayer(paint_context, layer_rec);
const SkCanvas::SaveLayerRec& layer_rec,
SaveMode save_mode) {
return Layer::AutoSaveLayer(paint_context, layer_rec, save_mode);
}
Layer::AutoSaveLayer::~AutoSaveLayer() {
if (paint_context_.checkerboard_offscreen_layers) {
DrawCheckerboard(paint_context_.internal_nodes_canvas, bounds_);
DrawCheckerboard(&canvas_, bounds_);
}
paint_context_.internal_nodes_canvas->restore();
canvas_.restore();
}
} // namespace flutter

View File

@@ -157,26 +157,60 @@ class Layer {
// draws a checkerboard over the layer if that is enabled in the PaintContext.
class AutoSaveLayer {
public:
[[nodiscard]] static AutoSaveLayer Create(const PaintContext& paint_context,
const SkRect& bounds,
const SkPaint* paint);
// Indicates which canvas the layer should be saved on.
//
// Usually layers are saved on the internal_nodes_canvas, so that all
// the canvas keep track of the current state of the layer tree.
// In some special cases, layers should only save on the leaf_nodes_canvas,
// See https:://flutter.dev/go/backdrop-filter-with-overlay-canvas for why
// it is the case for Backdrop filter layer.
enum SaveMode {
// The layer is saved on the internal_nodes_canvas.
kInternalNodesCanvas,
// The layer is saved on the leaf_nodes_canvas.
kLeafNodesCanvas
};
// Create a layer and save it on the canvas.
//
// The layer is restored from the canvas in destructor.
//
// By default, the layer is saved on and restored from
// `internal_nodes_canvas`. The `save_mode` parameter can be modified to
// save the layer on other canvases.
[[nodiscard]] static AutoSaveLayer Create(
const PaintContext& paint_context,
const SkCanvas::SaveLayerRec& layer_rec);
const SkRect& bounds,
const SkPaint* paint,
SaveMode save_mode = SaveMode::kInternalNodesCanvas);
// Create a layer and save it on the canvas.
//
// The layer is restored from the canvas in destructor.
//
// By default, the layer is saved on and restored from
// `internal_nodes_canvas`. The `save_mode` parameter can be modified to
// save the layer on other canvases.
[[nodiscard]] static AutoSaveLayer Create(
const PaintContext& paint_context,
const SkCanvas::SaveLayerRec& layer_rec,
SaveMode save_mode = SaveMode::kInternalNodesCanvas);
~AutoSaveLayer();
private:
AutoSaveLayer(const PaintContext& paint_context,
const SkRect& bounds,
const SkPaint* paint);
const SkPaint* paint,
SaveMode save_mode = SaveMode::kInternalNodesCanvas);
AutoSaveLayer(const PaintContext& paint_context,
const SkCanvas::SaveLayerRec& layer_rec);
const SkCanvas::SaveLayerRec& layer_rec,
SaveMode save_mode = SaveMode::kInternalNodesCanvas);
const PaintContext& paint_context_;
const SkRect bounds_;
// The canvas that this layer is saved on and popped from.
SkCanvas& canvas_;
};
virtual void Paint(PaintContext& context) const = 0;

View File

@@ -0,0 +1,117 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/flow/testing/layer_test.h"
#include "gtest/gtest.h"
namespace flutter {
namespace testing {
using AutoSaveLayerTests = LayerTest;
TEST_F(AutoSaveLayerTests, SaveLayerOnInternalNodesCanvasByDefault) {
// For:
// static AutoSaveLayer Create(const PaintContext& paint_context,
// const SkRect& bounds,
// const SkPaint* paint,
// SaveMode save_mode);
{
int saved_count_before =
paint_context().internal_nodes_canvas->getSaveCount();
{
const SkPaint paint;
const SkRect rect = SkRect::MakeEmpty();
Layer::AutoSaveLayer save =
Layer::AutoSaveLayer::Create(paint_context(), rect, &paint);
EXPECT_EQ(paint_context().internal_nodes_canvas->getSaveCount(),
saved_count_before + 1);
EXPECT_EQ(paint_context().leaf_nodes_canvas->getSaveCount(),
saved_count_before + 1);
}
EXPECT_EQ(paint_context().internal_nodes_canvas->getSaveCount(),
saved_count_before);
EXPECT_EQ(paint_context().leaf_nodes_canvas->getSaveCount(),
saved_count_before);
}
// For:
// static AutoSaveLayer Create(const PaintContext& paint_context,
// const SkCanvas::SaveLayerRec& layer_rec,
// SaveMode save_mode);
{
int saved_count_before =
paint_context().internal_nodes_canvas->getSaveCount();
{
const SkPaint paint;
const SkRect rect = SkRect::MakeEmpty();
const SkCanvas::SaveLayerRec save_layer_rect =
SkCanvas::SaveLayerRec{&rect, &paint, nullptr, 0};
Layer::AutoSaveLayer save =
Layer::AutoSaveLayer::Create(paint_context(), save_layer_rect);
EXPECT_EQ(paint_context().internal_nodes_canvas->getSaveCount(),
saved_count_before + 1);
EXPECT_EQ(paint_context().leaf_nodes_canvas->getSaveCount(),
saved_count_before + 1);
}
EXPECT_EQ(paint_context().internal_nodes_canvas->getSaveCount(),
saved_count_before);
EXPECT_EQ(paint_context().leaf_nodes_canvas->getSaveCount(),
saved_count_before);
}
}
TEST_F(AutoSaveLayerTests, SaveLayerOnlyOnLeafNodesCanvas) {
// For:
// static AutoSaveLayer Create(const PaintContext& paint_context,
// const SkRect& bounds,
// const SkPaint* paint,
// SaveMode save_mode);
{
int saved_count_before =
paint_context().internal_nodes_canvas->getSaveCount();
{
const SkPaint paint;
const SkRect rect = SkRect::MakeEmpty();
Layer::AutoSaveLayer save = Layer::AutoSaveLayer::Create(
paint_context(), rect, &paint,
Layer::AutoSaveLayer::SaveMode::kLeafNodesCanvas);
EXPECT_EQ(paint_context().internal_nodes_canvas->getSaveCount(),
saved_count_before);
EXPECT_EQ(paint_context().leaf_nodes_canvas->getSaveCount(),
saved_count_before + 1);
}
EXPECT_EQ(paint_context().internal_nodes_canvas->getSaveCount(),
saved_count_before);
EXPECT_EQ(paint_context().leaf_nodes_canvas->getSaveCount(),
saved_count_before);
}
// For:
// static AutoSaveLayer Create(const PaintContext& paint_context,
// const SkCanvas::SaveLayerRec& layer_rec,
// SaveMode save_mode);
{
int saved_count_before =
paint_context().internal_nodes_canvas->getSaveCount();
{
const SkPaint paint;
const SkRect rect = SkRect::MakeEmpty();
const SkCanvas::SaveLayerRec save_layer_rect =
SkCanvas::SaveLayerRec{&rect, &paint, nullptr, 0};
Layer::AutoSaveLayer save = Layer::AutoSaveLayer::Create(
paint_context(), save_layer_rect,
Layer::AutoSaveLayer::SaveMode::kLeafNodesCanvas);
EXPECT_EQ(paint_context().internal_nodes_canvas->getSaveCount(),
saved_count_before);
EXPECT_EQ(paint_context().leaf_nodes_canvas->getSaveCount(),
saved_count_before + 1);
}
EXPECT_EQ(paint_context().internal_nodes_canvas->getSaveCount(),
saved_count_before);
EXPECT_EQ(paint_context().leaf_nodes_canvas->getSaveCount(),
saved_count_before);
}
}
} // namespace testing
} // namespace flutter

View File

@@ -69,5 +69,14 @@ TEST_F(MockLayerTest, FakePlatformView) {
EXPECT_EQ(preroll_context()->has_platform_view, true);
}
TEST_F(MockLayerTest, SaveLayerOnLeafNodesCanvas) {
auto layer = std::make_shared<MockLayer>(SkPath(), SkPaint(),
true /* fake_has_platform_view */);
EXPECT_EQ(preroll_context()->has_platform_view, false);
layer->Preroll(preroll_context(), SkMatrix());
EXPECT_EQ(preroll_context()->has_platform_view, true);
}
} // namespace testing
} // namespace flutter

View File

@@ -422,7 +422,6 @@ void FlutterPlatformViewsController::CompositeWithParams(int view_id,
SkCanvas* FlutterPlatformViewsController::CompositeEmbeddedView(int view_id) {
// Any UIKit related code has to run on main thread.
FML_DCHECK([[NSThread currentThread] isMainThread]);
// Do nothing if the view doesn't need to be composited.
if (views_to_recomposite_.count(view_id) == 0) {
return picture_recorders_[view_id]->getRecordingCanvas();

View File

@@ -16,22 +16,22 @@
0AC83146256E534E00DAE6BE /* golden_bogus_font_text_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 0AC83145256E534E00DAE6BE /* golden_bogus_font_text_iPhone 8_simulator.png */; };
0D14A3FE239743190013D873 /* golden_platform_view_rotate_iPhone SE_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 0D14A3FD239743190013D873 /* golden_platform_view_rotate_iPhone SE_simulator.png */; };
0D8470A4240F0B1F0030B565 /* StatusBarTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D8470A3240F0B1F0030B565 /* StatusBarTest.m */; };
0DB781EF22E931BE00E9B371 /* Flutter.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0DB781F122E933E800E9B371 /* Flutter.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0DB781FE22EA2C6D00E9B371 /* Flutter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.xcframework */; };
0DB781FF22EA2C7200E9B371 /* Flutter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.xcframework */; };
0DB781EF22E931BE00E9B371 /* ../../Flutter.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0DB781F122E933E800E9B371 /* ../../Flutter.xcframework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0DB781FE22EA2C6D00E9B371 /* ../../Flutter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */; };
0DB781FF22EA2C7200E9B371 /* ../../Flutter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */; };
0DB7820022EA2C9D00E9B371 /* App.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4122E3B5F700073EBF /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0DB7820122EA2CA500E9B371 /* App.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 246B4E4122E3B5F700073EBF /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */; };
0DDEBC89258830B40065D0E8 /* SpawnEngineTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DDEBC88258830B40065D0E8 /* SpawnEngineTest.m */; };
0DDEBC8B258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 0DDEBC8A258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png */; };
0EE8986D2609D05E0061D5E5 /* golden_non_full_screen_flutter_view_platform_view_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 0EE8986C2609D05E0061D5E5 /* golden_non_full_screen_flutter_view_platform_view_iPhone 8_simulator.png */; };
242F37A222E636DE001E83D4 /* Flutter.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
242F37A222E636DE001E83D4 /* ../../Flutter.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
242F37A322E636DE001E83D4 /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4122E3B5F700073EBF /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
244EA6D0230DBE8900B2D26E /* golden_platform_view_D21AP.png in Resources */ = {isa = PBXBuildFile; fileRef = 244EA6CF230DBE8900B2D26E /* golden_platform_view_D21AP.png */; };
246A6611252E693A00EAB0F3 /* RenderingSelectionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 246A6610252E693A00EAB0F3 /* RenderingSelectionTest.m */; };
246B4E4222E3B5F700073EBF /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4122E3B5F700073EBF /* App.framework */; };
246B4E4622E3B61000073EBF /* Flutter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* Flutter.xcframework */; };
246B4E4622E3B61000073EBF /* ../../Flutter.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */; };
248D76CC22E388370012F0C1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76CB22E388370012F0C1 /* AppDelegate.m */; };
248D76D422E388380012F0C1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 248D76D322E388380012F0C1 /* Assets.xcassets */; };
248D76DA22E388380012F0C1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 248D76D922E388380012F0C1 /* main.m */; };
@@ -54,7 +54,9 @@
6816DB9E231750ED00A51400 /* GoldenPlatformViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6816DB9D231750ED00A51400 /* GoldenPlatformViewTests.m */; };
6816DBA12317573300A51400 /* GoldenImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 6816DBA02317573300A51400 /* GoldenImage.m */; };
6816DBA42318358200A51400 /* GoldenTestManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 6816DBA32318358200A51400 /* GoldenTestManager.m */; };
682BD8B526E93C2500FA6697 /* golden_platform_view_with_other_backdrop_filter_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 682BD8B426E93C2500FA6697 /* golden_platform_view_with_other_backdrop_filter_iPhone 8_simulator.png */; };
68A5B63423EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 68A5B63323EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m */; };
68C03C4826FCF02A00D4700A /* golden_two_platform_views_with_other_backdrop_filter_iPhone 8_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 68C03C4726FCF02A00D4700A /* golden_two_platform_views_with_other_backdrop_filter_iPhone 8_simulator.png */; };
68D4017D2564859300ECD91A /* ContinuousTexture.m in Sources */ = {isa = PBXBuildFile; fileRef = 68D4017C2564859300ECD91A /* ContinuousTexture.m */; };
F26F15B8268B6B5600EC54D3 /* iPadGestureTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F26F15B7268B6B5500EC54D3 /* iPadGestureTests.m */; };
/* End PBXBuildFile section */
@@ -83,7 +85,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
0DB781EF22E931BE00E9B371 /* Flutter.xcframework in CopyFiles */,
0DB781EF22E931BE00E9B371 /* ../../Flutter.xcframework in CopyFiles */,
0DB7820122EA2CA500E9B371 /* App.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -94,7 +96,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
0DB781F122E933E800E9B371 /* Flutter.xcframework in CopyFiles */,
0DB781F122E933E800E9B371 /* ../../Flutter.xcframework in CopyFiles */,
0DB7820022EA2C9D00E9B371 /* App.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -105,7 +107,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
242F37A222E636DE001E83D4 /* Flutter.xcframework in Embed Frameworks */,
242F37A222E636DE001E83D4 /* ../../Flutter.xcframework in Embed Frameworks */,
242F37A322E636DE001E83D4 /* App.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
@@ -135,7 +137,7 @@
244EA6CF230DBE8900B2D26E /* golden_platform_view_D21AP.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = golden_platform_view_D21AP.png; sourceTree = "<group>"; };
246A6610252E693A00EAB0F3 /* RenderingSelectionTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RenderingSelectionTest.m; sourceTree = "<group>"; };
246B4E4122E3B5F700073EBF /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = App.framework; sourceTree = "<group>"; };
246B4E4522E3B61000073EBF /* Flutter.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = ../../Flutter.xcframework; sourceTree = "<group>"; };
246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = ../../Flutter.xcframework; sourceTree = "<group>"; };
248D76C722E388370012F0C1 /* Scenarios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Scenarios.app; sourceTree = BUILT_PRODUCTS_DIR; };
248D76CA22E388370012F0C1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
248D76CB22E388370012F0C1 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -170,7 +172,9 @@
6816DBA02317573300A51400 /* GoldenImage.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GoldenImage.m; sourceTree = "<group>"; };
6816DBA22318358200A51400 /* GoldenTestManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GoldenTestManager.h; sourceTree = "<group>"; };
6816DBA32318358200A51400 /* GoldenTestManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GoldenTestManager.m; sourceTree = "<group>"; };
682BD8B426E93C2500FA6697 /* golden_platform_view_with_other_backdrop_filter_iPhone 8_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_platform_view_with_other_backdrop_filter_iPhone 8_simulator.png"; sourceTree = "<group>"; };
68A5B63323EB71D300BDBCDB /* PlatformViewGestureRecognizerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PlatformViewGestureRecognizerTests.m; sourceTree = "<group>"; };
68C03C4726FCF02A00D4700A /* golden_two_platform_views_with_other_backdrop_filter_iPhone 8_simulator.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "golden_two_platform_views_with_other_backdrop_filter_iPhone 8_simulator.png"; sourceTree = "<group>"; };
68D4017B2564859300ECD91A /* ContinuousTexture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContinuousTexture.h; sourceTree = "<group>"; };
68D4017C2564859300ECD91A /* ContinuousTexture.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ContinuousTexture.m; sourceTree = "<group>"; };
F26F15B7268B6B5500EC54D3 /* iPadGestureTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = iPadGestureTests.m; sourceTree = "<group>"; };
@@ -182,7 +186,7 @@
buildActionMask = 2147483647;
files = (
246B4E4222E3B5F700073EBF /* App.framework in Frameworks */,
246B4E4622E3B61000073EBF /* Flutter.xcframework in Frameworks */,
246B4E4622E3B61000073EBF /* ../../Flutter.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -190,7 +194,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0DB781FF22EA2C7200E9B371 /* Flutter.xcframework in Frameworks */,
0DB781FF22EA2C7200E9B371 /* ../../Flutter.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -198,7 +202,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0DB781FE22EA2C6D00E9B371 /* Flutter.xcframework in Frameworks */,
0DB781FE22EA2C6D00E9B371 /* ../../Flutter.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -261,9 +265,11 @@
248D76ED22E388380012F0C1 /* ScenariosUITests */ = {
isa = PBXGroup;
children = (
68C03C4726FCF02A00D4700A /* golden_two_platform_views_with_other_backdrop_filter_iPhone 8_simulator.png */,
0DDEBC8A258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png */,
4F06F1B124731F66000AF246 /* LocalizationInitializationTest.m */,
6402EBD024147BDA00987DCB /* UnobstructedPlatformViewTests.m */,
682BD8B426E93C2500FA6697 /* golden_platform_view_with_other_backdrop_filter_iPhone 8_simulator.png */,
0AC83145256E534E00DAE6BE /* golden_bogus_font_text_iPhone 8_simulator.png */,
0D14A3FD239743190013D873 /* golden_platform_view_rotate_iPhone SE_simulator.png */,
3DE09E8B23C010BC006C9851 /* golden_platform_view_clippath_iPhone 8_simulator.png */,
@@ -305,7 +311,7 @@
248D76FC22E388900012F0C1 /* Frameworks */ = {
isa = PBXGroup;
children = (
246B4E4522E3B61000073EBF /* Flutter.xcframework */,
246B4E4522E3B61000073EBF /* ../../Flutter.xcframework */,
246B4E4122E3B5F700073EBF /* App.framework */,
);
name = Frameworks;
@@ -437,6 +443,7 @@
files = (
3DEF491623C3BE6500184216 /* golden_platform_view_multiple_background_foreground_iPhone 8_simulator.png in Resources */,
3DEF491323C3BE6500184216 /* golden_platform_view_cliprect_iPhone 8_simulator.png in Resources */,
682BD8B526E93C2500FA6697 /* golden_platform_view_with_other_backdrop_filter_iPhone 8_simulator.png in Resources */,
3DEF491523C3BE6500184216 /* golden_platform_view_iPhone 8_simulator.png in Resources */,
0D14A3FE239743190013D873 /* golden_platform_view_rotate_iPhone SE_simulator.png in Resources */,
3DEF491823C3BE6500184216 /* golden_platform_view_opacity_iPhone 8_simulator.png in Resources */,
@@ -446,6 +453,7 @@
3DEF491223C3BE6500184216 /* golden_platform_view_clippath_iPhone 8_simulator.png in Resources */,
3DEF491423C3BE6500184216 /* golden_platform_view_cliprrect_iPhone 8_simulator.png in Resources */,
59A97FDA236B984300B4C066 /* golden_platform_view_multiple_background_foreground_iPhone SE_simulator.png in Resources */,
68C03C4826FCF02A00D4700A /* golden_two_platform_views_with_other_backdrop_filter_iPhone 8_simulator.png in Resources */,
3DEF491923C3BE6500184216 /* golden_platform_view_rotate_iPhone 8_simulator.png in Resources */,
24D47D1B230C79840069DD5E /* golden_platform_view_D211AP.png in Resources */,
0DDEBC8B258839760065D0E8 /* golden_spawn_engine_works_iPhone 8_simulator.png in Resources */,

View File

@@ -46,6 +46,9 @@
@"--platform-view-clippath" : @"platform_view_clippath",
@"--platform-view-transform" : @"platform_view_transform",
@"--platform-view-opacity" : @"platform_view_opacity",
@"--platform-view-with-other-backdrop-filter" : @"platform_view_with_other_backdrop_filter",
@"--two-platform-views-with-other-backdrop-filter" :
@"two_platform_views_with_other_backdrop_filter",
@"--platform-view-rotate" : @"platform_view_rotate",
@"--non-full-screen-flutter-view-platform-view" : @"non_full_screen_flutter_view_platform_view",
@"--gesture-reject-after-touches-ended" : @"platform_view_gesture_reject_after_touches_ended",

View File

@@ -32,6 +32,9 @@ NSDictionary* launchArgsMap;
@"--platform-view-clippath" : @"platform_view_clippath",
@"--platform-view-transform" : @"platform_view_transform",
@"--platform-view-opacity" : @"platform_view_opacity",
@"--platform-view-with-other-backdrop-filter" : @"platform_view_with_other_backdrop_filter",
@"--two-platform-views-with-other-backdrop-filter" :
@"two_platform_views_with_other_backdrop_filter",
@"--platform-view-rotate" : @"platform_view_rotate",
@"--non-full-screen-flutter-view-platform-view" :
@"non_full_screen_flutter_view_platform_view",

View File

@@ -170,6 +170,42 @@ static const NSInteger kSecondsToWaitForPlatformView = 30;
@end
@interface PlatformViewWithOtherBackdropFilterTests : GoldenPlatformViewTests
@end
@implementation PlatformViewWithOtherBackdropFilterTests
- (instancetype)initWithInvocation:(NSInvocation*)invocation {
GoldenTestManager* manager =
[[GoldenTestManager alloc] initWithLaunchArg:@"--platform-view-with-other-backdrop-filter"];
return [super initWithManager:manager invocation:invocation];
}
- (void)testPlatformView {
[self checkPlatformViewGolden];
}
@end
@interface TwoPlatformViewsWithOtherBackDropFilterTests : GoldenPlatformViewTests
@end
@implementation TwoPlatformViewsWithOtherBackDropFilterTests
- (instancetype)initWithInvocation:(NSInvocation*)invocation {
GoldenTestManager* manager = [[GoldenTestManager alloc]
initWithLaunchArg:@"--two-platform-views-with-other-backdrop-filter"];
return [super initWithManager:manager invocation:invocation];
}
- (void)testPlatformView {
[self checkPlatformViewGolden];
}
@end
@interface PlatformViewRotation : GoldenPlatformViewTests
@end

View File

@@ -11,6 +11,7 @@ import 'dart:ui';
import 'src/scenarios.dart';
void main() {
assert(window.locale != null);
window

View File

@@ -619,6 +619,152 @@ class PlatformViewWithContinuousTexture extends PlatformViewScenario {
}
}
/// A simple platform view for testing backDropFilter with a platform view in the scene.
///
/// The stack would look like: picture 1-> filter -> picture 2 -> pv -> picture 3. And picture 1 should be filtered.
///
/// Note it is not testing applying backDropFilter on a platform view.
/// See: https://github.com/flutter/flutter/issues/80766
class PlatformViewWithOtherBackDropFilter extends PlatformViewScenario {
/// Constructs the scenario.
PlatformViewWithOtherBackDropFilter(PlatformDispatcher dispatcher, String text, { int id = 0 })
: super(dispatcher, text, id: id);
@override
void onBeginFrame(Duration duration) {
final SceneBuilder builder = SceneBuilder();
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
// This is just a background picture to make the result more viewable.
canvas.drawRect(
const Rect.fromLTRB(0, 0, 500, 400),
Paint()..color = const Color(0xFFFF0000),
);
// This rect should look blur due to the backdrop filter.
canvas.drawRect(
const Rect.fromLTRB(0, 0, 300, 300),
Paint()..color = const Color(0xFF00FF00),
);
final Picture picture = recorder.endRecording();
builder.addPicture(const Offset(0, 0), picture);
final ImageFilter filter = ImageFilter.blur(sigmaX: 8, sigmaY: 8);
builder.pushBackdropFilter(filter);
final PictureRecorder recorder2 = PictureRecorder();
final Canvas canvas2 = Canvas(recorder2);
// This circle should not look blur.
canvas2.drawCircle(
const Offset(200, 100),
50,
Paint()..color = const Color(0xFF0000EF),
);
final Picture picture2 = recorder2.endRecording();
builder.addPicture(const Offset(100, 100), picture2);
builder.pop();
builder.pushOffset(0, 600);
_addPlatformViewToScene(builder, id, 500, 500);
builder.pop();
final PictureRecorder recorder3 = PictureRecorder();
final Canvas canvas3 = Canvas(recorder3);
// Add another picture layer so an overlay UIView is created, which was
// the root cause of the original issue.
canvas3.drawCircle(
const Offset(300, 200),
50,
Paint()..color = const Color(0xFF0000EF),
);
final Picture picture3 = recorder3.endRecording();
builder.addPicture(const Offset(100, 100), picture3);
final Scene scene = builder.build();
window.render(scene);
scene.dispose();
}
}
/// A simple platform view for testing backDropFilter with a platform view in the scene.
///
/// The stack would look like: picture 1 -> pv1 -> picture 2 -> filter -> pv2 - > picture 3.
/// Because backdrop filter on platform views has not been implemented(see: https://github.com/flutter/flutter/issues/43902),
/// the result will not including a filtered pv1.
class TwoPlatformViewsWithOtherBackDropFilter extends Scenario with _BasePlatformViewScenarioMixin {
/// Constructs the scenario.
TwoPlatformViewsWithOtherBackDropFilter(PlatformDispatcher dispatcher, {required int firstId, required int secondId})
: _firstId = firstId,
_secondId = secondId,
super(dispatcher) {
createPlatformView(dispatcher, 'platform view 1', firstId);
createPlatformView(dispatcher, 'platform view 2', secondId);
}
final int _firstId;
final int _secondId;
@override
void onBeginFrame(Duration duration) {
final SceneBuilder builder = SceneBuilder();
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
// This is just a background picture to make the result more viewable.
canvas.drawRect(
const Rect.fromLTRB(0, 0, 600, 1000),
Paint()..color = const Color(0xFFFF0000),
);
// This rect should look blur due to the backdrop filter.
canvas.drawRect(
const Rect.fromLTRB(0, 0, 300, 300),
Paint()..color = const Color(0xFF00FF00),
);
final Picture picture1 = recorder.endRecording();
builder.addPicture(const Offset(0, 0), picture1);
builder.pushOffset(0, 200);
_addPlatformViewToScene(builder, _firstId, 100, 100);
final PictureRecorder recorder2 = PictureRecorder();
final Canvas canvas2 = Canvas(recorder2);
// This circle should look blur due to the backdrop filter.
canvas2.drawCircle(
const Offset(200, 100),
50,
Paint()..color = const Color(0xFF0000EF),
);
final Picture picture2 = recorder2.endRecording();
builder.addPicture(const Offset(100, 100), picture2);
final ImageFilter filter = ImageFilter.blur(sigmaX: 8, sigmaY: 8);
builder.pushBackdropFilter(filter);
builder.pushOffset(0, 600);
_addPlatformViewToScene(builder, _secondId, 500, 500);
builder.pop();
builder.pop();
final PictureRecorder recorder3 = PictureRecorder();
final Canvas canvas3 = Canvas(recorder3);
// Add another picture layer so an overlay UIView is created, which was
// the root cause of the original issue.
canvas3.drawCircle(
const Offset(300, 200),
50,
Paint()..color = const Color(0xFF0000EF),
);
final Picture picture3 = recorder3.endRecording();
builder.addPicture(const Offset(100, 100), picture3);
final Scene scene = builder.build();
window.render(scene);
scene.dispose();
}
}
mixin _BasePlatformViewScenarioMixin on Scenario {
int? _textureId;

View File

@@ -33,6 +33,8 @@ Map<String, ScenarioFactory> _scenarios = <String, ScenarioFactory>{
'platform_view_clippath': () => PlatformViewClipPathScenario(PlatformDispatcher.instance, 'PlatformViewClipPath', id: _viewId++),
'platform_view_transform': () => PlatformViewTransformScenario(PlatformDispatcher.instance, 'PlatformViewTransform', id: _viewId++),
'platform_view_opacity': () => PlatformViewOpacityScenario(PlatformDispatcher.instance, 'PlatformViewOpacity', id: _viewId++),
'platform_view_with_other_backdrop_filter': () => PlatformViewWithOtherBackDropFilter(PlatformDispatcher.instance, 'PlatformViewWithOtherBackDropFilter', id: _viewId++),
'two_platform_views_with_other_backdrop_filter': () => TwoPlatformViewsWithOtherBackDropFilter(PlatformDispatcher.instance, firstId: _viewId++, secondId: _viewId++),
'platform_view_multiple': () => MultiPlatformViewScenario(PlatformDispatcher.instance, firstId: 6, secondId: _viewId++),
'platform_view_multiple_background_foreground': () => MultiPlatformViewBackgroundForegroundScenario(PlatformDispatcher.instance, firstId: _viewId++, secondId: _viewId++),
'non_full_screen_flutter_view_platform_view': () => NonFullScreenFlutterViewPlatformViewScenario(PlatformDispatcher.instance, 'Hello from Scenarios (Platform View)', id: _viewId++),