{-# language CPP #-}
module OpenXR.Extensions.XR_KHR_android_surface_swapchain ( createSwapchainAndroidSurfaceKHR
, withSwapchainAndroidSurfaceKHR
, KHR_android_surface_swapchain_SPEC_VERSION
, pattern KHR_android_surface_swapchain_SPEC_VERSION
, KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME
, pattern KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME
, Jobject
) where
import OpenXR.Internal.Utils (traceAroundEvent)
import Control.Exception.Base (bracket)
import Control.Monad (unless)
import Control.Monad.IO.Class (liftIO)
import Foreign.Marshal.Alloc (callocBytes)
import Foreign.Marshal.Alloc (free)
import GHC.Base (when)
import GHC.IO (throwIO)
import GHC.Ptr (nullFunPtr)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Cont (evalContT)
import OpenXR.CStruct (ToCStruct(..))
import Control.Monad.IO.Class (MonadIO)
import Data.String (IsString)
import Foreign.Storable (Storable(peek))
import GHC.IO.Exception (IOErrorType(..))
import GHC.IO.Exception (IOException(..))
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import Control.Monad.Trans.Cont (ContT(..))
import OpenXR.Core10.Image (destroySwapchain)
import OpenXR.CStruct.Extends (forgetExtensions)
import OpenXR.NamedType ((:::))
import OpenXR.CStruct.Extends (Extendss)
import OpenXR.Dynamic (InstanceCmds(pXrCreateSwapchainAndroidSurfaceKHR))
import OpenXR.Exception (OpenXrException(..))
import OpenXR.CStruct.Extends (PokeChain)
import OpenXR.Core10.Enums.Result (Result)
import OpenXR.Core10.Enums.Result (Result(..))
import OpenXR.Core10.Handles (Session)
import OpenXR.Core10.Handles (Session(..))
import OpenXR.Core10.Handles (Session_T)
import OpenXR.CStruct.Extends (SomeStruct)
import OpenXR.Core10.Handles (Swapchain)
import OpenXR.Core10.Handles (Swapchain(Swapchain))
import OpenXR.Core10.Image (SwapchainCreateInfo)
import OpenXR.Core10.Handles (Swapchain_T)
import OpenXR.Core10.Enums.Result (Result(SUCCESS))
foreign import ccall
#if !defined(SAFE_FOREIGN_CALLS)
unsafe
#endif
"dynamic" mkXrCreateSwapchainAndroidSurfaceKHR
:: FunPtr (Ptr Session_T -> Ptr (SomeStruct SwapchainCreateInfo) -> Ptr (Ptr Swapchain_T) -> Ptr Jobject -> IO Result) -> Ptr Session_T -> Ptr (SomeStruct SwapchainCreateInfo) -> Ptr (Ptr Swapchain_T) -> Ptr Jobject -> IO Result
createSwapchainAndroidSurfaceKHR :: forall a io
. (Extendss SwapchainCreateInfo a, PokeChain a, MonadIO io)
=>
Session
->
(SwapchainCreateInfo a)
->
("surface" ::: Ptr Jobject)
-> io (Result, Swapchain)
createSwapchainAndroidSurfaceKHR :: Session
-> SwapchainCreateInfo a
-> ("surface" ::: Ptr Jobject)
-> io (Result, Swapchain)
createSwapchainAndroidSurfaceKHR session :: Session
session info :: SwapchainCreateInfo a
info surface :: "surface" ::: Ptr Jobject
surface = IO (Result, Swapchain) -> io (Result, Swapchain)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Result, Swapchain) -> io (Result, Swapchain))
-> (ContT (Result, Swapchain) IO (Result, Swapchain)
-> IO (Result, Swapchain))
-> ContT (Result, Swapchain) IO (Result, Swapchain)
-> io (Result, Swapchain)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContT (Result, Swapchain) IO (Result, Swapchain)
-> IO (Result, Swapchain)
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT (Result, Swapchain) IO (Result, Swapchain)
-> io (Result, Swapchain))
-> ContT (Result, Swapchain) IO (Result, Swapchain)
-> io (Result, Swapchain)
forall a b. (a -> b) -> a -> b
$ do
let cmds :: InstanceCmds
cmds = Session -> InstanceCmds
instanceCmds (Session
session :: Session)
let xrCreateSwapchainAndroidSurfaceKHRPtr :: FunPtr
(Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result)
xrCreateSwapchainAndroidSurfaceKHRPtr = InstanceCmds
-> FunPtr
(Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result)
pXrCreateSwapchainAndroidSurfaceKHR InstanceCmds
cmds
IO () -> ContT (Result, Swapchain) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT (Result, Swapchain) IO ())
-> IO () -> ContT (Result, Swapchain) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FunPtr
(Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result)
xrCreateSwapchainAndroidSurfaceKHRPtr FunPtr
(Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result)
-> FunPtr
(Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result)
-> Bool
forall a. Eq a => a -> a -> Bool
/= FunPtr
(Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result)
forall a. FunPtr a
nullFunPtr) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
IOException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (IOException -> IO ()) -> IOException -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Handle
-> IOErrorType
-> String
-> String
-> Maybe CInt
-> Maybe String
-> IOException
IOError Maybe Handle
forall a. Maybe a
Nothing IOErrorType
InvalidArgument "" "The function pointer for xrCreateSwapchainAndroidSurfaceKHR is null" Maybe CInt
forall a. Maybe a
Nothing Maybe String
forall a. Maybe a
Nothing
let xrCreateSwapchainAndroidSurfaceKHR' :: Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result
xrCreateSwapchainAndroidSurfaceKHR' = FunPtr
(Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result)
-> Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result
mkXrCreateSwapchainAndroidSurfaceKHR FunPtr
(Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result)
xrCreateSwapchainAndroidSurfaceKHRPtr
Ptr (SwapchainCreateInfo a)
info' <- ((Ptr (SwapchainCreateInfo a) -> IO (Result, Swapchain))
-> IO (Result, Swapchain))
-> ContT (Result, Swapchain) IO (Ptr (SwapchainCreateInfo a))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr (SwapchainCreateInfo a) -> IO (Result, Swapchain))
-> IO (Result, Swapchain))
-> ContT (Result, Swapchain) IO (Ptr (SwapchainCreateInfo a)))
-> ((Ptr (SwapchainCreateInfo a) -> IO (Result, Swapchain))
-> IO (Result, Swapchain))
-> ContT (Result, Swapchain) IO (Ptr (SwapchainCreateInfo a))
forall a b. (a -> b) -> a -> b
$ SwapchainCreateInfo a
-> (Ptr (SwapchainCreateInfo a) -> IO (Result, Swapchain))
-> IO (Result, Swapchain)
forall a b. ToCStruct a => a -> (Ptr a -> IO b) -> IO b
withCStruct (SwapchainCreateInfo a
info)
"swapchain" ::: Ptr (Ptr Swapchain_T)
pSwapchain <- ((("swapchain" ::: Ptr (Ptr Swapchain_T))
-> IO (Result, Swapchain))
-> IO (Result, Swapchain))
-> ContT
(Result, Swapchain) IO ("swapchain" ::: Ptr (Ptr Swapchain_T))
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((("swapchain" ::: Ptr (Ptr Swapchain_T))
-> IO (Result, Swapchain))
-> IO (Result, Swapchain))
-> ContT
(Result, Swapchain) IO ("swapchain" ::: Ptr (Ptr Swapchain_T)))
-> ((("swapchain" ::: Ptr (Ptr Swapchain_T))
-> IO (Result, Swapchain))
-> IO (Result, Swapchain))
-> ContT
(Result, Swapchain) IO ("swapchain" ::: Ptr (Ptr Swapchain_T))
forall a b. (a -> b) -> a -> b
$ IO ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> (("swapchain" ::: Ptr (Ptr Swapchain_T)) -> IO ())
-> (("swapchain" ::: Ptr (Ptr Swapchain_T))
-> IO (Result, Swapchain))
-> IO (Result, Swapchain)
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket (Int -> IO ("swapchain" ::: Ptr (Ptr Swapchain_T))
forall a. Int -> IO (Ptr a)
callocBytes @(Ptr Swapchain_T) 8) ("swapchain" ::: Ptr (Ptr Swapchain_T)) -> IO ()
forall a. Ptr a -> IO ()
free
Result
r <- IO Result -> ContT (Result, Swapchain) IO Result
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO Result -> ContT (Result, Swapchain) IO Result)
-> IO Result -> ContT (Result, Swapchain) IO Result
forall a b. (a -> b) -> a -> b
$ String -> IO Result -> IO Result
forall a. String -> IO a -> IO a
traceAroundEvent "xrCreateSwapchainAndroidSurfaceKHR" (Ptr Session_T
-> ("info" ::: Ptr (SomeStruct SwapchainCreateInfo))
-> ("swapchain" ::: Ptr (Ptr Swapchain_T))
-> ("surface" ::: Ptr Jobject)
-> IO Result
xrCreateSwapchainAndroidSurfaceKHR' (Session -> Ptr Session_T
sessionHandle (Session
session)) (Ptr (SwapchainCreateInfo a)
-> "info" ::: Ptr (SomeStruct SwapchainCreateInfo)
forall (a :: [*] -> *) (es :: [*]).
Ptr (a es) -> Ptr (SomeStruct a)
forgetExtensions Ptr (SwapchainCreateInfo a)
info') ("swapchain" ::: Ptr (Ptr Swapchain_T)
pSwapchain) ("surface" ::: Ptr Jobject
surface))
IO () -> ContT (Result, Swapchain) IO ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO () -> ContT (Result, Swapchain) IO ())
-> IO () -> ContT (Result, Swapchain) IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Result
r Result -> Result -> Bool
forall a. Ord a => a -> a -> Bool
< Result
SUCCESS) (OpenXrException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (Result -> OpenXrException
OpenXrException Result
r))
Ptr Swapchain_T
swapchain <- IO (Ptr Swapchain_T)
-> ContT (Result, Swapchain) IO (Ptr Swapchain_T)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IO (Ptr Swapchain_T)
-> ContT (Result, Swapchain) IO (Ptr Swapchain_T))
-> IO (Ptr Swapchain_T)
-> ContT (Result, Swapchain) IO (Ptr Swapchain_T)
forall a b. (a -> b) -> a -> b
$ ("swapchain" ::: Ptr (Ptr Swapchain_T)) -> IO (Ptr Swapchain_T)
forall a. Storable a => Ptr a -> IO a
peek @(Ptr Swapchain_T) "swapchain" ::: Ptr (Ptr Swapchain_T)
pSwapchain
(Result, Swapchain)
-> ContT (Result, Swapchain) IO (Result, Swapchain)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Result, Swapchain)
-> ContT (Result, Swapchain) IO (Result, Swapchain))
-> (Result, Swapchain)
-> ContT (Result, Swapchain) IO (Result, Swapchain)
forall a b. (a -> b) -> a -> b
$ (Result
r, ((\h :: Ptr Swapchain_T
h -> Ptr Swapchain_T -> InstanceCmds -> Swapchain
Swapchain Ptr Swapchain_T
h InstanceCmds
cmds ) Ptr Swapchain_T
swapchain))
withSwapchainAndroidSurfaceKHR :: forall a io r . (Extendss SwapchainCreateInfo a, PokeChain a, MonadIO io) => Session -> SwapchainCreateInfo a -> Ptr Jobject -> (io (Result, Swapchain) -> ((Result, Swapchain) -> io ()) -> r) -> r
withSwapchainAndroidSurfaceKHR :: Session
-> SwapchainCreateInfo a
-> ("surface" ::: Ptr Jobject)
-> (io (Result, Swapchain) -> ((Result, Swapchain) -> io ()) -> r)
-> r
withSwapchainAndroidSurfaceKHR session :: Session
session info :: SwapchainCreateInfo a
info surface :: "surface" ::: Ptr Jobject
surface b :: io (Result, Swapchain) -> ((Result, Swapchain) -> io ()) -> r
b =
io (Result, Swapchain) -> ((Result, Swapchain) -> io ()) -> r
b (Session
-> SwapchainCreateInfo a
-> ("surface" ::: Ptr Jobject)
-> io (Result, Swapchain)
forall (a :: [*]) (io :: * -> *).
(Extendss SwapchainCreateInfo a, PokeChain a, MonadIO io) =>
Session
-> SwapchainCreateInfo a
-> ("surface" ::: Ptr Jobject)
-> io (Result, Swapchain)
createSwapchainAndroidSurfaceKHR Session
session SwapchainCreateInfo a
info "surface" ::: Ptr Jobject
surface)
(\(_, o1 :: Swapchain
o1) -> Swapchain -> io ()
forall (io :: * -> *). MonadIO io => Swapchain -> io ()
destroySwapchain Swapchain
o1)
type KHR_android_surface_swapchain_SPEC_VERSION = 4
pattern KHR_android_surface_swapchain_SPEC_VERSION :: forall a . Integral a => a
pattern $bKHR_android_surface_swapchain_SPEC_VERSION :: a
$mKHR_android_surface_swapchain_SPEC_VERSION :: forall r a. Integral a => a -> (Void# -> r) -> (Void# -> r) -> r
KHR_android_surface_swapchain_SPEC_VERSION = 4
type KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME = "XR_KHR_android_surface_swapchain"
pattern KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME :: forall a . (Eq a, IsString a) => a
pattern $bKHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME :: a
$mKHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME :: forall r a.
(Eq a, IsString a) =>
a -> (Void# -> r) -> (Void# -> r) -> r
KHR_ANDROID_SURFACE_SWAPCHAIN_EXTENSION_NAME = "XR_KHR_android_surface_swapchain"
data Jobject