DXGL r707 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r706‎ | r707 | r708 >
Date:04:37, 30 May 2017
Author:admin
Status:new
Tags:
Comment:
Add pixel doubled modes in Change Desktop Resolution.
Make adding extra modes default - adds doubled modes in Change Desktop Resolution.
Add 640x200 mode.
Set height doubling threshold to 300 lines.
Modified paths:
  • /cfgmgr/ReadMe.txt (modified) (history)
  • /cfgmgr/cfgmgr.c (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)

Diff [purge]

Index: cfgmgr/ReadMe.txt
@@ -38,7 +38,7 @@
3939 REG_DWORD HKCU\DXGL\Profiles\<app>\FirstScaleX
4040 Amount to stretch the display in the X direction for the first pass.
4141 If either X or Y is set to 0 or less than 0.25, automatically choose
42 -2x or 2x1 scaling for certain low resolutions.
 42+2x, 2x1, or 1x2 scaling for certain low resolutions.
4343 Stored as a 32-bit float encoded as a DWORD.
4444
4545 Member firstscaley
@@ -45,7 +45,7 @@
4646 REG_DWORD HKCU\DXGL\Profiles\<app>\FirstScaley
4747 Amount to stretch the display in the Y direction for the first pass.
4848 If either X or Y is set to 0 or less than 0.25, automatically choose
49 -2x or 2x1 scaling for certain low resolutions.
 49+2x, 2x1, or 1x2 scaling for certain low resolutions.
5050 Stored as a 32-bit float encoded as a DWORD.
5151
5252 Member scalingfilter
Index: cfgmgr/cfgmgr.c
@@ -723,6 +723,7 @@
724724 HKEY hKey;
725725 ZeroMemory(cfg,sizeof(DXGLCFG));
726726 cfg->DPIScale = 1;
 727+ cfg->AddModes = 1;
727728 if (initial) RegOpenKeyEx(HKEY_CURRENT_USER, regkeyglobal, 0, KEY_READ, &hKey);
728729 else RegCreateKeyEx(HKEY_CURRENT_USER, regkeyglobal, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL);
729730 if (hKey)
Index: ddraw/glDirectDraw.cpp
@@ -95,7 +95,9 @@
9696 return false;
9797 }
9898
99 -const int ExtraModes[30] [3] = {
 99+const int START_EXTRAMODESCOUNT = __LINE__;
 100+const int ExtraModes[] [3] =
 101+{
100102 {320,175,70},
101103 {320,200,70},
102104 {320,240,60},
@@ -109,6 +111,7 @@
110112 {416,312,75},
111113 {512,384,60},
112114 {576,432,60},
 115+ {640,200,70},
113116 {640,350,70},
114117 {640,400,70},
115118 {640,512,60},
@@ -127,7 +130,27 @@
128131 {960,600,60},
129132 {960,720,60}
130133 };
 134+const int END_EXTRAMODESCOUNT = __LINE__ - 4;
 135+const int numextramodes = END_EXTRAMODESCOUNT - START_EXTRAMODESCOUNT;
131136
 137+const int START_DOUBLEDMODESCOUNT = __LINE__;
 138+const int DoubledModes[] [5] =
 139+{
 140+ {320,175,70,640,350},
 141+ {320,200,70,640,400},
 142+ {320,240,60,640,480},
 143+ {320,400,70,640,400},
 144+ {320,480,60,640,480},
 145+ {640,200,70,640,400},
 146+ {360,200,70,720,400},
 147+ {360,240,60,720,480},
 148+ {360,400,70,720,400},
 149+ {360,480,60,720,480},
 150+ {400,300,60,800,600}
 151+};
 152+const int END_DOUBLEDMODESCOUNT = __LINE__ - 4;
 153+const int numdoubledmodes = END_DOUBLEDMODESCOUNT - START_DOUBLEDMODESCOUNT;
 154+
132155 bool ScanColorMode(DEVMODE *array, DWORD count, int bpp)
133156 {
134157 for(DWORD i = 0; i < count; i++)
@@ -150,7 +173,7 @@
151174
152175 void AddExtraResolutions(DEVMODE **array, DWORD *count)
153176 {
154 - DEVMODE *array2 = (DEVMODE *)malloc(sizeof(DEVMODE)*5*30);
 177+ DEVMODE *array2 = (DEVMODE *)malloc(sizeof(DEVMODE)*5*numextramodes);
155178 DEVMODE compmode = *array[0];
156179 DWORD newcount = 0;
157180 int i;
@@ -157,7 +180,7 @@
158181 if(ScanColorMode(*array,*count,8))
159182 {
160183 compmode.dmBitsPerPel = 8;
161 - for(i = 0; i < 30; i++)
 184+ for(i = 0; i < numextramodes; i++)
162185 {
163186 compmode.dmPelsWidth = ExtraModes[i][0];
164187 compmode.dmPelsHeight = ExtraModes[i][1];
@@ -172,7 +195,7 @@
173196 if(ScanColorMode(*array,*count,15))
174197 {
175198 compmode.dmBitsPerPel = 15;
176 - for(i = 0; i < 30; i++)
 199+ for(i = 0; i < numextramodes; i++)
177200 {
178201 compmode.dmPelsWidth = ExtraModes[i][0];
179202 compmode.dmPelsHeight = ExtraModes[i][1];
@@ -187,7 +210,7 @@
188211 if(ScanColorMode(*array,*count,16))
189212 {
190213 compmode.dmBitsPerPel = 16;
191 - for(i = 0; i < 30; i++)
 214+ for(i = 0; i < numextramodes; i++)
192215 {
193216 compmode.dmPelsWidth = ExtraModes[i][0];
194217 compmode.dmPelsHeight = ExtraModes[i][1];
@@ -202,7 +225,7 @@
203226 if(ScanColorMode(*array,*count,24))
204227 {
205228 compmode.dmBitsPerPel = 24;
206 - for(i = 0; i < 30; i++)
 229+ for(i = 0; i < numextramodes; i++)
207230 {
208231 compmode.dmPelsWidth = ExtraModes[i][0];
209232 compmode.dmPelsHeight = ExtraModes[i][1];
@@ -217,7 +240,7 @@
218241 if(ScanColorMode(*array,*count,32))
219242 {
220243 compmode.dmBitsPerPel = 32;
221 - for(i = 0; i < 30; i++)
 244+ for(i = 0; i < numextramodes; i++)
222245 {
223246 compmode.dmPelsWidth = ExtraModes[i][0];
224247 compmode.dmPelsHeight = ExtraModes[i][1];
@@ -237,7 +260,99 @@
238261
239262 void AddDoubledResolutions(DEVMODE **array, DWORD *count)
240263 {
241 -//#error Add doubled resolutions
 264+ DEVMODE *array2 = (DEVMODE *)malloc(sizeof(DEVMODE) * 5 * numdoubledmodes);
 265+ DEVMODE compmode = *array[0];
 266+ DWORD newcount = 0;
 267+ int i;
 268+ if (ScanColorMode(*array, *count, 8));
 269+ {
 270+ compmode.dmBitsPerPel = 8;
 271+ for (i = 0; i < numdoubledmodes; i++)
 272+ {
 273+ compmode.dmPelsWidth = DoubledModes[i][3];
 274+ compmode.dmPelsHeight = DoubledModes[i][4];
 275+ compmode.dmDisplayFrequency = DoubledModes[i][2];
 276+ if (ScanModeListNoRefresh(*array, compmode, *count))
 277+ {
 278+ compmode.dmPelsWidth = DoubledModes[i][0];
 279+ compmode.dmPelsHeight = DoubledModes[i][1];
 280+ array2[newcount] = compmode;
 281+ newcount++;
 282+ }
 283+ }
 284+ }
 285+ if (ScanColorMode(*array, *count, 15));
 286+ {
 287+ compmode.dmBitsPerPel = 15;
 288+ for (i = 0; i < numdoubledmodes; i++)
 289+ {
 290+ compmode.dmPelsWidth = DoubledModes[i][3];
 291+ compmode.dmPelsHeight = DoubledModes[i][4];
 292+ compmode.dmDisplayFrequency = DoubledModes[i][2];
 293+ if (ScanModeListNoRefresh(*array, compmode, *count))
 294+ {
 295+ compmode.dmPelsWidth = DoubledModes[i][0];
 296+ compmode.dmPelsHeight = DoubledModes[i][1];
 297+ array2[newcount] = compmode;
 298+ newcount++;
 299+ }
 300+ }
 301+ }
 302+ if (ScanColorMode(*array, *count, 16));
 303+ {
 304+ compmode.dmBitsPerPel = 16;
 305+ for (i = 0; i < numdoubledmodes; i++)
 306+ {
 307+ compmode.dmPelsWidth = DoubledModes[i][3];
 308+ compmode.dmPelsHeight = DoubledModes[i][4];
 309+ compmode.dmDisplayFrequency = DoubledModes[i][2];
 310+ if (ScanModeListNoRefresh(*array, compmode, *count))
 311+ {
 312+ compmode.dmPelsWidth = DoubledModes[i][0];
 313+ compmode.dmPelsHeight = DoubledModes[i][1];
 314+ array2[newcount] = compmode;
 315+ newcount++;
 316+ }
 317+ }
 318+ }
 319+ if (ScanColorMode(*array, *count, 24));
 320+ {
 321+ compmode.dmBitsPerPel = 24;
 322+ for (i = 0; i < numdoubledmodes; i++)
 323+ {
 324+ compmode.dmPelsWidth = DoubledModes[i][3];
 325+ compmode.dmPelsHeight = DoubledModes[i][4];
 326+ compmode.dmDisplayFrequency = DoubledModes[i][2];
 327+ if (ScanModeListNoRefresh(*array, compmode, *count))
 328+ {
 329+ compmode.dmPelsWidth = DoubledModes[i][0];
 330+ compmode.dmPelsHeight = DoubledModes[i][1];
 331+ array2[newcount] = compmode;
 332+ newcount++;
 333+ }
 334+ }
 335+ }
 336+ if (ScanColorMode(*array, *count, 32));
 337+ {
 338+ compmode.dmBitsPerPel = 32;
 339+ for (i = 0; i < numdoubledmodes; i++)
 340+ {
 341+ compmode.dmPelsWidth = DoubledModes[i][3];
 342+ compmode.dmPelsHeight = DoubledModes[i][4];
 343+ compmode.dmDisplayFrequency = DoubledModes[i][2];
 344+ if (ScanModeListNoRefresh(*array, compmode, *count))
 345+ {
 346+ compmode.dmPelsWidth = DoubledModes[i][0];
 347+ compmode.dmPelsHeight = DoubledModes[i][1];
 348+ array2[newcount] = compmode;
 349+ newcount++;
 350+ }
 351+ }
 352+ }
 353+ *array = (DEVMODE *)realloc(*array, (*count + newcount) * sizeof(DEVMODE));
 354+ memcpy(&(*array)[*count - 1], array2, newcount * sizeof(DEVMODE));
 355+ free(array2);
 356+ *count += newcount;
242357 }
243358
244359 void AddExtraColorModes(DEVMODE **array, DWORD *count)
@@ -398,8 +513,8 @@
399514 if(dxglcfg.AddColorDepths) AddExtraColorModes(&modes,&modenum); // FIXME: Add color depths by bitmask
400515 DiscardDuplicateModes(&modes,&modenum);
401516 if(dxglcfg.AddModes && (dxglcfg.scaler != 0)) AddExtraResolutions(&modes,&modenum); // FIXME: Add modes by bitmask
402 - if (_isnan(dxglcfg.firstscalex) || _isnan(dxglcfg.firstscaley) ||
403 - (dxglcfg.firstscalex < 0.25f) || (dxglcfg.firstscaley < 0.25f))
 517+ if (dxglcfg.AddModes && (_isnan(dxglcfg.firstscalex) || _isnan(dxglcfg.firstscaley) ||
 518+ (dxglcfg.firstscalex < 0.25f) || (dxglcfg.firstscaley < 0.25f)))
404519 AddDoubledResolutions(&modes, &modenum);
405520 modenum--;
406521 switch(dxglcfg.SortModes)
@@ -1663,7 +1778,7 @@
16641779 {
16651780 if (dwWidth <= 400) xscale = 2;
16661781 else xscale = 1;
1667 - if (dwHeight <= 240) yscale = 2;
 1782+ if (dwHeight <= 300) yscale = 2;
16681783 else yscale = 1;
16691784 }
16701785 else
Index: ddraw/glRenderer.cpp
@@ -3347,7 +3347,7 @@
33483348 {
33493349 if (sizes[2] <= 400) This->firstscalex = 2.0f;
33503350 else This->firstscalex = 1.0f;
3351 - if (sizes[3] <= 240) This->firstscaley = 2.0f;
 3351+ if (sizes[3] <= 300) This->firstscaley = 2.0f;
33523352 else This->firstscaley = 1.0f;
33533353 }
33543354 else
@@ -3737,8 +3737,8 @@
37383738 {
37393739 if (width <= 400) This->firstscalex = 2.0f;
37403740 else This->firstscaley = 1.0f;
3741 - if (height <= 240) This->firstscaley = 2;
3742 - else This->firstscaley = 1;
 3741+ if (height <= 300) This->firstscaley = 2.0f;
 3742+ else This->firstscaley = 1.0f;
37433743 }
37443744 else
37453745 {