|
@@ -53,6 +53,25 @@ struct uwin {
|
|
|
static struct usurf screen;
|
|
static struct usurf screen;
|
|
|
static struct uwin wins[WM_MAX_WINDOWS];
|
|
static struct uwin wins[WM_MAX_WINDOWS];
|
|
|
static unsigned int fbw, fbh;
|
|
static unsigned int fbw, fbh;
|
|
|
|
|
+
|
|
|
|
|
+/* Desktop wallpaper: the viewer stores a header plus RGB565 pixels; the WM
|
|
|
|
|
+ * only has to stretch that small buffer to the framebuffer, so no image
|
|
|
|
|
+ * decoder is linked in. The static buffer avoids pulling malloc into the
|
|
|
|
|
+ * WM and stays within the 4 MB user image window. */
|
|
|
|
|
+#define WALL_MAP_MAX 2048
|
|
|
|
|
+static unsigned char wall_data[sizeof(struct wm_wallpaper_hdr) +
|
|
|
|
|
+ (unsigned int)WM_WALLPAPER_MAX_W * WM_WALLPAPER_MAX_H * 2u + 512];
|
|
|
|
|
+static unsigned int wall_w, wall_h;
|
|
|
|
|
+static int wall_ready;
|
|
|
|
|
+static unsigned int wall_seq_seen;
|
|
|
|
|
+static int wall_boot_seen;
|
|
|
|
|
+static int wall_retries;
|
|
|
|
|
+static unsigned int wall_retry_ms;
|
|
|
|
|
+static unsigned short wall_xmap[WALL_MAP_MAX];
|
|
|
|
|
+static unsigned short wall_ymap[WALL_MAP_MAX];
|
|
|
|
|
+/* RGB565 -> 0xFFRRGGBB, built when the wallpaper loads so the 32 bpp
|
|
|
|
|
+ * desktop path is a table lookup instead of per-pixel shifts. */
|
|
|
|
|
+static unsigned int wall_rgb32[65536];
|
|
|
static int drag_id = -1;
|
|
static int drag_id = -1;
|
|
|
static int drag_dx, drag_dy;
|
|
static int drag_dx, drag_dy;
|
|
|
static int drag_mx, drag_my; /* press position, for restore-on-drag */
|
|
static int drag_mx, drag_my; /* press position, for restore-on-drag */
|
|
@@ -852,12 +871,143 @@ static unsigned int rect_sub(struct orect *out, const struct orect *r,
|
|
|
return n;
|
|
return n;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static void wall_build_maps(void)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned int i;
|
|
|
|
|
+
|
|
|
|
|
+ if (screen.bpp == 32) {
|
|
|
|
|
+ for (i = 0; i < 65536; i++) {
|
|
|
|
|
+ unsigned int r = (i >> 11) & 31;
|
|
|
|
|
+ unsigned int g = (i >> 5) & 63;
|
|
|
|
|
+ unsigned int b = i & 31;
|
|
|
|
|
+
|
|
|
|
|
+ wall_rgb32[i] = 0xFF000000u |
|
|
|
|
|
+ ((r << 3 | r >> 2) << 16) |
|
|
|
|
|
+ ((g << 2 | g >> 4) << 8) |
|
|
|
|
|
+ (b << 3 | b >> 2);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (i = 0; i < WALL_MAP_MAX; i++) {
|
|
|
|
|
+ unsigned int sx = 0, sy = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if (fbw && i < fbw)
|
|
|
|
|
+ sx = (unsigned int)((unsigned long long)i * wall_w / fbw);
|
|
|
|
|
+ if (fbh && i < fbh)
|
|
|
|
|
+ sy = (unsigned int)((unsigned long long)i * wall_h / fbh);
|
|
|
|
|
+ if (sx >= wall_w)
|
|
|
|
|
+ sx = wall_w - 1;
|
|
|
|
|
+ if (sy >= wall_h)
|
|
|
|
|
+ sy = wall_h - 1;
|
|
|
|
|
+ wall_xmap[i] = (unsigned short)sx;
|
|
|
|
|
+ wall_ymap[i] = (unsigned short)sy;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int wall_magic_ok(const struct wm_wallpaper_hdr *h)
|
|
|
|
|
+{
|
|
|
|
|
+ unsigned int i;
|
|
|
|
|
+
|
|
|
|
|
+ for (i = 0; i < sizeof(h->magic); i++)
|
|
|
|
|
+ if (h->magic[i] != WM_WALLPAPER_MAGIC[i])
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ return 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Read the persistent copy first, then the RAM copy. The FAT driver may
|
|
|
|
|
+ * write a final partial sector past the requested length, so wall_data has
|
|
|
|
|
+ * 512 bytes of slack and the read is capped one sector below its size. */
|
|
|
|
|
+static void wall_load(void)
|
|
|
|
|
+{
|
|
|
|
|
+ static const char *const paths[] = {
|
|
|
|
|
+ WM_WALLPAPER_DATA, WM_WALLPAPER_SHARE
|
|
|
|
|
+ };
|
|
|
|
|
+ struct wm_wallpaper_hdr *h = (struct wm_wallpaper_hdr *)wall_data;
|
|
|
|
|
+ unsigned int i, pixbytes;
|
|
|
|
|
+ int rn;
|
|
|
|
|
+
|
|
|
|
|
+ wall_ready = 0;
|
|
|
|
|
+ for (i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
|
|
|
|
|
+ rn = u_syscall3(SYS_READ_FILE, (int)paths[i], (int)wall_data,
|
|
|
|
|
+ (int)(sizeof(wall_data) - 512));
|
|
|
|
|
+ if (rn < (int)sizeof(*h) || !wall_magic_ok(h))
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (!h->width || !h->height ||
|
|
|
|
|
+ h->width > WM_WALLPAPER_MAX_W ||
|
|
|
|
|
+ h->height > WM_WALLPAPER_MAX_H)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ pixbytes = h->width * h->height * 2u;
|
|
|
|
|
+ if ((unsigned int)rn < sizeof(*h) + pixbytes)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ wall_w = h->width;
|
|
|
|
|
+ wall_h = h->height;
|
|
|
|
|
+ wall_ready = 1;
|
|
|
|
|
+ wall_build_maps();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/* Paint the desktop part of one damage rectangle. */
|
|
|
|
|
+static void wall_draw(int x, int y, unsigned int w, unsigned int h)
|
|
|
|
|
+{
|
|
|
|
|
+ const unsigned short *src = (const unsigned short *)(wall_data +
|
|
|
|
|
+ sizeof(struct wm_wallpaper_hdr));
|
|
|
|
|
+ int x0 = x, y0 = y, x1 = x + (int)w, y1 = y + (int)h;
|
|
|
|
|
+ unsigned int yy, xx;
|
|
|
|
|
+
|
|
|
|
|
+ if (!wall_ready) {
|
|
|
|
|
+ usurf_fill(&screen, x, y, w, h, COL_BG);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (x0 < 0) x0 = 0;
|
|
|
|
|
+ if (y0 < 0) y0 = 0;
|
|
|
|
|
+ if (x1 > (int)fbw) x1 = (int)fbw;
|
|
|
|
|
+ if (y1 > (int)fbh) y1 = (int)fbh;
|
|
|
|
|
+ if (x1 > WALL_MAP_MAX) x1 = WALL_MAP_MAX;
|
|
|
|
|
+ if (y1 > WALL_MAP_MAX) y1 = WALL_MAP_MAX;
|
|
|
|
|
+ if (x1 <= x0 || y1 <= y0)
|
|
|
|
|
+ return;
|
|
|
|
|
+ usurf_pixels += (unsigned int)(x1 - x0) * (unsigned int)(y1 - y0);
|
|
|
|
|
+ for (yy = (unsigned int)y0; yy < (unsigned int)y1; yy++) {
|
|
|
|
|
+ const unsigned short *srow = src + (unsigned int)wall_ymap[yy] *
|
|
|
|
|
+ wall_w;
|
|
|
|
|
+
|
|
|
|
|
+ if (screen.bpp == 16) {
|
|
|
|
|
+ unsigned short *d = (unsigned short *)(screen.px +
|
|
|
|
|
+ (unsigned long)yy * screen.pitch) + x0;
|
|
|
|
|
+
|
|
|
|
|
+ for (xx = (unsigned int)x0; xx < (unsigned int)x1; xx++)
|
|
|
|
|
+ d[xx] = srow[wall_xmap[xx]];
|
|
|
|
|
+ } else if (screen.bpp == 32) {
|
|
|
|
|
+ unsigned int *d = (unsigned int *)(screen.px +
|
|
|
|
|
+ (unsigned long)yy * screen.pitch) + x0;
|
|
|
|
|
+
|
|
|
|
|
+ for (xx = (unsigned int)x0; xx < (unsigned int)x1; xx++)
|
|
|
|
|
+ d[xx] = wall_rgb32[srow[wall_xmap[xx]]];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ unsigned char *d = screen.px +
|
|
|
|
|
+ (unsigned long)yy * screen.pitch + x0 * 3;
|
|
|
|
|
+
|
|
|
|
|
+ for (xx = (unsigned int)x0; xx < (unsigned int)x1; xx++) {
|
|
|
|
|
+ unsigned int c = srow[wall_xmap[xx]];
|
|
|
|
|
+ unsigned int r = (c >> 11) & 31;
|
|
|
|
|
+ unsigned int g = (c >> 5) & 63;
|
|
|
|
|
+ unsigned int b = c & 31;
|
|
|
|
|
+
|
|
|
|
|
+ d[0] = (unsigned char)(b << 3 | b >> 2);
|
|
|
|
|
+ d[1] = (unsigned char)(g << 2 | g >> 4);
|
|
|
|
|
+ d[2] = (unsigned char)(r << 3 | r >> 2);
|
|
|
|
|
+ d += 3;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/* Back-to-front repaint, used only if the visible-region list overflows. */
|
|
/* Back-to-front repaint, used only if the visible-region list overflows. */
|
|
|
static void draw_rect_naive(int x, int y, unsigned int w, unsigned int h)
|
|
static void draw_rect_naive(int x, int y, unsigned int w, unsigned int h)
|
|
|
{
|
|
{
|
|
|
unsigned int i;
|
|
unsigned int i;
|
|
|
|
|
|
|
|
- usurf_fill(&screen, x, y, w, h, COL_BG);
|
|
|
|
|
|
|
+ wall_draw(x, y, w, h);
|
|
|
for (i = 0; i < WM_MAX_WINDOWS; i++)
|
|
for (i = 0; i < WM_MAX_WINDOWS; i++)
|
|
|
if (wins[i].info.used && !wins[i].info.focused &&
|
|
if (wins[i].info.used && !wins[i].info.focused &&
|
|
|
!wins[i].info.popover &&
|
|
!wins[i].info.popover &&
|
|
@@ -904,7 +1054,7 @@ static void draw_rect(int x, int y, unsigned int w, unsigned int h)
|
|
|
dmg.y = y0;
|
|
dmg.y = y0;
|
|
|
dmg.w = (unsigned int)(x1 - x0);
|
|
dmg.w = (unsigned int)(x1 - x0);
|
|
|
dmg.h = (unsigned int)(y1 - y0);
|
|
dmg.h = (unsigned int)(y1 - y0);
|
|
|
- usurf_fill(&screen, dmg.x, dmg.y, dmg.w, dmg.h, COL_BG);
|
|
|
|
|
|
|
+ wall_draw(dmg.x, dmg.y, dmg.w, dmg.h);
|
|
|
|
|
|
|
|
n = build_order(order);
|
|
n = build_order(order);
|
|
|
for (i = 0; i < n; i++) {
|
|
for (i = 0; i < n; i++) {
|
|
@@ -2527,6 +2677,7 @@ void _start(const char *arg)
|
|
|
usurf_font_attach(&screen, "/ramfs/fonts/sans.ttf", 14);
|
|
usurf_font_attach(&screen, "/ramfs/fonts/sans.ttf", 14);
|
|
|
fbw = si.width;
|
|
fbw = si.width;
|
|
|
fbh = si.height;
|
|
fbh = si.height;
|
|
|
|
|
+ wall_load();
|
|
|
for (i = 0; i < WM_MAX_WINDOWS; i++) {
|
|
for (i = 0; i < WM_MAX_WINDOWS; i++) {
|
|
|
wins[i].info.used = 0;
|
|
wins[i].info.used = 0;
|
|
|
wins[i].mapped = 0;
|
|
wins[i].mapped = 0;
|
|
@@ -2538,6 +2689,28 @@ void _start(const char *arg)
|
|
|
|
|
|
|
|
if (u_wm_poll(&st) != 0)
|
|
if (u_wm_poll(&st) != 0)
|
|
|
u_exit(1);
|
|
u_exit(1);
|
|
|
|
|
+ if (st.wallpaper_seq != wall_seq_seen) {
|
|
|
|
|
+ wall_seq_seen = st.wallpaper_seq;
|
|
|
|
|
+ wall_load();
|
|
|
|
|
+ full_redraw = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ /* The WM starts before the storage scan, so the first load may not
|
|
|
|
|
+ * see /data yet. Reload when boot_ready says the mounts are up,
|
|
|
|
|
+ * and retry for ten seconds for the deferred USB /data volume. */
|
|
|
|
|
+ if (st.boot_ready && !wall_boot_seen) {
|
|
|
|
|
+ wall_boot_seen = 1;
|
|
|
|
|
+ wall_retries = 0;
|
|
|
|
|
+ wall_retry_ms = u_ticks_ms() + 1000;
|
|
|
|
|
+ wall_load();
|
|
|
|
|
+ full_redraw = 1;
|
|
|
|
|
+ } else if (wall_boot_seen && !wall_ready && wall_retries < 10 &&
|
|
|
|
|
+ (int)(u_ticks_ms() - wall_retry_ms) >= 0) {
|
|
|
|
|
+ wall_retries++;
|
|
|
|
|
+ wall_retry_ms += 1000;
|
|
|
|
|
+ wall_load();
|
|
|
|
|
+ if (wall_ready)
|
|
|
|
|
+ full_redraw = 1;
|
|
|
|
|
+ }
|
|
|
if (st.full_redraw)
|
|
if (st.full_redraw)
|
|
|
full_redraw = 1;
|
|
full_redraw = 1;
|
|
|
usurf_pixels = 0;
|
|
usurf_pixels = 0;
|