trunk/src/osd/sdl/blit13.h
| r243238 | r243239 | |
| 5 | 5 | // INLINE |
| 6 | 6 | //============================================================ |
| 7 | 7 | |
| 8 | | inline UINT32 premult32(const UINT32 pixel) |
| 8 | INLINE UINT32 premult32(UINT32 pixel) |
| 9 | 9 | { |
| 10 | | const UINT16 a = (pixel >> 24) & 0xff; |
| 11 | | const UINT16 r = (pixel >> 16) & 0xff; |
| 12 | | const UINT16 g = (pixel >> 8) & 0xff; |
| 13 | | const UINT16 b = (pixel >> 0) & 0xff; |
| 10 | UINT8 a = (pixel >> 24) & 0xff; |
| 11 | UINT8 r = (pixel >> 16) & 0xff; |
| 12 | UINT8 g = (pixel >> 8) & 0xff; |
| 13 | UINT8 b = (pixel >> 0) & 0xff; |
| 14 | 14 | |
| 15 | 15 | return 0xFF000000 | |
| 16 | | ((r * a) / 255) << 16 | |
| 17 | | ((g * a) / 255) << 8 | |
| 18 | | ((b * a) / 255); |
| 16 | (((UINT16)r * (UINT16)a) / 255) << 16 | |
| 17 | (((UINT16)g * (UINT16)a) / 255) << 8 | |
| 18 | (((UINT16)b * (UINT16)a) / 255); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | | inline UINT32 CLUL(const UINT32 x) |
| 22 | | { |
| 23 | | return ((INT32) x < 0) ? 0 : ((x > 65535) ? 255 : x >> 8); |
| 24 | | } |
| 21 | #define CLUL(x) ((int) (x) < 0 ? 0 : ((x) > 65535 ? 255 : (x)>>8)) |
| 25 | 22 | |
| 26 | | inline UINT32 ycc_to_rgb(const UINT8 y, const UINT8 cb, const UINT8 cr) |
| 23 | INLINE UINT32 ycc_to_rgb(UINT8 y, UINT8 cb, UINT8 cr) |
| 27 | 24 | { |
| 28 | | const UINT32 common = 298 * y - 56992; |
| 29 | | const UINT32 r = (common + 409 * cr); |
| 30 | | const UINT32 g = (common - 100 * cb - 208 * cr + 91776); |
| 31 | | const UINT32 b = (common + 516 * cb - 13696); |
| 25 | unsigned int r, g, b, common; |
| 32 | 26 | |
| 27 | common = 298 * y - 56992; |
| 28 | r = (common + 409 * cr); |
| 29 | g = (common - 100 * cb - 208 * cr + 91776); |
| 30 | b = (common + 516 * cb - 13696); |
| 31 | |
| 33 | 32 | return 0xff000000 | (CLUL(r)<<16) | (CLUL(g)<<8) | (CLUL(b)); |
| 34 | 33 | } |
| 35 | 34 | |
| 36 | | inline UINT32 pixel_ycc_to_rgb(const UINT16 *pixel) |
| 35 | INLINE UINT32 pixel_ycc_to_rgb(UINT16 *pixel) |
| 37 | 36 | { |
| 38 | | |
| 39 | | const UINT32 p = *(UINT32 *)((FPTR) pixel & ~3); |
| 37 | UINT32 p = *(UINT32 *)((FPTR) pixel & ~1); |
| 40 | 38 | return ycc_to_rgb((*pixel >> 8) & 0xff, (p) & 0xff, (p>>16) & 0xff); |
| 41 | 39 | } |
| 42 | 40 | |
| 43 | | inline UINT32 pixel_ycc_to_rgb_pal(const UINT16 *pixel, const rgb_t *palette) |
| 41 | INLINE UINT32 pixel_ycc_to_rgb_pal(UINT16 *pixel, const rgb_t *palette) |
| 44 | 42 | { |
| 45 | | const UINT32 p = *(UINT32 *)((FPTR) pixel & ~3); |
| 43 | UINT32 p = *(UINT32 *)((FPTR) pixel & ~1); |
| 46 | 44 | return ycc_to_rgb(palette[(*pixel >> 8) & 0xff], (p) & 0xff, (p>>16) & 0xff); |
| 47 | 45 | } |
| 48 | 46 | |
| r243238 | r243239 | |
| 50 | 48 | // Pixel conversions |
| 51 | 49 | //============================================================ |
| 52 | 50 | |
| 51 | #define OP_ARGB32_ARGB32(_src) (_src) |
| 53 | 52 | |
| 54 | | #define FUNC_DEF(source) op(const source &src, const rgb_t *palbase) const |
| 55 | | #define FUNCTOR(name, x...) \ |
| 56 | | template<typename _source, typename _dest> \ |
| 57 | | struct name { _dest FUNC_DEF(_source) { x } }; |
| 53 | #define OP_RGB32_ARGB32(_src) ((_src) | 0xff000000) |
| 58 | 54 | |
| 59 | | FUNCTOR(op_argb32_argb32, return src; ) |
| 60 | | FUNCTOR(op_rgb32_argb32, return src | 0xff000000; ) |
| 61 | | FUNCTOR(op_pal16_argb32, return 0xff000000 |palbase[src]; ) |
| 62 | | FUNCTOR(op_pal16_rgb32, return palbase[src]; ) |
| 63 | | FUNCTOR(op_rgb32pal_argb32, |
| 64 | | return palbase[0x200 + (((src) >> 16) & 0xff) ] | |
| 65 | | palbase[0x100 + (((src) >> 8) & 0xff) ] | |
| 66 | | palbase[((src) & 0xff) ] | 0xff000000; ) |
| 55 | #define OP_RGB32PAL_ARGB32(_src) \ |
| 56 | (palbase[0x200 + (((_src) >> 16) & 0xff) ] | \ |
| 57 | palbase[0x100 + (((_src) >> 8) & 0xff) ] | \ |
| 58 | palbase[((_src) & 0xff) ] | 0xff000000) |
| 67 | 59 | |
| 68 | | FUNCTOR(op_pal16a_argb32, return palbase[src]; ) |
| 60 | #define OP_PAL16_ARGB32(_src) (0xff000000 | palbase[_src]) |
| 69 | 61 | |
| 70 | | FUNCTOR(op_rgb15_argb32, |
| 71 | | return 0xff000000 | ((src & 0x7c00) << 9) | ((src & 0x03e0) << 6) |
| 72 | | | ((src & 0x001f) << 3) | ((((src & 0x7c00) << 9) |
| 73 | | | ((src & 0x03e0) << 6) | ((src & 0x001f) << 3) >> 5) & 0x070707); ) |
| 62 | #define OP_PAL16A_ARGB32(_src) (palbase[_src]) |
| 74 | 63 | |
| 75 | | FUNCTOR(op_rgb15pal_argb32, |
| 76 | | return 0xff000000 | palbase[0x40 + ((src >> 10) & 0x1f)] | |
| 77 | | palbase[0x20 + ((src >> 5) & 0x1f)] | palbase[0x00 + ((src >> 0) & 0x1f)]; ) |
| 64 | #define OP_RGB15_ARGB32(_src) (0xff000000 | ((_src & 0x7c00) << 9) | ((_src & 0x03e0) << 6) | ((_src & 0x001f) << 3) | \ |
| 65 | ((((_src & 0x7c00) << 9) | ((_src & 0x03e0) << 6) | ((_src & 0x001f) << 3) >> 5) & 0x070707)) |
| 78 | 66 | |
| 79 | | FUNCTOR(op_argb32_rgb32, return premult32(src); ) |
| 80 | | FUNCTOR(op_pal16a_rgb32, return premult32(palbase[src]); ) |
| 81 | | FUNCTOR(op_pal16_argb1555, |
| 82 | | return (palbase[src]&0xf80000) >> 9 | |
| 83 | | (palbase[src]&0x00f800) >> 6 | |
| 84 | | (palbase[src]&0x0000f8) >> 3 | 0x8000; ) |
| 67 | #define OP_RGB15PAL_ARGB32(_src) (0xff000000 | palbase[0x40 + ((_src >> 10) & 0x1f)] | \ |
| 68 | palbase[0x20 + ((_src >> 5) & 0x1f)] | palbase[0x00 + ((_src >> 0) & 0x1f)]) |
| 85 | 69 | |
| 86 | | FUNCTOR(op_rgb15_argb1555, return src | 0x8000; ) |
| 70 | #define OP_ARGB32_RGB32(_pixel) premult32(_pixel) |
| 87 | 71 | |
| 88 | | FUNCTOR(op_rgb15pal_argb1555, |
| 89 | | return (palbase[src >> 10] & 0xf8) << 7 | |
| 90 | | (palbase[(src >> 5) & 0x1f] & 0xf8) << 2 | |
| 91 | | (palbase[src & 0x1f] & 0xf8) >> 3 | 0x8000; ) |
| 72 | #define OP_PAL16A_RGB32(_src) premult32(palbase[_src]) |
| 92 | 73 | |
| 93 | | FUNCTOR(op_yuv16_uyvy, return src; ) |
| 94 | | FUNCTOR(op_yuv16pal_uyvy, return (palbase[(src >> 8) & 0xff] << 8) | (src & 0x00ff); ) |
| 74 | #define OP_PAL16_ARGB1555(_src) ((palbase[_src]&0xf80000) >> 9 | \ |
| 75 | (palbase[_src]&0x00f800) >> 6 | \ |
| 76 | (palbase[_src]&0x0000f8) >> 3 | 0x8000) |
| 95 | 77 | |
| 96 | | // FIXME: wrong ... see non_pal version |
| 97 | | FUNCTOR(op_yuv16pal_yvyu, return (palbase[(src >> 8) & 0xff] & 0xff) | ((src & 0xff) << 8); ) |
| 98 | | FUNCTOR(op_yuv16_yvyu, return ((src & 0xff00ff00) >> 8 ) | (src << 24) | ((src >> 8) & 0x00ff00); ) |
| 78 | #define OP_RGB15_ARGB1555(_src) ((_src) | 0x8000) |
| 99 | 79 | |
| 100 | | FUNCTOR(op_yuv16_yuy2, return ((src & 0xff00ff00) >> 8) | ((src & 0x00ff00ff) << 8); ) |
| 80 | #define OP_RGB15PAL_ARGB1555(_src) ((palbase[(_src) >> 10] & 0xf8) << 7 | \ |
| 81 | (palbase[((_src) >> 5) & 0x1f] & 0xf8) << 2 | \ |
| 82 | (palbase[(_src) & 0x1f] & 0xf8) >> 3 | 0x8000) |
| 101 | 83 | |
| 102 | | FUNCTOR(op_yuv16pal_yuy2, |
| 103 | | return (palbase[(src>>8) & 0xff]) | |
| 104 | | (palbase[(src>>24) & 0xff]<<16) | |
| 105 | | ((src<<8)&0xff00ff00);) |
| 84 | #define OP_YUV16_UYVY(_src) (_src) |
| 106 | 85 | |
| 107 | | FUNCTOR(op_yuv16_argb32, |
| 108 | | return (UINT64) ycc_to_rgb((src >> 8) & 0xff, src & 0xff , (src>>16) & 0xff) |
| 109 | | | ((UINT64)ycc_to_rgb((src >> 24) & 0xff, src & 0xff , (src>>16) & 0xff) << 32); ) |
| 86 | #define OP_YUV16PAL_UYVY(_src) ((palbase[((_src) >> 8) & 0xff] << 8) | ((_src) & 0x00ff)) |
| 110 | 87 | |
| 111 | | FUNCTOR(op_yuv16pal_argb32, |
| 112 | | return (UINT64)ycc_to_rgb(palbase[(src >> 8) & 0xff], src & 0xff , (src>>16) & 0xff) |
| 113 | | | ((UINT64)ycc_to_rgb(palbase[(src >> 24) & 0xff], src & 0xff , (src>>16) & 0xff) << 32);) |
| 88 | #define OP_YUV16PAL_YVYU(_src) ((palbase[((_src) >> 8) & 0xff] & 0xff) | ((_src & 0xff) << 8)) |
| 114 | 89 | |
| 115 | | FUNCTOR(op_yuv16_argb32rot, return pixel_ycc_to_rgb(&src) ; ) |
| 90 | #define OP_YUV16_YVYU(_src) ((((_src) >> 8) & 0xff) | ((_src & 0xff) << 8)) |
| 116 | 91 | |
| 117 | | FUNCTOR(op_yuv16pal_argb32rot, return pixel_ycc_to_rgb_pal(&src, palbase); ) |
| 92 | #define OP_YUV16_YUY2(_src) ( ((_src) & 0xff00ff00) | \ |
| 93 | (((_src)>>16)&0xff) | (((_src)<<16)&0xff0000) ) |
| 118 | 94 | |
| 119 | | //============================================================ |
| 120 | | // Copy and rotation |
| 121 | | //============================================================ |
| 95 | #define OP_YUV16PAL_YUY2(_src) ( (palbase[((_src)>>8) & 0xff]) | \ |
| 96 | (palbase[((_src)>>24) & 0xff]<<16) | \ |
| 97 | (((_src)<<8)&0xff00ff00) ) |
| 122 | 98 | |
| 123 | | struct blit_base { |
| 99 | #define OP_YUV16_ARGB32(_src) \ |
| 100 | (UINT64) ycc_to_rgb(((_src) >> 8) & 0xff, (_src) & 0xff , ((_src)>>16) & 0xff) \ |
| 101 | | ((UINT64)ycc_to_rgb(((_src) >> 24) & 0xff, (_src) & 0xff , ((_src)>>16) & 0xff) << 32) |
| 124 | 102 | |
| 125 | | blit_base(int dest_bpp, bool is_rot, bool is_passthrough) |
| 126 | | : m_dest_bpp(dest_bpp), m_is_rot(is_rot), m_is_passthrough(is_passthrough) |
| 127 | | { } |
| 128 | | virtual ~blit_base() { } |
| 103 | #define OP_YUV16PAL_ARGB32(_src) \ |
| 104 | (UINT64)ycc_to_rgb(palbase[((_src) >> 8) & 0xff], (_src) & 0xff , ((_src)>>16) & 0xff) \ |
| 105 | | ((UINT64)ycc_to_rgb(palbase[((_src) >> 24) & 0xff], (_src) & 0xff , ((_src)>>16) & 0xff) << 32) |
| 129 | 106 | |
| 130 | | virtual void texop(const texture_info *texture, const render_texinfo *texsource) const = 0; |
| 131 | | int m_dest_bpp; |
| 132 | | bool m_is_rot; |
| 133 | | bool m_is_passthrough; |
| 134 | | }; |
| 107 | #define OP_YUV16_ARGB32ROT(_src) pixel_ycc_to_rgb(&(_src)) |
| 135 | 108 | |
| 136 | | template<typename _src_type, typename _dest_type, typename _op, int _len_div> |
| 137 | | struct blit_texcopy : public blit_base |
| 138 | | { |
| 139 | | blit_texcopy() : blit_base(sizeof(_dest_type) / _len_div, false, false) { } |
| 140 | | void texop(const texture_info *texture, const render_texinfo *texsource) const |
| 141 | | { |
| 142 | | ATTR_UNUSED const rgb_t *palbase = texsource->palette(); |
| 143 | | int x, y; |
| 144 | | /* loop over Y */ |
| 145 | | for (y = 0; y < texsource->height; y++) { |
| 146 | | _src_type *src = (_src_type *)texsource->base + y * texsource->rowpixels / (_len_div); |
| 147 | | _dest_type *dst = (_dest_type *)((UINT8 *)texture->m_pixels + y * texture->m_pitch); |
| 148 | | x = texsource->width / (_len_div); |
| 149 | | while (x > 0) { |
| 150 | | *dst++ = m_op.op(*src, palbase); |
| 151 | | src++; |
| 152 | | x--; |
| 153 | | } |
| 154 | | } |
| 155 | | } |
| 156 | | private: |
| 157 | | _op m_op; |
| 158 | | }; |
| 109 | #define OP_YUV16PAL_ARGB32ROT(_src) pixel_ycc_to_rgb_pal(&(_src), palbase) |
| 159 | 110 | |
| 160 | | #define TEXCOPYA(a, b, c, d) \ |
| 161 | | const struct blit_texcopy<b, c, op_ ## a <b, c>, d> texcopy_ ## a; |
| 111 | //============================================================ |
| 112 | // Copy and rotation |
| 113 | //============================================================ |
| 162 | 114 | |
| 163 | | template<typename _src_type, typename _dest_type, typename _op> |
| 164 | | struct blit_texrot : public blit_base |
| 165 | | { |
| 166 | | blit_texrot() : blit_base(sizeof(_dest_type), true, false) { } |
| 167 | | void texop(const texture_info *texture, const render_texinfo *texsource) const |
| 168 | | { |
| 169 | | ATTR_UNUSED const rgb_t *palbase = texsource->palette(); |
| 170 | | int x, y; |
| 171 | | const quad_setup_data *setup = &texture->m_setup; |
| 172 | | int dudx = setup->dudx; |
| 173 | | int dvdx = setup->dvdx; |
| 174 | | /* loop over Y */ |
| 175 | | for (y = 0; y < setup->rotheight; y++) { |
| 176 | | INT32 curu = setup->startu + y * setup->dudy; |
| 177 | | INT32 curv = setup->startv + y * setup->dvdy; |
| 178 | | _dest_type *dst = (_dest_type *)((UINT8 *)texture->m_pixels + y * texture->m_pitch); |
| 179 | | x = setup->rotwidth; |
| 180 | | while (x>0) { |
| 181 | | _src_type *src = (_src_type *) texsource->base + (curv >> 16) * texsource->rowpixels + (curu >> 16); |
| 182 | | *dst++ = m_op.op(*src, palbase); |
| 183 | | curu += dudx; |
| 184 | | curv += dvdx; |
| 185 | | x--; |
| 186 | | } |
| 187 | | } |
| 188 | | } |
| 189 | | private: |
| 190 | | _op m_op; |
| 191 | | }; |
| 115 | #define TEXCOPY_M( _name, _src_type, _dest_type, _op, _len_div) \ |
| 116 | INLINE void texcopy_##_name (const texture_info *texture, const render_texinfo *texsource) { \ |
| 117 | ATTR_UNUSED const rgb_t *palbase = texsource->palette(); \ |
| 118 | int x, y; \ |
| 119 | /* loop over Y */ \ |
| 120 | for (y = 0; y < texsource->height; y++) { \ |
| 121 | _src_type *src = (_src_type *)texsource->base + y * texsource->rowpixels / (_len_div); \ |
| 122 | _dest_type *dst = (_dest_type *)((UINT8 *)texture->m_pixels + y * texture->m_pitch); \ |
| 123 | x = texsource->width / (_len_div); \ |
| 124 | while (x > 0) { \ |
| 125 | *dst++ = _op(*src); \ |
| 126 | src++; \ |
| 127 | x--; \ |
| 128 | } \ |
| 129 | } \ |
| 130 | } |
| 192 | 131 | |
| 193 | | #define TEXROTA(a, b, c) \ |
| 194 | | const struct blit_texrot<b, c, op_ ## a <b, c> > texcopy_rot_ ## a; |
| 132 | #define TEXCOPY( _name, _src_type, _dest_type, _op) \ |
| 133 | TEXCOPY_M( _name, _src_type, _dest_type, _op, 1) |
| 195 | 134 | |
| 196 | | template<typename _src_type, typename _dest_type> |
| 197 | | struct blit_texpass : public blit_base |
| 198 | | { |
| 199 | | blit_texpass() : blit_base(sizeof(_dest_type), false, true) { } |
| 200 | | void texop(const texture_info *texture, const render_texinfo *texsource) const |
| 201 | | { |
| 202 | | } |
| 203 | | }; |
| 135 | #define TEXROT( _name, _src_type, _dest_type, _op) \ |
| 136 | INLINE void texcopy_rot_##_name (const texture_info *texture, const render_texinfo *texsource) { \ |
| 137 | ATTR_UNUSED const rgb_t *palbase = texsource->palette(); \ |
| 138 | int x, y; \ |
| 139 | const quad_setup_data *setup = &texture->m_setup; \ |
| 140 | int dudx = setup->dudx; \ |
| 141 | int dvdx = setup->dvdx; \ |
| 142 | /* loop over Y */ \ |
| 143 | for (y = 0; y < setup->rotheight; y++) { \ |
| 144 | INT32 curu = setup->startu + y * setup->dudy; \ |
| 145 | INT32 curv = setup->startv + y * setup->dvdy; \ |
| 146 | _dest_type *dst = (_dest_type *)((UINT8 *)texture->m_pixels + y * texture->m_pitch); \ |
| 147 | x = setup->rotwidth; \ |
| 148 | while (x>0) { \ |
| 149 | _src_type *src = (_src_type *) texsource->base + (curv >> 16) * texsource->rowpixels + (curu >> 16); \ |
| 150 | *dst++ = _op(*src); \ |
| 151 | curu += dudx; \ |
| 152 | curv += dvdx; \ |
| 153 | x--; \ |
| 154 | } \ |
| 155 | } \ |
| 156 | } |
| 204 | 157 | |
| 205 | | #define TEXCOPYP(a, b, c) \ |
| 206 | | const struct blit_texpass<b, c> texcopy_ ## a; |
| 158 | //TEXCOPY(argb32_argb32, UINT32, UINT32, OP_ARGB32_ARGB32) |
| 207 | 159 | |
| 160 | TEXCOPY(rgb32_argb32, UINT32, UINT32, OP_RGB32_ARGB32) |
| 161 | TEXCOPY(rgb32pal_argb32, UINT32, UINT32, OP_RGB32PAL_ARGB32) |
| 162 | TEXCOPY(pal16_argb32, UINT16, UINT32, OP_PAL16_ARGB32) |
| 163 | TEXCOPY(pal16a_argb32, UINT16, UINT32, OP_PAL16A_ARGB32) |
| 164 | TEXCOPY(rgb15_argb32, UINT16, UINT32, OP_RGB15_ARGB32) |
| 165 | TEXCOPY(rgb15pal_argb32, UINT16, UINT32, OP_RGB15PAL_ARGB32) |
| 208 | 166 | |
| 209 | | TEXCOPYA(rgb32_argb32, UINT32, UINT32, 1) |
| 210 | | TEXCOPYP(rgb32_rgb32, UINT32, UINT32) |
| 167 | TEXCOPY(pal16_argb1555, UINT16, UINT16, OP_PAL16_ARGB1555) |
| 168 | TEXCOPY(rgb15_argb1555, UINT16, UINT16, OP_RGB15_ARGB1555) |
| 169 | TEXCOPY(rgb15pal_argb1555, UINT16, UINT16, OP_RGB15PAL_ARGB1555) |
| 211 | 170 | |
| 212 | | TEXCOPYA(rgb32pal_argb32, UINT32, UINT32, 1) |
| 213 | | TEXCOPYA(pal16_argb32, UINT16, UINT32, 1) |
| 214 | | TEXCOPYA(pal16a_argb32, UINT16, UINT32, 1) |
| 215 | | TEXCOPYA(rgb15_argb32, UINT16, UINT32, 1) |
| 216 | | TEXCOPYA(rgb15pal_argb32, UINT16, UINT32, 1) |
| 171 | TEXCOPY(argb32_rgb32, UINT32, UINT32, OP_ARGB32_RGB32) |
| 172 | TEXCOPY(pal16a_rgb32, UINT16, UINT32, OP_PAL16A_RGB32) |
| 217 | 173 | |
| 218 | | TEXCOPYA(pal16_argb1555, UINT16, UINT16, 1) |
| 219 | | TEXCOPYA(rgb15_argb1555, UINT16, UINT16, 1) |
| 220 | | TEXCOPYA(rgb15pal_argb1555, UINT16, UINT16, 1) |
| 174 | TEXCOPY_M(yuv16_argb32, UINT32, UINT64, OP_YUV16_ARGB32, 2) |
| 175 | TEXCOPY_M(yuv16pal_argb32, UINT32, UINT64, OP_YUV16PAL_ARGB32, 2) |
| 221 | 176 | |
| 222 | | TEXCOPYP(argb32_argb32, UINT32, UINT32) |
| 223 | | TEXCOPYA(argb32_rgb32, UINT32, UINT32, 1) |
| 224 | | TEXCOPYA(pal16a_rgb32, UINT16, UINT32, 1) |
| 177 | //TEXCOPY(yuv16_uyvy, UINT16, UINT16, OP_YUV16_UYVY) |
| 225 | 178 | |
| 226 | | TEXCOPYA(yuv16_argb32, UINT32, UINT64, 2) |
| 227 | | TEXCOPYA(yuv16pal_argb32, UINT32, UINT64, 2) |
| 179 | TEXCOPY(yuv16pal_uyvy, UINT16, UINT16, OP_YUV16PAL_UYVY) |
| 228 | 180 | |
| 229 | | TEXCOPYP(yuv16_uyvy, UINT16, UINT16) |
| 230 | | TEXCOPYP(rgb15_rgb555, UINT16, UINT16) |
| 181 | TEXCOPY(yuv16_yvyu, UINT16, UINT16, OP_YUV16_YVYU) |
| 182 | TEXCOPY(yuv16pal_yvyu, UINT16, UINT16, OP_YUV16PAL_YVYU) |
| 231 | 183 | |
| 232 | | TEXCOPYA(yuv16pal_uyvy, UINT16, UINT16, 1) |
| 184 | TEXCOPY_M(yuv16_yuy2, UINT32, UINT32, OP_YUV16_YUY2, 2) |
| 185 | TEXCOPY_M(yuv16pal_yuy2, UINT32, UINT32, OP_YUV16PAL_YUY2, 2) |
| 233 | 186 | |
| 234 | | TEXCOPYA(yuv16_yvyu, UINT32, UINT32, 2) |
| 235 | | TEXCOPYA(yuv16pal_yvyu, UINT16, UINT16, 1) |
| 236 | 187 | |
| 237 | | TEXCOPYA(yuv16_yuy2, UINT32, UINT32, 2) |
| 238 | | TEXCOPYA(yuv16pal_yuy2, UINT32, UINT32, 2) |
| 188 | TEXROT(argb32_argb32, UINT32, UINT32, OP_ARGB32_ARGB32) |
| 189 | TEXROT(rgb32_argb32, UINT32, UINT32, OP_RGB32_ARGB32) |
| 190 | TEXROT(rgb32pal_argb32, UINT32, UINT32, OP_RGB32PAL_ARGB32) |
| 191 | TEXROT(pal16_argb32, UINT16, UINT32, OP_PAL16_ARGB32) |
| 192 | TEXROT(pal16a_argb32, UINT16, UINT32, OP_PAL16A_ARGB32) |
| 193 | TEXROT(rgb15_argb32, UINT16, UINT32, OP_RGB15_ARGB32) |
| 194 | TEXROT(rgb15pal_argb32, UINT16, UINT32, OP_RGB15PAL_ARGB32) |
| 239 | 195 | |
| 196 | TEXROT(pal16_argb1555, UINT16, UINT16, OP_PAL16_ARGB1555) |
| 197 | TEXROT(rgb15_argb1555, UINT16, UINT16, OP_RGB15_ARGB1555) |
| 198 | TEXROT(rgb15pal_argb1555, UINT16, UINT16, OP_RGB15PAL_ARGB1555) |
| 240 | 199 | |
| 200 | TEXROT(argb32_rgb32, UINT32, UINT32, OP_ARGB32_RGB32) |
| 201 | TEXROT(pal16a_rgb32, UINT16, UINT32, OP_PAL16A_RGB32) |
| 241 | 202 | |
| 242 | | TEXROTA(argb32_argb32, UINT32, UINT32) |
| 243 | | TEXROTA(rgb32_argb32, UINT32, UINT32) |
| 244 | | TEXROTA(pal16_argb32, UINT16, UINT32) |
| 245 | | TEXROTA(pal16_rgb32, UINT16, UINT32) |
| 246 | | |
| 247 | | TEXROTA(rgb32pal_argb32, UINT32, UINT32) |
| 248 | | TEXROTA(pal16a_argb32, UINT16, UINT32) |
| 249 | | TEXROTA(rgb15_argb32, UINT16, UINT32) |
| 250 | | TEXROTA(rgb15pal_argb32, UINT16, UINT32) |
| 251 | | |
| 252 | | TEXROTA(pal16_argb1555, UINT16, UINT16) |
| 253 | | TEXROTA(rgb15_argb1555, UINT16, UINT16) |
| 254 | | TEXROTA(rgb15pal_argb1555, UINT16, UINT16) |
| 255 | | |
| 256 | | TEXROTA(argb32_rgb32, UINT32, UINT32) |
| 257 | | TEXROTA(pal16a_rgb32, UINT16, UINT32) |
| 258 | | |
| 259 | | TEXROTA(yuv16_argb32rot, UINT16, UINT32) |
| 260 | | TEXROTA(yuv16pal_argb32rot, UINT16, UINT32) |
| 203 | TEXROT(yuv16_argb32, UINT16, UINT32, OP_YUV16_ARGB32ROT) |
| 204 | TEXROT(yuv16pal_argb32, UINT16, UINT32, OP_YUV16PAL_ARGB32ROT) |
trunk/src/osd/sdl/draw13.c
| r243238 | r243239 | |
| 24 | 24 | #include "osdsdl.h" |
| 25 | 25 | #include "window.h" |
| 26 | 26 | |
| 27 | | |
| 28 | 27 | //============================================================ |
| 29 | 28 | // DEBUGGING |
| 30 | 29 | //============================================================ |
| r243238 | r243239 | |
| 49 | 48 | |
| 50 | 49 | static inline bool is_opaque(const float &a) |
| 51 | 50 | { |
| 52 | | return (a >= 1.0f); |
| 51 | return (a >= 1.0f); |
| 53 | 52 | } |
| 54 | 53 | |
| 55 | 54 | static inline bool is_transparent(const float &a) |
| 56 | 55 | { |
| 57 | | return (a < 0.0001f); |
| 56 | return (a < 0.0001f); |
| 58 | 57 | } |
| 59 | 58 | |
| 60 | 59 | //============================================================ |
| r243238 | r243239 | |
| 64 | 63 | |
| 65 | 64 | struct quad_setup_data |
| 66 | 65 | { |
| 67 | | quad_setup_data() |
| 68 | | : dudx(0), dvdx(0), dudy(0), dvdy(0), startu(0), startv(0), |
| 69 | | rotwidth(0), rotheight(0) |
| 70 | | {} |
| 71 | | void compute(const render_primitive &prim); |
| 66 | quad_setup_data() |
| 67 | : dudx(0), dvdx(0), dudy(0), dvdy(0), startu(0), startv(0), |
| 68 | rotwidth(0), rotheight(0) |
| 69 | {} |
| 70 | void compute(const render_primitive &prim); |
| 72 | 71 | |
| 73 | 72 | INT32 dudx, dvdx, dudy, dvdy; |
| 74 | 73 | INT32 startu, startv; |
| 75 | 74 | INT32 rotwidth, rotheight; |
| 76 | 75 | }; |
| 77 | 76 | |
| 77 | class texture_info; |
| 78 | |
| 79 | typedef void (*texture_copy_func)(const texture_info *texture, const render_texinfo *texsource); |
| 80 | |
| 81 | struct copy_info_t { |
| 82 | int src_fmt; |
| 83 | Uint32 dst_fmt; |
| 84 | int dst_bpp; |
| 85 | int rotate; |
| 86 | texture_copy_func func; |
| 87 | Uint32 bm_mask; |
| 88 | const char *srcname; |
| 89 | const char *dstname; |
| 90 | /* Statistics */ |
| 91 | UINT64 pixel_count; |
| 92 | INT64 time; |
| 93 | int samples; |
| 94 | int perf; |
| 95 | /* list */ |
| 96 | copy_info_t *next; |
| 97 | }; |
| 98 | |
| 78 | 99 | //============================================================ |
| 79 | 100 | // Textures |
| 80 | 101 | //============================================================ |
| 81 | 102 | |
| 82 | | struct sdl_info13; |
| 83 | | struct copy_info_t; |
| 103 | struct sdl_info; |
| 84 | 104 | |
| 85 | 105 | /* texture_info holds information about a texture */ |
| 86 | 106 | class texture_info |
| 87 | 107 | { |
| 88 | | friend class simple_list<texture_info>; |
| 108 | friend class simple_list<texture_info>; |
| 89 | 109 | public: |
| 90 | | texture_info(SDL_Renderer *renderer, const render_texinfo &texsource, const quad_setup_data &setup, const UINT32 flags); |
| 91 | | ~texture_info(); |
| 110 | texture_info(SDL_Renderer *renderer, const render_texinfo &texsource, const quad_setup_data &setup, const UINT32 flags); |
| 111 | ~texture_info(); |
| 92 | 112 | |
| 93 | | void set_data(const render_texinfo &texsource, const UINT32 flags); |
| 94 | | void render_quad(const render_primitive *prim, const int x, const int y); |
| 95 | | bool matches(const render_primitive &prim, const quad_setup_data &setup); |
| 113 | void set_data(const render_texinfo &texsource, const UINT32 flags); |
| 114 | void render_quad(const render_primitive *prim, const int x, const int y); |
| 115 | bool matches(const render_primitive &prim, const quad_setup_data &setup); |
| 96 | 116 | |
| 97 | | copy_info_t *compute_size_type(); |
| 117 | copy_info_t *compute_size_type(); |
| 98 | 118 | |
| 99 | 119 | void *m_pixels; // pixels for the texture |
| 100 | 120 | int m_pitch; |
| r243238 | r243239 | |
| 105 | 125 | osd_ticks_t m_last_access; |
| 106 | 126 | |
| 107 | 127 | int raw_width() const { return m_texinfo.width; } |
| 108 | | int raw_height() const { return m_texinfo.height; } |
| 128 | int raw_height() const { return m_texinfo.height; } |
| 109 | 129 | |
| 110 | | texture_info *next() { return m_next; } |
| 111 | | const render_texinfo &texinfo() const { return m_texinfo; } |
| 112 | | render_texinfo &texinfo() { return m_texinfo; } |
| 130 | texture_info *next() { return m_next; } |
| 131 | const render_texinfo &texinfo() const { return m_texinfo; } |
| 132 | render_texinfo &texinfo() { return m_texinfo; } |
| 113 | 133 | |
| 114 | | const HashT hash() const { return m_hash; } |
| 115 | | const UINT32 flags() const { return m_flags; } |
| 116 | | // FIXME: |
| 117 | | const bool is_pixels_owned() const; |
| 134 | const HashT hash() const { return m_hash; } |
| 135 | const UINT32 flags() const { return m_flags; } |
| 136 | const bool is_pixels_owned() const { // do we own / allocated it ? |
| 137 | return false && ((m_sdl_access == SDL_TEXTUREACCESS_STATIC) |
| 138 | && (m_copyinfo->func != NULL)) ; |
| 139 | } |
| 118 | 140 | |
| 119 | 141 | private: |
| 120 | | Uint32 m_sdl_access; |
| 121 | | SDL_Renderer * m_renderer; |
| 122 | | render_texinfo m_texinfo; // copy of the texture info |
| 123 | | HashT m_hash; // hash value for the texture (must be >= pointer size) |
| 124 | | UINT32 m_flags; // rendering flags |
| 142 | Uint32 m_sdl_access; |
| 143 | SDL_Renderer * m_renderer; |
| 144 | render_texinfo m_texinfo; // copy of the texture info |
| 145 | HashT m_hash; // hash value for the texture (must be >= pointer size) |
| 146 | UINT32 m_flags; // rendering flags |
| 125 | 147 | |
| 126 | | SDL_Texture * m_texture_id; |
| 127 | | bool m_is_rotated; |
| 148 | SDL_Texture * m_texture_id; |
| 149 | int m_is_rotated; |
| 128 | 150 | |
| 129 | | int m_format; // texture format |
| 130 | | SDL_BlendMode m_sdl_blendmode; |
| 151 | int m_format; // texture format |
| 152 | SDL_BlendMode m_sdl_blendmode; |
| 131 | 153 | |
| 132 | | texture_info * m_next; // next texture in the list |
| 154 | texture_info * m_next; // next texture in the list |
| 133 | 155 | }; |
| 134 | 156 | |
| 135 | | //============================================================ |
| 136 | | // TEXCOPY FUNCS |
| 137 | | //============================================================ |
| 138 | | |
| 139 | | #include "blit13.h" |
| 140 | | |
| 141 | 157 | /* sdl_info is the information about SDL for the current screen */ |
| 142 | | struct sdl_info13 |
| 158 | struct sdl_info |
| 143 | 159 | { |
| 144 | | sdl_info13() |
| 145 | | : m_blittimer(0), m_renderer(NULL), |
| 146 | | m_hofs(0), m_vofs(0), |
| 147 | | m_resize_pending(0), m_resize_width(0), m_resize_height(0), |
| 148 | | m_last_blit_time(0), m_last_blit_pixels(0) |
| 149 | | {} |
| 160 | sdl_info() |
| 161 | : m_blittimer(0), m_renderer(NULL), |
| 162 | m_hofs(0), m_vofs(0), |
| 163 | m_resize_pending(0), m_resize_width(0), m_resize_height(0), |
| 164 | m_last_blit_time(0), m_last_blit_pixels(0) |
| 165 | {} |
| 150 | 166 | |
| 151 | | void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); |
| 167 | void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); |
| 152 | 168 | |
| 153 | | texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); |
| 154 | | texture_info *texture_update(const render_primitive &prim); |
| 169 | texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); |
| 170 | texture_info *texture_update(const render_primitive &prim); |
| 155 | 171 | |
| 156 | 172 | INT32 m_blittimer; |
| 157 | 173 | |
| r243238 | r243239 | |
| 175 | 191 | SDL_DisplayMode m_original_mode; |
| 176 | 192 | }; |
| 177 | 193 | |
| 178 | | struct copy_info_t { |
| 179 | | int src_fmt; |
| 180 | | Uint32 dst_fmt; |
| 181 | | const blit_base *blitter; |
| 182 | | Uint32 bm_mask; |
| 183 | | const char *srcname; |
| 184 | | const char *dstname; |
| 185 | | /* Statistics */ |
| 186 | | UINT64 pixel_count; |
| 187 | | INT64 time; |
| 188 | | int samples; |
| 189 | | int perf; |
| 190 | | /* list */ |
| 191 | | copy_info_t *next; |
| 192 | | }; |
| 193 | | |
| 194 | 194 | //============================================================ |
| 195 | 195 | // PROTOTYPES |
| 196 | 196 | //============================================================ |
| r243238 | r243239 | |
| 209 | 209 | static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt); |
| 210 | 210 | |
| 211 | 211 | //============================================================ |
| 212 | // TEXCOPY FUNCS |
| 213 | //============================================================ |
| 214 | |
| 215 | #include "blit13.h" |
| 216 | |
| 217 | //============================================================ |
| 212 | 218 | // STATIC VARIABLES |
| 213 | 219 | //============================================================ |
| 214 | 220 | |
| r243238 | r243239 | |
| 216 | 222 | #define BM_ALL (-1) |
| 217 | 223 | //( SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD) |
| 218 | 224 | |
| 219 | | #define ENTRY(a,b,f) { SDL_TEXFORMAT_ ## a, SDL_PIXELFORMAT_ ## b, &texcopy_ ## f, BM_ALL, #a, #b, 0, 0, 0, 0} |
| 220 | | #define ENTRY_BM(a,b,f,bm) { SDL_TEXFORMAT_ ## a, SDL_PIXELFORMAT_ ## b, &texcopy_ ## f, bm, #a, #b, 0, 0, 0, 0} |
| 221 | | #define ENTRY_LR(a,b,f) { SDL_TEXFORMAT_ ## a, SDL_PIXELFORMAT_ ## b, &texcopy_ ## f, BM_ALL, #a, #b, 0, 0, 0, -1} |
| 225 | #define texcopy_NULL NULL |
| 226 | #define ENTRY(a,b,c,d,f) { SDL_TEXFORMAT_ ## a, SDL_PIXELFORMAT_ ## b, c, d, texcopy_ ## f, BM_ALL, #a, #b, 0, 0, 0, 0} |
| 227 | #define ENTRY_BM(a,b,c,d,f,bm) { SDL_TEXFORMAT_ ## a, SDL_PIXELFORMAT_ ## b, c, d, texcopy_ ## f, bm, #a, #b, 0, 0, 0, 0} |
| 228 | #define ENTRY_LR(a,b,c,d,f) { SDL_TEXFORMAT_ ## a, SDL_PIXELFORMAT_ ## b, c, d, texcopy_ ## f, BM_ALL, #a, #b, 0, 0, 0, -1} |
| 222 | 229 | |
| 223 | 230 | static copy_info_t blit_info_default[] = |
| 224 | 231 | { |
| 225 | 232 | /* no rotation */ |
| 226 | | ENTRY(ARGB32, ARGB8888, argb32_argb32), |
| 227 | | ENTRY_LR(ARGB32, RGB888, argb32_rgb32), |
| 233 | ENTRY(ARGB32, ARGB8888, 4, 0, NULL), |
| 234 | ENTRY_LR(ARGB32, RGB888, 4, 0, argb32_rgb32), |
| 228 | 235 | /* Entry primarily for directfb */ |
| 229 | | ENTRY_BM(ARGB32, RGB888, argb32_rgb32, SDL_BLENDMODE_ADD), |
| 230 | | ENTRY_BM(ARGB32, RGB888, argb32_rgb32, SDL_BLENDMODE_MOD), |
| 231 | | ENTRY_BM(ARGB32, RGB888, argb32_rgb32, SDL_BLENDMODE_NONE), |
| 236 | ENTRY_BM(ARGB32, RGB888, 4, 0, argb32_rgb32, SDL_BLENDMODE_ADD), |
| 237 | ENTRY_BM(ARGB32, RGB888, 4, 0, argb32_rgb32, SDL_BLENDMODE_MOD), |
| 238 | ENTRY_BM(ARGB32, RGB888, 4, 0, argb32_rgb32, SDL_BLENDMODE_NONE), |
| 232 | 239 | |
| 233 | | ENTRY(RGB32, ARGB8888, rgb32_argb32), |
| 234 | | ENTRY(RGB32, RGB888, rgb32_rgb32), |
| 240 | ENTRY(RGB32, ARGB8888, 4, 0, rgb32_argb32), |
| 241 | ENTRY(RGB32, RGB888, 4, 0, NULL), |
| 235 | 242 | |
| 236 | | ENTRY(RGB32_PALETTED, ARGB8888, rgb32pal_argb32), |
| 237 | | ENTRY(RGB32_PALETTED, RGB888, rgb32pal_argb32), |
| 243 | ENTRY(RGB32_PALETTED, ARGB8888, 4, 0, rgb32pal_argb32), |
| 244 | ENTRY(RGB32_PALETTED, RGB888, 4, 0, rgb32pal_argb32), |
| 238 | 245 | |
| 239 | | ENTRY(YUY16, UYVY, yuv16_uyvy), |
| 240 | | ENTRY(YUY16, YUY2, yuv16_yuy2), |
| 241 | | ENTRY(YUY16, YVYU, yuv16_yvyu), |
| 242 | | ENTRY(YUY16, ARGB8888, yuv16_argb32), |
| 243 | | ENTRY(YUY16, RGB888, yuv16_argb32), |
| 246 | ENTRY(YUY16, UYVY, 2, 0, NULL /* yuv16_uyvy*/), |
| 247 | ENTRY(YUY16, YUY2, 2, 0, yuv16_yuy2), |
| 248 | ENTRY(YUY16, YVYU, 2, 0, yuv16_yvyu), |
| 249 | ENTRY(YUY16, ARGB8888, 4, 0, yuv16_argb32), |
| 250 | ENTRY(YUY16, RGB888, 4, 0, yuv16_argb32), |
| 244 | 251 | |
| 245 | | ENTRY(YUY16_PALETTED, UYVY, yuv16pal_uyvy), |
| 246 | | ENTRY(YUY16_PALETTED, YUY2, yuv16pal_yuy2), |
| 247 | | ENTRY(YUY16_PALETTED, YVYU, yuv16pal_yvyu), |
| 248 | | ENTRY(YUY16_PALETTED, ARGB8888, yuv16pal_argb32), |
| 249 | | ENTRY(YUY16_PALETTED, RGB888, yuv16pal_argb32), |
| 252 | ENTRY(YUY16_PALETTED, UYVY, 2, 0, yuv16pal_uyvy), |
| 253 | ENTRY(YUY16_PALETTED, YUY2, 2, 0, yuv16pal_yuy2), |
| 254 | ENTRY(YUY16_PALETTED, YVYU, 2, 0, yuv16pal_yvyu), |
| 255 | ENTRY(YUY16_PALETTED, ARGB8888, 4, 0, yuv16pal_argb32), |
| 256 | ENTRY(YUY16_PALETTED, RGB888, 4, 0, yuv16pal_argb32), |
| 250 | 257 | |
| 251 | | ENTRY(PALETTE16, ARGB8888, pal16_argb32), |
| 252 | | ENTRY(PALETTE16, RGB888, pal16_argb32), |
| 258 | ENTRY(PALETTE16, ARGB8888, 4, 0, pal16_argb32), |
| 259 | ENTRY(PALETTE16, RGB888, 4, 0, pal16_argb32), |
| 253 | 260 | |
| 254 | | ENTRY(RGB15, RGB555, rgb15_rgb555), |
| 255 | | ENTRY(RGB15, ARGB1555, rgb15_argb1555), |
| 256 | | ENTRY(RGB15, ARGB8888, rgb15_argb32), |
| 257 | | ENTRY(RGB15, RGB888, rgb15_argb32), |
| 261 | ENTRY(RGB15, RGB555, 2, 0, NULL /* rgb15_argb1555 */), |
| 262 | ENTRY(RGB15, ARGB1555, 2, 0, rgb15_argb1555), |
| 263 | ENTRY(RGB15, ARGB8888, 4, 0, rgb15_argb32), |
| 264 | ENTRY(RGB15, RGB888, 4, 0, rgb15_argb32), |
| 258 | 265 | |
| 259 | | ENTRY(RGB15_PALETTED, ARGB8888, rgb15pal_argb32), |
| 260 | | ENTRY(RGB15_PALETTED, RGB888, rgb15pal_argb32), |
| 266 | ENTRY(RGB15_PALETTED, ARGB8888, 4, 0, rgb15pal_argb32), |
| 267 | ENTRY(RGB15_PALETTED, RGB888, 4, 0, rgb15pal_argb32), |
| 261 | 268 | |
| 262 | | ENTRY(PALETTE16A, ARGB8888, pal16a_argb32), |
| 263 | | ENTRY(PALETTE16A, RGB888, pal16a_rgb32), |
| 269 | ENTRY(PALETTE16A, ARGB8888, 4, 0, pal16a_argb32), |
| 270 | ENTRY(PALETTE16A, RGB888, 4, 0, pal16a_rgb32), |
| 264 | 271 | |
| 265 | 272 | /* rotation */ |
| 266 | | ENTRY(ARGB32, ARGB8888, rot_argb32_argb32), |
| 267 | | ENTRY_LR(ARGB32, RGB888, rot_argb32_rgb32), |
| 273 | ENTRY(ARGB32, ARGB8888, 4, 1, rot_argb32_argb32), |
| 274 | ENTRY_LR(ARGB32, RGB888, 4, 1, rot_argb32_rgb32), |
| 268 | 275 | /* Entry primarily for directfb */ |
| 269 | | ENTRY_BM(ARGB32, RGB888, rot_argb32_rgb32, SDL_BLENDMODE_ADD), |
| 270 | | ENTRY_BM(ARGB32, RGB888, rot_argb32_rgb32, SDL_BLENDMODE_MOD), |
| 271 | | ENTRY_BM(ARGB32, RGB888, rot_argb32_rgb32, SDL_BLENDMODE_NONE), |
| 276 | ENTRY_BM(ARGB32, RGB888, 4, 1, rot_argb32_rgb32, SDL_BLENDMODE_ADD), |
| 277 | ENTRY_BM(ARGB32, RGB888, 4, 1, rot_argb32_rgb32, SDL_BLENDMODE_MOD), |
| 278 | ENTRY_BM(ARGB32, RGB888, 4, 1, rot_argb32_rgb32, SDL_BLENDMODE_NONE), |
| 272 | 279 | |
| 273 | | ENTRY(RGB32, ARGB8888, rot_rgb32_argb32), |
| 274 | | ENTRY(RGB32, RGB888, rot_argb32_argb32), |
| 280 | ENTRY(RGB32, ARGB8888, 4, 1, rot_rgb32_argb32), |
| 281 | ENTRY(RGB32, RGB888, 4, 1, rot_argb32_argb32), |
| 275 | 282 | |
| 276 | | ENTRY(RGB32_PALETTED, ARGB8888, rot_rgb32pal_argb32), |
| 277 | | ENTRY(RGB32_PALETTED, RGB888, rot_rgb32pal_argb32), |
| 283 | ENTRY(RGB32_PALETTED, ARGB8888, 4, 1, rot_rgb32pal_argb32), |
| 284 | ENTRY(RGB32_PALETTED, RGB888, 4, 1, rot_rgb32pal_argb32), |
| 278 | 285 | |
| 279 | | ENTRY(YUY16, ARGB8888, rot_yuv16_argb32rot), |
| 280 | | ENTRY(YUY16, RGB888, rot_yuv16_argb32rot), |
| 286 | ENTRY(YUY16, ARGB8888, 4, 1, rot_yuv16_argb32), |
| 287 | ENTRY(YUY16, RGB888, 4, 1, rot_yuv16_argb32), |
| 281 | 288 | |
| 282 | | ENTRY(YUY16_PALETTED, ARGB8888, rot_yuv16pal_argb32rot), |
| 283 | | ENTRY(YUY16_PALETTED, RGB888, rot_yuv16pal_argb32rot), |
| 289 | ENTRY(YUY16_PALETTED, ARGB8888, 4, 1, rot_yuv16pal_argb32), |
| 290 | ENTRY(YUY16_PALETTED, RGB888, 4, 1, rot_yuv16pal_argb32), |
| 284 | 291 | |
| 285 | | ENTRY(PALETTE16, ARGB8888, rot_pal16_argb32), |
| 286 | | ENTRY(PALETTE16, RGB888, rot_pal16_argb32), |
| 292 | ENTRY(PALETTE16, ARGB8888, 4, 1, rot_pal16_argb32), |
| 293 | ENTRY(PALETTE16, RGB888, 4, 1, rot_pal16_argb32), |
| 287 | 294 | |
| 288 | | ENTRY(RGB15, RGB555, rot_rgb15_argb1555), |
| 289 | | ENTRY(RGB15, ARGB1555, rot_rgb15_argb1555), |
| 290 | | ENTRY(RGB15, ARGB8888, rot_rgb15_argb32), |
| 291 | | ENTRY(RGB15, RGB888, rot_rgb15_argb32), |
| 295 | ENTRY(RGB15, RGB555, 2, 1, rot_rgb15_argb1555), |
| 296 | ENTRY(RGB15, ARGB1555, 2, 1, rot_rgb15_argb1555), |
| 297 | ENTRY(RGB15, ARGB8888, 4, 1, rot_rgb15_argb32), |
| 298 | ENTRY(RGB15, RGB888, 4, 1, rot_rgb15_argb32), |
| 292 | 299 | |
| 293 | | ENTRY(RGB15_PALETTED, ARGB8888, rot_rgb15pal_argb32), |
| 294 | | ENTRY(RGB15_PALETTED, RGB888, rot_rgb15pal_argb32), |
| 300 | ENTRY(RGB15_PALETTED, ARGB8888, 4, 1, rot_rgb15pal_argb32), |
| 301 | ENTRY(RGB15_PALETTED, RGB888, 4, 1, rot_rgb15pal_argb32), |
| 295 | 302 | |
| 296 | | ENTRY(PALETTE16A, ARGB8888, rot_pal16a_argb32), |
| 297 | | ENTRY(PALETTE16A, RGB888, rot_pal16a_rgb32), |
| 303 | ENTRY(PALETTE16A, ARGB8888, 4, 1, rot_pal16a_argb32), |
| 304 | ENTRY(PALETTE16A, RGB888, 4, 1, rot_pal16a_rgb32), |
| 298 | 305 | |
| 299 | 306 | { -1 }, |
| 300 | 307 | }; |
| r243238 | r243239 | |
| 387 | 394 | SDL_RenderCopy(m_renderer, m_texture_id, NULL, &target_rect); |
| 388 | 395 | } |
| 389 | 396 | |
| 390 | | void sdl_info13::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y) |
| 397 | void sdl_info::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y) |
| 391 | 398 | { |
| 392 | 399 | SDL_Rect target_rect; |
| 393 | 400 | |
| r243238 | r243239 | |
| 541 | 548 | { |
| 542 | 549 | if (bi->pixel_count) |
| 543 | 550 | osd_printf_verbose("%s -> %s %s blendmode 0x%02x, %d samples: %d KPixel/sec\n", bi->srcname, bi->dstname, |
| 544 | | bi->blitter->m_is_rot ? "rot" : "norot", bi->bm_mask, bi->samples, |
| 551 | bi->rotate ? "rot" : "norot", bi->bm_mask, bi->samples, |
| 545 | 552 | (int) bi->perf); |
| 546 | 553 | freeme = bi; |
| 547 | 554 | bi = bi->next; |
| r243238 | r243239 | |
| 573 | 580 | static int drawsdl2_window_create(sdl_window_info *window, int width, int height) |
| 574 | 581 | { |
| 575 | 582 | // allocate memory for our structures |
| 576 | | sdl_info13 *sdl = global_alloc(sdl_info13); |
| 583 | sdl_info *sdl = global_alloc(sdl_info); |
| 577 | 584 | |
| 578 | 585 | /* FIXME: On Ubuntu and potentially other Linux OS you should use |
| 579 | 586 | * to disable panning. This has to be done before every invocation of mame. |
| r243238 | r243239 | |
| 589 | 596 | UINT32 extra_flags = (window->fullscreen() ? |
| 590 | 597 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 591 | 598 | |
| 592 | | #if defined(SDLMAME_WIN32) |
| 593 | | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 594 | | #endif |
| 595 | 599 | // create the SDL window |
| 596 | | window->sdl_window = SDL_CreateWindow(window->title, |
| 597 | | window->monitor()->position_size().x, window->monitor()->position_size().y, |
| 600 | window->sdl_window = SDL_CreateWindow(window->title, window->monitor()->monitor_x, 0, |
| 598 | 601 | width, height, extra_flags); |
| 599 | 602 | |
| 600 | 603 | if (window->fullscreen() && video_config.switchres) |
| r243238 | r243239 | |
| 607 | 610 | mode.h = height; |
| 608 | 611 | if (window->refresh) |
| 609 | 612 | mode.refresh_rate = window->refresh; |
| 610 | | #if 0 |
| 611 | 613 | if (window->depth) |
| 612 | 614 | { |
| 613 | 615 | switch (window->depth) |
| r243238 | r243239 | |
| 628 | 630 | osd_printf_warning("Ignoring depth %d\n", window->depth); |
| 629 | 631 | } |
| 630 | 632 | } |
| 631 | | #endif |
| 632 | | |
| 633 | 633 | SDL_SetWindowDisplayMode(window->sdl_window, &mode); // Try to set mode |
| 634 | 634 | #ifndef SDLMAME_WIN32 |
| 635 | 635 | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| r243238 | r243239 | |
| 640 | 640 | #endif |
| 641 | 641 | } |
| 642 | 642 | else |
| 643 | | { |
| 644 | | //SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop |
| 645 | | } |
| 643 | SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop |
| 644 | |
| 646 | 645 | // create renderer |
| 647 | 646 | |
| 648 | 647 | if (video_config.waitvsync) |
| r243238 | r243239 | |
| 656 | 655 | } |
| 657 | 656 | |
| 658 | 657 | //SDL_SelectRenderer(window->sdl_window); |
| 658 | |
| 659 | 659 | SDL_ShowWindow(window->sdl_window); |
| 660 | 660 | //SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 661 | 661 | SDL_RaiseWindow(window->sdl_window); |
| 662 | | |
| 663 | 662 | SDL_GetWindowSize(window->sdl_window, &window->width, &window->height); |
| 664 | 663 | |
| 665 | 664 | sdl->m_blittimer = 3; |
| r243238 | r243239 | |
| 675 | 674 | |
| 676 | 675 | static void drawsdl2_window_resize(sdl_window_info *window, int width, int height) |
| 677 | 676 | { |
| 678 | | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 677 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 679 | 678 | |
| 680 | 679 | sdl->m_resize_pending = 1; |
| 681 | 680 | sdl->m_resize_height = height; |
| r243238 | r243239 | |
| 694 | 693 | |
| 695 | 694 | static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 696 | 695 | { |
| 697 | | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 696 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 698 | 697 | |
| 699 | 698 | *xt = x - sdl->m_hofs; |
| 700 | 699 | *yt = y - sdl->m_vofs; |
| r243238 | r243239 | |
| 711 | 710 | |
| 712 | 711 | static void drawsdl2_set_target_bounds(sdl_window_info *window) |
| 713 | 712 | { |
| 714 | | window->target->set_bounds(window->blitwidth, window->blitheight, window->monitor()->aspect()); |
| 713 | window->target->set_bounds(window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor())); |
| 715 | 714 | } |
| 716 | 715 | |
| 717 | 716 | //============================================================ |
| r243238 | r243239 | |
| 720 | 719 | |
| 721 | 720 | static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) |
| 722 | 721 | { |
| 723 | | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 722 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 724 | 723 | render_primitive *prim; |
| 725 | 724 | texture_info *texture=NULL; |
| 726 | 725 | float vofs, hofs; |
| r243238 | r243239 | |
| 762 | 761 | |
| 763 | 762 | if ((window->fullscreen()) && (!video_config.switchres)) |
| 764 | 763 | { |
| 765 | | ch = window->monitor()->center_height(); |
| 766 | | cw = window->monitor()->center_width(); |
| 764 | ch = window->monitor()->center_height; |
| 765 | cw = window->monitor()->center_width; |
| 767 | 766 | } |
| 768 | 767 | else |
| 769 | 768 | { |
| r243238 | r243239 | |
| 834 | 833 | |
| 835 | 834 | static void drawsdl2_window_clear(sdl_window_info *window) |
| 836 | 835 | { |
| 837 | | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 836 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 838 | 837 | |
| 839 | 838 | sdl->m_blittimer = 2; |
| 840 | 839 | } |
| r243238 | r243239 | |
| 846 | 845 | |
| 847 | 846 | static void drawsdl2_window_destroy(sdl_window_info *window) |
| 848 | 847 | { |
| 849 | | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 848 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 850 | 849 | |
| 851 | 850 | // skip if nothing |
| 852 | 851 | if (sdl == NULL) |
| r243238 | r243239 | |
| 885 | 884 | |
| 886 | 885 | for (bi = blit_info[m_format]; bi != NULL; bi = bi->next) |
| 887 | 886 | { |
| 888 | | if ((m_is_rotated == bi->blitter->m_is_rot) |
| 887 | if ((m_is_rotated == bi->rotate) |
| 889 | 888 | && (m_sdl_blendmode == bi->bm_mask)) |
| 890 | 889 | { |
| 891 | 890 | if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname)) |
| r243238 | r243239 | |
| 906 | 905 | /* try last resort handlers */ |
| 907 | 906 | for (bi = blit_info[m_format]; bi != NULL; bi = bi->next) |
| 908 | 907 | { |
| 909 | | if ((m_is_rotated == bi->blitter->m_is_rot) |
| 908 | if ((m_is_rotated == bi->rotate) |
| 910 | 909 | && (m_sdl_blendmode == bi->bm_mask)) |
| 911 | 910 | if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname)) |
| 912 | 911 | return bi; |
| r243238 | r243239 | |
| 915 | 914 | return NULL; |
| 916 | 915 | } |
| 917 | 916 | |
| 918 | | // FIXME: |
| 919 | | const bool texture_info::is_pixels_owned() const |
| 920 | | { // do we own / allocated it ? |
| 921 | | return ((m_sdl_access == SDL_TEXTUREACCESS_STATIC) |
| 922 | | && (m_copyinfo->blitter->m_is_passthrough)); |
| 923 | | } |
| 924 | | |
| 925 | 917 | //============================================================ |
| 926 | 918 | // texture_info::matches |
| 927 | 919 | //============================================================ |
| r243238 | r243239 | |
| 951 | 943 | m_flags = flags; |
| 952 | 944 | m_texinfo = texsource; |
| 953 | 945 | m_texinfo.seqid = -1; // force set data |
| 954 | | m_is_rotated = false; |
| 946 | m_is_rotated = FALSE; |
| 955 | 947 | m_setup = setup; |
| 956 | 948 | m_sdl_blendmode = map_blendmode(PRIMFLAG_GET_BLENDMODE(flags)); |
| 957 | 949 | m_pitch = 0; |
| r243238 | r243239 | |
| 980 | 972 | |
| 981 | 973 | if (setup.rotwidth != m_texinfo.width || setup.rotheight != m_texinfo.height |
| 982 | 974 | || setup.dudx < 0 || setup.dvdy < 0) |
| 983 | | m_is_rotated = true; |
| 975 | m_is_rotated = TRUE; |
| 984 | 976 | else |
| 985 | | m_is_rotated = false; |
| 977 | m_is_rotated = FALSE; |
| 986 | 978 | |
| 987 | 979 | //m_sdl_access = SDL_TEXTUREACCESS_STATIC; |
| 988 | 980 | m_sdl_access = SDL_TEXTUREACCESS_STREAMING; |
| r243238 | r243239 | |
| 1004 | 996 | |
| 1005 | 997 | if (m_sdl_access == SDL_TEXTUREACCESS_STATIC) |
| 1006 | 998 | { |
| 1007 | | if (m_copyinfo->blitter->m_is_passthrough) |
| 1008 | | m_pixels = NULL; |
| 999 | if (m_copyinfo->func != NULL) |
| 1000 | m_pixels = malloc(m_setup.rotwidth * m_setup.rotheight * m_copyinfo->dst_bpp); |
| 1009 | 1001 | else |
| 1010 | | m_pixels = malloc(m_setup.rotwidth * m_setup.rotheight * m_copyinfo->blitter->m_dest_bpp); |
| 1002 | m_pixels = NULL; |
| 1011 | 1003 | } |
| 1012 | 1004 | m_last_access = osd_ticks(); |
| 1013 | 1005 | |
| r243238 | r243239 | |
| 1029 | 1021 | m_copyinfo->time -= osd_ticks(); |
| 1030 | 1022 | if (m_sdl_access == SDL_TEXTUREACCESS_STATIC) |
| 1031 | 1023 | { |
| 1032 | | if ( m_copyinfo->blitter->m_is_passthrough ) |
| 1024 | if ( m_copyinfo->func ) |
| 1033 | 1025 | { |
| 1034 | | m_pixels = texsource.base; |
| 1035 | | m_pitch = m_texinfo.rowpixels * m_copyinfo->blitter->m_dest_bpp; |
| 1026 | m_pitch = m_setup.rotwidth * m_copyinfo->dst_bpp; |
| 1027 | m_copyinfo->func(this, &texsource); |
| 1036 | 1028 | } |
| 1037 | 1029 | else |
| 1038 | 1030 | { |
| 1039 | | m_pitch = m_setup.rotwidth * m_copyinfo->blitter->m_dest_bpp; |
| 1040 | | m_copyinfo->blitter->texop(this, &texsource); |
| 1031 | m_pixels = texsource.base; |
| 1032 | m_pitch = m_texinfo.rowpixels * m_copyinfo->dst_bpp; |
| 1041 | 1033 | } |
| 1042 | 1034 | SDL_UpdateTexture(m_texture_id, NULL, m_pixels, m_pitch); |
| 1043 | 1035 | } |
| 1044 | 1036 | else |
| 1045 | 1037 | { |
| 1046 | 1038 | SDL_LockTexture(m_texture_id, NULL, (void **) &m_pixels, &m_pitch); |
| 1047 | | if ( m_copyinfo->blitter->m_is_passthrough ) |
| 1039 | if ( m_copyinfo->func ) |
| 1040 | m_copyinfo->func(this, &texsource); |
| 1041 | else |
| 1048 | 1042 | { |
| 1049 | 1043 | UINT8 *src = (UINT8 *) texsource.base; |
| 1050 | 1044 | UINT8 *dst = (UINT8 *) m_pixels; |
| 1051 | | int spitch = texsource.rowpixels * m_copyinfo->blitter->m_dest_bpp; |
| 1052 | | int num = texsource.width * m_copyinfo->blitter->m_dest_bpp; |
| 1045 | int spitch = texsource.rowpixels * m_copyinfo->dst_bpp; |
| 1046 | int num = texsource.width * m_copyinfo->dst_bpp; |
| 1053 | 1047 | int h = texsource.height; |
| 1054 | 1048 | while (h--) { |
| 1055 | 1049 | memcpy(dst, src, num); |
| r243238 | r243239 | |
| 1057 | 1051 | dst += m_pitch; |
| 1058 | 1052 | } |
| 1059 | 1053 | } |
| 1060 | | else |
| 1061 | | m_copyinfo->blitter->texop(this, &texsource); |
| 1062 | 1054 | SDL_UnlockTexture(m_texture_id); |
| 1063 | 1055 | } |
| 1064 | 1056 | m_copyinfo->time += osd_ticks(); |
| r243238 | r243239 | |
| 1119 | 1111 | // texture_find |
| 1120 | 1112 | //============================================================ |
| 1121 | 1113 | |
| 1122 | | texture_info *sdl_info13::texture_find(const render_primitive &prim, const quad_setup_data &setup) |
| 1114 | texture_info *sdl_info::texture_find(const render_primitive &prim, const quad_setup_data &setup) |
| 1123 | 1115 | { |
| 1124 | 1116 | HashT texhash = texture_compute_hash(prim.texture, prim.flags); |
| 1125 | 1117 | texture_info *texture; |
| r243238 | r243239 | |
| 1156 | 1148 | // texture_update |
| 1157 | 1149 | //============================================================ |
| 1158 | 1150 | |
| 1159 | | texture_info * sdl_info13::texture_update(const render_primitive &prim) |
| 1151 | texture_info * sdl_info::texture_update(const render_primitive &prim) |
| 1160 | 1152 | { |
| 1161 | 1153 | quad_setup_data setup; |
| 1162 | 1154 | texture_info *texture; |
| r243238 | r243239 | |
| 1190 | 1182 | |
| 1191 | 1183 | static void drawsdl2_destroy_all_textures(sdl_window_info *window) |
| 1192 | 1184 | { |
| 1193 | | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 1185 | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 1194 | 1186 | |
| 1195 | 1187 | if (sdl == NULL) |
| 1196 | 1188 | return; |
trunk/src/osd/sdl/video.c
| r243238 | r243239 | |
| 69 | 69 | #endif |
| 70 | 70 | #endif |
| 71 | 71 | |
| 72 | | sdl_monitor_info *sdl_monitor_info::primary_monitor = NULL; |
| 73 | | sdl_monitor_info *sdl_monitor_info::list = NULL; |
| 74 | | |
| 75 | 72 | //============================================================ |
| 76 | 73 | // LOCAL VARIABLES |
| 77 | 74 | //============================================================ |
| 78 | 75 | |
| 76 | static sdl_monitor_info *primary_monitor; |
| 77 | static sdl_monitor_info *sdl_monitor_list; |
| 78 | |
| 79 | 79 | //============================================================ |
| 80 | 80 | // PROTOTYPES |
| 81 | 81 | //============================================================ |
| 82 | 82 | |
| 83 | static void init_monitors(void); |
| 84 | static sdl_monitor_info *pick_monitor(sdl_options &options, int index); |
| 85 | |
| 83 | 86 | static void check_osd_inputs(running_machine &machine); |
| 84 | 87 | |
| 85 | 88 | static float get_aspect(const char *defdata, const char *data, int report_error); |
| r243238 | r243239 | |
| 98 | 101 | extract_video_config(machine()); |
| 99 | 102 | |
| 100 | 103 | // set up monitors first |
| 101 | | sdl_monitor_info::init(); |
| 104 | init_monitors(); |
| 102 | 105 | |
| 103 | 106 | // we need the beam width in a float, contrary to what the core does. |
| 104 | 107 | video_config.beamwidth = options().beam(); |
| r243238 | r243239 | |
| 112 | 115 | { |
| 113 | 116 | sdl_window_config conf; |
| 114 | 117 | memset(&conf, 0, sizeof(conf)); |
| 115 | | get_resolution(options().resolution(), options().resolution(index), &conf, TRUE); |
| 116 | | if (sdlwindow_video_window_create(machine(), index, sdl_monitor_info::pick_monitor(options(), index), &conf)) |
| 118 | extract_window_config(index, &conf); |
| 119 | if (sdlwindow_video_window_create(machine(), index, pick_monitor(options(), index), &conf)) |
| 117 | 120 | return false; |
| 118 | 121 | } |
| 119 | 122 | |
| r243238 | r243239 | |
| 128 | 131 | void sdl_osd_interface::video_exit() |
| 129 | 132 | { |
| 130 | 133 | window_exit(); |
| 131 | | sdl_monitor_info::exit(); |
| 134 | |
| 135 | // free all of our monitor information |
| 136 | while (sdl_monitor_list != NULL) |
| 137 | { |
| 138 | sdl_monitor_info *temp = sdl_monitor_list; |
| 139 | sdl_monitor_list = temp->next; |
| 140 | global_free(temp); |
| 141 | } |
| 142 | |
| 132 | 143 | } |
| 133 | 144 | |
| 134 | 145 | |
| r243238 | r243239 | |
| 136 | 147 | // sdlvideo_monitor_refresh |
| 137 | 148 | //============================================================ |
| 138 | 149 | |
| 139 | | void sdl_monitor_info::refresh() |
| 150 | void sdlvideo_monitor_refresh(sdl_monitor_info *monitor) |
| 140 | 151 | { |
| 141 | 152 | #if (SDLMAME_SDL2) |
| 142 | 153 | SDL_DisplayMode dmode; |
| 143 | 154 | |
| 144 | 155 | #if defined(SDLMAME_WIN32) |
| 145 | | SDL_GetDesktopDisplayMode(m_handle, &dmode); |
| 156 | SDL_GetDesktopDisplayMode(monitor->handle, &dmode); |
| 146 | 157 | #else |
| 147 | | SDL_GetCurrentDisplayMode(m_handle, &dmode); |
| 158 | SDL_GetCurrentDisplayMode(monitor->handle, &dmode); |
| 148 | 159 | #endif |
| 149 | | SDL_GetDisplayBounds(m_handle, &m_dimensions); |
| 150 | | m_center_width = m_dimensions.w; |
| 151 | | m_center_height = m_dimensions.h; |
| 160 | monitor->monitor_width = dmode.w; |
| 161 | monitor->monitor_height = dmode.h; |
| 162 | monitor->center_width = dmode.w; |
| 163 | monitor->center_height = dmode.h; |
| 152 | 164 | |
| 153 | 165 | // FIXME: Use SDL_GetDisplayBounds(monitor->handle, &tt) to update monitor_x |
| 154 | 166 | // SDL_Rect tt; |
| r243238 | r243239 | |
| 157 | 169 | MONITORINFOEX info; |
| 158 | 170 | info.cbSize = sizeof(info); |
| 159 | 171 | GetMonitorInfo((HMONITOR)monitor->handle, (LPMONITORINFO)&info); |
| 160 | | monitor->m_dimensions.x = monitor->m_dimensions.y = 0; |
| 161 | | monitor->m_center_width = monitor->m_dimensions.w = info.rcMonitor.right - info.rcMonitor.left; |
| 162 | | monitor->m_center_height = monitor->m_dimensions.h = info.rcMonitor.bottom - info.rcMonitor.top; |
| 172 | monitor->center_width = monitor->monitor_width = info.rcMonitor.right - info.rcMonitor.left; |
| 173 | monitor->center_height = monitor->monitor_height = info.rcMonitor.bottom - info.rcMonitor.top; |
| 163 | 174 | char *temp = utf8_from_wstring(info.szDevice); |
| 164 | 175 | strcpy(monitor->monitor_device, temp); |
| 165 | 176 | osd_free(temp); |
| r243238 | r243239 | |
| 274 | 285 | // sdlvideo_monitor_get_aspect |
| 275 | 286 | //============================================================ |
| 276 | 287 | |
| 277 | | float sdl_monitor_info::aspect() |
| 288 | float sdlvideo_monitor_get_aspect(sdl_monitor_info *monitor) |
| 278 | 289 | { |
| 279 | 290 | // refresh the monitor information and compute the aspect |
| 280 | | refresh(); |
| 281 | | // FIXME: returning 0 looks odd, video_config is bad |
| 282 | 291 | if (video_config.keepaspect) |
| 283 | 292 | { |
| 284 | | return m_aspect / ((float)m_dimensions.w / (float)m_dimensions.h); |
| 293 | sdlvideo_monitor_refresh(monitor); |
| 294 | return monitor->aspect / ((float)monitor->monitor_width / (float)monitor->monitor_height); |
| 285 | 295 | } |
| 286 | 296 | return 0.0f; |
| 287 | 297 | } |
| 288 | 298 | |
| 289 | 299 | |
| 290 | 300 | |
| 301 | //============================================================ |
| 302 | // sdlvideo_monitor_from_handle |
| 303 | //============================================================ |
| 291 | 304 | |
| 305 | sdl_monitor_info *sdlvideo_monitor_from_handle(UINT32 hmonitor) |
| 306 | { |
| 307 | sdl_monitor_info *monitor; |
| 308 | |
| 309 | // find the matching monitor |
| 310 | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 311 | if (monitor->handle == hmonitor) |
| 312 | return monitor; |
| 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | |
| 292 | 317 | //============================================================ |
| 293 | 318 | // update |
| 294 | 319 | //============================================================ |
| r243238 | r243239 | |
| 406 | 431 | // init_monitors |
| 407 | 432 | //============================================================ |
| 408 | 433 | |
| 409 | | void sdl_monitor_info::init() |
| 434 | static void init_monitors(void) |
| 410 | 435 | { |
| 411 | 436 | sdl_monitor_info **tailptr; |
| 412 | 437 | |
| 413 | 438 | // make a list of monitors |
| 414 | | sdl_monitor_info::list = NULL; |
| 415 | | tailptr = &sdl_monitor_info::list; |
| 439 | sdl_monitor_list = NULL; |
| 440 | tailptr = &sdl_monitor_list; |
| 416 | 441 | |
| 417 | 442 | #if (SDLMAME_SDL2) |
| 418 | 443 | { |
| r243238 | r243239 | |
| 427 | 452 | |
| 428 | 453 | // allocate a new monitor info |
| 429 | 454 | monitor = global_alloc_clear(sdl_monitor_info); |
| 430 | | monitor->m_handle = i; |
| 431 | 455 | |
| 432 | | snprintf(monitor->m_monitor_device, sizeof(monitor->m_monitor_device)-1, "%s%d", OSDOPTION_SCREEN,i); |
| 456 | snprintf(monitor->monitor_device, sizeof(monitor->monitor_device)-1, "%s%d", OSDOPTION_SCREEN,i); |
| 433 | 457 | |
| 434 | 458 | SDL_GetDesktopDisplayMode(i, &dmode); |
| 435 | | SDL_GetDisplayBounds(i, &monitor->m_dimensions); |
| 436 | | monitor->m_center_width = monitor->m_dimensions.w; |
| 437 | | monitor->m_center_height = monitor->m_dimensions.h; |
| 438 | | |
| 459 | monitor->monitor_width = dmode.w; |
| 460 | monitor->monitor_height = dmode.h; |
| 461 | monitor->center_width = dmode.w; |
| 462 | monitor->center_height = dmode.h; |
| 463 | // FIXME: this should use SDL_GetDisplayBounds! |
| 464 | monitor->monitor_x = monx; |
| 465 | monitor->handle = i; |
| 439 | 466 | // guess the aspect ratio assuming square pixels |
| 440 | | monitor->m_aspect = (float)(dmode.w) / (float)(dmode.h); |
| 467 | monitor->aspect = (float)(dmode.w) / (float)(dmode.h); |
| 468 | osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->monitor_device, dmode.w, dmode.h); |
| 441 | 469 | |
| 442 | | osd_printf_verbose("Adding monitor %s (%d x %d)\n", monitor->m_monitor_device, dmode.w, dmode.h); |
| 443 | | |
| 444 | 470 | monx += dmode.w; |
| 445 | 471 | |
| 446 | 472 | // save the primary monitor handle |
| r243238 | r243239 | |
| 460 | 486 | #endif |
| 461 | 487 | } |
| 462 | 488 | |
| 463 | | void sdl_monitor_info::exit() |
| 464 | | { |
| 465 | | // free all of our monitor information |
| 466 | | while (sdl_monitor_info::list != NULL) |
| 467 | | { |
| 468 | | sdl_monitor_info *temp = sdl_monitor_info::list; |
| 469 | | sdl_monitor_info::list = temp->next; |
| 470 | | global_free(temp); |
| 471 | | } |
| 472 | | } |
| 473 | 489 | |
| 474 | | |
| 475 | 490 | //============================================================ |
| 476 | 491 | // pick_monitor |
| 477 | 492 | //============================================================ |
| 478 | 493 | |
| 479 | 494 | #if (SDLMAME_SDL2) || defined(SDLMAME_WIN32) |
| 480 | | sdl_monitor_info *sdl_monitor_info::pick_monitor(sdl_options &options, int index) |
| 495 | static sdl_monitor_info *pick_monitor(sdl_options &options, int index) |
| 481 | 496 | { |
| 482 | 497 | sdl_monitor_info *monitor; |
| 483 | 498 | const char *scrname, *scrname2; |
| r243238 | r243239 | |
| 498 | 513 | // look for a match in the name first |
| 499 | 514 | if (scrname != NULL) |
| 500 | 515 | { |
| 501 | | for (monitor = sdl_monitor_info::list; monitor != NULL; monitor = monitor->next) |
| 516 | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 502 | 517 | { |
| 503 | 518 | moncount++; |
| 504 | | if (strcmp(scrname, monitor->device()) == 0) |
| 519 | if (strcmp(scrname, monitor->monitor_device) == 0) |
| 505 | 520 | goto finishit; |
| 506 | 521 | } |
| 507 | 522 | } |
| 508 | 523 | |
| 509 | 524 | // didn't find it; alternate monitors until we hit the jackpot |
| 510 | 525 | index %= moncount; |
| 511 | | for (monitor = sdl_monitor_info::list; monitor != NULL; monitor = monitor->next) |
| 526 | for (monitor = sdl_monitor_list; monitor != NULL; monitor = monitor->next) |
| 512 | 527 | if (index-- == 0) |
| 513 | 528 | goto finishit; |
| 514 | 529 | |
| r243238 | r243239 | |
| 518 | 533 | finishit: |
| 519 | 534 | if (aspect != 0) |
| 520 | 535 | { |
| 521 | | monitor->set_aspect(aspect); |
| 536 | monitor->aspect = aspect; |
| 522 | 537 | } |
| 523 | 538 | return monitor; |
| 524 | 539 | } |
| r243238 | r243239 | |
| 594 | 609 | } |
| 595 | 610 | |
| 596 | 611 | //============================================================ |
| 612 | // extract_window_config |
| 613 | //============================================================ |
| 614 | |
| 615 | void sdl_osd_interface::extract_window_config(int index, sdl_window_config *conf) |
| 616 | { |
| 617 | // per-window options: extract the data |
| 618 | get_resolution(options().resolution(), options().resolution(index), conf, TRUE); |
| 619 | } |
| 620 | |
| 621 | //============================================================ |
| 597 | 622 | // extract_video_config |
| 598 | 623 | //============================================================ |
| 599 | 624 | |