2010-01-10 17:28:24 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
|
|
|
* Copyright (C)2010 Intel Corporation.
|
|
|
|
*
|
2014-02-22 01:28:54 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-03-01 12:56:10 +00:00
|
|
|
*
|
|
|
|
*
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Damien Lespiau <damien.lespiau@intel.com>
|
2010-07-05 15:14:00 +00:00
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-20 17:49:08 +00:00
|
|
|
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
|
2010-01-10 17:28:24 +00:00
|
|
|
#error "Only <cogl/cogl.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __COGL_BUFFER_H__
|
|
|
|
#define __COGL_BUFFER_H__
|
|
|
|
|
|
|
|
#include <cogl/cogl-types.h>
|
|
|
|
|
2018-11-23 07:42:05 +00:00
|
|
|
G_BEGIN_DECLS
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:cogl-buffer
|
2011-06-27 10:16:21 +00:00
|
|
|
* @short_description: Common buffer functions, including data upload APIs
|
2011-12-16 15:07:25 +00:00
|
|
|
* @stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
2011-06-27 10:16:21 +00:00
|
|
|
* The CoglBuffer API provides a common interface to manipulate
|
|
|
|
* buffers that have been allocated either via cogl_pixel_buffer_new()
|
|
|
|
* or cogl_attribute_buffer_new(). The API allows you to upload data
|
|
|
|
* to these buffers and define usage hints that help Cogl manage your
|
|
|
|
* buffer optimally.
|
|
|
|
*
|
|
|
|
* Data can either be uploaded by supplying a pointer and size so Cogl
|
|
|
|
* can copy your data, or you can mmap() a CoglBuffer and then you can
|
|
|
|
* copy data to the buffer directly.
|
|
|
|
*
|
|
|
|
* One of the most common uses for CoglBuffers is to upload texture
|
|
|
|
* data asynchronously since the ability to mmap the buffers into
|
|
|
|
* the CPU makes it possible for another thread to handle the IO
|
|
|
|
* of loading an image file and unpacking it into the mapped buffer
|
|
|
|
* without blocking other Cogl operations.
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
|
|
|
|
2016-06-16 20:32:04 +00:00
|
|
|
#if defined(__COGL_H_INSIDE__) && !defined(COGL_ENABLE_MUTTER_API) && \
|
|
|
|
!defined(COGL_GIR_SCANNING)
|
2013-10-09 12:31:12 +00:00
|
|
|
/* For the public C api we typedef interface types as void to avoid needing
|
|
|
|
* lots of casting in code and instead we will rely on runtime type checking
|
|
|
|
* for these objects. */
|
|
|
|
typedef void CoglBuffer;
|
|
|
|
#else
|
2010-05-27 22:40:40 +00:00
|
|
|
typedef struct _CoglBuffer CoglBuffer;
|
2013-10-09 12:31:12 +00:00
|
|
|
#define COGL_BUFFER(buffer) ((CoglBuffer *)(buffer))
|
|
|
|
#endif
|
2010-05-27 22:40:40 +00:00
|
|
|
|
2012-11-08 17:54:10 +00:00
|
|
|
#define COGL_BUFFER_ERROR (_cogl_buffer_error_domain ())
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CoglBufferError:
|
|
|
|
* @COGL_BUFFER_ERROR_MAP: A buffer could not be mapped either
|
|
|
|
* because the feature isn't supported or because a system
|
|
|
|
* limitation was hit.
|
|
|
|
*
|
|
|
|
* Error enumeration for #CoglBuffer
|
|
|
|
*
|
|
|
|
* Stability: unstable
|
|
|
|
*/
|
2018-12-19 08:04:25 +00:00
|
|
|
typedef enum /*< prefix=COGL_BUFFER_ERROR >*/
|
|
|
|
{
|
2014-04-11 08:18:17 +00:00
|
|
|
COGL_BUFFER_ERROR_MAP
|
2012-11-08 17:54:10 +00:00
|
|
|
} CoglBufferError;
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
_cogl_buffer_error_domain (void);
|
|
|
|
|
2010-01-10 17:28:24 +00:00
|
|
|
/**
|
|
|
|
* cogl_is_buffer:
|
2012-02-13 15:19:05 +00:00
|
|
|
* @object: a buffer object
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
2010-05-27 22:40:40 +00:00
|
|
|
* Checks whether @buffer is a buffer object.
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if the handle is a CoglBuffer, and %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2019-11-21 11:15:22 +00:00
|
|
|
COGL_EXPORT gboolean
|
2012-03-14 13:45:00 +00:00
|
|
|
cogl_is_buffer (void *object);
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_get_size:
|
2010-05-27 22:40:40 +00:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
|
|
|
* Retrieves the size of buffer
|
|
|
|
*
|
|
|
|
* Return value: the size of the buffer in bytes
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2019-11-21 11:15:22 +00:00
|
|
|
COGL_EXPORT unsigned int
|
2010-05-27 22:40:40 +00:00
|
|
|
cogl_buffer_get_size (CoglBuffer *buffer);
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CoglBufferUpdateHint:
|
|
|
|
* @COGL_BUFFER_UPDATE_HINT_STATIC: the buffer will not change over time
|
|
|
|
* @COGL_BUFFER_UPDATE_HINT_DYNAMIC: the buffer will change from time to time
|
|
|
|
* @COGL_BUFFER_UPDATE_HINT_STREAM: the buffer will be used once or a couple of
|
|
|
|
* times
|
|
|
|
*
|
2010-02-09 14:41:37 +00:00
|
|
|
* The update hint on a buffer allows the user to give some detail on how often
|
2010-01-10 17:28:24 +00:00
|
|
|
* the buffer data is going to be updated.
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2018-12-19 08:04:25 +00:00
|
|
|
typedef enum /*< prefix=COGL_BUFFER_UPDATE_HINT >*/
|
|
|
|
{
|
2010-01-10 17:28:24 +00:00
|
|
|
COGL_BUFFER_UPDATE_HINT_STATIC,
|
|
|
|
COGL_BUFFER_UPDATE_HINT_DYNAMIC,
|
|
|
|
COGL_BUFFER_UPDATE_HINT_STREAM
|
|
|
|
} CoglBufferUpdateHint;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_set_update_hint:
|
2010-05-27 22:40:40 +00:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 17:28:24 +00:00
|
|
|
* @hint: the new hint
|
|
|
|
*
|
2010-02-09 14:41:37 +00:00
|
|
|
* Sets the update hint on a buffer. See #CoglBufferUpdateHint for a description
|
2010-01-10 17:28:24 +00:00
|
|
|
* of the available hints.
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2019-11-21 11:15:22 +00:00
|
|
|
COGL_EXPORT void
|
2010-05-27 22:40:40 +00:00
|
|
|
cogl_buffer_set_update_hint (CoglBuffer *buffer,
|
2010-01-10 17:28:24 +00:00
|
|
|
CoglBufferUpdateHint hint);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_get_update_hint:
|
2010-05-27 22:40:40 +00:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
2010-02-09 14:41:37 +00:00
|
|
|
* Retrieves the update hints set using cogl_buffer_set_update_hint()
|
|
|
|
*
|
2010-01-10 17:28:24 +00:00
|
|
|
* Return value: the #CoglBufferUpdateHint currently used by the buffer
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2019-11-21 11:15:22 +00:00
|
|
|
COGL_EXPORT CoglBufferUpdateHint
|
2010-05-27 22:40:40 +00:00
|
|
|
cogl_buffer_get_update_hint (CoglBuffer *buffer);
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CoglBufferAccess:
|
|
|
|
* @COGL_BUFFER_ACCESS_READ: the buffer will be read
|
|
|
|
* @COGL_BUFFER_ACCESS_WRITE: the buffer will written to
|
|
|
|
* @COGL_BUFFER_ACCESS_READ_WRITE: the buffer will be used for both reading and
|
|
|
|
* writing
|
|
|
|
*
|
2010-02-09 14:41:37 +00:00
|
|
|
* The access hints for cogl_buffer_set_update_hint()
|
|
|
|
*
|
2010-01-10 17:28:24 +00:00
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2018-12-19 08:04:25 +00:00
|
|
|
typedef enum /*< prefix=COGL_BUFFER_ACCESS >*/
|
|
|
|
{
|
2010-01-10 17:28:24 +00:00
|
|
|
COGL_BUFFER_ACCESS_READ = 1 << 0,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE = 1 << 1,
|
2010-09-15 10:56:59 +00:00
|
|
|
COGL_BUFFER_ACCESS_READ_WRITE = COGL_BUFFER_ACCESS_READ | COGL_BUFFER_ACCESS_WRITE
|
2010-01-10 17:28:24 +00:00
|
|
|
} CoglBufferAccess;
|
|
|
|
|
2010-07-05 15:14:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CoglBufferMapHint:
|
2010-12-22 09:42:41 +00:00
|
|
|
* @COGL_BUFFER_MAP_HINT_DISCARD: Tells Cogl that you plan to replace
|
2012-10-17 20:28:45 +00:00
|
|
|
* all the buffer's contents. When this flag is used to map a
|
|
|
|
* buffer, the entire contents of the buffer become undefined, even
|
|
|
|
* if only a subregion of the buffer is mapped.
|
|
|
|
* @COGL_BUFFER_MAP_HINT_DISCARD_RANGE: Tells Cogl that you plan to
|
|
|
|
* replace all the contents of the mapped region. The contents of
|
|
|
|
* the region specified are undefined after this flag is used to
|
|
|
|
* map a buffer.
|
2010-07-05 15:14:00 +00:00
|
|
|
*
|
|
|
|
* Hints to Cogl about how you are planning to modify the data once it
|
|
|
|
* is mapped.
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-07-05 15:14:00 +00:00
|
|
|
*/
|
2018-12-19 08:04:25 +00:00
|
|
|
typedef enum /*< prefix=COGL_BUFFER_MAP_HINT >*/
|
|
|
|
{
|
2012-10-17 20:28:45 +00:00
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD = 1 << 0,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD_RANGE = 1 << 1
|
2010-07-05 15:14:00 +00:00
|
|
|
} CoglBufferMapHint;
|
|
|
|
|
2010-01-10 17:28:24 +00:00
|
|
|
/**
|
|
|
|
* cogl_buffer_map:
|
2010-05-27 22:40:40 +00:00
|
|
|
* @buffer: a buffer object
|
2010-07-05 15:14:00 +00:00
|
|
|
* @access: how the mapped buffer will be used by the application
|
|
|
|
* @hints: A mask of #CoglBufferMapHint<!-- -->s that tell Cogl how
|
2010-12-22 09:42:41 +00:00
|
|
|
* the data will be modified once mapped.
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
2012-10-17 20:28:45 +00:00
|
|
|
* Maps the buffer into the application address space for direct
|
|
|
|
* access. This is equivalent to calling cogl_buffer_map_range() with
|
|
|
|
* zero as the offset and the size of the entire buffer as the size.
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
2010-07-05 15:14:00 +00:00
|
|
|
* It is strongly recommended that you pass
|
|
|
|
* %COGL_BUFFER_MAP_HINT_DISCARD as a hint if you are going to replace
|
|
|
|
* all the buffer's data. This way if the buffer is currently being
|
|
|
|
* used by the GPU then the driver won't have to stall the CPU and
|
|
|
|
* wait for the hardware to finish because it can instead allocate a
|
|
|
|
* new buffer to map.
|
|
|
|
*
|
|
|
|
* The behaviour is undefined if you access the buffer in a way
|
2010-07-05 22:32:55 +00:00
|
|
|
* conflicting with the @access mask you pass. It is also an error to
|
|
|
|
* release your last reference while the buffer is mapped.
|
2010-07-05 15:14:00 +00:00
|
|
|
*
|
2013-09-03 15:17:04 +00:00
|
|
|
* Return value: (transfer none): A pointer to the mapped memory or
|
|
|
|
* %NULL is the call fails
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2019-11-21 11:15:22 +00:00
|
|
|
COGL_EXPORT void *
|
2012-11-08 17:54:10 +00:00
|
|
|
cogl_buffer_map (CoglBuffer *buffer,
|
|
|
|
CoglBufferAccess access,
|
|
|
|
CoglBufferMapHint hints);
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2012-10-17 20:28:45 +00:00
|
|
|
/**
|
|
|
|
* cogl_buffer_map_range:
|
|
|
|
* @buffer: a buffer object
|
|
|
|
* @offset: Offset within the buffer to start the mapping
|
|
|
|
* @size: The size of data to map
|
|
|
|
* @access: how the mapped buffer will be used by the application
|
|
|
|
* @hints: A mask of #CoglBufferMapHint<!-- -->s that tell Cogl how
|
|
|
|
* the data will be modified once mapped.
|
2019-06-18 06:02:10 +00:00
|
|
|
* @error: A #GError for catching exceptional errors
|
2012-10-17 20:28:45 +00:00
|
|
|
*
|
|
|
|
* Maps a sub-region of the buffer into the application's address space
|
|
|
|
* for direct access.
|
|
|
|
*
|
|
|
|
* It is strongly recommended that you pass
|
|
|
|
* %COGL_BUFFER_MAP_HINT_DISCARD as a hint if you are going to replace
|
|
|
|
* all the buffer's data. This way if the buffer is currently being
|
|
|
|
* used by the GPU then the driver won't have to stall the CPU and
|
|
|
|
* wait for the hardware to finish because it can instead allocate a
|
|
|
|
* new buffer to map. You can pass
|
2012-12-31 23:26:11 +00:00
|
|
|
* %COGL_BUFFER_MAP_HINT_DISCARD_RANGE instead if you want the
|
2012-10-17 20:28:45 +00:00
|
|
|
* regions outside of the mapping to be retained.
|
|
|
|
*
|
|
|
|
* The behaviour is undefined if you access the buffer in a way
|
|
|
|
* conflicting with the @access mask you pass. It is also an error to
|
|
|
|
* release your last reference while the buffer is mapped.
|
|
|
|
*
|
2013-09-03 15:17:04 +00:00
|
|
|
* Return value: (transfer none): A pointer to the mapped memory or
|
|
|
|
* %NULL is the call fails
|
2012-10-17 20:28:45 +00:00
|
|
|
*
|
|
|
|
* Since: 2.0
|
|
|
|
* Stability: unstable
|
|
|
|
*/
|
2019-11-21 11:15:22 +00:00
|
|
|
COGL_EXPORT void *
|
2012-10-17 20:28:45 +00:00
|
|
|
cogl_buffer_map_range (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
size_t size,
|
|
|
|
CoglBufferAccess access,
|
2012-11-08 17:54:10 +00:00
|
|
|
CoglBufferMapHint hints,
|
2019-06-18 06:02:10 +00:00
|
|
|
GError **error);
|
2012-10-17 20:28:45 +00:00
|
|
|
|
2010-01-10 17:28:24 +00:00
|
|
|
/**
|
|
|
|
* cogl_buffer_unmap:
|
2010-05-27 22:40:40 +00:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 17:28:24 +00:00
|
|
|
*
|
|
|
|
* Unmaps a buffer previously mapped by cogl_buffer_map().
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2019-11-21 11:15:22 +00:00
|
|
|
COGL_EXPORT void
|
2010-05-27 22:40:40 +00:00
|
|
|
cogl_buffer_unmap (CoglBuffer *buffer);
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* cogl_buffer_set_data:
|
2010-05-27 22:40:40 +00:00
|
|
|
* @buffer: a buffer object
|
2010-01-10 17:28:24 +00:00
|
|
|
* @offset: destination offset (in bytes) in the buffer
|
|
|
|
* @data: a pointer to the data to be copied into the buffer
|
|
|
|
* @size: number of bytes to copy
|
|
|
|
*
|
|
|
|
* Updates part of the buffer with new data from @data. Where to put this new
|
|
|
|
* data is controlled by @offset and @offset + @data should be less than the
|
|
|
|
* buffer size.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE is the operation succeeded, %FALSE otherwise
|
|
|
|
*
|
|
|
|
* Since: 1.2
|
2011-12-16 15:07:25 +00:00
|
|
|
* Stability: unstable
|
2010-01-10 17:28:24 +00:00
|
|
|
*/
|
2019-11-21 11:15:22 +00:00
|
|
|
COGL_EXPORT gboolean
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
cogl_buffer_set_data (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
const void *data,
|
|
|
|
size_t size);
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2018-11-23 07:42:05 +00:00
|
|
|
G_END_DECLS
|
2010-01-10 17:28:24 +00:00
|
|
|
|
|
|
|
#endif /* __COGL_BUFFER_H__ */
|