Commit 23845a57 authored by Alexander Larsson's avatar Alexander Larsson

broadway: Add GskBroadwayRenderer

This is a custom renderer for broadway windows, although at the
moment it doesn't really do anything other than the old cairo
fallbacks.
parent 9fef90b0
#include "config.h"
#include "gskbroadwayrendererprivate.h"
#include "broadway/gdkprivate-broadway.h"
#include "gskdebugprivate.h"
#include "gskrendererprivate.h"
#include "gskrendernodeprivate.h"
#include "gdk/gdktextureprivate.h"
struct _GskBroadwayRenderer
{
GskRenderer parent_instance;
};
struct _GskBroadwayRendererClass
{
GskRendererClass parent_class;
};
G_DEFINE_TYPE (GskBroadwayRenderer, gsk_broadway_renderer, GSK_TYPE_RENDERER)
static gboolean
gsk_broadway_renderer_realize (GskRenderer *renderer,
GdkWindow *window,
GError **error)
{
return TRUE;
}
static void
gsk_broadway_renderer_unrealize (GskRenderer *renderer)
{
}
static GdkTexture *
gsk_broadway_renderer_render_texture (GskRenderer *renderer,
GskRenderNode *root,
const graphene_rect_t *viewport)
{
GdkTexture *texture;
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_render_node_draw (root, cr);
cairo_destroy (cr);
texture = gdk_texture_new_for_surface (surface);
cairo_surface_destroy (surface);
return texture;
}
static void
gsk_broadway_renderer_render (GskRenderer *renderer,
GskRenderNode *root)
{
GdkDrawingContext *context = gsk_renderer_get_drawing_context (renderer);
graphene_rect_t viewport;
cairo_t *cr;
cr = gdk_drawing_context_get_cairo_context (context);
g_return_if_fail (cr != NULL);
gsk_renderer_get_viewport (renderer, &viewport);
if (GSK_RENDER_MODE_CHECK (GEOMETRY))
{
cairo_save (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_rectangle (cr,
viewport.origin.x,
viewport.origin.y,
viewport.size.width,
viewport.size.height);
cairo_set_source_rgba (cr, 0, 0, 0.85, 0.5);
cairo_stroke (cr);
cairo_restore (cr);
}
gsk_render_node_draw (root, cr);
}
static void
gsk_broadway_renderer_class_init (GskBroadwayRendererClass *klass)
{
GskRendererClass *renderer_class = GSK_RENDERER_CLASS (klass);
renderer_class->realize = gsk_broadway_renderer_realize;
renderer_class->unrealize = gsk_broadway_renderer_unrealize;
renderer_class->render = gsk_broadway_renderer_render;
renderer_class->render_texture = gsk_broadway_renderer_render_texture;
}
static void
gsk_broadway_renderer_init (GskBroadwayRenderer *self)
{
}
#ifndef __GSK_BROADWAY_RENDERER_PRIVATE_H__
#define __GSK_BROADWAY_RENDERER_PRIVATE_H__
#include "broadway/gdkbroadway.h"
#include <gsk/gskrenderer.h>
G_BEGIN_DECLS
#define GSK_TYPE_BROADWAY_RENDERER (gsk_broadway_renderer_get_type ())
#define GSK_BROADWAY_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GSK_TYPE_BROADWAY_RENDERER, GskBroadwayRenderer))
#define GSK_IS_BROADWAY_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GSK_TYPE_BROADWAY_RENDERER))
#define GSK_BROADWAY_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GSK_TYPE_BROADWAY_RENDERER, GskBroadwayRendererClass))
#define GSK_IS_BROADWAY_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GSK_TYPE_BROADWAY_RENDERER))
#define GSK_BROADWAY_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GSK_TYPE_BROADWAY_RENDERER, GskBroadwayRendererClass))
typedef struct _GskBroadwayRenderer GskBroadwayRenderer;
typedef struct _GskBroadwayRendererClass GskBroadwayRendererClass;
GType gsk_broadway_renderer_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* __GSK_BROADWAY_RENDERER_PRIVATE_H__ */
......@@ -55,6 +55,9 @@
#ifdef GDK_WINDOWING_WAYLAND
#include <gdk/wayland/gdkwayland.h>
#endif
#ifdef GDK_WINDOWING_BROADWAY
#include "gskbroadwayrendererprivate.h"
#endif
#ifdef GDK_RENDERING_VULKAN
#include "gskvulkanrendererprivate.h"
#endif
......@@ -752,6 +755,10 @@ get_renderer_for_backend (GdkWindow *window)
if (GDK_IS_WAYLAND_WINDOW (window))
return GSK_TYPE_GL_RENDERER;
#endif
#ifdef GDK_WINDOWING_BROADWAY
if (GDK_IS_BROADWAY_WINDOW (window))
return GSK_TYPE_BROADWAY_RENDERER;
#endif
return G_TYPE_INVALID;
}
......
......@@ -80,6 +80,12 @@ if have_vulkan
subdir('resources/vulkan')
endif # have_vulkan
if get_variable('broadway_enabled')
gsk_private_sources += files([
'gskbroadwayrenderer.c',
])
endif
gsk_resources_xml = configure_file(output: 'gsk.resources.xml',
input: 'gen-gsk-gresources-xml.py',
command: [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment