This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Do not involve external_view_embedder in submit frame process if threads are not merged. #22275
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1a9d81
Do not involve external_view_embedder in submit frame process if thre…
8fa56f3
link todo to issue
4a1e8f5
rasterizer tests
b357f74
ensure thread initlized
dbb7b63
reviews
ed75ac6
Merge branch 'master' into escape
ce7e971
merge mater
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
rasterizer tests
- Loading branch information
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,16 @@ | |
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #define FML_USED_ON_EMBEDDER | ||
|
|
||
| #include "flutter/shell/common/rasterizer.h" | ||
|
|
||
| #include "flutter/shell/common/thread_host.h" | ||
| #include "flutter/testing/testing.h" | ||
| #include "gmock/gmock.h" | ||
|
|
||
| using testing::_; | ||
| using testing::ByMove; | ||
| using testing::Return; | ||
| using testing::ReturnRef; | ||
|
|
||
|
|
@@ -92,7 +95,8 @@ TEST(RasterizerTest, drawEmptyPipeline) { | |
| latch.Wait(); | ||
| } | ||
|
|
||
| TEST(RasterizerTest, drawWithExternalViewEmbedder) { | ||
| TEST(RasterizerTest, | ||
| drawWithExternalViewEmbedder_ExternalViewEmbedderSubmitFrameCalled) { | ||
| std::string test_name = | ||
| ::testing::UnitTest::GetInstance()->current_test_info()->name(); | ||
| ThreadHost thread_host("io.flutter.test." + test_name + ".", | ||
|
|
@@ -111,11 +115,70 @@ TEST(RasterizerTest, drawWithExternalViewEmbedder) { | |
| MockExternalViewEmbedder external_view_embedder; | ||
| EXPECT_CALL(*surface, GetExternalViewEmbedder()) | ||
| .WillRepeatedly(Return(&external_view_embedder)); | ||
|
|
||
| auto surface_frame = std::make_unique<SurfaceFrame>( | ||
| nullptr, true, [](const SurfaceFrame&, SkCanvas*) { return true; }); | ||
| EXPECT_CALL(*surface, AcquireFrame(SkISize())) | ||
| .WillOnce(Return(ByMove(std::move(surface_frame)))); | ||
|
|
||
| EXPECT_CALL(external_view_embedder, | ||
| BeginFrame(SkISize(), nullptr, 2.0, | ||
| fml::RefPtr<fml::RasterThreadMerger>(nullptr))); | ||
| fml::RefPtr<fml::RasterThreadMerger>(nullptr))) | ||
| .Times(1); | ||
| EXPECT_CALL(external_view_embedder, SubmitFrame).Times(1); | ||
| EXPECT_CALL(external_view_embedder, | ||
| EndFrame(false, fml::RefPtr<fml::RasterThreadMerger>(nullptr))); | ||
| EndFrame(false, fml::RefPtr<fml::RasterThreadMerger>(nullptr))) | ||
| .Times(1); | ||
|
|
||
| rasterizer->Setup(std::move(surface)); | ||
| fml::AutoResetWaitableEvent latch; | ||
| thread_host.raster_thread->GetTaskRunner()->PostTask([&] { | ||
| auto pipeline = fml::AdoptRef(new Pipeline<LayerTree>(/*depth=*/10)); | ||
| auto layer_tree = std::make_unique<LayerTree>(/*frame_size=*/SkISize(), | ||
| /*device_pixel_ratio=*/2.0f); | ||
| bool result = pipeline->Produce().Complete(std::move(layer_tree)); | ||
| EXPECT_TRUE(result); | ||
| std::function<bool(LayerTree&)> no_discard = [](LayerTree&) { | ||
| return false; | ||
| }; | ||
| rasterizer->Draw(pipeline, no_discard); | ||
| latch.Signal(); | ||
| }); | ||
| latch.Wait(); | ||
| } | ||
|
|
||
| TEST( | ||
| RasterizerTest, | ||
| drawWithExternalViewEmbedderAndThreadMergerNotMerged_ExternalViewEmbedderSubmitFrameNotCalled) { | ||
| std::string test_name = | ||
| ::testing::UnitTest::GetInstance()->current_test_info()->name(); | ||
| ThreadHost thread_host("io.flutter.test." + test_name + ".", | ||
| ThreadHost::Type::Platform | ThreadHost::Type::GPU | | ||
| ThreadHost::Type::IO | ThreadHost::Type::UI); | ||
| TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(), | ||
| thread_host.raster_thread->GetTaskRunner(), | ||
| thread_host.ui_thread->GetTaskRunner(), | ||
| thread_host.io_thread->GetTaskRunner()); | ||
| MockDelegate delegate; | ||
| EXPECT_CALL(delegate, GetTaskRunners()) | ||
| .WillRepeatedly(ReturnRef(task_runners)); | ||
| EXPECT_CALL(delegate, OnFrameRasterized(_)); | ||
| auto rasterizer = std::make_unique<Rasterizer>(delegate); | ||
| auto surface = std::make_unique<MockSurface>(); | ||
| MockExternalViewEmbedder external_view_embedder; | ||
| EXPECT_CALL(*surface, GetExternalViewEmbedder()) | ||
| .WillRepeatedly(Return(&external_view_embedder)); | ||
| EXPECT_CALL(external_view_embedder, SupportsDynamicThreadMerging) | ||
| .WillRepeatedly(Return(true)); | ||
| auto surface_frame = std::make_unique<SurfaceFrame>( | ||
| nullptr, true, [](const SurfaceFrame&, SkCanvas*) { return true; }); | ||
| EXPECT_CALL(*surface, AcquireFrame(SkISize())) | ||
| .WillOnce(Return(ByMove(std::move(surface_frame)))); | ||
|
|
||
| EXPECT_CALL(external_view_embedder, BeginFrame).Times(1); | ||
| EXPECT_CALL(external_view_embedder, SubmitFrame).Times(0); | ||
| EXPECT_CALL(external_view_embedder, EndFrame).Times(1); | ||
|
|
||
| rasterizer->Setup(std::move(surface)); | ||
| fml::AutoResetWaitableEvent latch; | ||
| thread_host.raster_thread->GetTaskRunner()->PostTask([&] { | ||
|
|
@@ -132,4 +195,51 @@ TEST(RasterizerTest, drawWithExternalViewEmbedder) { | |
| }); | ||
| latch.Wait(); | ||
| } | ||
|
|
||
| TEST( | ||
| RasterizerTest, | ||
| drawWithExternalViewEmbedderAndThreadsMerged_ExternalViewEmbedderSubmitFrameCalled) { | ||
| std::string test_name = | ||
| ::testing::UnitTest::GetInstance()->current_test_info()->name(); | ||
| ThreadHost thread_host("io.flutter.test." + test_name + ".", | ||
| ThreadHost::Type::Platform | ThreadHost::Type::GPU | | ||
| ThreadHost::Type::IO | ThreadHost::Type::UI); | ||
| TaskRunners task_runners("test", | ||
| fml::MessageLoop::GetCurrent().GetTaskRunner(), | ||
| fml::MessageLoop::GetCurrent().GetTaskRunner(), | ||
| thread_host.ui_thread->GetTaskRunner(), | ||
| thread_host.io_thread->GetTaskRunner()); | ||
|
|
||
| MockDelegate delegate; | ||
| EXPECT_CALL(delegate, GetTaskRunners()) | ||
| .WillRepeatedly(ReturnRef(task_runners)); | ||
| EXPECT_CALL(delegate, OnFrameRasterized(_)); | ||
|
|
||
| auto rasterizer = std::make_unique<Rasterizer>(delegate); | ||
| auto surface = std::make_unique<MockSurface>(); | ||
|
|
||
| MockExternalViewEmbedder external_view_embedder; | ||
| EXPECT_CALL(*surface, GetExternalViewEmbedder()) | ||
| .WillRepeatedly(Return(&external_view_embedder)); | ||
| auto surface_frame = std::make_unique<SurfaceFrame>( | ||
| nullptr, true, [](const SurfaceFrame&, SkCanvas*) { return true; }); | ||
| EXPECT_CALL(*surface, AcquireFrame(SkISize())) | ||
| .WillOnce(Return(ByMove(std::move(surface_frame)))); | ||
| EXPECT_CALL(external_view_embedder, SupportsDynamicThreadMerging) | ||
| .WillRepeatedly(Return(true)); | ||
|
|
||
| EXPECT_CALL(external_view_embedder, BeginFrame).Times(1); | ||
| EXPECT_CALL(external_view_embedder, SubmitFrame).Times(1); | ||
| EXPECT_CALL(external_view_embedder, EndFrame).Times(1); | ||
|
||
|
|
||
| rasterizer->Setup(std::move(surface)); | ||
|
|
||
| auto pipeline = fml::AdoptRef(new Pipeline<LayerTree>(/*depth=*/10)); | ||
| auto layer_tree = std::make_unique<LayerTree>(/*frame_size=*/SkISize(), | ||
| /*device_pixel_ratio=*/2.0f); | ||
| bool result = pipeline->Produce().Complete(std::move(layer_tree)); | ||
| EXPECT_TRUE(result); | ||
| std::function<bool(LayerTree&)> no_discard = [](LayerTree&) { return false; }; | ||
|
||
| rasterizer->Draw(pipeline, no_discard); | ||
| } | ||
| } // namespace flutter | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add parameter name comments for parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done