2010-01-10 12:28:24 -05:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
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.
|
2010-03-01 07:56:10 -05:00
|
|
|
*
|
|
|
|
*
|
2010-01-10 12:28:24 -05:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Damien Lespiau <damien.lespiau@intel.com>
|
2010-07-05 11:14:00 -04:00
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
2010-01-10 12:28:24 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* For an overview of the functionality implemented here, please see
|
|
|
|
* cogl-buffer.h, which contains the gtk-doc section overview for the
|
|
|
|
* Pixel Buffers API.
|
|
|
|
*/
|
|
|
|
|
2016-05-05 10:21:51 -04:00
|
|
|
#include "cogl-config.h"
|
2010-01-10 12:28:24 -05:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "cogl-util.h"
|
2010-11-04 18:25:52 -04:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 09:14:10 -04:00
|
|
|
#include "cogl-object-private.h"
|
2011-03-02 10:19:57 -05:00
|
|
|
#include "cogl-pixel-buffer-private.h"
|
2010-01-10 12:28:24 -05:00
|
|
|
|
2010-07-03 18:56:44 -04:00
|
|
|
/* XXX:
|
2012-04-16 09:14:10 -04:00
|
|
|
* The CoglObject macros don't support any form of inheritance, so for
|
2010-07-03 18:56:44 -04:00
|
|
|
* now we implement the CoglObject support for the CoglBuffer
|
|
|
|
* abstract class manually.
|
|
|
|
*/
|
|
|
|
|
2012-02-06 12:08:58 -05:00
|
|
|
static GSList *_cogl_buffer_types;
|
|
|
|
|
2010-07-03 18:56:44 -04:00
|
|
|
void
|
2012-01-24 11:24:26 -05:00
|
|
|
_cogl_buffer_register_buffer_type (const CoglObjectClass *klass)
|
2010-07-03 18:56:44 -04:00
|
|
|
{
|
2012-02-06 12:08:58 -05:00
|
|
|
_cogl_buffer_types = g_slist_prepend (_cogl_buffer_types, (void *) klass);
|
2010-07-03 18:56:44 -04:00
|
|
|
}
|
|
|
|
|
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 16:56:40 -04:00
|
|
|
CoglBool
|
2012-03-14 09:45:00 -04:00
|
|
|
cogl_is_buffer (void *object)
|
2010-01-10 12:28:24 -05:00
|
|
|
{
|
2012-04-16 09:14:10 -04:00
|
|
|
const CoglObject *obj = object;
|
2010-07-03 18:56:44 -04:00
|
|
|
GSList *l;
|
2010-01-10 12:28:24 -05:00
|
|
|
|
2010-07-03 18:56:44 -04:00
|
|
|
if (object == NULL)
|
2010-01-10 12:28:24 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2012-02-06 12:08:58 -05:00
|
|
|
for (l = _cogl_buffer_types; l; l = l->next)
|
2012-01-24 11:24:26 -05:00
|
|
|
if (l->data == obj->klass)
|
2010-07-03 18:56:44 -04:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2010-01-10 12:28:24 -05:00
|
|
|
}
|
|
|
|
|
2010-07-05 20:21:43 -04:00
|
|
|
/*
|
|
|
|
* Fallback path, buffer->data points to a malloc'ed buffer.
|
|
|
|
*/
|
|
|
|
|
2010-11-04 12:01:23 -04:00
|
|
|
static void *
|
2012-10-17 16:28:45 -04:00
|
|
|
malloc_map_range (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
size_t size,
|
|
|
|
CoglBufferAccess access,
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBufferMapHint hints,
|
|
|
|
CoglError **error)
|
2010-07-05 20:21:43 -04:00
|
|
|
{
|
2010-10-12 06:46:29 -04:00
|
|
|
buffer->flags |= COGL_BUFFER_FLAG_MAPPED;
|
2012-10-17 16:28:45 -04:00
|
|
|
return buffer->data + offset;
|
2010-07-05 20:21:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
malloc_unmap (CoglBuffer *buffer)
|
|
|
|
{
|
2010-10-12 06:46:29 -04:00
|
|
|
buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED;
|
2010-07-05 20:21:43 -04:00
|
|
|
}
|
|
|
|
|
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 16:56:40 -04:00
|
|
|
static CoglBool
|
2012-11-08 12:54:10 -05:00
|
|
|
malloc_set_data (CoglBuffer *buffer,
|
|
|
|
unsigned int offset,
|
|
|
|
const void *data,
|
|
|
|
unsigned int size,
|
|
|
|
CoglError **error)
|
2010-07-05 20:21:43 -04:00
|
|
|
{
|
|
|
|
memcpy (buffer->data + offset, data, size);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-10 12:28:24 -05:00
|
|
|
void
|
2012-09-19 16:34:24 -04:00
|
|
|
_cogl_buffer_initialize (CoglBuffer *buffer,
|
2012-09-19 17:32:25 -04:00
|
|
|
CoglContext *ctx,
|
2012-09-19 16:34:24 -04:00
|
|
|
size_t size,
|
|
|
|
CoglBufferBindTarget default_target,
|
|
|
|
CoglBufferUsageHint usage_hint,
|
|
|
|
CoglBufferUpdateHint update_hint)
|
2010-01-10 12:28:24 -05:00
|
|
|
{
|
2012-09-19 16:34:24 -04:00
|
|
|
CoglBool use_malloc = FALSE;
|
|
|
|
|
2012-09-19 17:32:25 -04:00
|
|
|
buffer->context = ctx;
|
2012-09-10 06:26:17 -04:00
|
|
|
buffer->flags = COGL_BUFFER_FLAG_NONE;
|
2010-10-26 11:06:46 -04:00
|
|
|
buffer->store_created = FALSE;
|
2012-09-10 06:26:17 -04:00
|
|
|
buffer->size = size;
|
|
|
|
buffer->last_target = default_target;
|
|
|
|
buffer->usage_hint = usage_hint;
|
|
|
|
buffer->update_hint = update_hint;
|
|
|
|
buffer->data = NULL;
|
2010-10-26 14:08:51 -04:00
|
|
|
buffer->immutable_ref = 0;
|
2010-01-10 12:28:24 -05:00
|
|
|
|
2012-09-19 16:34:24 -04:00
|
|
|
if (default_target == COGL_BUFFER_BIND_TARGET_PIXEL_PACK ||
|
|
|
|
default_target == COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK)
|
|
|
|
{
|
2013-11-25 11:11:36 -05:00
|
|
|
if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_PBOS))
|
2012-09-19 16:34:24 -04:00
|
|
|
use_malloc = TRUE;
|
|
|
|
}
|
|
|
|
else if (default_target == COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER ||
|
|
|
|
default_target == COGL_BUFFER_BIND_TARGET_INDEX_BUFFER)
|
|
|
|
{
|
2013-11-25 11:11:36 -05:00
|
|
|
if (!_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_VBOS))
|
2012-09-19 16:34:24 -04:00
|
|
|
use_malloc = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:21:43 -04:00
|
|
|
if (use_malloc)
|
|
|
|
{
|
2012-10-17 16:28:45 -04:00
|
|
|
buffer->vtable.map_range = malloc_map_range;
|
2010-07-05 20:21:43 -04:00
|
|
|
buffer->vtable.unmap = malloc_unmap;
|
|
|
|
buffer->vtable.set_data = malloc_set_data;
|
2010-01-10 12:28:24 -05:00
|
|
|
|
2010-07-05 20:21:43 -04:00
|
|
|
buffer->data = g_malloc (size);
|
|
|
|
}
|
|
|
|
else
|
2010-07-05 18:24:34 -04:00
|
|
|
{
|
2012-10-17 16:28:45 -04:00
|
|
|
buffer->vtable.map_range = ctx->driver_vtable->buffer_map_range;
|
2012-09-19 17:32:25 -04:00
|
|
|
buffer->vtable.unmap = ctx->driver_vtable->buffer_unmap;
|
|
|
|
buffer->vtable.set_data = ctx->driver_vtable->buffer_set_data;
|
|
|
|
|
|
|
|
ctx->driver_vtable->buffer_create (buffer);
|
2010-07-05 20:21:43 -04:00
|
|
|
|
2010-10-12 06:46:29 -04:00
|
|
|
buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT;
|
2010-07-05 18:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 20:21:43 -04:00
|
|
|
void
|
|
|
|
_cogl_buffer_fini (CoglBuffer *buffer)
|
2010-07-05 18:24:34 -04:00
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED));
|
|
|
|
_COGL_RETURN_IF_FAIL (buffer->immutable_ref == 0);
|
2010-11-14 22:59:24 -05:00
|
|
|
|
|
|
|
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
2012-09-19 17:32:25 -04:00
|
|
|
buffer->context->driver_vtable->buffer_destroy (buffer);
|
2010-11-14 22:59:24 -05:00
|
|
|
else
|
|
|
|
g_free (buffer->data);
|
2010-07-05 18:24:34 -04:00
|
|
|
}
|
|
|
|
|
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
|
2010-06-30 13:06:04 -04:00
|
|
|
cogl_buffer_get_size (CoglBuffer *buffer)
|
2010-01-10 12:28:24 -05:00
|
|
|
{
|
2010-05-27 18:40:40 -04:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 12:28:24 -05:00
|
|
|
return 0;
|
|
|
|
|
2010-05-27 18:40:40 -04:00
|
|
|
return COGL_BUFFER (buffer)->size;
|
2010-01-10 12:28:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 13:06:04 -04:00
|
|
|
cogl_buffer_set_update_hint (CoglBuffer *buffer,
|
|
|
|
CoglBufferUpdateHint hint)
|
2010-01-10 12:28:24 -05:00
|
|
|
{
|
2010-05-27 18:40:40 -04:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 12:28:24 -05:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (hint > COGL_BUFFER_UPDATE_HINT_STREAM))
|
|
|
|
hint = COGL_BUFFER_UPDATE_HINT_STATIC;
|
|
|
|
|
2010-05-27 18:40:40 -04:00
|
|
|
buffer->update_hint = hint;
|
2010-01-10 12:28:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglBufferUpdateHint
|
2010-06-30 13:06:04 -04:00
|
|
|
cogl_buffer_get_update_hint (CoglBuffer *buffer)
|
2010-01-10 12:28:24 -05:00
|
|
|
{
|
2010-05-27 18:40:40 -04:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 12:28:24 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2010-05-27 18:40:40 -04:00
|
|
|
return buffer->update_hint;
|
2010-01-10 12:28:24 -05:00
|
|
|
}
|
|
|
|
|
2010-10-26 14:08:51 -04:00
|
|
|
static void
|
|
|
|
warn_about_midscene_changes (void)
|
|
|
|
{
|
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 16:56:40 -04:00
|
|
|
static CoglBool seen = FALSE;
|
2010-10-26 14:08:51 -04:00
|
|
|
if (!seen)
|
|
|
|
{
|
|
|
|
g_warning ("Mid-scene modification of buffers has "
|
|
|
|
"undefined results\n");
|
|
|
|
seen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 12:01:23 -04:00
|
|
|
void *
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_buffer_map (CoglBuffer *buffer,
|
|
|
|
CoglBufferAccess access,
|
|
|
|
CoglBufferMapHint hints,
|
|
|
|
CoglError **error)
|
2010-01-10 12:28:24 -05:00
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_buffer (buffer), NULL);
|
2010-10-26 14:08:51 -04:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return cogl_buffer_map_range (buffer, 0, buffer->size, access, hints, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
cogl_buffer_map (CoglBuffer *buffer,
|
|
|
|
CoglBufferAccess access,
|
|
|
|
CoglBufferMapHint hints)
|
|
|
|
{
|
|
|
|
CoglError *ignore_error = NULL;
|
|
|
|
void *ptr =
|
|
|
|
cogl_buffer_map_range (buffer, 0, buffer->size, access, hints,
|
|
|
|
&ignore_error);
|
|
|
|
if (!ptr)
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
return ptr;
|
2012-10-17 16:28:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
cogl_buffer_map_range (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
size_t size,
|
|
|
|
CoglBufferAccess access,
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglBufferMapHint hints,
|
|
|
|
CoglError **error)
|
2012-10-17 16:28:45 -04:00
|
|
|
{
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_buffer (buffer), NULL);
|
2012-11-08 12:54:10 -05:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED), NULL);
|
2012-10-17 16:28:45 -04:00
|
|
|
|
2010-10-26 14:08:51 -04:00
|
|
|
if (G_UNLIKELY (buffer->immutable_ref))
|
|
|
|
warn_about_midscene_changes ();
|
2010-01-10 12:28:24 -05:00
|
|
|
|
2012-10-17 16:28:45 -04:00
|
|
|
buffer->data = buffer->vtable.map_range (buffer,
|
|
|
|
offset,
|
|
|
|
size,
|
|
|
|
access,
|
2012-11-08 12:54:10 -05:00
|
|
|
hints,
|
|
|
|
error);
|
2012-10-17 16:28:45 -04:00
|
|
|
|
2010-01-10 12:28:24 -05:00
|
|
|
return buffer->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 13:06:04 -04:00
|
|
|
cogl_buffer_unmap (CoglBuffer *buffer)
|
2010-01-10 12:28:24 -05:00
|
|
|
{
|
2010-05-27 18:40:40 -04:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 12:28:24 -05:00
|
|
|
return;
|
|
|
|
|
2010-10-12 06:46:29 -04:00
|
|
|
if (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED))
|
2010-01-10 12:28:24 -05:00
|
|
|
return;
|
|
|
|
|
2010-07-05 20:21:43 -04:00
|
|
|
buffer->vtable.unmap (buffer);
|
2010-01-10 12:28:24 -05:00
|
|
|
}
|
|
|
|
|
2011-01-13 10:35:30 -05:00
|
|
|
void *
|
|
|
|
_cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer)
|
2012-10-17 16:36:10 -04:00
|
|
|
{
|
|
|
|
return _cogl_buffer_map_range_for_fill_or_fallback (buffer, 0, buffer->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
_cogl_buffer_map_range_for_fill_or_fallback (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
size_t size)
|
2011-01-13 10:35:30 -05:00
|
|
|
{
|
2012-02-06 12:08:58 -05:00
|
|
|
CoglContext *ctx = buffer->context;
|
2011-01-13 10:35:30 -05:00
|
|
|
void *ret;
|
2012-11-08 12:54:10 -05:00
|
|
|
CoglError *ignore_error = NULL;
|
2011-01-13 10:35:30 -05:00
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (!ctx->buffer_map_fallback_in_use, NULL);
|
2011-01-13 10:35:30 -05:00
|
|
|
|
|
|
|
ctx->buffer_map_fallback_in_use = TRUE;
|
|
|
|
|
2012-10-17 16:36:10 -04:00
|
|
|
ret = cogl_buffer_map_range (buffer,
|
|
|
|
offset,
|
|
|
|
size,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
2012-11-08 12:54:10 -05:00
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD,
|
|
|
|
&ignore_error);
|
2011-01-13 10:35:30 -05:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2013-03-06 11:37:19 -05:00
|
|
|
cogl_error_free (ignore_error);
|
2011-01-13 10:35:30 -05:00
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
/* If the map fails then we'll use a temporary buffer to fill
|
|
|
|
the data and then upload it using cogl_buffer_set_data when
|
|
|
|
the buffer is unmapped. The temporary buffer is shared to
|
|
|
|
avoid reallocating it every time */
|
|
|
|
g_byte_array_set_size (ctx->buffer_map_fallback_array, size);
|
|
|
|
ctx->buffer_map_fallback_offset = offset;
|
|
|
|
|
|
|
|
buffer->flags |= COGL_BUFFER_FLAG_MAPPED_FALLBACK;
|
|
|
|
|
|
|
|
return ctx->buffer_map_fallback_array->data;
|
2011-01-13 10:35:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_buffer_unmap_for_fill_or_fallback (CoglBuffer *buffer)
|
|
|
|
{
|
2012-02-06 12:08:58 -05:00
|
|
|
CoglContext *ctx = buffer->context;
|
2011-01-13 10:35:30 -05:00
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (ctx->buffer_map_fallback_in_use);
|
2011-01-13 10:35:30 -05:00
|
|
|
|
|
|
|
ctx->buffer_map_fallback_in_use = FALSE;
|
|
|
|
|
|
|
|
if ((buffer->flags & COGL_BUFFER_FLAG_MAPPED_FALLBACK))
|
|
|
|
{
|
2012-11-08 12:54:10 -05:00
|
|
|
/* Note: don't try to catch OOM errors here since the use cases
|
|
|
|
* we currently have for this api (the journal and path stroke
|
|
|
|
* tesselator) don't have anything particularly sensible they
|
|
|
|
* can do in response to a failure anyway so it seems better to
|
|
|
|
* simply abort instead.
|
|
|
|
*
|
|
|
|
* If we find this is a problem for real world applications
|
|
|
|
* then in the path tesselation case we could potentially add an
|
|
|
|
* explicit cogl_path_tesselate_stroke() api that can throw an
|
|
|
|
* error for the app to cache. For the journal we could
|
|
|
|
* potentially flush the journal in smaller batches so we use
|
|
|
|
* smaller buffers, though that would probably not help for
|
|
|
|
* deferred renderers.
|
|
|
|
*/
|
|
|
|
_cogl_buffer_set_data (buffer,
|
|
|
|
ctx->buffer_map_fallback_offset,
|
|
|
|
ctx->buffer_map_fallback_array->data,
|
|
|
|
ctx->buffer_map_fallback_array->len,
|
|
|
|
NULL);
|
2011-01-13 10:35:30 -05:00
|
|
|
buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED_FALLBACK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cogl_buffer_unmap (buffer);
|
|
|
|
}
|
|
|
|
|
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 16:56:40 -04:00
|
|
|
CoglBool
|
2012-11-08 12:54:10 -05:00
|
|
|
_cogl_buffer_set_data (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
const void *data,
|
|
|
|
size_t size,
|
|
|
|
CoglError **error)
|
2010-01-10 12:28:24 -05:00
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_buffer (buffer), FALSE);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL ((offset + size) <= buffer->size, FALSE);
|
2010-01-10 12:28:24 -05:00
|
|
|
|
2010-10-26 14:08:51 -04:00
|
|
|
if (G_UNLIKELY (buffer->immutable_ref))
|
|
|
|
warn_about_midscene_changes ();
|
|
|
|
|
2012-11-08 12:54:10 -05:00
|
|
|
return buffer->vtable.set_data (buffer, offset, data, size, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglBool
|
|
|
|
cogl_buffer_set_data (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
const void *data,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
CoglError *ignore_error = NULL;
|
|
|
|
CoglBool status =
|
|
|
|
_cogl_buffer_set_data (buffer, offset, data, size, &ignore_error);
|
|
|
|
if (!status)
|
|
|
|
cogl_error_free (ignore_error);
|
|
|
|
return status;
|
2010-01-10 12:28:24 -05:00
|
|
|
}
|
2010-10-26 14:08:51 -04:00
|
|
|
|
|
|
|
CoglBuffer *
|
|
|
|
_cogl_buffer_immutable_ref (CoglBuffer *buffer)
|
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_buffer (buffer), NULL);
|
2010-10-26 14:08:51 -04:00
|
|
|
|
|
|
|
buffer->immutable_ref++;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_buffer_immutable_unref (CoglBuffer *buffer)
|
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_buffer (buffer));
|
|
|
|
_COGL_RETURN_IF_FAIL (buffer->immutable_ref > 0);
|
2010-10-26 14:08:51 -04:00
|
|
|
|
|
|
|
buffer->immutable_ref--;
|
|
|
|
}
|
|
|
|
|