| 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 "gpu.h" |
| 13 | #include "cspace.h" |
| 14 | #include "../../frontend/plugin_lib.h" |
| 15 | |
| 16 | static const struct rearmed_cbs *cbs; |
| 17 | static void *screen_buf; |
| 18 | |
| 19 | int vout_init(void) |
| 20 | { |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | int vout_finish(void) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | static void check_mode_change(void) |
| 30 | { |
| 31 | static uint32_t old_status; |
| 32 | static int old_h; |
| 33 | |
| 34 | // width|rgb24 change? |
| 35 | if ((gpu.status.reg ^ old_status) & ((7<<16)|(1<<21)) || gpu.screen.h != old_h) |
| 36 | { |
| 37 | old_status = gpu.status.reg; |
| 38 | old_h = gpu.screen.h; |
| 39 | screen_buf = cbs->pl_vout_set_mode(gpu.screen.hres, |
| 40 | gpu.screen.h, gpu.status.rgb24 ? 24 : 16); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | static void blit(void) |
| 45 | { |
| 46 | int x = gpu.screen.x & ~1; // alignment needed by blitter |
| 47 | int y = gpu.screen.y; |
| 48 | int w = gpu.screen.w; |
| 49 | int h = gpu.screen.h; |
| 50 | uint16_t *vram = gpu.vram; |
| 51 | int stride = gpu.screen.hres; |
| 52 | int fb_offs, doffs; |
| 53 | uint8_t *dest; |
| 54 | |
| 55 | fb_offs = y * 1024 + x; |
| 56 | dest = (uint8_t *)screen_buf; |
| 57 | |
| 58 | // only do centering, at least for now |
| 59 | doffs = (stride - w) / 2 & ~1; |
| 60 | |
| 61 | if (gpu.status.rgb24) |
| 62 | { |
| 63 | #ifndef MAEMO |
| 64 | dest += (doffs / 8) * 24; |
| 65 | for (; h-- > 0; dest += stride * 3, fb_offs += 1024) |
| 66 | { |
| 67 | fb_offs &= 1024*512-1; |
| 68 | bgr888_to_rgb888(dest, vram + fb_offs, w * 3); |
| 69 | } |
| 70 | #else |
| 71 | dest += doffs * 2; |
| 72 | for (; h-- > 0; dest += stride * 2, fb_offs += 1024) |
| 73 | { |
| 74 | fb_offs &= 1024*512-1; |
| 75 | bgr888_to_rgb565(dest, vram + fb_offs, w * 3); |
| 76 | } |
| 77 | #endif |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | dest += doffs * 2; |
| 82 | for (; h-- > 0; dest += stride * 2, fb_offs += 1024) |
| 83 | { |
| 84 | fb_offs &= 1024*512-1; |
| 85 | bgr555_to_rgb565(dest, vram + fb_offs, w * 2); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | screen_buf = cbs->pl_vout_flip(); |
| 90 | } |
| 91 | |
| 92 | void vout_update(void) |
| 93 | { |
| 94 | check_mode_change(); |
| 95 | if (cbs->pl_vout_raw_flip) |
| 96 | cbs->pl_vout_raw_flip(gpu.screen.x, gpu.screen.y); |
| 97 | else |
| 98 | blit(); |
| 99 | } |
| 100 | |
| 101 | long GPUopen(void **unused) |
| 102 | { |
| 103 | gpu.frameskip.active = 0; |
| 104 | gpu.frameskip.frame_ready = 1; |
| 105 | |
| 106 | cbs->pl_vout_open(); |
| 107 | screen_buf = cbs->pl_vout_flip(); |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | long GPUclose(void) |
| 112 | { |
| 113 | cbs->pl_vout_close(); |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | void vout_set_config(const struct rearmed_cbs *cbs_) |
| 118 | { |
| 119 | cbs = cbs_; |
| 120 | } |
| 121 | |
| 122 | // vim:shiftwidth=2:expandtab |