summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-16bit.c
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-09-26 08:37:00 +0100
committerAidan MacDonald <amachronic@protonmail.com>2022-10-09 22:07:44 +0100
commit4b8fe8acd1c079e75bb9229791170c549188fc08 (patch)
treee3f3a8ab80a6a603488781a933bb16ba90e8a68e /firmware/drivers/lcd-16bit.c
parent70d5b2cd45b29e64ab17b04d995dce1080d7fca9 (diff)
downloadrockbox-4b8fe8acd1c079e75bb9229791170c549188fc08.tar.gz
rockbox-4b8fe8acd1c079e75bb9229791170c549188fc08.zip
lcd: Consolidate in-viewport clipping routines
In-viewport clipping code is duplicated across 8 files, making it a chore to change anything related to clipping; refactor the clipping logic into dedicated functions. Change-Id: I4ab20bb3c59b0406098d0c7d23833025f17a320a
Diffstat (limited to 'firmware/drivers/lcd-16bit.c')
-rw-r--r--firmware/drivers/lcd-16bit.c107
1 files changed, 6 insertions, 101 deletions
diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c
index 6dff6f3b50..fd032c0956 100644
--- a/firmware/drivers/lcd-16bit.c
+++ b/firmware/drivers/lcd-16bit.c
@@ -62,36 +62,14 @@ static void ICODE_ATTR lcd_alpha_bitmap_part_mix(const fb_data* image,
62/* Draw a horizontal line (optimised) */ 62/* Draw a horizontal line (optimised) */
63void lcd_hline(int x1, int x2, int y) 63void lcd_hline(int x1, int x2, int y)
64{ 64{
65 int x, width; 65 int width;
66 unsigned bits = 0; 66 unsigned bits = 0;
67 enum fill_opt fillopt = OPT_NONE; 67 enum fill_opt fillopt = OPT_NONE;
68 fb_data *dst, *dst_end; 68 fb_data *dst, *dst_end;
69 69
70 /* direction flip */ 70 if (!lcd_clip_viewport_hline(&x1, &x2, &y))
71 if (x2 < x1)
72 {
73 x = x1;
74 x1 = x2;
75 x2 = x;
76 }
77
78 /******************** In viewport clipping **********************/
79 /* nothing to draw? */
80 if (((unsigned)y >= (unsigned)lcd_current_viewport->height) ||
81 (x1 >= lcd_current_viewport->width) ||
82 (x2 < 0))
83 return; 71 return;
84 72
85 if (x1 < 0)
86 x1 = 0;
87 if (x2 >= lcd_current_viewport->width)
88 x2 = lcd_current_viewport->width-1;
89
90 /* Adjust x1 and y to viewport */
91 x1 += lcd_current_viewport->x;
92 x2 += lcd_current_viewport->x;
93 y += lcd_current_viewport->y;
94
95 width = x2 - x1 + 1; 73 width = x2 - x1 + 1;
96 74
97 /* drawmode and optimisation */ 75 /* drawmode and optimisation */
@@ -144,37 +122,14 @@ void lcd_hline(int x1, int x2, int y)
144/* Draw a vertical line (optimised) */ 122/* Draw a vertical line (optimised) */
145void lcd_vline(int x, int y1, int y2) 123void lcd_vline(int x, int y1, int y2)
146{ 124{
147 int y;
148 fb_data *dst, *dst_end; 125 fb_data *dst, *dst_end;
149 int stride_dst; 126 int stride_dst;
150 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[lcd_current_viewport->drawmode]; 127 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[lcd_current_viewport->drawmode];
151 128
152 /* direction flip */ 129 if (!lcd_clip_viewport_vline(&x, &y1, &y2))
153 if (y2 < y1)
154 {
155 y = y1;
156 y1 = y2;
157 y2 = y;
158 }
159
160 /******************** In viewport clipping **********************/
161 /* nothing to draw? */
162 if (((unsigned)x >= (unsigned)lcd_current_viewport->width) ||
163 (y1 >= lcd_current_viewport->height) ||
164 (y2 < 0))
165 return; 130 return;
166 131
167 if (y1 < 0) 132 dst = FBADDR(x, y1);
168 y1 = 0;
169 if (y2 >= lcd_current_viewport->height)
170 y2 = lcd_current_viewport->height-1;
171
172 /* adjust for viewport */
173 x += lcd_current_viewport->x;
174 y1 += lcd_current_viewport->y;
175 y2 += lcd_current_viewport->y;
176
177 dst = FBADDR(x , y1);
178 stride_dst = lcd_current_viewport->buffer->stride; 133 stride_dst = lcd_current_viewport->buffer->stride;
179 dst_end = dst + (y2 - y1) * stride_dst; 134 dst_end = dst + (y2 - y1) * stride_dst;
180 135
@@ -194,34 +149,9 @@ void ICODE_ATTR lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
194 fb_data *dst; 149 fb_data *dst;
195 int stride_dst; 150 int stride_dst;
196 151
197 /******************** Image in viewport clipping **********************/ 152 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
198 /* nothing to draw? */
199 if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width) ||
200 (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0))
201 return; 153 return;
202 154
203 if (x < 0)
204 {
205 width += x;
206 src_x -= x;
207 x = 0;
208 }
209 if (y < 0)
210 {
211 height += y;
212 src_y -= y;
213 y = 0;
214 }
215
216 if (x + width > lcd_current_viewport->width)
217 width = lcd_current_viewport->width - x;
218 if (y + height > lcd_current_viewport->height)
219 height = lcd_current_viewport->height - y;
220
221 /* adjust for viewport */
222 x += lcd_current_viewport->x;
223 y += lcd_current_viewport->y;
224
225 src += stride * src_y + src_x; /* move starting point */ 155 src += stride * src_y + src_x; /* move starting point */
226 dst = FBADDR(x, y); 156 dst = FBADDR(x, y);
227 stride_dst = lcd_current_viewport->buffer->stride; 157 stride_dst = lcd_current_viewport->buffer->stride;
@@ -244,34 +174,9 @@ void ICODE_ATTR lcd_bitmap_transparent_part(const fb_data *src, int src_x,
244 unsigned fg = lcd_current_viewport->fg_pattern; 174 unsigned fg = lcd_current_viewport->fg_pattern;
245 int stride_dst = lcd_current_viewport->buffer->stride; 175 int stride_dst = lcd_current_viewport->buffer->stride;
246 176
247 /******************** Image in viewport clipping **********************/ 177 if (!lcd_clip_viewport_rect(&x, &y, &width, &height, &src_x, &src_y))
248 /* nothing to draw? */
249 if ((width <= 0) || (height <= 0) || (x >= lcd_current_viewport->width) ||
250 (y >= lcd_current_viewport->height) || (x + width <= 0) || (y + height <= 0))
251 return; 178 return;
252 179
253 if (x < 0)
254 {
255 width += x;
256 src_x -= x;
257 x = 0;
258 }
259 if (y < 0)
260 {
261 height += y;
262 src_y -= y;
263 y = 0;
264 }
265
266 if (x + width > lcd_current_viewport->width)
267 width = lcd_current_viewport->width - x;
268 if (y + height > lcd_current_viewport->height)
269 height = lcd_current_viewport->height - y;
270
271 /* adjust for viewport */
272 x += lcd_current_viewport->x;
273 y += lcd_current_viewport->y;
274
275 src += stride * src_y + src_x; /* move starting point */ 180 src += stride * src_y + src_x; /* move starting point */
276 dst = FBADDR(x, y); 181 dst = FBADDR(x, y);
277 182