FreeBASIC  0.91.0
gfx_page.c
Go to the documentation of this file.
1 /* screen multiple pages handling */
2 
3 #include "fb_gfx.h"
4 
5 
6 /*:::::*/
7 FBCALL int fb_GfxFlip(int from_page, int to_page)
8 {
10  unsigned char *dest, *src;
11  int i, size, text_size, lock = FALSE;
12  int src_page, dest_page;
13 
14  if (!__fb_gfx)
16 
17  if (__fb_gfx->driver->flip) {
18  __fb_gfx->driver->flip();
22  }
23 
24  fb_hPrepareTarget(context, NULL);
26 
27  if (from_page < 0) {
28  src = context->line[0];
29  src_page = context->work_page;
30  }
31  else if (from_page >= __fb_gfx->num_pages)
33  else {
34  src = __fb_gfx->page[from_page];
35  src_page = from_page;
36  }
37  if (to_page < 0) {
38  dest = __fb_gfx->framebuffer;
39  dest_page = __fb_gfx->visible_page;
40  }
41  else if (to_page >= __fb_gfx->num_pages)
43  else {
44  dest = __fb_gfx->page[to_page];
45  dest_page = to_page;
46  }
47 
48  if (src == dest)
50  if ((dest == __fb_gfx->framebuffer) && (__fb_gfx->lock_count==0))
51  lock = TRUE;
52 
53  text_size = __fb_gfx->text_w * __fb_gfx->text_h * sizeof(GFX_CHAR_CELL);
54 
55  src += (context->view_y * __fb_gfx->pitch) + (context->view_x * __fb_gfx->bpp);
56  dest += (context->view_y * __fb_gfx->pitch) + (context->view_x * __fb_gfx->bpp);
57  size = context->view_w * __fb_gfx->bpp;
58 
59  if (lock)
60  DRIVER_LOCK();
61  for (i = context->view_h; i; i--) {
62  fb_hMemCpy(dest, src, size);
63  dest += __fb_gfx->pitch;
64  src += __fb_gfx->pitch;
65  }
66  /* Copy the character cell pages too */
67  fb_hMemCpy(__fb_gfx->con_pages[dest_page], __fb_gfx->con_pages[src_page], text_size);
68  if (lock) {
69  fb_hMemSet(__fb_gfx->dirty + context->view_y, TRUE, context->view_h);
70  DRIVER_UNLOCK();
71  }
72 
74 }
75 
76 /*:::::*/
77 int fb_GfxPageCopy(int from_page, int to_page)
78 {
79  return fb_GfxFlip( from_page, to_page );
80 }
81 
82 /*:::::*/
83 int fb_GfxPageSet(int work_page, int visible_page)
84 {
86 
87  int res = context->work_page | (__fb_gfx->visible_page << 8);
88 
89  if (!__fb_gfx)
90  return -1;
91 
92  fb_hPrepareTarget(context, NULL);
94 
95  if ((work_page < 0) && (visible_page < 0))
96  work_page = visible_page = 0;
97 
98  if ((work_page >= 0) && (work_page < __fb_gfx->num_pages)) {
99  int i;
100  for (i = 0; i < __fb_gfx->h; i++)
101  context->line[i] = __fb_gfx->page[work_page] + (i * __fb_gfx->pitch);
102  context->work_page = work_page;
103  }
104  if ((visible_page >= 0) && (visible_page < __fb_gfx->num_pages) && (visible_page != __fb_gfx->visible_page)) {
105  DRIVER_LOCK();
106  __fb_gfx->framebuffer = __fb_gfx->page[visible_page];
107  __fb_gfx->visible_page = visible_page;
109  DRIVER_UNLOCK();
110  }
111 
112  return res;
113 }
114 
115