gpu: move enhacement logic out of vout_pl
[pcsx_rearmed.git] / plugins / gpulib / vout_pl.c
... / ...
CommitLineData
1/*
2 * video output handling using plugin_lib
3 * (C) GraÅžvydas "notaz" Ignotas, 2011
4 *
5 * This work is licensed under the terms of any of these licenses
6 * (at your option):
7 * - GNU GPL, version 2 or later.
8 * - GNU LGPL, version 2.1 or later.
9 * See the COPYING file in the top-level directory.
10 */
11
12#include <string.h>
13#include "gpu.h"
14#include "cspace.h"
15#include "../../frontend/plugin_lib.h"
16
17static const struct rearmed_cbs *cbs;
18static void *screen_buf;
19
20int vout_init(void)
21{
22 return 0;
23}
24
25int vout_finish(void)
26{
27 return 0;
28}
29
30static void check_mode_change(void)
31{
32 static uint32_t old_status;
33 static int old_h;
34 int w = gpu.screen.hres;
35 int h = gpu.screen.h;
36
37 gpu.state.enhancement_active =
38 gpu.get_enhancement_bufer != NULL && gpu.state.enhancement_enable
39 && w <= 512 && h <= 256 && !gpu.status.rgb24;
40
41 if (gpu.state.enhancement_active) {
42 w *= 2;
43 h *= 2;
44 }
45
46 // width|rgb24 change?
47 if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || h != old_h)
48 {
49 old_status = gpu.status.reg;
50 old_h = h;
51
52 screen_buf = cbs->pl_vout_set_mode(w, h,
53 (gpu.status.rgb24 && !cbs->only_16bpp) ? 24 : 16);
54 }
55}
56
57static void blit(void)
58{
59 int x = gpu.screen.x & ~1; // alignment needed by blitter
60 int y = gpu.screen.y;
61 int w = gpu.screen.w;
62 int h = gpu.screen.h;
63 uint16_t *vram = gpu.vram;
64 int stride = gpu.screen.hres;
65 int vram_stride = 1024;
66 int vram_mask = 1024 * 512 - 1;
67 int fb_offs, doffs;
68 uint8_t *dest;
69
70 dest = (uint8_t *)screen_buf;
71 if (dest == NULL || w == 0 || stride == 0)
72 return;
73
74 if (gpu.state.enhancement_active)
75 vram = gpu.get_enhancement_bufer(&x, &y, &w, &h, &stride, &vram_mask);
76
77 fb_offs = y * vram_stride + x;
78
79 // only do centering, at least for now
80 doffs = (stride - w) / 2 & ~1;
81
82 if (gpu.status.rgb24)
83 {
84 if (cbs->only_16bpp) {
85 dest += doffs * 2;
86 for (; h-- > 0; dest += stride * 2, fb_offs += vram_stride)
87 {
88 fb_offs &= vram_mask;
89 bgr888_to_rgb565(dest, vram + fb_offs, w * 3);
90 }
91 }
92 else {
93 dest += (doffs / 8) * 24;
94 for (; h-- > 0; dest += stride * 3, fb_offs += vram_stride)
95 {
96 fb_offs &= vram_mask;
97 bgr888_to_rgb888(dest, vram + fb_offs, w * 3);
98 }
99 }
100 }
101 else
102 {
103 dest += doffs * 2;
104 for (; h-- > 0; dest += stride * 2, fb_offs += vram_stride)
105 {
106 fb_offs &= vram_mask;
107 bgr555_to_rgb565(dest, vram + fb_offs, w * 2);
108 }
109 }
110
111 screen_buf = cbs->pl_vout_flip();
112}
113
114void vout_update(void)
115{
116 check_mode_change();
117 if (cbs->pl_vout_raw_flip)
118 cbs->pl_vout_raw_flip(gpu.screen.x, gpu.screen.y);
119 else
120 blit();
121}
122
123void vout_blank(void)
124{
125 if (cbs->pl_vout_raw_flip == NULL) {
126 int w = gpu.screen.hres;
127 int h = gpu.screen.h;
128 int bytespp = gpu.status.rgb24 ? 3 : 2;
129 if (gpu.state.enhancement_active) {
130 w *= 2;
131 h *= 2;
132 }
133 memset(screen_buf, 0, w * h * bytespp);
134 screen_buf = cbs->pl_vout_flip();
135 }
136}
137
138long GPUopen(void **unused)
139{
140 gpu.frameskip.active = 0;
141 gpu.frameskip.frame_ready = 1;
142
143 cbs->pl_vout_open();
144 screen_buf = cbs->pl_vout_flip();
145 return 0;
146}
147
148long GPUclose(void)
149{
150 cbs->pl_vout_close();
151 return 0;
152}
153
154void vout_set_config(const struct rearmed_cbs *cbs_)
155{
156 cbs = cbs_;
157}
158
159// vim:shiftwidth=2:expandtab