buffer: move choice about using malloc closer to driver
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. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 06d46f10bf755d3009c28904e616a0adb4586cf5)
This commit is contained in:
parent
ffd2cf8ef8
commit
91a02e9107
@ -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);
|
||||
|
@ -115,8 +115,7 @@ _cogl_buffer_register_buffer_type (const CoglObjectClass *klass);
|
||||
void
|
||||
_cogl_buffer_initialize (CoglBuffer *buffer,
|
||||
CoglContext *context,
|
||||
unsigned int size,
|
||||
CoglBool use_malloc,
|
||||
size_t size,
|
||||
CoglBufferBindTarget default_target,
|
||||
CoglBufferUsageHint usage_hint,
|
||||
CoglBufferUpdateHint update_hint);
|
||||
|
@ -294,12 +294,13 @@ malloc_set_data (CoglBuffer *buffer,
|
||||
void
|
||||
_cogl_buffer_initialize (CoglBuffer *buffer,
|
||||
CoglContext *context,
|
||||
unsigned int size,
|
||||
CoglBool use_malloc,
|
||||
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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user