3 * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #ifndef _GST_GL_BASE_MEMORY_H_
22 #define _GST_GL_BASE_MEMORY_H_
25 #include <gst/gstallocator.h>
26 #include <gst/gstmemory.h>
28 #include <gst/gl/gstgl_fwd.h>
33 * GST_TYPE_GL_BASE_MEMORY:
35 * Deprecated: 1.22: This type has no use.
37 #define GST_TYPE_GL_BASE_MEMORY (gst_gl_base_memory_get_type())
39 GType gst_gl_base_memory_get_type(void);
41 #define GST_TYPE_GL_BASE_MEMORY_ALLOCATOR (gst_gl_base_memory_allocator_get_type())
43 GType gst_gl_base_memory_allocator_get_type(void);
45 #define GST_IS_GL_BASE_MEMORY_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR))
46 #define GST_IS_GL_BASE_MEMORY_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR))
47 #define GST_GL_BASE_MEMORY_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR, GstGLBaseMemoryAllocatorClass))
48 #define GST_GL_BASE_MEMORY_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR, GstGLBaseMemoryAllocator))
49 #define GST_GL_BASE_MEMORY_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_GL_BASE_MEMORY_ALLOCATOR, GstGLBaseMemoryAllocatorClass))
50 #define GST_GL_BASE_MEMORY_ALLOCATOR_CAST(obj) ((GstGLBaseMemoryAllocator *)(obj))
52 #define GST_GL_BASE_MEMORY_CAST(mem) ((GstGLBaseMemory *)mem)
55 GQuark gst_gl_base_memory_error_quark (void);
57 * GST_GL_BASE_MEMORY_ERROR:
59 * Error domain for GStreamer's GL memory module. Errors in this domain will be
60 * from the #GstGLBaseMemoryError enumeration
62 #define GST_GL_BASE_MEMORY_ERROR (gst_gl_base_memory_error_quark ())
65 * GstGLBaseMemoryError:
66 * @GST_GL_BASE_MEMORY_ERROR_FAILED: generic failure
67 * @GST_GL_BASE_MEMORY_ERROR_OLD_LIBS: the implementation is too old and doesn't
68 * implement enough features
69 * @GST_GL_BASE_MEMORY_ERROR_RESOURCE_UNAVAILABLE: a resource could not be found
73 GST_GL_BASE_MEMORY_ERROR_FAILED,
74 GST_GL_BASE_MEMORY_ERROR_OLD_LIBS,
75 GST_GL_BASE_MEMORY_ERROR_RESOURCE_UNAVAILABLE,
76 } GstGLBaseMemoryError;
79 * GstGLBaseMemoryTransfer:
80 * @GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD: the texture needs downloading
82 * @GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD: the data pointer needs uploading
87 GST_GL_BASE_MEMORY_TRANSFER_NEED_DOWNLOAD = (GST_MEMORY_FLAG_LAST << 0),
88 GST_GL_BASE_MEMORY_TRANSFER_NEED_UPLOAD = (GST_MEMORY_FLAG_LAST << 1)
89 } GstGLBaseMemoryTransfer;
94 * Flag indicating that we should map the GL object instead of to system memory.
96 * Combining #GST_MAP_GL with #GST_MAP_WRITE has the same semantics as though
97 * you are writing to OpenGL. Conversely, combining #GST_MAP_GL with
98 * #GST_MAP_READ has the same semantics as though you are reading from OpenGL.
100 #define GST_MAP_GL (GST_MAP_FLAG_LAST << 1)
104 * @mem: the parent object
105 * @context: the #GstGLContext to use for GL operations
107 * Represents information about a GL memory object
109 struct _GstGLBaseMemory
113 GstGLContext *context;
118 GstMapFlags map_flags; /* cumulative map flags */
127 gsize alloc_size; /* because maxsize is used for mapping */
130 GDestroyNotify notify;
133 gpointer _padding[GST_PADDING];
136 typedef struct _GstGLAllocationParams GstGLAllocationParams;
138 * GstGLAllocationParamsCopyFunc:
139 * @src: the source #GstGLAllocationParams to copy from
140 * @dest: the source #GstGLAllocationParams to copy
142 * Copies the parameters from @src into @dest. The subclass must compose copy
143 * functions from the superclass.
145 typedef void (*GstGLAllocationParamsCopyFunc) (GstGLAllocationParams * src, GstGLAllocationParams * dest);
147 * GstGLAllocationParamsFreeFunc:
148 * @params: a #GstGLAllocationParams
150 * Free any dynamically allocated data. The subclass must call the superclass'
153 typedef void (*GstGLAllocationParamsFreeFunc) (gpointer params);
155 #define GST_TYPE_GL_ALLOCATION_PARAMS (gst_gl_allocation_params_get_type())
157 GType gst_gl_allocation_params_get_type (void);
160 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_ALLOC:
162 * GL Allocation flag indicating that the implementation should allocate the
163 * necessary resources.
165 #define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_ALLOC (1 << 0)
168 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM:
170 * GL Allocation flag for using the provided system memory data as storage.
172 #define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM (1 << 1)
175 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE:
177 * GL Allocation flag for using the provided GPU handle as storage.
179 #define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE (1 << 2)
182 * GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_USER:
184 * Values >= than #GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_USER can be used for
185 * user-defined purposes.
187 #define GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_USER (1 << 16)
190 * GstGLAllocationParams:
191 * @struct_size: the size of the struct (including and subclass data)
192 * @copy: a #GstGLAllocationParamsCopyFunc
193 * @free: a #GstGLAllocationParamsFreeFunc
194 * @alloc_flags: allocation flags
195 * @alloc_size: the allocation size
196 * @alloc_params: the #GstAllocationParams
197 * @context: a #GstGLContext
198 * @notify: a #GDestroyNotify
199 * @user_data: argument to call @notify with
200 * @wrapped_data: the wrapped data pointer
201 * @gl_handle: the wrapped OpenGL handle
203 /* Because GstAllocationParams is not subclassable, start our own subclass
204 * chain. FIXME: 2.0 make GstAllocationParams subclassable */
205 struct _GstGLAllocationParams
208 GstGLAllocationParamsCopyFunc copy;
209 GstGLAllocationParamsFreeFunc free;
213 GstAllocationParams *alloc_params;
214 GstGLContext *context;
215 GDestroyNotify notify;
218 /* GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_SYSMEM only */
219 gpointer wrapped_data;
220 /* GST_GL_ALLOCATION_PARAMS_ALLOC_FLAG_WRAP_GPU_HANDLE only */
224 gpointer _padding[GST_PADDING];
228 gboolean gst_gl_allocation_params_init (GstGLAllocationParams * params,
231 GstGLAllocationParamsCopyFunc copy,
232 GstGLAllocationParamsFreeFunc free,
233 GstGLContext * context,
235 const GstAllocationParams * alloc_params,
236 gpointer wrapped_data,
239 GDestroyNotify notify);
241 /* free with gst_gl_allocation_params_free */
243 GstGLAllocationParams * gst_gl_allocation_params_copy (GstGLAllocationParams * src);
246 void gst_gl_allocation_params_free (GstGLAllocationParams * params);
250 void gst_gl_allocation_params_free_data (GstGLAllocationParams * params);
254 void gst_gl_allocation_params_copy_data (GstGLAllocationParams * src,
255 GstGLAllocationParams * dest);
258 * GstGLBaseMemoryAllocatorAllocFunction:
259 * @allocator: a #GstGLBaseMemoryAllocator
260 * @params: the #GstGLAllocationParams to allocate the memory with
262 * Note: not called with a GL context current
264 * Returns: a newly allocated #GstGLBaseMemory from @allocator and @params
268 typedef GstGLBaseMemory * (*GstGLBaseMemoryAllocatorAllocFunction) (GstGLBaseMemoryAllocator * allocator,
269 GstGLAllocationParams * params);
272 * GstGLBaseMemoryAllocatorCreateFunction:
273 * @mem: a #GstGLBaseMemory
274 * @error: a #GError to use on failure
276 * As this virtual method is called with an OpenGL context current, use this
277 * function to allocate and OpenGL resources needed for your application
279 * Returns: whether the creation succeeded
283 typedef gboolean (*GstGLBaseMemoryAllocatorCreateFunction) (GstGLBaseMemory * mem,
287 * GstGLBaseMemoryAllocatorMapFunction:
288 * @mem: a #GstGLBaseMemory
289 * @info: a #GstMapInfo to map with
290 * @maxsize: the size to map
292 * Also see gst_memory_map();
294 * Returns: the mapped pointer
298 typedef gpointer (*GstGLBaseMemoryAllocatorMapFunction) (GstGLBaseMemory * mem,
302 * GstGLBaseMemoryAllocatorUnmapFunction:
303 * @mem: a #GstGLBaseMemory
304 * @info: a #GstMapInfo to map with
306 * Also see gst_memory_unmap();
310 typedef void (*GstGLBaseMemoryAllocatorUnmapFunction) (GstGLBaseMemory * mem,
314 * GstGLBaseMemoryAllocatorCopyFunction:
315 * @mem: a #GstGLBaseMemory
316 * @offset: the offset to copy from
317 * @size: the number of bytes to copy
319 * Also see gst_memory_copy();
321 * Returns: the newly copied #GstGLMemory or %NULL
325 typedef GstGLBaseMemory * (*GstGLBaseMemoryAllocatorCopyFunction) (GstGLBaseMemory * mem,
330 * GstGLBaseMemoryAllocatorDestroyFunction:
331 * @mem: a #GstGLBaseMemory
333 * Destroy any resources allocated throughout the lifetime of @mem
337 typedef void (*GstGLBaseMemoryAllocatorDestroyFunction) (GstGLBaseMemory * mem);
340 * GstGLBaseMemoryAllocator:
342 * Opaque #GstGLBaseMemoryAllocator struct
346 struct _GstGLBaseMemoryAllocator
350 GstMemoryCopyFunction fallback_mem_copy;
352 gpointer _padding[GST_PADDING];
356 * GstGLBaseMemoryAllocatorClass:
357 * @parent_class: the parent class
358 * @alloc: a #GstGLBaseMemoryAllocatorAllocFunction
359 * @create: a #GstGLBaseMemoryAllocatorCreateFunction
360 * @map: a #GstGLBaseMemoryAllocatorMapFunction
361 * @unmap: a #GstGLBaseMemoryAllocatorUnmapFunction
362 * @copy: a #GstGLBaseMemoryAllocatorCopyFunction
363 * @destroy: a #GstGLBaseMemoryAllocatorDestroyFunction
367 struct _GstGLBaseMemoryAllocatorClass
369 GstAllocatorClass parent_class;
371 GstGLBaseMemoryAllocatorAllocFunction alloc;
373 GstGLBaseMemoryAllocatorCreateFunction create;
374 GstGLBaseMemoryAllocatorMapFunction map;
375 GstGLBaseMemoryAllocatorUnmapFunction unmap;
376 GstGLBaseMemoryAllocatorCopyFunction copy;
377 GstGLBaseMemoryAllocatorDestroyFunction destroy;
380 gpointer _padding[GST_PADDING];
383 #include <gst/gl/gstglconfig.h>
384 #include <gst/gl/gstglformat.h>
387 * GST_GL_BASE_MEMORY_ALLOCATOR_NAME:
389 * The name of the GL buffer allocator
393 #define GST_GL_BASE_MEMORY_ALLOCATOR_NAME "GLBaseMemory"
396 void gst_gl_base_memory_init_once (void);
399 gboolean gst_is_gl_base_memory (GstMemory * mem);
402 void gst_gl_base_memory_init (GstGLBaseMemory * mem,
403 GstAllocator * allocator,
405 GstGLContext * context,
406 const GstAllocationParams * params,
409 GDestroyNotify notify);
412 gboolean gst_gl_base_memory_alloc_data (GstGLBaseMemory * gl_mem);
415 gboolean gst_gl_base_memory_memcpy (GstGLBaseMemory * src,
416 GstGLBaseMemory * dest,
421 GstGLBaseMemory * gst_gl_base_memory_alloc (GstGLBaseMemoryAllocator * allocator,
422 GstGLAllocationParams * params);
426 #endif /* _GST_GL_BUFFER_H_ */