[Cogl] [PATCH] buffer: move choice about using malloc closer to driver
Robert Bragg
robert at sixbynine.org
Mon Sep 24 09:44:47 PDT 2012
From: Robert Bragg <robert at linux.intel.com>
This moves the decision about whether a buffer should be allocated using
malloc or not into cogl-buffer.c closer to the driver since it seem
there could be other driver specific factors that might also influence
this choice that we don't currently consider.
---
cogl/cogl-attribute-buffer.c | 7 -------
cogl/cogl-buffer-private.h | 9 ++++-----
cogl/cogl-buffer.c | 28 +++++++++++++++++++++-------
cogl/cogl-index-buffer.c | 7 -------
cogl/cogl-pixel-buffer.c | 7 -------
5 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/cogl/cogl-attribute-buffer.c b/cogl/cogl-attribute-buffer.c
index f9eeeac..a122e96 100644
--- a/cogl/cogl-attribute-buffer.c
+++ b/cogl/cogl-attribute-buffer.c
@@ -44,18 +44,11 @@ cogl_attribute_buffer_new (CoglContext *context,
const void *data)
{
CoglAttributeBuffer *array = g_slice_new (CoglAttributeBuffer);
- CoglBool use_malloc;
-
- if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
- use_malloc = TRUE;
- else
- use_malloc = FALSE;
/* parent's constructor */
_cogl_buffer_initialize (COGL_BUFFER (array),
context,
bytes,
- use_malloc,
COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER,
COGL_BUFFER_USAGE_HINT_ATTRIBUTE_BUFFER,
COGL_BUFFER_UPDATE_HINT_STATIC);
diff --git a/cogl/cogl-buffer-private.h b/cogl/cogl-buffer-private.h
index 52bffaf..7e81e26 100644
--- a/cogl/cogl-buffer-private.h
+++ b/cogl/cogl-buffer-private.h
@@ -113,12 +113,11 @@ _cogl_buffer_register_buffer_type (const CoglObjectClass *klass);
_cogl_buffer_register_buffer_type (&_cogl_##type_name##_class))
void
-_cogl_buffer_initialize (CoglBuffer *buffer,
- CoglContext *context,
- unsigned int size,
- CoglBool use_malloc,
+_cogl_buffer_initialize (CoglBuffer *buffer,
+ CoglContext *context,
+ size_t size,
CoglBufferBindTarget default_target,
- CoglBufferUsageHint usage_hint,
+ CoglBufferUsageHint usage_hint,
CoglBufferUpdateHint update_hint);
void
diff --git a/cogl/cogl-buffer.c b/cogl/cogl-buffer.c
index ffd1ef1..12b2d5a 100644
--- a/cogl/cogl-buffer.c
+++ b/cogl/cogl-buffer.c
@@ -292,14 +292,15 @@ malloc_set_data (CoglBuffer *buffer,
}
void
-_cogl_buffer_initialize (CoglBuffer *buffer,
- CoglContext *context,
- unsigned int size,
- CoglBool use_malloc,
- CoglBufferBindTarget default_target,
- CoglBufferUsageHint usage_hint,
- CoglBufferUpdateHint update_hint)
+_cogl_buffer_initialize (CoglBuffer *buffer,
+ CoglContext *context,
+ size_t size,
+ CoglBufferBindTarget default_target,
+ CoglBufferUsageHint usage_hint,
+ CoglBufferUpdateHint update_hint)
{
+ CoglBool use_malloc = FALSE;
+
buffer->context = context;
buffer->flags = COGL_BUFFER_FLAG_NONE;
buffer->store_created = FALSE;
@@ -310,6 +311,19 @@ _cogl_buffer_initialize (CoglBuffer *buffer,
buffer->data = NULL;
buffer->immutable_ref = 0;
+ if (default_target == COGL_BUFFER_BIND_TARGET_PIXEL_PACK ||
+ default_target == COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK)
+ {
+ if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_PBOS))
+ use_malloc = TRUE;
+ }
+ else if (default_target == COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER ||
+ default_target == COGL_BUFFER_BIND_TARGET_INDEX_BUFFER)
+ {
+ if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
+ use_malloc = TRUE;
+ }
+
if (use_malloc)
{
buffer->vtable.map = malloc_map;
diff --git a/cogl/cogl-index-buffer.c b/cogl/cogl-index-buffer.c
index 547cae3..a36c2d2 100644
--- a/cogl/cogl-index-buffer.c
+++ b/cogl/cogl-index-buffer.c
@@ -45,18 +45,11 @@ CoglIndexBuffer *
cogl_index_buffer_new (CoglContext *context, size_t bytes)
{
CoglIndexBuffer *indices = g_slice_new (CoglIndexBuffer);
- CoglBool use_malloc;
-
- if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
- use_malloc = TRUE;
- else
- use_malloc = FALSE;
/* parent's constructor */
_cogl_buffer_initialize (COGL_BUFFER (indices),
context,
bytes,
- use_malloc,
COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
COGL_BUFFER_USAGE_HINT_INDEX_BUFFER,
COGL_BUFFER_UPDATE_HINT_STATIC);
diff --git a/cogl/cogl-pixel-buffer.c b/cogl/cogl-pixel-buffer.c
index 7b505d9..0c7502c 100644
--- a/cogl/cogl-pixel-buffer.c
+++ b/cogl/cogl-pixel-buffer.c
@@ -73,18 +73,11 @@ cogl_pixel_buffer_new (CoglContext *context,
{
CoglPixelBuffer *pixel_buffer = g_slice_new0 (CoglPixelBuffer);
CoglBuffer *buffer = COGL_BUFFER (pixel_buffer);
- CoglBool use_malloc;
-
- if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_PBOS))
- use_malloc = TRUE;
- else
- use_malloc = FALSE;
/* parent's constructor */
_cogl_buffer_initialize (buffer,
context,
size,
- use_malloc,
COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
COGL_BUFFER_USAGE_HINT_TEXTURE,
COGL_BUFFER_UPDATE_HINT_STATIC);
--
1.7.7.6
More information about the Cogl
mailing list