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
Include TextureViews in the output of Scene.toImage[Sync] #35527
Merged
jonahwilliams
merged 35 commits into
flutter-team-archive:main
from
jonahwilliams:hack_for_texture_view
Aug 19, 2022
Merged
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
c82840f
delete dl flag from allowlist
856069a
hhacky
679d7f2
Merge branch 'master' of github.com:flutter/engine into hack_for_text…
614836d
Re-arrange interface
73197e9
++
8ba46b2
Update snapshot_delegate.h
11d1844
run flatten on raster thread
68bb764
make FlattenWithContext an optional parameter on Flatten
36bed16
++
550a907
Update layer_tree.h
cd92c27
Merge branch 'hack_for_texture_view' of github.com:jonahwilliams/engi…
a8c43a0
amost works
87c2edb
almost
1fb2718
change to shared_ptr
b3c0e00
++
f7c8de4
add nullchecks and texture test
f612d0e
Merge branch 'master' of github.com:flutter/engine into hack_for_text…
3d21528
++
abdf5b8
Update compositing_test.dart
62437b4
Merge branch 'hack_for_texture_view' of github.com:jonahwilliams/engi…
844c4dd
Merge branch 'master' of github.com:flutter/engine into hack_for_text…
bcb3f44
Work in progress unification of toImage and toImageSync
b628bfd
Merge branch 'master' of github.com:flutter/engine into hack_for_text…
535a8c8
++
9c0a286
include gr direct context
2a1a51c
++
acfb369
Merge branch 'master' of github.com:flutter/engine into hack_for_text…
a3e8b53
Merge branch 'master' of github.com:flutter/engine into hack_for_text…
fdf2f5a
sync to head
eff8964
I dont know cpp
8b3dd48
fix size
da5b3a1
revert toImage change
9708ebe
dnfield review
a802cc5
Add some doc comments
657902b
++
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
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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| #include "flutter/lib/ui/compositing/scene.h" | ||
|
|
||
| #include "flutter/fml/trace_event.h" | ||
| #include "flutter/lib/ui/painting/display_list_deferred_image_gpu.h" | ||
| #include "flutter/lib/ui/painting/image.h" | ||
| #include "flutter/lib/ui/painting/picture.h" | ||
| #include "flutter/lib/ui/ui_dart_state.h" | ||
|
|
@@ -42,7 +43,7 @@ Scene::Scene(std::shared_ptr<flutter::Layer> rootLayer, | |
| ->get_window(0) | ||
| ->viewport_metrics(); | ||
|
|
||
| layer_tree_ = std::make_unique<LayerTree>( | ||
| layer_tree_ = std::make_shared<LayerTree>( | ||
| SkISize::Make(viewport_metrics.physical_width, | ||
| viewport_metrics.physical_height), | ||
| static_cast<float>(viewport_metrics.device_pixel_ratio)); | ||
|
|
@@ -69,33 +70,46 @@ Dart_Handle Scene::toImageSync(uint32_t width, | |
| return tonic::ToDart("Scene did not contain a layer tree."); | ||
| } | ||
|
|
||
| auto picture = layer_tree_->Flatten(SkRect::MakeWH(width, height)); | ||
| if (!picture) { | ||
| return tonic::ToDart("Could not flatten scene into a layer tree."); | ||
| } | ||
|
|
||
| Picture::RasterizeToImageSync(picture, width, height, raw_image_handle); | ||
| Scene::RasterizeToImage(width, height, raw_image_handle); | ||
| return Dart_Null(); | ||
| } | ||
|
|
||
| Dart_Handle Scene::toImage(uint32_t width, | ||
| uint32_t height, | ||
| Dart_Handle raw_image_callback) { | ||
| Dart_Handle raw_image_handle) { | ||
| TRACE_EVENT0("flutter", "Scene::toImage"); | ||
|
|
||
| if (!layer_tree_) { | ||
| return tonic::ToDart("Scene did not contain a layer tree."); | ||
| } | ||
|
|
||
| auto picture = layer_tree_->Flatten(SkRect::MakeWH(width, height)); | ||
| if (!picture) { | ||
| return tonic::ToDart("Could not flatten scene into a layer tree."); | ||
| } | ||
| Scene::RasterizeToImage(width, height, raw_image_handle); | ||
| return Dart_Null(); | ||
| } | ||
|
|
||
| return Picture::RasterizeToImage(picture, width, height, raw_image_callback); | ||
| void Scene::RasterizeToImage(uint32_t width, | ||
| uint32_t height, | ||
| Dart_Handle raw_image_handle) { | ||
| auto* dart_state = UIDartState::Current(); | ||
| if (!dart_state) { | ||
| return; | ||
| } | ||
| auto unref_queue = dart_state->GetSkiaUnrefQueue(); | ||
| auto snapshot_delegate = dart_state->GetSnapshotDelegate(); | ||
| auto raster_task_runner = dart_state->GetTaskRunners().GetRasterTaskRunner(); | ||
|
|
||
| auto image = CanvasImage::Create(); | ||
| const SkImageInfo image_info = SkImageInfo::Make( | ||
| width, height, kRGBA_8888_SkColorType, kPremul_SkAlphaType); | ||
| auto dl_image = DlDeferredImageGPU::MakeFromLayerTree( | ||
| image_info, std::move(layer_tree_), width, height, | ||
|
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. width, height are redundant with what's stored in the SkImageInfo. |
||
| std::move(snapshot_delegate), std::move(raster_task_runner), | ||
| std::move(unref_queue)); | ||
| image->set_image(dl_image); | ||
| image->AssociateWithDartWrapper(raw_image_handle); | ||
| } | ||
|
|
||
| std::unique_ptr<flutter::LayerTree> Scene::takeLayerTree() { | ||
| std::shared_ptr<flutter::LayerTree> Scene::takeLayerTree() { | ||
| return std::move(layer_tree_); | ||
| } | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
I'm not sure this is the right choice here.
The current API returns a host copy of the image every time, which can't get lost of GPU context gets lost and is safe to use in the background.
The new API fails in this scenario:
I think we should try to merge these in the C++ layer for now.
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.
So we could let the APIs diverge then, but I'm not sure of the exact mechanics here. Since the texture registry is only available on the raster thread, don't we need to both flatten and rasterize on that thread in order to retain the contents?
We can always punt on this for now, but I'd like to figure out what the path forward is.
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.
i.e. can I tweak the toImage path to flatten/rasterize on the raster thread and still be safe here?
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.
toImagealready posts a task to the raster thread. We'd just need to move the flattening of the layer tree to that task.I think the path forward would be to refactor
Picture::RasterizeToImageso that its guts live onScene::RasterizeToImageand the scene version knows how to convert a layer tree to a display list on the raster thread (but also can still take a display list if the call is coming from Picture, which already has one).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.
Got it