add OMAP layer, also preliminary menu, hud and input support
[pcsx_rearmed.git] / plugins / dfxvideo / draw_fb.c
1 /*
2  * (C) notaz, 2010
3  *
4  * This work is licensed under the terms of the GNU GPLv2 or later.
5  * See the COPYING file in the top-level directory.
6  */
7
8 #define _IN_DRAW
9
10 #include "externals.h"
11 #include "gpu.h"
12 #include "draw.h"
13 #include "prim.h"
14 #include "menu.h"
15 #include "interp.h"
16 #include "swap.h"
17
18 #include "plugin_lib.h"
19
20 // misc globals
21 int            iResX;
22 int            iResY;
23 long           lLowerpart;
24 BOOL           bIsFirstFrame = TRUE;
25 BOOL           bCheckMask = FALSE;
26 unsigned short sSetMask = 0;
27 unsigned long  lSetMask = 0;
28 int            iDesktopCol = 16;
29 int            iShowFPS = 0;
30 int            iWinSize; 
31 int            iMaintainAspect = 0;
32 int            iUseNoStretchBlt = 0;
33 int            iFastFwd = 0;
34 int            iFVDisplay = 0;
35 PSXPoint_t     ptCursorPoint[8];
36 unsigned short usCursorActive = 0;
37 char *         pCaptionText;
38
39 static int fbw, fbh, fb24bpp;
40 static int flip_cnt, flips_per_sec;
41
42 #ifndef __arm__
43 #define bgr555_to_rgb565 memcpy
44 #define bgr888_to_rgb888 memcpy
45 #endif
46
47 static void blit(void)
48 {
49  extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
50  extern void bgr888_to_rgb888(void *dst, void *src, int bytes);
51  int x = PSXDisplay.DisplayPosition.x;
52  int y = PSXDisplay.DisplayPosition.y;
53  int w = PreviousPSXDisplay.Range.x1;
54  int h = PreviousPSXDisplay.DisplayMode.y;
55  int pitch = PreviousPSXDisplay.DisplayMode.x;
56  unsigned short *srcs = psxVuw + y * 1024 + x;
57  unsigned char *dest = pl_fbdev_buf;
58
59  if (w <= 0)
60    return;
61
62  // TODO: clear border if centering
63
64  pitch *= PSXDisplay.RGB24 ? 3 : 2;
65
66  // account for centering
67  h -= PreviousPSXDisplay.Range.y0;
68  dest += PreviousPSXDisplay.Range.y0 / 2 * pitch;
69  dest += PreviousPSXDisplay.Range.x0 * 2; // XXX
70
71  if (PSXDisplay.RGB24)
72  {
73    for (; h-- > 0; dest += pitch, srcs += 1024)
74    {
75      bgr888_to_rgb888(dest, srcs, w * 3);
76    }
77  }
78  else
79  {
80    for (; h-- > 0; dest += pitch, srcs += 1024)
81    {
82      bgr555_to_rgb565(dest, srcs, w * 2);
83    }
84    pl_text_out16(2, fbh - 10, "%2d %2.1f", flips_per_sec, fps_cur);
85  }
86 }
87
88 #include "pcnt.h"
89
90 void DoBufferSwap(void)
91 {
92  static int fps_counter;
93  if (PSXDisplay.DisplayMode.x == 0 || PSXDisplay.DisplayMode.y == 0)
94   return;
95
96  if (PSXDisplay.DisplayMode.x != fbw || PSXDisplay.DisplayMode.y != fbh
97      || PSXDisplay.RGB24 != fb24bpp) {
98   fbw = PSXDisplay.DisplayMode.x;
99   fbh = PSXDisplay.DisplayMode.y;
100   fb24bpp = PSXDisplay.RGB24;
101   pl_fbdev_set_mode(fbw, fbh, fb24bpp ? 24 : 16);
102  }
103
104  blit();
105  pl_fbdev_flip();
106
107  pcnt_end(PCNT_ALL);
108
109  {
110   static int oldsec;
111   struct timeval tv;
112   flip_cnt++;
113   gettimeofday(&tv, 0);
114   if (tv.tv_sec != oldsec) {
115     flips_per_sec = flip_cnt;
116     flip_cnt = 0;
117     oldsec = tv.tv_sec;
118   }
119  }
120  if (++fps_counter == 60/6) {
121   pcnt_print(fps_cur);
122   fps_counter = 0;
123  }
124
125  pcnt_start(PCNT_ALL);
126 }
127
128 void DoClearScreenBuffer(void)                         // CLEAR DX BUFFER
129 {
130 }
131
132 void DoClearFrontBuffer(void)                          // CLEAR DX BUFFER
133 {
134 }
135
136 static int initialize(void)
137 {
138  iDesktopCol=32;
139
140  bUsingTWin=FALSE;
141  bIsFirstFrame = FALSE;                                // done
142
143  if(iShowFPS)
144   {
145    iShowFPS=0;
146    ulKeybits|=KEY_SHOWFPS;
147    szDispBuf[0]=0;
148    BuildDispMenu(0);
149   }
150
151  return 0;
152 }
153
154 unsigned long ulInitDisplay(void)
155 {
156  iShowFPS=1;
157  initialize();
158
159  if (pl_fbdev_init() != 0)
160   return 0;
161
162  return 1; /* ok */
163 }
164
165 void CloseDisplay(void)
166 {
167  CloseMenu();
168  pl_fbdev_finish();
169  //WriteConfig();
170 }
171
172 void CreatePic(unsigned char * pMem)
173 {
174 }
175
176 void DestroyPic(void)
177 {
178 }
179
180 void HandleKey(int keycode)
181 {
182 }