summaryrefslogtreecommitdiffstats
path: root/apps/plugins
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2020-10-31 00:22:11 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2020-10-31 00:30:55 -0400
commit202f9df0c1e6132631e9e1372d50fe8dc8e87f20 (patch)
tree521f066670bfecfcdd5128a89edb4fb1121d9920 /apps/plugins
parent7eee526e6ab37f89d370de52e92d3cef36f1cf2b (diff)
downloadrockbox-202f9df0c1.tar.gz
rockbox-202f9df0c1.zip
Test_Viewports BUGFIX
putting a framebuffer on the stack is never a good idea Added comments Change-Id: I5553050785b74cb847db03957c6377cab11e816c
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/test_viewports.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/apps/plugins/test_viewports.c b/apps/plugins/test_viewports.c
index 60c6672456..669766a207 100644
--- a/apps/plugins/test_viewports.c
+++ b/apps/plugins/test_viewports.c
@@ -122,13 +122,20 @@ static struct viewport rvp1 =
static void *test_address_fn(int x, int y)
{
- struct frame_buffer_t *fb = vp0.buffer;
+/* Address lookup function
+ * core will use this to get an address from x/y coord
+ * depending on the lcd function core sometimes uses this for
+ * only the first and last address
+ * and handles subsequent address based on stride */
+ struct frame_buffer_t *fb = vp0.buffer;
+/* LCD_STRIDEFORMAT & LCD_NATIVE_STRIDE macros allow Horiz screens to work with RB */
#if defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE
size_t element = (x * LCD_NATIVE_STRIDE(fb->stride)) + y;
#else
size_t element = (y * LCD_NATIVE_STRIDE(fb->stride)) + x;
#endif
+ /* use mod fb->elems to protect from buffer ovfl */
return fb->fb_ptr + (element % fb->elems);
}
@@ -137,17 +144,39 @@ enum plugin_status plugin_start(const void* parameter)
(void)parameter;
char buf[80];
int i,y;
- fb_data vp_buffer[LCD_NBELEMS(vp0.width, vp0.height)];
+ size_t plugin_buf_len;
+ void* plugin_buf = (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len);
+
+/* Here we will test if viewports of non standard size work with the rb core */
struct frame_buffer_t fb;
+ rb->font_getstringsize("W", NULL, &vp0.height, vp0.font);
+ fb.elems = LCD_NBELEMS(vp0.width, vp0.height);
+
+ /* set stride based on the with or height of our buffer (macro picks the proper one) */
fb.stride = STRIDE_MAIN(vp0.width, vp0.height);
- fb.fb_ptr = vp_buffer;
- fb.elems = LCD_NBELEMS(vp0.width, vp0.height);
+ /*set the framebuffer pointer to our buffer (union - pick appropriate data type) */
+ fb.data = plugin_buf;
+ /* Valid data types for fb union
+ void* - data
+ char* - ch_ptr,
+ fb_data* - fb_ptr,
+ fb_remote_data - fb_remote_ptr;
+ */
+ if (fb.elems * sizeof(fb_data) > plugin_buf_len)
+ return PLUGIN_ERROR;
+
+ plugin_buf += fb.elems * sizeof(fb_data);
+ plugin_buf_len -= fb.elems * sizeof(fb_data); /* buffer bookkeeping */
+
+ /* set a frame buffer address lookup function */
fb.get_address_fn = &test_address_fn;
+ /* set our newly built buffer to the viewport */
rb->viewport_set_buffer(&vp0, &fb, SCREEN_MAIN);
+
rb->screens[SCREEN_MAIN]->set_viewport(&vp0);
rb->screens[SCREEN_MAIN]->clear_viewport();