@@ -19,10 +19,8 @@ void pyfb_init(void) {
19
19
framebuffers [i ].users = 0 ;
20
20
framebuffers [i ].fb_info .fb_size_b = 0 ;
21
21
framebuffers [i ].u32_buffer = NULL ;
22
-
23
- atomic_flag flag = ATOMIC_FLAG_INIT ;
24
-
25
- framebuffers [i ].fb_lock = flag ;
22
+ atomic_flag flag = ATOMIC_FLAG_INIT ;
23
+ framebuffers [i ].fb_lock = flag ;
26
24
}
27
25
}
28
26
@@ -110,9 +108,6 @@ int pyfb_open(uint8_t fbnum) {
110
108
111
109
if (buffer == NULL ) {
112
110
// got out of memory for the offscreen buffers
113
- if (buffer != NULL ) {
114
- free (buffer );
115
- }
116
111
117
112
// free up all other resources for the new buffer
118
113
close (fb_fd );
@@ -234,10 +229,10 @@ void pyfb_vinfo(uint8_t fbnum, struct pyfb_videomode_info* info_ptr) {
234
229
unlock (framebuffers [fbnum ].fb_lock );
235
230
}
236
231
237
- void pyfb_flushBuffer (uint8_t fbnum ) {
232
+ int pyfb_flushBuffer (uint8_t fbnum ) {
238
233
// first test if this device number is valid
239
234
if (fbnum >= MAX_FRAMEBUFFERS ) {
240
- return ;
235
+ return -1 ;
241
236
}
242
237
243
238
lock (framebuffers [fbnum ].fb_lock );
@@ -246,19 +241,27 @@ void pyfb_flushBuffer(uint8_t fbnum) {
246
241
if (framebuffers [fbnum ].fb_fd == -1 ) {
247
242
// this framebuffer is not in use, so ignore
248
243
unlock (framebuffers [fbnum ].fb_lock );
249
- return ;
244
+ return -1 ;
250
245
}
251
246
252
247
// if we get here, flush the offscreen buffer to the framebuffer
253
- lseek (framebuffers [fbnum ].fb_fd , 0L , SEEK_SET );
248
+ if (lseek (framebuffers [fbnum ].fb_fd , 0L , SEEK_SET ) == -1 ) {
249
+ unlock (framebuffers [fbnum ].fb_lock );
250
+ return -1 ;
251
+ }
252
+
253
+ size_t buf_len = (size_t )framebuffers [fbnum ].fb_info .fb_size_b ;
254
+ unsigned long int exitcode = 0 ;
255
+
254
256
if (framebuffers [fbnum ].fb_info .vinfo .bits_per_pixel == 32 ) {
255
- write (framebuffers [fbnum ].fb_fd , (void * )framebuffers [fbnum ].u32_buffer , ( size_t ) framebuffers [ fbnum ]. fb_info . fb_size_b );
257
+ exitcode = ( unsigned int ) write (framebuffers [fbnum ].fb_fd , (void * )framebuffers [fbnum ].u32_buffer , buf_len );
256
258
} else {
257
- write (framebuffers [fbnum ].fb_fd , (void * )framebuffers [fbnum ].u16_buffer , ( size_t ) framebuffers [ fbnum ]. fb_info . fb_size_b );
259
+ exitcode = ( unsigned int ) write (framebuffers [fbnum ].fb_fd , (void * )framebuffers [fbnum ].u16_buffer , buf_len );
258
260
}
259
261
260
262
// okay, ready flushed
261
263
unlock (framebuffers [fbnum ].fb_lock );
264
+ return buf_len == exitcode ? 0 : -1 ;
262
265
}
263
266
264
267
/**
@@ -308,6 +311,7 @@ void __APISTATUS_internal pyfb_setPixel(uint8_t fbnum,
308
311
// do
309
312
unsigned int xres = framebuffers [fbnum ].fb_info .vinfo .xres ;
310
313
unsigned int width = framebuffers [fbnum ].fb_info .vinfo .bits_per_pixel ;
314
+
311
315
if (width == 16 ) {
312
316
pyfb_pixel16 (fbnum , x , y , color , xres );
313
317
} else {
@@ -343,6 +347,7 @@ void pyfb_ssetPixel(uint8_t fbnum, unsigned long int x, unsigned long int y, con
343
347
344
348
// else all is okay and we can continue
345
349
unsigned int width = framebuffers [fbnum ].fb_info .vinfo .bits_per_pixel ;
350
+
346
351
if (width == 16 ) {
347
352
pyfb_pixel16 (fbnum , x , y , color , xres );
348
353
} else {
@@ -388,6 +393,7 @@ void pyfb_sdrawHorizontalLine(uint8_t fbnum,
388
393
// Now test if the ranges are okay
389
394
unsigned long int xres = framebuffers [fbnum ].fb_info .vinfo .xres ;
390
395
unsigned long int yres = framebuffers [fbnum ].fb_info .vinfo .yres ;
396
+
391
397
if (y >= yres ) {
392
398
unlock (framebuffers [fbnum ].fb_lock );
393
399
return ;
@@ -440,6 +446,7 @@ void pyfb_sdrawVerticalLine(uint8_t fbnum,
440
446
// Now test if the ranges are okay
441
447
unsigned long int xres = framebuffers [fbnum ].fb_info .vinfo .xres ;
442
448
unsigned long int yres = framebuffers [fbnum ].fb_info .vinfo .yres ;
449
+
443
450
if (y >= yres || (y + len - 1 ) >= yres ) {
444
451
unlock (framebuffers [fbnum ].fb_lock );
445
452
return ;
0 commit comments