Call fb_draw() only from separate thread, add MR_CONTINUOUS_FB_UPDATE
This commit is contained in:
		@@ -154,6 +154,10 @@ ifeq ($(MR_USE_QCOM_OVERLAY),true)
 | 
			
		||||
    LOCAL_SRC_FILES += framebuffer_qcom_overlay.c
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
ifeq ($(MR_CONTINUOUS_FB_UPDATE),true)
 | 
			
		||||
    LOCAL_CFLAGS += -DMR_CONTINUOUS_FB_UPDATE
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
include $(BUILD_EXECUTABLE)
 | 
			
		||||
 | 
			
		||||
# Trampoline
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								button.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								button.c
									
									
									
									
									
								
							@@ -95,7 +95,7 @@ void button_set_hover(button *b, int hover)
 | 
			
		||||
    if(b->text)
 | 
			
		||||
    {
 | 
			
		||||
        button_update_colors(b);
 | 
			
		||||
        fb_draw();
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -181,7 +181,7 @@ void button_set_checked(button *b, int checked)
 | 
			
		||||
        b->flags &= ~(BTN_CHECKED);
 | 
			
		||||
 | 
			
		||||
    button_update_colors(b);
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int button_keyaction_call(void *data, int act)
 | 
			
		||||
 
 | 
			
		||||
@@ -123,7 +123,7 @@ int checkbox_touch_handler(touch_event *ev, void *data)
 | 
			
		||||
 | 
			
		||||
        box->touch_id = ev->id;
 | 
			
		||||
        box->hover = fb_add_rect(box->x-TOUCH, box->y-TOUCH, CHECKBOX_SIZE+TOUCH*2, CHECKBOX_SIZE+TOUCH*2, CLR_SECONDARY);
 | 
			
		||||
        fb_draw();
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(box->touch_id != ev->id)
 | 
			
		||||
@@ -141,7 +141,7 @@ int checkbox_touch_handler(touch_event *ev, void *data)
 | 
			
		||||
        box->hover = NULL;
 | 
			
		||||
        box->touch_id = -1;
 | 
			
		||||
 | 
			
		||||
        fb_draw();
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,7 @@
 | 
			
		||||
#include <linux/kd.h>
 | 
			
		||||
#include <cutils/memory.h>
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
#include <sys/atomics.h>
 | 
			
		||||
 | 
			
		||||
#include "log.h"
 | 
			
		||||
#include "framebuffer.h"
 | 
			
		||||
@@ -56,7 +57,6 @@ static fb_items_t fb_items = { NULL, NULL, NULL };
 | 
			
		||||
static fb_items_t **inactive_ctx = NULL;
 | 
			
		||||
static uint8_t **fb_rot_helpers = NULL;
 | 
			
		||||
static pthread_mutex_t fb_mutex = PTHREAD_MUTEX_INITIALIZER;
 | 
			
		||||
static pthread_mutex_t fb_draw_req_mutex = PTHREAD_MUTEX_INITIALIZER;
 | 
			
		||||
static pthread_t fb_draw_thread;
 | 
			
		||||
static volatile int fb_draw_requested = 0;
 | 
			
		||||
static volatile int fb_draw_run = 0;
 | 
			
		||||
@@ -743,11 +743,8 @@ void fb_draw_overlay(void)
 | 
			
		||||
#endif // MR_DISABLE_ALPHA
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void fb_draw(void)
 | 
			
		||||
static void fb_draw(void)
 | 
			
		||||
{
 | 
			
		||||
    if(fb_frozen)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    uint32_t i;
 | 
			
		||||
    pthread_mutex_lock(&fb_mutex);
 | 
			
		||||
 | 
			
		||||
@@ -834,14 +831,12 @@ void fb_pop_context(void)
 | 
			
		||||
 | 
			
		||||
    list_rm_noreorder(ctx, &inactive_ctx, &free);
 | 
			
		||||
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define SLEEP_CONST 16
 | 
			
		||||
void *fb_draw_thread_work(void *cookie)
 | 
			
		||||
{
 | 
			
		||||
    volatile int req = 0;
 | 
			
		||||
 | 
			
		||||
    struct timespec last, curr;
 | 
			
		||||
    uint32_t diff = 0, prevSleepTime = 0;
 | 
			
		||||
    clock_gettime(CLOCK_MONOTONIC, &last);
 | 
			
		||||
@@ -851,13 +846,18 @@ void *fb_draw_thread_work(void *cookie)
 | 
			
		||||
        clock_gettime(CLOCK_MONOTONIC, &curr);
 | 
			
		||||
        diff = timespec_diff(&last, &curr);
 | 
			
		||||
 | 
			
		||||
        pthread_mutex_lock(&fb_draw_req_mutex);
 | 
			
		||||
        req = fb_draw_requested;
 | 
			
		||||
        fb_draw_requested = 0;
 | 
			
		||||
        pthread_mutex_unlock(&fb_draw_req_mutex);
 | 
			
		||||
 | 
			
		||||
        if(req)
 | 
			
		||||
        if(__atomic_cmpxchg(1, 0, &fb_draw_requested) == 0)
 | 
			
		||||
        {
 | 
			
		||||
            fb_draw();
 | 
			
		||||
        }
 | 
			
		||||
#ifdef MR_CONTINUOUS_FB_UPDATE
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            pthread_mutex_lock(&fb_mutex);
 | 
			
		||||
            fb_update();
 | 
			
		||||
            pthread_mutex_unlock(&fb_mutex);
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        last = curr;
 | 
			
		||||
        if(diff <= SLEEP_CONST+prevSleepTime)
 | 
			
		||||
@@ -873,7 +873,6 @@ void *fb_draw_thread_work(void *cookie)
 | 
			
		||||
 | 
			
		||||
void fb_request_draw(void)
 | 
			
		||||
{
 | 
			
		||||
    pthread_mutex_lock(&fb_draw_req_mutex);
 | 
			
		||||
    fb_draw_requested = 1;
 | 
			
		||||
    pthread_mutex_unlock(&fb_draw_req_mutex);
 | 
			
		||||
    if(!fb_frozen)
 | 
			
		||||
        __atomic_cmpxchg(0, 1, &fb_draw_requested);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -176,7 +176,6 @@ void fb_draw_square(int x, int y, px_type color, int size);
 | 
			
		||||
void fb_draw_overlay(void);
 | 
			
		||||
void fb_draw_rect(fb_rect *r);
 | 
			
		||||
void fb_fill(uint32_t color);
 | 
			
		||||
void fb_draw(void);
 | 
			
		||||
void fb_request_draw(void);
 | 
			
		||||
void fb_clear(void);
 | 
			
		||||
void fb_freeze(int freeze);
 | 
			
		||||
 
 | 
			
		||||
@@ -276,7 +276,7 @@ void multirom_emergency_reboot(void)
 | 
			
		||||
 | 
			
		||||
    fb_add_text_long(0, 395, GRAYISH, 1, ++tail);
 | 
			
		||||
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
 | 
			
		||||
    multirom_copy_log(klog);
 | 
			
		||||
    free(klog);
 | 
			
		||||
@@ -1323,7 +1323,7 @@ void multirom_take_screenshot(void)
 | 
			
		||||
    fb_fill(WHITE);
 | 
			
		||||
    fb_update();
 | 
			
		||||
    usleep(100000);
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int multirom_get_trampoline_ver(void)
 | 
			
		||||
 
 | 
			
		||||
@@ -106,7 +106,7 @@ int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot)
 | 
			
		||||
 | 
			
		||||
        ERROR("Couldn't find theme for resolution %dx%d!\n", fb_width, fb_height);
 | 
			
		||||
        fb_add_text(0, 0, WHITE, SIZE_SMALL, "Couldn't find theme for resolution %dx%d!\nPress POWER to reboot.", fb_width, fb_height);
 | 
			
		||||
        fb_draw();
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
        fb_clear();
 | 
			
		||||
        fb_close();
 | 
			
		||||
 | 
			
		||||
@@ -133,7 +133,7 @@ int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot)
 | 
			
		||||
    if(s->auto_boot_rom && s->auto_boot_seconds > 0)
 | 
			
		||||
        multirom_ui_auto_boot();
 | 
			
		||||
    else
 | 
			
		||||
        fb_draw();
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
 | 
			
		||||
    while(1)
 | 
			
		||||
    {
 | 
			
		||||
@@ -180,7 +180,7 @@ int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot)
 | 
			
		||||
            multirom_ui_switch(tab);
 | 
			
		||||
 | 
			
		||||
            fb_freeze(0);
 | 
			
		||||
            fb_draw();
 | 
			
		||||
            fb_request_draw();
 | 
			
		||||
 | 
			
		||||
            loop_act &= ~(LOOP_CHANGE_CLR);
 | 
			
		||||
        }
 | 
			
		||||
@@ -214,7 +214,7 @@ int multirom_ui(struct multirom_status *s, struct multirom_rom **to_boot)
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    fb_freeze(1);
 | 
			
		||||
 | 
			
		||||
    cur_theme->destroy(themes_info->data);
 | 
			
		||||
@@ -319,7 +319,7 @@ void multirom_ui_switch(int tab)
 | 
			
		||||
    themes_info->data->selected_tab = tab;
 | 
			
		||||
 | 
			
		||||
    fb_freeze(0);
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void multirom_ui_fill_rom_list(listview *view, int mask)
 | 
			
		||||
@@ -384,7 +384,7 @@ int multirom_ui_destroy_msgbox(void)
 | 
			
		||||
    pthread_mutex_lock(&exit_code_mutex);
 | 
			
		||||
    fb_destroy_msgbox();
 | 
			
		||||
    fb_freeze(0);
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    active_msgbox = NULL;
 | 
			
		||||
    set_touch_handlers_mode(HANDLERS_FIRST);
 | 
			
		||||
    pthread_mutex_unlock(&exit_code_mutex);
 | 
			
		||||
@@ -402,7 +402,7 @@ void multirom_ui_auto_boot(void)
 | 
			
		||||
 | 
			
		||||
    fb_text *sec_text = fb_msgbox_add_text(-1, -1, SIZE_BIG, "%d", seconds/1000);
 | 
			
		||||
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    fb_freeze(1);
 | 
			
		||||
    set_touch_handlers_mode(HANDLERS_ALL);
 | 
			
		||||
 | 
			
		||||
@@ -432,7 +432,7 @@ void multirom_ui_auto_boot(void)
 | 
			
		||||
        {
 | 
			
		||||
            sprintf(sec_text->text, "%d", seconds/1000);
 | 
			
		||||
            fb_freeze(0);
 | 
			
		||||
            fb_draw();
 | 
			
		||||
            fb_request_draw();
 | 
			
		||||
            fb_freeze(1);
 | 
			
		||||
        }
 | 
			
		||||
        usleep(50000);
 | 
			
		||||
@@ -527,7 +527,7 @@ void multirom_ui_tab_rom_selected(listview_item *prev, listview_item *now)
 | 
			
		||||
 | 
			
		||||
    cur_theme->center_rom_name(t, rom->name);
 | 
			
		||||
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void multirom_ui_tab_rom_confirmed(listview_item *it)
 | 
			
		||||
@@ -557,7 +557,7 @@ void multirom_ui_tab_rom_boot_btn(int action)
 | 
			
		||||
        fb_msgbox_add_text(-1, 180*DPI_MUL, SIZE_NORMAL, "See XDA thread for more info.");
 | 
			
		||||
        fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to close");
 | 
			
		||||
 | 
			
		||||
        fb_draw();
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
        fb_freeze(1);
 | 
			
		||||
        set_touch_handlers_mode(HANDLERS_ALL);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -574,7 +574,7 @@ void multirom_ui_tab_rom_boot_btn(int action)
 | 
			
		||||
        fb_msgbox_add_text(-1, 215*DPI_MUL, SIZE_NORMAL, "kexec-hardboot support.");
 | 
			
		||||
        fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to close");
 | 
			
		||||
 | 
			
		||||
        fb_draw();
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
        fb_freeze(1);
 | 
			
		||||
        set_touch_handlers_mode(HANDLERS_ALL);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -588,7 +588,7 @@ void multirom_ui_tab_rom_boot_btn(int action)
 | 
			
		||||
        fb_msgbox_add_text(-1, 180*DPI_MUL, SIZE_NORMAL, "Remove spaces from ROM's name");
 | 
			
		||||
        fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to close");
 | 
			
		||||
 | 
			
		||||
        fb_draw();
 | 
			
		||||
        fb_request_draw();
 | 
			
		||||
        fb_freeze(1);
 | 
			
		||||
        set_touch_handlers_mode(HANDLERS_ALL);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -612,7 +612,7 @@ void multirom_ui_tab_rom_update_usb(void *data)
 | 
			
		||||
    listview_update_ui(t->list);
 | 
			
		||||
 | 
			
		||||
    multirom_ui_tab_rom_set_empty(data, (int)(t->list->items == NULL));
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void multirom_ui_tab_rom_refresh_usb(int action)
 | 
			
		||||
@@ -706,7 +706,7 @@ void multirom_ui_tab_misc_copy_log(int action)
 | 
			
		||||
        fb_msgbox_add_text(-1, -1, SIZE_NORMAL, "/sdcard/multirom/error.txt");
 | 
			
		||||
    fb_msgbox_add_text(-1, active_msgbox->h-60*DPI_MUL, SIZE_NORMAL, "Touch anywhere to close");
 | 
			
		||||
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    fb_freeze(1);
 | 
			
		||||
    set_touch_handlers_mode(HANDLERS_ALL);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,7 @@ progdots *progdots_create(int x, int y)
 | 
			
		||||
 | 
			
		||||
    workers_add(progdots_animate, p);
 | 
			
		||||
 | 
			
		||||
    fb_draw();
 | 
			
		||||
    fb_request_draw();
 | 
			
		||||
    return p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user