font: require compositor reference
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 22 Jan 2012 12:51:23 +0000 (13:51 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 22 Jan 2012 12:51:23 +0000 (13:51 +0100)
To avoid cairo dependencies we now take a compositor reference in the
font backend so fonts can be drawn with GL textures instead of cairo.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/font.h
src/font_freetype.c
src/font_pango.c
tests/test_console.c
tests/test_terminal.c

index 1486922..8d1ee55 100644 (file)
 #define KMSCON_FONT_H
 
 #include <stdlib.h>
+#include "output.h"
 #include "unicode.h"
 
 struct kmscon_font_factory;
 struct kmscon_font;
 
 int kmscon_font_factory_new(struct kmscon_font_factory **out,
-                                       struct kmscon_symbol_table *st);
+       struct kmscon_symbol_table *st, struct kmscon_compositor *comp);
 void kmscon_font_factory_ref(struct kmscon_font_factory *ff);
 void kmscon_font_factory_unref(struct kmscon_font_factory *ff);
 
index f619872..ccb59e5 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "font.h"
 #include "log.h"
+#include "output.h"
 #include "unicode.h"
 
 #include <ft2build.h>
@@ -46,6 +47,8 @@ struct kmscon_font_factory {
        unsigned long ref;
        struct kmscon_symbol_table *st;
        FT_Library lib;
+       struct kmscon_compositor *comp;
+       struct kmscon_context *ctx;
 };
 
 struct kmscon_font {
@@ -62,13 +65,13 @@ struct kmscon_glyph {
 };
 
 int kmscon_font_factory_new(struct kmscon_font_factory **out,
-                                       struct kmscon_symbol_table *st)
+       struct kmscon_symbol_table *st, struct kmscon_compositor *comp)
 {
        struct kmscon_font_factory *ff;
        FT_Error err;
        int ret;
 
-       if (!out)
+       if (!out || !st || !comp)
                return -EINVAL;
 
        ff = malloc(sizeof(*ff));
@@ -78,6 +81,8 @@ int kmscon_font_factory_new(struct kmscon_font_factory **out,
        memset(ff, 0, sizeof(*ff));
        ff->ref = 1;
        ff->st = st;
+       ff->comp = comp;
+       ff->ctx = kmscon_compositor_get_context(comp);
 
        err = FT_Init_FreeType(&ff->lib);
        if (err) {
@@ -86,6 +91,7 @@ int kmscon_font_factory_new(struct kmscon_font_factory **out,
                goto err_free;
        }
 
+       kmscon_compositor_ref(ff->comp);
        kmscon_symbol_table_ref(ff->st);
        *out = ff;
 
@@ -118,6 +124,7 @@ void kmscon_font_factory_unref(struct kmscon_font_factory *ff)
        if (err)
                log_warning("font: cannot deinitialize FreeType library\n");
 
+       kmscon_compositor_unref(ff->comp);
        kmscon_symbol_table_unref(ff->st);
        free(ff);
 }
index 8fd12fe..22c58ee 100644 (file)
@@ -41,6 +41,7 @@
 #include <pango/pangocairo.h>
 #include "font.h"
 #include "log.h"
+#include "output.h"
 #include "unicode.h"
 
 enum glyph_type {
@@ -71,6 +72,8 @@ struct kmscon_glyph {
 struct kmscon_font_factory {
        unsigned long ref;
        struct kmscon_symbol_table *st;
+       struct kmscon_compositor *comp;
+       struct kmscon_context *ctx;
 };
 
 struct kmscon_font {
@@ -228,11 +231,11 @@ static int kmscon_glyph_set(struct kmscon_glyph *glyph,
 }
 
 int kmscon_font_factory_new(struct kmscon_font_factory **out,
-                                       struct kmscon_symbol_table *st)
+       struct kmscon_symbol_table *st, struct kmscon_compositor *comp)
 {
        struct kmscon_font_factory *ff;
 
-       if (!out)
+       if (!out || !st || !comp)
                return -EINVAL;
 
        ff = malloc(sizeof(*ff));
@@ -242,7 +245,10 @@ int kmscon_font_factory_new(struct kmscon_font_factory **out,
        memset(ff, 0, sizeof(*ff));
        ff->ref = 1;
        ff->st = st;
+       ff->comp = comp;
+       ff->ctx = kmscon_compositor_get_context(comp);
 
+       kmscon_compositor_ref(ff->comp);
        kmscon_symbol_table_ref(ff->st);
        *out = ff;
 
@@ -265,6 +271,7 @@ void kmscon_font_factory_unref(struct kmscon_font_factory *ff)
        if (--ff->ref)
                return;
 
+       kmscon_compositor_unref(ff->comp);
        kmscon_symbol_table_unref(ff->st);
        free(ff);
 }
index d243644..536a50b 100644 (file)
@@ -274,15 +274,15 @@ static int setup_eloop(struct console *con)
        if (ret)
                goto err_loop;
 
-       ret = kmscon_font_factory_new(&con->ff, con->st);
+       ret = kmscon_compositor_new(&con->comp);
        if (ret)
                goto err_loop;
 
-       ret = kmscon_compositor_new(&con->comp);
+       ret = kmscon_compositor_use(con->comp);
        if (ret)
                goto err_loop;
 
-       ret = kmscon_compositor_use(con->comp);
+       ret = kmscon_font_factory_new(&con->ff, con->st, con->comp);
        if (ret)
                goto err_loop;
 
index 969f1ec..ae4cc39 100644 (file)
@@ -158,15 +158,15 @@ static int setup_app(struct app *app)
        if (ret)
                goto err_loop;
 
-       ret = kmscon_font_factory_new(&app->ff, app->st);
+       ret = kmscon_compositor_new(&app->comp);
        if (ret)
                goto err_loop;
 
-       ret = kmscon_compositor_new(&app->comp);
+       ret = kmscon_compositor_use(app->comp);
        if (ret)
                goto err_loop;
 
-       ret = kmscon_compositor_use(app->comp);
+       ret = kmscon_font_factory_new(&app->ff, app->st, app->comp);
        if (ret)
                goto err_loop;