Skip to content
Snippets Groups Projects

Pippin/media framework

Merged pippin requested to merge pippin/media_framework into main
2 unresolved threads
2 files
+ 66
41
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 65
40
/* ctx git commit: aeaa8b2b */
/* ctx git commit: 2f95901e */
/*
* ctx.h is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -868,7 +868,9 @@ Ctx * ctx_new_for_cairo (cairo_t *cr);
char *ctx_render_string (Ctx *ctx, int longform, int *retlen);
void ctx_render_stream (Ctx *ctx, FILE *stream, int formatter);
void ctx_render_stream (Ctx *ctx, FILE *stream, int longform);
void ctx_render_fd (Ctx *ctx, int fd, int longform);
void ctx_render_ctx (Ctx *ctx, Ctx *d_ctx);
void ctx_render_ctx_textures (Ctx *ctx, Ctx *d_ctx); /* cycles through all
@@ -5786,6 +5788,9 @@ static inline CtxList *ctx_list_find_custom (CtxList *list,
#define CTX_STROKE_1PX 0
#endif
#ifndef CTX_PICO
#define CTX_PICO 0
#endif
/* Copyright (C) 2020 Øyvind Kolås <pippin@gimp.org>
*/
@@ -37243,7 +37248,7 @@ void _ctx_mouse (Ctx *term, int mode)
#if !__COSMOPOLITAN__
#if CTX_PTY==0
#if CTX_PICO
#include "pico/stdlib.h"
#include "hardware/timer.h"
static uint64_t pico_get_time(void) {
@@ -37263,7 +37268,7 @@ _ctx_init_ticks (void)
if (done)
return;
done = 1;
#if CTX_PTY==0
#if CTX_PICO
start_time = pico_get_time();
#else
gettimeofday (&start_time, NULL);
@@ -37273,7 +37278,7 @@ _ctx_init_ticks (void)
static inline unsigned long
_ctx_ticks (void)
{
#if CTX_PTY==0
#if CTX_PICO
uint64_t measure_time = pico_get_time();
return measure_time - start_time;
#else
@@ -45461,7 +45466,6 @@ ctx_new_for_cairo (cairo_t *cr)
#endif
#if CTX_TERMINAL_EVENTS
int ctx_frame_ack = -1;
#if CTX_FORMATTER
@@ -45839,10 +45843,13 @@ static void ctx_ctx_end_frame (Ctx *ctx)
fprintf (stdout, "\033[5n");
fflush (stdout);
#if CTX_EVENTS
ctx_frame_ack = 0;
do {
ctx_consume_events (ctxctx->backend.ctx);
} while (ctx_frame_ack != 1);
#endif
#else
fflush (stdout);
#endif
@@ -45850,7 +45857,9 @@ static void ctx_ctx_end_frame (Ctx *ctx)
void ctx_ctx_destroy (CtxCtx *ctx)
{
#if CTX_TERMINAL_EVENTS
nc_at_exit ();
#endif
ctx_free (ctx);
/* we're not destoring the ctx member, this is function is called in ctx' teardown */
}
@@ -45865,7 +45874,7 @@ void ctx_ctx_consume_events (Ctx *ctx)
#endif
assert (ctx_native_events);
#if 1
#if CTX_TERMINAL_EVENTS
{ /* XXX : this is a work-around for signals not working properly, we are polling the
size with an ioctl per consume-events
*/
@@ -45990,7 +45999,6 @@ Ctx *ctx_new_ctx (int width, int height)
void ctx_ctx_pcm (Ctx *ctx);
#endif
#endif
#if CTX_TILED
@@ -50050,26 +50058,25 @@ ctx_cb_end_frame (Ctx *ctx)
if (cb_backend->flags & CTX_FLAG_SHOW_FPS)
{
float em = ctx_height (ctx) * 0.08f;
float y = em;
ctx_font_size (ctx, em);
ctx_rectangle (ctx, ctx_width(ctx)-(em*4), 0, em *4, em * 1.1f);
ctx_rgba (ctx, 0, 0, 0, 0.7f);
ctx_fill (ctx);
ctx_rgba (ctx, 1, 1, 0, 1);
if (prev_time)
{
char buf[22];
float fps = 1.0f/((cur_time-prev_time)/1000.0f);
ctx_move_to (ctx, width - (em * 3.8f), y);
sprintf (buf, "%2.1f fps", (double)fps);
ctx_text (ctx, buf);
ctx_begin_path (ctx);
}
prev_time = cur_time;
float em = ctx_height (ctx) * 0.08f;
float y = em;
ctx_font_size (ctx, em);
ctx_rectangle (ctx, ctx_width(ctx)-(em*4), 0, em *4, em * 1.1f);
ctx_rgba (ctx, 0, 0, 0, 0.7f);
ctx_fill (ctx);
ctx_rgba (ctx, 1, 1, 0, 1);
if (prev_time)
{
char buf[22];
float fps = 1.0f/((cur_time-prev_time)/1000.0f);
ctx_move_to (ctx, width - (em * 3.8f), y);
sprintf (buf, "%2.1f fps", (double)fps);
ctx_text (ctx, buf);
ctx_begin_path (ctx);
}
prev_time = cur_time;
}
@@ -52128,6 +52135,17 @@ static void _ctx_stream_addstr (CtxFormatter *formatter, const char *str, int le
fwrite (str, len, 1, (FILE*)formatter->target);
}
static void _ctx_fd_addstr (CtxFormatter *formatter, const char *str, int len)
{
if (!str || len == 0)
{
return;
}
if (len < 0) len = ctx_strlen (str);
write ((size_t)formatter->target, str, len);
}
void _ctx_string_addstr (CtxFormatter *formatter, const char *str, int len)
{
if (!str || len == 0)
@@ -52954,6 +52972,23 @@ ctx_render_stream (Ctx *ctx, FILE *stream, int longform)
fwrite ("\n", 1, 1, stream);
}
void
ctx_render_fd (Ctx *ctx, int fd, int longform)
{
CtxIterator iterator;
CtxFormatter formatter;
formatter.target = (void*)((size_t)fd);
formatter.longform = longform;
formatter.indent = 0;
formatter.add_str = _ctx_fd_addstr;
CtxCommand *command;
ctx_iterator_init (&iterator, &ctx->drawlist, 0,
CTX_ITERATOR_EXPAND_BITPACK);
while ( (command = ctx_iterator_next (&iterator) ) )
{ ctx_formatter_process (&formatter, command); }
write (fd, "\n", 1);
}
char *
ctx_render_string (Ctx *ctx, int longform, int *retlen)
{
@@ -53344,7 +53379,6 @@ void ctx_texture (Ctx *ctx, const char *eid, float x, float y)
{
int eid_len = ctx_strlen (eid);
char ascii[41]="";
//fprintf (stderr, "tx %s\n", eid);
if (eid_len > 50)
{
CtxSHA1 *sha1 = ctx_sha1_new ();
@@ -53362,17 +53396,8 @@ void ctx_texture (Ctx *ctx, const char *eid, float x, float y)
eid=ascii;
}
//FILE *f = fopen ("/tmp/l", "a");
if (ctx_eid_valid (ctx, eid, 0, 0))
{
ctx_process_cmd_str_float (ctx, CTX_TEXTURE, eid, x, y);
//fprintf (stderr, "setting texture eid %s\n", eid);
}
else
{
//fprintf (stderr, "tried setting invalid texture eid %s\n", eid);
}
//fclose (f);
}
int
ctx_textureclock (Ctx *ctx)
@@ -55072,14 +55097,14 @@ ctx_new_drawlist (int width, int height)
static Ctx *ctx_new_ui (int width, int height, const char *backend);
#endif
#if CTX_PTY==0
#if CTX_PICO
Ctx *ctx_pico_init (void);
#endif
CTX_EXPORT Ctx *
ctx_new (int width, int height, const char *backend)
{
#if CTX_PTY==0
#if CTX_PICO
return ctx_pico_init ();
#endif
Loading