2010-01-10 17:28:24 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "cogl-internal.h"
|
|
|
|
#include "cogl-util.h"
|
2010-11-04 22:25:52 +00:00
|
|
|
#include "cogl-context-private.h"
|
2012-04-16 13:14:10 +00:00
|
|
|
#include "cogl-object-private.h"
|
2011-03-02 15:19:57 +00:00
|
|
|
#include "cogl-pixel-buffer-private.h"
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2010-07-03 22:56:44 +00:00
|
|
|
/* XXX:
|
2012-04-16 13:14:10 +00:00
|
|
|
* The CoglObject macros don't support any form of inheritance, so for
|
2010-07-03 22:56:44 +00:00
|
|
|
* now we implement the CoglObject support for the CoglBuffer
|
|
|
|
* abstract class manually.
|
|
|
|
*/
|
|
|
|
|
2012-02-06 17:08:58 +00:00
|
|
|
static GSList *_cogl_buffer_types;
|
|
|
|
|
2010-07-03 22:56:44 +00:00
|
|
|
void
|
2012-01-24 16:24:26 +00:00
|
|
|
_cogl_buffer_register_buffer_type (const CoglObjectClass *klass)
|
2010-07-03 22:56:44 +00:00
|
|
|
{
|
2012-02-06 17:08:58 +00:00
|
|
|
_cogl_buffer_types = g_slist_prepend (_cogl_buffer_types, (void *) klass);
|
2010-07-03 22:56:44 +00: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 20:56:40 +00:00
|
|
|
CoglBool
|
2012-03-14 13:45:00 +00:00
|
|
|
cogl_is_buffer (void *object)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2012-04-16 13:14:10 +00:00
|
|
|
const CoglObject *obj = object;
|
2010-07-03 22:56:44 +00:00
|
|
|
GSList *l;
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2010-07-03 22:56:44 +00:00
|
|
|
if (object == NULL)
|
2010-01-10 17:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2012-02-06 17:08:58 +00:00
|
|
|
for (l = _cogl_buffer_types; l; l = l->next)
|
2012-01-24 16:24:26 +00:00
|
|
|
if (l->data == obj->klass)
|
2010-07-03 22:56:44 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
2010-07-06 00:21:43 +00:00
|
|
|
/*
|
|
|
|
* Fallback path, buffer->data points to a malloc'ed buffer.
|
|
|
|
*/
|
|
|
|
|
2010-11-04 16:01:23 +00:00
|
|
|
static void *
|
2012-10-17 20:28:45 +00:00
|
|
|
malloc_map_range (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
size_t size,
|
|
|
|
CoglBufferAccess access,
|
|
|
|
CoglBufferMapHint hints)
|
2010-07-06 00:21:43 +00:00
|
|
|
{
|
2010-10-12 10:46:29 +00:00
|
|
|
buffer->flags |= COGL_BUFFER_FLAG_MAPPED;
|
2012-10-17 20:28:45 +00:00
|
|
|
return buffer->data + offset;
|
2010-07-06 00:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
malloc_unmap (CoglBuffer *buffer)
|
|
|
|
{
|
2010-10-12 10:46:29 +00:00
|
|
|
buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED;
|
2010-07-06 00:21:43 +00: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 20:56:40 +00:00
|
|
|
static CoglBool
|
2010-07-06 00:21:43 +00:00
|
|
|
malloc_set_data (CoglBuffer *buffer,
|
|
|
|
unsigned int offset,
|
2010-11-04 16:01:23 +00:00
|
|
|
const void *data,
|
2010-07-06 00:21:43 +00:00
|
|
|
unsigned int size)
|
|
|
|
{
|
|
|
|
memcpy (buffer->data + offset, data, size);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-10 17:28:24 +00:00
|
|
|
void
|
2012-09-19 20:34:24 +00:00
|
|
|
_cogl_buffer_initialize (CoglBuffer *buffer,
|
2012-09-19 21:32:25 +00:00
|
|
|
CoglContext *ctx,
|
2012-09-19 20:34:24 +00:00
|
|
|
size_t size,
|
|
|
|
CoglBufferBindTarget default_target,
|
|
|
|
CoglBufferUsageHint usage_hint,
|
|
|
|
CoglBufferUpdateHint update_hint)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2012-09-19 20:34:24 +00:00
|
|
|
CoglBool use_malloc = FALSE;
|
|
|
|
|
2012-09-19 21:32:25 +00:00
|
|
|
buffer->context = ctx;
|
2012-09-10 10:26:17 +00:00
|
|
|
buffer->flags = COGL_BUFFER_FLAG_NONE;
|
2010-10-26 15:06:46 +00:00
|
|
|
buffer->store_created = FALSE;
|
2012-09-10 10:26:17 +00: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 18:08:51 +00:00
|
|
|
buffer->immutable_ref = 0;
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2012-09-19 20:34:24 +00:00
|
|
|
if (default_target == COGL_BUFFER_BIND_TARGET_PIXEL_PACK ||
|
|
|
|
default_target == COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK)
|
|
|
|
{
|
2012-09-19 21:32:25 +00:00
|
|
|
if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_PBOS))
|
2012-09-19 20:34:24 +00:00
|
|
|
use_malloc = TRUE;
|
|
|
|
}
|
|
|
|
else if (default_target == COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER ||
|
|
|
|
default_target == COGL_BUFFER_BIND_TARGET_INDEX_BUFFER)
|
|
|
|
{
|
2012-09-19 21:32:25 +00:00
|
|
|
if (!(ctx->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
|
2012-09-19 20:34:24 +00:00
|
|
|
use_malloc = TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-06 00:21:43 +00:00
|
|
|
if (use_malloc)
|
|
|
|
{
|
2012-10-17 20:28:45 +00:00
|
|
|
buffer->vtable.map_range = malloc_map_range;
|
2010-07-06 00:21:43 +00:00
|
|
|
buffer->vtable.unmap = malloc_unmap;
|
|
|
|
buffer->vtable.set_data = malloc_set_data;
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2010-07-06 00:21:43 +00:00
|
|
|
buffer->data = g_malloc (size);
|
|
|
|
}
|
|
|
|
else
|
2010-07-05 22:24:34 +00:00
|
|
|
{
|
2012-10-17 20:28:45 +00:00
|
|
|
buffer->vtable.map_range = ctx->driver_vtable->buffer_map_range;
|
2012-09-19 21:32:25 +00: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-06 00:21:43 +00:00
|
|
|
|
2010-10-12 10:46:29 +00:00
|
|
|
buffer->flags |= COGL_BUFFER_FLAG_BUFFER_OBJECT;
|
2010-07-05 22:24:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-06 00:21:43 +00:00
|
|
|
void
|
|
|
|
_cogl_buffer_fini (CoglBuffer *buffer)
|
2010-07-05 22:24:34 +00:00
|
|
|
{
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_IF_FAIL (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED));
|
|
|
|
_COGL_RETURN_IF_FAIL (buffer->immutable_ref == 0);
|
2010-11-15 03:59:24 +00:00
|
|
|
|
|
|
|
if (buffer->flags & COGL_BUFFER_FLAG_BUFFER_OBJECT)
|
2012-09-19 21:32:25 +00:00
|
|
|
buffer->context->driver_vtable->buffer_destroy (buffer);
|
2010-11-15 03:59:24 +00:00
|
|
|
else
|
|
|
|
g_free (buffer->data);
|
2010-07-05 22:24:34 +00: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-10 01:57:32 +00:00
|
|
|
unsigned int
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_get_size (CoglBuffer *buffer)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
return COGL_BUFFER (buffer)->size;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_set_update_hint (CoglBuffer *buffer,
|
|
|
|
CoglBufferUpdateHint hint)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (hint > COGL_BUFFER_UPDATE_HINT_STREAM))
|
|
|
|
hint = COGL_BUFFER_UPDATE_HINT_STATIC;
|
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
buffer->update_hint = hint;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CoglBufferUpdateHint
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_get_update_hint (CoglBuffer *buffer)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-05-27 22:40:40 +00:00
|
|
|
return buffer->update_hint;
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 18:08:51 +00: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 20:56:40 +00:00
|
|
|
static CoglBool seen = FALSE;
|
2010-10-26 18:08:51 +00:00
|
|
|
if (!seen)
|
|
|
|
{
|
|
|
|
g_warning ("Mid-scene modification of buffers has "
|
|
|
|
"undefined results\n");
|
|
|
|
seen = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-04 16:01:23 +00:00
|
|
|
void *
|
2010-07-05 15:14:00 +00:00
|
|
|
cogl_buffer_map (CoglBuffer *buffer,
|
|
|
|
CoglBufferAccess access,
|
|
|
|
CoglBufferMapHint hints)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_buffer (buffer), NULL);
|
2010-10-26 18:08:51 +00:00
|
|
|
|
2012-10-17 20:28:45 +00:00
|
|
|
return cogl_buffer_map_range (buffer, 0, buffer->size, access, hints);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
cogl_buffer_map_range (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
size_t size,
|
|
|
|
CoglBufferAccess access,
|
|
|
|
CoglBufferMapHint hints)
|
|
|
|
{
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_buffer (buffer), NULL);
|
|
|
|
|
2010-10-26 18:08:51 +00:00
|
|
|
if (G_UNLIKELY (buffer->immutable_ref))
|
|
|
|
warn_about_midscene_changes ();
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2010-10-12 10:46:29 +00:00
|
|
|
if (buffer->flags & COGL_BUFFER_FLAG_MAPPED)
|
2010-01-10 17:28:24 +00:00
|
|
|
return buffer->data;
|
|
|
|
|
2012-10-17 20:28:45 +00:00
|
|
|
buffer->data = buffer->vtable.map_range (buffer,
|
|
|
|
offset,
|
|
|
|
size,
|
|
|
|
access,
|
|
|
|
hints);
|
|
|
|
|
2010-01-10 17:28:24 +00:00
|
|
|
return buffer->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-30 17:06:04 +00:00
|
|
|
cogl_buffer_unmap (CoglBuffer *buffer)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2010-05-27 22:40:40 +00:00
|
|
|
if (!cogl_is_buffer (buffer))
|
2010-01-10 17:28:24 +00:00
|
|
|
return;
|
|
|
|
|
2010-10-12 10:46:29 +00:00
|
|
|
if (!(buffer->flags & COGL_BUFFER_FLAG_MAPPED))
|
2010-01-10 17:28:24 +00:00
|
|
|
return;
|
|
|
|
|
2010-07-06 00:21:43 +00:00
|
|
|
buffer->vtable.unmap (buffer);
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 15:35:30 +00:00
|
|
|
void *
|
|
|
|
_cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer)
|
2012-10-17 20:36:10 +00: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 15:35:30 +00:00
|
|
|
{
|
2012-02-06 17:08:58 +00:00
|
|
|
CoglContext *ctx = buffer->context;
|
2011-01-13 15:35:30 +00:00
|
|
|
void *ret;
|
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (!ctx->buffer_map_fallback_in_use, NULL);
|
2011-01-13 15:35:30 +00:00
|
|
|
|
|
|
|
ctx->buffer_map_fallback_in_use = TRUE;
|
|
|
|
|
2012-10-17 20:36:10 +00:00
|
|
|
ret = cogl_buffer_map_range (buffer,
|
|
|
|
offset,
|
|
|
|
size,
|
|
|
|
COGL_BUFFER_ACCESS_WRITE,
|
|
|
|
COGL_BUFFER_MAP_HINT_DISCARD);
|
2011-01-13 15:35:30 +00:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* 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 */
|
2012-10-17 20:36:10 +00:00
|
|
|
g_byte_array_set_size (ctx->buffer_map_fallback_array, size);
|
|
|
|
ctx->buffer_map_fallback_offset = offset;
|
2011-01-13 15:35:30 +00:00
|
|
|
|
|
|
|
buffer->flags |= COGL_BUFFER_FLAG_MAPPED_FALLBACK;
|
|
|
|
|
|
|
|
return ctx->buffer_map_fallback_array->data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_buffer_unmap_for_fill_or_fallback (CoglBuffer *buffer)
|
|
|
|
{
|
2012-02-06 17:08:58 +00:00
|
|
|
CoglContext *ctx = buffer->context;
|
2011-01-13 15:35:30 +00:00
|
|
|
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_IF_FAIL (ctx->buffer_map_fallback_in_use);
|
2011-01-13 15:35:30 +00:00
|
|
|
|
|
|
|
ctx->buffer_map_fallback_in_use = FALSE;
|
|
|
|
|
|
|
|
if ((buffer->flags & COGL_BUFFER_FLAG_MAPPED_FALLBACK))
|
|
|
|
{
|
2012-10-17 20:36:10 +00:00
|
|
|
cogl_buffer_set_data (buffer,
|
|
|
|
ctx->buffer_map_fallback_offset,
|
2011-01-13 15:35:30 +00:00
|
|
|
ctx->buffer_map_fallback_array->data,
|
2012-10-17 20:36:10 +00:00
|
|
|
ctx->buffer_map_fallback_array->len);
|
2011-01-13 15:35:30 +00: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 20:56:40 +00:00
|
|
|
CoglBool
|
|
|
|
cogl_buffer_set_data (CoglBuffer *buffer,
|
|
|
|
size_t offset,
|
|
|
|
const void *data,
|
|
|
|
size_t size)
|
2010-01-10 17:28:24 +00:00
|
|
|
{
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_buffer (buffer), FALSE);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL ((offset + size) <= buffer->size, FALSE);
|
2010-01-10 17:28:24 +00:00
|
|
|
|
2010-10-26 18:08:51 +00:00
|
|
|
if (G_UNLIKELY (buffer->immutable_ref))
|
|
|
|
warn_about_midscene_changes ();
|
|
|
|
|
2010-07-06 00:21:43 +00:00
|
|
|
return buffer->vtable.set_data (buffer, offset, data, size);
|
2010-01-10 17:28:24 +00:00
|
|
|
}
|
2010-10-26 18:08:51 +00:00
|
|
|
|
|
|
|
CoglBuffer *
|
|
|
|
_cogl_buffer_immutable_ref (CoglBuffer *buffer)
|
|
|
|
{
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (cogl_is_buffer (buffer), NULL);
|
2010-10-26 18:08:51 +00:00
|
|
|
|
|
|
|
buffer->immutable_ref++;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_buffer_immutable_unref (CoglBuffer *buffer)
|
|
|
|
{
|
2011-10-13 21:34:30 +00:00
|
|
|
_COGL_RETURN_IF_FAIL (cogl_is_buffer (buffer));
|
|
|
|
_COGL_RETURN_IF_FAIL (buffer->immutable_ref > 0);
|
2010-10-26 18:08:51 +00:00
|
|
|
|
|
|
|
buffer->immutable_ref--;
|
|
|
|
}
|
|
|
|
|