font: require compositor reference

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>
This commit is contained in:
David Herrmann 2012-01-22 13:51:23 +01:00
parent 0f6c75637f
commit e5f5c2729a
5 changed files with 28 additions and 13 deletions

View File

@ -35,13 +35,14 @@
#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);

View 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);
}

View 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);
}

View File

@ -274,10 +274,6 @@ static int setup_eloop(struct console *con)
if (ret)
goto err_loop;
ret = kmscon_font_factory_new(&con->ff, con->st);
if (ret)
goto err_loop;
ret = kmscon_compositor_new(&con->comp);
if (ret)
goto err_loop;
@ -286,6 +282,10 @@ static int setup_eloop(struct console *con)
if (ret)
goto err_loop;
ret = kmscon_font_factory_new(&con->ff, con->st, con->comp);
if (ret)
goto err_loop;
ret = kmscon_vt_new(&con->vt, vt_switch, con);
if (ret)
goto err_loop;

View File

@ -158,10 +158,6 @@ static int setup_app(struct app *app)
if (ret)
goto err_loop;
ret = kmscon_font_factory_new(&app->ff, app->st);
if (ret)
goto err_loop;
ret = kmscon_compositor_new(&app->comp);
if (ret)
goto err_loop;
@ -170,6 +166,10 @@ static int setup_app(struct app *app)
if (ret)
goto err_loop;
ret = kmscon_font_factory_new(&app->ff, app->st, app->comp);
if (ret)
goto err_loop;
ret = kmscon_input_new(&app->input);
if (ret)
goto err_loop;