1 /*
2 * Copyright (C) 2002-2013 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19
20 //TODO:
21 //Maybe just do the cache checking back into the simple scalers so they can
22 //just handle it all in one go, but this seems to work well enough for now
23
24 #include "dosbox.h"
25 #include "render.h"
26 #include <string.h>
27
28 Bit8u Scaler_Aspect[SCALER_MAXHEIGHT];
29 Bit16u Scaler_ChangedLines[SCALER_MAXHEIGHT];
30 Bitu Scaler_ChangedLineIndex;
31
32 static union {
33 Bit32u b32 [4][SCALER_MAXWIDTH*3];
34 Bit16u b16 [4][SCALER_MAXWIDTH*3];
35 Bit8u b8 [4][SCALER_MAXWIDTH*3];
36 } scalerWriteCache;
37 //scalerFrameCache_t scalerFrameCache;
38 scalerSourceCache_t scalerSourceCache;
39
40 #define _conc2(A,B) A ## B
41 #define _conc3(A,B,C) A ## B ## C
42 #define _conc4(A,B,C,D) A ## B ## C ## D
43 #define _conc5(A,B,C,D,E) A ## B ## C ## D ## E
44 #define _conc7(A,B,C,D,E,F,G) A ## B ## C ## D ## E ## F ## G
45
46 #define conc2(A,B) _conc2(A,B)
47 #define conc3(A,B,C) _conc3(A,B,C)
48 #define conc4(A,B,C,D) _conc4(A,B,C,D)
49 #define conc2d(A,B) _conc3(A,_,B)
50 #define conc3d(A,B,C) _conc5(A,_,B,_,C)
51 #define conc4d(A,B,C,D) _conc7(A,_,B,_,C,_,D)
52
ScalerAddLines(Bitu changed,Bitu count)53 static INLINE void ScalerAddLines( Bitu changed, Bitu count ) {
54 if ((Scaler_ChangedLineIndex & 1) == changed ) {
55 Scaler_ChangedLines[Scaler_ChangedLineIndex] += count;
56 } else {
57 Scaler_ChangedLines[++Scaler_ChangedLineIndex] = count;
58 }
59 render.scale.outWrite += render.scale.outPitch * count;
60 }
61
62 #if defined(ANDROID) || defined(__linux__) || defined(__APPLE__) || defined(EMSCRIPTEN) || defined(_WIN32)
63 //platform optimized memcpy will probably be faster
64 #define BituMove(dst,src,size) memcpy((void*)(dst),(void*)(src),(size))
65 #define BituMove2(dst,src,size) memcpy((void*)(dst),(void*)(src),(size))
66 #else
67 //no platform optimized memcpy avalible
BituMove(void * _dst,const void * _src,Bitu size)68 static INLINE void BituMove( void *_dst, const void * _src, Bitu size) {
69 Bitu * dst=(Bitu *)(_dst);
70 const Bitu * src=(Bitu *)(_src);
71 size/=sizeof(Bitu);
72 for (Bitu x=0; x<size;x++)
73 dst[x] = src[x];
74 }
75
76 #define BituMove2(_DST,_SRC,_SIZE) \
77 { \
78 Bitu bsize=(_SIZE)/sizeof(Bitu); \
79 Bitu * bdst=(Bitu *)(_DST); \
80 Bitu * bsrc=(Bitu *)(_SRC); \
81 while (bsize--) *bdst++=*bsrc++; \
82 }
83 #endif
84
85 #define interp_w2(P0,P1,W0,W1) \
86 ((((P0&redblueMask)*W0+(P1&redblueMask)*W1)/(W0+W1)) & redblueMask) | \
87 ((((P0& greenMask)*W0+(P1& greenMask)*W1)/(W0+W1)) & greenMask)
88 #define interp_w3(P0,P1,P2,W0,W1,W2) \
89 ((((P0&redblueMask)*W0+(P1&redblueMask)*W1+(P2&redblueMask)*W2)/(W0+W1+W2)) & redblueMask) | \
90 ((((P0& greenMask)*W0+(P1& greenMask)*W1+(P2& greenMask)*W2)/(W0+W1+W2)) & greenMask)
91 #define interp_w4(P0,P1,P2,P3,W0,W1,W2,W3) \
92 ((((P0&redblueMask)*W0+(P1&redblueMask)*W1+(P2&redblueMask)*W2+(P3&redblueMask)*W3)/(W0+W1+W2+W3)) & redblueMask) | \
93 ((((P0& greenMask)*W0+(P1& greenMask)*W1+(P2& greenMask)*W2+(P3& greenMask)*W3)/(W0+W1+W2+W3)) & greenMask)
94
95
96 #define CC scalerChangeCache
97
98 /* Include the different rendering routines */
99 #define SBPP 8
100 #define DBPP 8
101 #include "render_templates.h"
102 #undef DBPP
103 #define DBPP 15
104 #include "render_templates.h"
105 #undef DBPP
106 #define DBPP 16
107 #include "render_templates.h"
108 #undef DBPP
109 #define DBPP 32
110 #include "render_templates.h"
111 #undef SBPP
112 #undef DBPP
113
114 /* SBPP 9 is a special case with palette check support */
115 #define SBPP 9
116 #define DBPP 8
117 #include "render_templates.h"
118 #undef DBPP
119 #define DBPP 15
120 #include "render_templates.h"
121 #undef DBPP
122 #define DBPP 16
123 #include "render_templates.h"
124 #undef DBPP
125 #define DBPP 32
126 #include "render_templates.h"
127 #undef SBPP
128 #undef DBPP
129
130 #define SBPP 15
131 #define DBPP 15
132 #include "render_templates.h"
133 #undef DBPP
134 #define DBPP 16
135 #include "render_templates.h"
136 #undef DBPP
137 #define DBPP 32
138 #include "render_templates.h"
139 #undef SBPP
140 #undef DBPP
141
142 #define SBPP 16
143 #define DBPP 15
144 #include "render_templates.h"
145 #undef DBPP
146 #define DBPP 16
147 #include "render_templates.h"
148 #undef DBPP
149 #define DBPP 32
150 #include "render_templates.h"
151 #undef SBPP
152 #undef DBPP
153
154 #define SBPP 32
155 #define DBPP 15
156 #include "render_templates.h"
157 #undef DBPP
158 #define DBPP 16
159 #include "render_templates.h"
160 #undef DBPP
161 #define DBPP 32
162 #include "render_templates.h"
163 #undef SBPP
164 #undef DBPP
165
166
167 ScalerSimpleBlock_t ScaleNormal1x = {
168 "Normal",
169 GFX_CAN_8|GFX_CAN_15|GFX_CAN_16|GFX_CAN_32,
170 1,1,{
171 { Normal1x_8_8_L, Normal1x_8_15_L , Normal1x_8_16_L , Normal1x_8_32_L },
172 { 0, Normal1x_15_15_L, Normal1x_15_16_L, Normal1x_15_32_L},
173 { 0, Normal1x_16_15_L, Normal1x_16_16_L, Normal1x_16_32_L},
174 { 0, Normal1x_32_15_L, Normal1x_32_16_L, Normal1x_32_32_L},
175 { Normal1x_8_8_L, Normal1x_9_15_L , Normal1x_9_16_L , Normal1x_9_32_L }
176 },{
177 { Normal1x_8_8_R, Normal1x_8_15_R , Normal1x_8_16_R , Normal1x_8_32_R },
178 { 0, Normal1x_15_15_R, Normal1x_15_16_R, Normal1x_15_32_R},
179 { 0, Normal1x_16_15_R, Normal1x_16_16_R, Normal1x_16_32_R},
180 { 0, Normal1x_32_15_R, Normal1x_32_16_R, Normal1x_32_32_R},
181 { Normal1x_8_8_R, Normal1x_9_15_R , Normal1x_9_16_R , Normal1x_9_32_R }
182 }};
183
184 ScalerSimpleBlock_t ScaleNormalDw = {
185 "Normal",
186 GFX_CAN_8|GFX_CAN_15|GFX_CAN_16|GFX_CAN_32,
187 2,1,{
188 { NormalDw_8_8_L, NormalDw_8_15_L , NormalDw_8_16_L , NormalDw_8_32_L },
189 { 0, NormalDw_15_15_L, NormalDw_15_16_L, NormalDw_15_32_L},
190 { 0, NormalDw_16_15_L, NormalDw_16_16_L, NormalDw_16_32_L},
191 { 0, NormalDw_32_15_L, NormalDw_32_16_L, NormalDw_32_32_L},
192 { NormalDw_8_8_L, NormalDw_9_15_L , NormalDw_9_16_L , NormalDw_9_32_L }
193 },{
194 { NormalDw_8_8_R, NormalDw_8_15_R , NormalDw_8_16_R , NormalDw_8_32_R },
195 { 0, NormalDw_15_15_R, NormalDw_15_16_R, NormalDw_15_32_R},
196 { 0, NormalDw_16_15_R, NormalDw_16_16_R, NormalDw_16_32_R},
197 { 0, NormalDw_32_15_R, NormalDw_32_16_R, NormalDw_32_32_R},
198 { NormalDw_8_8_R, NormalDw_9_15_R , NormalDw_9_16_R , NormalDw_9_32_R }
199 }};
200
201 ScalerSimpleBlock_t ScaleNormalDh = {
202 "Normal",
203 GFX_CAN_8|GFX_CAN_15|GFX_CAN_16|GFX_CAN_32,
204 1,2,{
205 { NormalDh_8_8_L, NormalDh_8_15_L , NormalDh_8_16_L , NormalDh_8_32_L },
206 { 0, NormalDh_15_15_L, NormalDh_15_16_L, NormalDh_15_32_L},
207 { 0, NormalDh_16_15_L, NormalDh_16_16_L, NormalDh_16_32_L},
208 { 0, NormalDh_32_15_L, NormalDh_32_16_L, NormalDh_32_32_L},
209 { NormalDh_8_8_L, NormalDh_9_15_L , NormalDh_9_16_L , NormalDh_9_32_L }
210 },{
211 { NormalDh_8_8_R, NormalDh_8_15_R , NormalDh_8_16_R , NormalDh_8_32_R },
212 { 0, NormalDh_15_15_R, NormalDh_15_16_R, NormalDh_15_32_R},
213 { 0, NormalDh_16_15_R, NormalDh_16_16_R, NormalDh_16_32_R},
214 { 0, NormalDh_32_15_R, NormalDh_32_16_R, NormalDh_32_32_R},
215 { NormalDh_8_8_R, NormalDh_9_15_R , NormalDh_9_16_R , NormalDh_9_32_R }
216 }};
217