[gtk+/wip/otte/shader: 138/269] gsksltype: Add gsk_sl_type_get_index_stride()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 138/269] gsksltype: Add gsk_sl_type_get_index_stride()
- Date: Tue, 24 Oct 2017 06:02:12 +0000 (UTC)
commit e53916a572cb913d2e372ba8474a9bde8aee4aee
Author: Benjamin Otte <otte redhat com>
Date: Wed Sep 27 03:12:55 2017 +0200
gsksltype: Add gsk_sl_type_get_index_stride()
This allows operations on GskSlValues that are arrays, because one can
just do code like:
data = gsk_sl_value_get_data (value);
stride = gsk_sl_value_get_index_stride (type);
for (i = 0; i < gsk_sl_value_get_length (type); i++)
{
do_stuff_with_data (data + i * stride);
}
gsk/gsksltype.c | 32 ++++++++++++++++++++++++++++++++
gsk/gsksltypeprivate.h | 1 +
gsk/gskslvalue.c | 4 ++--
3 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/gsk/gsksltype.c b/gsk/gsksltype.c
index 9510557..80b2199 100644
--- a/gsk/gsksltype.c
+++ b/gsk/gsksltype.c
@@ -44,6 +44,7 @@ struct _GskSlTypeClass {
const char * (* get_name) (const GskSlType *type);
GskSlScalarType (* get_scalar_type) (const GskSlType *type);
GskSlType * (* get_index_type) (const GskSlType *type);
+ gsize (* get_index_stride) (const GskSlType *type);
guint (* get_length) (const GskSlType *type);
gsize (* get_size) (const GskSlType *type);
gboolean (* can_convert) (const GskSlType *target,
@@ -349,6 +350,12 @@ gsk_sl_type_scalar_get_index_type (const GskSlType *type)
return NULL;
}
+static gsize
+gsk_sl_type_scalar_get_index_stride (const GskSlType *type)
+{
+ return 0;
+}
+
static guint
gsk_sl_type_scalar_get_length (const GskSlType *type)
{
@@ -472,6 +479,7 @@ static const GskSlTypeClass GSK_SL_TYPE_SCALAR = {
gsk_sl_type_scalar_get_name,
gsk_sl_type_scalar_get_scalar_type,
gsk_sl_type_scalar_get_index_type,
+ gsk_sl_type_scalar_get_index_stride,
gsk_sl_type_scalar_get_length,
gsk_sl_type_scalar_get_size,
gsk_sl_type_scalar_can_convert,
@@ -522,6 +530,14 @@ gsk_sl_type_vector_get_index_type (const GskSlType *type)
return gsk_sl_type_get_scalar (vector->scalar);
}
+static gsize
+gsk_sl_type_vector_get_index_stride (const GskSlType *type)
+{
+ const GskSlTypeVector *vector = (const GskSlTypeVector *) type;
+
+ return scalar_infos[vector->scalar].size;
+}
+
static guint
gsk_sl_type_vector_get_length (const GskSlType *type)
{
@@ -636,6 +652,7 @@ static const GskSlTypeClass GSK_SL_TYPE_VECTOR = {
gsk_sl_type_vector_get_name,
gsk_sl_type_vector_get_scalar_type,
gsk_sl_type_vector_get_index_type,
+ gsk_sl_type_vector_get_index_stride,
gsk_sl_type_vector_get_length,
gsk_sl_type_vector_get_size,
gsk_sl_type_vector_can_convert,
@@ -687,6 +704,14 @@ gsk_sl_type_matrix_get_index_type (const GskSlType *type)
return gsk_sl_type_get_vector (matrix->scalar, matrix->rows);
}
+static gsize
+gsk_sl_type_matrix_get_index_stride (const GskSlType *type)
+{
+ const GskSlTypeMatrix *matrix = (const GskSlTypeMatrix *) type;
+
+ return scalar_infos[matrix->scalar].size * matrix->rows;
+}
+
static guint
gsk_sl_type_matrix_get_length (const GskSlType *type)
{
@@ -802,6 +827,7 @@ static const GskSlTypeClass GSK_SL_TYPE_MATRIX = {
gsk_sl_type_matrix_get_name,
gsk_sl_type_matrix_get_scalar_type,
gsk_sl_type_matrix_get_index_type,
+ gsk_sl_type_matrix_get_index_stride,
gsk_sl_type_matrix_get_length,
gsk_sl_type_matrix_get_size,
gsk_sl_type_matrix_can_convert,
@@ -1124,6 +1150,12 @@ gsk_sl_type_get_index_type (const GskSlType *type)
return type->class->get_index_type (type);
}
+gsize
+gsk_sl_type_get_index_stride (const GskSlType *type)
+{
+ return type->class->get_index_stride (type);
+}
+
guint
gsk_sl_type_get_length (const GskSlType *type)
{
diff --git a/gsk/gsksltypeprivate.h b/gsk/gsksltypeprivate.h
index efb8f85..a23f3be 100644
--- a/gsk/gsksltypeprivate.h
+++ b/gsk/gsksltypeprivate.h
@@ -52,6 +52,7 @@ gboolean gsk_sl_type_is_matrix (const GskSlType
const char * gsk_sl_type_get_name (const GskSlType *type);
GskSlScalarType gsk_sl_type_get_scalar_type (const GskSlType *type);
GskSlType * gsk_sl_type_get_index_type (const GskSlType *type);
+gsize gsk_sl_type_get_index_stride (const GskSlType *type);
guint gsk_sl_type_get_length (const GskSlType *type);
gsize gsk_sl_type_get_size (const GskSlType *type);
gboolean gsk_sl_scalar_type_can_convert (GskSlScalarType target,
diff --git a/gsk/gskslvalue.c b/gsk/gskslvalue.c
index ff52e3f..4049730 100644
--- a/gsk/gskslvalue.c
+++ b/gsk/gskslvalue.c
@@ -113,8 +113,8 @@ gsk_sl_value_new_convert (GskSlValue *source,
result = gsk_sl_value_new (new_type);
sdata = source->data;
ddata = result->data;
- sstride = gsk_sl_type_get_size (source->type) / n;
- dstride = gsk_sl_type_get_size (new_type) / n;
+ sstride = gsk_sl_type_get_index_stride (source->type);
+ dstride = gsk_sl_type_get_index_stride (new_type);
for (i = 0; i < n; i++)
{
gsk_sl_scalar_type_convert_value (gsk_sl_type_get_scalar_type (new_type),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]