How to implement function that like fitToWindow when using GPU render

I have two functions that need to set the scaling value, one is based on the window size, and the other is the original size of the image. But I don’t know how to calculate it. When CPU rendering, I know that it can be achieved through fitToWindow and the value 1.

Thank you very much.