You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to skia-discuss
Hi, I’m currently working on rendering images using Skia and have observed a performance-quality trade-off depending on the SkSamplingOptions used with canvas->drawImageRect(). I construct the image using: image = SkImages::RasterFromPixmap(pixmap, nullptr, nullptr); And draw it like this: canvas->drawImageRect(image, imageRect, SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear)); While this produces high-quality results — especially for downscaled images — it introduces noticeable performance overhead. On the other hand, drawing the image using the default SkSamplingOptions(): canvas->drawImageRect(image, imageRect, SkSamplingOptions()); is significantly faster, but leads to very poor image quality, especially when downscaling. What I Tried : To balance performance and quality, I’ve implemented conditional sampling based on the image size and destination imageRect: auto samplingOptions = SkSamplingOptions(); if (imgWidth > imageRect.width() && imgHeight > imageRect.height()) { // Downscaling samplingOptions = SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear); } else if (imgWidth < imageRect.width() || imgHeight < imageRect.height()) { // Upscaling samplingOptions = SkSamplingOptions(SkFilterMode::kLinear); } // No sampling for exact size match canvas->drawImageRect(image, imageRect, samplingOptions); This helps improve performance slightly while preserving decent quality in most scenarios. Are there any better practices or optimizations you’d recommend for: Improving rendering speed while maintaining image quality? Choosing the most appropriate SkSamplingOptions dynamically? Possibly using mipmaps more efficiently (or alternatives)? Any insights would be greatly appreciated.
Thanks
Michael Ludwig
unread,
Jul 28, 2025, 11:10:38 AMJul 28
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to skia-discuss
Those are reasonable heuristics to use for performance. Cubic filtering can give higher quality than linear filtering when upscaling, but it is going to be more expensive. You could experiment with SkMipmapMode::kNearest for downscaling, as I believe that will be faster on the CPU backend while still producing better results than linear or nearest for downscaling. But realistically, CPU image filtering performance is quite sensitive to the sampling options you use. GPU rendering will avoid most of that cost.