Previous 199869 Revisions Next

r34187 Sunday 4th January, 2015 at 15:23:45 UTC by Ramiro Polla
Run build tools based on build OS
[/trunk]makefile
[src/build]build.mak
[src/mame/drivers]aleck64.c
[src/osd/sdl]blit13.h draw13.c drawogl.c drawsdl.c sdl.mak sdlwork.c window.c window.h

trunk/makefile
r242698r242699
340340EXE = .exe
341341endif
342342
343ifndef BUILD_EXE
344BUILD_EXE = $(EXE)
343# extension for build tools
344BUILD_EXE =
345
346ifeq ($(OS),Windows_NT)
347BUILD_EXE = .exe
345348endif
349ifneq ($(OS2_SHELL),)
350BUILD_EXE = .exe
351endif
346352
347353# compiler, linker and utilities
348354ifneq ($(TARGETOS),emscripten)
r242698r242699
350356CC = @gcc
351357LD = @g++
352358endif
353MD = -mkdir$(EXE)
359MD = -mkdir$(BUILD_EXE)
354360RM = @rm -f
355361OBJDUMP = @objdump
356362PYTHON = @python
trunk/src/build/build.mak
r242698r242699
3131VERINFO = $(VERINFO_TARGET)
3232
3333ifneq ($(TERM),cygwin)
34ifeq ($(TARGETOS),win32)
34ifeq ($(OS),Windows_NT)
3535MAKEDEP = $(subst /,\,$(MAKEDEP_TARGET))
3636MAKEMAK = $(subst /,\,$(MAKEMAK_TARGET))
3737MAKELIST = $(subst /,\,$(MAKELIST_TARGET))
trunk/src/mame/drivers/aleck64.c
r242698r242699
881881   PIF_BOOTROM
882882
883883   ROM_REGION32_BE( 0x4000000, "user2", 0 )
884   ROM_LOAD16_WORD_SWAP( "nus-zhaj.u3", 0x000000, 0x0800000, BAD_DUMP CRC(95258ba2) SHA1(0299b8fb9a8b1b24428d0f340f6bf1cfaf99c672) )
884   ROM_LOAD16_WORD_SWAP( "nus-zhaj.u3", 0x000000, 0x0800000,  CRC(95258ba2) SHA1(0299b8fb9a8b1b24428d0f340f6bf1cfaf99c672) )
885885
886886   ROM_REGION16_BE( 0x80, "normpoint", 0 )
887887   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
895895   PIF_BOOTROM
896896
897897   ROM_REGION32_BE( 0x4000000, "user2", 0 )
898   ROM_LOAD16_WORD_SWAP( "nus-zcaj.u4", 0x000000, 0x1000000, CRC(ec4563fc) SHA1(4d5a30873a5850cf4cd1c0bdbe24e1934f163cd0) )
898   ROM_LOAD16_WORD_SWAP( "nus-zcaj.u4", 0x000000, 0x1000000, CRC(ec4563fc) SHA1(4d5a30873a5850cf4cd1c0bdbe24e1934f163cd0) )
899899
900900   ROM_REGION32_BE( 0x100000, "user3", 0 )
901   ROM_LOAD ( "tet-01m.u5", 0x000000, 0x100000, CRC(f78f859b) SHA1(b07c85e0453869fe43792f42081f64a5327e58e6) )
901   ROM_LOAD ( "tet-01m.u5", 0x000000, 0x100000, CRC(f78f859b) SHA1(b07c85e0453869fe43792f42081f64a5327e58e6) )
902902
903903   ROM_REGION32_BE( 0x80, "user4", 0 )
904   ROM_LOAD ( "at24c01.u34", 0x000000, 0x80, CRC(ba7e503f) SHA1(454aa4fdde7d8694d1affaf25cd750fa678686bb) )
904   ROM_LOAD ( "at24c01.u34", 0x000000, 0x80, CRC(ba7e503f) SHA1(454aa4fdde7d8694d1affaf25cd750fa678686bb) )
905905
906906   ROM_REGION16_BE( 0x80, "normpoint", 0 )
907907   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
924924   PIF_BOOTROM
925925
926926   ROM_REGION32_BE( 0x4000000, "user2", 0 )
927   ROM_LOAD16_WORD_SWAP( "nus-zhbj-0.u3", 0x000000, 0xc00000, CRC(a4edac93) SHA1(3794606c008fb69f5d16dcccece94d03da23bf8a) )
927   ROM_LOAD16_WORD_SWAP( "nus-zhbj-0.u3", 0x000000, 0xc00000, CRC(a4edac93) SHA1(3794606c008fb69f5d16dcccece94d03da23bf8a) )
928928
929929   ROM_REGION16_BE( 0x80, "normpoint", 0 )
930930   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
939939   PIF_BOOTROM
940940
941941   ROM_REGION32_BE( 0x4000000, "user2", 0 )
942   ROM_LOAD16_WORD_SWAP( "nus-zsej-0.u2", 0x000000, 0x2000000, CRC(44f40102) SHA1(a78de955f2fcd99dda14e782984368b320eb5415) )
942   ROM_LOAD16_WORD_SWAP( "nus-zsej-0.u2", 0x000000, 0x2000000, CRC(44f40102) SHA1(a78de955f2fcd99dda14e782984368b320eb5415) )
943943
944944   ROM_REGION16_BE( 0x80, "normpoint", 0 )
945945   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
963963   PIF_BOOTROM
964964
965965   ROM_REGION32_BE( 0x4000000, "user2", 0 )
966   ROM_LOAD16_WORD_SWAP( "nus-zsaj-0.u3", 0x000000, 0x800000, CRC(f3220e29) SHA1(06d8b808cc19378b046803f4dc75c7d791b7767f) )
966   ROM_LOAD16_WORD_SWAP( "nus-zsaj-0.u3", 0x000000, 0x800000, CRC(f3220e29) SHA1(06d8b808cc19378b046803f4dc75c7d791b7767f) )
967967
968968   ROM_REGION16_BE( 0x80, "normpoint", 0 )
969969   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
991991   PIF_BOOTROM
992992
993993   ROM_REGION32_BE( 0x4000000, "user2", 0 )
994   ROM_LOAD16_WORD_SWAP( "ua3012--all02.u3", 0x000000, 0x1000000, CRC(904a91a7) SHA1(7dfa3447d2c489c0448c4004dc12d3037c05a0f3) )
994   ROM_LOAD16_WORD_SWAP( "ua3012--all02.u3", 0x000000, 0x1000000, CRC(904a91a7) SHA1(7dfa3447d2c489c0448c4004dc12d3037c05a0f3) )
995995
996996   ROM_REGION32_BE( 0x800000, "user3", 0 )
997   ROM_LOAD16_WORD_SWAP( "nus-zsij-0.u1", 0x000000, 0x800000, CRC(2389576f) SHA1(dc22b2eab4d7a02cb918827a62e6c120b3a84e6c) )
997   ROM_LOAD16_WORD_SWAP( "nus-zsij-0.u1", 0x000000, 0x800000, CRC(2389576f) SHA1(dc22b2eab4d7a02cb918827a62e6c120b3a84e6c) )
998998
999999   ROM_REGION16_BE( 0x80, "normpoint", 0 )
10001000   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
10091009   PIF_BOOTROM
10101010
10111011   ROM_REGION32_BE( 0x4000000, "user2", 0 )
1012   ROM_LOAD16_WORD_SWAP( "ua2011-all02.u3", 0x0000000, 0x1000000, CRC(eb4b96d0) SHA1(e909ea5b71b81087da07821c4f57244576363678) )
1013   ROM_LOAD16_WORD_SWAP( "ua2011-alh02.u4", 0x1000000, 0x1000000, CRC(b8e35ddf) SHA1(7c3e59f6520dc3f0aa592e682fa82e30ffd1f4d0) )
1012   ROM_LOAD16_WORD_SWAP( "ua2011-all02.u3", 0x0000000, 0x1000000,  CRC(eb4b96d0) SHA1(e909ea5b71b81087da07821c4f57244576363678) )
1013   ROM_LOAD16_WORD_SWAP( "ua2011-alh02.u4", 0x1000000, 0x1000000,  CRC(b8e35ddf) SHA1(7c3e59f6520dc3f0aa592e682fa82e30ffd1f4d0) )
10141014
10151015   ROM_REGION32_BE( 0x800000, "user3", 0 )
1016   ROM_LOAD16_WORD_SWAP( "nus-nsij-0.u1", 0x000000, 0x800000, CRC(94cf9f8d) SHA1(cd624d1f5de2be3bec3ece06556a2e39bef66d77) )
1016   ROM_LOAD16_WORD_SWAP( "nus-nsij-0.u1", 0x000000, 0x800000, CRC(94cf9f8d) SHA1(cd624d1f5de2be3bec3ece06556a2e39bef66d77) )
10171017
10181018   ROM_REGION16_BE( 0x80, "normpoint", 0 )
10191019   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
10281028   PIF_BOOTROM
10291029
10301030   ROM_REGION32_BE( 0x4000000, "user2", 0 )
1031   ROM_LOAD16_WORD_SWAP( "ua3088-all01.u3", 0x0000000, 0x1000000, CRC(00db4dbc) SHA1(824fdce01fffdfcbcc9b1fbda4ab389a10b2b418) )
1032   ROM_LOAD16_WORD_SWAP( "ua3088-alh04.u4", 0x1000000, 0x1000000, CRC(c96bc7c0) SHA1(2b6ca1a769dee74e112c2b287dacd0bf46dda091) )
1031   ROM_LOAD16_WORD_SWAP( "ua3088-all01.u3", 0x0000000, 0x1000000,  CRC(00db4dbc) SHA1(824fdce01fffdfcbcc9b1fbda4ab389a10b2b418) )
1032   ROM_LOAD16_WORD_SWAP( "ua3088-alh04.u4", 0x1000000, 0x1000000,  CRC(c96bc7c0) SHA1(2b6ca1a769dee74e112c2b287dacd0bf46dda091) )
10331033
10341034   ROM_REGION32_BE( 0x800000, "user3", 0 )
1035   ROM_LOAD16_WORD_SWAP( "nus-zsij-0.u1", 0x000000, 0x800000, CRC(2389576f) SHA1(dc22b2eab4d7a02cb918827a62e6c120b3a84e6c) ) // same as tower & shaft
1035   ROM_LOAD16_WORD_SWAP( "nus-zsij-0.u1", 0x000000, 0x800000,   CRC(2389576f) SHA1(dc22b2eab4d7a02cb918827a62e6c120b3a84e6c) ) // same as tower & shaft
10361036
10371037   ROM_REGION16_BE( 0x80, "normpoint", 0 )
10381038   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
10461046   PIF_BOOTROM
10471047
10481048   ROM_REGION32_BE( 0x4000000, "user2", 0 )
1049   ROM_LOAD16_WORD_SWAP( "ua3003-all01.u3", 0x0000000, 0x1000000, CRC(f362fa82) SHA1(4f41ee23edc18110be1218ba333d1c58376ab175) )
1050   ROM_LOAD16_WORD_SWAP( "ua3003-alh01.u4", 0x1000000, 0x1000000, CRC(47c56387) SHA1(c8cc6c0a456b593aef711d0a75b2342ba2f8203f) )
1049   ROM_LOAD16_WORD_SWAP( "ua3003-all01.u3", 0x0000000, 0x1000000,  CRC(f362fa82) SHA1(4f41ee23edc18110be1218ba333d1c58376ab175) )
1050   ROM_LOAD16_WORD_SWAP( "ua3003-alh01.u4", 0x1000000, 0x1000000,  CRC(47c56387) SHA1(c8cc6c0a456b593aef711d0a75b2342ba2f8203f) )
10511051
10521052   ROM_REGION32_BE( 0x800000, "user3", 0 )
10531053   ROM_LOAD16_WORD_SWAP( "nus-zsij-0.u1", 0x000000, 0x800000, CRC(547d8122) SHA1(347f0785767265acb0f0c21646e06cbe6f561821) )
r242698r242699
10651065   PIF_BOOTROM
10661066
10671067   ROM_REGION32_BE( 0x4000000, "user2", 0 )
1068   ROM_LOAD16_WORD_SWAP( "nus-zscj.u3", 0x000000, 0x800000, CRC(8b36eb91) SHA1(179745625c16c6813d5f8d29bfd7628783d55806) )
1068   ROM_LOAD16_WORD_SWAP( "nus-zscj.u3", 0x000000, 0x800000, CRC(8b36eb91) SHA1(179745625c16c6813d5f8d29bfd7628783d55806) )
10691069
10701070   ROM_REGION16_BE( 0x80, "normpoint", 0 )
10711071   ROM_LOAD( "normpnt.rom", 0x00, 0x80, CRC(e7f2a005) SHA1(c27b4a364a24daeee6e99fd286753fd6216362b4) )
r242698r242699
10791079
10801080
10811081// BIOS
1082GAME( 1998, aleck64,  0,        aleck64, aleck64, aleck64_state,  aleck64, ROT0, "Nintendo / Seta", "Aleck64 PIF BIOS", GAME_IS_BIOS_ROOT)
1082GAME( 1998, aleck64,        0,  aleck64, aleck64, aleck64_state,  aleck64, ROT0, "Nintendo / Seta", "Aleck64 PIF BIOS", GAME_IS_BIOS_ROOT)
10831083
10841084// games
10851085GAME( 1998, 11beat,   aleck64,  aleck64, 11beat, aleck64_state,   aleck64, ROT0, "Hudson", "Eleven Beat", GAME_NOT_WORKING|GAME_NO_SOUND )
trunk/src/osd/sdl/blit13.h
r242698r242699
113113//============================================================
114114
115115#define TEXCOPY_M( _name, _src_type, _dest_type,  _op, _len_div) \
116INLINE void texcopy_##_name (const texture_info *texture, const render_texinfo *texsource) { \
116INLINE void texcopy_##_name (texture_info *texture, const render_texinfo *texsource) { \
117117    ATTR_UNUSED const rgb_t *palbase = texsource->palette(); \
118118   int x, y; \
119119   /* loop over Y */ \
120120   for (y = 0; y < texsource->height; y++) { \
121121      _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); \
122      _dest_type *dst = (_dest_type *)((UINT8 *)texture->pixels + y * texture->pitch); \
123123      x = texsource->width / (_len_div); \
124124      while (x > 0) { \
125125         *dst++ = _op(*src); \
r242698r242699
133133   TEXCOPY_M( _name, _src_type, _dest_type,  _op, 1)
134134
135135#define TEXROT( _name, _src_type, _dest_type, _op) \
136INLINE void texcopy_rot_##_name (const texture_info *texture, const render_texinfo *texsource) { \
136INLINE void texcopy_rot_##_name (texture_info *texture, const render_texinfo *texsource) { \
137137    ATTR_UNUSED const rgb_t *palbase = texsource->palette(); \
138138   int x, y; \
139   const quad_setup_data *setup = &texture->m_setup; \
139   quad_setup_data *setup = &texture->setup; \
140140   int dudx = setup->dudx; \
141141   int dvdx = setup->dvdx; \
142142   /* loop over Y */ \
143143   for (y = 0; y < setup->rotheight; y++) { \
144144      INT32 curu = setup->startu + y * setup->dudy; \
145145      INT32 curv = setup->startv + y * setup->dvdy; \
146      _dest_type *dst = (_dest_type *)((UINT8 *)texture->m_pixels + y * texture->m_pitch); \
146      _dest_type *dst = (_dest_type *)((UINT8 *)texture->pixels + y * texture->pitch); \
147147      x = setup->rotwidth; \
148148      while (x>0) { \
149149         _src_type *src = (_src_type *) texsource->base + (curv >> 16) * texsource->rowpixels + (curu >> 16); \
trunk/src/osd/sdl/draw13.c
r242698r242699
4343
4444
4545//============================================================
46//  Inline functions
46//  MACROS
4747//============================================================
4848
49static inline bool is_opaque(const float &a)
50{
51    return (a >= 1.0f);
52}
49#define IS_OPAQUE(a)        (a >= 1.0f)
50#define IS_TRANSPARENT(a)   (a <  0.0001f)
5351
54static inline bool is_transparent(const float &a)
55{
56    return (a <  0.0001f);
57}
52#define MAX4(a, b, c, d) MAX(a, MAX(b, MAX(c, d)))
53#define MIN4(a, b, c, d) MIN(a, MIN(b, MIN(c, d)))
5854
55
5956//============================================================
6057//  TYPES
6158//============================================================
r242698r242699
6764    : dudx(0), dvdx(0), dudy(0), dvdy(0), startu(0), startv(0),
6865      rotwidth(0), rotheight(0)
6966    {}
70    void compute(const render_primitive &prim);
71
7267   INT32           dudx, dvdx, dudy, dvdy;
7368   INT32           startu, startv;
7469   INT32           rotwidth, rotheight;
7570};
7671
77class texture_info;
72struct texture_info;
7873
79typedef void (*texture_copy_func)(const texture_info *texture, const render_texinfo *texsource);
74typedef void (*texture_copy_func)(texture_info *texture, const render_texinfo *texsource);
8075
81struct copy_info_t {
76struct copy_info {
8277   int                 src_fmt;
8378   Uint32              dst_fmt;
8479   int                 dst_bpp;
r242698r242699
9388   int                 samples;
9489   int                 perf;
9590   /* list */
96   copy_info_t           *next;
91   copy_info           *next;
9792};
9893
99//============================================================
100//  Textures
101//============================================================
102
103struct sdl_info;
104
10594/* texture_info holds information about a texture */
106class texture_info
95struct texture_info
10796{
108    friend class simple_list<texture_info>;
109public:
110    texture_info(SDL_Renderer *renderer, const render_texinfo &texsource, const quad_setup_data &setup, const UINT32 flags);
111    ~texture_info();
97    texture_info()
98    : next(NULL), hash(0), flags(0), rawwidth(0), rawheight(0), format(0),
99      pixels(NULL), pitch(0), pixels_own(0), texture_id(NULL), copyinfo(NULL),
100      sdl_access(0), sdl_blendmode(SDL_BLENDMODE_NONE), is_rotated(0), last_access(0)
101    {
102    }
103   texture_info *      next;               // next texture in the list
112104
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);
105   HashT               hash;               // hash value for the texture (must be >= pointer size)
106   UINT32              flags;              // rendering flags
107   render_texinfo      texinfo;            // copy of the texture info
116108
117    copy_info_t *compute_size_type();
109   int                 rawwidth, rawheight;// raw width/height of the texture
118110
119   void                *m_pixels;            // pixels for the texture
120   int                 m_pitch;
111   int                 format;             // texture format
112   void                *pixels;            // pixels for the texture
113   int                 pitch;
114   int                 pixels_own;         // do we own / allocated it ?
121115
122   copy_info_t         *m_copyinfo;
123   quad_setup_data     m_setup;
116   SDL_Texture         *texture_id;
124117
125   osd_ticks_t         m_last_access;
118   copy_info           *copyinfo;
119   Uint32              sdl_access;
120   SDL_BlendMode       sdl_blendmode;
121   quad_setup_data     setup;
122   int                 is_rotated;
126123
127   int raw_width() const { return m_texinfo.width; }
128    int raw_height() const { return m_texinfo.height; }
129
130    texture_info *next() { return m_next; }
131    const render_texinfo &texinfo() const { return m_texinfo; }
132    render_texinfo &texinfo() { return m_texinfo; }
133
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 m_sdl_access == SDL_TEXTUREACCESS_STATIC
138                && m_copyinfo->func != NULL ;
139    }
140
141private:
142    SDL_Renderer *      m_renderer;
143    render_texinfo      m_texinfo;            // copy of the texture info
144    HashT               m_hash;               // hash value for the texture (must be >= pointer size)
145    UINT32              m_flags;              // rendering flags
146
147    SDL_Texture *       m_texture_id;
148    int                 m_is_rotated;
149
150    int                 m_format;             // texture format
151    SDL_BlendMode       m_sdl_blendmode;
152    Uint32              m_sdl_access;
153
154    texture_info *      m_next;               // next texture in the list
124   osd_ticks_t         last_access;
155125};
156126
157127/* sdl_info is the information about SDL for the current screen */
158128struct sdl_info
159129{
160130    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)
131    : blittimer(0), extra_flags(0), sdl_renderer(NULL), texlist(NULL),
132      texture_max_width(0), texture_max_height(0), last_hofs(0), last_vofs(0),
133      resize_pending(0), resize_width(0), resize_height(0),
134      last_blit_time(0), last_blit_pixels(0)
165135    {}
136   INT32           blittimer;
137   UINT32          extra_flags;
166138
167    void render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y);
139   SDL_Renderer    *sdl_renderer;
140   texture_info *  texlist;                // list of active textures
141   INT32           texture_max_width;      // texture maximum width
142   INT32           texture_max_height;     // texture maximum height
168143
169    texture_info *texture_find(const render_primitive &prim, const quad_setup_data &setup);
170    texture_info *texture_update(const render_primitive &prim);
144   float           last_hofs;
145   float           last_vofs;
171146
172   INT32           m_blittimer;
173
174   SDL_Renderer *  m_renderer;
175   simple_list<texture_info>  m_texlist;                // list of active textures
176
177   float           m_hofs;
178   float           m_vofs;
179
180147   // resize information
181148
182   UINT8           m_resize_pending;
183   UINT32          m_resize_width;
184   UINT32          m_resize_height;
149   UINT8           resize_pending;
150   UINT32          resize_width;
151   UINT32          resize_height;
185152
186153   // Stats
187   INT64           m_last_blit_time;
188   INT64           m_last_blit_pixels;
154   INT64           last_blit_time;
155   INT64           last_blit_pixels;
189156};
190157
191158//============================================================
r242698r242699
200167static void drawsdl2_window_resize(sdl_window_info *window, int width, int height);
201168static void drawsdl2_window_destroy(sdl_window_info *window);
202169static int drawsdl2_window_draw(sdl_window_info *window, UINT32 dc, int update);
203static void drawsdl2_set_target_bounds(sdl_window_info *window);
170static render_primitive_list &drawsdl2_window_get_primitives(sdl_window_info *window);
204171static void drawsdl2_destroy_all_textures(sdl_window_info *window);
205172static void drawsdl2_window_clear(sdl_window_info *window);
206173static int drawsdl2_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt);
174static void drawsdl2_destroy_texture(sdl_info *sdl, texture_info *texture);
207175
208176//============================================================
177//  Textures
178//============================================================
179
180static void texture_set_data(sdl_info *sdl, texture_info *texture, const render_texinfo *texsource, UINT32 flags);
181static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, quad_setup_data *setup, UINT32 flags);
182static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim, quad_setup_data *setup);
183static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim);
184
185
186//============================================================
209187//  TEXCOPY FUNCS
210188//============================================================
211189
r242698r242699
224202#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}
225203#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}
226204
227static copy_info_t blit_info_default[] =
205static copy_info blit_info_default[] =
228206{
229207   /* no rotation */
230208   ENTRY(ARGB32,           ARGB8888,   4, 0, NULL),
231209   ENTRY_LR(ARGB32,        RGB888,     4, 0, argb32_rgb32),
232   /* Entry primarily for directfb */
210   /* Entry for primarily for directfb */
233211   ENTRY_BM(ARGB32,        RGB888,     4, 0, argb32_rgb32, SDL_BLENDMODE_ADD),
234212   ENTRY_BM(ARGB32,        RGB888,     4, 0, argb32_rgb32, SDL_BLENDMODE_MOD),
235213   ENTRY_BM(ARGB32,        RGB888,     4, 0, argb32_rgb32, SDL_BLENDMODE_NONE),
r242698r242699
269247   /* rotation */
270248   ENTRY(ARGB32,           ARGB8888,   4, 1, rot_argb32_argb32),
271249   ENTRY_LR(ARGB32,        RGB888,     4, 1, rot_argb32_rgb32),
272   /* Entry primarily for directfb */
250   /* Entry for primarily for directfb */
273251   ENTRY_BM(ARGB32,        RGB888,     4, 1, rot_argb32_rgb32, SDL_BLENDMODE_ADD),
274252   ENTRY_BM(ARGB32,        RGB888,     4, 1, rot_argb32_rgb32, SDL_BLENDMODE_MOD),
275253   ENTRY_BM(ARGB32,        RGB888,     4, 1, rot_argb32_rgb32, SDL_BLENDMODE_NONE),
r242698r242699
303281{ -1 },
304282};
305283
306static copy_info_t *blit_info[SDL_TEXFORMAT_LAST+1];
284static copy_info *blit_info[SDL_TEXFORMAT_LAST+1];
307285
308286static struct
309287{
r242698r242699
322300   return floor(f + 0.5f);
323301}
324302
325INLINE HashT texture_compute_hash(const render_texinfo &texture, const UINT32 flags)
303INLINE HashT texture_compute_hash(const render_texinfo *texture, UINT32 flags)
326304{
327   return (HashT)texture.base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
305   return (HashT)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
328306}
329307
330INLINE SDL_BlendMode map_blendmode(const int blendmode)
308INLINE SDL_BlendMode map_blendmode(int blendmode)
331309{
332310   switch (blendmode)
333311   {
r242698r242699
353331   UINT32 sa = (UINT32)(255.0f * color->a);
354332
355333
356   if (color->r >= 1.0f && color->g >= 1.0f && color->b >= 1.0f && is_opaque(color->a))
334   if (color->r >= 1.0f && color->g >= 1.0f && color->b >= 1.0f && IS_OPAQUE(color->a))
357335   {
358336      SDL_SetTextureColorMod(texture_id, 0xFF, 0xFF, 0xFF);
359337      SDL_SetTextureAlphaMod(texture_id, 0xFF);
360338   }
361339   /* coloring-only case */
362   else if (is_opaque(color->a))
340   else if (IS_OPAQUE(color->a))
363341   {
364342      SDL_SetTextureColorMod(texture_id, sr, sg, sb);
365343      SDL_SetTextureAlphaMod(texture_id, 0xFF);
366344   }
367345   /* alpha and/or coloring case */
368   else if (!is_transparent(color->a))
346   else if (!IS_TRANSPARENT(color->a))
369347   {
370348      SDL_SetTextureColorMod(texture_id, sr, sg, sb);
371349      SDL_SetTextureAlphaMod(texture_id, sa);
r242698r242699
377355   }
378356}
379357
380void texture_info::render_quad(const render_primitive *prim, const int x, const int y)
358INLINE void render_quad(sdl_info *sdl, texture_info *texture, render_primitive *prim, int x, int y)
381359{
360   SDL_Texture *texture_id;
382361   SDL_Rect target_rect;
383362
384363   target_rect.x = x;
r242698r242699
386365   target_rect.w = round_nearest(prim->bounds.x1 - prim->bounds.x0);
387366   target_rect.h = round_nearest(prim->bounds.y1 - prim->bounds.y0);
388367
368   if (texture)
369   {
370      texture_id = texture->texture_id;
371
372      texture->copyinfo->time -= osd_ticks();
389373#if 0
390   // no longer supported in SDL2
391    if ((PRIMFLAG_GET_SCREENTEX(prim->m_flags)) && video_config.filter)
392    {
393        SDL_SetTextureScaleMode(texture->m_texture_id,  DRAW2_SCALEMODE_BEST);
394    }
395    else
396    {
397        SDL_SetTextureScaleMode(texture->m_texture_id,  DRAW2_SCALEMODE_NEAREST);
398    }
374      if ((PRIMFLAG_GET_SCREENTEX(prim->flags)) && video_config.filter)
375      {
376         SDL_SetTextureScaleMode(texture->texture_id,  DRAW2_SCALEMODE_BEST);
377      }
378      else
379      {
380         SDL_SetTextureScaleMode(texture->texture_id,  DRAW2_SCALEMODE_NEAREST);
381      }
399382#endif
400    SDL_SetTextureBlendMode(m_texture_id, m_sdl_blendmode);
401    set_coloralphamode(m_texture_id, &prim->color);
402    SDL_RenderCopy(m_renderer,  m_texture_id, NULL, &target_rect);
383      SDL_SetTextureBlendMode(texture_id, texture->sdl_blendmode);
384      set_coloralphamode(texture_id, &prim->color);
385      SDL_RenderCopy(sdl->sdl_renderer,  texture_id, NULL, &target_rect);
386      texture->copyinfo->time += osd_ticks();
387
388      texture->copyinfo->pixel_count += MAX(STAT_PIXEL_THRESHOLD , (texture->rawwidth * texture->rawheight));
389      if (sdl->last_blit_pixels)
390      {
391         texture->copyinfo->time += (sdl->last_blit_time * (INT64) (texture->rawwidth * texture->rawheight)) / (INT64) sdl->last_blit_pixels;
392      }
393      texture->copyinfo->samples++;
394      texture->copyinfo->perf = ( texture->copyinfo->pixel_count * (osd_ticks_per_second()/1000)) / texture->copyinfo->time;
395   }
396   else
397   {
398      UINT32 sr = (UINT32)(255.0f * prim->color.r);
399      UINT32 sg = (UINT32)(255.0f * prim->color.g);
400      UINT32 sb = (UINT32)(255.0f * prim->color.b);
401      UINT32 sa = (UINT32)(255.0f * prim->color.a);
402
403      SDL_SetRenderDrawBlendMode(sdl->sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
404      SDL_SetRenderDrawColor(sdl->sdl_renderer, sr, sg, sb, sa);
405      SDL_RenderFillRect(sdl->sdl_renderer, &target_rect);
406   }
403407}
404408
405void sdl_info::render_quad(texture_info *texture, const render_primitive *prim, const int x, const int y)
409#if 0
410static int RendererSupportsFormat(Uint32 format, Uint32 access, const char *sformat)
406411{
407    SDL_Rect target_rect;
412   struct SDL_RendererInfo render_info;
413   int i;
408414
409    target_rect.x = x;
410    target_rect.y = y;
411    target_rect.w = round_nearest(prim->bounds.x1 - prim->bounds.x0);
412    target_rect.h = round_nearest(prim->bounds.y1 - prim->bounds.y0);
415   SDL_GetRendererInfo(&render_info);
413416
414    if (texture)
415    {
416        copy_info_t *copyinfo = texture->m_copyinfo;
417        copyinfo->time -= osd_ticks();
418        texture->render_quad(prim, x, y);
419        copyinfo->time += osd_ticks();
420
421        copyinfo->pixel_count += MAX(STAT_PIXEL_THRESHOLD , (texture->raw_width() * texture->raw_height()));
422        if (m_last_blit_pixels)
423        {
424            copyinfo->time += (m_last_blit_time * (INT64) (texture->raw_width() * texture->raw_height())) / (INT64) m_last_blit_pixels;
425        }
426        copyinfo->samples++;
427        copyinfo->perf = ( texture->m_copyinfo->pixel_count * (osd_ticks_per_second()/1000)) / texture->m_copyinfo->time;
428    }
429    else
430    {
431        UINT32 sr = (UINT32)(255.0f * prim->color.r);
432        UINT32 sg = (UINT32)(255.0f * prim->color.g);
433        UINT32 sb = (UINT32)(255.0f * prim->color.b);
434        UINT32 sa = (UINT32)(255.0f * prim->color.a);
435
436        SDL_SetRenderDrawBlendMode(m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
437        SDL_SetRenderDrawColor(m_renderer, sr, sg, sb, sa);
438        SDL_RenderFillRect(m_renderer, &target_rect);
439    }
417   for (i=0; i < render_info.num_texture_formats; i++)
418   {
419      if (format == render_info.texture_formats[i])
420         return 1;
421   }
422   osd_printf_verbose("Pixelformat <%s> not supported\n", sformat);
423   return 0;
440424}
441
425#else
442426static int RendererSupportsFormat(SDL_Renderer *renderer, Uint32 format, Uint32 access, const char *sformat)
443427{
444428   int i;
r242698r242699
465449   fmt_support[i].status = 0;
466450   return 0;
467451}
452#endif
468453
469454//============================================================
470455//  drawsdl2_init
471456//============================================================
472457
473static void add_list(copy_info_t **head, copy_info_t *element, Uint32 bm)
458static void add_list(copy_info **head, copy_info *element, Uint32 bm)
474459{
475   copy_info_t *newci = global_alloc(copy_info_t);
460   copy_info *newci = global_alloc(copy_info);
476461   *newci = *element;
477462
478463   newci->bm_mask = bm;
r242698r242699
480465   *head = newci;
481466}
482467
483static void expand_copy_info(copy_info_t *list)
468static void expand_copy_info(copy_info *list)
484469{
485   copy_info_t   *bi;
470   copy_info   *bi;
486471
487472   for (bi = list; bi->src_fmt != -1; bi++)
488473   {
r242698r242699
521506
522507   // No fatalerror here since not all video drivers support GL !
523508   if (SDL_GL_LoadLibrary(stemp) != 0) // Load library (default for e==NULL
524      osd_printf_warning("Warning: Unable to load opengl library: %s\n", stemp ? stemp : "<default>");
509      osd_printf_verbose("Warning: Unable to load opengl library: %s\n", stemp ? stemp : "<default>");
525510   else
526511      osd_printf_verbose("Loaded opengl shared library: %s\n", stemp ? stemp : "<default>");
527512
r242698r242699
536521static void drawsdl2_exit(void)
537522{
538523   int i;
539   copy_info_t *bi, *freeme;
524   copy_info *bi, *freeme;
540525   for (i = 0; i <= SDL_TEXFORMAT_LAST; i++)
541526      for (bi = blit_info[i]; bi != NULL; )
542527      {
r242698r242699
559544   // fill in the callbacks
560545   window->create = drawsdl2_window_create;
561546   window->resize = drawsdl2_window_resize;
562   window->set_target_bounds = drawsdl2_set_target_bounds;
547   window->get_primitives = drawsdl2_window_get_primitives;
563548   window->draw = drawsdl2_window_draw;
564549   window->destroy = drawsdl2_window_destroy;
565550   window->destroy_all_textures = drawsdl2_destroy_all_textures;
r242698r242699
580565
581566   window->dxdata = sdl;
582567
583   UINT32 extra_flags = (window->fullscreen() ?
568   sdl->extra_flags = (window->fullscreen() ?
584569         SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
585570
586571   // create the SDL window
587572   window->sdl_window = SDL_CreateWindow(window->title, window->monitor()->monitor_x, 0,
588         width, height, extra_flags);
573         width, height, sdl->extra_flags);
589574
590575   if (window->fullscreen() && video_config.switchres)
591576   {
r242698r242699
623608   // create renderer
624609
625610   if (video_config.waitvsync)
626      sdl->m_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
611      sdl->sdl_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
627612   else
628      sdl->m_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_ACCELERATED);
613      sdl->sdl_renderer = SDL_CreateRenderer(window->sdl_window, -1, SDL_RENDERER_ACCELERATED);
629614
630   if (!sdl->m_renderer)
615   if (!sdl->sdl_renderer)
631616   {
632617      fatalerror("Error on creating renderer: %s\n", SDL_GetError());
633618   }
r242698r242699
640625   SDL_GetWindowSize(window->sdl_window, &window->width, &window->height);
641626
642627
643   sdl->m_blittimer = 3;
628   sdl->blittimer = 3;
644629
645   SDL_RenderPresent(sdl->m_renderer);
630   // in case any textures try to come up before these are validated,
631   // OpenGL guarantees all implementations can handle something this size.
632   sdl->texture_max_width = 64;
633   sdl->texture_max_height = 64;
634
635   SDL_RenderPresent(sdl->sdl_renderer);
646636   osd_printf_verbose("Leave drawsdl2_window_create\n");
647637   return 0;
648638}
r242698r242699
655645{
656646   sdl_info *sdl = (sdl_info *) window->dxdata;
657647
658   sdl->m_resize_pending = 1;
659   sdl->m_resize_height = height;
660   sdl->m_resize_width = width;
648   sdl->resize_pending = 1;
649   sdl->resize_height = height;
650   sdl->resize_width = width;
661651
662652   window->width = width;
663653   window->height = height;
664654
665   sdl->m_blittimer = 3;
655   sdl->blittimer = 3;
666656
667657}
668658
r242698r242699
674664{
675665   sdl_info *sdl = (sdl_info *) window->dxdata;
676666
677   *xt = x - sdl->m_hofs;
678   *yt = y - sdl->m_vofs;
667   *xt = x - sdl->last_hofs;
668   *yt = y - sdl->last_vofs;
679669   if (*xt<0 || *xt >= window->blitwidth)
680670      return 0;
681671   if (*yt<0 || *yt >= window->blitheight)
r242698r242699
687677//  drawsdl2_window_get_primitives
688678//============================================================
689679
690static void drawsdl2_set_target_bounds(sdl_window_info *window)
680static render_primitive_list &drawsdl2_window_get_primitives(sdl_window_info *window)
691681{
682   if ((!window->fullscreen()) || (video_config.switchres))
683   {
684      window->blit_surface_size(window->width, window->height);
685   }
686   else
687   {
688      window->blit_surface_size(window->monitor()->center_width, window->monitor()->center_height);
689   }
692690   window->target->set_bounds(window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor()));
691   return window->target->get_primitives();
693692}
694693
695694//============================================================
r242698r242699
709708      return 0;
710709   }
711710
712   if (sdl->m_resize_pending)
711   if (sdl->resize_pending)
713712   {
714      SDL_SetWindowSize(window->sdl_window, sdl->m_resize_width, sdl->m_resize_height);
713      SDL_SetWindowSize(window->sdl_window, sdl->resize_width, sdl->resize_height);
715714      SDL_GetWindowSize(window->sdl_window, &window->width, &window->height);
716      sdl->m_resize_pending = 0;
717      SDL_RenderSetViewport(sdl->m_renderer, NULL);
715      sdl->resize_pending = 0;
716      SDL_RenderSetViewport(sdl->sdl_renderer, NULL);
718717   }
719718
720719   //SDL_SelectRenderer(window->sdl_window);
721720
722   if (sdl->m_blittimer > 0)
721   if (sdl->blittimer > 0)
723722   {
724723      /* SDL Underlays need alpha = 0 ! */
725      SDL_SetRenderDrawBlendMode(sdl->m_renderer, SDL_BLENDMODE_NONE);
724      SDL_SetRenderDrawBlendMode(sdl->sdl_renderer, SDL_BLENDMODE_NONE);
726725      //SDL_SetRenderDrawColor(0,0,0,255);
727      SDL_SetRenderDrawColor(sdl->m_renderer, 0,0,0,0);
728      SDL_RenderFillRect(sdl->m_renderer, NULL);
729      sdl->m_blittimer--;
726      SDL_SetRenderDrawColor(sdl->sdl_renderer, 0,0,0,0);
727      SDL_RenderFillRect(sdl->sdl_renderer, NULL);
728      sdl->blittimer--;
730729   }
731730
732731   // compute centering parameters
r242698r242699
757756      }
758757   }
759758
760   sdl->m_hofs = hofs;
761   sdl->m_vofs = vofs;
759   sdl->last_hofs = hofs;
760   sdl->last_vofs = vofs;
762761
763762   window->primlist->acquire_lock();
764763
r242698r242699
775774            sb = (int)(255.0f * prim->color.b);
776775            sa = (int)(255.0f * prim->color.a);
777776
778            SDL_SetRenderDrawBlendMode(sdl->m_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
779            SDL_SetRenderDrawColor(sdl->m_renderer, sr, sg, sb, sa);
780            SDL_RenderDrawLine(sdl->m_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs,
777            SDL_SetRenderDrawBlendMode(sdl->sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags)));
778            SDL_SetRenderDrawColor(sdl->sdl_renderer, sr, sg, sb, sa);
779            SDL_RenderDrawLine(sdl->sdl_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs,
781780                  prim->bounds.x1 + hofs, prim->bounds.y1 + vofs);
782781            break;
783782         case render_primitive::QUAD:
784            texture = sdl->texture_update(*prim);
783            texture = texture_update(window, prim);
785784            if (texture)
786               blit_pixels += (texture->raw_height() * texture->raw_width());
787            sdl->render_quad(texture, prim,
785               blit_pixels += (texture->rawheight * texture->rawwidth);
786            render_quad(sdl, texture, prim,
788787                  round_nearest(hofs + prim->bounds.x0),
789788                  round_nearest(vofs + prim->bounds.y0));
790789            break;
r242698r242699
795794
796795   window->primlist->release_lock();
797796
798   sdl->m_last_blit_pixels = blit_pixels;
799   sdl->m_last_blit_time = -osd_ticks();
800   SDL_RenderPresent(sdl->m_renderer);
801   sdl->m_last_blit_time += osd_ticks();
797   sdl->last_blit_pixels = blit_pixels;
798   sdl->last_blit_time = -osd_ticks();
799   SDL_RenderPresent(sdl->sdl_renderer);
800   sdl->last_blit_time += osd_ticks();
802801
803802   return 0;
804803}
r242698r242699
812811{
813812   sdl_info *sdl = (sdl_info *) window->dxdata;
814813
815   sdl->m_blittimer = 2;
814   sdl->blittimer = 2;
816815}
817816
818817
r242698r242699
846845//  texture_compute_size and type
847846//============================================================
848847
849copy_info_t *texture_info::compute_size_type()
848static copy_info *texture_compute_size_type(SDL_Renderer *renderer, const render_texinfo *texsource, texture_info *texture, UINT32 flags)
850849{
851   copy_info_t *bi;
852   copy_info_t *result = NULL;
850   copy_info *bi;
851   copy_info *result = NULL;
853852   int maxperf = 0;
853   //int bm = PRIMFLAG_GET_BLENDMODE(flags);
854854
855   for (bi = blit_info[m_format]; bi != NULL; bi = bi->next)
855   for (bi = blit_info[texture->format]; bi != NULL; bi = bi->next)
856856   {
857      if ((m_is_rotated == bi->rotate)
858            && (m_sdl_blendmode == bi->bm_mask))
857      if ((texture->is_rotated == bi->rotate)
858            && (texture->sdl_blendmode == bi->bm_mask))
859859      {
860         if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname))
860         if (RendererSupportsFormat(renderer, bi->dst_fmt, texture->sdl_access, bi->dstname))
861861         {
862             int perf = bi->perf;
863            if (perf == 0)
862            if (bi->perf == 0)
864863               return bi;
865            else if (perf > (maxperf * 102) / 100)
864            else if (bi->perf > (maxperf * 102) / 100)
866865            {
867866               result = bi;
868               maxperf = perf;
867               maxperf = bi->perf;
869868            }
870869         }
871870      }
r242698r242699
873872   if (result)
874873      return result;
875874   /* try last resort handlers */
876   for (bi = blit_info[m_format]; bi != NULL; bi = bi->next)
875   for (bi = blit_info[texture->format]; bi != NULL; bi = bi->next)
877876   {
878      if ((m_is_rotated == bi->rotate)
879         && (m_sdl_blendmode == bi->bm_mask))
880         if (RendererSupportsFormat(m_renderer, bi->dst_fmt, m_sdl_access, bi->dstname))
877      if ((texture->is_rotated == bi->rotate)
878         && (texture->sdl_blendmode == bi->bm_mask))
879         if (RendererSupportsFormat(renderer, bi->dst_fmt, texture->sdl_access, bi->dstname))
881880            return bi;
882881   }
883882   //FIXME: crash implement a -do nothing handler */
r242698r242699
885884}
886885
887886//============================================================
888//  texture_info::matches
887//  texture_create
889888//============================================================
890889
891bool texture_info::matches(const render_primitive &prim, const quad_setup_data &setup)
890static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, quad_setup_data *setup, UINT32 flags)
892891{
893    return  texinfo().base == prim.texture.base &&
894            texinfo().width == prim.texture.width &&
895            texinfo().height == prim.texture.height &&
896            texinfo().rowpixels == prim.texture.rowpixels &&
897            m_setup.dudx == setup.dudx &&
898            m_setup.dvdx == setup.dvdx &&
899            m_setup.dudy == setup.dudy &&
900            m_setup.dvdy == setup.dvdy &&
901            ((flags() ^ prim.flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0;
902}
892   sdl_info *sdl = (sdl_info *) window->dxdata;
893   texture_info *texture;
903894
904//============================================================
905//  texture_create
906//============================================================
895   // allocate a new texture
896   texture = global_alloc(texture_info);
907897
908texture_info::texture_info(SDL_Renderer *renderer, const render_texinfo &texsource, const quad_setup_data &setup, UINT32 flags)
909{
910
911898   // fill in the core data
912    m_renderer = renderer;
913   m_hash = texture_compute_hash(texsource, flags);
914   m_flags = flags;
915   m_texinfo = texsource;
916   m_texinfo.seqid = -1; // force set data
917   m_is_rotated = FALSE;
918   m_setup = setup;
919   m_sdl_blendmode = map_blendmode(PRIMFLAG_GET_BLENDMODE(flags));
920   m_pitch = 0;
899   texture->hash = texture_compute_hash(texsource, flags);
900   texture->flags = flags;
901   texture->texinfo = *texsource;
902   texture->texinfo.seqid = -1; // force set data
903   texture->is_rotated = FALSE;
904   texture->setup = *setup;
905   texture->sdl_blendmode = map_blendmode(PRIMFLAG_GET_BLENDMODE(flags));
921906
922907   switch (PRIMFLAG_GET_TEXFORMAT(flags))
923908   {
924909      case TEXFORMAT_ARGB32:
925         m_format = SDL_TEXFORMAT_ARGB32;
910         texture->format = SDL_TEXFORMAT_ARGB32;
926911         break;
927912      case TEXFORMAT_RGB32:
928         m_format = texsource.palette() ? SDL_TEXFORMAT_RGB32_PALETTED : SDL_TEXFORMAT_RGB32;
913         texture->format = texsource->palette() ? SDL_TEXFORMAT_RGB32_PALETTED : SDL_TEXFORMAT_RGB32;
929914         break;
930915      case TEXFORMAT_PALETTE16:
931         m_format = SDL_TEXFORMAT_PALETTE16;
916         texture->format = SDL_TEXFORMAT_PALETTE16;
932917         break;
933918      case TEXFORMAT_PALETTEA16:
934         m_format = SDL_TEXFORMAT_PALETTE16A;
919         texture->format = SDL_TEXFORMAT_PALETTE16A;
935920         break;
936921      case TEXFORMAT_YUY16:
937         m_format = texsource.palette() ? SDL_TEXFORMAT_YUY16_PALETTED : SDL_TEXFORMAT_YUY16;
922         texture->format = texsource->palette() ? SDL_TEXFORMAT_YUY16_PALETTED : SDL_TEXFORMAT_YUY16;
938923         break;
939924
940925      default:
941926         osd_printf_error("Unknown textureformat %d\n", PRIMFLAG_GET_TEXFORMAT(flags));
942927   }
943928
944   if (setup.rotwidth != m_texinfo.width || setup.rotheight != m_texinfo.height
945         || setup.dudx < 0 || setup.dvdy < 0)
946      m_is_rotated = TRUE;
929   texture->rawwidth = texsource->width;
930   texture->rawheight = texsource->height;
931   if (setup->rotwidth != texture->rawwidth || setup->rotheight != texture->rawheight
932         || setup->dudx < 0 )
933      texture->is_rotated = TRUE;
947934   else
948      m_is_rotated = FALSE;
935      texture->is_rotated = FALSE;
949936
950   //m_sdl_access = SDL_TEXTUREACCESS_STATIC;
951   m_sdl_access = SDL_TEXTUREACCESS_STREAMING;
937   //texture->sdl_access = SDL_TEXTUREACCESS_STATIC;
938   texture->sdl_access = SDL_TEXTUREACCESS_STREAMING;
952939
953940   // Watch out for 0x0 textures ...
954   if (!m_setup.rotwidth || !m_setup.rotheight)
941   if (!texture->setup.rotwidth || !texture->setup.rotheight)
955942      osd_printf_warning("Trying to create texture with zero dim\n");
956943
957   // set copy_info
944   // compute the size
945   texture->copyinfo = texture_compute_size_type(sdl->sdl_renderer, texsource, texture, flags);
958946
959   m_copyinfo = compute_size_type();
947   texture->texture_id = SDL_CreateTexture(sdl->sdl_renderer, texture->copyinfo->dst_fmt, texture->sdl_access,
948         texture->setup.rotwidth, texture->setup.rotheight);
960949
961   m_texture_id = SDL_CreateTexture(m_renderer, m_copyinfo->dst_fmt, m_sdl_access,
962         m_setup.rotwidth, m_setup.rotheight);
950   if (!texture->texture_id)
951      osd_printf_error("Error creating texture: %d x %d, pixelformat %s error: %s\n", texture->setup.rotwidth, texture->setup.rotheight,
952            texture->copyinfo->dstname, SDL_GetError());
963953
964   if (!m_texture_id)
965      osd_printf_error("Error creating texture: %d x %d, pixelformat %s error: %s\n", m_setup.rotwidth, m_setup.rotheight,
966            m_copyinfo->dstname, SDL_GetError());
967
968   if (m_sdl_access == SDL_TEXTUREACCESS_STATIC)
954   if ( (texture->copyinfo->func != NULL) && (texture->sdl_access == SDL_TEXTUREACCESS_STATIC))
969955   {
970       if (m_copyinfo->func != NULL)
971           m_pixels = malloc(m_setup.rotwidth * m_setup.rotheight * m_copyinfo->dst_bpp);
972       else
973           m_pixels = NULL;
956      texture->pixels = malloc(texture->setup.rotwidth * texture->setup.rotheight * texture->copyinfo->dst_bpp);
957      texture->pixels_own=TRUE;
974958   }
975   m_last_access = osd_ticks();
959   /* add us to the texture list */
960   texture->next = sdl->texlist;
961   sdl->texlist = texture;
976962
977}
963   texture->last_access = osd_ticks();
978964
979texture_info::~texture_info()
980{
981    SDL_DestroyTexture(m_texture_id);
982    if ( is_pixels_owned() && m_pixels != NULL )
983        free(m_pixels);
965   return texture;
984966}
985967
986968//============================================================
987969//  texture_set_data
988970//============================================================
989971
990void texture_info::set_data(const render_texinfo &texsource, const UINT32 flags)
972static void texture_set_data(sdl_info *sdl, texture_info *texture, const render_texinfo *texsource, UINT32 flags)
991973{
992   m_copyinfo->time -= osd_ticks();
993   if (m_sdl_access == SDL_TEXTUREACCESS_STATIC)
974   texture->copyinfo->time -= osd_ticks();
975   if (texture->sdl_access == SDL_TEXTUREACCESS_STATIC)
994976   {
995      if ( m_copyinfo->func )
977      if ( texture->copyinfo->func )
996978      {
997         m_pitch = m_setup.rotwidth * m_copyinfo->dst_bpp;
998         m_copyinfo->func(this, &texsource);
979         texture->pitch = texture->setup.rotwidth * texture->copyinfo->dst_bpp;
980         texture->copyinfo->func(texture, texsource);
999981      }
1000982      else
1001983      {
1002         m_pixels = texsource.base;
1003         m_pitch = m_texinfo.rowpixels * m_copyinfo->dst_bpp;
984         texture->pixels = texsource->base;
985         texture->pitch = texture->texinfo.rowpixels * texture->copyinfo->dst_bpp;
1004986      }
1005      SDL_UpdateTexture(m_texture_id, NULL, m_pixels, m_pitch);
987      SDL_UpdateTexture(texture->texture_id, NULL, texture->pixels, texture->pitch);
1006988   }
1007989   else
1008990   {
1009      SDL_LockTexture(m_texture_id, NULL, (void **) &m_pixels, &m_pitch);
1010      if ( m_copyinfo->func )
1011         m_copyinfo->func(this, &texsource);
991      SDL_LockTexture(texture->texture_id, NULL, (void **) &texture->pixels, &texture->pitch);
992      if ( texture->copyinfo->func )
993         texture->copyinfo->func(texture, texsource);
1012994      else
1013995      {
1014         UINT8 *src = (UINT8 *) texsource.base;
1015         UINT8 *dst = (UINT8 *) m_pixels;
1016         int spitch = texsource.rowpixels * m_copyinfo->dst_bpp;
1017         int num = texsource.width * m_copyinfo->dst_bpp;
1018         int h = texsource.height;
996         UINT8 *src = (UINT8 *) texsource->base;
997         UINT8 *dst = (UINT8 *) texture->pixels;
998         int spitch = texsource->rowpixels * texture->copyinfo->dst_bpp;
999         int num = texsource->width * texture->copyinfo->dst_bpp;
1000         int h = texsource->height;
10191001         while (h--) {
10201002            memcpy(dst, src, num);
10211003            src += spitch;
1022            dst += m_pitch;
1004            dst += texture->pitch;
10231005         }
10241006      }
1025      SDL_UnlockTexture(m_texture_id);
1007      SDL_UnlockTexture(texture->texture_id);
10261008   }
1027   m_copyinfo->time += osd_ticks();
1009   texture->copyinfo->time += osd_ticks();
10281010}
10291011
10301012//============================================================
10311013//  compute rotation setup
10321014//============================================================
10331015
1034void quad_setup_data::compute(const render_primitive &prim)
1016static void compute_setup(sdl_info *sdl, const render_primitive *prim, quad_setup_data *setup, int flags)
10351017{
1036   const render_quad_texuv *texcoords = &prim.texcoords;
1037   int texwidth = prim.texture.width;
1038   int texheight = prim.texture.height;
1018   const render_quad_texuv *texcoords = &prim->texcoords;
1019   int texwidth = prim->texture.width;
1020   int texheight = prim->texture.height;
10391021   float fdudx, fdvdx, fdudy, fdvdy;
10401022   float width, height;
10411023   float fscale;
10421024   /* determine U/V deltas */
1043   if ((PRIMFLAG_GET_SCREENTEX(prim.flags)))
1025   if ((PRIMFLAG_GET_SCREENTEX(flags)))
10441026      fscale = (float) video_config.prescale;
10451027   else
10461028      fscale = 1.0f;
r242698r242699
10501032   fdudy = (texcoords->bl.u - texcoords->tl.u) / fscale; // b a12
10511033   fdvdy = (texcoords->bl.v - texcoords->tl.v) / fscale; // d a22
10521034
1053#if 0
1054   printf("tl.u %f tl.v %f\n", texcoords->tl.u, texcoords->tl.v);
1055    printf("tr.u %f tr.v %f\n", texcoords->tr.u, texcoords->tr.v);
1056    printf("bl.u %f bl.v %f\n", texcoords->bl.u, texcoords->bl.v);
1057    printf("br.u %f br.v %f\n", texcoords->br.u, texcoords->br.v);
10581035   /* compute start and delta U,V coordinates now */
1059#endif
10601036
1061   dudx = round_nearest(65536.0f * fdudx);
1062   dvdx = round_nearest(65536.0f * fdvdx);
1063   dudy = round_nearest(65536.0f * fdudy);
1064   dvdy = round_nearest(65536.0f * fdvdy);
1065   startu = round_nearest(65536.0f * (float) texwidth * texcoords->tl.u);
1066   startv = round_nearest(65536.0f * (float) texheight * texcoords->tl.v);
1037   setup->dudx = round_nearest(65536.0f * fdudx);
1038   setup->dvdx = round_nearest(65536.0f * fdvdx);
1039   setup->dudy = round_nearest(65536.0f * fdudy);
1040   setup->dvdy = round_nearest(65536.0f * fdvdy);
1041   setup->startu = round_nearest(65536.0f * (float) texwidth * texcoords->tl.u);
1042   setup->startv = round_nearest(65536.0f * (float) texheight * texcoords->tl.v);
10671043
10681044   /* clamp to integers */
10691045
10701046   width = fabs((fdudx * (float) (texwidth) + fdvdx * (float) (texheight)) * fscale * fscale);
10711047   height = fabs((fdudy * (float)(texwidth) + fdvdy * (float) (texheight)) * fscale * fscale);
10721048
1073   rotwidth = width;
1074   rotheight = height;
1049   setup->rotwidth = width;
1050   setup->rotheight = height;
10751051
1076   startu += (dudx + dudy) / 2;
1077   startv += (dvdx + dvdy) / 2;
1052   setup->startu += (setup->dudx + setup->dudy) / 2;
1053   setup->startv += (setup->dvdx + setup->dvdy) / 2;
10781054
10791055}
10801056
r242698r242699
10821058//  texture_find
10831059//============================================================
10841060
1085texture_info *sdl_info::texture_find(const render_primitive &prim, const quad_setup_data &setup)
1061static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim, quad_setup_data *setup)
10861062{
1087   HashT texhash = texture_compute_hash(prim.texture, prim.flags);
1063   HashT texhash = texture_compute_hash(&prim->texture, prim->flags);
10881064   texture_info *texture;
10891065   osd_ticks_t now = osd_ticks();
10901066
10911067   // find a match
1092   for (texture = m_texlist.first(); texture != NULL; )
1093      if (texture->hash() == texhash &&
1094         texture->matches(prim, setup))
1068   for (texture = sdl->texlist; texture != NULL; )
1069      if (texture->hash == texhash &&
1070         texture->texinfo.base == prim->texture.base &&
1071         texture->texinfo.width == prim->texture.width &&
1072         texture->texinfo.height == prim->texture.height &&
1073         texture->texinfo.rowpixels == prim->texture.rowpixels &&
1074         texture->setup.dudx == setup->dudx &&
1075         texture->setup.dvdx == setup->dvdx &&
1076         texture->setup.dudy == setup->dudy &&
1077         texture->setup.dvdy == setup->dvdy &&
1078         ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
10951079      {
1096         /* would we choose another blitter based on performance ? */
1097         if ((texture->m_copyinfo->samples & 0x7f) == 0x7f)
1080         /* would we choose another blitter ? */
1081         if ((texture->copyinfo->samples & 0x1f) == 0x1f)
10981082         {
1099            if (texture->m_copyinfo != texture->compute_size_type())
1083            if (texture->copyinfo != texture_compute_size_type(sdl->sdl_renderer, &texture->texinfo, texture, prim->flags))
11001084               return NULL;
1085#if 0
1086            else
1087            {
1088               /* reset stats */
1089               texture->copyinfo->samples = 0;
1090               texture->copyinfo->time = 0;
1091               texture->copyinfo->pixel_count = 0;
1092            }
1093#endif
11011094         }
1102         texture->m_last_access = now;
1095         texture->last_access = now;
11031096         return texture;
11041097      }
11051098      else
11061099      {
11071100         /* free resources not needed any longer? */
11081101         texture_info *expire = texture;
1109         texture = texture->next();
1110         if (now - expire->m_last_access > osd_ticks_per_second())
1111            m_texlist.remove(*expire);
1102         texture = texture->next;
1103         if (now - expire->last_access > osd_ticks_per_second())
1104            drawsdl2_destroy_texture(sdl, expire);
11121105      }
11131106
11141107   // nothing found
r242698r242699
11191112//  texture_update
11201113//============================================================
11211114
1122texture_info * sdl_info::texture_update(const render_primitive &prim)
1115static texture_info * texture_update(sdl_window_info *window, const render_primitive *prim)
11231116{
1117   sdl_info *sdl = (sdl_info *) window->dxdata;
11241118   quad_setup_data setup;
11251119   texture_info *texture;
11261120
1127   setup.compute(prim);
1121   compute_setup(sdl, prim, &setup, prim->flags);
11281122
1129   texture = texture_find(prim, setup);
1123   texture = texture_find(sdl, prim, &setup);
11301124
11311125   // if we didn't find one, create a new texture
1132   if (texture == NULL && prim.texture.base != NULL)
1126   if (texture == NULL && prim->texture.base != NULL)
11331127   {
1134      texture = global_alloc(texture_info(m_renderer, prim.texture, setup, prim.flags));
1135       /* add us to the texture list */
1136      m_texlist.prepend(*texture);
1137
1128      texture = texture_create(window, &prim->texture, &setup, prim->flags);
11381129   }
11391130
11401131   if (texture != NULL)
11411132   {
1142      if (prim.texture.base != NULL && texture->texinfo().seqid != prim.texture.seqid)
1133      if (prim->texture.base != NULL && texture->texinfo.seqid != prim->texture.seqid)
11431134      {
1144         texture->texinfo().seqid = prim.texture.seqid;
1135         texture->texinfo.seqid = prim->texture.seqid;
11451136         // if we found it, but with a different seqid, copy the data
1146         texture->set_data(prim.texture, prim.flags);
1137         texture_set_data(sdl, texture, &prim->texture, prim->flags);
11471138      }
11481139
11491140   }
11501141   return texture;
11511142}
11521143
1144static void drawsdl2_destroy_texture(sdl_info *sdl, texture_info *texture)
1145{
1146   texture_info *p;
11531147
1148   SDL_DestroyTexture(texture->texture_id);
1149   if ( texture->pixels_own )
1150   {
1151      free(texture->pixels);
1152      texture->pixels=NULL;
1153      texture->pixels_own=FALSE;
1154   }
1155
1156   for (p=sdl->texlist; p != NULL; p = p->next)
1157      if (p->next == texture)
1158         break;
1159   if (p == NULL)
1160      sdl->texlist = NULL;
1161   else
1162      p->next = texture->next;
1163   global_free(texture);
1164}
1165
11541166static void drawsdl2_destroy_all_textures(sdl_window_info *window)
11551167{
11561168   sdl_info *sdl = (sdl_info *) window->dxdata;
1169   texture_info *next_texture=NULL, *texture = NULL;
1170   int lock=FALSE;
11571171
11581172   if (sdl == NULL)
11591173      return;
11601174
11611175   if(window->primlist)
11621176   {
1177      lock=TRUE;
11631178      window->primlist->acquire_lock();
1164        sdl->m_texlist.reset();
1165        window->primlist->release_lock();
11661179   }
1167   else
1168        sdl->m_texlist.reset();
1180
1181   texture = sdl->texlist;
1182
1183   while (texture)
1184   {
1185      next_texture = texture->next;
1186      drawsdl2_destroy_texture(sdl, texture);
1187      texture = next_texture;
1188   }
1189
1190   if (lock)
1191      window->primlist->release_lock();
11691192}
trunk/src/osd/sdl/drawogl.c
r242698r242699
367367static void drawogl_window_resize(sdl_window_info *window, int width, int height);
368368static void drawogl_window_destroy(sdl_window_info *window);
369369static int drawogl_window_draw(sdl_window_info *window, UINT32 dc, int update);
370static void drawogl_set_target_bounds(sdl_window_info *window);
370static render_primitive_list &drawogl_window_get_primitives(sdl_window_info *window);
371371static void drawogl_destroy_all_textures(sdl_window_info *window);
372372static void drawogl_window_clear(sdl_window_info *window);
373373static int drawogl_xy_to_render_target(sdl_window_info *window, int x, int y, int *xt, int *yt);
r242698r242699
454454   // fill in the callbacks
455455   window->create = drawogl_window_create;
456456   window->resize = drawogl_window_resize;
457   window->set_target_bounds = drawogl_set_target_bounds;
457   window->get_primitives = drawogl_window_get_primitives;
458458   window->draw = drawogl_window_draw;
459459   window->destroy = drawogl_window_destroy;
460460   window->destroy_all_textures = drawogl_destroy_all_textures;
r242698r242699
840840//  drawogl_window_get_primitives
841841//============================================================
842842
843static void drawogl_set_target_bounds(sdl_window_info *window)
843static render_primitive_list &drawogl_window_get_primitives(sdl_window_info *window)
844844{
845   if ((!window->fullscreen()) || (video_config.switchres))
846   {
847      window->blit_surface_size(window->width, window->height);
848   }
849   else
850   {
851      window->blit_surface_size(window->monitor()->center_width, window->monitor()->center_height);
852   }
845853   window->target->set_bounds(window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor()));
854   return window->target->get_primitives();
846855}
847856
848857//============================================================
trunk/src/osd/sdl/drawsdl.c
r242698r242699
105105static int drawsdl_window_create(sdl_window_info *window, int width, int height);
106106static void drawsdl_window_resize(sdl_window_info *window, int width, int height);
107107static void drawsdl_window_destroy(sdl_window_info *window);
108static void drawsdl_set_target_bounds(sdl_window_info *window);
108static render_primitive_list &drawsdl_window_get_primitives(sdl_window_info *window);
109109static int drawsdl_window_draw(sdl_window_info *window, UINT32 dc, int update);
110110static void drawsdl_destroy_all_textures(sdl_window_info *window);
111111static void drawsdl_window_clear(sdl_window_info *window);
r242698r242699
221221   // fill in the callbacks
222222   window->create = drawsdl_window_create;
223223   window->resize = drawsdl_window_resize;
224   window->set_target_bounds = drawsdl_set_target_bounds;
224   window->get_primitives = drawsdl_window_get_primitives;
225225   window->draw = drawsdl_window_draw;
226226   window->destroy = drawsdl_window_destroy;
227227   window->destroy_all_textures = drawsdl_destroy_all_textures;
r242698r242699
460460
461461         if (!found)
462462         {
463            fatalerror("window: Scale mode %s not supported!", sm->name);
463            osd_printf_verbose("window: Scale mode %s not supported!\n", sm->name);
464            window->machine().ui().popup_time(3, "Scale mode %s not supported!", sm->name);
464465         }
465466      }
466467   }
r242698r242699
617618//  drawsdl_window_get_primitives
618619//============================================================
619620
620static void drawsdl_set_target_bounds(sdl_window_info *window)
621static render_primitive_list &drawsdl_window_get_primitives(sdl_window_info *window)
621622{
622623   sdl_info *sdl = (sdl_info *) window->dxdata;
623624   const sdl_scale_mode *sm = &scale_modes[video_config.scale_mode];
624625
626   if ((!window->fullscreen()) || (video_config.switchres))
627   {
628      window->blit_surface_size(window->width, window->height);
629   }
630   else
631   {
632      window->blit_surface_size(window->monitor()->center_width, window->monitor()->center_height);
633   }
634
625635   if (!sm->is_scale)
626636      window->target->set_bounds(window->blitwidth, window->blitheight, sdlvideo_monitor_get_aspect(window->monitor()));
627637   else
628638      window->target->set_bounds(sdl->hw_scale_width, sdl->hw_scale_height);
639
640   return window->target->get_primitives();
629641}
630642
631643//============================================================
trunk/src/osd/sdl/sdl.mak
r242698r242699
7777# change for custom OS X installations
7878SDL_FRAMEWORK_PATH = /Library/Frameworks/
7979
80# uncomment to use SDL1.2 (depracated)
8180# SDL_LIBVER = sdl
8281
8382###########################################################################
r242698r242699
742741# Default libs
743742DEFS += -DSDLMAME_X11
744743LIBS += -lX11 -lXinerama
745ifneq ($(SDL_LIBVER),sdl2)
746BASELIBS += -lX11
747endif
748744
749745# The newer debugger uses QT
750746ifndef NO_USE_QTDEBUG
trunk/src/osd/sdl/sdlwork.c
r242698r242699
687687   // loop until everything is processed
688688   while (true)
689689   {
690      osd_work_item *item = NULL;
690      osd_work_item *item;
691691
692692      bool end_loop = false;
693693
r242698r242699
767767   osd_scalable_lock_release(queue->lock, lockslot);
768768   return has_list_items;
769769}
770#endif // SDLMAME_NOASM
770#endif // SDLMAME_NOASM
No newline at end of file
trunk/src/osd/sdl/window.c
r242698r242699
109109   : m_window(awindow), m_list(NULL), m_machine(&amachine), m_resize_new_width(0), m_resize_new_height(0)
110110   {
111111   }
112   worker_param(running_machine &amachine, sdl_window_info *awindow, render_primitive_list &alist)
113   : m_window(awindow), m_list(&alist), m_machine(&amachine), m_resize_new_width(0), m_resize_new_height(0)
112   worker_param(running_machine &amachine, sdl_window_info *awindow, render_primitive_list *alist)
113   : m_window(awindow), m_list(alist), m_machine(&amachine), m_resize_new_width(0), m_resize_new_height(0)
114114   {
115115   }
116116   worker_param(sdl_window_info *awindow, int anew_width, int anew_height)
r242698r242699
980980
981981      if (osd_event_wait(rendered_event, event_wait_ticks))
982982      {
983          if ((!fullscreen()) || (video_config.switchres))
984          {
985              blit_surface_size(width, height);
986          }
987          else
988          {
989              blit_surface_size(monitor()->center_width, monitor()->center_height);
990          }
991
992983         // ensure the target bounds are up-to-date, and then get the primitives
993          set_target_bounds(this);
984         render_primitive_list *primlist = &get_primitives(this);
994985
995         render_primitive_list &primlist = target->get_primitives();
996
997986         // and redraw now
998987
999988         execute_async(&draw_video_contents_wt, worker_param(machine, this, primlist));
trunk/src/osd/sdl/window.h
r242698r242699
9494   int (*create)(sdl_window_info *window, int width, int height);
9595   void (*resize)(sdl_window_info *window, int width, int height);
9696   int (*draw)(sdl_window_info *window, UINT32 dc, int update);
97   void (*set_target_bounds)(sdl_window_info *window);
97   render_primitive_list &(*get_primitives)(sdl_window_info *window);
9898   int (*xy_to_render_target)(sdl_window_info *window, int x, int y, int *xt, int *yt);
9999   void (*destroy_all_textures)(sdl_window_info *window);
100100   void (*destroy)(sdl_window_info *window);


Previous 199869 Revisions Next


© 1997-2024 The MAME Team