bring GPUvBlank back
[pcsx_rearmed.git] / plugins / gpu_neon / vout_fb.c
CommitLineData
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
15static const struct rearmed_cbs *cbs;
16static void *screen_buf;
17
18int vout_init(void)
19{
20 return 0;
21}
22
23int vout_finish(void)
24{
25 return 0;
26}
27
7d993ee2 28static void check_mode_change(void)
56f08d83 29{
6f2ee2be 30 static uint32_t old_status;
31 static int old_h;
7d993ee2 32
33 // width|rgb24 change?
34 if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || gpu.screen.h != old_h)
35 {
36 old_status = gpu.status.reg;
37 old_h = gpu.screen.h;
38 screen_buf = cbs->pl_vout_set_mode(gpu.screen.hres,
39 gpu.screen.h, gpu.status.rgb24 ? 24 : 16);
40 }
41}
42
43static void blit(void)
44{
8dd855cd 45 int x = gpu.screen.x & ~1; // alignment needed by blitter
56f08d83 46 int y = gpu.screen.y;
47 int w = gpu.screen.w;
8dd855cd 48 int h = gpu.screen.h;
5f26e402 49 uint16_t *vram = gpu.vram;
8dd855cd 50 int stride = gpu.screen.hres;
5f26e402 51 int fb_offs, doffs;
52 uint8_t *dest;
56f08d83 53
5f26e402 54 fb_offs = y * 1024 + x;
6f2ee2be 55 dest = (uint8_t *)screen_buf;
56f08d83 56
8dd855cd 57 // only do centering, at least for now
58 doffs = (stride - w) / 2 & ~1;
59
56f08d83 60 if (gpu.status.rgb24)
61 {
62#ifndef MAEMO
8dd855cd 63 dest += (doffs / 8) * 24;
5f26e402 64 for (; h-- > 0; dest += stride * 3, fb_offs += 1024)
56f08d83 65 {
5f26e402 66 fb_offs &= 1024*512-1;
67 bgr888_to_rgb888(dest, vram + fb_offs, w * 3);
56f08d83 68 }
69#else
8dd855cd 70 dest += doffs * 2;
5f26e402 71 for (; h-- > 0; dest += stride * 2, fb_offs += 1024)
56f08d83 72 {
5f26e402 73 fb_offs &= 1024*512-1;
74 bgr888_to_rgb565(dest, vram + fb_offs, w * 3);
56f08d83 75 }
76#endif
77 }
78 else
79 {
8dd855cd 80 dest += doffs * 2;
5f26e402 81 for (; h-- > 0; dest += stride * 2, fb_offs += 1024)
56f08d83 82 {
5f26e402 83 fb_offs &= 1024*512-1;
84 bgr555_to_rgb565(dest, vram + fb_offs, w * 2);
56f08d83 85 }
86 }
87
9394ada5 88 screen_buf = cbs->pl_vout_flip();
56f08d83 89}
90
91void GPUupdateLace(void)
92{
19e7cf87 93 if (gpu.status.blanking || !gpu.state.fb_dirty)
fc84f618 94 return;
95
ea4a16e7 96 if (gpu.frameskip.set) {
fb4c6fba 97 if (!gpu.frameskip.frame_ready) {
98 if (*gpu.state.frame_count - gpu.frameskip.last_flip_frame < 9)
99 return;
19e7cf87 100 }
101 gpu.frameskip.frame_ready = 0;
fc84f618 102 }
19e7cf87 103
c7945666 104 if (gpu.cmd_len > 0)
105 flush_cmd_buffer();
19e7cf87 106 renderer_flush_queues();
7d993ee2 107 check_mode_change();
108 if (cbs->pl_vout_raw_flip)
109 cbs->pl_vout_raw_flip(gpu.screen.x, gpu.screen.y);
110 else
111 blit();
19e7cf87 112 gpu.state.fb_dirty = 0;
56f08d83 113}
114
096ec49b 115long GPUopen(void **unused)
56f08d83 116{
19e7cf87 117 gpu.frameskip.active = 0;
118 gpu.frameskip.frame_ready = 1;
fc84f618 119
9394ada5 120 cbs->pl_vout_open();
121 screen_buf = cbs->pl_vout_flip();
56f08d83 122 return 0;
123}
124
125long GPUclose(void)
126{
9394ada5 127 cbs->pl_vout_close();
56f08d83 128 return 0;
129}
130
131void GPUrearmedCallbacks(const struct rearmed_cbs *cbs_)
132{
133 cbs = cbs_;
ea4a16e7 134 gpu.frameskip.set = cbs->frameskip;
135 gpu.frameskip.advice = &cbs->fskip_advice;
136 gpu.frameskip.active = 0;
137 gpu.frameskip.frame_ready = 1;
24de2dd4 138 gpu.state.hcnt = cbs->gpu_hcnt;
3ece2f0c 139 gpu.state.frame_count = cbs->gpu_frame_count;
914455e6 140
141 if (cbs->pl_vout_set_raw_vram)
142 cbs->pl_vout_set_raw_vram(gpu.vram);
143 renderer_set_config(cbs_);
56f08d83 144}
145
146// vim:shiftwidth=2:expandtab