Revert "temp remove before release"

This reverts commit 19ca956e7c.
This commit is contained in:
MX 2023-09-12 18:59:12 +03:00
parent 19ca956e7c
commit 6a2adf69e6
No known key found for this signature in database
GPG key ID: 7CCC66B7DBDD1C83

View file

@ -6,8 +6,6 @@
#include "gui.h" #include "gui.h"
#include "gui_i.h" #include "gui_i.h"
// TODO: add mutex to view_port ops
_Static_assert(ViewPortOrientationMAX == 4, "Incorrect ViewPortOrientation count"); _Static_assert(ViewPortOrientationMAX == 4, "Incorrect ViewPortOrientation count");
_Static_assert( _Static_assert(
(ViewPortOrientationHorizontal == 0 && ViewPortOrientationHorizontalFlip == 1 && (ViewPortOrientationHorizontal == 0 && ViewPortOrientationHorizontalFlip == 1 &&
@ -94,52 +92,73 @@ ViewPort* view_port_alloc() {
ViewPort* view_port = malloc(sizeof(ViewPort)); ViewPort* view_port = malloc(sizeof(ViewPort));
view_port->orientation = ViewPortOrientationHorizontal; view_port->orientation = ViewPortOrientationHorizontal;
view_port->is_enabled = true; view_port->is_enabled = true;
view_port->mutex = furi_mutex_alloc(FuriMutexTypeRecursive);
return view_port; return view_port;
} }
void view_port_free(ViewPort* view_port) { void view_port_free(ViewPort* view_port) {
furi_assert(view_port); furi_assert(view_port);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
furi_check(view_port->gui == NULL); furi_check(view_port->gui == NULL);
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
furi_mutex_free(view_port->mutex);
free(view_port); free(view_port);
} }
void view_port_set_width(ViewPort* view_port, uint8_t width) { void view_port_set_width(ViewPort* view_port, uint8_t width) {
furi_assert(view_port); furi_assert(view_port);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
view_port->width = width; view_port->width = width;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
uint8_t view_port_get_width(const ViewPort* view_port) { uint8_t view_port_get_width(const ViewPort* view_port) {
furi_assert(view_port); furi_assert(view_port);
return view_port->width; furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
uint8_t width = view_port->width;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
return width;
} }
void view_port_set_height(ViewPort* view_port, uint8_t height) { void view_port_set_height(ViewPort* view_port, uint8_t height) {
furi_assert(view_port); furi_assert(view_port);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
view_port->height = height; view_port->height = height;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
uint8_t view_port_get_height(const ViewPort* view_port) { uint8_t view_port_get_height(const ViewPort* view_port) {
furi_assert(view_port); furi_assert(view_port);
return view_port->height; furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
uint8_t height = view_port->height;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
return height;
} }
void view_port_enabled_set(ViewPort* view_port, bool enabled) { void view_port_enabled_set(ViewPort* view_port, bool enabled) {
furi_assert(view_port); furi_assert(view_port);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
if(view_port->is_enabled != enabled) { if(view_port->is_enabled != enabled) {
view_port->is_enabled = enabled; view_port->is_enabled = enabled;
if(view_port->gui) gui_update(view_port->gui); if(view_port->gui) gui_update(view_port->gui);
} }
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
bool view_port_is_enabled(const ViewPort* view_port) { bool view_port_is_enabled(const ViewPort* view_port) {
furi_assert(view_port); furi_assert(view_port);
return view_port->is_enabled; furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
bool is_enabled = view_port->is_enabled;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
return is_enabled;
} }
void view_port_draw_callback_set(ViewPort* view_port, ViewPortDrawCallback callback, void* context) { void view_port_draw_callback_set(ViewPort* view_port, ViewPortDrawCallback callback, void* context) {
furi_assert(view_port); furi_assert(view_port);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
view_port->draw_callback = callback; view_port->draw_callback = callback;
view_port->draw_callback_context = context; view_port->draw_callback_context = context;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
void view_port_input_callback_set( void view_port_input_callback_set(
@ -147,34 +166,44 @@ void view_port_input_callback_set(
ViewPortInputCallback callback, ViewPortInputCallback callback,
void* context) { void* context) {
furi_assert(view_port); furi_assert(view_port);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
view_port->input_callback = callback; view_port->input_callback = callback;
view_port->input_callback_context = context; view_port->input_callback_context = context;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
void view_port_update(ViewPort* view_port) { void view_port_update(ViewPort* view_port) {
furi_assert(view_port); furi_assert(view_port);
// TODO: Uncomment when all apps are verified to be fixed !!!!!!!!!!!!!!!!!!!!!!!
//furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
if(view_port->gui && view_port->is_enabled) gui_update(view_port->gui); if(view_port->gui && view_port->is_enabled) gui_update(view_port->gui);
//furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
void view_port_gui_set(ViewPort* view_port, Gui* gui) { void view_port_gui_set(ViewPort* view_port, Gui* gui) {
furi_assert(view_port); furi_assert(view_port);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
view_port->gui = gui; view_port->gui = gui;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
void view_port_draw(ViewPort* view_port, Canvas* canvas) { void view_port_draw(ViewPort* view_port, Canvas* canvas) {
furi_assert(view_port); furi_assert(view_port);
furi_assert(canvas); furi_assert(canvas);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
furi_check(view_port->gui); furi_check(view_port->gui);
if(view_port->draw_callback) { if(view_port->draw_callback) {
view_port_setup_canvas_orientation(view_port, canvas); view_port_setup_canvas_orientation(view_port, canvas);
view_port->draw_callback(canvas, view_port->draw_callback_context); view_port->draw_callback(canvas, view_port->draw_callback_context);
} }
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
void view_port_input(ViewPort* view_port, InputEvent* event) { void view_port_input(ViewPort* view_port, InputEvent* event) {
furi_assert(view_port); furi_assert(view_port);
furi_assert(event); furi_assert(event);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
furi_check(view_port->gui); furi_check(view_port->gui);
if(view_port->input_callback) { if(view_port->input_callback) {
@ -182,13 +211,19 @@ void view_port_input(ViewPort* view_port, InputEvent* event) {
view_port_map_input(event, orientation); view_port_map_input(event, orientation);
view_port->input_callback(event, view_port->input_callback_context); view_port->input_callback(event, view_port->input_callback_context);
} }
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
void view_port_set_orientation(ViewPort* view_port, ViewPortOrientation orientation) { void view_port_set_orientation(ViewPort* view_port, ViewPortOrientation orientation) {
furi_assert(view_port); furi_assert(view_port);
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
view_port->orientation = orientation; view_port->orientation = orientation;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
} }
ViewPortOrientation view_port_get_orientation(const ViewPort* view_port) { ViewPortOrientation view_port_get_orientation(const ViewPort* view_port) {
return view_port->orientation; furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
} ViewPortOrientation orientation = view_port->orientation;
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
return orientation;
}