frontend: fix screenshot functionality for pollux
[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, old_h;
31   int x = gpu.screen.x & ~1; // alignment needed by blitter
32   int y = gpu.screen.y;
33   int w = gpu.screen.w;
34   int h = gpu.screen.h;
35   uint16_t *vram = gpu.vram;
36   int stride = gpu.screen.hres;
37   int fb_offs, doffs;
38   uint8_t *dest;
39
40   fb_offs = y * 1024 + x;
41
42   if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || h != old_h) // width|rgb24 change?
43   {
44     old_status = gpu.status.reg;
45     old_h = h;
46     screen_buf = cbs->pl_vout_set_mode(stride, h, gpu.status.rgb24 ? 24 : 16);
47   }
48
49   dest = screen_buf;
50
51   // only do centering, at least for now
52   doffs = (stride - w) / 2 & ~1;
53
54   if (gpu.status.rgb24)
55   {
56 #ifndef MAEMO
57     dest += (doffs / 8) * 24;
58     for (; h-- > 0; dest += stride * 3, fb_offs += 1024)
59     {
60       fb_offs &= 1024*512-1;
61       bgr888_to_rgb888(dest, vram + fb_offs, w * 3);
62     }
63 #else
64     dest += doffs * 2;
65     for (; h-- > 0; dest += stride * 2, fb_offs += 1024)
66     {
67       fb_offs &= 1024*512-1;
68       bgr888_to_rgb565(dest, vram + fb_offs, w * 3);
69     }
70 #endif
71   }
72   else
73   {
74     dest += doffs * 2;
75     for (; h-- > 0; dest += stride * 2, fb_offs += 1024)
76     {
77       fb_offs &= 1024*512-1;
78       bgr555_to_rgb565(dest, vram + fb_offs, w * 2);
79     }
80   }
81
82   screen_buf = cbs->pl_vout_flip();
83 }
84
85 void GPUupdateLace(void)
86 {
87   if (gpu.status.blanking || !gpu.state.fb_dirty)
88     return;
89
90   if (gpu.frameskip.set) {
91     if (!gpu.frameskip.frame_ready && gpu.frameskip.skipped_blits < 9) {
92       gpu.frameskip.skipped_blits++;
93       return;
94     }
95     gpu.frameskip.frame_ready = 0;
96     gpu.frameskip.skipped_blits = 0;
97   }
98
99   renderer_flush_queues();
100   blit();
101   gpu.state.fb_dirty = 0;
102 }
103
104 long GPUopen(void)
105 {
106   gpu.frameskip.active = 0;
107   gpu.frameskip.frame_ready = 1;
108
109   cbs->pl_vout_open();
110   screen_buf = cbs->pl_vout_flip();
111   return 0;
112 }
113
114 long GPUclose(void)
115 {
116   cbs->pl_vout_close();
117   return 0;
118 }
119
120 void GPUrearmedCallbacks(const struct rearmed_cbs *cbs_)
121 {
122   cbs = cbs_;
123   gpu.frameskip.set = cbs->frameskip;
124   gpu.frameskip.advice = &cbs->fskip_advice;
125   gpu.frameskip.active = 0;
126   gpu.frameskip.frame_ready = 1;
127 }
128
129 // vim:shiftwidth=2:expandtab