From 00d695849a5fb503d87203e3515f761fa8dac850 Mon Sep 17 00:00:00 2001
From: Jonathon Hall <jonathon.hall@puri.sm>
Date: Mon, 15 Jul 2024 16:37:40 -0400
Subject: [PATCH] bootsplash: Increase heap from 1 MB to 4 MB when bootsplash
 is enabled

Since commit 1d029b40c9de ("lib/jpeg: Replace decoder with Wuffs'
implementation"), a relatively large heap allocation is needed to
decode many JPEGs for use as work area.  The prior decoder did not need
this, but also had many limitations in the JPEGs it could decode.

A 1024x768 non-progressive JPEG used in Heads needs 1179648 bytes of
work area; about 1.2 MB.  While the work area will also depend on the
subsampling of each channel, it's generally proportional to the image
size.

Increasing the heap size to 4 MB when bootsplash is enabled should be
enough to decode bootsplashes up to 1920x1080 with some headroom.

Change-Id: Ia4348d39effbc16c1b42ab01bcf1e4ec5d652fa9
Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
---
 src/device/Kconfig | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/device/Kconfig b/src/device/Kconfig
index 243e23e52a..4dd03eba21 100644
--- a/src/device/Kconfig
+++ b/src/device/Kconfig
@@ -501,6 +501,11 @@ config BOOTSPLASH
 	  image in the 'General' section or add it manually to CBFS, using,
 	  for example, cbfstool.
 
+# The bootsplash JPEG decoder requires heap space approximately proportional to
+# the image size.  This usually needs a larger heap.
+config HEAP_SIZE
+	default 0x400000 if BOOTSPLASH
+
 config LINEAR_FRAMEBUFFER_MAX_WIDTH
 	int "Maximum width in pixels"
 	depends on LINEAR_FRAMEBUFFER && MAINBOARD_USE_LIBGFXINIT
-- 
2.39.2

