{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- /No description available in the introspection data./

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.Cogl.Objects.Offscreen
    ( 

-- * Exported types
    Offscreen(..)                           ,
    IsOffscreen                             ,
    toOffscreen                             ,


 -- * Methods

#if defined(ENABLE_OVERLOADING)
    ResolveOffscreenMethod                  ,
#endif

-- ** newToTexture #method:newToTexture#

    offscreenNewToTexture                   ,


-- ** newWithTexture #method:newWithTexture#

    offscreenNewWithTexture                 ,


-- ** ref #method:ref#

    offscreenRef                            ,


-- ** unref #method:unref#

    offscreenUnref                          ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.Kind as DK
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL
import qualified GHC.Records as R

import {-# SOURCE #-} qualified GI.Cogl.Interfaces.Texture as Cogl.Texture

-- | Memory-managed wrapper type.
newtype Offscreen = Offscreen (SP.ManagedPtr Offscreen)
    deriving (Offscreen -> Offscreen -> Bool
(Offscreen -> Offscreen -> Bool)
-> (Offscreen -> Offscreen -> Bool) -> Eq Offscreen
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Offscreen -> Offscreen -> Bool
== :: Offscreen -> Offscreen -> Bool
$c/= :: Offscreen -> Offscreen -> Bool
/= :: Offscreen -> Offscreen -> Bool
Eq)

instance SP.ManagedPtrNewtype Offscreen where
    toManagedPtr :: Offscreen -> ManagedPtr Offscreen
toManagedPtr (Offscreen ManagedPtr Offscreen
p) = ManagedPtr Offscreen
p

foreign import ccall "cogl_offscreen_get_gtype"
    c_cogl_offscreen_get_gtype :: IO B.Types.GType

instance B.Types.TypedObject Offscreen where
    glibType :: IO GType
glibType = IO GType
c_cogl_offscreen_get_gtype

-- | Type class for types which can be safely cast to `Offscreen`, for instance with `toOffscreen`.
class (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf Offscreen o) => IsOffscreen o
instance (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf Offscreen o) => IsOffscreen o

instance O.HasParentTypes Offscreen
type instance O.ParentTypes Offscreen = '[]

-- | Cast to `Offscreen`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toOffscreen :: (MIO.MonadIO m, IsOffscreen o) => o -> m Offscreen
toOffscreen :: forall (m :: * -> *) o.
(MonadIO m, IsOffscreen o) =>
o -> m Offscreen
toOffscreen = IO Offscreen -> m Offscreen
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO Offscreen -> m Offscreen)
-> (o -> IO Offscreen) -> o -> m Offscreen
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr Offscreen -> Offscreen) -> o -> IO Offscreen
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr Offscreen -> Offscreen
Offscreen

--- XXX Missing getter and/or setter, so no GValue instance could be generated.
#if defined(ENABLE_OVERLOADING)
type family ResolveOffscreenMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveOffscreenMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveOffscreenMethod t Offscreen, O.OverloadedMethod info Offscreen p) => OL.IsLabel t (Offscreen -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveOffscreenMethod t Offscreen, O.OverloadedMethod info Offscreen p, R.HasField t Offscreen p) => R.HasField t Offscreen p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveOffscreenMethod t Offscreen, O.OverloadedMethodInfo info Offscreen) => OL.IsLabel t (O.MethodProxy info Offscreen) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif

-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance BoxedPtr Offscreen where
    boxedPtrCopy :: Offscreen -> IO Offscreen
boxedPtrCopy = Offscreen -> IO Offscreen
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
    boxedPtrFree :: Offscreen -> IO ()
boxedPtrFree = \Offscreen
_x -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- method Offscreen::new_to_texture
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "texture"
--           , argType =
--               TInterface Name { namespace = "Cogl" , name = "Texture" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A #CoglTexture pointer"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Cogl" , name = "Offscreen" })
-- throws : False
-- Skip return : False

foreign import ccall "cogl_offscreen_new_to_texture" cogl_offscreen_new_to_texture :: 
    Ptr Cogl.Texture.Texture ->             -- texture : TInterface (Name {namespace = "Cogl", name = "Texture"})
    IO (Ptr Offscreen)

{-# DEPRECATED offscreenNewToTexture ["(Since version 1.16)","Use cogl_offscreen_new_with_texture instead."] #-}
-- | This creates an offscreen buffer object using the given /@texture@/ as the
-- primary color buffer. It doesn\'t just initialize the contents of the
-- offscreen buffer with the /@texture@/; they are tightly bound so that
-- drawing to the offscreen buffer effectivly updates the contents of the
-- given texture. You don\'t need to destroy the offscreen buffer before
-- you can use the /@texture@/ again.
-- 
-- \<note>This only works with low-level @/CoglTexture/@ types such as
-- @/CoglTexture2D/@, @/CoglTexture3D/@ and @/CoglTextureRectangle/@, and not
-- with meta-texture types such as @/CoglTexture2DSliced/@.\<\/note>
offscreenNewToTexture ::
    (B.CallStack.HasCallStack, MonadIO m, Cogl.Texture.IsTexture a) =>
    a
    -- ^ /@texture@/: A @/CoglTexture/@ pointer
    -> m Offscreen
    -- ^ __Returns:__ a newly instantiated t'GI.Cogl.Objects.Offscreen.Offscreen'
    --   framebuffer or 'P.Nothing' if it wasn\'t possible to create the
    --   buffer.
offscreenNewToTexture :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTexture a) =>
a -> m Offscreen
offscreenNewToTexture a
texture = IO Offscreen -> m Offscreen
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Offscreen -> m Offscreen) -> IO Offscreen -> m Offscreen
forall a b. (a -> b) -> a -> b
$ do
    Ptr Texture
texture' <- a -> IO (Ptr Texture)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
texture
    Ptr Offscreen
result <- Ptr Texture -> IO (Ptr Offscreen)
cogl_offscreen_new_to_texture Ptr Texture
texture'
    Text -> Ptr Offscreen -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"offscreenNewToTexture" Ptr Offscreen
result
    Offscreen
result' <- ((ManagedPtr Offscreen -> Offscreen)
-> Ptr Offscreen -> IO Offscreen
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr Offscreen -> Offscreen
Offscreen) Ptr Offscreen
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
texture
    Offscreen -> IO Offscreen
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Offscreen
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method Offscreen::new_with_texture
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "texture"
--           , argType =
--               TInterface Name { namespace = "Cogl" , name = "Texture" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A #CoglTexture pointer"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Cogl" , name = "Offscreen" })
-- throws : False
-- Skip return : False

foreign import ccall "cogl_offscreen_new_with_texture" cogl_offscreen_new_with_texture :: 
    Ptr Cogl.Texture.Texture ->             -- texture : TInterface (Name {namespace = "Cogl", name = "Texture"})
    IO (Ptr Offscreen)

-- | This creates an offscreen framebuffer object using the given
-- /@texture@/ as the primary color buffer. It doesn\'t just initialize
-- the contents of the offscreen buffer with the /@texture@/; they are
-- tightly bound so that drawing to the offscreen buffer effectively
-- updates the contents of the given texture. You don\'t need to
-- destroy the offscreen buffer before you can use the /@texture@/ again.
-- 
-- \<note>This api only works with low-level @/CoglTexture/@ types such as
-- @/CoglTexture2D/@, @/CoglTexture3D/@ and @/CoglTextureRectangle/@, and not
-- with meta-texture types such as @/CoglTexture2DSliced/@.\<\/note>
-- 
-- The storage for the framebuffer is actually allocated lazily
-- so this function will never return 'P.Nothing' to indicate a runtime
-- error. This means it is still possible to configure the framebuffer
-- before it is really allocated.
-- 
-- Simple applications without full error handling can simply rely on
-- Cogl to lazily allocate the storage of framebuffers but you should
-- be aware that if Cogl encounters an error (such as running out of
-- GPU memory) then your application will simply abort with an error
-- message. If you need to be able to catch such exceptions at runtime
-- then you can explicitly allocate your framebuffer when you have
-- finished configuring it by calling @/cogl_framebuffer_allocate()/@ and
-- passing in a @/CoglError/@ argument to catch any exceptions.
offscreenNewWithTexture ::
    (B.CallStack.HasCallStack, MonadIO m, Cogl.Texture.IsTexture a) =>
    a
    -- ^ /@texture@/: A @/CoglTexture/@ pointer
    -> m Offscreen
    -- ^ __Returns:__ a newly instantiated t'GI.Cogl.Objects.Offscreen.Offscreen'
    --   framebuffer.
offscreenNewWithTexture :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTexture a) =>
a -> m Offscreen
offscreenNewWithTexture a
texture = IO Offscreen -> m Offscreen
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Offscreen -> m Offscreen) -> IO Offscreen -> m Offscreen
forall a b. (a -> b) -> a -> b
$ do
    Ptr Texture
texture' <- a -> IO (Ptr Texture)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
texture
    Ptr Offscreen
result <- Ptr Texture -> IO (Ptr Offscreen)
cogl_offscreen_new_with_texture Ptr Texture
texture'
    Text -> Ptr Offscreen -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"offscreenNewWithTexture" Ptr Offscreen
result
    Offscreen
result' <- ((ManagedPtr Offscreen -> Offscreen)
-> Ptr Offscreen -> IO Offscreen
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr Offscreen -> Offscreen
Offscreen) Ptr Offscreen
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
texture
    Offscreen -> IO Offscreen
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Offscreen
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method Offscreen::ref
-- method type : MemberFunction
-- Args: [ Arg
--           { argCName = "offscreen"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A pointer to a #CoglOffscreen framebuffer"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TPtr)
-- throws : False
-- Skip return : False

foreign import ccall "cogl_offscreen_ref" cogl_offscreen_ref :: 
    Ptr () ->                               -- offscreen : TBasicType TPtr
    IO (Ptr ())

{-# DEPRECATED offscreenRef ["(Since version 1.2)","@/cogl_object_ref()/@ should be used in new code."] #-}
-- | Increments the reference count on the /@offscreen@/ framebuffer.
offscreenRef ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Ptr ()
    -- ^ /@offscreen@/: A pointer to a t'GI.Cogl.Objects.Offscreen.Offscreen' framebuffer
    -> m (Ptr ())
    -- ^ __Returns:__ For convenience it returns the
    --                                given /@offscreen@/
offscreenRef :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Ptr () -> m (Ptr ())
offscreenRef Ptr ()
offscreen = IO (Ptr ()) -> m (Ptr ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
forall a b. (a -> b) -> a -> b
$ do
    Ptr ()
result <- Ptr () -> IO (Ptr ())
cogl_offscreen_ref Ptr ()
offscreen
    Ptr () -> IO (Ptr ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr ()
result

#if defined(ENABLE_OVERLOADING)
#endif

-- method Offscreen::unref
-- method type : MemberFunction
-- Args: [ Arg
--           { argCName = "offscreen"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A pointer to a #CoglOffscreen framebuffer"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "cogl_offscreen_unref" cogl_offscreen_unref :: 
    Ptr () ->                               -- offscreen : TBasicType TPtr
    IO ()

{-# DEPRECATED offscreenUnref ["(Since version 1.2)","@/cogl_object_unref()/@ should be used in new code."] #-}
-- | Decreases the reference count for the /@offscreen@/ buffer and frees it when
-- the count reaches 0.
offscreenUnref ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Ptr ()
    -- ^ /@offscreen@/: A pointer to a t'GI.Cogl.Objects.Offscreen.Offscreen' framebuffer
    -> m ()
offscreenUnref :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Ptr () -> m ()
offscreenUnref Ptr ()
offscreen = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr () -> IO ()
cogl_offscreen_unref Ptr ()
offscreen
    () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
#endif