Blame gst-libs/gst/gl/gstglbasememory.h

Packit 971217
/*
Packit 971217
 * GStreamer
Packit 971217
 * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifndef _GST_GL_BASE_MEMORY_H_
Packit 971217
#define _GST_GL_BASE_MEMORY_H_
Packit 971217
Packit 971217
#include <gst/gst.h>
Packit 971217
#include <gst/gstallocator.h>
Packit 971217
#include <gst/gstmemory.h>
Packit 971217
Packit 971217
#include <gst/gl/gstgl_fwd.h>
Packit 971217
Packit 971217
G_BEGIN_DECLS
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_GL_BASE_MEMORY_ERROR:
Packit 971217
 *
Packit 971217
 * Error domain for GStreamer's GL memory module. Errors in this domain will be
Packit 971217
 * from the #GstGLBaseMemoryError enumeration
Packit 971217
 */
Packit 971217
#define GST_TYPE_GL_BASE_MEMORY (gst_gl_base_memory_get_type())
Packit 971217
GST_GL_API
Packit 971217
GType gst_gl_base_memory_get_type(void);
Packit 971217
Packit 971217
#define GST_TYPE_GL_BASE_MEMORY_ALLOCATOR (gst_gl_base_memory_allocator_get_type())
Packit 971217
GST_GL_API
Packit 971217
GType gst_gl_base_memory_allocator_get_type(void);
Packit 971217
Packit 971217
#define GST_IS_GL_BASE_MEMORY_ALLOCATOR(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR))
Packit 971217
#define GST_IS_GL_BASE_MEMORY_ALLOCATOR_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR))
Packit 971217
#define GST_GL_BASE_MEMORY_ALLOCATOR_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR, GstGLBaseMemoryAllocatorClass))
Packit 971217
#define GST_GL_BASE_MEMORY_ALLOCATOR(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR, GstGLBaseMemoryAllocator))
Packit 971217
#define GST_GL_BASE_MEMORY_ALLOCATOR_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR, GstGLBaseMemoryAllocatorClass))
Packit 971217
#define GST_GL_BASE_MEMORY_ALLOCATOR_CAST(obj)            ((GstGLBaseMemoryAllocator *)(obj))
Packit 971217
Packit 971217
#define GST_GL_BASE_MEMORY_CAST(mem) ((GstGLBaseMemory *)mem)
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
GQuark gst_gl_base_memory_error_quark (void);
Packit 971217
#define GST_GL_BASE_MEMORY_ERROR (gst_gl_base_memory_error_quark ())
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryError:
Packit 971217
 * @GST_GL_BASE_MEMORY_ERROR_FAILED: generic faliure
Packit 971217
 * @GST_GL_BASE_MEMORY_ERROR_OLD_LIBS: the implementation is too old and doesn't
Packit 971217
 *                                     implement enough features
Packit 971217
 * @GST_GL_BASE_MEMORY_ERROR_RESOURCE_UNAVAILABLE: a resource could not be found
Packit 971217
 */
Packit 971217
typedef enum
Packit 971217
{
Packit 971217
  GST_GL_BASE_MEMORY_ERROR_FAILED,
Packit 971217
  GST_GL_BASE_MEMORY_ERROR_OLD_LIBS,
Packit 971217
  GST_GL_BASE_MEMORY_ERROR_RESOURCE_UNAVAILABLE,
Packit 971217
} GstGLBaseMemoryError;
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryTransfer:
Packit 971217
 * @GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD: the texture needs downloading
Packit 971217
 *                                             to the data pointer
Packit 971217
 * @GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD:   the data pointer needs uploading
Packit 971217
 *                                             to the texture
Packit 971217
 */
Packit 971217
typedef enum
Packit 971217
{
Packit 971217
  GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD   = (GST_MEMORY_FLAG_LAST << 0),
Packit 971217
  GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD     = (GST_MEMORY_FLAG_LAST << 1)
Packit 971217
} GstGLBaseMemoryTransfer;
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_MAP_GL:
Packit 971217
 *
Packit 971217
 * Flag indicating that we should map the GL object instead of to system memory.
Packit 971217
 *
Packit 971217
 * Combining #GST_MAP_GL with #GST_MAP_WRITE has the same semantics as though
Packit 971217
 * you are writing to OpenGL. Conversely, combining #GST_MAP_GL with
Packit 971217
 * #GST_MAP_READ has the same semantics as though you are reading from OpenGL.
Packit 971217
 */
Packit 971217
#define GST_MAP_GL (GST_MAP_FLAG_LAST << 1)
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemory:
Packit 971217
 * @mem: the parent object
Packit 971217
 * @context: the #GstGLContext to use for GL operations
Packit 971217
 *
Packit 971217
 * Represents information about a GL memory object
Packit 971217
 */
Packit 971217
struct _GstGLBaseMemory
Packit 971217
{
Packit 971217
  GstMemory             mem;
Packit 971217
Packit 971217
  GstGLContext         *context;
Packit 971217
Packit 971217
  /* <protected> */
Packit 971217
  GMutex                lock;
Packit 971217
Packit 971217
  GstMapFlags           map_flags;       /* cumulative map flags */
Packit 971217
  gint                  map_count;
Packit 971217
  gint                  gl_map_count;
Packit 971217
Packit 971217
  gpointer              data;
Packit 971217
Packit 971217
  GstGLQuery           *query;
Packit 971217
Packit 971217
  /* <private> */
Packit 971217
  gsize                 alloc_size;     /* because maxsize is used for mapping */
Packit 971217
  gpointer              alloc_data;
Packit 971217
Packit 971217
  GDestroyNotify        notify;
Packit 971217
  gpointer              user_data;
Packit 971217
Packit 971217
  gpointer              _padding[GST_PADDING];
Packit 971217
};
Packit 971217
Packit 971217
typedef struct _GstGLAllocationParams GstGLAllocationParams;
Packit 971217
/**
Packit 971217
 * GstGLAllocationParamsCopyFunc:
Packit 971217
 * @src: the source #GstGLAllocationParams to copy from
Packit 971217
 * @dest: the source #GstGLAllocationParams to copy
Packit 971217
 *
Packit 971217
 * Copies the parameters from @src into @dest.  The subclass must compose copy
Packit 971217
 * functions from the superclass.
Packit 971217
 */
Packit 971217
typedef void    (*GstGLAllocationParamsCopyFunc)    (GstGLAllocationParams * src, GstGLAllocationParams * dest);
Packit 971217
/**
Packit 971217
 * GstGLAllocationParamsFreeFunc:
Packit 971217
 * @params: a #GstGLAllocationParams
Packit 971217
 *
Packit 971217
 * Free any dynamically allocated data.  The subclass must call the superclass'
Packit 971217
 * free.
Packit 971217
 */
Packit 971217
typedef void    (*GstGLAllocationParamsFreeFunc)    (gpointer params);
Packit 971217
Packit 971217
#define GST_TYPE_GL_ALLOCATION_PARAMS (gst_gl_allocation_params_get_type())
Packit 971217
GST_GL_API
Packit 971217
GType gst_gl_allocation_params_get_type (void);
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_ALLOC:
Packit 971217
 *
Packit 971217
 * GL Allocation flag indicating that the implementation should allocate the
Packit 971217
 * necessary resources.
Packit 971217
 */
Packit 971217
#define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_ALLOC (1 << 0)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM:
Packit 971217
 *
Packit 971217
 * GL Allocation flag for using the provided system memory data as storage.
Packit 971217
 */
Packit 971217
#define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM (1 << 1)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE:
Packit 971217
 *
Packit 971217
 * GL Allocation flag for using the provided GPU handle as storage.
Packit 971217
 */
Packit 971217
#define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE (1 << 2)
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_USER:
Packit 971217
 *
Packit 971217
 * Values >= than #GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_USER can be used for
Packit 971217
 * user-defined purposes.
Packit 971217
 */
Packit 971217
#define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_USER (1 << 16)
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLAllocationParams:
Packit 971217
 * @struct_size: the size of the struct (including and subclass data)
Packit 971217
 * @copy: a #GstGLAllocationParamsCopyFunc
Packit 971217
 * @free: a #GstGLAllocationParamsFreeFunc
Packit 971217
 * @alloc_flags: allocation flags
Packit 971217
 * @alloc_size: the allocation size
Packit 971217
 * @alloc_params: the #GstAllocationParams
Packit 971217
 * @context: a #GstGLContext
Packit 971217
 * @notify: a #GDestroyNotify
Packit 971217
 * @user_data: argument to call @notify with
Packit 971217
 * @wrapped_data: the wrapped data pointer
Packit 971217
 * @gl_handle: the wrapped OpenGL handle
Packit 971217
 */
Packit 971217
/* Because GstAllocationParams is not subclassable, start our own subclass
Packit 971217
 * chain.  FIXME: 2.0 make GstAllocationParams subclassable */
Packit 971217
struct _GstGLAllocationParams
Packit 971217
{
Packit 971217
  gsize                             struct_size;
Packit 971217
  GstGLAllocationParamsCopyFunc     copy;
Packit 971217
  GstGLAllocationParamsFreeFunc     free;
Packit 971217
Packit 971217
  guint                             alloc_flags;
Packit 971217
  gsize                             alloc_size;
Packit 971217
  GstAllocationParams              *alloc_params;
Packit 971217
  GstGLContext                     *context;
Packit 971217
  GDestroyNotify                    notify;
Packit 971217
  gpointer                          user_data;
Packit 971217
Packit 971217
  /* GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM only */
Packit 971217
  gpointer                          wrapped_data;
Packit 971217
  /* GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE only */
Packit 971217
  gpointer                          gl_handle;
Packit 971217
Packit 971217
  /* <private> */
Packit 971217
  gpointer                          _padding[GST_PADDING];
Packit 971217
};
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
gboolean                gst_gl_allocation_params_init       (GstGLAllocationParams * params,
Packit 971217
                                                             gsize struct_size,
Packit 971217
                                                             guint alloc_flags,
Packit 971217
                                                             GstGLAllocationParamsCopyFunc copy,
Packit 971217
                                                             GstGLAllocationParamsFreeFunc free,
Packit 971217
                                                             GstGLContext * context,
Packit 971217
                                                             gsize alloc_size,
Packit 971217
                                                             GstAllocationParams * alloc_params,
Packit 971217
                                                             gpointer wrapped_data,
Packit 971217
                                                             gpointer gl_handle,
Packit 971217
                                                             gpointer user_data,
Packit 971217
                                                             GDestroyNotify notify);
Packit 971217
Packit 971217
/* free with gst_gl_allocation_params_free */
Packit 971217
GST_GL_API
Packit 971217
GstGLAllocationParams * gst_gl_allocation_params_copy       (GstGLAllocationParams * src);
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
void                    gst_gl_allocation_params_free       (GstGLAllocationParams * params);
Packit 971217
Packit 971217
/* subclass usage */
Packit 971217
GST_GL_API
Packit 971217
void                    gst_gl_allocation_params_free_data  (GstGLAllocationParams * params);
Packit 971217
Packit 971217
/* subclass usage */
Packit 971217
GST_GL_API
Packit 971217
void                    gst_gl_allocation_params_copy_data  (GstGLAllocationParams * src,
Packit 971217
                                                             GstGLAllocationParams * dest);
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryAllocatorAllocFunction:
Packit 971217
 * @allocator: a #GstGLBaseMemoryAllocator
Packit 971217
 * @params: the #GstGLAllocationParams to allocate the memory with
Packit 971217
 *
Packit 971217
 * Note: not called with a GL context current
Packit 971217
 *
Packit 971217
 * Returns: a newly allocated #GstGLBaseMemory from @allocator and @params
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
typedef GstGLBaseMemory *   (*GstGLBaseMemoryAllocatorAllocFunction)        (GstGLBaseMemoryAllocator * allocator,
Packit 971217
                                                                             GstGLAllocationParams * params);
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryAllocatorCreateFunction:
Packit 971217
 * @mem: a #GstGLBaseMemory
Packit 971217
 * @error: a #GError to use on failure
Packit 971217
 *
Packit 971217
 * As this virtual method is called with an OpenGL context current, use this
Packit 971217
 * function to allocate and OpenGL resources needed for your application
Packit 971217
 *
Packit 971217
 * Returns: whether the creation succeeded
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
typedef gboolean            (*GstGLBaseMemoryAllocatorCreateFunction)       (GstGLBaseMemory * mem,
Packit 971217
                                                                             GError ** error);
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryAllocatorMapFunction:
Packit 971217
 * @mem: a #GstGLBaseMemory
Packit 971217
 * @info: a #GstMapInfo to map with
Packit 971217
 * @maxsize: the size to map
Packit 971217
 *
Packit 971217
 * Also see gst_memory_map();
Packit 971217
 *
Packit 971217
 * Returns: the mapped pointer
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
typedef gpointer            (*GstGLBaseMemoryAllocatorMapFunction)          (GstGLBaseMemory * mem,
Packit 971217
                                                                             GstMapInfo * info,
Packit 971217
                                                                             gsize maxsize);
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryAllocatorUnmapFunction:
Packit 971217
 * @mem: a #GstGLBaseMemory
Packit 971217
 * @info: a #GstMapInfo to map with
Packit 971217
 *
Packit 971217
 * Also see gst_memory_unmap();
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
typedef void                (*GstGLBaseMemoryAllocatorUnmapFunction)        (GstGLBaseMemory * mem,
Packit 971217
                                                                             GstMapInfo * info);
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryAllocatorCopyFunction:
Packit 971217
 * @mem: a #GstGLBaseMemory
Packit 971217
 * @offset: the offset to copy from
Packit 971217
 * @size: the number of bytes to copy
Packit 971217
 *
Packit 971217
 * Also see gst_memory_copy();
Packit 971217
 *
Packit 971217
 * Returns: the newly copied #GstGLMemory or %NULL
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
typedef GstGLBaseMemory *   (*GstGLBaseMemoryAllocatorCopyFunction)         (GstGLBaseMemory * mem,
Packit 971217
                                                                             gssize offset,
Packit 971217
                                                                             gssize size);
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryAllocatorDestroyFunction:
Packit 971217
 * @mem: a #GstGLBaseMemory
Packit 971217
 *
Packit 971217
 * Destroy any resources allocated throughout the lifetime of @mem
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
typedef void                (*GstGLBaseMemoryAllocatorDestroyFunction)      (GstGLBaseMemory * mem);
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryAllocator
Packit 971217
 *
Packit 971217
 * Opaque #GstGLBaseMemoryAllocator struct
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
struct _GstGLBaseMemoryAllocator
Packit 971217
{
Packit 971217
  /*< private >*/
Packit 971217
  GstAllocator parent;
Packit 971217
  GstMemoryCopyFunction fallback_mem_copy;
Packit 971217
Packit 971217
  gpointer _padding[GST_PADDING];
Packit 971217
};
Packit 971217
Packit 971217
/**
Packit 971217
 * GstGLBaseMemoryAllocatorClass:
Packit 971217
 * @parent_class: the parent class
Packit 971217
 * @alloc: a #GstGLBaseMemoryAllocatorAllocFunction
Packit 971217
 * @create: a #GstGLBaseMemoryAllocatorCreateFunction
Packit 971217
 * @map: a #GstGLBaseMemoryAllocatorMapFunction
Packit 971217
 * @unmap: a #GstGLBaseMemoryAllocatorUnmapFunction
Packit 971217
 * @copy: a #GstGLBaseMemoryAllocatorCopyFunction
Packit 971217
 * @destroy: a #GstGLBaseMemoryAllocatorDestroyFunction
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
struct _GstGLBaseMemoryAllocatorClass
Packit 971217
{
Packit 971217
  GstAllocatorClass parent_class;
Packit 971217
Packit 971217
  GstGLBaseMemoryAllocatorAllocFunction         alloc;
Packit 971217
Packit 971217
  GstGLBaseMemoryAllocatorCreateFunction        create;
Packit 971217
  GstGLBaseMemoryAllocatorMapFunction           map;
Packit 971217
  GstGLBaseMemoryAllocatorUnmapFunction         unmap;
Packit 971217
  GstGLBaseMemoryAllocatorCopyFunction          copy;
Packit 971217
  GstGLBaseMemoryAllocatorDestroyFunction       destroy;
Packit 971217
  /* <private> */
Packit 971217
Packit 971217
  gpointer                                      _padding[GST_PADDING];
Packit 971217
};
Packit 971217
Packit 971217
#include <gst/gl/gstglconfig.h>
Packit 971217
#include <gst/gl/gstglformat.h>
Packit 971217
Packit 971217
/**
Packit 971217
 * GST_GL_BASE_MEMORY_ALLOCATOR_NAME:
Packit 971217
 *
Packit 971217
 * The name of the GL buffer allocator
Packit 971217
 *
Packit 971217
 * Since: 1.8
Packit 971217
 */
Packit 971217
#define GST_GL_BASE_MEMORY_ALLOCATOR_NAME   "GLBaseMemory"
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
void          gst_gl_base_memory_init_once (void);
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
gboolean      gst_is_gl_base_memory        (GstMemory * mem);
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
void          gst_gl_base_memory_init      (GstGLBaseMemory * mem,
Packit 971217
                                            GstAllocator * allocator,
Packit 971217
                                            GstMemory * parent,
Packit 971217
                                            GstGLContext * context,
Packit 971217
                                            GstAllocationParams * params,
Packit 971217
                                            gsize size,
Packit 971217
                                            gpointer user_data,
Packit 971217
                                            GDestroyNotify notify);
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
gboolean      gst_gl_base_memory_alloc_data (GstGLBaseMemory * gl_mem);
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
gboolean      gst_gl_base_memory_memcpy     (GstGLBaseMemory * src,
Packit 971217
                                             GstGLBaseMemory * dest,
Packit 971217
                                             gssize offset,
Packit 971217
                                             gssize size);
Packit 971217
Packit 971217
GST_GL_API
Packit 971217
GstGLBaseMemory *   gst_gl_base_memory_alloc    (GstGLBaseMemoryAllocator * allocator,
Packit 971217
                                                 GstGLAllocationParams * params);
Packit 971217
Packit 971217
G_END_DECLS
Packit 971217
Packit 971217
#endif /* _GST_GL_BUFFER_H_ */