summaryrefslogtreecommitdiff
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-202f9df0c1e6132631e9e1372d50fe8dc8e87f20.tar.gz
rockbox-202f9df0c1e6132631e9e1372d50fe8dc8e87f20.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 =
122 122
123static void *test_address_fn(int x, int y) 123static void *test_address_fn(int x, int y)
124{ 124{
125 struct frame_buffer_t *fb = vp0.buffer; 125/* Address lookup function
126 * core will use this to get an address from x/y coord
127 * depending on the lcd function core sometimes uses this for
128 * only the first and last address
129 * and handles subsequent address based on stride */
126 130
131 struct frame_buffer_t *fb = vp0.buffer;
132/* LCD_STRIDEFORMAT & LCD_NATIVE_STRIDE macros allow Horiz screens to work with RB */
127#if defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE 133#if defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE
128 size_t element = (x * LCD_NATIVE_STRIDE(fb->stride)) + y; 134 size_t element = (x * LCD_NATIVE_STRIDE(fb->stride)) + y;
129#else 135#else
130 size_t element = (y * LCD_NATIVE_STRIDE(fb->stride)) + x; 136 size_t element = (y * LCD_NATIVE_STRIDE(fb->stride)) + x;
131#endif 137#endif
138 /* use mod fb->elems to protect from buffer ovfl */
132 return fb->fb_ptr + (element % fb->elems); 139 return fb->fb_ptr + (element % fb->elems);
133} 140}
134 141
@@ -137,17 +144,39 @@ enum plugin_status plugin_start(const void* parameter)
137 (void)parameter; 144 (void)parameter;
138 char buf[80]; 145 char buf[80];
139 int i,y; 146 int i,y;
140 fb_data vp_buffer[LCD_NBELEMS(vp0.width, vp0.height)];
141 147
148 size_t plugin_buf_len;
149 void* plugin_buf = (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len);
150
151/* Here we will test if viewports of non standard size work with the rb core */
142 struct frame_buffer_t fb; 152 struct frame_buffer_t fb;
143 153
154 rb->font_getstringsize("W", NULL, &vp0.height, vp0.font);
155 fb.elems = LCD_NBELEMS(vp0.width, vp0.height);
156
157 /* set stride based on the with or height of our buffer (macro picks the proper one) */
144 fb.stride = STRIDE_MAIN(vp0.width, vp0.height); 158 fb.stride = STRIDE_MAIN(vp0.width, vp0.height);
145 159
146 fb.fb_ptr = vp_buffer; 160 /*set the framebuffer pointer to our buffer (union - pick appropriate data type) */
147 fb.elems = LCD_NBELEMS(vp0.width, vp0.height); 161 fb.data = plugin_buf;
162 /* Valid data types for fb union
163 void* - data
164 char* - ch_ptr,
165 fb_data* - fb_ptr,
166 fb_remote_data - fb_remote_ptr;
167 */
168 if (fb.elems * sizeof(fb_data) > plugin_buf_len)
169 return PLUGIN_ERROR;
170
171 plugin_buf += fb.elems * sizeof(fb_data);
172 plugin_buf_len -= fb.elems * sizeof(fb_data); /* buffer bookkeeping */
173
174 /* set a frame buffer address lookup function */
148 fb.get_address_fn = &test_address_fn; 175 fb.get_address_fn = &test_address_fn;
149 176
177 /* set our newly built buffer to the viewport */
150 rb->viewport_set_buffer(&vp0, &fb, SCREEN_MAIN); 178 rb->viewport_set_buffer(&vp0, &fb, SCREEN_MAIN);
179
151 rb->screens[SCREEN_MAIN]->set_viewport(&vp0); 180 rb->screens[SCREEN_MAIN]->set_viewport(&vp0);
152 rb->screens[SCREEN_MAIN]->clear_viewport(); 181 rb->screens[SCREEN_MAIN]->clear_viewport();
153 182