trunk/src/osd/sdl/blit13.h
| r243239 | r243240 | |
| 5 | 5 | // INLINE |
| 6 | 6 | //============================================================ |
| 7 | 7 | |
| 8 | | INLINE UINT32 premult32(UINT32 pixel) |
| 8 | inline UINT32 premult32(const UINT32 pixel) |
| 9 | 9 | { |
| 10 | | UINT8 a = (pixel >> 24) & 0xff; |
| 11 | | UINT8 r = (pixel >> 16) & 0xff; |
| 12 | | UINT8 g = (pixel >> 8) & 0xff; |
| 13 | | UINT8 b = (pixel >> 0) & 0xff; |
| 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; |
| 14 | 14 | |
| 15 | 15 | return 0xFF000000 | |
| 16 | | (((UINT16)r * (UINT16)a) / 255) << 16 | |
| 17 | | (((UINT16)g * (UINT16)a) / 255) << 8 | |
| 18 | | (((UINT16)b * (UINT16)a) / 255); |
| 16 | ((r * a) / 255) << 16 | |
| 17 | ((g * a) / 255) << 8 | |
| 18 | ((b * a) / 255); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | | #define CLUL(x) ((int) (x) < 0 ? 0 : ((x) > 65535 ? 255 : (x)>>8)) |
| 21 | inline UINT32 CLUL(const UINT32 x) |
| 22 | { |
| 23 | return ((INT32) x < 0) ? 0 : ((x > 65535) ? 255 : x >> 8); |
| 24 | } |
| 22 | 25 | |
| 23 | | INLINE UINT32 ycc_to_rgb(UINT8 y, UINT8 cb, UINT8 cr) |
| 26 | inline UINT32 ycc_to_rgb(const UINT8 y, const UINT8 cb, const UINT8 cr) |
| 24 | 27 | { |
| 25 | | unsigned int r, g, b, common; |
| 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); |
| 26 | 32 | |
| 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 | | |
| 32 | 33 | return 0xff000000 | (CLUL(r)<<16) | (CLUL(g)<<8) | (CLUL(b)); |
| 33 | 34 | } |
| 34 | 35 | |
| 35 | | INLINE UINT32 pixel_ycc_to_rgb(UINT16 *pixel) |
| 36 | inline UINT32 pixel_ycc_to_rgb(const UINT16 *pixel) |
| 36 | 37 | { |
| 37 | | UINT32 p = *(UINT32 *)((FPTR) pixel & ~1); |
| 38 | |
| 39 | const UINT32 p = *(UINT32 *)((FPTR) pixel & ~3); |
| 38 | 40 | return ycc_to_rgb((*pixel >> 8) & 0xff, (p) & 0xff, (p>>16) & 0xff); |
| 39 | 41 | } |
| 40 | 42 | |
| 41 | | INLINE UINT32 pixel_ycc_to_rgb_pal(UINT16 *pixel, const rgb_t *palette) |
| 43 | inline UINT32 pixel_ycc_to_rgb_pal(const UINT16 *pixel, const rgb_t *palette) |
| 42 | 44 | { |
| 43 | | UINT32 p = *(UINT32 *)((FPTR) pixel & ~1); |
| 45 | const UINT32 p = *(UINT32 *)((FPTR) pixel & ~3); |
| 44 | 46 | return ycc_to_rgb(palette[(*pixel >> 8) & 0xff], (p) & 0xff, (p>>16) & 0xff); |
| 45 | 47 | } |
| 46 | 48 | |
| r243239 | r243240 | |
| 48 | 50 | // Pixel conversions |
| 49 | 51 | //============================================================ |
| 50 | 52 | |
| 51 | | #define OP_ARGB32_ARGB32(_src) (_src) |
| 52 | 53 | |
| 53 | | #define OP_RGB32_ARGB32(_src) ((_src) | 0xff000000) |
| 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 } }; |
| 54 | 58 | |
| 55 | | #define OP_RGB32PAL_ARGB32(_src) \ |
| 56 | | (palbase[0x200 + (((_src) >> 16) & 0xff) ] | \ |
| 57 | | palbase[0x100 + (((_src) >> 8) & 0xff) ] | \ |
| 58 | | palbase[((_src) & 0xff) ] | 0xff000000) |
| 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; ) |
| 59 | 67 | |
| 60 | | #define OP_PAL16_ARGB32(_src) (0xff000000 | palbase[_src]) |
| 68 | FUNCTOR(op_pal16a_argb32, return palbase[src]; ) |
| 61 | 69 | |
| 62 | | #define OP_PAL16A_ARGB32(_src) (palbase[_src]) |
| 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); ) |
| 63 | 74 | |
| 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)) |
| 75 | FUNCTOR(op_rgb15pal_argb32, |
| 76 | return 0xff000000 | palbase[0x40 + ((src >> 10) & 0x1f)] | |
| 77 | palbase[0x20 + ((src >> 5) & 0x1f)] | palbase[0x00 + ((src >> 0) & 0x1f)]; ) |
| 66 | 78 | |
| 67 | | #define OP_RGB15PAL_ARGB32(_src) (0xff000000 | palbase[0x40 + ((_src >> 10) & 0x1f)] | \ |
| 68 | | palbase[0x20 + ((_src >> 5) & 0x1f)] | palbase[0x00 + ((_src >> 0) & 0x1f)]) |
| 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; ) |
| 69 | 85 | |
| 70 | | #define OP_ARGB32_RGB32(_pixel) premult32(_pixel) |
| 86 | FUNCTOR(op_rgb15_argb1555, return src | 0x8000; ) |
| 71 | 87 | |
| 72 | | #define OP_PAL16A_RGB32(_src) premult32(palbase[_src]) |
| 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; ) |
| 73 | 92 | |
| 74 | | #define OP_PAL16_ARGB1555(_src) ((palbase[_src]&0xf80000) >> 9 | \ |
| 75 | | (palbase[_src]&0x00f800) >> 6 | \ |
| 76 | | (palbase[_src]&0x0000f8) >> 3 | 0x8000) |
| 93 | FUNCTOR(op_yuv16_uyvy, return src; ) |
| 94 | FUNCTOR(op_yuv16pal_uyvy, return (palbase[(src >> 8) & 0xff] << 8) | (src & 0x00ff); ) |
| 77 | 95 | |
| 78 | | #define OP_RGB15_ARGB1555(_src) ((_src) | 0x8000) |
| 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); ) |
| 79 | 99 | |
| 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) |
| 100 | FUNCTOR(op_yuv16_yuy2, return ((src & 0xff00ff00) >> 8) | ((src & 0x00ff00ff) << 8); ) |
| 83 | 101 | |
| 84 | | #define OP_YUV16_UYVY(_src) (_src) |
| 102 | FUNCTOR(op_yuv16pal_yuy2, |
| 103 | return (palbase[(src>>8) & 0xff]) | |
| 104 | (palbase[(src>>24) & 0xff]<<16) | |
| 105 | ((src<<8)&0xff00ff00);) |
| 85 | 106 | |
| 86 | | #define OP_YUV16PAL_UYVY(_src) ((palbase[((_src) >> 8) & 0xff] << 8) | ((_src) & 0x00ff)) |
| 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); ) |
| 87 | 110 | |
| 88 | | #define OP_YUV16PAL_YVYU(_src) ((palbase[((_src) >> 8) & 0xff] & 0xff) | ((_src & 0xff) << 8)) |
| 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);) |
| 89 | 114 | |
| 90 | | #define OP_YUV16_YVYU(_src) ((((_src) >> 8) & 0xff) | ((_src & 0xff) << 8)) |
| 115 | FUNCTOR(op_yuv16_argb32rot, return pixel_ycc_to_rgb(&src) ; ) |
| 91 | 116 | |
| 92 | | #define OP_YUV16_YUY2(_src) ( ((_src) & 0xff00ff00) | \ |
| 93 | | (((_src)>>16)&0xff) | (((_src)<<16)&0xff0000) ) |
| 117 | FUNCTOR(op_yuv16pal_argb32rot, return pixel_ycc_to_rgb_pal(&src, palbase); ) |
| 94 | 118 | |
| 95 | | #define OP_YUV16PAL_YUY2(_src) ( (palbase[((_src)>>8) & 0xff]) | \ |
| 96 | | (palbase[((_src)>>24) & 0xff]<<16) | \ |
| 97 | | (((_src)<<8)&0xff00ff00) ) |
| 119 | //============================================================ |
| 120 | // Copy and rotation |
| 121 | //============================================================ |
| 98 | 122 | |
| 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) |
| 123 | struct blit_base { |
| 102 | 124 | |
| 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) |
| 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() { } |
| 106 | 129 | |
| 107 | | #define OP_YUV16_ARGB32ROT(_src) pixel_ycc_to_rgb(&(_src)) |
| 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 | }; |
| 108 | 135 | |
| 109 | | #define OP_YUV16PAL_ARGB32ROT(_src) pixel_ycc_to_rgb_pal(&(_src), palbase) |
| 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 | }; |
| 110 | 159 | |
| 111 | | //============================================================ |
| 112 | | // Copy and rotation |
| 113 | | //============================================================ |
| 160 | #define TEXCOPYA(a, b, c, d) \ |
| 161 | const struct blit_texcopy<b, c, op_ ## a <b, c>, d> texcopy_ ## a; |
| 114 | 162 | |
| 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 | | } |
| 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 | }; |
| 131 | 192 | |
| 132 | | #define TEXCOPY( _name, _src_type, _dest_type, _op) \ |
| 133 | | TEXCOPY_M( _name, _src_type, _dest_type, _op, 1) |
| 193 | #define TEXROTA(a, b, c) \ |
| 194 | const struct blit_texrot<b, c, op_ ## a <b, c> > texcopy_rot_ ## a; |
| 134 | 195 | |
| 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 | | } |
| 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 | }; |
| 157 | 204 | |
| 158 | | //TEXCOPY(argb32_argb32, UINT32, UINT32, OP_ARGB32_ARGB32) |
| 205 | #define TEXCOPYP(a, b, c) \ |
| 206 | const struct blit_texpass<b, c> texcopy_ ## a; |
| 159 | 207 | |
| 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) |
| 166 | 208 | |
| 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) |
| 209 | TEXCOPYA(rgb32_argb32, UINT32, UINT32, 1) |
| 210 | TEXCOPYP(rgb32_rgb32, UINT32, UINT32) |
| 170 | 211 | |
| 171 | | TEXCOPY(argb32_rgb32, UINT32, UINT32, OP_ARGB32_RGB32) |
| 172 | | TEXCOPY(pal16a_rgb32, UINT16, UINT32, OP_PAL16A_RGB32) |
| 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) |
| 173 | 217 | |
| 174 | | TEXCOPY_M(yuv16_argb32, UINT32, UINT64, OP_YUV16_ARGB32, 2) |
| 175 | | TEXCOPY_M(yuv16pal_argb32, UINT32, UINT64, OP_YUV16PAL_ARGB32, 2) |
| 218 | TEXCOPYA(pal16_argb1555, UINT16, UINT16, 1) |
| 219 | TEXCOPYA(rgb15_argb1555, UINT16, UINT16, 1) |
| 220 | TEXCOPYA(rgb15pal_argb1555, UINT16, UINT16, 1) |
| 176 | 221 | |
| 177 | | //TEXCOPY(yuv16_uyvy, UINT16, UINT16, OP_YUV16_UYVY) |
| 222 | TEXCOPYP(argb32_argb32, UINT32, UINT32) |
| 223 | TEXCOPYA(argb32_rgb32, UINT32, UINT32, 1) |
| 224 | TEXCOPYA(pal16a_rgb32, UINT16, UINT32, 1) |
| 178 | 225 | |
| 179 | | TEXCOPY(yuv16pal_uyvy, UINT16, UINT16, OP_YUV16PAL_UYVY) |
| 226 | TEXCOPYA(yuv16_argb32, UINT32, UINT64, 2) |
| 227 | TEXCOPYA(yuv16pal_argb32, UINT32, UINT64, 2) |
| 180 | 228 | |
| 181 | | TEXCOPY(yuv16_yvyu, UINT16, UINT16, OP_YUV16_YVYU) |
| 182 | | TEXCOPY(yuv16pal_yvyu, UINT16, UINT16, OP_YUV16PAL_YVYU) |
| 229 | TEXCOPYP(yuv16_uyvy, UINT16, UINT16) |
| 230 | TEXCOPYP(rgb15_rgb555, UINT16, UINT16) |
| 183 | 231 | |
| 184 | | TEXCOPY_M(yuv16_yuy2, UINT32, UINT32, OP_YUV16_YUY2, 2) |
| 185 | | TEXCOPY_M(yuv16pal_yuy2, UINT32, UINT32, OP_YUV16PAL_YUY2, 2) |
| 232 | TEXCOPYA(yuv16pal_uyvy, UINT16, UINT16, 1) |
| 186 | 233 | |
| 234 | TEXCOPYA(yuv16_yvyu, UINT32, UINT32, 2) |
| 235 | TEXCOPYA(yuv16pal_yvyu, UINT16, UINT16, 1) |
| 187 | 236 | |
| 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) |
| 237 | TEXCOPYA(yuv16_yuy2, UINT32, UINT32, 2) |
| 238 | TEXCOPYA(yuv16pal_yuy2, UINT32, UINT32, 2) |
| 195 | 239 | |
| 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) |
| 199 | 240 | |
| 200 | | TEXROT(argb32_rgb32, UINT32, UINT32, OP_ARGB32_RGB32) |
| 201 | | TEXROT(pal16a_rgb32, UINT16, UINT32, OP_PAL16A_RGB32) |
| 202 | 241 | |
| 203 | | TEXROT(yuv16_argb32, UINT16, UINT32, OP_YUV16_ARGB32ROT) |
| 204 | | TEXROT(yuv16pal_argb32, UINT16, UINT32, OP_YUV16PAL_ARGB32ROT) |
| 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) |
trunk/src/osd/sdl/draw13.c
| r243239 | r243240 | |
| 24 | 24 | #include "osdsdl.h" |
| 25 | 25 | #include "window.h" |
| 26 | 26 | |
| 27 | |
| 27 | 28 | //============================================================ |
| 28 | 29 | // DEBUGGING |
| 29 | 30 | //============================================================ |
| r243239 | r243240 | |
| 48 | 49 | |
| 49 | 50 | static inline bool is_opaque(const float &a) |
| 50 | 51 | { |
| 51 | | return (a >= 1.0f); |
| 52 | return (a >= 1.0f); |
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | static inline bool is_transparent(const float &a) |
| 55 | 56 | { |
| 56 | | return (a < 0.0001f); |
| 57 | return (a < 0.0001f); |
| 57 | 58 | } |
| 58 | 59 | |
| 59 | 60 | //============================================================ |
| r243239 | r243240 | |
| 63 | 64 | |
| 64 | 65 | struct quad_setup_data |
| 65 | 66 | { |
| 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); |
| 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); |
| 71 | 72 | |
| 72 | 73 | INT32 dudx, dvdx, dudy, dvdy; |
| 73 | 74 | INT32 startu, startv; |
| 74 | 75 | INT32 rotwidth, rotheight; |
| 75 | 76 | }; |
| 76 | 77 | |
| 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 | | |
| 99 | 78 | //============================================================ |
| 100 | 79 | // Textures |
| 101 | 80 | //============================================================ |
| 102 | 81 | |
| 103 | | struct sdl_info; |
| 82 | struct sdl_info13; |
| 83 | struct copy_info_t; |
| 104 | 84 | |
| 105 | 85 | /* texture_info holds information about a texture */ |
| 106 | 86 | class texture_info |
| 107 | 87 | { |
| 108 | | friend class simple_list<texture_info>; |
| 88 | friend class simple_list<texture_info>; |
| 109 | 89 | public: |
| 110 | | texture_info(SDL_Renderer *renderer, const render_texinfo &texsource, const quad_setup_data &setup, const UINT32 flags); |
| 111 | | ~texture_info(); |
| 90 | texture_info(SDL_Renderer *renderer, const render_texinfo &texsource, const quad_setup_data &setup, const UINT32 flags); |
| 91 | ~texture_info(); |
| 112 | 92 | |
| 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); |
| 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); |
| 116 | 96 | |
| 117 | | copy_info_t *compute_size_type(); |
| 97 | copy_info_t *compute_size_type(); |
| 118 | 98 | |
| 119 | 99 | void *m_pixels; // pixels for the texture |
| 120 | 100 | int m_pitch; |
| r243239 | r243240 | |
| 125 | 105 | osd_ticks_t m_last_access; |
| 126 | 106 | |
| 127 | 107 | int raw_width() const { return m_texinfo.width; } |
| 128 | | int raw_height() const { return m_texinfo.height; } |
| 108 | int raw_height() const { return m_texinfo.height; } |
| 129 | 109 | |
| 130 | | texture_info *next() { return m_next; } |
| 131 | | const render_texinfo &texinfo() const { return m_texinfo; } |
| 132 | | render_texinfo &texinfo() { return m_texinfo; } |
| 110 | texture_info *next() { return m_next; } |
| 111 | const render_texinfo &texinfo() const { return m_texinfo; } |
| 112 | render_texinfo &texinfo() { return m_texinfo; } |
| 133 | 113 | |
| 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 | | } |
| 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; |
| 140 | 118 | |
| 141 | 119 | private: |
| 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 |
| 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 |
| 147 | 125 | |
| 148 | | SDL_Texture * m_texture_id; |
| 149 | | int m_is_rotated; |
| 126 | SDL_Texture * m_texture_id; |
| 127 | bool m_is_rotated; |
| 150 | 128 | |
| 151 | | int m_format; // texture format |
| 152 | | SDL_BlendMode m_sdl_blendmode; |
| 129 | int m_format; // texture format |
| 130 | SDL_BlendMode m_sdl_blendmode; |
| 153 | 131 | |
| 154 | | texture_info * m_next; // next texture in the list |
| 132 | texture_info * m_next; // next texture in the list |
| 155 | 133 | }; |
| 156 | 134 | |
| 135 | //============================================================ |
| 136 | // TEXCOPY FUNCS |
| 137 | //============================================================ |
| 138 | |
| 139 | #include "blit13.h" |
| 140 | |
| 157 | 141 | /* sdl_info is the information about SDL for the current screen */ |
| 158 | | struct sdl_info |
| 142 | struct sdl_info13 |
| 159 | 143 | { |
| 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 | | {} |
| 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 | {} |
| 166 | 150 | |
| 167 | | void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); |
| 151 | void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y); |
| 168 | 152 | |
| 169 | | texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); |
| 170 | | texture_info *texture_update(const render_primitive &prim); |
| 153 | texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup); |
| 154 | texture_info *texture_update(const render_primitive &prim); |
| 171 | 155 | |
| 172 | 156 | INT32 m_blittimer; |
| 173 | 157 | |
| r243239 | r243240 | |
| 191 | 175 | SDL_DisplayMode m_original_mode; |
| 192 | 176 | }; |
| 193 | 177 | |
| 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 | //============================================================ |
| r243239 | r243240 | |
| 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 | | //============================================================ |
| 218 | 212 | // STATIC VARIABLES |
| 219 | 213 | //============================================================ |
| 220 | 214 | |
| r243239 | r243240 | |
| 222 | 216 | #define BM_ALL (-1) |
| 223 | 217 | //( SDL_BLENDMODE_MASK | SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD) |
| 224 | 218 | |
| 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} |
| 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} |
| 229 | 222 | |
| 230 | 223 | static copy_info_t blit_info_default[] = |
| 231 | 224 | { |
| 232 | 225 | /* no rotation */ |
| 233 | | ENTRY(ARGB32, ARGB8888, 4, 0, NULL), |
| 234 | | ENTRY_LR(ARGB32, RGB888, 4, 0, argb32_rgb32), |
| 226 | ENTRY(ARGB32, ARGB8888, argb32_argb32), |
| 227 | ENTRY_LR(ARGB32, RGB888, argb32_rgb32), |
| 235 | 228 | /* Entry primarily for directfb */ |
| 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), |
| 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), |
| 239 | 232 | |
| 240 | | ENTRY(RGB32, ARGB8888, 4, 0, rgb32_argb32), |
| 241 | | ENTRY(RGB32, RGB888, 4, 0, NULL), |
| 233 | ENTRY(RGB32, ARGB8888, rgb32_argb32), |
| 234 | ENTRY(RGB32, RGB888, rgb32_rgb32), |
| 242 | 235 | |
| 243 | | ENTRY(RGB32_PALETTED, ARGB8888, 4, 0, rgb32pal_argb32), |
| 244 | | ENTRY(RGB32_PALETTED, RGB888, 4, 0, rgb32pal_argb32), |
| 236 | ENTRY(RGB32_PALETTED, ARGB8888, rgb32pal_argb32), |
| 237 | ENTRY(RGB32_PALETTED, RGB888, rgb32pal_argb32), |
| 245 | 238 | |
| 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), |
| 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), |
| 251 | 244 | |
| 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), |
| 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), |
| 257 | 250 | |
| 258 | | ENTRY(PALETTE16, ARGB8888, 4, 0, pal16_argb32), |
| 259 | | ENTRY(PALETTE16, RGB888, 4, 0, pal16_argb32), |
| 251 | ENTRY(PALETTE16, ARGB8888, pal16_argb32), |
| 252 | ENTRY(PALETTE16, RGB888, pal16_argb32), |
| 260 | 253 | |
| 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), |
| 254 | ENTRY(RGB15, RGB555, rgb15_rgb555), |
| 255 | ENTRY(RGB15, ARGB1555, rgb15_argb1555), |
| 256 | ENTRY(RGB15, ARGB8888, rgb15_argb32), |
| 257 | ENTRY(RGB15, RGB888, rgb15_argb32), |
| 265 | 258 | |
| 266 | | ENTRY(RGB15_PALETTED, ARGB8888, 4, 0, rgb15pal_argb32), |
| 267 | | ENTRY(RGB15_PALETTED, RGB888, 4, 0, rgb15pal_argb32), |
| 259 | ENTRY(RGB15_PALETTED, ARGB8888, rgb15pal_argb32), |
| 260 | ENTRY(RGB15_PALETTED, RGB888, rgb15pal_argb32), |
| 268 | 261 | |
| 269 | | ENTRY(PALETTE16A, ARGB8888, 4, 0, pal16a_argb32), |
| 270 | | ENTRY(PALETTE16A, RGB888, 4, 0, pal16a_rgb32), |
| 262 | ENTRY(PALETTE16A, ARGB8888, pal16a_argb32), |
| 263 | ENTRY(PALETTE16A, RGB888, pal16a_rgb32), |
| 271 | 264 | |
| 272 | 265 | /* rotation */ |
| 273 | | ENTRY(ARGB32, ARGB8888, 4, 1, rot_argb32_argb32), |
| 274 | | ENTRY_LR(ARGB32, RGB888, 4, 1, rot_argb32_rgb32), |
| 266 | ENTRY(ARGB32, ARGB8888, rot_argb32_argb32), |
| 267 | ENTRY_LR(ARGB32, RGB888, rot_argb32_rgb32), |
| 275 | 268 | /* Entry primarily for directfb */ |
| 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), |
| 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), |
| 279 | 272 | |
| 280 | | ENTRY(RGB32, ARGB8888, 4, 1, rot_rgb32_argb32), |
| 281 | | ENTRY(RGB32, RGB888, 4, 1, rot_argb32_argb32), |
| 273 | ENTRY(RGB32, ARGB8888, rot_rgb32_argb32), |
| 274 | ENTRY(RGB32, RGB888, rot_argb32_argb32), |
| 282 | 275 | |
| 283 | | ENTRY(RGB32_PALETTED, ARGB8888, 4, 1, rot_rgb32pal_argb32), |
| 284 | | ENTRY(RGB32_PALETTED, RGB888, 4, 1, rot_rgb32pal_argb32), |
| 276 | ENTRY(RGB32_PALETTED, ARGB8888, rot_rgb32pal_argb32), |
| 277 | ENTRY(RGB32_PALETTED, RGB888, rot_rgb32pal_argb32), |
| 285 | 278 | |
| 286 | | ENTRY(YUY16, ARGB8888, 4, 1, rot_yuv16_argb32), |
| 287 | | ENTRY(YUY16, RGB888, 4, 1, rot_yuv16_argb32), |
| 279 | ENTRY(YUY16, ARGB8888, rot_yuv16_argb32rot), |
| 280 | ENTRY(YUY16, RGB888, rot_yuv16_argb32rot), |
| 288 | 281 | |
| 289 | | ENTRY(YUY16_PALETTED, ARGB8888, 4, 1, rot_yuv16pal_argb32), |
| 290 | | ENTRY(YUY16_PALETTED, RGB888, 4, 1, rot_yuv16pal_argb32), |
| 282 | ENTRY(YUY16_PALETTED, ARGB8888, rot_yuv16pal_argb32rot), |
| 283 | ENTRY(YUY16_PALETTED, RGB888, rot_yuv16pal_argb32rot), |
| 291 | 284 | |
| 292 | | ENTRY(PALETTE16, ARGB8888, 4, 1, rot_pal16_argb32), |
| 293 | | ENTRY(PALETTE16, RGB888, 4, 1, rot_pal16_argb32), |
| 285 | ENTRY(PALETTE16, ARGB8888, rot_pal16_argb32), |
| 286 | ENTRY(PALETTE16, RGB888, rot_pal16_argb32), |
| 294 | 287 | |
| 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), |
| 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), |
| 299 | 292 | |
| 300 | | ENTRY(RGB15_PALETTED, ARGB8888, 4, 1, rot_rgb15pal_argb32), |
| 301 | | ENTRY(RGB15_PALETTED, RGB888, 4, 1, rot_rgb15pal_argb32), |
| 293 | ENTRY(RGB15_PALETTED, ARGB8888, rot_rgb15pal_argb32), |
| 294 | ENTRY(RGB15_PALETTED, RGB888, rot_rgb15pal_argb32), |
| 302 | 295 | |
| 303 | | ENTRY(PALETTE16A, ARGB8888, 4, 1, rot_pal16a_argb32), |
| 304 | | ENTRY(PALETTE16A, RGB888, 4, 1, rot_pal16a_rgb32), |
| 296 | ENTRY(PALETTE16A, ARGB8888, rot_pal16a_argb32), |
| 297 | ENTRY(PALETTE16A, RGB888, rot_pal16a_rgb32), |
| 305 | 298 | |
| 306 | 299 | { -1 }, |
| 307 | 300 | }; |
| r243239 | r243240 | |
| 394 | 387 | SDL_RenderCopy(m_renderer, m_texture_id, NULL, &target_rect); |
| 395 | 388 | } |
| 396 | 389 | |
| 397 | | void sdl_info::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y) |
| 390 | void sdl_info13::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y) |
| 398 | 391 | { |
| 399 | 392 | SDL_Rect target_rect; |
| 400 | 393 | |
| r243239 | r243240 | |
| 548 | 541 | { |
| 549 | 542 | if (bi->pixel_count) |
| 550 | 543 | osd_printf_verbose("%s -> %s %s blendmode 0x%02x, %d samples: %d KPixel/sec\n", bi->srcname, bi->dstname, |
| 551 | | bi->rotate ? "rot" : "norot", bi->bm_mask, bi->samples, |
| 544 | bi->blitter->m_is_rot ? "rot" : "norot", bi->bm_mask, bi->samples, |
| 552 | 545 | (int) bi->perf); |
| 553 | 546 | freeme = bi; |
| 554 | 547 | bi = bi->next; |
| r243239 | r243240 | |
| 580 | 573 | static int drawsdl2_window_create(sdl_window_info *window, int width, int height) |
| 581 | 574 | { |
| 582 | 575 | // allocate memory for our structures |
| 583 | | sdl_info *sdl = global_alloc(sdl_info); |
| 576 | sdl_info13 *sdl = global_alloc(sdl_info13); |
| 584 | 577 | |
| 585 | 578 | /* FIXME: On Ubuntu and potentially other Linux OS you should use |
| 586 | 579 | * to disable panning. This has to be done before every invocation of mame. |
| r243239 | r243240 | |
| 596 | 589 | UINT32 extra_flags = (window->fullscreen() ? |
| 597 | 590 | SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE); |
| 598 | 591 | |
| 592 | #if defined(SDLMAME_WIN32) |
| 593 | SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); |
| 594 | #endif |
| 599 | 595 | // create the SDL window |
| 600 | 596 | window->sdl_window = SDL_CreateWindow(window->title, window->monitor()->monitor_x, 0, |
| 601 | 597 | width, height, extra_flags); |
| r243239 | r243240 | |
| 610 | 606 | mode.h = height; |
| 611 | 607 | if (window->refresh) |
| 612 | 608 | mode.refresh_rate = window->refresh; |
| 609 | #if 0 |
| 613 | 610 | if (window->depth) |
| 614 | 611 | { |
| 615 | 612 | switch (window->depth) |
| r243239 | r243240 | |
| 630 | 627 | osd_printf_warning("Ignoring depth %d\n", window->depth); |
| 631 | 628 | } |
| 632 | 629 | } |
| 630 | #endif |
| 631 | |
| 633 | 632 | SDL_SetWindowDisplayMode(window->sdl_window, &mode); // Try to set mode |
| 634 | 633 | #ifndef SDLMAME_WIN32 |
| 635 | 634 | /* FIXME: Warp the mouse to 0,0 in case a virtual desktop resolution |
| r243239 | r243240 | |
| 640 | 639 | #endif |
| 641 | 640 | } |
| 642 | 641 | else |
| 643 | | SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop |
| 644 | | |
| 642 | { |
| 643 | //SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop |
| 644 | } |
| 645 | 645 | // create renderer |
| 646 | 646 | |
| 647 | 647 | if (video_config.waitvsync) |
| r243239 | r243240 | |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | //SDL_SelectRenderer(window->sdl_window); |
| 658 | | |
| 659 | 658 | SDL_ShowWindow(window->sdl_window); |
| 660 | 659 | //SDL_SetWindowFullscreen(window->window_id, window->fullscreen); |
| 661 | 660 | SDL_RaiseWindow(window->sdl_window); |
| 661 | |
| 662 | 662 | SDL_GetWindowSize(window->sdl_window, &window->width, &window->height); |
| 663 | 663 | |
| 664 | 664 | sdl->m_blittimer = 3; |
| r243239 | r243240 | |
| 674 | 674 | |
| 675 | 675 | static void drawsdl2_window_resize(sdl_window_info *window, int width, int height) |
| 676 | 676 | { |
| 677 | | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 677 | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 678 | 678 | |
| 679 | 679 | sdl->m_resize_pending = 1; |
| 680 | 680 | sdl->m_resize_height = height; |
| r243239 | r243240 | |
| 693 | 693 | |
| 694 | 694 | static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt) |
| 695 | 695 | { |
| 696 | | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 696 | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 697 | 697 | |
| 698 | 698 | *xt = x - sdl->m_hofs; |
| 699 | 699 | *yt = y - sdl->m_vofs; |
| r243239 | r243240 | |
| 719 | 719 | |
| 720 | 720 | static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update) |
| 721 | 721 | { |
| 722 | | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 722 | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 723 | 723 | render_primitive *prim; |
| 724 | 724 | texture_info *texture=NULL; |
| 725 | 725 | float vofs, hofs; |
| r243239 | r243240 | |
| 833 | 833 | |
| 834 | 834 | static void drawsdl2_window_clear(sdl_window_info *window) |
| 835 | 835 | { |
| 836 | | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 836 | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 837 | 837 | |
| 838 | 838 | sdl->m_blittimer = 2; |
| 839 | 839 | } |
| r243239 | r243240 | |
| 845 | 845 | |
| 846 | 846 | static void drawsdl2_window_destroy(sdl_window_info *window) |
| 847 | 847 | { |
| 848 | | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 848 | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 849 | 849 | |
| 850 | 850 | // skip if nothing |
| 851 | 851 | if (sdl == NULL) |
| r243239 | r243240 | |
| 884 | 884 | |
| 885 | 885 | for (bi = blit_info[m_format]; bi != NULL; bi = bi->next) |
| 886 | 886 | { |
| 887 | | if ((m_is_rotated == bi->rotate) |
| 887 | if ((m_is_rotated == bi->blitter->m_is_rot) |
| 888 | 888 | && (m_sdl_blendmode == bi->bm_mask)) |
| 889 | 889 | { |
| 890 | 890 | if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname)) |
| r243239 | r243240 | |
| 905 | 905 | /* try last resort handlers */ |
| 906 | 906 | for (bi = blit_info[m_format]; bi != NULL; bi = bi->next) |
| 907 | 907 | { |
| 908 | | if ((m_is_rotated == bi->rotate) |
| 908 | if ((m_is_rotated == bi->blitter->m_is_rot) |
| 909 | 909 | && (m_sdl_blendmode == bi->bm_mask)) |
| 910 | 910 | if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname)) |
| 911 | 911 | return bi; |
| r243239 | r243240 | |
| 914 | 914 | return NULL; |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | // FIXME: |
| 918 | const bool texture_info::is_pixels_owned() const |
| 919 | { // do we own / allocated it ? |
| 920 | return ((m_sdl_access == SDL_TEXTUREACCESS_STATIC) |
| 921 | && (m_copyinfo->blitter->m_is_passthrough)); |
| 922 | } |
| 923 | |
| 917 | 924 | //============================================================ |
| 918 | 925 | // texture_info::matches |
| 919 | 926 | //============================================================ |
| r243239 | r243240 | |
| 943 | 950 | m_flags = flags; |
| 944 | 951 | m_texinfo = texsource; |
| 945 | 952 | m_texinfo.seqid = -1; // force set data |
| 946 | | m_is_rotated = FALSE; |
| 953 | m_is_rotated = false; |
| 947 | 954 | m_setup = setup; |
| 948 | 955 | m_sdl_blendmode = map_blendmode(PRIMFLAG_GET_BLENDMODE(flags)); |
| 949 | 956 | m_pitch = 0; |
| r243239 | r243240 | |
| 972 | 979 | |
| 973 | 980 | if (setup.rotwidth != m_texinfo.width || setup.rotheight != m_texinfo.height |
| 974 | 981 | || setup.dudx < 0 || setup.dvdy < 0) |
| 975 | | m_is_rotated = TRUE; |
| 982 | m_is_rotated = true; |
| 976 | 983 | else |
| 977 | | m_is_rotated = FALSE; |
| 984 | m_is_rotated = false; |
| 978 | 985 | |
| 979 | 986 | //m_sdl_access = SDL_TEXTUREACCESS_STATIC; |
| 980 | 987 | m_sdl_access = SDL_TEXTUREACCESS_STREAMING; |
| r243239 | r243240 | |
| 996 | 1003 | |
| 997 | 1004 | if (m_sdl_access == SDL_TEXTUREACCESS_STATIC) |
| 998 | 1005 | { |
| 999 | | if (m_copyinfo->func != NULL) |
| 1000 | | m_pixels = malloc(m_setup.rotwidth * m_setup.rotheight * m_copyinfo->dst_bpp); |
| 1006 | if (m_copyinfo->blitter->m_is_passthrough) |
| 1007 | m_pixels = NULL; |
| 1001 | 1008 | else |
| 1002 | | m_pixels = NULL; |
| 1009 | m_pixels = malloc(m_setup.rotwidth * m_setup.rotheight * m_copyinfo->blitter->m_dest_bpp); |
| 1003 | 1010 | } |
| 1004 | 1011 | m_last_access = osd_ticks(); |
| 1005 | 1012 | |
| r243239 | r243240 | |
| 1021 | 1028 | m_copyinfo->time -= osd_ticks(); |
| 1022 | 1029 | if (m_sdl_access == SDL_TEXTUREACCESS_STATIC) |
| 1023 | 1030 | { |
| 1024 | | if ( m_copyinfo->func ) |
| 1031 | if ( m_copyinfo->blitter->m_is_passthrough ) |
| 1025 | 1032 | { |
| 1026 | | m_pitch = m_setup.rotwidth * m_copyinfo->dst_bpp; |
| 1027 | | m_copyinfo->func(this, &texsource); |
| 1033 | m_pixels = texsource.base; |
| 1034 | m_pitch = m_texinfo.rowpixels * m_copyinfo->blitter->m_dest_bpp; |
| 1028 | 1035 | } |
| 1029 | 1036 | else |
| 1030 | 1037 | { |
| 1031 | | m_pixels = texsource.base; |
| 1032 | | m_pitch = m_texinfo.rowpixels * m_copyinfo->dst_bpp; |
| 1038 | m_pitch = m_setup.rotwidth * m_copyinfo->blitter->m_dest_bpp; |
| 1039 | m_copyinfo->blitter->texop(this, &texsource); |
| 1033 | 1040 | } |
| 1034 | 1041 | SDL_UpdateTexture(m_texture_id, NULL, m_pixels, m_pitch); |
| 1035 | 1042 | } |
| 1036 | 1043 | else |
| 1037 | 1044 | { |
| 1038 | 1045 | SDL_LockTexture(m_texture_id, NULL, (void **) &m_pixels, &m_pitch); |
| 1039 | | if ( m_copyinfo->func ) |
| 1040 | | m_copyinfo->func(this, &texsource); |
| 1041 | | else |
| 1046 | if ( m_copyinfo->blitter->m_is_passthrough ) |
| 1042 | 1047 | { |
| 1043 | 1048 | UINT8 *src = (UINT8 *) texsource.base; |
| 1044 | 1049 | UINT8 *dst = (UINT8 *) m_pixels; |
| 1045 | | int spitch = texsource.rowpixels * m_copyinfo->dst_bpp; |
| 1046 | | int num = texsource.width * m_copyinfo->dst_bpp; |
| 1050 | int spitch = texsource.rowpixels * m_copyinfo->blitter->m_dest_bpp; |
| 1051 | int num = texsource.width * m_copyinfo->blitter->m_dest_bpp; |
| 1047 | 1052 | int h = texsource.height; |
| 1048 | 1053 | while (h--) { |
| 1049 | 1054 | memcpy(dst, src, num); |
| r243239 | r243240 | |
| 1051 | 1056 | dst += m_pitch; |
| 1052 | 1057 | } |
| 1053 | 1058 | } |
| 1059 | else |
| 1060 | m_copyinfo->blitter->texop(this, &texsource); |
| 1054 | 1061 | SDL_UnlockTexture(m_texture_id); |
| 1055 | 1062 | } |
| 1056 | 1063 | m_copyinfo->time += osd_ticks(); |
| r243239 | r243240 | |
| 1111 | 1118 | // texture_find |
| 1112 | 1119 | //============================================================ |
| 1113 | 1120 | |
| 1114 | | texture_info *sdl_info::texture_find(const render_primitive &prim, const quad_setup_data &setup) |
| 1121 | texture_info *sdl_info13::texture_find(const render_primitive &prim, const quad_setup_data &setup) |
| 1115 | 1122 | { |
| 1116 | 1123 | HashT texhash = texture_compute_hash(prim.texture, prim.flags); |
| 1117 | 1124 | texture_info *texture; |
| r243239 | r243240 | |
| 1148 | 1155 | // texture_update |
| 1149 | 1156 | //============================================================ |
| 1150 | 1157 | |
| 1151 | | texture_info * sdl_info::texture_update(const render_primitive &prim) |
| 1158 | texture_info * sdl_info13::texture_update(const render_primitive &prim) |
| 1152 | 1159 | { |
| 1153 | 1160 | quad_setup_data setup; |
| 1154 | 1161 | texture_info *texture; |
| r243239 | r243240 | |
| 1182 | 1189 | |
| 1183 | 1190 | static void drawsdl2_destroy_all_textures(sdl_window_info *window) |
| 1184 | 1191 | { |
| 1185 | | sdl_info *sdl = (sdl_info *) window->dxdata; |
| 1192 | sdl_info13 *sdl = (sdl_info13 *) window->dxdata; |
| 1186 | 1193 | |
| 1187 | 1194 | if (sdl == NULL) |
| 1188 | 1195 | return; |