2016-03-17 13:48:19 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskcairorendererprivate.h"
|
|
|
|
|
|
|
|
#include "gskdebugprivate.h"
|
|
|
|
#include "gskrendererprivate.h"
|
|
|
|
#include "gskrendernodeprivate.h"
|
2017-11-02 20:39:00 +00:00
|
|
|
#include "gdk/gdktextureprivate.h"
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-20 04:28:52 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
typedef struct {
|
|
|
|
GQuark cpu_time;
|
|
|
|
GQuark gpu_time;
|
|
|
|
} ProfileTimers;
|
|
|
|
#endif
|
|
|
|
|
2016-03-17 13:48:19 +00:00
|
|
|
struct _GskCairoRenderer
|
|
|
|
{
|
|
|
|
GskRenderer parent_instance;
|
|
|
|
|
2016-11-20 04:28:52 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
ProfileTimers profile_timers;
|
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GskCairoRendererClass
|
|
|
|
{
|
|
|
|
GskRendererClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GskCairoRenderer, gsk_cairo_renderer, GSK_TYPE_RENDERER)
|
|
|
|
|
|
|
|
static gboolean
|
2016-11-29 03:51:07 +00:00
|
|
|
gsk_cairo_renderer_realize (GskRenderer *renderer,
|
2018-03-21 10:49:14 +00:00
|
|
|
GdkSurface *surface,
|
2016-11-29 03:51:07 +00:00
|
|
|
GError **error)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_cairo_renderer_unrealize (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-12-21 19:23:46 +00:00
|
|
|
gsk_cairo_renderer_do_render (GskRenderer *renderer,
|
|
|
|
cairo_t *cr,
|
|
|
|
GskRenderNode *root)
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
2016-11-20 04:28:52 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2016-12-21 19:23:46 +00:00
|
|
|
GskCairoRenderer *self = GSK_CAIRO_RENDERER (renderer);
|
2016-11-20 04:28:52 +00:00
|
|
|
GskProfiler *profiler;
|
|
|
|
gint64 cpu_time;
|
|
|
|
#endif
|
|
|
|
|
2016-12-21 19:23:46 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
profiler = gsk_renderer_get_profiler (renderer);
|
|
|
|
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gsk_render_node_draw (root, cr);
|
|
|
|
|
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
static GdkTexture *
|
2016-12-21 19:23:46 +00:00
|
|
|
gsk_cairo_renderer_render_texture (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const graphene_rect_t *viewport)
|
|
|
|
{
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture;
|
2016-12-21 19:23:46 +00:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, ceil (viewport->size.width), ceil (viewport->size.height));
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
|
|
|
cairo_translate (cr, - viewport->origin.x, - viewport->origin.y);
|
|
|
|
|
|
|
|
gsk_cairo_renderer_do_render (renderer, cr, root);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
texture = gdk_texture_new_for_surface (surface);
|
2016-12-21 19:23:46 +00:00
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_cairo_renderer_render (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root)
|
|
|
|
{
|
|
|
|
GdkDrawingContext *context = gsk_renderer_get_drawing_context (renderer);
|
2018-03-21 10:49:14 +00:00
|
|
|
GdkSurface *surface = gsk_renderer_get_surface (renderer);
|
2016-12-21 19:23:46 +00:00
|
|
|
|
2016-08-25 10:29:00 +00:00
|
|
|
cairo_t *cr;
|
|
|
|
|
2016-12-13 04:07:43 +00:00
|
|
|
cr = gdk_drawing_context_get_cairo_context (context);
|
2016-08-25 10:31:56 +00:00
|
|
|
|
2016-12-13 04:07:43 +00:00
|
|
|
g_return_if_fail (cr != NULL);
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2018-01-14 20:11:33 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (renderer, GEOMETRY))
|
2016-03-17 13:48:19 +00:00
|
|
|
{
|
|
|
|
cairo_save (cr);
|
|
|
|
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_rectangle (cr,
|
2017-11-04 19:05:56 +00:00
|
|
|
0, 0,
|
2018-03-21 10:49:14 +00:00
|
|
|
gdk_surface_get_width (surface), gdk_surface_get_height (surface));
|
2016-03-17 13:48:19 +00:00
|
|
|
cairo_set_source_rgba (cr, 0, 0, 0.85, 0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
2018-01-14 20:11:33 +00:00
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-12-21 19:23:46 +00:00
|
|
|
gsk_cairo_renderer_do_render (renderer, cr, root);
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_cairo_renderer_class_init (GskCairoRendererClass *klass)
|
|
|
|
{
|
|
|
|
GskRendererClass *renderer_class = GSK_RENDERER_CLASS (klass);
|
|
|
|
|
|
|
|
renderer_class->realize = gsk_cairo_renderer_realize;
|
|
|
|
renderer_class->unrealize = gsk_cairo_renderer_unrealize;
|
|
|
|
renderer_class->render = gsk_cairo_renderer_render;
|
2016-12-21 19:23:46 +00:00
|
|
|
renderer_class->render_texture = gsk_cairo_renderer_render_texture;
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_cairo_renderer_init (GskCairoRenderer *self)
|
|
|
|
{
|
2016-11-20 04:28:52 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler = gsk_renderer_get_profiler (GSK_RENDERER (self));
|
2016-03-17 13:48:19 +00:00
|
|
|
|
2016-11-20 04:28:52 +00:00
|
|
|
self->profile_timers.cpu_time = gsk_profiler_add_timer (profiler, "cpu-time", "CPU time", FALSE, TRUE);
|
|
|
|
#endif
|
2016-03-17 13:48:19 +00:00
|
|
|
}
|