Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scenic loop #54

Merged
merged 10 commits into from
Oct 21, 2023
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ NVG_COMMON_SRCS = \
c_src/device/nvg/nanovg/nanovg.c \
c_src/device/nvg/nvg_font_ops.c \
c_src/device/nvg/nvg_image_ops.c \
c_src/device/nvg/nvg_scenic.c \
c_src/device/nvg/nvg_script_ops.c

CAIRO_COMMON_SRCS = \
Expand Down
6 changes: 6 additions & 0 deletions c_src/device/cairo/cairo_fb.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "comms.h"
#include "device.h"
#include "fontstash.h"
#include "scenic_ops.h"

const char* device = "/dev/fb0";

Expand Down Expand Up @@ -328,3 +329,8 @@ void device_end_render(driver_data_t* p_data)
render_cairo_surface_to_fb(p_ctx);
}

void device_loop(driver_data_t* p_data)
{
scenic_loop(p_data);
}

23 changes: 11 additions & 12 deletions c_src/device/cairo/cairo_gtk.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <cairo.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
Expand All @@ -14,6 +13,7 @@
#include "comms.h"
#include "device.h"
#include "fontstash.h"
#include "scenic_ops.h"
#include "script_ops.h"

typedef struct {
Expand All @@ -29,14 +29,6 @@ cairo_gtk_t g_cairo_gtk;
extern device_info_t g_device_info;
extern device_opts_t g_opts;

static gpointer cairo_gtk_main(gpointer user_data)
{
gtk_widget_show_all((GtkWidget*)g_cairo_gtk.window);
gtk_main();

return NULL;
}

static gboolean on_draw(GtkWidget* widget,
cairo_t* cr,
gpointer data)
Expand Down Expand Up @@ -155,8 +147,6 @@ int device_init(const device_opts_t* p_opts,
gtk_container_add(GTK_CONTAINER(g_cairo_gtk.window), (GtkWidget*)drawing_area);
g_signal_connect((GtkWidget*)drawing_area, "draw", G_CALLBACK(on_draw), p_ctx);

g_cairo_gtk.main = g_thread_new("gtk_main", cairo_gtk_main, NULL);

return 0;
}

Expand All @@ -168,8 +158,9 @@ int device_close(device_info_t* p_info)

scenic_cairo_ctx_t* p_ctx = (scenic_cairo_ctx_t*)p_info->v_ctx;
gtk_main_quit();
g_thread_join(g_cairo_gtk.main);
scenic_cairo_fini(p_ctx);

return 0;
}

void device_poll()
Expand Down Expand Up @@ -211,3 +202,11 @@ void device_end_render(driver_data_t* p_data)

g_idle_add((GSourceFunc)gtk_widget_queue_draw, (void*)g_cairo_gtk.window);
}

void device_loop(driver_data_t* p_data)
{
g_cairo_gtk.main = g_thread_new("scenic_loop", scenic_loop, p_data);

gtk_widget_show_all((GtkWidget*)g_cairo_gtk.window);
gtk_main();
}
7 changes: 4 additions & 3 deletions c_src/device/cairo/cairo_script_ops.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cairo.h>
#define _GNU_SOURCE
#include <math.h>

#include "cairo_ctx.h"
Expand Down Expand Up @@ -258,7 +259,7 @@ void script_ops_draw_text(void* v_ctx,
cairo_text_extents_t text_extents;
cairo_scaled_font_glyph_extents(scaled_font, glyphs, glyph_count, &text_extents);

float align_offset;
float align_offset = 0;
switch (p_ctx->text_align) {
case TEXT_ALIGN_LEFT:
align_offset = 0;
Expand All @@ -271,7 +272,7 @@ void script_ops_draw_text(void* v_ctx,
break;
}

float base_offset;
float base_offset = 0;
switch (p_ctx->text_base) {
case TEXT_BASE_TOP:
base_offset = font_extents.ascent;
Expand Down Expand Up @@ -345,7 +346,7 @@ void script_ops_draw_sprites(void* v_ctx,

image_pattern_data_t* image_data = find_image_pattern(p_ctx, p_image->image_id);

for (int i = 0; i < count; i++) {
for (uint32_t i = 0; i < count; i++) {
draw_sprite(p_ctx, image_data->surface, sprites[i]);
}
}
Expand Down
1 change: 1 addition & 0 deletions c_src/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ int device_init(const device_opts_t* p_opts,
driver_data_t* p_data);
int device_close(device_info_t* p_info);
void device_poll();
void device_loop(driver_data_t* p_data);
void device_begin_render(driver_data_t* p_data);
void device_begin_cursor_render(driver_data_t* p_data);
void device_end_render(driver_data_t* p_data);
Expand Down
7 changes: 7 additions & 0 deletions c_src/device/nvg/nvg_scenic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "device.h"
#include "scenic_ops.h"

void device_loop(driver_data_t* p_data)
{
scenic_loop(p_data);
}
2 changes: 1 addition & 1 deletion c_src/font/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ font_t* get_font(sid_t id)
}

//---------------------------------------------------------
void put_font(int* p_msg_length, void* v_ctx)
void put_font(uint32_t* p_msg_length, void* v_ctx)
{
// read in the id size, which is in the first four bytes
uint32_t id_length;
Expand Down
2 changes: 1 addition & 1 deletion c_src/font/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#include "font_ops.h"

void init_fonts(void);
void put_font(int* p_msg_length, void* v_ctx);
void put_font(uint32_t* p_msg_length, void* v_ctx);
font_t* get_font(sid_t id);

8 changes: 5 additions & 3 deletions c_src/image/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include "common.h"
#include "comms.h"
#include "image.h"
#include "image_ops.h"
#include "scenic_types.h"
#include "utils.h"
#include "image_ops.h"

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
Expand Down Expand Up @@ -80,7 +80,7 @@ void reset_images(void* v_ctx)
int read_pixels(void* p_pixels,
uint32_t width, uint32_t height,
image_format_t format_in,
int* p_msg_length)
uint32_t* p_msg_length)
{
// read incoming data into a temporary buffer
int buffer_size = *p_msg_length;
Expand Down Expand Up @@ -145,6 +145,8 @@ int read_pixels(void* p_pixels,
case IMAGE_FORMAT_RGBA:
memcpy(p_pixels, p_buffer, pixel_count * 4);
break;
default:
break;
}

// clean up
Expand All @@ -154,7 +156,7 @@ int read_pixels(void* p_pixels,
}

//---------------------------------------------------------
void put_image(int* p_msg_length, void* v_ctx)
void put_image(uint32_t* p_msg_length, void* v_ctx)
{
// read in the fixed size data
uint32_t id_length;
Expand Down
3 changes: 1 addition & 2 deletions c_src/image/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ typedef enum {
IMAGE_FORMAT_GRAY_ALPHA = 2,
IMAGE_FORMAT_RGB = 3,
IMAGE_FORMAT_RGBA = 4,
IMAGE_FORMAT_SIZE = 0xffffffff, // ensure enum is 32 bits wide
} image_format_t;

void init_images(void);
void put_image(int* p_msg_length, void* v_ctx);
void put_image(uint32_t* p_msg_length, void* v_ctx);
void reset_images(void* v_ctx);
image_t* get_image(sid_t id);
17 changes: 1 addition & 16 deletions c_src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,8 @@ int main(int argc, char **argv)
data.debug_mode = g_opts.debug_mode;
data.v_ctx = g_device_info.v_ctx;

// signal the app that the window is ready
send_ready();
device_loop(&data);

#ifdef SCENIC_GLES2
log_info("~~~~~~~~~~~~~SCENIC_GLES2 was defined!");
#endif

/* Loop until the calling app closes the window */
while (data.keep_going && !isCallerDown()) {
// check for incoming messages - blocks with a timeout
handle_stdio_in(&data);
device_poll();
}

reset_images(data.v_ctx);

device_close(&g_device_info);
return 0;
}

Loading