5#include "flutter/lib/ui/painting/display_list_deferred_image_gpu_impeller.h"
9#include "flutter/fml/make_copyable.h"
14 std::unique_ptr<LayerTree> layer_tree,
19 std::move(layer_tree), std::move(snapshot_delegate),
20 std::move(raster_task_runner))));
30 std::move(display_list),
size, std::move(snapshot_delegate),
31 std::move(raster_task_runner))));
34DlDeferredImageGPUImpeller::DlDeferredImageGPUImpeller(
35 std::shared_ptr<ImageWrapper> wrapper)
36 : wrapper_(
std::move(wrapper)) {}
47std::shared_ptr<impeller::Texture>
52 return wrapper_->texture();
63 return wrapper_ && wrapper_->isTextureBacked();
76 return wrapper_->size();
83 if (wrapper_->texture()) {
84 size += wrapper_->texture()
85 ->GetTextureDescriptor()
86 .GetByteSizeOfBaseMipLevel();
88 size += wrapper_->size().width() * wrapper_->size().height() * 4;
94std::shared_ptr<DlDeferredImageGPUImpeller::ImageWrapper>
100 auto wrapper = std::shared_ptr<ImageWrapper>(
new ImageWrapper(
101 std::move(display_list),
size, std::move(snapshot_delegate),
102 std::move(raster_task_runner)));
103 wrapper->SnapshotDisplayList();
107std::shared_ptr<DlDeferredImageGPUImpeller::ImageWrapper>
109 std::unique_ptr<LayerTree> layer_tree,
112 auto wrapper = std::shared_ptr<ImageWrapper>(
new ImageWrapper(
113 nullptr, layer_tree->frame_size(), std::move(snapshot_delegate),
114 std::move(raster_task_runner)));
115 wrapper->SnapshotDisplayList(std::move(layer_tree));
119DlDeferredImageGPUImpeller::ImageWrapper::ImageWrapper(
125 display_list_(
std::move(display_list)),
127 raster_task_runner_(
std::move(raster_task_runner)) {}
129DlDeferredImageGPUImpeller::ImageWrapper::~ImageWrapper() {
131 raster_task_runner_, [
id =
reinterpret_cast<uintptr_t
>(
this),
132 texture_registry = std::move(texture_registry_)]() {
133 if (texture_registry) {
134 texture_registry->UnregisterContextListener(
id);
139void DlDeferredImageGPUImpeller::ImageWrapper::OnGrContextCreated() {
140 FML_DCHECK(raster_task_runner_->RunsTasksOnCurrentThread());
141 SnapshotDisplayList();
144void DlDeferredImageGPUImpeller::ImageWrapper::OnGrContextDestroyed() {
149bool DlDeferredImageGPUImpeller::ImageWrapper::isTextureBacked()
const {
150 return texture_ && texture_->IsValid();
153void DlDeferredImageGPUImpeller::ImageWrapper::SnapshotDisplayList(
154 std::unique_ptr<LayerTree> layer_tree) {
158 layer_tree = std::move(layer_tree)]() {
159 TRACE_EVENT0(
"flutter",
"SnapshotDisplayList (impeller)");
160 auto wrapper = weak_this.lock();
164 auto snapshot_delegate = wrapper->snapshot_delegate_;
165 if (!snapshot_delegate) {
169 wrapper->texture_registry_ = snapshot_delegate->GetTextureRegistry();
170 wrapper->texture_registry_->RegisterContextListener(
171 reinterpret_cast<uintptr_t
>(wrapper.get()), weak_this);
174 wrapper->display_list_ = layer_tree->Flatten(
176 wrapper->texture_registry_);
178 auto snapshot = snapshot_delegate->MakeRasterSnapshotSync(
179 wrapper->display_list_, wrapper->size_);
181 std::scoped_lock lock(wrapper->error_mutex_);
182 wrapper->error_ =
"Failed to create snapshot.";
185 wrapper->texture_ = snapshot->impeller_texture();
189std::optional<std::string>
190DlDeferredImageGPUImpeller::ImageWrapper::get_error() {
191 std::scoped_lock lock(error_mutex_);
size_t GetApproximateByteSize() const override
SkISize dimensions() const override
bool isUIThreadSafe() const override
If the underlying platform image held by this object has no threading requirements for the release of...
bool isTextureBacked() const override
bool isOpaque() const override
If the pixel format of this image ignores alpha, this returns true. This method might conservatively ...
sk_sp< SkImage > skia_image() const override
If this display list image is meant to be used by the Skia backend, an SkImage instance....
std::shared_ptr< impeller::Texture > impeller_texture() const override
If this display list image is meant to be used by the Impeller backend, an Impeller texture instance....
static sk_sp< DlDeferredImageGPUImpeller > Make(std::unique_ptr< LayerTree > layer_tree, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, fml::RefPtr< fml::TaskRunner > raster_task_runner)
~DlDeferredImageGPUImpeller() override
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate_
#define FML_DCHECK(condition)
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
internal::CopyableLambda< T > MakeCopyable(T lambda)
static constexpr SkISize MakeEmpty()
static constexpr SkRect MakeWH(float w, float h)
#define TRACE_EVENT0(category_group, name)