2016-11-29 15:33:14 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkanrendererprivate.h"
|
|
|
|
|
|
|
|
#include "gskdebugprivate.h"
|
2016-12-05 01:50:06 +00:00
|
|
|
#include "gskprivate.h"
|
2016-11-29 15:33:14 +00:00
|
|
|
#include "gskrendererprivate.h"
|
|
|
|
#include "gskrendernodeprivate.h"
|
|
|
|
#include "gsktextureprivate.h"
|
2016-12-05 01:50:06 +00:00
|
|
|
#include "gskvulkanbufferprivate.h"
|
2016-12-06 13:42:46 +00:00
|
|
|
#include "gskvulkanimageprivate.h"
|
2016-12-05 01:50:06 +00:00
|
|
|
#include "gskvulkanpipelineprivate.h"
|
2016-12-07 13:50:52 +00:00
|
|
|
#include "gskvulkanrenderprivate.h"
|
2016-11-29 15:33:14 +00:00
|
|
|
|
2016-12-07 00:48:31 +00:00
|
|
|
#include <graphene.h>
|
|
|
|
|
2016-12-09 06:23:04 +00:00
|
|
|
typedef struct _GskVulkanTextureData GskVulkanTextureData;
|
|
|
|
|
|
|
|
struct _GskVulkanTextureData {
|
|
|
|
GskTexture *texture;
|
|
|
|
GskVulkanImage *image;
|
|
|
|
GskVulkanRenderer *renderer;
|
|
|
|
};
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
typedef struct {
|
|
|
|
GQuark cpu_time;
|
|
|
|
GQuark gpu_time;
|
|
|
|
} ProfileTimers;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct _GskVulkanRenderer
|
|
|
|
{
|
|
|
|
GskRenderer parent_instance;
|
|
|
|
|
|
|
|
GdkVulkanContext *vulkan;
|
2016-11-30 01:08:17 +00:00
|
|
|
|
|
|
|
guint n_targets;
|
2016-12-08 21:35:16 +00:00
|
|
|
GskVulkanImage **targets;
|
2016-11-30 02:59:28 +00:00
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
VkSampler sampler;
|
|
|
|
|
2016-12-09 05:13:14 +00:00
|
|
|
GskVulkanRender *render;
|
2016-12-08 17:40:35 +00:00
|
|
|
|
2016-12-09 06:23:04 +00:00
|
|
|
GSList *textures;
|
|
|
|
|
2017-09-01 20:58:42 +00:00
|
|
|
GHashTable *glyph_cache;
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
ProfileTimers profile_timers;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GskVulkanRendererClass
|
|
|
|
{
|
|
|
|
GskRendererClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GskVulkanRenderer, gsk_vulkan_renderer, GSK_TYPE_RENDERER)
|
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_free_targets (GskVulkanRenderer *self)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < self->n_targets; i++)
|
|
|
|
{
|
2016-12-08 21:35:16 +00:00
|
|
|
g_object_unref (self->targets[i]);
|
2016-11-30 01:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_clear_pointer (&self->targets, g_free);
|
|
|
|
self->n_targets = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_update_images_cb (GdkVulkanContext *context,
|
|
|
|
GskVulkanRenderer *self)
|
|
|
|
{
|
2016-12-08 20:14:41 +00:00
|
|
|
GdkWindow *window;
|
|
|
|
gint scale_factor;
|
|
|
|
gsize width, height;
|
2016-11-30 01:08:17 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
gsk_vulkan_renderer_free_targets (self);
|
|
|
|
|
|
|
|
self->n_targets = gdk_vulkan_context_get_n_images (context);
|
2016-12-08 21:35:16 +00:00
|
|
|
self->targets = g_new (GskVulkanImage *, self->n_targets);
|
2016-11-30 01:08:17 +00:00
|
|
|
|
2016-12-08 20:14:41 +00:00
|
|
|
window = gsk_renderer_get_window (GSK_RENDERER (self));
|
|
|
|
scale_factor = gdk_window_get_scale_factor (window);
|
|
|
|
width = gdk_window_get_width (window) * scale_factor;
|
|
|
|
height = gdk_window_get_height (window) * scale_factor;
|
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
for (i = 0; i < self->n_targets; i++)
|
|
|
|
{
|
2016-12-08 21:35:16 +00:00
|
|
|
self->targets[i] = gsk_vulkan_image_new_for_swapchain (self->vulkan,
|
|
|
|
gdk_vulkan_context_get_image (context, i),
|
|
|
|
gdk_vulkan_context_get_image_format (self->vulkan),
|
|
|
|
width, height);
|
2016-11-30 01:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
static gboolean
|
|
|
|
gsk_vulkan_renderer_realize (GskRenderer *renderer,
|
2016-11-30 01:08:17 +00:00
|
|
|
GdkWindow *window,
|
|
|
|
GError **error)
|
2016-11-29 15:33:14 +00:00
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
2016-11-30 02:59:28 +00:00
|
|
|
VkDevice device;
|
2016-11-29 15:33:14 +00:00
|
|
|
|
|
|
|
self->vulkan = gdk_window_create_vulkan_context (window, error);
|
|
|
|
if (self->vulkan == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-11-30 02:59:28 +00:00
|
|
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
GSK_VK_CHECK (vkCreateSampler, device,
|
|
|
|
&(VkSamplerCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
|
|
|
.magFilter = VK_FILTER_LINEAR,
|
|
|
|
.minFilter = VK_FILTER_LINEAR,
|
|
|
|
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
|
|
|
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
|
|
|
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT,
|
|
|
|
.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
|
|
|
|
.unnormalizedCoordinates = VK_FALSE
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->sampler);
|
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
g_signal_connect (self->vulkan,
|
|
|
|
"images-updated",
|
|
|
|
G_CALLBACK (gsk_vulkan_renderer_update_images_cb),
|
|
|
|
self);
|
|
|
|
gsk_vulkan_renderer_update_images_cb (self->vulkan, self);
|
|
|
|
|
2016-12-09 05:13:14 +00:00
|
|
|
self->render = gsk_vulkan_render_new (renderer, self->vulkan);
|
2016-12-08 17:40:35 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_unrealize (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
2016-11-30 02:59:28 +00:00
|
|
|
VkDevice device;
|
2016-12-09 06:23:04 +00:00
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = self->textures; l; l = l->next)
|
|
|
|
{
|
|
|
|
GskVulkanTextureData *data = l->data;
|
|
|
|
|
|
|
|
data->renderer = NULL;
|
|
|
|
gsk_texture_clear_render_data (data->texture);
|
|
|
|
}
|
|
|
|
g_clear_pointer (&self->textures, (GDestroyNotify) g_slist_free);
|
2016-11-30 02:59:28 +00:00
|
|
|
|
2016-12-09 05:13:14 +00:00
|
|
|
g_clear_pointer (&self->render, gsk_vulkan_render_free);
|
2016-12-08 17:40:35 +00:00
|
|
|
|
2016-11-30 02:59:28 +00:00
|
|
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
2016-11-29 15:33:14 +00:00
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
gsk_vulkan_renderer_free_targets (self);
|
|
|
|
g_signal_handlers_disconnect_by_func(self->vulkan,
|
|
|
|
gsk_vulkan_renderer_update_images_cb,
|
|
|
|
self);
|
2016-11-30 02:59:28 +00:00
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
vkDestroySampler (device,
|
|
|
|
self->sampler,
|
|
|
|
NULL);
|
|
|
|
self->sampler = VK_NULL_HANDLE;
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
g_clear_object (&self->vulkan);
|
|
|
|
}
|
|
|
|
|
2016-12-22 18:01:07 +00:00
|
|
|
static GskTexture *
|
|
|
|
gsk_vulkan_renderer_render_texture (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const graphene_rect_t *viewport)
|
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
|
|
|
GskVulkanRender *render;
|
|
|
|
GskVulkanImage *image;
|
|
|
|
GskTexture *texture;
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler;
|
|
|
|
gint64 cpu_time;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
profiler = gsk_renderer_get_profiler (renderer);
|
|
|
|
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
render = gsk_vulkan_render_new (renderer, self->vulkan);
|
|
|
|
|
|
|
|
image = gsk_vulkan_image_new_for_framebuffer (self->vulkan,
|
|
|
|
ceil (viewport->size.width),
|
|
|
|
ceil (viewport->size.height));
|
|
|
|
|
|
|
|
gsk_vulkan_render_reset (render, image, viewport);
|
|
|
|
|
|
|
|
gsk_vulkan_render_add_node (render, root);
|
|
|
|
|
|
|
|
gsk_vulkan_render_upload (render);
|
|
|
|
|
|
|
|
gsk_vulkan_render_draw (render, self->sampler);
|
|
|
|
|
|
|
|
texture = gsk_vulkan_render_download_target (render);
|
|
|
|
|
|
|
|
g_object_unref (image);
|
|
|
|
gsk_vulkan_render_free (render);
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
|
|
|
|
gsk_profiler_timer_set (profiler, self->profile_timers.cpu_time, cpu_time);
|
|
|
|
|
|
|
|
gsk_profiler_push_samples (profiler);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_render (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root)
|
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
2016-12-08 16:46:08 +00:00
|
|
|
GskVulkanRender *render;
|
2016-11-29 15:33:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler;
|
|
|
|
gint64 cpu_time;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
profiler = gsk_renderer_get_profiler (renderer);
|
|
|
|
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
|
|
|
|
#endif
|
|
|
|
|
2016-12-09 05:13:14 +00:00
|
|
|
render = self->render;
|
2016-12-08 17:40:35 +00:00
|
|
|
|
2016-12-22 18:01:07 +00:00
|
|
|
gsk_vulkan_render_reset (render, self->targets[gdk_vulkan_context_get_draw_index (self->vulkan)], NULL);
|
2016-12-07 13:50:52 +00:00
|
|
|
|
2016-12-08 16:46:08 +00:00
|
|
|
gsk_vulkan_render_add_node (render, root);
|
2016-12-07 13:50:52 +00:00
|
|
|
|
2016-12-08 16:46:08 +00:00
|
|
|
gsk_vulkan_render_upload (render);
|
2016-12-07 13:50:52 +00:00
|
|
|
|
2016-12-08 23:06:59 +00:00
|
|
|
gsk_vulkan_render_draw (render, self->sampler);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
|
|
|
|
gsk_profiler_timer_set (profiler, self->profile_timers.cpu_time, cpu_time);
|
|
|
|
|
|
|
|
gsk_profiler_push_samples (profiler);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-12-01 03:07:20 +00:00
|
|
|
static GdkDrawingContext *
|
|
|
|
gsk_vulkan_renderer_begin_draw_frame (GskRenderer *renderer,
|
|
|
|
const cairo_region_t *region)
|
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
|
|
|
GdkDrawingContext *result;
|
|
|
|
|
2016-12-26 23:18:52 +00:00
|
|
|
result = gdk_window_begin_draw_frame (gsk_renderer_get_window (renderer),
|
2016-12-01 03:07:20 +00:00
|
|
|
GDK_DRAW_CONTEXT (self->vulkan),
|
2016-12-26 23:18:52 +00:00
|
|
|
region);
|
2016-12-01 03:07:20 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_class_init (GskVulkanRendererClass *klass)
|
|
|
|
{
|
|
|
|
GskRendererClass *renderer_class = GSK_RENDERER_CLASS (klass);
|
|
|
|
|
|
|
|
renderer_class->realize = gsk_vulkan_renderer_realize;
|
|
|
|
renderer_class->unrealize = gsk_vulkan_renderer_unrealize;
|
|
|
|
renderer_class->render = gsk_vulkan_renderer_render;
|
2016-12-22 18:01:07 +00:00
|
|
|
renderer_class->render_texture = gsk_vulkan_renderer_render_texture;
|
2016-12-01 03:07:20 +00:00
|
|
|
renderer_class->begin_draw_frame = gsk_vulkan_renderer_begin_draw_frame;
|
2016-11-29 15:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_init (GskVulkanRenderer *self)
|
|
|
|
{
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler = gsk_renderer_get_profiler (GSK_RENDERER (self));
|
2016-12-05 01:50:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
gsk_ensure_resources ();
|
2016-11-29 15:33:14 +00:00
|
|
|
|
2016-12-05 01:50:06 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2016-11-29 15:33:14 +00:00
|
|
|
self->profile_timers.cpu_time = gsk_profiler_add_timer (profiler, "cpu-time", "CPU time", FALSE, TRUE);
|
|
|
|
#endif
|
|
|
|
}
|
2016-12-09 06:23:04 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_clear_texture (gpointer p)
|
|
|
|
{
|
|
|
|
GskVulkanTextureData *data = p;
|
|
|
|
|
|
|
|
if (data->renderer != NULL)
|
|
|
|
data->renderer->textures = g_slist_remove (data->renderer->textures, data);
|
|
|
|
|
|
|
|
g_object_unref (data->image);
|
|
|
|
|
|
|
|
g_slice_free (GskVulkanTextureData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
GskVulkanImage *
|
2016-12-17 03:22:44 +00:00
|
|
|
gsk_vulkan_renderer_ref_texture_image (GskVulkanRenderer *self,
|
|
|
|
GskTexture *texture,
|
|
|
|
GskVulkanUploader *uploader)
|
2016-12-09 06:23:04 +00:00
|
|
|
{
|
|
|
|
GskVulkanTextureData *data;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
GskVulkanImage *image;
|
|
|
|
|
|
|
|
data = gsk_texture_get_render_data (texture, self);
|
|
|
|
if (data)
|
|
|
|
return g_object_ref (data->image);
|
|
|
|
|
2016-12-21 19:28:21 +00:00
|
|
|
surface = gsk_texture_download_surface (texture);
|
2016-12-17 03:22:44 +00:00
|
|
|
image = gsk_vulkan_image_new_from_data (uploader,
|
2016-12-09 06:23:04 +00:00
|
|
|
cairo_image_surface_get_data (surface),
|
|
|
|
cairo_image_surface_get_width (surface),
|
|
|
|
cairo_image_surface_get_height (surface),
|
|
|
|
cairo_image_surface_get_stride (surface));
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
data = g_slice_new0 (GskVulkanTextureData);
|
|
|
|
data->image = image;
|
|
|
|
data->texture = texture;
|
|
|
|
data->renderer = self;
|
|
|
|
|
|
|
|
if (gsk_texture_set_render_data (texture, self, data, gsk_vulkan_renderer_clear_texture))
|
|
|
|
{
|
|
|
|
g_object_ref (data->image);
|
|
|
|
self->textures = g_slist_prepend (self->textures, data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_slice_free (GskVulkanTextureData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
2017-09-01 20:58:42 +00:00
|
|
|
|
|
|
|
#ifndef STACK_BUFFER_SIZE
|
|
|
|
#define STACK_BUFFER_SIZE (512 * sizeof (int))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STACK_ARRAY_LENGTH(T) (STACK_BUFFER_SIZE / sizeof(T))
|
|
|
|
|
|
|
|
static void
|
|
|
|
render_text (cairo_t *cr,
|
|
|
|
PangoFont *font,
|
|
|
|
PangoGlyphString *glyphs,
|
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float width,
|
|
|
|
float height)
|
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
int x_position = 0;
|
|
|
|
cairo_scaled_font_t *scaled_font;
|
|
|
|
cairo_glyph_t *cairo_glyphs;
|
|
|
|
cairo_glyph_t stack_glyphs[STACK_ARRAY_LENGTH (cairo_glyph_t)];
|
|
|
|
|
|
|
|
scaled_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *)font);
|
|
|
|
if (G_UNLIKELY (!scaled_font || cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cairo_set_scaled_font (cr, scaled_font);
|
|
|
|
cairo_set_source_rgba (cr, 0, 0, 0, 1);
|
|
|
|
|
|
|
|
if (glyphs->num_glyphs > (int) G_N_ELEMENTS (stack_glyphs))
|
|
|
|
cairo_glyphs = g_new (cairo_glyph_t, glyphs->num_glyphs);
|
|
|
|
else
|
|
|
|
cairo_glyphs = stack_glyphs;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < glyphs->num_glyphs; i++)
|
|
|
|
{
|
|
|
|
PangoGlyphInfo *gi = &glyphs->glyphs[i];
|
|
|
|
|
|
|
|
if (gi->glyph != PANGO_GLYPH_EMPTY)
|
|
|
|
{
|
|
|
|
double cx = x + (double)(x_position + gi->geometry.x_offset) / PANGO_SCALE;
|
|
|
|
double cy = y + (double)(gi->geometry.y_offset) / PANGO_SCALE;
|
|
|
|
|
|
|
|
if (!(gi->glyph & PANGO_GLYPH_UNKNOWN_FLAG))
|
|
|
|
{
|
|
|
|
cairo_glyphs[count].index = gi->glyph;
|
|
|
|
cairo_glyphs[count].x = cx;
|
|
|
|
cairo_glyphs[count].y = cy;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x_position += gi->geometry.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_show_glyphs (cr, cairo_glyphs, count);
|
|
|
|
|
|
|
|
if (cairo_glyphs != stack_glyphs)
|
|
|
|
g_free (cairo_glyphs);
|
|
|
|
}
|
|
|
|
|
|
|
|
GskVulkanImage *
|
|
|
|
gsk_vulkan_renderer_ref_glyph_image (GskVulkanRenderer *self,
|
|
|
|
GskVulkanUploader *uploader,
|
|
|
|
PangoFont *font,
|
|
|
|
PangoGlyphString *glyphs)
|
|
|
|
{
|
|
|
|
PangoRectangle ink_rect;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
GskVulkanImage *image;
|
|
|
|
|
|
|
|
pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
|
|
|
|
pango_extents_to_pixels (&ink_rect, NULL);
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
|
|
ink_rect.x + ink_rect.width,
|
|
|
|
ink_rect.height);
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
render_text (cr, font, glyphs, 0, - ink_rect.y, ink_rect.x + ink_rect.width, ink_rect.height);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
image = gsk_vulkan_image_new_from_data (uploader,
|
|
|
|
cairo_image_surface_get_data (surface),
|
|
|
|
cairo_image_surface_get_width (surface),
|
|
|
|
cairo_image_surface_get_height (surface),
|
|
|
|
cairo_image_surface_get_stride (surface));
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
place_text (PangoFont *font,
|
|
|
|
PangoGlyphString *glyphs,
|
|
|
|
GskGlyphCoords *coords,
|
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float width,
|
|
|
|
float height)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int x_position = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < glyphs->num_glyphs; i++)
|
|
|
|
{
|
|
|
|
PangoGlyphInfo *gi = &glyphs->glyphs[i];
|
|
|
|
|
|
|
|
if (gi->glyph != PANGO_GLYPH_EMPTY)
|
|
|
|
{
|
|
|
|
double cx = x + (double)(x_position + gi->geometry.x_offset) / PANGO_SCALE;
|
|
|
|
|
|
|
|
if (!(gi->glyph & PANGO_GLYPH_UNKNOWN_FLAG))
|
|
|
|
{
|
|
|
|
coords[i].glyph = gi->glyph;
|
|
|
|
coords[i].x = cx / width;
|
|
|
|
coords[i].y = 0.0;
|
|
|
|
coords[i].width = (float)gi->geometry.width / (PANGO_SCALE * width);
|
|
|
|
coords[i].height = 1.0; // FIXME get actual glyph height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x_position += gi->geometry.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_vulkan_renderer_get_glyph_coords (GskVulkanRenderer *self,
|
|
|
|
PangoFont *font,
|
|
|
|
PangoGlyphString *glyphs,
|
|
|
|
GskGlyphCoords *coords)
|
|
|
|
{
|
|
|
|
PangoRectangle ink_rect;
|
|
|
|
|
|
|
|
pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
|
|
|
|
pango_extents_to_pixels (&ink_rect, NULL);
|
|
|
|
|
|
|
|
place_text (font, glyphs, coords, 0, - ink_rect.y, ink_rect.x + ink_rect.width, ink_rect.height);
|
|
|
|
}
|