summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-12-04 07:45:41 +0100
committerKim Woelders <kim@woelders.dk>2021-12-08 19:12:29 +0100
commit8370777a31258854b97c7ef8212f90f0c82587e6 (patch)
tree3b3ae7a58c037b7a56a96c2a80a8ed4288d47cc7 /src/lib
parent01d76b56a0aecb292a52bff19104d4a89532eea5 (diff)
downloadimlib2-8370777a31258854b97c7ef8212f90f0c82587e6.tar.gz
Make initial context static
Avoids having to check on every API function call.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/api.c77
1 files changed, 30 insertions, 47 deletions
diff --git a/src/lib/api.c b/src/lib/api.c
index 6485c1e..7c343cf 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -61,10 +61,7 @@ typedef void (*Imlib_Internal_Progress_Function)(void *, char, int, int,
int, int);
typedef void (*Imlib_Internal_Data_Destructor_Function)(void *, void *);
-struct _imlibcontext;
-typedef struct _imlibcontext ImlibContext;
-
-struct _imlibcontext {
+typedef struct {
#ifdef BUILD_X11
Display *display;
Visual *visual;
@@ -96,20 +93,42 @@ struct _imlibcontext {
int references;
char dirty;
-};
+} ImlibContext;
-struct _imlibcontextitem;
typedef struct _imlibcontextitem ImlibContextItem;
struct _imlibcontextitem {
ImlibContext *context;
ImlibContextItem *below;
};
-/* a stack of contexts -- only used by context-handling functions. */
-static ImlibContextItem *contexts = NULL; /* (ImlibContext*) imlib_context_new(); */
+#define DefaultContext { \
+ .anti_alias = 1, \
+ .dither = 0, \
+ .blend = 1, \
+ .operation = (ImlibOp) IMLIB_OP_COPY, \
+ .direction = IMLIB_TEXT_TO_RIGHT, \
+ .angle = 0.0, \
+ .color.alpha = 255, \
+ .color.red = 255, \
+ .color.green = 255, \
+ .color.blue = 255, \
+ .pixel = 0xffffffff, \
+ .mask_alpha_threshold = 128, \
+ .encoding = IMLIB_TTF_ENCODING_ISO_8859_1, \
+}
+
+/* A default context, only used for initialization */
+static const ImlibContext ctx_default = DefaultContext;
-/* this is the context all functions use rely on */
-static ImlibContext *ctx = NULL; /* contexts->context; */
+/* The initial context */
+static ImlibContext ctx0 = DefaultContext;
+
+/* Current context */
+static ImlibContext *ctx = &ctx0;
+
+/* a stack of contexts -- only used by context-handling functions. */
+static ImlibContextItem contexts0 = {.context = &ctx0 };
+static ImlibContextItem *contexts = &contexts0;
/* frees the given context including all its members */
static void
@@ -156,43 +175,7 @@ imlib_context_new(void)
{
ImlibContext *context = malloc(sizeof(ImlibContext));
-#ifdef BUILD_X11
- context->display = NULL;
- context->visual = NULL;
- context->colormap = 0;
- context->depth = 0;
- context->drawable = 0;
- context->mask = 0;
-#endif
- context->anti_alias = 1;
- context->dither = 0;
- context->blend = 1;
- context->color_modifier = NULL;
- context->operation = (ImlibOp) IMLIB_OP_COPY;
- context->font = NULL;
- context->direction = IMLIB_TEXT_TO_RIGHT;
- context->angle = 0.0;
- context->color.alpha = 255;
- context->color.red = 255;
- context->color.green = 255;
- context->color.blue = 255;
- context->pixel = 0xffffffff;
- context->color_range = NULL;
- context->image = NULL;
- context->image_data_memory_func = NULL;
- context->progress_func = NULL;
- context->progress_granularity = 0;
- context->dither_mask = 0;
- context->mask_alpha_threshold = 128;
- context->filter = NULL;
- context->cliprect.x = 0;
- context->cliprect.y = 0;
- context->cliprect.w = 0;
- context->cliprect.h = 0;
- context->encoding = IMLIB_TTF_ENCODING_ISO_8859_1;
-
- context->references = 0;
- context->dirty = 0;
+ *context = ctx_default;
return (Imlib_Context) context;
}