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
Ensure we use the base CompositorContext's AcquireFrame method when screenshotting #13934
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6007ec3
Ensure we use the base CompositorContext's AcquireFrame method when
54df916
Review updates
ca3df5a
Revert "Review updates"
d7420f8
Use test fixtures
18594cc
review updates
03e94d5
formatting
88216cc
review update
4ceef76
formatting
fd5c031
update licence file
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #include <memory> | ||
|
|
||
| #include "flutter/flow/layers/layer_tree.h" | ||
| #include "flutter/flow/layers/picture_layer.h" | ||
| #include "flutter/flow/layers/transform_layer.h" | ||
| #include "flutter/fml/command_line.h" | ||
| #include "flutter/fml/make_copyable.h" | ||
|
|
@@ -952,5 +953,66 @@ TEST_F(ShellTest, IsolateCanAccessPersistentIsolateData) { | |
| DestroyShell(std::move(shell), std::move(task_runners)); | ||
| } | ||
|
|
||
| TEST_F(ShellTest, Screenshot) { | ||
gw280 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| auto settings = CreateSettingsForFixture(); | ||
| fml::AutoResetWaitableEvent firstFrameLatch; | ||
| settings.frame_rasterized_callback = | ||
| [&firstFrameLatch](const FrameTiming& t) { firstFrameLatch.Signal(); }; | ||
|
|
||
| std::unique_ptr<Shell> shell = CreateShell(settings); | ||
|
|
||
| // Create the surface needed by rasterizer | ||
| PlatformViewNotifyCreated(shell.get()); | ||
|
|
||
| auto configuration = RunConfiguration::InferFromSettings(settings); | ||
| configuration.SetEntrypoint("emptyMain"); | ||
|
|
||
| RunEngine(shell.get(), std::move(configuration)); | ||
|
|
||
| LayerTreeBuilder builder = [&](std::shared_ptr<ContainerLayer> root) { | ||
| SkPictureRecorder recorder; | ||
| SkCanvas* recording_canvas = | ||
| recorder.beginRecording(SkRect::MakeXYWH(0, 0, 80, 80)); | ||
| recording_canvas->drawRect(SkRect::MakeXYWH(0, 0, 80, 80), | ||
| SkPaint(SkColor4f::FromColor(SK_ColorRED))); | ||
| auto sk_picture = recorder.finishRecordingAsPicture(); | ||
| fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>( | ||
| this->GetCurrentTaskRunner(), fml::TimeDelta::FromSeconds(0)); | ||
| auto picture_layer = std::make_shared<PictureLayer>( | ||
| SkPoint::Make(10, 10), | ||
| flutter::SkiaGPUObject<SkPicture>({sk_picture, queue}), false, false); | ||
| root->Add(picture_layer); | ||
| }; | ||
|
|
||
| PumpOneFrame(shell.get(), 100, 100, builder); | ||
| firstFrameLatch.Wait(); | ||
|
|
||
| std::promise<Rasterizer::Screenshot> screenshot_promise; | ||
| auto screenshot_future = screenshot_promise.get_future(); | ||
|
Comment on lines
+990
to
+991
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, i've never used promises in C++. This is a good use! |
||
|
|
||
| fml::TaskRunner::RunNowOrPostTask( | ||
| shell->GetTaskRunners().GetGPUTaskRunner(), | ||
| [&screenshot_promise, &shell]() { | ||
| auto rasterizer = shell->GetRasterizer(); | ||
| screenshot_promise.set_value(rasterizer->ScreenshotLastLayerTree( | ||
| Rasterizer::ScreenshotType::CompressedImage, false)); | ||
| }); | ||
|
|
||
| auto fixtures_dir = | ||
| fml::OpenDirectory(GetFixturesPath(), false, fml::FilePermission::kRead); | ||
|
|
||
| auto reference_png = fml::FileMapping::CreateReadOnly( | ||
| fixtures_dir, "shelltest_screenshot.png"); | ||
|
|
||
| // Use MakeWithoutCopy instead of MakeWithCString because we don't want to | ||
| // encode the null sentinel | ||
| sk_sp<SkData> reference_data = SkData::MakeWithoutCopy( | ||
| reference_png->GetMapping(), reference_png->GetSize()); | ||
|
|
||
| ASSERT_TRUE(reference_data->equals(screenshot_future.get().data.get())); | ||
|
|
||
| DestroyShell(std::move(shell)); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // 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.
Uh oh!
There was an error while loading. Please reload this page.