Apply Shader to existing SkCanvas w/ Texture

瀏覽次數:77 次
跳到第一則未讀訊息

mrousavy

未讀,
2022年11月22日 上午9:57:382022/11/22
收件者:skia-discuss
Hi all!
  1. I have a Metal Texture containing an Image.
  2. I am creating the SkCanvas from this Metal Texture directly (so I avoid the SkImage conversion + drawImage(...) call)
  3. Now I want to apply a Paint to the Canvas that contains a Shader/Runtime Effect/Image Filter. Is that possible?

The reason I'm doing this is because I am building a Camera app that's streaming Frames (CVPixelBuffer). I want to show those Frames to the Preview View, and it turns out that the CVPixelBuffer -> SkImage conversion is quite slow (considering I have to go from YUV to RGB), so I wanted to convert that to a simple Metal Texture (stay on the GPU) and then apply my Shader ontop of that, but that doesn't work with a uniform shader image parameter then to sample it...

Brian Osman

未讀,
2022年11月22日 上午10:16:342022/11/22
收件者:skia-d...@googlegroups.com
Hi,
Just want to clarify what you mean in a couple spots:
"I am creating the SkCanvas from this Metal Texture directly (so I avoid the SkImage conversion + drawImage(...) call)" -- What does this mean, exactly? SkCanvas is an interface to an SkSurface (usually), and can't be directly constructed from a texture/image. Are you wrapping the texture in an SkSurface (with `MakeFromBackend...`, and then getting the canvas from that surface?).

Ultimately, the runtime shader/effect will require an SkShader as input, which means something that can be sampled. This could be a simple RGB texture (wrapped in an SkImage), or it could be a planar SkImage, with multiple underlying textures, per your other email. But it should still be possible to make that work while keeping everything on the GPU. Let us know which types you're using to import the camera feed, and I suspect we can make it work. (I'm assuming that if the YUV image stuff works out, then you'd be all set?)

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/3307af8e-7f6c-4b6b-8b73-7d59dcf2c464n%40googlegroups.com.

mrousavy

未讀,
2022年11月22日 上午11:47:542022/11/22
收件者:skia-discuss
I think I confused something here. You're right, I cannot create the SkSurface/SkCanvas from the existing CVPixelBuffer Metal Texture directly, I have to create the texture from the Metal Layer first, then draw the CVPixelBuffer onto the Canvas later.

I am still not sure how to do that SkImage conversion as efficiently as possible, i.e. stay in the YUV space all the time, no conversions, and only on the GPU. Will continue in the other thread - thanks for your help!

Sorry for the confusion!

回覆所有人
回覆作者
轉寄
0 則新訊息