Limit exposure of skin engine internals

Drop wps_internals.h from skin_engine.h. The WPS and to a lesser
extent the radio screen are too tightly integrated to drop their
dependency on wps_internals.h, unfortunately. Skinned lists, for
obvious reasons, also need access to the internals.

Change-Id: I00a55aa423900f9ad22edccbe2fc1910af380e38
This commit is contained in:
Aidan MacDonald 2022-10-02 18:02:27 +01:00
parent 4bd97c6535
commit c6ee9dc883
15 changed files with 157 additions and 142 deletions

View file

@ -2509,59 +2509,6 @@ static bool dbg_pic(void)
}
#endif
static bool dbg_skin_engine(void)
{
struct simplelist_info info;
int i, total = 0;
#if defined(HAVE_BACKDROP_IMAGE)
int ref_count;
char *path;
size_t bytes;
int path_prefix_len = strlen(ROCKBOX_DIR "/wps/");
#endif
simplelist_info_init(&info, "Skin engine usage", 0, NULL);
simplelist_set_line_count(0);
FOR_NB_SCREENS(j) {
#if NB_SCREENS > 1
simplelist_addline("%s display:",
j == 0 ? "Main" : "Remote");
#endif
for (i = 0; i < skin_get_num_skins(); i++) {
struct skin_stats *stats = skin_get_stats(i, j);
if (stats->buflib_handles)
{
simplelist_addline("Skin ID: %d, %d allocations",
i, stats->buflib_handles);
simplelist_addline("\tskin: %d bytes",
stats->tree_size);
simplelist_addline("\tImages: %d bytes",
stats->images_size);
simplelist_addline("\tTotal: %d bytes",
stats->tree_size + stats->images_size);
total += stats->tree_size + stats->images_size;
}
}
}
simplelist_addline("Skin total usage: %d bytes", total);
#if defined(HAVE_BACKDROP_IMAGE)
simplelist_addline("Backdrop Images:");
i = 0;
while (skin_backdrop_get_debug(i++, &path, &ref_count, &bytes)) {
if (ref_count > 0) {
if (!strncasecmp(path, ROCKBOX_DIR "/wps/", path_prefix_len))
path += path_prefix_len;
simplelist_addline("%s", path);
simplelist_addline("\tref_count: %d", ref_count);
simplelist_addline("\tsize: %d", bytes);
total += bytes;
}
}
simplelist_addline("Total usage: %d bytes", total);
#endif
return simplelist_show_list(&info);
}
#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
static bool dbg_boot_data(void)
{

View file

@ -229,16 +229,7 @@ extern bool gui_synclist_keyclick_callback(int action, void* data);
*/
extern bool gui_synclist_do_button(struct gui_synclist * lists, int *action);
#if !defined(PLUGIN)
struct listitem_viewport_cfg {
struct wps_data *data;
OFFSETTYPE(char *) label;
int width;
int height;
int xmargin;
int ymargin;
bool tile;
struct skin_viewport selected_item_vp;
};
struct listitem_viewport_cfg;
bool skinlist_get_item(struct screen *display, struct gui_synclist *list, int x, int y, int *item);
bool skinlist_draw(struct screen *display, struct gui_synclist *list);

View file

@ -46,6 +46,7 @@
#include "tagcache.h"
#include "list.h"
#include "option_select.h"
#include "buffering.h"
#include "peakmeter.h"
/* Image stuff */
@ -636,6 +637,76 @@ void draw_peakmeters(struct gui_wps *gwps, int line_number,
}
}
/* Draw the album art bitmap from the given handle ID onto the given WPS.
Call with clear = true to clear the bitmap instead of drawing it. */
void draw_album_art(struct gui_wps *gwps, int handle_id, bool clear)
{
if (!gwps || !gwps->data || !gwps->display || handle_id < 0)
return;
struct wps_data *data = gwps->data;
struct skin_albumart *aa = SKINOFFSETTOPTR(get_skin_buffer(data), data->albumart);
if (!aa)
return;
struct bitmap *bmp;
if (bufgetdata(handle_id, 0, (void *)&bmp) <= 0)
return;
short x = aa->x;
short y = aa->y;
short width = bmp->width;
short height = bmp->height;
if (aa->width > 0)
{
/* Crop if the bitmap is too wide */
width = MIN(bmp->width, aa->width);
/* Align */
if (aa->xalign & WPS_ALBUMART_ALIGN_RIGHT)
x += aa->width - width;
else if (aa->xalign & WPS_ALBUMART_ALIGN_CENTER)
x += (aa->width - width) / 2;
}
if (aa->height > 0)
{
/* Crop if the bitmap is too high */
height = MIN(bmp->height, aa->height);
/* Align */
if (aa->yalign & WPS_ALBUMART_ALIGN_BOTTOM)
y += aa->height - height;
else if (aa->yalign & WPS_ALBUMART_ALIGN_CENTER)
y += (aa->height - height) / 2;
}
if (!clear)
{
/* Draw the bitmap */
gwps->display->bitmap_part((fb_data*)bmp->data, 0, 0,
STRIDE(gwps->display->screen_type,
bmp->width, bmp->height),
x, y, width, height);
#ifdef HAVE_LCD_INVERT
if (global_settings.invert) {
gwps->display->set_drawmode(DRMODE_COMPLEMENT);
gwps->display->fillrect(x, y, width, height);
gwps->display->set_drawmode(DRMODE_SOLID);
}
#endif
}
else
{
/* Clear the bitmap */
gwps->display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
gwps->display->fillrect(x, y, width, height);
gwps->display->set_drawmode(DRMODE_SOLID);
}
}
bool skin_has_sbs(enum screen_type screen, struct wps_data *data)
{
(void)screen;

View file

@ -54,4 +54,8 @@ void write_line(struct screen *display, struct align_pos *format_align,
int line, bool scroll, struct line_desc *line_desc);
void draw_peakmeters(struct gui_wps *gwps, int line_number,
struct viewport *viewport);
/* Draw the album art bitmap from the given handle ID onto the given Skin.
Call with clear = true to clear the bitmap instead of drawing it. */
void draw_album_art(struct gui_wps *gwps, int handle_id, bool clear);
#endif

View file

@ -34,9 +34,11 @@
#if CONFIG_TUNER
#include "radio.h"
#endif
#include "gui/list.h"
#include "skin_engine.h"
#include "skin_buffer.h"
#include "statusbar-skinned.h"
#include "wps_internals.h"
#define FAILSAFENAME "rockbox_failsafe"
@ -334,3 +336,56 @@ void skin_request_full_update(enum skinnable_screens skin)
FOR_NB_SCREENS(i)
skins[skin][i].needs_full_update = true;
}
bool dbg_skin_engine(void)
{
struct simplelist_info info;
int i, total = 0;
#if defined(HAVE_BACKDROP_IMAGE)
int ref_count;
char *path;
size_t bytes;
int path_prefix_len = strlen(ROCKBOX_DIR "/wps/");
#endif
simplelist_info_init(&info, "Skin engine usage", 0, NULL);
simplelist_set_line_count(0);
FOR_NB_SCREENS(j) {
#if NB_SCREENS > 1
simplelist_addline("%s display:",
j == 0 ? "Main" : "Remote");
#endif
for (i = 0; i < skin_get_num_skins(); i++) {
struct skin_stats *stats = skin_get_stats(i, j);
if (stats->buflib_handles)
{
simplelist_addline("Skin ID: %d, %d allocations",
i, stats->buflib_handles);
simplelist_addline("\tskin: %d bytes",
stats->tree_size);
simplelist_addline("\tImages: %d bytes",
stats->images_size);
simplelist_addline("\tTotal: %d bytes",
stats->tree_size + stats->images_size);
total += stats->tree_size + stats->images_size;
}
}
}
simplelist_addline("Skin total usage: %d bytes", total);
#if defined(HAVE_BACKDROP_IMAGE)
simplelist_addline("Backdrop Images:");
i = 0;
while (skin_backdrop_get_debug(i++, &path, &ref_count, &bytes)) {
if (ref_count > 0) {
if (!strncasecmp(path, ROCKBOX_DIR "/wps/", path_prefix_len))
path += path_prefix_len;
simplelist_addline("%s", path);
simplelist_addline("\tref_count: %d", ref_count);
simplelist_addline("\tsize: %d", bytes);
total += bytes;
}
}
simplelist_addline("Total usage: %d bytes", total);
#endif
return simplelist_show_list(&info);
}

View file

@ -26,8 +26,7 @@
#ifndef PLUGIN
#include "tag_table.h"
#include "wps_internals.h" /* TODO: remove this line.. shoudlnt be needed */
#include "screen_access.h"
enum skinnable_screens {
CUSTOM_STATUSBAR,
@ -39,6 +38,11 @@ enum skinnable_screens {
SKINNABLE_SCREENS_COUNT
};
struct skin_stats;
struct skin_viewport;
struct touchregion;
struct wps_data;
#ifdef HAVE_TOUCHSCREEN
int skin_get_touchaction(struct wps_data *data, int* edge_offset,
struct touchregion **retregion);
@ -89,5 +93,7 @@ void skin_unload_all(void);
bool skin_do_full_update(enum skinnable_screens skin, enum screen_type screen);
void skin_request_full_update(enum skinnable_screens skin);
bool dbg_skin_engine(void);
#endif /* !PLUGIN */
#endif

View file

@ -74,6 +74,8 @@ struct skin_draw_info {
int offset; /* used by the playlist viewer */
};
extern void sb_set_info_vp(enum screen_type screen, OFFSETTYPE(char*) label);
typedef bool (*skin_render_func)(struct skin_element* alternator, struct skin_draw_info *info);
bool skin_render_alternator(struct skin_element* alternator, struct skin_draw_info *info);

View file

@ -313,6 +313,17 @@ struct listitem {
short offset;
};
struct listitem_viewport_cfg {
struct wps_data *data;
OFFSETTYPE(char *) label;
int width;
int height;
int xmargin;
int ymargin;
bool tile;
struct skin_viewport selected_item_vp;
};
#ifdef HAVE_SKIN_VARIABLES
struct skin_var {
OFFSETTYPE(const char *) label;

View file

@ -53,6 +53,8 @@ static const char* sbs_title[NB_SCREENS];
static enum themable_icons sbs_icon[NB_SCREENS];
static bool sbs_loaded[NB_SCREENS] = { false };
void sb_set_info_vp(enum screen_type screen, OFFSETTYPE(char*) label);
bool sb_set_title_text(const char* title, enum themable_icons icon, enum screen_type screen)
{
sbs_title[screen] = title;

View file

@ -34,7 +34,6 @@ void sb_skin_data_load(enum screen_type screen, const char *buf, bool isfile);
char* sb_create_from_settings(enum screen_type screen);
void sb_skin_init(void) INIT_ATTR;
void sb_set_info_vp(enum screen_type screen, OFFSETTYPE(char*) label);
struct viewport *sb_skin_get_info_vp(enum screen_type screen);
void sb_skin_update(enum screen_type screen, bool force);

View file

@ -61,6 +61,7 @@
#include "playlist_viewer.h"
#include "wps.h"
#include "statusbar-skinned.h"
#include "skin_engine/wps_internals.h"
#define RESTORE_WPS_INSTANTLY 0l
#define RESTORE_WPS_NEXT_SECOND ((long)(HZ+current_tick))

View file

@ -56,6 +56,7 @@
#include "statusbar-skinned.h"
#include "playback.h"
#include "presets.h"
#include "skin_engine/wps_internals.h"
#if CONFIG_TUNER

View file

@ -36,6 +36,7 @@
#include "sound.h"
#include "misc.h"
#endif
#include "skin_engine/wps_internals.h"
char* default_radio_skin(enum screen_type screen)

View file

@ -297,74 +297,4 @@ bool find_albumart(const struct mp3entry *id3, char *buf, int buflen,
return search_albumart_files(id3, size_string, buf, buflen);
}
/* Draw the album art bitmap from the given handle ID onto the given WPS.
Call with clear = true to clear the bitmap instead of drawing it. */
void draw_album_art(struct gui_wps *gwps, int handle_id, bool clear)
{
if (!gwps || !gwps->data || !gwps->display || handle_id < 0)
return;
struct wps_data *data = gwps->data;
struct skin_albumart *aa = SKINOFFSETTOPTR(get_skin_buffer(data), data->albumart);
if (!aa)
return;
struct bitmap *bmp;
if (bufgetdata(handle_id, 0, (void *)&bmp) <= 0)
return;
short x = aa->x;
short y = aa->y;
short width = bmp->width;
short height = bmp->height;
if (aa->width > 0)
{
/* Crop if the bitmap is too wide */
width = MIN(bmp->width, aa->width);
/* Align */
if (aa->xalign & WPS_ALBUMART_ALIGN_RIGHT)
x += aa->width - width;
else if (aa->xalign & WPS_ALBUMART_ALIGN_CENTER)
x += (aa->width - width) / 2;
}
if (aa->height > 0)
{
/* Crop if the bitmap is too high */
height = MIN(bmp->height, aa->height);
/* Align */
if (aa->yalign & WPS_ALBUMART_ALIGN_BOTTOM)
y += aa->height - height;
else if (aa->yalign & WPS_ALBUMART_ALIGN_CENTER)
y += (aa->height - height) / 2;
}
if (!clear)
{
/* Draw the bitmap */
gwps->display->bitmap_part((fb_data*)bmp->data, 0, 0,
STRIDE(gwps->display->screen_type,
bmp->width, bmp->height),
x, y, width, height);
#ifdef HAVE_LCD_INVERT
if (global_settings.invert) {
gwps->display->set_drawmode(DRMODE_COMPLEMENT);
gwps->display->fillrect(x, y, width, height);
gwps->display->set_drawmode(DRMODE_SOLID);
}
#endif
}
else
{
/* Clear the bitmap */
gwps->display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
gwps->display->fillrect(x, y, width, height);
gwps->display->set_drawmode(DRMODE_SOLID);
}
}
#endif /* PLUGIN */

View file

@ -35,12 +35,6 @@
bool find_albumart(const struct mp3entry *id3, char *buf, int buflen,
const struct dim *dim);
#ifndef PLUGIN
/* Draw the album art bitmap from the given handle ID onto the given Skin.
Call with clear = true to clear the bitmap instead of drawing it. */
void draw_album_art(struct gui_wps *gwps, int handle_id, bool clear);
#endif
bool search_albumart_files(const struct mp3entry *id3, const char *size_string,
char *buf, int buflen);