mutter/cogl/cogl-buffer.h

325 lines
9.9 KiB
C
Raw Normal View History

/*
* Cogl
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-21 20:28:54 -05:00
* A Low Level GPU Graphics and Utilities API
*
* Copyright (C)2010 Intel Corporation.
*
This re-licenses Cogl 1.18 under the MIT license Since the Cogl 1.18 branch is actively maintained in parallel with the master branch; this is a counter part to commit 1b83ef938fc16b which re-licensed the master branch to use the MIT license. This re-licensing is a follow up to the proposal that was sent to the Cogl mailing list: http://lists.freedesktop.org/archives/cogl/2013-December/001465.html Note: there was a copyright assignment policy in place for Clutter (and therefore Cogl which was part of Clutter at the time) until the 11th of June 2010 and so we only checked the details after that point (commit 0bbf50f905) For each file, authors were identified via this Git command: $ git blame -p -C -C -C20 -M -M10 0bbf50f905..HEAD We received blanket approvals for re-licensing all Red Hat and Collabora contributions which reduced how many people needed to be contacted individually: - http://lists.freedesktop.org/archives/cogl/2013-December/001470.html - http://lists.freedesktop.org/archives/cogl/2014-January/001536.html Individual approval requests were sent to all the other identified authors who all confirmed the re-license on the Cogl mailinglist: http://lists.freedesktop.org/archives/cogl/2014-January As well as updating the copyright header in all sources files, the COPYING file has been updated to reflect the license change and also document the other licenses used in Cogl such as the SGI Free Software License B, version 2.0 and the 3-clause BSD license. This patch was not simply cherry-picked from master; but the same methodology was used to check the source files.
2014-02-21 20:28:54 -05: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.
*
*
*
* Authors:
* Damien Lespiau <damien.lespiau@intel.com>
* Robert Bragg <robert@linux.intel.com>
*/
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
#error "Only <cogl/cogl.h> can be included directly."
#endif
#ifndef __COGL_BUFFER_H__
#define __COGL_BUFFER_H__
#include <cogl/cogl-types.h>
Allow propogation of OOM errors to apps This allows apps to catch out-of-memory errors when allocating textures. Textures can be pretty huge at times and so it's quite possible for an application to try and allocate more memory than is available. It's also very possible that the application can take some action in response to reduce memory pressure (such as freeing up texture caches perhaps) so we shouldn't just automatically abort like we do for trivial heap allocations. These public functions now take a CoglError argument so applications can catch out of memory errors: cogl_buffer_map cogl_buffer_map_range cogl_buffer_set_data cogl_framebuffer_read_pixels_into_bitmap cogl_pixel_buffer_new cogl_texture_new_from_data cogl_texture_new_from_bitmap Note: we've been quite conservative with how many apis we let throw OOM CoglErrors since we don't really want to put a burdon on developers to be checking for errors with every cogl api call. So long as there is some lower level api for apps to use that let them catch OOM errors for everything necessary that's enough and we don't have to make more convenient apis more awkward to use. The main focus is on bitmaps and texture allocations since they can be particularly large and prone to failing. A new cogl_attribute_buffer_new_with_size() function has been added in case developers need to catch OOM errors when allocating attribute buffers whereby they can first use _buffer_new_with_size() (which doesn't take a CoglError) followed by cogl_buffer_set_data() which will lazily allocate the buffer storage and report OOM errors. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit f7735e141ad537a253b02afa2a8238f96340b978) Note: since we can't break the API for Cogl 1.x then actually the main purpose of cherry picking this patch is to keep in-line with changes on the master branch so that we can easily cherry-pick patches. All the api changes relating stable apis released on the 1.12 branch have been reverted as part of cherry-picking this patch so this most just applies all the internal plumbing changes that enable us to correctly propagate OOM errors.
2012-11-08 12:54:10 -05:00
#include <cogl/cogl-error.h>
COGL_BEGIN_DECLS
/**
* SECTION:cogl-buffer
* @short_description: Common buffer functions, including data upload APIs
* @stability: unstable
*
* 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.
*/
#ifdef __COGL_H_INSIDE__
/* 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
typedef struct _CoglBuffer CoglBuffer;
#define COGL_BUFFER(buffer) ((CoglBuffer *)(buffer))
#endif
Allow propogation of OOM errors to apps This allows apps to catch out-of-memory errors when allocating textures. Textures can be pretty huge at times and so it's quite possible for an application to try and allocate more memory than is available. It's also very possible that the application can take some action in response to reduce memory pressure (such as freeing up texture caches perhaps) so we shouldn't just automatically abort like we do for trivial heap allocations. These public functions now take a CoglError argument so applications can catch out of memory errors: cogl_buffer_map cogl_buffer_map_range cogl_buffer_set_data cogl_framebuffer_read_pixels_into_bitmap cogl_pixel_buffer_new cogl_texture_new_from_data cogl_texture_new_from_bitmap Note: we've been quite conservative with how many apis we let throw OOM CoglErrors since we don't really want to put a burdon on developers to be checking for errors with every cogl api call. So long as there is some lower level api for apps to use that let them catch OOM errors for everything necessary that's enough and we don't have to make more convenient apis more awkward to use. The main focus is on bitmaps and texture allocations since they can be particularly large and prone to failing. A new cogl_attribute_buffer_new_with_size() function has been added in case developers need to catch OOM errors when allocating attribute buffers whereby they can first use _buffer_new_with_size() (which doesn't take a CoglError) followed by cogl_buffer_set_data() which will lazily allocate the buffer storage and report OOM errors. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit f7735e141ad537a253b02afa2a8238f96340b978) Note: since we can't break the API for Cogl 1.x then actually the main purpose of cherry picking this patch is to keep in-line with changes on the master branch so that we can easily cherry-pick patches. All the api changes relating stable apis released on the 1.12 branch have been reverted as part of cherry-picking this patch so this most just applies all the internal plumbing changes that enable us to correctly propagate OOM errors.
2012-11-08 12:54:10 -05: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
*/
typedef enum { /*< prefix=COGL_BUFFER_ERROR >*/
COGL_BUFFER_ERROR_MAP,
} CoglBufferError;
uint32_t
_cogl_buffer_error_domain (void);
/**
* cogl_is_buffer:
* @object: a buffer object
*
* Checks whether @buffer is a buffer object.
*
* Return value: %TRUE if the handle is a CoglBuffer, and %FALSE otherwise
*
* Since: 1.2
* Stability: unstable
*/
CoglBool
cogl_is_buffer (void *object);
/**
* cogl_buffer_get_size:
* @buffer: a buffer object
*
* Retrieves the size of buffer
*
* Return value: the size of the buffer in bytes
*
* Since: 1.2
* Stability: unstable
*/
cogl: improves header and coding style consistency We've had complaints that our Cogl code/headers are a bit "special" so this is a first pass at tidying things up by giving them some consistency. These changes are all consistent with how new code in Cogl is being written, but the style isn't consistently applied across all code yet. There are two parts to this patch; but since each one required a large amount of effort to maintain tidy indenting it made sense to combine the changes to reduce the time spent re indenting the same lines. The first change is to use a consistent style for declaring function prototypes in headers. Cogl headers now consistently use this style for prototypes: return_type cogl_function_name (CoglType arg0, CoglType arg1); Not everyone likes this style, but it seems that most of the currently active Cogl developers agree on it. The second change is to constrain the use of redundant glib data types in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all been replaced with int, unsigned int, float, long, unsigned long and char respectively. When talking about pixel data; use of guchar has been replaced with guint8, otherwise unsigned char can be used. The glib types that we continue to use for portability are gboolean, gint{8,16,32,64}, guint{8,16,32,64} and gsize. The general intention is that Cogl should look palatable to the widest range of C programmers including those outside the Gnome community so - especially for the public API - we want to minimize the number of foreign looking typedefs.
2010-02-09 20:57:32 -05:00
unsigned int
cogl_buffer_get_size (CoglBuffer *buffer);
/**
* 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
*
* The update hint on a buffer allows the user to give some detail on how often
* the buffer data is going to be updated.
*
* Since: 1.2
* Stability: unstable
*/
typedef enum { /*< prefix=COGL_BUFFER_UPDATE_HINT >*/
COGL_BUFFER_UPDATE_HINT_STATIC,
COGL_BUFFER_UPDATE_HINT_DYNAMIC,
COGL_BUFFER_UPDATE_HINT_STREAM
} CoglBufferUpdateHint;
/**
* cogl_buffer_set_update_hint:
* @buffer: a buffer object
* @hint: the new hint
*
* Sets the update hint on a buffer. See #CoglBufferUpdateHint for a description
* of the available hints.
*
* Since: 1.2
* Stability: unstable
*/
void
cogl_buffer_set_update_hint (CoglBuffer *buffer,
CoglBufferUpdateHint hint);
/**
* cogl_buffer_get_update_hint:
* @buffer: a buffer object
*
* Retrieves the update hints set using cogl_buffer_set_update_hint()
*
* Return value: the #CoglBufferUpdateHint currently used by the buffer
*
* Since: 1.2
* Stability: unstable
*/
CoglBufferUpdateHint
cogl_buffer_get_update_hint (CoglBuffer *buffer);
/**
* 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
*
* The access hints for cogl_buffer_set_update_hint()
*
* Since: 1.2
* Stability: unstable
*/
typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/
COGL_BUFFER_ACCESS_READ = 1 << 0,
COGL_BUFFER_ACCESS_WRITE = 1 << 1,
COGL_BUFFER_ACCESS_READ_WRITE = COGL_BUFFER_ACCESS_READ | COGL_BUFFER_ACCESS_WRITE
} CoglBufferAccess;
/**
* CoglBufferMapHint:
2010-12-22 04:42:41 -05:00
* @COGL_BUFFER_MAP_HINT_DISCARD: Tells Cogl that you plan to replace
* 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.
*
* Hints to Cogl about how you are planning to modify the data once it
* is mapped.
*
* Since: 1.4
* Stability: unstable
*/
typedef enum { /*< prefix=COGL_BUFFER_MAP_HINT >*/
COGL_BUFFER_MAP_HINT_DISCARD = 1 << 0,
COGL_BUFFER_MAP_HINT_DISCARD_RANGE = 1 << 1
} CoglBufferMapHint;
/**
* cogl_buffer_map:
* @buffer: a buffer object
* @access: how the mapped buffer will be used by the application
* @hints: A mask of #CoglBufferMapHint<!-- -->s that tell Cogl how
2010-12-22 04:42:41 -05:00
* the data will be modified once mapped.
*
* 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.
*
* 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
* conflicting with the @access mask you pass. It is also an error to
* release your last reference while the buffer is mapped.
*
* Return value: (transfer none): A pointer to the mapped memory or
* %NULL is the call fails
*
* Since: 1.2
* Stability: unstable
*/
void *
Allow propogation of OOM errors to apps This allows apps to catch out-of-memory errors when allocating textures. Textures can be pretty huge at times and so it's quite possible for an application to try and allocate more memory than is available. It's also very possible that the application can take some action in response to reduce memory pressure (such as freeing up texture caches perhaps) so we shouldn't just automatically abort like we do for trivial heap allocations. These public functions now take a CoglError argument so applications can catch out of memory errors: cogl_buffer_map cogl_buffer_map_range cogl_buffer_set_data cogl_framebuffer_read_pixels_into_bitmap cogl_pixel_buffer_new cogl_texture_new_from_data cogl_texture_new_from_bitmap Note: we've been quite conservative with how many apis we let throw OOM CoglErrors since we don't really want to put a burdon on developers to be checking for errors with every cogl api call. So long as there is some lower level api for apps to use that let them catch OOM errors for everything necessary that's enough and we don't have to make more convenient apis more awkward to use. The main focus is on bitmaps and texture allocations since they can be particularly large and prone to failing. A new cogl_attribute_buffer_new_with_size() function has been added in case developers need to catch OOM errors when allocating attribute buffers whereby they can first use _buffer_new_with_size() (which doesn't take a CoglError) followed by cogl_buffer_set_data() which will lazily allocate the buffer storage and report OOM errors. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit f7735e141ad537a253b02afa2a8238f96340b978) Note: since we can't break the API for Cogl 1.x then actually the main purpose of cherry picking this patch is to keep in-line with changes on the master branch so that we can easily cherry-pick patches. All the api changes relating stable apis released on the 1.12 branch have been reverted as part of cherry-picking this patch so this most just applies all the internal plumbing changes that enable us to correctly propagate OOM errors.
2012-11-08 12:54:10 -05:00
cogl_buffer_map (CoglBuffer *buffer,
CoglBufferAccess access,
CoglBufferMapHint hints);
/**
* 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.
Allow propogation of OOM errors to apps This allows apps to catch out-of-memory errors when allocating textures. Textures can be pretty huge at times and so it's quite possible for an application to try and allocate more memory than is available. It's also very possible that the application can take some action in response to reduce memory pressure (such as freeing up texture caches perhaps) so we shouldn't just automatically abort like we do for trivial heap allocations. These public functions now take a CoglError argument so applications can catch out of memory errors: cogl_buffer_map cogl_buffer_map_range cogl_buffer_set_data cogl_framebuffer_read_pixels_into_bitmap cogl_pixel_buffer_new cogl_texture_new_from_data cogl_texture_new_from_bitmap Note: we've been quite conservative with how many apis we let throw OOM CoglErrors since we don't really want to put a burdon on developers to be checking for errors with every cogl api call. So long as there is some lower level api for apps to use that let them catch OOM errors for everything necessary that's enough and we don't have to make more convenient apis more awkward to use. The main focus is on bitmaps and texture allocations since they can be particularly large and prone to failing. A new cogl_attribute_buffer_new_with_size() function has been added in case developers need to catch OOM errors when allocating attribute buffers whereby they can first use _buffer_new_with_size() (which doesn't take a CoglError) followed by cogl_buffer_set_data() which will lazily allocate the buffer storage and report OOM errors. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit f7735e141ad537a253b02afa2a8238f96340b978) Note: since we can't break the API for Cogl 1.x then actually the main purpose of cherry picking this patch is to keep in-line with changes on the master branch so that we can easily cherry-pick patches. All the api changes relating stable apis released on the 1.12 branch have been reverted as part of cherry-picking this patch so this most just applies all the internal plumbing changes that enable us to correctly propagate OOM errors.
2012-11-08 12:54:10 -05:00
* @error: A #CoglError for catching exceptional errors
*
* 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
* %COGL_BUFFER_MAP_HINT_DISCARD_RANGE instead if you want the
* 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.
*
* Return value: (transfer none): A pointer to the mapped memory or
* %NULL is the call fails
*
* Since: 2.0
* Stability: unstable
*/
void *
cogl_buffer_map_range (CoglBuffer *buffer,
size_t offset,
size_t size,
CoglBufferAccess access,
Allow propogation of OOM errors to apps This allows apps to catch out-of-memory errors when allocating textures. Textures can be pretty huge at times and so it's quite possible for an application to try and allocate more memory than is available. It's also very possible that the application can take some action in response to reduce memory pressure (such as freeing up texture caches perhaps) so we shouldn't just automatically abort like we do for trivial heap allocations. These public functions now take a CoglError argument so applications can catch out of memory errors: cogl_buffer_map cogl_buffer_map_range cogl_buffer_set_data cogl_framebuffer_read_pixels_into_bitmap cogl_pixel_buffer_new cogl_texture_new_from_data cogl_texture_new_from_bitmap Note: we've been quite conservative with how many apis we let throw OOM CoglErrors since we don't really want to put a burdon on developers to be checking for errors with every cogl api call. So long as there is some lower level api for apps to use that let them catch OOM errors for everything necessary that's enough and we don't have to make more convenient apis more awkward to use. The main focus is on bitmaps and texture allocations since they can be particularly large and prone to failing. A new cogl_attribute_buffer_new_with_size() function has been added in case developers need to catch OOM errors when allocating attribute buffers whereby they can first use _buffer_new_with_size() (which doesn't take a CoglError) followed by cogl_buffer_set_data() which will lazily allocate the buffer storage and report OOM errors. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit f7735e141ad537a253b02afa2a8238f96340b978) Note: since we can't break the API for Cogl 1.x then actually the main purpose of cherry picking this patch is to keep in-line with changes on the master branch so that we can easily cherry-pick patches. All the api changes relating stable apis released on the 1.12 branch have been reverted as part of cherry-picking this patch so this most just applies all the internal plumbing changes that enable us to correctly propagate OOM errors.
2012-11-08 12:54:10 -05:00
CoglBufferMapHint hints,
CoglError **error);
/**
* cogl_buffer_unmap:
* @buffer: a buffer object
*
* Unmaps a buffer previously mapped by cogl_buffer_map().
*
* Since: 1.2
* Stability: unstable
*/
void
cogl_buffer_unmap (CoglBuffer *buffer);
/**
* cogl_buffer_set_data:
* @buffer: a buffer object
* @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
* Stability: unstable
*/
CoglBool
cogl_buffer_set_data (CoglBuffer *buffer,
size_t offset,
const void *data,
size_t size);
COGL_END_DECLS
#endif /* __COGL_BUFFER_H__ */