Compare commits
3 Commits
gpu-desc-n
...
gpu-2d-typ
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdc6ef5b8b | ||
|
|
81da31d662 | ||
|
|
f3c2cdb94d |
497
gsk/boxprivate.h
Normal file
497
gsk/boxprivate.h
Normal file
@@ -0,0 +1,497 @@
|
||||
#pragma once
|
||||
|
||||
#include <graphene.h>
|
||||
#include <math.h>
|
||||
#include "gsktypesprivate.h"
|
||||
#include "scaleprivate.h"
|
||||
#include "pointprivate.h"
|
||||
|
||||
#ifndef USE_SIMD
|
||||
|
||||
struct _Box
|
||||
{
|
||||
float x0, y0, x1, y1;
|
||||
};
|
||||
|
||||
static inline float
|
||||
box_x0 (const Box box)
|
||||
{
|
||||
return box.x0;
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_y0 (const Box box)
|
||||
{
|
||||
return box.y0;
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_x1 (const Box box)
|
||||
{
|
||||
return box.x1;
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_y1 (const Box box)
|
||||
{
|
||||
return box.y1;
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_width (const Box box)
|
||||
{
|
||||
return box.x1 - box.x0;
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_height (const Box box)
|
||||
{
|
||||
return box.y1 - box.y0;
|
||||
}
|
||||
|
||||
/* Assumes x0 <= x1 && y0 <= y1 */
|
||||
static inline Box
|
||||
box (float x0,
|
||||
float y0,
|
||||
float x1,
|
||||
float y1)
|
||||
{
|
||||
return (Box) { .x0 = x0, .y0 = y0, .x1 = x1, .y1 = y1 };
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_from_rect (float x,
|
||||
float y,
|
||||
float w,
|
||||
float h)
|
||||
{
|
||||
return box (x, y, x + w, y + h);
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_from_graphene (const graphene_rect_t *rect)
|
||||
{
|
||||
return box_from_rect (rect->origin.x,
|
||||
rect->origin.y,
|
||||
rect->size.width,
|
||||
rect->size.height);
|
||||
}
|
||||
|
||||
static inline void
|
||||
box_to_graphene (const Box box,
|
||||
graphene_rect_t *rect)
|
||||
{
|
||||
graphene_rect_init (rect, box.x0, box.y0, box.x1 - box.x0, box.y1 - box.y0);
|
||||
}
|
||||
|
||||
/* Assumes p0.x <= p1.x && p0.y <= p1.y */
|
||||
static inline Box
|
||||
box_from_points (Point p0,
|
||||
Point p1)
|
||||
{
|
||||
return box (p0.x, p0.y, p1.x, p1.y);
|
||||
}
|
||||
|
||||
static inline Point
|
||||
box_origin (const Box box)
|
||||
{
|
||||
return point (box.x0, box.y0);
|
||||
}
|
||||
|
||||
static inline Point
|
||||
box_opposite (const Box box)
|
||||
{
|
||||
return point (box.x1, box.y1);
|
||||
}
|
||||
|
||||
static inline void
|
||||
box_to_float (const Box box,
|
||||
float v[4])
|
||||
{
|
||||
v[0] = box.x0;
|
||||
v[1] = box.y0;
|
||||
v[2] = box.x1 - box.x0;
|
||||
v[3] = box.y1 - box.y0;
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_inset (const Box box,
|
||||
float dx,
|
||||
float dy)
|
||||
{
|
||||
return (Box) { .x0 = box.x0 + dx, .y0 = box.y0 + dy,
|
||||
.x1 = box.x1 - dx, .y1 = box.y1 - dy };
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
box_intersect (const Box box1,
|
||||
const Box box2,
|
||||
Box *box)
|
||||
{
|
||||
Box b;
|
||||
|
||||
b.x0 = MAX (box1.x0, box2.x0);
|
||||
b.y0 = MAX (box1.y0, box2.y0);
|
||||
b.x1 = MIN (box1.x1, box2.x1);
|
||||
b.y1 = MIN (box1.y1, box2.y1);
|
||||
|
||||
if (b.x0 <= b.x1 && b.y0 <= b.x1)
|
||||
{
|
||||
if (box)
|
||||
*box = b;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
box_equal (const Box box1,
|
||||
const Box box2)
|
||||
{
|
||||
return memcmp (&box1, &box2, sizeof (Box)) == 0;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
box_contains (const Box box1,
|
||||
const Box box2)
|
||||
{
|
||||
Box box;
|
||||
|
||||
if (box_intersect (box1, box2, &box))
|
||||
return box_equal (box, box2);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
box_empty (const Box box)
|
||||
{
|
||||
return box.x0 == box.x1 || box.y0 == box.y1;
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_add (const Box box,
|
||||
const Point offset)
|
||||
{
|
||||
return (Box) { .x0 = box.x0 + offset.x, .y0 = box.y0 + offset.y,
|
||||
.x1 = box.x1 + offset.x, .y1 = box.y1 + offset.y };
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_sub (const Box box,
|
||||
const Point offset)
|
||||
{
|
||||
return (Box) { .x0 = box.x0 - offset.x, .y0 = box.y0 - offset.y,
|
||||
.x1 = box.x1 - offset.x, .y1 = box.y1 - offset.y };
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_mul (const Box box,
|
||||
const Scale scale)
|
||||
{
|
||||
Box b = (Box) { .x0 = box.x0 * scale.x, .y0 = box.y0 * scale.y,
|
||||
.x1 = box.x1 * scale.x, .y1 = box.y1 * scale.y };
|
||||
|
||||
if (G_UNLIKELY (scale.x < 0 || scale.y < 0))
|
||||
return (Box) { .x0 = MIN (b.x0, b.x1), .y0 = MIN (b.y0, b.y1),
|
||||
.x1 = MAX (b.x0, b.x1), .y1 = MAX (b.y0, b.y1) };
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_div (const Box box,
|
||||
const Scale scale)
|
||||
{
|
||||
return box_mul (box, scale_inv (scale));
|
||||
}
|
||||
|
||||
static inline void
|
||||
box_offset_to_float (const Box box,
|
||||
const Point offset,
|
||||
float v[4])
|
||||
{
|
||||
box_to_float (box_add (box, offset), v);
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_round_larger (const Box box)
|
||||
{
|
||||
return (Box) { .x0 = floorf (box.x0), .y0 = floorf (box.y0),
|
||||
.x1 = ceilf (box.x1), .y1 = ceilf (box.y1) };
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_round_to_pixels (const Box box,
|
||||
const Scale scale,
|
||||
const Point offset)
|
||||
{
|
||||
return box_sub (box_div (box_round_larger (box_mul (box_add (box, offset), scale)), scale), offset);
|
||||
}
|
||||
|
||||
#else /* USE_SIMD */
|
||||
|
||||
struct _Box
|
||||
{
|
||||
GRAPHENE_ALIGNED_DECL (graphene_simd4f_t v, 16);
|
||||
};
|
||||
|
||||
static inline float
|
||||
box_x0 (const Box box)
|
||||
{
|
||||
return graphene_simd4f_get_x (box.v);
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_y0 (const Box box)
|
||||
{
|
||||
return graphene_simd4f_get_y (box.v);
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_x1 (const Box box)
|
||||
{
|
||||
return graphene_simd4f_get_z (box.v);
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_y1 (const Box box)
|
||||
{
|
||||
return graphene_simd4f_get_w (box.v);
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_width (const Box box)
|
||||
{
|
||||
return box_x1 (box) - box_x0 (box);
|
||||
}
|
||||
|
||||
static inline float
|
||||
box_height (const Box box)
|
||||
{
|
||||
return box_y1 (box) - box_y0 (box);
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box (float x0,
|
||||
float y0,
|
||||
float x1,
|
||||
float y1)
|
||||
{
|
||||
return (Box) { .v = graphene_simd4f_init (x0, y0, x1, y1) };
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_from_rect (float x,
|
||||
float y,
|
||||
float w,
|
||||
float h)
|
||||
{
|
||||
return box (x, y, x + w, y + h);
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_from_graphene (const graphene_rect_t *rect)
|
||||
{
|
||||
return box_from_rect (rect->origin.x,
|
||||
rect->origin.y,
|
||||
rect->size.width,
|
||||
rect->size.height);
|
||||
}
|
||||
|
||||
static inline void
|
||||
box_to_graphene (const Box box,
|
||||
graphene_rect_t *rect)
|
||||
{
|
||||
graphene_rect_init (rect, box_x0 (box),
|
||||
box_y0 (box),
|
||||
box_x1 (box) - box_x0 (box),
|
||||
box_y1 (box) - box_y0 (box));
|
||||
}
|
||||
|
||||
/* Assumes p0.x <= p1.x && p0.y <= p1.y */
|
||||
/* { a[0], a[1], b[0], b[1] } */
|
||||
# define graphene_simd4f_splat_xyxy(a,b) \
|
||||
(__extension__ ({ \
|
||||
(graphene_simd4f_t) _mm_shuffle_ps ((a), (b), _MM_SHUFFLE (1, 0, 1, 0)); \
|
||||
}))
|
||||
|
||||
static inline Box
|
||||
box_from_points (Point p0,
|
||||
Point p1)
|
||||
{
|
||||
return (Box) { .v = graphene_simd4f_splat_xyxy (p0.v, p1.v) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
box_origin (const Box box)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_zero_zw (box.v) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
box_opposite (const Box box)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_zero_zw (graphene_simd4f_shuffle_zwxy (box.v)) };
|
||||
}
|
||||
|
||||
static inline void
|
||||
box_to_float (const Box box,
|
||||
float v[4])
|
||||
{
|
||||
graphene_simd4f_dup_4f (box.v, v);
|
||||
v[2] -= v[0];
|
||||
v[3] -= v[1];
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_inset (const Box box,
|
||||
float dx,
|
||||
float dy)
|
||||
{
|
||||
return (Box) { .v = graphene_simd4f_add (box.v, graphene_simd4f_init (dx, dy, -dx, -dy)) };
|
||||
}
|
||||
|
||||
/* return a[0] < b[0] && a[1] < b[1] */
|
||||
#ifndef graphene_simd4f_cmple_xy
|
||||
# define graphene_simd4f_cmple_xy(a,b) \
|
||||
(__extension__ ({ \
|
||||
__m128i __res = (__m128i) _mm_cmple_ps ((a), (b)); \
|
||||
(bool) ((_mm_movemask_epi8 (__res) & 0xff) == 0xff); \
|
||||
}))
|
||||
#endif
|
||||
|
||||
static inline gboolean
|
||||
box_intersect (const Box box1,
|
||||
const Box box2,
|
||||
Box *box)
|
||||
{
|
||||
graphene_simd4f_t s, t, t1;
|
||||
|
||||
s = graphene_simd4f_max (box1.v, box2.v);
|
||||
t = graphene_simd4f_min (box1.v, box2.v);
|
||||
t1 = graphene_simd4f_shuffle_zwxy (t);
|
||||
|
||||
if (graphene_simd4f_cmple_xy (s, t1))
|
||||
{
|
||||
if (box)
|
||||
box->v = graphene_simd4f_splat_xyxy (s, t);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
box_equal (const Box box1,
|
||||
const Box box2)
|
||||
{
|
||||
return (gboolean) !!graphene_simd4f_cmp_eq (box1.v, box2.v);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
box_contains (const Box box1,
|
||||
const Box box2)
|
||||
{
|
||||
Box box;
|
||||
|
||||
if (box_intersect (box1, box2, &box))
|
||||
return box_equal (box, box2);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
box_empty (const Box box)
|
||||
{
|
||||
/* FIXME simd */
|
||||
return box_x0 (box) == box_x1 (box) || box_y0 (box) == box_y1 (box);
|
||||
}
|
||||
|
||||
/* a splat variation */
|
||||
#ifndef graphene_simd4f_shuffle_xyxy
|
||||
# define graphene_simd4f_shuffle_xyxy(v) \
|
||||
(__extension__ ({ \
|
||||
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (1, 0, 1, 0)); \
|
||||
}))
|
||||
#endif
|
||||
|
||||
static inline Box
|
||||
box_add (const Box box,
|
||||
const Point offset)
|
||||
{
|
||||
return (Box) { .v = graphene_simd4f_add (box.v, graphene_simd4f_shuffle_xyxy (offset.v)) };
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_sub (const Box box,
|
||||
const Point offset)
|
||||
{
|
||||
return (Box) { .v = graphene_simd4f_sub (box.v, graphene_simd4f_shuffle_xyxy (offset.v)) };
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_mul (const Box box,
|
||||
const Scale scale)
|
||||
{
|
||||
Box b = (Box) { .v = graphene_simd4f_mul (box.v, graphene_simd4f_shuffle_xyxy (scale.v)) };
|
||||
|
||||
if (G_UNLIKELY (!graphene_simd4f_cmple_xy (graphene_simd4f_init (0, 0, 0, 0), scale.v)))
|
||||
{
|
||||
graphene_simd4f_t v = graphene_simd4f_shuffle_zwxy (b.v);
|
||||
graphene_simd4f_t s = graphene_simd4f_min (b.v, v);
|
||||
graphene_simd4f_t t = graphene_simd4f_max (b.v, v);
|
||||
|
||||
return (Box) { .v = graphene_simd4f_splat_xyxy (s, t) };
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static inline Box
|
||||
box_div (const Box box,
|
||||
const Scale scale)
|
||||
{
|
||||
return box_mul (box, scale_inv (scale));
|
||||
}
|
||||
|
||||
static inline void
|
||||
box_offset_to_float (const Box box,
|
||||
const Point offset,
|
||||
float v[4])
|
||||
{
|
||||
box_to_float (box_add (box, offset), v);
|
||||
}
|
||||
|
||||
#ifdef __SSE4_1__
|
||||
|
||||
static inline Box
|
||||
box_round_larger (const Box box)
|
||||
{
|
||||
return { (Box) .v = graphene_simd4f_splat_xyxy (graphene_simd4f_floor (b.v), graphene_simd4f_ceil (b.v)) };
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline Box
|
||||
box_round_larger (const Box b)
|
||||
{
|
||||
return box (floorf (box_x0 (b)),
|
||||
floorf (box_y0 (b)),
|
||||
ceilf (box_x1 (b)),
|
||||
ceilf (box_y1 (b)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static inline Box
|
||||
box_round_to_pixels (const Box box,
|
||||
const Scale scale,
|
||||
const Point offset)
|
||||
{
|
||||
return box_sub (box_div (box_round_larger (box_mul (box_add (box, offset), scale)), scale), offset);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "gskglbufferprivate.h"
|
||||
#include "gskglimageprivate.h"
|
||||
|
||||
|
||||
struct _GskGLDescriptors
|
||||
{
|
||||
GskGpuDescriptors parent_instance;
|
||||
@@ -14,12 +13,16 @@ struct _GskGLDescriptors
|
||||
guint n_external;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GskGLDescriptors, gsk_gl_descriptors, GSK_TYPE_GPU_DESCRIPTORS)
|
||||
|
||||
static void
|
||||
gsk_gl_descriptors_finalize (GskGpuDescriptors *desc)
|
||||
gsk_gl_descriptors_finalize (GObject *object)
|
||||
{
|
||||
GskGLDescriptors *self = GSK_GL_DESCRIPTORS (desc);
|
||||
GskGLDescriptors *self = GSK_GL_DESCRIPTORS (object);
|
||||
|
||||
g_object_unref (self->device);
|
||||
|
||||
G_OBJECT_CLASS (gsk_gl_descriptors_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -69,24 +72,33 @@ gsk_gl_descriptors_add_buffer (GskGpuDescriptors *desc,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GskGpuDescriptorsClass GSK_GL_DESCRIPTORS_CLASS =
|
||||
static void
|
||||
gsk_gl_descriptors_class_init (GskGLDescriptorsClass *klass)
|
||||
{
|
||||
.finalize = gsk_gl_descriptors_finalize,
|
||||
.add_image = gsk_gl_descriptors_add_image,
|
||||
.add_buffer = gsk_gl_descriptors_add_buffer,
|
||||
};
|
||||
GskGpuDescriptorsClass *descriptors_class = GSK_GPU_DESCRIPTORS_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = gsk_gl_descriptors_finalize;
|
||||
|
||||
descriptors_class->add_image = gsk_gl_descriptors_add_image;
|
||||
descriptors_class->add_buffer = gsk_gl_descriptors_add_buffer;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_gl_descriptors_init (GskGLDescriptors *self)
|
||||
{
|
||||
}
|
||||
|
||||
GskGpuDescriptors *
|
||||
gsk_gl_descriptors_new (GskGLDevice *device)
|
||||
{
|
||||
GskGpuDescriptors *desc;
|
||||
GskGLDescriptors *self;
|
||||
|
||||
desc = gsk_gpu_descriptors_new ((GskGpuDescriptorsClass *) &GSK_GL_DESCRIPTORS_CLASS,
|
||||
sizeof (GskGLDescriptors));
|
||||
self = g_object_new (GSK_TYPE_GL_DESCRIPTORS, NULL);
|
||||
|
||||
GSK_GL_DESCRIPTORS (desc)->device = g_object_ref (device);
|
||||
self->device = g_object_ref (device);
|
||||
|
||||
return desc;
|
||||
return GSK_GPU_DESCRIPTORS (self);
|
||||
}
|
||||
|
||||
guint
|
||||
@@ -98,7 +110,7 @@ gsk_gl_descriptors_get_n_external (GskGLDescriptors *self)
|
||||
void
|
||||
gsk_gl_descriptors_use (GskGLDescriptors *self)
|
||||
{
|
||||
GskGpuDescriptors *desc = &self->parent_instance;
|
||||
GskGpuDescriptors *desc = GSK_GPU_DESCRIPTORS (self);
|
||||
gsize i, ext, n_textures;
|
||||
|
||||
n_textures = 16 - 3 * self->n_external;
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskGLDescriptors GskGLDescriptors;
|
||||
|
||||
#define GSK_GL_DESCRIPTORS(d) ((GskGLDescriptors *) (d))
|
||||
#define GSK_TYPE_GL_DESCRIPTORS (gsk_gl_descriptors_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GskGLDescriptors, gsk_gl_descriptors, GSK, GL_DESCRIPTORS, GskGpuDescriptors)
|
||||
|
||||
GskGpuDescriptors * gsk_gl_descriptors_new (GskGLDevice *device);
|
||||
|
||||
|
||||
@@ -52,39 +52,43 @@ gsk_gpu_buffer_entry_clear (gpointer data)
|
||||
#define GDK_ARRAY_NO_MEMSET 1
|
||||
#include "gdk/gdkarrayimpl.c"
|
||||
|
||||
typedef struct _GskGpuDescriptorsPrivate GskGpuDescriptorsPrivate;
|
||||
|
||||
struct _GskGpuDescriptorsPrivate
|
||||
{
|
||||
GskGpuImageEntries images;
|
||||
GskGpuBufferEntries buffers;
|
||||
};
|
||||
|
||||
static inline GskGpuDescriptorsPrivate *
|
||||
gsk_gpu_descriptors_get_instance_private (GskGpuDescriptors *self)
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GskGpuDescriptors, gsk_gpu_descriptors, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
gsk_gpu_descriptors_finalize (GObject *object)
|
||||
{
|
||||
return (GskGpuDescriptorsPrivate *) (((guchar *)self) - sizeof (GskGpuDescriptorsPrivate));
|
||||
GskGpuDescriptors *self = GSK_GPU_DESCRIPTORS (object);
|
||||
GskGpuDescriptorsPrivate *priv = gsk_gpu_descriptors_get_instance_private (self);
|
||||
|
||||
gsk_gpu_image_entries_clear (&priv->images);
|
||||
gsk_gpu_buffer_entries_clear (&priv->buffers);
|
||||
|
||||
G_OBJECT_CLASS (gsk_gpu_descriptors_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
/* Just for subclasses */
|
||||
GskGpuDescriptors *
|
||||
gsk_gpu_descriptors_new (GskGpuDescriptorsClass *desc_class,
|
||||
gsize child_size)
|
||||
static void
|
||||
gsk_gpu_descriptors_class_init (GskGpuDescriptorsClass *klass)
|
||||
{
|
||||
GskGpuDescriptors *self;
|
||||
GskGpuDescriptorsPrivate *priv;
|
||||
guchar *data;
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
data = g_new0 (guchar, child_size + sizeof (GskGpuDescriptorsPrivate));
|
||||
object_class->finalize = gsk_gpu_descriptors_finalize;
|
||||
}
|
||||
|
||||
priv = (GskGpuDescriptorsPrivate *) data;
|
||||
self = (GskGpuDescriptors *) (data + sizeof (GskGpuDescriptorsPrivate));
|
||||
|
||||
self->ref_count = 1;
|
||||
self->desc_class = desc_class;
|
||||
static void
|
||||
gsk_gpu_descriptors_init (GskGpuDescriptors *self)
|
||||
{
|
||||
GskGpuDescriptorsPrivate *priv = gsk_gpu_descriptors_get_instance_private (self);
|
||||
|
||||
gsk_gpu_image_entries_init (&priv->images);
|
||||
gsk_gpu_buffer_entries_init (&priv->buffers);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
gsize
|
||||
@@ -185,7 +189,7 @@ gsk_gpu_descriptors_add_image (GskGpuDescriptors *self,
|
||||
}
|
||||
}
|
||||
|
||||
if (!self->desc_class->add_image (self, image, sampler, &descriptor))
|
||||
if (!GSK_GPU_DESCRIPTORS_GET_CLASS (self)->add_image (self, image, sampler, &descriptor))
|
||||
return FALSE;
|
||||
|
||||
gsk_gpu_image_entries_append (&priv->images,
|
||||
@@ -220,7 +224,7 @@ gsk_gpu_descriptors_add_buffer (GskGpuDescriptors *self,
|
||||
}
|
||||
}
|
||||
|
||||
if (!self->desc_class->add_buffer (self, buffer, &descriptor))
|
||||
if (!GSK_GPU_DESCRIPTORS_GET_CLASS (self)->add_buffer (self, buffer, &descriptor))
|
||||
return FALSE;
|
||||
|
||||
gsk_gpu_buffer_entries_append (&priv->buffers,
|
||||
@@ -234,28 +238,3 @@ gsk_gpu_descriptors_add_buffer (GskGpuDescriptors *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GskGpuDescriptors *
|
||||
gsk_gpu_descriptors_ref (GskGpuDescriptors *self)
|
||||
{
|
||||
self->ref_count++;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
gsk_gpu_descriptors_unref (GskGpuDescriptors *self)
|
||||
{
|
||||
self->ref_count--;
|
||||
|
||||
if (self->ref_count == 0)
|
||||
{
|
||||
GskGpuDescriptorsPrivate *priv = gsk_gpu_descriptors_get_instance_private (self);
|
||||
|
||||
self->desc_class->finalize (self);
|
||||
|
||||
gsk_gpu_image_entries_clear (&priv->images);
|
||||
gsk_gpu_buffer_entries_clear (&priv->buffers);
|
||||
|
||||
g_free (priv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,24 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskGpuDescriptors GskGpuDescriptors;
|
||||
typedef struct _GskGpuDescriptorsClass GskGpuDescriptorsClass;
|
||||
typedef struct _GskGpuDescriptorsPrivate GskGpuDescriptorsPrivate;
|
||||
#define GSK_TYPE_GPU_DESCRIPTORS (gsk_gpu_descriptors_get_type ())
|
||||
#define GSK_GPU_DESCRIPTORS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSK_TYPE_GPU_DESCRIPTORS, GskGpuDescriptors))
|
||||
#define GSK_GPU_DESCRIPTORS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSK_TYPE_GPU_DESCRIPTORS, GskGpuDescriptorsClass))
|
||||
#define GSK_IS_GPU_DESCRIPTORS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSK_TYPE_GPU_DESCRIPTORS))
|
||||
#define GSK_IS_GPU_DESCRIPTORS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSK_TYPE_GPU_DESCRIPTORS))
|
||||
#define GSK_GPU_DESCRIPTORS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSK_TYPE_GPU_DESCRIPTORS, GskGpuDescriptorsClass))
|
||||
|
||||
#define GSK_GPU_DESCRIPTORS(d) ((GskGpuDescriptors *) (d))
|
||||
typedef struct _GskGpuDescriptorsClass GskGpuDescriptorsClass;
|
||||
|
||||
struct _GskGpuDescriptors
|
||||
{
|
||||
GskGpuDescriptorsClass *desc_class;
|
||||
int ref_count;
|
||||
|
||||
GskGpuDescriptorsPrivate *priv;
|
||||
GObject parent_instance;
|
||||
};
|
||||
|
||||
struct _GskGpuDescriptorsClass
|
||||
{
|
||||
void (* finalize) (GskGpuDescriptors *self);
|
||||
GObjectClass parent_class;
|
||||
|
||||
gboolean (* add_image) (GskGpuDescriptors *self,
|
||||
GskGpuImage *image,
|
||||
GskGpuSampler sampler,
|
||||
@@ -30,8 +31,7 @@ struct _GskGpuDescriptorsClass
|
||||
guint32 *out_id);
|
||||
};
|
||||
|
||||
GskGpuDescriptors * gsk_gpu_descriptors_ref (GskGpuDescriptors *self);
|
||||
void gsk_gpu_descriptors_unref (GskGpuDescriptors *self);
|
||||
GType gsk_gpu_descriptors_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gsize gsk_gpu_descriptors_get_n_images (GskGpuDescriptors *self);
|
||||
gsize gsk_gpu_descriptors_get_n_buffers (GskGpuDescriptors *self);
|
||||
@@ -55,8 +55,7 @@ gboolean gsk_gpu_descriptors_add_buffer (GskGpuD
|
||||
GskGpuBuffer *buffer,
|
||||
guint32 *out_descriptor);
|
||||
|
||||
GskGpuDescriptors *gsk_gpu_descriptors_new (GskGpuDescriptorsClass *desc_class,
|
||||
gsize child_size);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GskGpuDescriptors, g_object_unref)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -45,6 +45,10 @@
|
||||
#include "gdk/gdkrgbaprivate.h"
|
||||
#include "gdk/gdksubsurfaceprivate.h"
|
||||
|
||||
#include "gsk/scaleprivate.h"
|
||||
#include "gsk/pointprivate.h"
|
||||
#include "gsk/boxprivate.h"
|
||||
|
||||
/* the epsilon we allow pixels to be off due to rounding errors.
|
||||
* Chosen rather randomly.
|
||||
*/
|
||||
@@ -152,7 +156,7 @@ static void
|
||||
gsk_gpu_node_processor_finish (GskGpuNodeProcessor *self)
|
||||
{
|
||||
g_clear_pointer (&self->modelview, gsk_transform_unref);
|
||||
g_clear_pointer (&self->desc, gsk_gpu_descriptors_unref);
|
||||
g_clear_object (&self->desc);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -170,7 +174,7 @@ gsk_gpu_node_processor_init (GskGpuNodeProcessor *self,
|
||||
|
||||
self->frame = frame;
|
||||
if (desc)
|
||||
self->desc = gsk_gpu_descriptors_ref (desc);
|
||||
self->desc = g_object_ref (desc);
|
||||
else
|
||||
self->desc = NULL;
|
||||
|
||||
@@ -268,7 +272,7 @@ gsk_gpu_node_processor_add_image (GskGpuNodeProcessor *self,
|
||||
if (gsk_gpu_descriptors_add_image (self->desc, image, sampler, &descriptor))
|
||||
return descriptor;
|
||||
|
||||
gsk_gpu_descriptors_unref (self->desc);
|
||||
g_object_unref (self->desc);
|
||||
}
|
||||
|
||||
self->desc = gsk_gpu_frame_create_descriptors (self->frame);
|
||||
@@ -545,7 +549,7 @@ gsk_gpu_pattern_writer_finish (GskGpuPatternWriter *self)
|
||||
{
|
||||
pattern_buffer_clear (&self->buffer);
|
||||
g_assert (self->stack == 0);
|
||||
g_clear_pointer (&self->desc, gsk_gpu_descriptors_unref);
|
||||
g_clear_object (&self->desc);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -2996,16 +3000,13 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
|
||||
GskGpuDevice *device;
|
||||
const PangoGlyphInfo *glyphs;
|
||||
PangoFont *font;
|
||||
graphene_point_t offset;
|
||||
Point offset;
|
||||
Scale s, pango_scale, s4, ss;
|
||||
guint i, num_glyphs;
|
||||
float scale, inv_scale;
|
||||
GdkRGBA color;
|
||||
float align_scale_x, align_scale_y;
|
||||
float inv_align_scale_x, inv_align_scale_y;
|
||||
unsigned int flags_mask;
|
||||
GskGpuImage *last_image;
|
||||
guint32 descriptor;
|
||||
const float inv_pango_scale = 1.f / PANGO_SCALE;
|
||||
gboolean glyph_align;
|
||||
gboolean hinting;
|
||||
unsigned int mask;
|
||||
|
||||
if (self->opacity < 1.0 &&
|
||||
gsk_text_node_has_color_glyphs (node))
|
||||
@@ -3021,71 +3022,68 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
|
||||
num_glyphs = gsk_text_node_get_num_glyphs (node);
|
||||
glyphs = gsk_text_node_get_glyphs (node, NULL);
|
||||
font = gsk_text_node_get_font (node);
|
||||
offset = *gsk_text_node_get_offset (node);
|
||||
offset.x += self->offset.x;
|
||||
offset.y += self->offset.y;
|
||||
offset = point_add (point_from_graphene (gsk_text_node_get_offset (node)),
|
||||
point_from_graphene (&self->offset));
|
||||
s = scale_max (scale_from_graphene (&self->scale));
|
||||
s4 = scale_mul (s, scale_from_float (4));
|
||||
pango_scale = scale_from_float (PANGO_SCALE);
|
||||
|
||||
scale = MAX (graphene_vec2_get_x (&self->scale), graphene_vec2_get_y (&self->scale));
|
||||
inv_scale = 1.f / scale;
|
||||
glyph_align = gsk_gpu_frame_should_optimize (self->frame, GSK_GPU_OPTIMIZE_GLYPH_ALIGN);
|
||||
hinting = gsk_font_get_hint_style (font) != CAIRO_HINT_STYLE_NONE;
|
||||
|
||||
if (gsk_font_get_hint_style (font) != CAIRO_HINT_STYLE_NONE)
|
||||
if (hinting && glyph_align)
|
||||
{
|
||||
align_scale_x = scale * 4;
|
||||
align_scale_y = scale;
|
||||
flags_mask = 3;
|
||||
ss = scale (scale_x (s4), scale_y (s));
|
||||
mask = 3;
|
||||
}
|
||||
else if (glyph_align)
|
||||
{
|
||||
ss = s4;
|
||||
mask = 15;
|
||||
}
|
||||
else
|
||||
{
|
||||
align_scale_x = align_scale_y = scale * 4;
|
||||
flags_mask = 15;
|
||||
ss = s;
|
||||
mask = 0;
|
||||
}
|
||||
|
||||
inv_align_scale_x = 1 / align_scale_x;
|
||||
inv_align_scale_y = 1 / align_scale_y;
|
||||
|
||||
last_image = NULL;
|
||||
descriptor = 0;
|
||||
for (i = 0; i < num_glyphs; i++)
|
||||
{
|
||||
GskGpuImage *image;
|
||||
Point origin;
|
||||
graphene_rect_t glyph_bounds, glyph_tex_rect;
|
||||
graphene_point_t glyph_offset, glyph_origin;
|
||||
guint32 descriptor;
|
||||
GskGpuGlyphLookupFlags flags;
|
||||
|
||||
glyph_origin = GRAPHENE_POINT_INIT (offset.x + glyphs[i].geometry.x_offset * inv_pango_scale,
|
||||
offset.y + glyphs[i].geometry.y_offset * inv_pango_scale);
|
||||
origin = point_add (offset, point_div (point (glyphs[i].geometry.x_offset, glyphs[i].geometry.y_offset), pango_scale));
|
||||
|
||||
glyph_origin.x = floorf (glyph_origin.x * align_scale_x + 0.5f);
|
||||
glyph_origin.y = floorf (glyph_origin.y * align_scale_y + 0.5f);
|
||||
flags = (((int) glyph_origin.x & 3) | (((int) glyph_origin.y & 3) << 2)) & flags_mask;
|
||||
glyph_origin.x *= inv_align_scale_x;
|
||||
glyph_origin.y *= inv_align_scale_y;
|
||||
origin = point_round (point_mul (origin, ss));
|
||||
flags = (((int) point_x (origin) & 3) | (((int) point_y (origin) & 3) << 2)) & mask;
|
||||
origin = point_div (origin, ss);
|
||||
|
||||
image = gsk_gpu_device_lookup_glyph_image (device,
|
||||
self->frame,
|
||||
font,
|
||||
glyphs[i].glyph,
|
||||
flags,
|
||||
scale,
|
||||
scale_x (s),
|
||||
&glyph_bounds,
|
||||
&glyph_offset);
|
||||
|
||||
glyph_tex_rect = GRAPHENE_RECT_INIT (-glyph_bounds.origin.x * inv_scale,
|
||||
-glyph_bounds.origin.y * inv_scale,
|
||||
gsk_gpu_image_get_width (image) * inv_scale,
|
||||
gsk_gpu_image_get_height (image) * inv_scale);
|
||||
glyph_tex_rect = GRAPHENE_RECT_INIT (-glyph_bounds.origin.x / scale_x (s),
|
||||
-glyph_bounds.origin.y / scale_y (s),
|
||||
gsk_gpu_image_get_width (image) / scale_x (s),
|
||||
gsk_gpu_image_get_height (image) / scale_y (s));
|
||||
glyph_bounds = GRAPHENE_RECT_INIT (0,
|
||||
0,
|
||||
glyph_bounds.size.width * inv_scale,
|
||||
glyph_bounds.size.height * inv_scale);
|
||||
glyph_origin = GRAPHENE_POINT_INIT (glyph_origin.x - glyph_offset.x * inv_scale,
|
||||
glyph_origin.y - glyph_offset.y * inv_scale);
|
||||
glyph_bounds.size.width / scale_x (s),
|
||||
glyph_bounds.size.height / scale_y (s));
|
||||
|
||||
if (image != last_image)
|
||||
{
|
||||
descriptor = gsk_gpu_node_processor_add_image (self, image, GSK_GPU_SAMPLER_DEFAULT);
|
||||
last_image = image;
|
||||
}
|
||||
point_to_graphene (point_sub (origin, point_div (point_from_graphene (&glyph_offset), s)),
|
||||
&glyph_origin);
|
||||
|
||||
descriptor = gsk_gpu_node_processor_add_image (self, image, GSK_GPU_SAMPLER_DEFAULT);
|
||||
|
||||
if (glyphs[i].attr.is_color)
|
||||
gsk_gpu_texture_op (self->frame,
|
||||
@@ -3105,7 +3103,7 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
|
||||
&glyph_tex_rect,
|
||||
&color);
|
||||
|
||||
offset.x += glyphs[i].geometry.width * inv_pango_scale;
|
||||
offset.x += (float) glyphs[i].geometry.width / PANGO_SCALE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3122,10 +3120,8 @@ gsk_gpu_node_processor_create_glyph_pattern (GskGpuPatternWriter *self,
|
||||
guint32 tex_id;
|
||||
GskGpuImage *last_image;
|
||||
graphene_point_t offset;
|
||||
float align_scale_x, align_scale_y;
|
||||
float inv_align_scale_x, inv_align_scale_y;
|
||||
unsigned int flags_mask;
|
||||
const float inv_pango_scale = 1.f / PANGO_SCALE;
|
||||
gboolean glyph_align;
|
||||
gboolean hinting;
|
||||
|
||||
if (gsk_text_node_has_color_glyphs (node))
|
||||
return FALSE;
|
||||
@@ -3145,20 +3141,8 @@ gsk_gpu_node_processor_create_glyph_pattern (GskGpuPatternWriter *self,
|
||||
gsk_gpu_pattern_writer_append_rgba (self, gsk_text_node_get_color (node));
|
||||
gsk_gpu_pattern_writer_append_uint (self, num_glyphs);
|
||||
|
||||
if (gsk_font_get_hint_style (font) != CAIRO_HINT_STYLE_NONE)
|
||||
{
|
||||
align_scale_x = scale * 4;
|
||||
align_scale_y = scale;
|
||||
flags_mask = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
align_scale_x = align_scale_y = scale * 4;
|
||||
flags_mask = 15;
|
||||
}
|
||||
|
||||
inv_align_scale_x = 1 / align_scale_x;
|
||||
inv_align_scale_y = 1 / align_scale_y;
|
||||
glyph_align = gsk_gpu_frame_should_optimize (self->frame, GSK_GPU_OPTIMIZE_GLYPH_ALIGN);
|
||||
hinting = gsk_font_get_hint_style (font) != CAIRO_HINT_STYLE_NONE;
|
||||
|
||||
last_image = NULL;
|
||||
for (i = 0; i < num_glyphs; i++)
|
||||
@@ -3168,14 +3152,34 @@ gsk_gpu_node_processor_create_glyph_pattern (GskGpuPatternWriter *self,
|
||||
graphene_point_t glyph_offset, glyph_origin;
|
||||
GskGpuGlyphLookupFlags flags;
|
||||
|
||||
glyph_origin = GRAPHENE_POINT_INIT (offset.x + glyphs[i].geometry.x_offset * inv_pango_scale,
|
||||
offset.y + glyphs[i].geometry.y_offset * inv_pango_scale);
|
||||
glyph_origin = GRAPHENE_POINT_INIT (offset.x + (float) glyphs[i].geometry.x_offset / PANGO_SCALE,
|
||||
offset.y + (float) glyphs[i].geometry.y_offset / PANGO_SCALE);
|
||||
|
||||
glyph_origin.x = floorf (glyph_origin.x * align_scale_x + 0.5f);
|
||||
glyph_origin.y = floorf (glyph_origin.y * align_scale_y + 0.5f);
|
||||
flags = (((int) glyph_origin.x & 3) | (((int) glyph_origin.y & 3) << 2)) & flags_mask;
|
||||
glyph_origin.x *= inv_align_scale_x;
|
||||
glyph_origin.y *= inv_align_scale_y;
|
||||
if (hinting && glyph_align)
|
||||
{
|
||||
/* Force glyph_origin.y to be device pixel aligned.
|
||||
* The hinter expects that.
|
||||
*/
|
||||
glyph_origin.x = roundf (glyph_origin.x * scale * 4);
|
||||
flags = ((int) glyph_origin.x & 3);
|
||||
glyph_origin.x = 0.25 * inv_scale * glyph_origin.x;
|
||||
glyph_origin.y = roundf (glyph_origin.y * scale) * inv_scale;
|
||||
}
|
||||
else if (glyph_align)
|
||||
{
|
||||
glyph_origin.x = roundf (glyph_origin.x * scale * 4);
|
||||
glyph_origin.y = roundf (glyph_origin.y * scale * 4);
|
||||
flags = ((int) glyph_origin.x & 3) |
|
||||
(((int) glyph_origin.y & 3) << 2);
|
||||
glyph_origin.x = 0.25 * inv_scale * glyph_origin.x;
|
||||
glyph_origin.y = 0.25 * inv_scale * glyph_origin.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
glyph_origin.x = roundf (glyph_origin.x * scale) * inv_scale;
|
||||
glyph_origin.y = roundf (glyph_origin.y * scale) * inv_scale;
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
image = gsk_gpu_device_lookup_glyph_image (device,
|
||||
self->frame,
|
||||
@@ -3215,7 +3219,7 @@ gsk_gpu_node_processor_create_glyph_pattern (GskGpuPatternWriter *self,
|
||||
),
|
||||
&glyph_origin);
|
||||
|
||||
offset.x += glyphs[i].geometry.width * inv_pango_scale;
|
||||
offset.x += (float) glyphs[i].geometry.width / PANGO_SCALE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
@@ -30,6 +30,7 @@ static const GdkDebugKey gsk_gpu_optimization_keys[] = {
|
||||
{ "blit", GSK_GPU_OPTIMIZE_BLIT, "Use shaders instead of vkCmdBlit()/glBlitFramebuffer()" },
|
||||
{ "gradients", GSK_GPU_OPTIMIZE_GRADIENTS, "Don't supersample gradients" },
|
||||
{ "mipmap", GSK_GPU_OPTIMIZE_MIPMAP, "Avoid creating mipmaps" },
|
||||
{ "glyph-align", GSK_GPU_OPTIMIZE_GLYPH_ALIGN, "Never align glyphs to the subpixel grid" },
|
||||
|
||||
{ "gl-baseinstance", GSK_GPU_OPTIMIZE_GL_BASE_INSTANCE, "Assume no ARB/EXT_base_instance support" },
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ gsk_gpu_shader_op_finish (GskGpuOp *op)
|
||||
{
|
||||
GskGpuShaderOp *self = (GskGpuShaderOp *) op;
|
||||
|
||||
g_clear_pointer (&self->desc, gsk_gpu_descriptors_unref);
|
||||
g_clear_object (&self->desc);
|
||||
}
|
||||
|
||||
#ifdef GDK_RENDERING_VULKAN
|
||||
@@ -197,7 +197,7 @@ gsk_gpu_shader_op_alloc (GskGpuFrame *frame,
|
||||
self->variation = variation;
|
||||
self->clip = clip;
|
||||
if (desc)
|
||||
self->desc = gsk_gpu_descriptors_ref (desc);
|
||||
self->desc = g_object_ref (desc);
|
||||
else
|
||||
self->desc = NULL;
|
||||
self->vertex_offset = gsk_gpu_frame_reserve_vertex_data (frame, op_class->vertex_size);
|
||||
|
||||
@@ -118,7 +118,8 @@ typedef enum {
|
||||
GSK_GPU_OPTIMIZE_BLIT = 1 << 3,
|
||||
GSK_GPU_OPTIMIZE_GRADIENTS = 1 << 4,
|
||||
GSK_GPU_OPTIMIZE_MIPMAP = 1 << 5,
|
||||
GSK_GPU_OPTIMIZE_GLYPH_ALIGN = 1 << 6,
|
||||
/* These require hardware support */
|
||||
GSK_GPU_OPTIMIZE_GL_BASE_INSTANCE = 1 << 6,
|
||||
GSK_GPU_OPTIMIZE_GL_BASE_INSTANCE = 1 << 7,
|
||||
} GskGpuOptimizations;
|
||||
|
||||
|
||||
@@ -6,13 +6,22 @@
|
||||
#include "gskvulkanframeprivate.h"
|
||||
#include "gskvulkanimageprivate.h"
|
||||
|
||||
G_DEFINE_TYPE (GskVulkanDescriptors, gsk_vulkan_descriptors, GSK_TYPE_GPU_DESCRIPTORS)
|
||||
|
||||
static void
|
||||
gsk_vulkan_descriptors_class_init (GskVulkanDescriptorsClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_descriptors_init (GskVulkanDescriptors *self)
|
||||
{
|
||||
}
|
||||
|
||||
GskVulkanPipelineLayout *
|
||||
gsk_vulkan_descriptors_get_pipeline_layout (GskVulkanDescriptors *self)
|
||||
{
|
||||
GskGpuDescriptors *desc = GSK_GPU_DESCRIPTORS (self);
|
||||
GskVulkanDescriptorsClass *class = GSK_VULKAN_DESCRIPTORS_CLASS (desc->desc_class);
|
||||
|
||||
return class->get_pipeline_layout (self);
|
||||
return GSK_VULKAN_DESCRIPTORS_GET_CLASS (self)->get_pipeline_layout (self);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -39,19 +48,5 @@ gsk_vulkan_descriptors_bind (GskVulkanDescriptors *self,
|
||||
GskVulkanDescriptors *previous,
|
||||
VkCommandBuffer vk_command_buffer)
|
||||
{
|
||||
GskGpuDescriptors *desc = GSK_GPU_DESCRIPTORS (self);
|
||||
GskVulkanDescriptorsClass *class = GSK_VULKAN_DESCRIPTORS_CLASS (desc->desc_class);
|
||||
|
||||
return class->bind (self, previous, vk_command_buffer);
|
||||
}
|
||||
|
||||
GskVulkanDescriptors *
|
||||
gsk_vulkan_descriptors_new (GskVulkanDescriptorsClass *desc_class,
|
||||
gsize child_size)
|
||||
{
|
||||
GskGpuDescriptors *desc;
|
||||
|
||||
desc = gsk_gpu_descriptors_new ((GskGpuDescriptorsClass *)desc_class, child_size);
|
||||
|
||||
return GSK_VULKAN_DESCRIPTORS (desc);
|
||||
return GSK_VULKAN_DESCRIPTORS_GET_CLASS (self)->bind (self, previous, vk_command_buffer);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,14 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskVulkanDescriptors GskVulkanDescriptors;
|
||||
typedef struct _GskVulkanDescriptorsClass GskVulkanDescriptorsClass;
|
||||
#define GSK_TYPE_VULKAN_DESCRIPTORS (gsk_vulkan_descriptors_get_type ())
|
||||
#define GSK_VULKAN_DESCRIPTORS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSK_TYPE_VULKAN_DESCRIPTORS, GskVulkanDescriptors))
|
||||
#define GSK_VULKAN_DESCRIPTORS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GSK_TYPE_VULKAN_DESCRIPTORS, GskVulkanDescriptorsClass))
|
||||
#define GSK_IS_VULKAN_DESCRIPTORS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSK_TYPE_VULKAN_DESCRIPTORS))
|
||||
#define GSK_IS_VULKAN_DESCRIPTORS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSK_TYPE_VULKAN_DESCRIPTORS))
|
||||
#define GSK_VULKAN_DESCRIPTORS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSK_TYPE_VULKAN_DESCRIPTORS, GskVulkanDescriptorsClass))
|
||||
|
||||
#define GSK_VULKAN_DESCRIPTORS(d) ((GskVulkanDescriptors *) (d))
|
||||
#define GSK_VULKAN_DESCRIPTORS_CLASS(d) ((GskVulkanDescriptorsClass *) (d))
|
||||
typedef struct _GskVulkanDescriptorsClass GskVulkanDescriptorsClass;
|
||||
|
||||
struct _GskVulkanDescriptors
|
||||
{
|
||||
@@ -27,6 +30,8 @@ struct _GskVulkanDescriptorsClass
|
||||
VkCommandBuffer vk_command_buffer);
|
||||
};
|
||||
|
||||
GType gsk_vulkan_descriptors_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GskVulkanPipelineLayout * gsk_vulkan_descriptors_get_pipeline_layout (GskVulkanDescriptors *self);
|
||||
|
||||
void gsk_vulkan_descriptors_transition (GskVulkanDescriptors *self,
|
||||
@@ -36,9 +41,7 @@ void gsk_vulkan_descriptors_bind
|
||||
GskVulkanDescriptors *previous,
|
||||
VkCommandBuffer vk_command_buffer);
|
||||
|
||||
GskVulkanDescriptors * gsk_vulkan_descriptors_new (GskVulkanDescriptorsClass *desc_class,
|
||||
gsize child_size);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GskVulkanDescriptors, g_object_unref)
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -13,16 +13,10 @@
|
||||
#include "gdk/gdkdisplayprivate.h"
|
||||
#include "gdk/gdkdmabuftextureprivate.h"
|
||||
|
||||
static inline void
|
||||
gsk_vulkan_real_descriptors_unref (GskVulkanRealDescriptors *desc)
|
||||
{
|
||||
gsk_gpu_descriptors_unref (GSK_GPU_DESCRIPTORS (desc));
|
||||
}
|
||||
|
||||
#define GDK_ARRAY_NAME gsk_descriptors
|
||||
#define GDK_ARRAY_TYPE_NAME GskDescriptors
|
||||
#define GDK_ARRAY_ELEMENT_TYPE GskVulkanRealDescriptors *
|
||||
#define GDK_ARRAY_FREE_FUNC gsk_vulkan_real_descriptors_unref
|
||||
#define GDK_ARRAY_FREE_FUNC g_object_unref
|
||||
#define GDK_ARRAY_NO_MEMSET 1
|
||||
#include "gdk/gdkarrayimpl.c"
|
||||
|
||||
@@ -268,7 +262,7 @@ gsk_vulkan_frame_create_descriptors (GskGpuFrame *frame)
|
||||
desc = gsk_vulkan_real_descriptors_new (self);
|
||||
gsk_descriptors_append (&self->descriptors, desc);
|
||||
|
||||
return gsk_gpu_descriptors_ref (GSK_GPU_DESCRIPTORS (desc));
|
||||
return GSK_GPU_DESCRIPTORS (g_object_ref (desc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#include "gskvulkanrealdescriptorsprivate.h"
|
||||
|
||||
#include "gskvulkanbufferprivate.h"
|
||||
#include "gskvulkanframeprivate.h"
|
||||
#include "gskvulkanimageprivate.h"
|
||||
|
||||
#define GDK_ARRAY_NAME gsk_descriptor_image_infos
|
||||
#define GDK_ARRAY_TYPE_NAME GskDescriptorImageInfos
|
||||
#define GDK_ARRAY_ELEMENT_TYPE VkDescriptorImageInfo
|
||||
@@ -41,6 +45,8 @@ struct _GskVulkanRealDescriptors
|
||||
VkDescriptorSet descriptor_sets[GSK_VULKAN_N_DESCRIPTOR_SETS];
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GskVulkanRealDescriptors, gsk_vulkan_real_descriptors, GSK_TYPE_VULKAN_DESCRIPTORS)
|
||||
|
||||
static GskVulkanPipelineLayout *
|
||||
gsk_vulkan_real_descriptors_get_pipeline_layout (GskVulkanDescriptors *desc)
|
||||
{
|
||||
@@ -148,9 +154,9 @@ gsk_vulkan_real_descriptors_add_buffer (GskGpuDescriptors *desc,
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_real_descriptors_finalize (GskGpuDescriptors *desc)
|
||||
gsk_vulkan_real_descriptors_finalize (GObject *object)
|
||||
{
|
||||
GskVulkanRealDescriptors *self = GSK_VULKAN_REAL_DESCRIPTORS (desc);
|
||||
GskVulkanRealDescriptors *self = GSK_VULKAN_REAL_DESCRIPTORS (object);
|
||||
|
||||
gsk_samplers_clear (&self->immutable_samplers);
|
||||
gsk_descriptor_image_infos_clear (&self->descriptor_immutable_images);
|
||||
@@ -159,18 +165,25 @@ gsk_vulkan_real_descriptors_finalize (GskGpuDescriptors *desc)
|
||||
|
||||
gsk_vulkan_device_release_pipeline_layout (GSK_VULKAN_DEVICE (gsk_gpu_frame_get_device (GSK_GPU_FRAME (self->frame))),
|
||||
self->pipeline_layout);
|
||||
|
||||
G_OBJECT_CLASS (gsk_vulkan_real_descriptors_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static GskVulkanDescriptorsClass GSK_VULKAN_REAL_DESCRIPTORS_CLASS =
|
||||
static void
|
||||
gsk_vulkan_real_descriptors_class_init (GskVulkanRealDescriptorsClass *klass)
|
||||
{
|
||||
.parent_class = (GskGpuDescriptorsClass) {
|
||||
.finalize = gsk_vulkan_real_descriptors_finalize,
|
||||
.add_image = gsk_vulkan_real_descriptors_add_image,
|
||||
.add_buffer = gsk_vulkan_real_descriptors_add_buffer,
|
||||
},
|
||||
.get_pipeline_layout = gsk_vulkan_real_descriptors_get_pipeline_layout,
|
||||
.bind = gsk_vulkan_real_descriptors_bind
|
||||
};
|
||||
GskVulkanDescriptorsClass *vulkan_descriptors_class = GSK_VULKAN_DESCRIPTORS_CLASS (klass);
|
||||
GskGpuDescriptorsClass *descriptors_class = GSK_GPU_DESCRIPTORS_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = gsk_vulkan_real_descriptors_finalize;
|
||||
|
||||
descriptors_class->add_image = gsk_vulkan_real_descriptors_add_image;
|
||||
descriptors_class->add_buffer = gsk_vulkan_real_descriptors_add_buffer;
|
||||
|
||||
vulkan_descriptors_class->get_pipeline_layout = gsk_vulkan_real_descriptors_get_pipeline_layout;
|
||||
vulkan_descriptors_class->bind = gsk_vulkan_real_descriptors_bind;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_real_descriptors_init (GskVulkanRealDescriptors *self)
|
||||
@@ -185,14 +198,9 @@ GskVulkanRealDescriptors *
|
||||
gsk_vulkan_real_descriptors_new (GskVulkanFrame *frame)
|
||||
{
|
||||
GskVulkanRealDescriptors *self;
|
||||
GskVulkanDescriptors *desc;
|
||||
|
||||
desc = gsk_vulkan_descriptors_new (&GSK_VULKAN_REAL_DESCRIPTORS_CLASS,
|
||||
sizeof (GskVulkanRealDescriptors));
|
||||
self = g_object_new (GSK_TYPE_VULKAN_REAL_DESCRIPTORS, NULL);
|
||||
|
||||
self = GSK_VULKAN_REAL_DESCRIPTORS (desc);
|
||||
|
||||
gsk_vulkan_real_descriptors_init (self);
|
||||
self->frame = frame;
|
||||
|
||||
return self;
|
||||
|
||||
@@ -3,17 +3,11 @@
|
||||
#include "gskvulkandescriptorsprivate.h"
|
||||
#include "gskvulkanframeprivate.h"
|
||||
|
||||
#include "gskvulkanbufferprivate.h"
|
||||
#include "gskvulkanframeprivate.h"
|
||||
#include "gskvulkanimageprivate.h"
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskVulkanRealDescriptors GskVulkanRealDescriptors;
|
||||
|
||||
#define GSK_VULKAN_REAL_DESCRIPTORS(d) ((GskVulkanRealDescriptors *) (d))
|
||||
#define GSK_TYPE_VULKAN_REAL_DESCRIPTORS (gsk_vulkan_real_descriptors_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GskVulkanRealDescriptors, gsk_vulkan_real_descriptors, GSK, VULKAN_REAL_DESCRIPTORS, GskVulkanDescriptors)
|
||||
|
||||
GskVulkanRealDescriptors * gsk_vulkan_real_descriptors_new (GskVulkanFrame *frame);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "gskvulkansubdescriptorsprivate.h"
|
||||
|
||||
|
||||
struct _GskVulkanSubDescriptors
|
||||
{
|
||||
GskVulkanDescriptors parent_instance;
|
||||
@@ -10,31 +9,7 @@ struct _GskVulkanSubDescriptors
|
||||
GskVulkanDescriptors *parent;
|
||||
};
|
||||
|
||||
|
||||
static void gsk_vulkan_sub_descriptors_finalize (GskGpuDescriptors *desc);
|
||||
static gboolean gsk_vulkan_sub_descriptors_add_buffer (GskGpuDescriptors *desc,
|
||||
GskGpuBuffer *buffer,
|
||||
guint32 *out_descriptor);
|
||||
static gboolean gsk_vulkan_sub_descriptors_add_image (GskGpuDescriptors *desc,
|
||||
GskGpuImage *image,
|
||||
GskGpuSampler sampler,
|
||||
guint32 *out_descriptor);
|
||||
static GskVulkanPipelineLayout *
|
||||
gsk_vulkan_sub_descriptors_get_pipeline_layout (GskVulkanDescriptors *desc);
|
||||
static void gsk_vulkan_sub_descriptors_bind (GskVulkanDescriptors *desc,
|
||||
GskVulkanDescriptors *previous,
|
||||
VkCommandBuffer vk_command_buffer);
|
||||
|
||||
static GskVulkanDescriptorsClass GSK_VULKAN_SUB_DESCRIPTORS_CLASS =
|
||||
{
|
||||
.parent_class = (GskGpuDescriptorsClass) {
|
||||
.finalize = gsk_vulkan_sub_descriptors_finalize,
|
||||
.add_image = gsk_vulkan_sub_descriptors_add_image,
|
||||
.add_buffer = gsk_vulkan_sub_descriptors_add_buffer,
|
||||
},
|
||||
.get_pipeline_layout = gsk_vulkan_sub_descriptors_get_pipeline_layout,
|
||||
.bind = gsk_vulkan_sub_descriptors_bind,
|
||||
};
|
||||
G_DEFINE_TYPE (GskVulkanSubDescriptors, gsk_vulkan_sub_descriptors, GSK_TYPE_VULKAN_DESCRIPTORS)
|
||||
|
||||
static GskVulkanPipelineLayout *
|
||||
gsk_vulkan_sub_descriptors_get_pipeline_layout (GskVulkanDescriptors *desc)
|
||||
@@ -51,7 +26,7 @@ gsk_vulkan_sub_descriptors_bind (GskVulkanDescriptors *desc,
|
||||
{
|
||||
GskVulkanSubDescriptors *self = GSK_VULKAN_SUB_DESCRIPTORS (desc);
|
||||
|
||||
if (GSK_GPU_DESCRIPTORS (previous)->desc_class == (GskGpuDescriptorsClass *) &GSK_VULKAN_SUB_DESCRIPTORS_CLASS)
|
||||
if (GSK_IS_VULKAN_SUB_DESCRIPTORS (previous))
|
||||
previous = GSK_VULKAN_SUB_DESCRIPTORS (previous)->parent;
|
||||
|
||||
if (self->parent == previous)
|
||||
@@ -87,24 +62,45 @@ gsk_vulkan_sub_descriptors_add_buffer (GskGpuDescriptors *desc,
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_sub_descriptors_finalize (GskGpuDescriptors *desc)
|
||||
gsk_vulkan_sub_descriptors_finalize (GObject *object)
|
||||
{
|
||||
GskVulkanSubDescriptors *self = GSK_VULKAN_SUB_DESCRIPTORS (desc);
|
||||
GskVulkanSubDescriptors *self = GSK_VULKAN_SUB_DESCRIPTORS (object);
|
||||
|
||||
gsk_gpu_descriptors_unref (GSK_GPU_DESCRIPTORS (self->parent));
|
||||
g_object_unref (self->parent);
|
||||
|
||||
G_OBJECT_CLASS (gsk_vulkan_sub_descriptors_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_sub_descriptors_class_init (GskVulkanSubDescriptorsClass *klass)
|
||||
{
|
||||
GskVulkanDescriptorsClass *vulkan_descriptors_class = GSK_VULKAN_DESCRIPTORS_CLASS (klass);
|
||||
GskGpuDescriptorsClass *descriptors_class = GSK_GPU_DESCRIPTORS_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = gsk_vulkan_sub_descriptors_finalize;
|
||||
|
||||
descriptors_class->add_image = gsk_vulkan_sub_descriptors_add_image;
|
||||
descriptors_class->add_buffer = gsk_vulkan_sub_descriptors_add_buffer;
|
||||
|
||||
vulkan_descriptors_class->get_pipeline_layout = gsk_vulkan_sub_descriptors_get_pipeline_layout;
|
||||
vulkan_descriptors_class->bind = gsk_vulkan_sub_descriptors_bind;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_sub_descriptors_init (GskVulkanSubDescriptors *self)
|
||||
{
|
||||
}
|
||||
|
||||
GskVulkanSubDescriptors *
|
||||
gsk_vulkan_sub_descriptors_new (GskVulkanDescriptors *parent)
|
||||
{
|
||||
GskVulkanSubDescriptors *self;
|
||||
GskVulkanDescriptors *desc;
|
||||
|
||||
desc = gsk_vulkan_descriptors_new (&GSK_VULKAN_SUB_DESCRIPTORS_CLASS,
|
||||
sizeof (GskVulkanSubDescriptors));
|
||||
self = g_object_new (GSK_TYPE_VULKAN_SUB_DESCRIPTORS, NULL);
|
||||
|
||||
self = GSK_VULKAN_SUB_DESCRIPTORS (desc);
|
||||
self->parent = GSK_VULKAN_DESCRIPTORS (gsk_gpu_descriptors_ref (GSK_GPU_DESCRIPTORS (parent)));
|
||||
self->parent = g_object_ref (parent);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskVulkanSubDescriptors GskVulkanSubDescriptors;
|
||||
|
||||
#define GSK_VULKAN_SUB_DESCRIPTORS(d) ((GskVulkanSubDescriptors *) (d))
|
||||
#define GSK_TYPE_VULKAN_SUB_DESCRIPTORS (gsk_vulkan_sub_descriptors_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GskVulkanSubDescriptors, gsk_vulkan_sub_descriptors, GSK, VULKAN_SUB_DESCRIPTORS, GskVulkanDescriptors)
|
||||
|
||||
GskVulkanSubDescriptors * gsk_vulkan_sub_descriptors_new (GskVulkanDescriptors *parent);
|
||||
|
||||
|
||||
22
gsk/gsktypesprivate.h
Normal file
22
gsk/gsktypesprivate.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* GSK - The GTK Scene Kit
|
||||
* Copyright 2024 Red Hat, Inc.
|
||||
*
|
||||
* 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
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct _Scale Scale;
|
||||
typedef struct _Point Point;
|
||||
typedef struct _Box Box;
|
||||
268
gsk/pointprivate.h
Normal file
268
gsk/pointprivate.h
Normal file
@@ -0,0 +1,268 @@
|
||||
#pragma once
|
||||
|
||||
#include "gsktypesprivate.h"
|
||||
#include <graphene.h>
|
||||
#include <math.h>
|
||||
#include <smmintrin.h>
|
||||
|
||||
#include "scaleprivate.h"
|
||||
|
||||
#ifndef USE_SIMD
|
||||
|
||||
struct _Point
|
||||
{
|
||||
float x, y;
|
||||
};
|
||||
|
||||
static inline float
|
||||
point_x (const Point p)
|
||||
{
|
||||
return p.x;
|
||||
}
|
||||
|
||||
static inline float
|
||||
point_y (const Point p)
|
||||
{
|
||||
return p.y;
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point (float x,
|
||||
float y)
|
||||
{
|
||||
return (Point) { .x = x, .y = y };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_from_graphene (const graphene_point_t *p)
|
||||
{
|
||||
return point (p->x, p->y);
|
||||
}
|
||||
|
||||
static inline void
|
||||
point_to_graphene (const Point p,
|
||||
graphene_point_t *v)
|
||||
{
|
||||
v->x = p.x;
|
||||
v->y = p.y;
|
||||
}
|
||||
|
||||
static inline void
|
||||
point_to_float (const Point p,
|
||||
float v[2])
|
||||
{
|
||||
v[0] = p.x;
|
||||
v[1] = p.y;
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_zero (void)
|
||||
{
|
||||
return point (0, 0);
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_neg (const Point p)
|
||||
{
|
||||
return (Point) { .x = -p.x, .y = -p.y };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_mul (const Point p,
|
||||
const Scale s)
|
||||
{
|
||||
return (Point) { .x = p.x * s.x, .y = p.y * s.y };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_div (const Point p,
|
||||
const Scale s)
|
||||
{
|
||||
return (Point) { .x = p.x / s.x, .y = p.y / s.y };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_add (const Point p1,
|
||||
const Point p2)
|
||||
{
|
||||
return (Point) { .x = p1.x + p2.x, .y = p1.y + p2.y };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_sub (const Point p1,
|
||||
const Point p2)
|
||||
{
|
||||
return (Point) { .x = p1.x - p2.x, .y = p1.y - p2.y };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_floor (const Point p)
|
||||
{
|
||||
return (Point) { .x = floorf (p.x), .y = floorf (p.y) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_ceil (const Point p)
|
||||
{
|
||||
return (Point) { .x = ceilf (p.x), .y = ceilf (p.y) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_round (const Point p)
|
||||
{
|
||||
return (Point) { .x = roundf (p.x), .y = roundf (p.y) };
|
||||
}
|
||||
|
||||
#else /* USE_SIMD */
|
||||
|
||||
#include <smmintrin.h>
|
||||
|
||||
struct _Point
|
||||
{
|
||||
GRAPHENE_ALIGNED_DECL (graphene_simd4f_t v, 16);
|
||||
};
|
||||
|
||||
static inline float
|
||||
point_x (const Point p)
|
||||
{
|
||||
return graphene_simd4f_get_x (p.v);
|
||||
}
|
||||
|
||||
static inline float
|
||||
point_y (const Point p)
|
||||
{
|
||||
return graphene_simd4f_get_y (p.v);
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point (float x,
|
||||
float y)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_init (x, y, 0.f, 0.f) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_from_graphene (const graphene_point_t *p)
|
||||
{
|
||||
return point (p->x, p->y);
|
||||
}
|
||||
|
||||
static inline void
|
||||
point_to_graphene (const Point p,
|
||||
graphene_point_t *v)
|
||||
{
|
||||
v->x = p.x;
|
||||
v->y = p.y;
|
||||
}
|
||||
|
||||
static inline void
|
||||
point_to_float (const Point p,
|
||||
float v[2])
|
||||
{
|
||||
graphene_simd4f_dup_2f (p.v, v);
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_zero (void)
|
||||
{
|
||||
return point (0, 0);
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_neg (const Point p)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_neg (p.v) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_mul (const Point p,
|
||||
const Scale s)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_mul (p.v, s.v) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_div (const Point p,
|
||||
const Scale s)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_div (p.v, s.v) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_add (const Point p1,
|
||||
const Point p2)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_add (p1.v, p2.v) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_sub (const Point p1,
|
||||
const Point p2)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_sub (p1.v, p2.v) };
|
||||
}
|
||||
|
||||
#ifdef __SSE4_1__
|
||||
|
||||
#ifndef graphene_simd4f_floor
|
||||
# define graphene_simd4f_floor(v) \
|
||||
(__extension__ ({ \
|
||||
(graphene_simd4f_t) _mm_floor_ps ((v)); \
|
||||
}))
|
||||
#endif
|
||||
|
||||
#ifndef graphene_simd4f_ceil
|
||||
# define graphene_simd4f_ceil(v) \
|
||||
(__extension__ ({ \
|
||||
(graphene_simd4f_t) _mm_ceil_ps ((v)); \
|
||||
}))
|
||||
#endif
|
||||
|
||||
#ifndef graphene_simd4f_round
|
||||
# define graphene_simd4f_round(v) \
|
||||
(__extension__ ({ \
|
||||
(graphene_simd4f_t) _mm_round_ps ((v)); \
|
||||
}))
|
||||
#endif
|
||||
|
||||
static inline Point
|
||||
point_floor (const Point p)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_floor (p.v) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_ceil (const Point p)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_ceil (p.v) };
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_round (const Point p)
|
||||
{
|
||||
return (Point) { .v = graphene_simd4f_round (p.v) };
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline Point
|
||||
point_floor (const Point p)
|
||||
{
|
||||
return point (floorf (point_x (p)), floorf (point_y (p)));
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_ceil (const Point p)
|
||||
{
|
||||
return point (ceilf (point_x (p)), ceilf (point_y (p)));
|
||||
}
|
||||
|
||||
static inline Point
|
||||
point_round (const Point p)
|
||||
{
|
||||
return point (roundf (point_x (p)), roundf (point_y (p)));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
197
gsk/scaleprivate.h
Normal file
197
gsk/scaleprivate.h
Normal file
@@ -0,0 +1,197 @@
|
||||
#pragma once
|
||||
|
||||
#include "gsktypesprivate.h"
|
||||
#include <graphene.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifndef USE_SIMD
|
||||
|
||||
struct _Scale
|
||||
{
|
||||
float x, y;
|
||||
};
|
||||
|
||||
static inline float
|
||||
scale_x (const Scale s)
|
||||
{
|
||||
return s.x;
|
||||
}
|
||||
|
||||
static inline float
|
||||
scale_y (const Scale s)
|
||||
{
|
||||
return s.y;
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale (float x,
|
||||
float y)
|
||||
{
|
||||
return (Scale) { .x = x, .y = y };
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_from_float (float s)
|
||||
{
|
||||
return scale (s, s);
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_from_graphene (const graphene_vec2_t *v)
|
||||
{
|
||||
return (Scale) { .x = graphene_vec2_get_x (v), .y = graphene_vec2_get_y (v) };
|
||||
}
|
||||
|
||||
static inline void
|
||||
scale_to_graphene (const Scale s,
|
||||
graphene_vec2_t *v)
|
||||
{
|
||||
graphene_vec2_init (v, s.x, s.y);
|
||||
}
|
||||
|
||||
static inline void
|
||||
scale_to_float (const Scale s,
|
||||
float v[2])
|
||||
{
|
||||
v[0] = s.x;
|
||||
v[1] = s.y;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
scale_equal (const Scale s1,
|
||||
const Scale s2)
|
||||
{
|
||||
return (gboolean) (s1.x == s2.x && s1.y == s2.y);
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_one (void)
|
||||
{
|
||||
return scale (1, 1);
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_inv (const Scale s)
|
||||
{
|
||||
return (Scale) { .x = 1 / s.x, .y = 1 / s.y };
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_mul (const Scale s1,
|
||||
const Scale s2)
|
||||
{
|
||||
return (Scale) { .x = s1.x * s2.x, .y = s1.y * s2.y };
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_div (const Scale s1,
|
||||
const Scale s2)
|
||||
{
|
||||
return (Scale) { .x = s1.x / s2.x, .y = s1.y / s2.y };
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_max (const Scale s)
|
||||
{
|
||||
return (Scale) { .x = MAX (s.x, s.y), .y = MAX (s.x, s.y) };
|
||||
}
|
||||
|
||||
#else /* USE_SIMD */
|
||||
|
||||
struct _Scale
|
||||
{
|
||||
GRAPHENE_ALIGNED_DECL (graphene_simd4f_t v, 16);
|
||||
};
|
||||
|
||||
static inline float
|
||||
scale_x (const Scale s)
|
||||
{
|
||||
return graphene_simd4f_get_x (s.v);
|
||||
}
|
||||
|
||||
static inline float
|
||||
scale_y (const Scale s)
|
||||
{
|
||||
return graphene_simd4f_get_y (s.v);
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale (float x,
|
||||
float y)
|
||||
{
|
||||
return (Scale) { .v = graphene_simd4f_init (x, y, 0.f, 0.f) };
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_from_float (float s)
|
||||
{
|
||||
return scale (s, s);
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_from_graphene (const graphene_vec2_t *v)
|
||||
{
|
||||
return (Scale) { .v = v->__graphene_private_value };
|
||||
}
|
||||
|
||||
static inline void
|
||||
scale_to_graphene (const Scale s,
|
||||
graphene_vec2_t *v)
|
||||
{
|
||||
v->__graphene_private_value = s.v;
|
||||
}
|
||||
|
||||
static inline void
|
||||
scale_to_float (const Scale s,
|
||||
float v[2])
|
||||
{
|
||||
graphene_simd4f_dup_2f (s.v, v);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
scale_equal (const Scale s1,
|
||||
const Scale s2)
|
||||
{
|
||||
return (gboolean) graphene_simd4f_cmp_eq (s1.v, s2.v);
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_one (void)
|
||||
{
|
||||
return scale (1, 1);
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_inv (const Scale s)
|
||||
{
|
||||
return (Scale) { .v = graphene_simd4f_reciprocal (s.v) };
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_mul (const Scale s1,
|
||||
const Scale s2)
|
||||
{
|
||||
return (Scale) { .v = graphene_simd4f_mul (s1.v, s2.v) };
|
||||
}
|
||||
|
||||
static inline Scale
|
||||
scale_div (const Scale s1,
|
||||
const Scale s2)
|
||||
{
|
||||
return (Scale) { .v = graphene_simd4f_div (s1.v, s2.v) };
|
||||
}
|
||||
|
||||
#ifndef graphene_simd4f_shuffle_yxzw
|
||||
# define graphene_simd4f_shuffle_yxzw(v) \
|
||||
(__extension__ ({ \
|
||||
(graphene_simd4f_t) _mm_shuffle_ps ((v), (v), _MM_SHUFFLE (3, 2, 0, 1)); \
|
||||
}))
|
||||
#endif
|
||||
|
||||
static inline Scale
|
||||
scale_max (const Scale s)
|
||||
{
|
||||
return (Scale) { .v = graphene_simd4f_max (graphene_simd4f_shuffle_yxzw (s.v), s.v) };
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3639,19 +3639,6 @@ avahi_request_printer_list (GtkPrintBackendCups *cups_backend)
|
||||
g_bus_get (G_BUS_TYPE_SYSTEM, cups_backend->avahi_cancellable, avahi_create_browsers, cups_backend);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print backend can be disposed together with all its printers
|
||||
* as a reaction to user stopping enumeration of printers.
|
||||
*/
|
||||
static void
|
||||
backend_finalized_cb (gpointer data,
|
||||
GObject *where_the_object_was)
|
||||
{
|
||||
gboolean *backend_finalized = data;
|
||||
|
||||
*backend_finalized = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
|
||||
GtkCupsResult *result,
|
||||
@@ -3664,7 +3651,6 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
|
||||
GList *removed_printer_checklist;
|
||||
char *remote_default_printer = NULL;
|
||||
GList *iter;
|
||||
gboolean backend_finalized = FALSE;
|
||||
|
||||
list_has_changed = FALSE;
|
||||
|
||||
@@ -3697,8 +3683,6 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
|
||||
*/
|
||||
removed_printer_checklist = gtk_print_backend_get_printer_list (backend);
|
||||
|
||||
g_object_weak_ref (G_OBJECT (backend), backend_finalized_cb, &backend_finalized);
|
||||
|
||||
response = gtk_cups_result_get_response (result);
|
||||
for (attr = ippFirstAttribute (response); attr != NULL;
|
||||
attr = ippNextAttribute (response))
|
||||
@@ -3816,9 +3800,6 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
|
||||
{
|
||||
g_signal_emit_by_name (backend, "printer-added", printer);
|
||||
|
||||
if (backend_finalized)
|
||||
break;
|
||||
|
||||
gtk_printer_set_is_new (printer, FALSE);
|
||||
}
|
||||
|
||||
@@ -3856,44 +3837,36 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
|
||||
break;
|
||||
}
|
||||
|
||||
if (!backend_finalized)
|
||||
/* look at the removed printers checklist and mark any printer
|
||||
as inactive if it is in the list, emitting a printer_removed signal */
|
||||
if (removed_printer_checklist != NULL)
|
||||
{
|
||||
g_object_weak_unref (G_OBJECT (backend), backend_finalized_cb, &backend_finalized);
|
||||
|
||||
/* look at the removed printers checklist and mark any printer
|
||||
as inactive if it is in the list, emitting a printer_removed signal */
|
||||
if (removed_printer_checklist != NULL)
|
||||
for (iter = removed_printer_checklist; iter; iter = iter->next)
|
||||
{
|
||||
for (iter = removed_printer_checklist; iter; iter = iter->next)
|
||||
if (!GTK_PRINTER_CUPS (iter->data)->avahi_browsed)
|
||||
{
|
||||
if (!GTK_PRINTER_CUPS (iter->data)->avahi_browsed)
|
||||
{
|
||||
mark_printer_inactive (GTK_PRINTER (iter->data), backend);
|
||||
list_has_changed = TRUE;
|
||||
}
|
||||
mark_printer_inactive (GTK_PRINTER (iter->data), backend);
|
||||
list_has_changed = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free (removed_printer_checklist);
|
||||
g_list_free (removed_printer_checklist);
|
||||
}
|
||||
|
||||
done:
|
||||
if (!backend_finalized)
|
||||
if (list_has_changed)
|
||||
g_signal_emit_by_name (backend, "printer-list-changed");
|
||||
|
||||
gtk_print_backend_set_list_done (backend);
|
||||
|
||||
if (!cups_backend->got_default_printer && remote_default_printer != NULL)
|
||||
{
|
||||
if (list_has_changed)
|
||||
g_signal_emit_by_name (backend, "printer-list-changed");
|
||||
|
||||
gtk_print_backend_set_list_done (backend);
|
||||
|
||||
if (!cups_backend->got_default_printer && remote_default_printer != NULL)
|
||||
{
|
||||
set_default_printer (cups_backend, remote_default_printer);
|
||||
g_free (remote_default_printer);
|
||||
}
|
||||
|
||||
if (!cups_backend->got_default_printer && cups_backend->avahi_default_printer != NULL)
|
||||
set_default_printer (cups_backend, cups_backend->avahi_default_printer);
|
||||
set_default_printer (cups_backend, remote_default_printer);
|
||||
g_free (remote_default_printer);
|
||||
}
|
||||
|
||||
if (!cups_backend->got_default_printer && cups_backend->avahi_default_printer != NULL)
|
||||
set_default_printer (cups_backend, cups_backend->avahi_default_printer);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user