| 68 | } |
| 69 | |
| 70 | Valdi::Shared<snap::valdi_core::Cancelable> ImageLoader::loadAsset( |
| 71 | const Valdi::StringBox& url, |
| 72 | int32_t preferredWidth, |
| 73 | int32_t preferredHeight, |
| 74 | const Valdi::Value& associatedData, |
| 75 | const Valdi::Ref<Valdi::IRemoteDownloader>& downloader, |
| 76 | const Valdi::Ref<Valdi::AssetLoaderCompletion>& completion) { |
| 77 | auto task = Valdi::makeShared<ImageLoaderTask>( |
| 78 | Valdi::weakRef(this), url, preferredWidth, preferredHeight, associatedData, downloader, completion); |
| 79 | |
| 80 | _queue->async([task] { |
| 81 | if (auto strongThis = task->getImageLoader().lock()) { |
| 82 | strongThis->loadImage(task); |
| 83 | } |
| 84 | }); |
| 85 | |
| 86 | return Valdi::makeShared<ImageLoaderTaskCancelable>(task); |
| 87 | } |
| 88 | |
| 89 | void ImageLoader::loadImage(const Ref<ImageLoaderTask>& task) { |
| 90 | if (task->wasCanceled()) { |