summaryrefslogtreecommitdiff
path: root/apps/gui/skin_engine/skin_parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/skin_engine/skin_parser.c')
-rw-r--r--apps/gui/skin_engine/skin_parser.c69
1 files changed, 57 insertions, 12 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 373309ff51..a866101c1c 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -24,6 +24,7 @@
24#include <string.h> 24#include <string.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include "config.h" 26#include "config.h"
27#include "core_alloc.h"
27#include "file.h" 28#include "file.h"
28#include "misc.h" 29#include "misc.h"
29#include "plugin.h" 30#include "plugin.h"
@@ -364,6 +365,7 @@ static int parse_image_load(struct skin_element *element,
364 img->always_display = false; 365 img->always_display = false;
365 img->display = -1; 366 img->display = -1;
366 img->using_preloaded_icons = false; 367 img->using_preloaded_icons = false;
368 img->buflib_handle = -1;
367 369
368 /* save current viewport */ 370 /* save current viewport */
369 img->vp = &curr_vp->vp; 371 img->vp = &curr_vp->vp;
@@ -885,6 +887,7 @@ static int parse_progressbar_tag(struct skin_element* element,
885 img->always_display = false; 887 img->always_display = false;
886 img->display = -1; 888 img->display = -1;
887 img->using_preloaded_icons = false; 889 img->using_preloaded_icons = false;
890 img->buflib_handle = -1;
888 img->vp = &curr_vp->vp; 891 img->vp = &curr_vp->vp;
889 struct skin_token_list *item = 892 struct skin_token_list *item =
890 (struct skin_token_list *)new_skin_token_list_item(NULL, img); 893 (struct skin_token_list *)new_skin_token_list_item(NULL, img);
@@ -1389,10 +1392,20 @@ static bool check_feature_tag(const int type)
1389 **/ 1392 **/
1390static void skin_data_reset(struct wps_data *wps_data) 1393static void skin_data_reset(struct wps_data *wps_data)
1391{ 1394{
1392 wps_data->tree = NULL;
1393#ifdef HAVE_LCD_BITMAP 1395#ifdef HAVE_LCD_BITMAP
1396#ifndef __PCTOOL__
1397 struct skin_token_list *list = wps_data->images;
1398 while (list)
1399 {
1400 struct gui_img *img = (struct gui_img*)list->token->value.data;
1401 if (img->buflib_handle > 0)
1402 core_free(img->buflib_handle);
1403 list = list->next;
1404 }
1405#endif
1394 wps_data->images = NULL; 1406 wps_data->images = NULL;
1395#endif 1407#endif
1408 wps_data->tree = NULL;
1396#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1 1409#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
1397 if (wps_data->backdrop_id >= 0) 1410 if (wps_data->backdrop_id >= 0)
1398 skin_backdrop_unload(wps_data->backdrop_id); 1411 skin_backdrop_unload(wps_data->backdrop_id);
@@ -1430,11 +1443,33 @@ static void skin_data_reset(struct wps_data *wps_data)
1430} 1443}
1431 1444
1432#ifdef HAVE_LCD_BITMAP 1445#ifdef HAVE_LCD_BITMAP
1433static bool load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir) 1446#ifndef __PCTOOL__
1447static int currently_loading_handle = -1;
1448static int buflib_move_callback(int handle, void* current, void* new)
1449{
1450 (void)current;
1451 (void)new;
1452 if (handle == currently_loading_handle)
1453 return BUFLIB_CB_CANNOT_MOVE;
1454 return BUFLIB_CB_OK;
1455}
1456static struct buflib_callbacks buflib_ops = {buflib_move_callback, NULL};
1457static void lock_handle(int handle)
1458{
1459 currently_loading_handle = handle;
1460}
1461static void unlock_handle(void)
1462{
1463 currently_loading_handle = -1;
1464}
1465#endif
1466
1467static int load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char* bmpdir)
1434{ 1468{
1435 (void)wps_data; /* only needed for remote targets */ 1469 (void)wps_data; /* only needed for remote targets */
1436 char img_path[MAX_PATH]; 1470 char img_path[MAX_PATH];
1437 int fd; 1471 int fd;
1472 int handle;
1438 get_image_filename(bitmap->data, bmpdir, 1473 get_image_filename(bitmap->data, bmpdir,
1439 img_path, sizeof(img_path)); 1474 img_path, sizeof(img_path));
1440 1475
@@ -1451,35 +1486,44 @@ static bool load_skin_bmp(struct wps_data *wps_data, struct bitmap *bitmap, char
1451 if (fd < 0) 1486 if (fd < 0)
1452 { 1487 {
1453 DEBUGF("Couldn't open %s\n", img_path); 1488 DEBUGF("Couldn't open %s\n", img_path);
1454 return false; 1489 return fd;
1455 } 1490 }
1491#ifndef __PCTOOL__
1456 size_t buf_size = read_bmp_fd(fd, bitmap, 0, 1492 size_t buf_size = read_bmp_fd(fd, bitmap, 0,
1457 format|FORMAT_RETURN_SIZE, NULL); 1493 format|FORMAT_RETURN_SIZE, NULL);
1458 char* imgbuf = (char*)skin_buffer_alloc(buf_size); 1494 handle = core_alloc_ex(bitmap->data, buf_size, &buflib_ops);
1459 if (!imgbuf) 1495 if (handle < 0)
1460 { 1496 {
1461#ifndef APPLICATION 1497#ifndef APPLICATION
1462 DEBUGF("Not enough skin buffer: need %zd more.\n", 1498 DEBUGF("Not enough skin buffer: need %zd more.\n",
1463 buf_size - skin_buffer_freespace()); 1499 buf_size - skin_buffer_freespace());
1464#endif 1500#endif
1465 close(fd); 1501 close(fd);
1466 return NULL; 1502 return handle;
1467 } 1503 }
1468 lseek(fd, 0, SEEK_SET); 1504 lseek(fd, 0, SEEK_SET);
1469 bitmap->data = imgbuf; 1505 lock_handle(handle);
1506 bitmap->data = core_get_data(handle);
1470 int ret = read_bmp_fd(fd, bitmap, buf_size, format, NULL); 1507 int ret = read_bmp_fd(fd, bitmap, buf_size, format, NULL);
1471 1508 bitmap->data = NULL; /* do this to force a crash later if the
1509 caller doesnt call core_get_data() */
1510 unlock_handle();
1472 close(fd); 1511 close(fd);
1473 if (ret > 0) 1512 if (ret > 0)
1474 { 1513 {
1475 return true; 1514 return handle;
1476 } 1515 }
1477 else 1516 else
1478 { 1517 {
1479 /* Abort if we can't load an image */ 1518 /* Abort if we can't load an image */
1480 DEBUGF("Couldn't load '%s'\n", img_path); 1519 DEBUGF("Couldn't load '%s'\n", img_path);
1481 return false; 1520 core_free(handle);
1521 return -1;
1482 } 1522 }
1523#else /* !__PCTOOL__ */
1524 close(fd);
1525 return 1;
1526#endif
1483} 1527}
1484 1528
1485static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir) 1529static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir)
@@ -1501,7 +1545,8 @@ static bool load_skin_bitmaps(struct wps_data *wps_data, char *bmpdir)
1501 } 1545 }
1502 else 1546 else
1503 { 1547 {
1504 img->loaded = load_skin_bmp(wps_data, &img->bm, bmpdir); 1548 img->buflib_handle = load_skin_bmp(wps_data, &img->bm, bmpdir);
1549 img->loaded = img->buflib_handle >= 0;
1505 if (img->loaded) 1550 if (img->loaded)
1506 img->subimage_height = img->bm.height / img->num_subimages; 1551 img->subimage_height = img->bm.height / img->num_subimages;
1507 else 1552 else