@@ -151,8 +151,7 @@ static sk_sp<SkImage> ImageFromCompressedData(
151151
152152static SkiaGPUObject<SkImage> UploadRasterImage (
153153 sk_sp<SkImage> image,
154- fml::WeakPtr<GrContext> context,
155- fml::RefPtr<flutter::SkiaUnrefQueue> queue,
154+ fml::WeakPtr<IOManager> io_manager,
156155 const fml::tracing::TraceFlow& flow) {
157156 TRACE_EVENT0 (" flutter" , __FUNCTION__);
158157 flow.Step (__FUNCTION__);
@@ -161,7 +160,7 @@ static SkiaGPUObject<SkImage> UploadRasterImage(
161160 // the this method.
162161 FML_DCHECK (!image->isTextureBacked ());
163162
164- if (!context || !queue ) {
163+ if (!io_manager-> GetResourceContext () || !io_manager-> GetSkiaUnrefQueue () ) {
165164 FML_LOG (ERROR )
166165 << " Could not acquire context of release queue for texture upload." ;
167166 return {};
@@ -173,19 +172,36 @@ static SkiaGPUObject<SkImage> UploadRasterImage(
173172 return {};
174173 }
175174
176- auto texture_image =
177- SkImage::MakeCrossContextFromPixmap (context.get (), // context
178- pixmap, // pixmap
179- true , // buildMips,
180- true // limitToMaxTextureSize
181- );
182-
183- if (!texture_image) {
184- FML_LOG (ERROR ) << " Could not make x-context image." ;
185- return {};
186- }
187-
188- return {texture_image, queue};
175+ SkiaGPUObject<SkImage> result;
176+ io_manager->GetIsGpuDisabledSyncSwitch ()->Execute (
177+ fml::SyncSwitch::Handlers ()
178+ .SetIfTrue ([&result, &pixmap, &image] {
179+ SkSafeRef (image.get ());
180+ sk_sp<SkImage> texture_image = SkImage::MakeFromRaster (
181+ pixmap,
182+ [](const void * pixels, SkImage::ReleaseContext context) {
183+ SkSafeUnref (static_cast <SkImage*>(context));
184+ },
185+ image.get ());
186+ result = {texture_image, nullptr };
187+ })
188+ .SetIfFalse ([&result, context = io_manager->GetResourceContext (),
189+ &pixmap, queue = io_manager->GetSkiaUnrefQueue ()] {
190+ sk_sp<SkImage> texture_image = SkImage::MakeCrossContextFromPixmap (
191+ context.get (), // context
192+ pixmap, // pixmap
193+ true , // buildMips,
194+ true // limitToMaxTextureSize
195+ );
196+ if (!texture_image) {
197+ FML_LOG (ERROR ) << " Could not make x-context image." ;
198+ result = {};
199+ } else {
200+ result = {texture_image, queue};
201+ }
202+ }));
203+
204+ return result;
189205}
190206
191207void ImageDecoder::Decode (ImageDescriptor descriptor,
@@ -265,9 +281,8 @@ void ImageDecoder::Decode(ImageDescriptor descriptor,
265281 return ;
266282 }
267283
268- auto uploaded = UploadRasterImage (
269- std::move (decompressed), io_manager->GetResourceContext (),
270- io_manager->GetSkiaUnrefQueue (), flow);
284+ auto uploaded =
285+ UploadRasterImage (std::move (decompressed), io_manager, flow);
271286
272287 if (!uploaded.get ()) {
273288 FML_LOG (ERROR ) << " Could not upload image to the GPU." ;
0 commit comments