{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- 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.Gdk.Objects.GLTexture
    ( 

-- * Exported types
    GLTexture(..)                           ,
    IsGLTexture                             ,
    toGLTexture                             ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveGLTextureMethod                  ,
#endif


-- ** new #method:new#

    gLTextureNew                            ,


-- ** release #method:release#

#if defined(ENABLE_OVERLOADING)
    GLTextureReleaseMethodInfo              ,
#endif
    gLTextureRelease                        ,




    ) 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.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
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.Text as T
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 GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gdk.Interfaces.Paintable as Gdk.Paintable
import {-# SOURCE #-} qualified GI.Gdk.Objects.GLContext as Gdk.GLContext
import {-# SOURCE #-} qualified GI.Gdk.Objects.Texture as Gdk.Texture

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

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

foreign import ccall "gdk_gl_texture_get_type"
    c_gdk_gl_texture_get_type :: IO B.Types.GType

instance B.Types.TypedObject GLTexture where
    glibType :: IO GType
glibType = IO GType
c_gdk_gl_texture_get_type

instance B.Types.GObject GLTexture

-- | Convert 'GLTexture' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue GLTexture where
    toGValue :: GLTexture -> IO GValue
toGValue GLTexture
o = do
        GType
gtype <- IO GType
c_gdk_gl_texture_get_type
        GLTexture -> (Ptr GLTexture -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr GLTexture
o (GType
-> (GValue -> Ptr GLTexture -> IO ()) -> Ptr GLTexture -> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr GLTexture -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
        
    fromGValue :: GValue -> IO GLTexture
fromGValue GValue
gv = do
        Ptr GLTexture
ptr <- GValue -> IO (Ptr GLTexture)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr GLTexture)
        (ManagedPtr GLTexture -> GLTexture)
-> Ptr GLTexture -> IO GLTexture
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr GLTexture -> GLTexture
GLTexture Ptr GLTexture
ptr
        
    

-- | Type class for types which can be safely cast to `GLTexture`, for instance with `toGLTexture`.
class (SP.GObject o, O.IsDescendantOf GLTexture o) => IsGLTexture o
instance (SP.GObject o, O.IsDescendantOf GLTexture o) => IsGLTexture o

instance O.HasParentTypes GLTexture
type instance O.ParentTypes GLTexture = '[Gdk.Texture.Texture, GObject.Object.Object, Gdk.Paintable.Paintable]

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

#if defined(ENABLE_OVERLOADING)
type family ResolveGLTextureMethod (t :: Symbol) (o :: *) :: * where
    ResolveGLTextureMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveGLTextureMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveGLTextureMethod "computeConcreteSize" o = Gdk.Paintable.PaintableComputeConcreteSizeMethodInfo
    ResolveGLTextureMethod "download" o = Gdk.Texture.TextureDownloadMethodInfo
    ResolveGLTextureMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveGLTextureMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveGLTextureMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveGLTextureMethod "invalidateContents" o = Gdk.Paintable.PaintableInvalidateContentsMethodInfo
    ResolveGLTextureMethod "invalidateSize" o = Gdk.Paintable.PaintableInvalidateSizeMethodInfo
    ResolveGLTextureMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveGLTextureMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveGLTextureMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveGLTextureMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveGLTextureMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveGLTextureMethod "release" o = GLTextureReleaseMethodInfo
    ResolveGLTextureMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveGLTextureMethod "saveToPng" o = Gdk.Texture.TextureSaveToPngMethodInfo
    ResolveGLTextureMethod "snapshot" o = Gdk.Paintable.PaintableSnapshotMethodInfo
    ResolveGLTextureMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveGLTextureMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveGLTextureMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveGLTextureMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveGLTextureMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveGLTextureMethod "getCurrentImage" o = Gdk.Paintable.PaintableGetCurrentImageMethodInfo
    ResolveGLTextureMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveGLTextureMethod "getFlags" o = Gdk.Paintable.PaintableGetFlagsMethodInfo
    ResolveGLTextureMethod "getHeight" o = Gdk.Texture.TextureGetHeightMethodInfo
    ResolveGLTextureMethod "getIntrinsicAspectRatio" o = Gdk.Paintable.PaintableGetIntrinsicAspectRatioMethodInfo
    ResolveGLTextureMethod "getIntrinsicHeight" o = Gdk.Paintable.PaintableGetIntrinsicHeightMethodInfo
    ResolveGLTextureMethod "getIntrinsicWidth" o = Gdk.Paintable.PaintableGetIntrinsicWidthMethodInfo
    ResolveGLTextureMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveGLTextureMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveGLTextureMethod "getWidth" o = Gdk.Texture.TextureGetWidthMethodInfo
    ResolveGLTextureMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveGLTextureMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveGLTextureMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveGLTextureMethod l o = O.MethodResolutionFailed l o

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

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList GLTexture
type instance O.AttributeList GLTexture = GLTextureAttributeList
type GLTextureAttributeList = ('[ '("height", Gdk.Texture.TextureHeightPropertyInfo), '("width", Gdk.Texture.TextureWidthPropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList GLTexture = GLTextureSignalList
type GLTextureSignalList = ('[ '("invalidateContents", Gdk.Paintable.PaintableInvalidateContentsSignalInfo), '("invalidateSize", Gdk.Paintable.PaintableInvalidateSizeSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method GLTexture::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "context"
--           , argType =
--               TInterface Name { namespace = "Gdk" , name = "GLContext" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GdkGLContext" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "id"
--           , argType = TBasicType TUInt
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the ID of a texture that was created with @context"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "width"
--           , argType = TBasicType TInt
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the nominal width of the texture"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "height"
--           , argType = TBasicType TInt
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the nominal height of the texture"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "destroy"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "DestroyNotify" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "a destroy notify that will be called when the GL resources\n          are released"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "data that gets passed to @destroy"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gdk" , name = "GLTexture" })
-- throws : False
-- Skip return : False

foreign import ccall "gdk_gl_texture_new" gdk_gl_texture_new :: 
    Ptr Gdk.GLContext.GLContext ->          -- context : TInterface (Name {namespace = "Gdk", name = "GLContext"})
    Word32 ->                               -- id : TBasicType TUInt
    Int32 ->                                -- width : TBasicType TInt
    Int32 ->                                -- height : TBasicType TInt
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- destroy : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    Ptr () ->                               -- data : TBasicType TPtr
    IO (Ptr GLTexture)

-- | Creates a new texture for an existing GL texture.
-- 
-- Note that the GL texture must not be modified until /@destroy@/ is called,
-- which will happen when the GdkTexture object is finalized, or due to
-- an explicit call of 'GI.Gdk.Objects.GLTexture.gLTextureRelease'.
gLTextureNew ::
    (B.CallStack.HasCallStack, MonadIO m, Gdk.GLContext.IsGLContext a) =>
    a
    -- ^ /@context@/: a t'GI.Gdk.Objects.GLContext.GLContext'
    -> Word32
    -- ^ /@id@/: the ID of a texture that was created with /@context@/
    -> Int32
    -- ^ /@width@/: the nominal width of the texture
    -> Int32
    -- ^ /@height@/: the nominal height of the texture
    -> GLib.Callbacks.DestroyNotify
    -- ^ /@destroy@/: a destroy notify that will be called when the GL resources
    --           are released
    -> Ptr ()
    -- ^ /@data@/: data that gets passed to /@destroy@/
    -> m GLTexture
    -- ^ __Returns:__ A newly-created t'GI.Gdk.Objects.Texture.Texture'
gLTextureNew :: a
-> Word32
-> Int32
-> Int32
-> DestroyNotify
-> Ptr ()
-> m GLTexture
gLTextureNew a
context Word32
id Int32
width Int32
height DestroyNotify
destroy Ptr ()
data_ = IO GLTexture -> m GLTexture
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO GLTexture -> m GLTexture) -> IO GLTexture -> m GLTexture
forall a b. (a -> b) -> a -> b
$ do
    Ptr GLContext
context' <- a -> IO (Ptr GLContext)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
context
    Ptr (FunPtr DestroyNotify)
ptrdestroy <- IO (Ptr (FunPtr DestroyNotify))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr GLib.Callbacks.C_DestroyNotify))
    FunPtr DestroyNotify
destroy' <- DestroyNotify -> IO (FunPtr DestroyNotify)
GLib.Callbacks.mk_DestroyNotify (Maybe (Ptr (FunPtr DestroyNotify))
-> DestroyNotify -> DestroyNotify
GLib.Callbacks.wrap_DestroyNotify (Ptr (FunPtr DestroyNotify) -> Maybe (Ptr (FunPtr DestroyNotify))
forall a. a -> Maybe a
Just Ptr (FunPtr DestroyNotify)
ptrdestroy) DestroyNotify
destroy)
    Ptr (FunPtr DestroyNotify) -> FunPtr DestroyNotify -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr DestroyNotify)
ptrdestroy FunPtr DestroyNotify
destroy'
    Ptr GLTexture
result <- Ptr GLContext
-> Word32
-> Int32
-> Int32
-> FunPtr DestroyNotify
-> Ptr ()
-> IO (Ptr GLTexture)
gdk_gl_texture_new Ptr GLContext
context' Word32
id Int32
width Int32
height FunPtr DestroyNotify
destroy' Ptr ()
data_
    Text -> Ptr GLTexture -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"gLTextureNew" Ptr GLTexture
result
    GLTexture
result' <- ((ManagedPtr GLTexture -> GLTexture)
-> Ptr GLTexture -> IO GLTexture
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr GLTexture -> GLTexture
GLTexture) Ptr GLTexture
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
context
    GLTexture -> IO GLTexture
forall (m :: * -> *) a. Monad m => a -> m a
return GLTexture
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method GLTexture::release
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Gdk" , name = "GLTexture" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GdkTexture wrapping a GL texture"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gdk_gl_texture_release" gdk_gl_texture_release :: 
    Ptr GLTexture ->                        -- self : TInterface (Name {namespace = "Gdk", name = "GLTexture"})
    IO ()

-- | Releases the GL resources held by a t'GI.Gdk.Objects.GLTexture.GLTexture' that
-- was created with 'GI.Gdk.Objects.GLTexture.gLTextureNew'.
-- 
-- The texture contents are still available via the
-- 'GI.Gdk.Objects.Texture.textureDownload' function, after this function
-- has been called.
gLTextureRelease ::
    (B.CallStack.HasCallStack, MonadIO m, IsGLTexture a) =>
    a
    -- ^ /@self@/: a t'GI.Gdk.Objects.Texture.Texture' wrapping a GL texture
    -> m ()
gLTextureRelease :: a -> m ()
gLTextureRelease a
self = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr GLTexture
self' <- a -> IO (Ptr GLTexture)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
self
    Ptr GLTexture -> IO ()
gdk_gl_texture_release Ptr GLTexture
self'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
self
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data GLTextureReleaseMethodInfo
instance (signature ~ (m ()), MonadIO m, IsGLTexture a) => O.MethodInfo GLTextureReleaseMethodInfo a signature where
    overloadedMethod = gLTextureRelease

#endif