| 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 | |
| 17 | static const struct rearmed_cbs *cbs; |
| 18 | static void *screen_buf; |
| 19 | |
| 20 | int vout_init(void) |
| 21 | { |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | int vout_finish(void) |
| 26 | { |
| 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | static 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.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 | |
| 57 | static 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 | // this layout is gpu_neon specific.. |
| 76 | vram = gpu.enhancement_bufer + |
| 77 | (x + 8) / stride * 1024 * 1024; |
| 78 | x *= 2; |
| 79 | y *= 2; |
| 80 | w = w * 2; |
| 81 | h = h * 2; |
| 82 | stride *= 2; |
| 83 | vram_mask = 1024 * 1024 - 1; |
| 84 | } |
| 85 | fb_offs = y * vram_stride + x; |
| 86 | |
| 87 | // only do centering, at least for now |
| 88 | doffs = (stride - w) / 2 & ~1; |
| 89 | |
| 90 | if (gpu.status.rgb24) |
| 91 | { |
| 92 | if (cbs->only_16bpp) { |
| 93 | dest += doffs * 2; |
| 94 | for (; h-- > 0; dest += stride * 2, fb_offs += vram_stride) |
| 95 | { |
| 96 | fb_offs &= vram_mask; |
| 97 | bgr888_to_rgb565(dest, vram + fb_offs, w * 3); |
| 98 | } |
| 99 | } |
| 100 | else { |
| 101 | dest += (doffs / 8) * 24; |
| 102 | for (; h-- > 0; dest += stride * 3, fb_offs += vram_stride) |
| 103 | { |
| 104 | fb_offs &= vram_mask; |
| 105 | bgr888_to_rgb888(dest, vram + fb_offs, w * 3); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | dest += doffs * 2; |
| 112 | for (; h-- > 0; dest += stride * 2, fb_offs += vram_stride) |
| 113 | { |
| 114 | fb_offs &= vram_mask; |
| 115 | bgr555_to_rgb565(dest, vram + fb_offs, w * 2); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | screen_buf = cbs->pl_vout_flip(); |
| 120 | } |
| 121 | |
| 122 | void vout_update(void) |
| 123 | { |
| 124 | check_mode_change(); |
| 125 | if (cbs->pl_vout_raw_flip) |
| 126 | cbs->pl_vout_raw_flip(gpu.screen.x, gpu.screen.y); |
| 127 | else |
| 128 | blit(); |
| 129 | } |
| 130 | |
| 131 | void vout_blank(void) |
| 132 | { |
| 133 | if (cbs->pl_vout_raw_flip == NULL) { |
| 134 | int w = gpu.screen.hres; |
| 135 | int h = gpu.screen.h; |
| 136 | int bytespp = gpu.status.rgb24 ? 3 : 2; |
| 137 | if (gpu.state.enhancement_active) { |
| 138 | w *= 2; |
| 139 | h *= 2; |
| 140 | } |
| 141 | memset(screen_buf, 0, w * h * bytespp); |
| 142 | screen_buf = cbs->pl_vout_flip(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | long GPUopen(void **unused) |
| 147 | { |
| 148 | gpu.frameskip.active = 0; |
| 149 | gpu.frameskip.frame_ready = 1; |
| 150 | |
| 151 | cbs->pl_vout_open(); |
| 152 | screen_buf = cbs->pl_vout_flip(); |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | long GPUclose(void) |
| 157 | { |
| 158 | cbs->pl_vout_close(); |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | void vout_set_config(const struct rearmed_cbs *cbs_) |
| 163 | { |
| 164 | cbs = cbs_; |
| 165 | } |
| 166 | |
| 167 | // vim:shiftwidth=2:expandtab |