export frame count to gpu too
[pcsx_rearmed.git] / plugins / gpu_neon / vout_fb.c
1 /*
2  * (C) GraÅžvydas "notaz" Ignotas, 2011
3  *
4  * This work is licensed under the terms of any of these licenses
5  * (at your option):
6  *  - GNU GPL, version 2 or later.
7  *  - GNU LGPL, version 2.1 or later.
8  * See the COPYING file in the top-level directory.
9  */
10
11 #include "gpu.h"
12 #include "../../frontend/plugin_lib.h"
13 #include "../../frontend/cspace.h"
14
15 static const struct rearmed_cbs *cbs;
16 static void *screen_buf;
17
18 int vout_init(void)
19 {
20   return 0;
21 }
22
23 int vout_finish(void)
24 {
25   return 0;
26 }
27
28 static void blit(void)
29 {
30   static uint32_t old_status;
31   static int old_h;
32   int x = gpu.screen.x & ~1; // alignment needed by blitter
33   int y = gpu.screen.y;
34   int w = gpu.screen.w;
35   int h = gpu.screen.h;
36   uint16_t *vram = gpu.vram;
37   int stride = gpu.screen.hres;
38   int fb_offs, doffs;
39   uint8_t *dest;
40
41   fb_offs = y * 1024 + x;
42
43   if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || h != old_h) // width|rgb24 change?
44   {
45     old_status = gpu.status.reg;
46     old_h = h;
47     screen_buf = cbs->pl_vout_set_mode(stride, h, gpu.status.rgb24 ? 24 : 16);
48   }
49
50   dest = (uint8_t *)screen_buf;
51
52   // only do centering, at least for now
53   doffs = (stride - w) / 2 & ~1;
54
55   if (gpu.status.rgb24)
56   {
57 #ifndef MAEMO
58     dest += (doffs / 8) * 24;
59     for (; h-- > 0; dest += stride * 3, fb_offs += 1024)
60     {
61       fb_offs &= 1024*512-1;
62       bgr888_to_rgb888(dest, vram + fb_offs, w * 3);
63     }
64 #else
65     dest += doffs * 2;
66     for (; h-- > 0; dest += stride * 2, fb_offs += 1024)
67     {
68       fb_offs &= 1024*512-1;
69       bgr888_to_rgb565(dest, vram + fb_offs, w * 3);
70     }
71 #endif
72   }
73   else
74   {
75     dest += doffs * 2;
76     for (; h-- > 0; dest += stride * 2, fb_offs += 1024)
77     {
78       fb_offs &= 1024*512-1;
79       bgr555_to_rgb565(dest, vram + fb_offs, w * 2);
80     }
81   }
82
83   screen_buf = cbs->pl_vout_flip();
84 }
85
86 void GPUupdateLace(void)
87 {
88   if (gpu.status.blanking || !gpu.state.fb_dirty)
89     return;
90
91   if (gpu.frameskip.set) {
92     if (!gpu.frameskip.frame_ready && gpu.frameskip.skipped_blits < 9) {
93       gpu.frameskip.skipped_blits++;
94       return;
95     }
96     gpu.frameskip.frame_ready = 0;
97     gpu.frameskip.skipped_blits = 0;
98   }
99
100   renderer_flush_queues();
101   blit();
102   gpu.state.fb_dirty = 0;
103 }
104
105 long GPUopen(void)
106 {
107   gpu.frameskip.active = 0;
108   gpu.frameskip.frame_ready = 1;
109
110   cbs->pl_vout_open();
111   screen_buf = cbs->pl_vout_flip();
112   return 0;
113 }
114
115 long GPUclose(void)
116 {
117   cbs->pl_vout_close();
118   return 0;
119 }
120
121 void GPUrearmedCallbacks(const struct rearmed_cbs *cbs_)
122 {
123   cbs = cbs_;
124   gpu.frameskip.set = cbs->frameskip;
125   gpu.frameskip.advice = &cbs->fskip_advice;
126   gpu.frameskip.active = 0;
127   gpu.frameskip.frame_ready = 1;
128   gpu.state.hcnt = cbs->gpu_hcnt;
129   gpu.state.frame_count = cbs->gpu_frame_count;
130 }
131
132 // vim:shiftwidth=2:expandtab