Skip to content

Commit e4dc6f8

Browse files
committed
better handling of screen backbuffers
1 parent 28cb099 commit e4dc6f8

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

drivers/staging/fbtft/fbtft-bus.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int fbtft_start_new_screen_transfer_async(struct fbtft_par *par)
124124
lock = true;
125125

126126
/* Debug fps */
127-
#define FPS_DEBUG
127+
//#define FPS_DEBUG
128128
#ifdef FPS_DEBUG
129129
long fps;
130130
ktime_t ts_now = ktime_get();
@@ -156,17 +156,6 @@ int fbtft_start_new_screen_transfer_async(struct fbtft_par *par)
156156

157157
#endif //FPS_DEBUG
158158

159-
/* Get last memory buffer not written */
160-
if(par->nb_backbuffers_full > 0){
161-
par->vmem_ptr = par->vmem_back_buffers[par->vmem_prev_buf_idx];
162-
par->nb_backbuffers_full--;
163-
par->nb_backbuffers_full = !!par->nb_backbuffers_full; //back to 1 or 0 to avoid overflows
164-
}
165-
else{
166-
par->nb_backbuffers_full = 0; // Avoid overflows, should not happen
167-
par->vmem_ptr = par->info->screen_buffer;
168-
}
169-
170159
/* Post process screen for doufle buf copy, notifs, rotation soft... */
171160
fbtft_post_process_screen(par);
172161

drivers/staging/fbtft/fbtft-core.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,15 @@ void fbtft_post_process_screen(struct fbtft_par *par)
578578
screen_post_process = true;
579579
}
580580

581+
/* Get last memory buffer not written */
582+
if(par->nb_backbuffers_full > 0){
583+
par->vmem_ptr = par->vmem_back_buffers[par->vmem_prev_buf_idx];
584+
par->nb_backbuffers_full--;
585+
}
586+
else{
587+
par->vmem_ptr = par->info->screen_buffer;
588+
par->nb_backbuffers_full = 0; // Avoid overflows, should not happen anyway
589+
}
581590
//par->vmem_ptr = par->vmem_back_buffers[par->vmem_prev_buf_idx];
582591
//par->vmem_ptr = par->info->screen_buffer;
583592

@@ -645,7 +654,8 @@ void fbtft_flip_backbuffer(struct fbtft_par *par)
645654
par->vmem_size);
646655
par->vmem_prev_buf_idx = par->vmem_cur_buf_idx;
647656
par->vmem_cur_buf_idx = (par->vmem_cur_buf_idx+1)%FBTFT_VMEM_BUFS;
648-
par->nb_backbuffers_full++;
657+
if(par->nb_backbuffers_full < FBTFT_VMEM_BUFS)
658+
par->nb_backbuffers_full++;
649659
//spin_unlock(&par->dirty_lock);
650660
}
651661

@@ -1709,18 +1719,15 @@ static irqreturn_t irq_TE_handler(int irq_no, void *dev_id)
17091719
if(!pdata->par->ready_for_spi_async)
17101720
return IRQ_HANDLED;
17111721

1722+
/* This should be enabled otherwise there will be some
1723+
soft tearing if the userspace flip speed is lower than
1724+
TE's IRQ speed. Why? because if we don't wxit now, we'll
1725+
display the frambeffer instead of the saved backed buffers*/
17121726
#if 0
1713-
if (pdata->par->nb_backbuffers_full <= 0)
1727+
if (pdata->par->nb_backbuffers_full <= 0){
1728+
pdata->par->nb_backbuffers_full = 0;
17141729
return IRQ_HANDLED;
1715-
/*static int prev_must_render = 0;
1716-
if (prev_must_render == pdata->par->nb_backbuffers_full);
1717-
return IRQ_HANDLED;*/
1718-
1719-
pdata->par->nb_backbuffers_full--;
1720-
if(pdata->par->nb_backbuffers_full > 1024){
1721-
pdata->par->nb_backbuffers_full=1;
17221730
}
1723-
prev_must_render = pdata->par->nb_backbuffers_full;
17241731
#endif
17251732

17261733
fbtft_start_new_screen_transfer_async(pdata->par);

drivers/video/fbdev/core/fbmem.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <linux/device.h>
3333
#include <linux/efi.h>
3434
#include <linux/fb.h>
35+
#include <linux/fbtft.h>
3536
#include <linux/fbcon.h>
3637
#include <linux/mem_encrypt.h>
3738

@@ -1147,6 +1148,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
11471148
ret = fb_cmap_to_user(&cmap_from, &cmap);
11481149
break;
11491150
case FBIOPAN_DISPLAY:
1151+
11501152
if (copy_from_user(&var, argp, sizeof(var)))
11511153
return -EFAULT;
11521154
console_lock();
@@ -1155,6 +1157,10 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
11551157
return -ENODEV;
11561158
}
11571159
ret = fb_pan_display(info, &var);
1160+
1161+
/** fbtft switch buffer */
1162+
fbtft_flip_backbuffer(info->par);
1163+
11581164
unlock_fb_info(info);
11591165
console_unlock();
11601166
if (ret == 0 && copy_to_user(argp, &var, sizeof(var)))

0 commit comments

Comments
 (0)