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