7#include "flutter/lib/ui/painting/display_list_deferred_image_gpu_skia.h"
9#include "flutter/fml/make_copyable.h"
24 std::move(snapshot_delegate), raster_task_runner,
25 std::move(unref_queue)),
31 std::unique_ptr<LayerTree> layer_tree,
36 ImageWrapper::MakeFromLayerTree(
37 image_info, std::move(layer_tree), std::move(snapshot_delegate),
38 raster_task_runner, std::move(unref_queue)),
42DlDeferredImageGPUSkia::DlDeferredImageGPUSkia(
43 std::shared_ptr<ImageWrapper> image_wrapper,
45 : image_wrapper_(
std::move(image_wrapper)),
46 raster_task_runner_(
std::move(raster_task_runner)) {}
51 [image_wrapper = image_wrapper_]() {
55 image_wrapper->Unregister();
56 image_wrapper->DeleteTexture();
62 return image_wrapper_ ? image_wrapper_->CreateSkiaImage() :
nullptr;
73 return image_wrapper_ ? image_wrapper_->image_info().isOpaque() :
false;
78 return image_wrapper_ ? image_wrapper_->isTextureBacked() :
false;
88 return image_wrapper_ ? image_wrapper_->image_info().dimensions()
94 return sizeof(*this) +
95 (image_wrapper_ ? image_wrapper_->image_info().computeMinByteSize()
100 return image_wrapper_ ? image_wrapper_->get_error() : std::nullopt;
103std::shared_ptr<DlDeferredImageGPUSkia::ImageWrapper>
110 auto wrapper = std::shared_ptr<ImageWrapper>(
new ImageWrapper(
111 image_info, std::move(display_list), std::move(snapshot_delegate),
112 std::move(raster_task_runner), std::move(unref_queue)));
113 wrapper->SnapshotDisplayList();
117std::shared_ptr<DlDeferredImageGPUSkia::ImageWrapper>
118DlDeferredImageGPUSkia::ImageWrapper::MakeFromLayerTree(
120 std::unique_ptr<LayerTree> layer_tree,
124 auto wrapper = std::shared_ptr<ImageWrapper>(
125 new ImageWrapper(image_info,
nullptr, std::move(snapshot_delegate),
126 std::move(raster_task_runner), std::move(unref_queue)));
127 wrapper->SnapshotDisplayList(std::move(layer_tree));
131DlDeferredImageGPUSkia::ImageWrapper::ImageWrapper(
137 : image_info_(image_info),
138 display_list_(
std::move(display_list)),
140 raster_task_runner_(
std::move(raster_task_runner)),
141 unref_queue_(
std::move(unref_queue)) {}
143void DlDeferredImageGPUSkia::ImageWrapper::OnGrContextCreated() {
144 FML_DCHECK(raster_task_runner_->RunsTasksOnCurrentThread());
145 SnapshotDisplayList();
148void DlDeferredImageGPUSkia::ImageWrapper::OnGrContextDestroyed() {
149 FML_DCHECK(raster_task_runner_->RunsTasksOnCurrentThread());
153sk_sp<SkImage> DlDeferredImageGPUSkia::ImageWrapper::CreateSkiaImage()
const {
154 FML_DCHECK(raster_task_runner_->RunsTasksOnCurrentThread());
156 if (texture_.isValid() && context_) {
159 image_info_.colorType(), image_info_.alphaType(),
160 image_info_.refColorSpace());
165bool DlDeferredImageGPUSkia::ImageWrapper::isTextureBacked()
const {
166 return texture_.isValid();
169void DlDeferredImageGPUSkia::ImageWrapper::SnapshotDisplayList(
170 std::unique_ptr<LayerTree> layer_tree) {
174 layer_tree = std::move(layer_tree)]()
mutable {
175 auto wrapper = weak_this.lock();
179 auto snapshot_delegate = wrapper->snapshot_delegate_;
180 if (!snapshot_delegate) {
186 wrapper->image_info_.height()),
187 snapshot_delegate->GetTextureRegistry(),
188 snapshot_delegate->GetGrContext());
189 wrapper->display_list_ = std::move(display_list);
191 auto result = snapshot_delegate->MakeSkiaGpuImage(
192 wrapper->display_list_, wrapper->image_info_);
194 wrapper->texture_ = result->texture;
195 wrapper->context_ = std::move(result->context);
196 wrapper->texture_registry_ =
197 wrapper->snapshot_delegate_->GetTextureRegistry();
198 wrapper->texture_registry_->RegisterContextListener(
199 reinterpret_cast<uintptr_t>(wrapper.get()), weak_this);
201 wrapper->image_ = std::move(result->image);
203 std::scoped_lock lock(wrapper->error_mutex_);
204 wrapper->error_ = result->error;
209std::optional<std::string> DlDeferredImageGPUSkia::ImageWrapper::get_error() {
210 std::scoped_lock lock(error_mutex_);
214void DlDeferredImageGPUSkia::ImageWrapper::Unregister() {
215 if (texture_registry_) {
216 texture_registry_->UnregisterContextListener(
217 reinterpret_cast<uintptr_t
>(
this));
221void DlDeferredImageGPUSkia::ImageWrapper::DeleteTexture() {
222 if (texture_.isValid()) {
223 unref_queue_->DeleteTexture(texture_);
@ kTopLeft_GrSurfaceOrigin
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::optional< std::string > get_error() const override
static sk_sp< DlDeferredImageGPUSkia > Make(const SkImageInfo &image_info, sk_sp< DisplayList > display_list, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, const fml::RefPtr< fml::TaskRunner > &raster_task_runner, fml::RefPtr< SkiaUnrefQueue > unref_queue)
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....
bool isTextureBacked() const override
SkISize dimensions() const override
~DlDeferredImageGPUSkia() override
bool isOpaque() const override
If the pixel format of this image ignores alpha, this returns true. This method might conservatively ...
static sk_sp< DlDeferredImageGPUSkia > MakeFromLayerTree(const SkImageInfo &image_info, std::unique_ptr< LayerTree > layer_tree, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, const fml::RefPtr< fml::TaskRunner > &raster_task_runner, fml::RefPtr< SkiaUnrefQueue > unref_queue)
bool isUIThreadSafe() const override
If the underlying platform image held by this object has no threading requirements for the release of...
virtual size_t GetApproximateByteSize() const 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< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
internal::CopyableLambda< T > MakeCopyable(T lambda)
static constexpr SkISize MakeEmpty()
static constexpr SkRect MakeWH(float w, float h)