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