18
18
* along with this program; if not, write to the Free Software
19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/engines/testbed/graphics.cpp $
22
* $Id: graphics.cpp 52685 2010-09-12 14:20:52Z sev $
25
25
#include "common/events.h"
34
34
#include "graphics/cursorman.h"
35
35
#include "graphics/fontman.h"
36
#include "graphics/palette.h"
36
37
#include "graphics/surface.h"
37
38
#include "graphics/VectorRendererSpec.h"
39
40
namespace Testbed {
41
byte GFXTestSuite::_palette[256 * 4] = {0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0};
42
byte GFXTestSuite::_palette[256 * 3] = {0, 0, 0, 255, 255, 255, 255, 255, 255};
43
44
GFXTestSuite::GFXTestSuite() {
44
45
// Initialize color palettes
45
46
// The fourth field is for alpha channel which is unused
46
47
// Assuming 8bpp as of now
47
g_system->setPalette(_palette, 0, 3);
48
g_system->getPaletteManager()->setPalette(_palette, 0, 3);
49
50
// Init Mouse Palette (White-black-yellow)
50
51
GFXtests::initMousePalette();
81
82
void GFXTestSuite::setCustomColor(uint r, uint g, uint b) {
86
87
// Set colorNum kColorSpecial with a special color.
87
int absIndx = kColorSpecial * 4;
88
int absIndx = kColorSpecial * 3;
88
89
_palette[absIndx + 1] = 173;
89
90
_palette[absIndx + 2] = 255;
90
91
_palette[absIndx + 3] = 47;
91
g_system->setPalette(_palette, 0, 256);
92
g_system->getPaletteManager()->setPalette(_palette, 0, 256);
94
95
// Helper functions used by GFX tests
96
97
void GFXtests::initMousePalette() {
97
byte palette[3 * 4]; // Black, white and yellow
98
byte palette[3 * 3]; // Black, white and yellow
99
100
palette[0] = palette[1] = palette[2] = 0;
100
palette[4] = palette[5] = palette[6] = 255;
101
palette[8] = palette[9] = 255;
101
palette[3] = palette[4] = palette[5] = 255;
102
palette[6] = palette[7] = 255;
104
105
CursorMan.replaceCursorPalette(palette, 0, 3);
229
230
// Rotate the colors starting from address palette "size" times
231
232
// take a temporary palette color
232
byte tColor[4] = {0};
233
byte tColor[3] = {0};
233
234
// save first color in it.
234
memcpy(tColor, &palette[0], 4 * sizeof(byte));
235
memcpy(tColor, &palette[0], 3 * sizeof(byte));
236
237
// Move each color upward by 1
237
238
for (int i = 0; i < size - 1; i++) {
238
memcpy(&palette[i * 4], &palette[(i + 1) * 4], 4 * sizeof(byte));
239
memcpy(&palette[i * 3], &palette[(i + 1) * 3], 3 * sizeof(byte));
240
241
// Assign last color to tcolor
241
memcpy(&palette[(size - 1) * 4], tColor, 4 * sizeof(byte));
242
memcpy(&palette[(size - 1) * 3], tColor, 3 * sizeof(byte));
346
347
* Used by aspectRatio()
348
349
void GFXtests::drawEllipse(int cx, int cy, int a, int b) {
350
351
// Take a buffer of screen size
351
352
int width = g_system->getWidth();
352
353
int height = Testsuite::getDisplayRegionCoordinates().y;
353
354
byte *buffer = new byte[height * width];
355
356
int x, y, x1, y1;
357
358
memset(buffer, 0, sizeof(byte) * width * height);
398
399
* Tests the fullscreen mode by: toggling between fullscreen and windowed mode
400
bool GFXtests::fullScreenMode() {
401
TestExitStatus GFXtests::fullScreenMode() {
401
402
Testsuite::clearScreen();
402
403
Common::String info = "Fullscreen test. Here you should expect a toggle between windowed and fullscreen states depending "
403
404
"upon your initial state.";
405
406
Common::Point pt(0, 100);
406
407
Testsuite::writeOnScreen("Testing fullscreen mode", pt);
408
409
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
409
410
Testsuite::logPrintf("Info! Skipping test : FullScreenMode\n");
413
414
bool isFeaturePresent;
414
415
bool isFeatureEnabled;
416
TestExitStatus passed = kTestPassed;
416
417
Common::String prompt;
417
418
OptionSelected shouldSelect;
482
483
* Tests the aspect ratio correction by: drawing an ellipse, when corrected the ellipse should render to a circle
484
bool GFXtests::aspectRatio() {
485
TestExitStatus GFXtests::aspectRatio() {
486
487
Testsuite::clearScreen();
487
488
Common::String info = "Aspect Ratio Correction test. If aspect ratio correction is enabled you should expect a circle on screen,"
488
489
" an ellipse otherwise.";
490
491
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
491
492
Testsuite::logPrintf("Info! Skipping test : Aspect Ratio\n");
494
495
// Draw an ellipse on the screen
495
496
drawEllipse(80, 160, 72, 60);
497
498
bool isFeaturePresent;
498
499
bool isFeatureEnabled;
500
TestExitStatus passed = kTestPassed;
500
501
Common::String prompt;
501
502
OptionSelected shouldSelect;
563
564
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
564
565
Testsuite::logPrintf("Info! Skipping test : Palettized Cursors\n");
569
TestExitStatus passed = kTestPassed;
570
571
// Testing with cursor Palette
571
572
setupMouseLoop();
573
574
if (Testsuite::handleInteractiveInput("Which color did the cursor appeared to you?", "Yellow", "Any other", kOptionRight)) {
574
575
Testsuite::logDetailedPrintf("Couldn't use cursor palette for rendering cursor\n");
576
passed = kTestFailed;
578
579
// Testing with game Palette
599
600
* Tests automated mouse movements. "Warp" functionality provided by the backend.
602
bool GFXtests::mouseMovements() {
603
TestExitStatus GFXtests::mouseMovements() {
603
604
Testsuite::clearScreen();
604
// Make mouse visible
605
// Ensure that the cursor is visible
605
606
CursorMan.showMouse(true);
607
608
Common::String info = "Testing Automated Mouse movements.\n"
608
609
"You should expect cursor hotspot(top-left corner) to automatically move from (0, 0) to (100, 100).\n"
609
"There we have a rectangle drawn, finally the cursor would lie centred in that rectangle.";
610
"There we have a rectangle drawn, finally the cursor would lie centered in that rectangle.";
611
612
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
612
613
Testsuite::logPrintf("Info! Skipping test : Mouse Movements\n");
616
617
// Draw Rectangle
617
618
Graphics::Surface *screen = g_system->lockScreen();
619
// Ensure that 2 represents red in current palette
620
GFXTestSuite::setCustomColor(255, 0, 0);
618
621
screen->fillRect(Common::Rect::center(106, 106, 14, 14), 2);
619
622
g_system->unlockScreen();
648
651
* This basically blits the screen by the contents of its buffer.
651
bool GFXtests::copyRectToScreen() {
654
TestExitStatus GFXtests::copyRectToScreen() {
653
656
Testsuite::clearScreen();
654
657
Common::String info = "Testing Blitting a Bitmap to screen.\n"
655
"You should expect to see a 20x40 yellow horizontal rectangle centred at the screen.";
658
"You should expect to see a 20x40 yellow horizontal rectangle centered at the screen.";
657
660
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
658
661
Testsuite::logPrintf("Info! Skipping test : Blitting Bitmap\n");
662
665
GFXTestSuite::setCustomColor(255, 255, 0);
663
666
byte buffer[20 * 40];
664
667
memset(buffer, 2, 20 * 40);
670
673
g_system->updateScreen();
671
674
g_system->delayMillis(1000);
673
if (Testsuite::handleInteractiveInput("Did you see yellow rectangle?", "Yes", "No", kOptionRight)) {
676
if (Testsuite::handleInteractiveInput(" Did you see yellow rectangle ? ", "Yes", "No", kOptionRight)) {
681
684
* Testing feature : Iconifying window
682
685
* It is expected the screen minimizes when this feature is enabled
684
bool GFXtests::iconifyWindow() {
687
TestExitStatus GFXtests::iconifyWindow() {
686
689
Testsuite::clearScreen();
687
690
Common::String info = "Testing Iconify Window mode.\n If the feature is supported by the backend, "
688
691
"you should expect the window to be minimized.\n However you would manually need to de-iconify.";
690
693
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
691
694
Testsuite::logPrintf("Info! Skipping test : Iconifying window\n");
695
698
Common::Point pt(0, 100);
696
699
Testsuite::writeOnScreen("Testing Iconifying window", pt);
718
721
Testsuite::displayMessage("feature not supported");
721
if (Testsuite::handleInteractiveInput("Did you see window minimized?", "Yes", "No", kOptionRight)) {
724
if (Testsuite::handleInteractiveInput(" Did you see the window minimized? ", "Yes", "No", kOptionRight)) {
729
732
* Testing feature: Scaled cursors
731
bool GFXtests::scaledCursors() {
734
TestExitStatus GFXtests::scaledCursors() {
733
736
Testsuite::clearScreen();
734
737
Common::String info = "Testing : Scaled cursors\n"
735
738
"Here every graphics mode is tried with a cursorTargetScale of 1, 2 and 3.\n"
736
"The expected cursor size is drawn as a rectangle, the cursor should entirely cover that rectangle.\n"
739
"The expected cursor size is drawn as a rectangle.\n The cursor should approximately match that rectangle.\n"
737
740
"This may take time, You may skip the later scalers and just examine the first three i.e 1x, 2x and 3x";
742
bool isAspectRatioCorrected = g_system->getFeatureState(OSystem::kFeatureAspectRatioCorrection);
744
if (isAspectRatioCorrected) {
745
info += "\nDisabling Aspect ratio correction, for letting cusors match exactly, will be restored after this test.";
739
748
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
740
749
Testsuite::logPrintf("Info! Skipping test : Scaled Cursors\n");
744
753
int maxLimit = 1000;
753
769
// for every graphics mode display cursors for cursorTargetScale 1, 2 and 3
754
770
// Switch Graphics mode
755
771
// FIXME: Crashes with "3x" mode now.:
773
info = Common::String::format("Testing : Scaled cursors with GFX Mode %s\n", gfxMode->name);
774
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
775
Testsuite::logPrintf("\tInfo! Skipping sub-test : Scaled Cursors :: GFX Mode %s\n", gfxMode->name);
780
if (Engine::shouldQuit()) {
781
// Explicit exit requested
782
Testsuite::logPrintf("Info! Explicit exit requested during scaling test, this test may be incomplete\n");
756
786
g_system->beginGFXTransaction();
758
788
bool isGFXModeSet = g_system->setGraphicsMode(gfxMode->id);
771
801
Testsuite::clearScreen();
773
803
Testsuite::logDetailedPrintf("Switching to graphics mode %s failed\n", gfxMode->name);
809
info = "Did the expected cursor size and the actual cursor size matched?";
810
if (Testsuite::handleInteractiveInput(info, "Yes", "No", kOptionRight)) {
811
Testsuite::logPrintf("\tInfo! Failed sub-test : Scaled Cursors :: GFX Mode %s\n", gfxMode->name);
814
if (Engine::shouldQuit()) {
815
// Explicit exit requested
816
Testsuite::logPrintf("Info! Explicit exit requested during scaling test, this test may be incomplete\n");
780
822
// Restore Original State
781
823
g_system->beginGFXTransaction();
782
824
bool isGFXModeSet = g_system->setGraphicsMode(currGFXMode);
783
825
g_system->initSize(320, 200);
827
if (isAspectRatioCorrected) {
828
g_system->setFeatureState(OSystem::kFeatureAspectRatioCorrection, true);
784
831
OSystem::TransactionError gfxError = g_system->endGFXTransaction();
786
833
if (gfxError != OSystem::kTransactionSuccess || !isGFXModeSet) {
787
834
Testsuite::logDetailedPrintf("Switcing to initial state failed\n");
791
838
// Done with cursors, Make them invisible, any other test may enable and use it.
792
839
CursorMan.showMouse(false);
796
bool GFXtests::shakingEffect() {
843
TestExitStatus GFXtests::shakingEffect() {
798
845
Testsuite::clearScreen();
799
846
Common::String info = "Shaking test. You should expect the graphics(text/bars etc) drawn on the screen to shake!";
801
848
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
802
849
Testsuite::logPrintf("Info! Skipping test : Shaking Effect\n");
806
853
Common::Point pt(0, 100);
807
854
Testsuite::writeOnScreen("If Shaking Effect works, this should shake!", pt);
809
856
while (times--) {
810
857
g_system->setShakePos(25);
858
g_system->delayMillis(50);
811
859
g_system->updateScreen();
812
860
g_system->setShakePos(0);
861
g_system->delayMillis(50);
813
862
g_system->updateScreen();
815
864
g_system->delayMillis(1500);
817
866
if (Testsuite::handleInteractiveInput("Did the Shaking test worked as you were expecting?", "Yes", "No", kOptionRight)) {
818
867
Testsuite::logDetailedPrintf("Shaking Effect didn't worked");
824
bool GFXtests::focusRectangle() {
873
TestExitStatus GFXtests::focusRectangle() {
826
875
Testsuite::clearScreen();
827
876
Common::String info = "Testing : Setting and hiding Focus \n"
828
877
"If this feature is implemented, the focus should be toggled between the two rectangles on the corners";
830
879
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
831
880
Testsuite::logPrintf("Info! Skipping test : focus Rectangle\n");
835
884
const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kConsoleFont));
837
886
Graphics::Surface *screen = g_system->lockScreen();
867
916
Testsuite::logDetailedPrintf("Focus Rectangle feature doesn't works. Check platform.\n");
873
bool GFXtests::overlayGraphics() {
922
TestExitStatus GFXtests::overlayGraphics() {
874
923
Testsuite::clearScreen();
875
924
Common::String info = "Overlay Graphics. You should expect to see a green colored rectangle on the screen";
877
926
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
878
927
Testsuite::logPrintf("Info! Skipping test : Overlay Graphics\n");
882
931
Graphics::PixelFormat pf = g_system->getOverlayFormat();
884
933
OverlayColor buffer[50 * 100];
900
949
if (Testsuite::handleInteractiveInput("Did you see a green overlayed rectangle?", "Yes", "No", kOptionRight)) {
901
950
Testsuite::logDetailedPrintf("Overlay Rectangle feature doesn't works\n");
908
bool GFXtests::paletteRotation() {
957
TestExitStatus GFXtests::paletteRotation() {
910
959
Common::String info = "Palette rotation. Here we draw a full 256 colored rainbow and then rotate it.\n"
911
960
"Note that the screen graphics change without having to draw anything.\n"
912
"The palette should appear to rotate, Click the mouse button to exit.";
961
"The palette should appear to rotate, as a result, the background will change its color too.\n"
962
"Click the mouse button to exit.";
914
964
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
915
965
Testsuite::logPrintf("Info! Skipping test : palette Rotation\n");
968
Common::Point pt(0, 10);
918
969
Testsuite::clearEntireScreen();
920
971
// Use 256 colors
921
byte palette[256 * 4] = {0};
972
byte palette[256 * 3] = {0};
926
977
for (int i = 0; i < 256; i++) {
927
978
HSVtoRGB(r, g, b, i, 1, 1);
929
980
palette[colIndx] = r;
930
981
palette[colIndx + 1] = g;
931
982
palette[colIndx + 2] = b;
934
985
// Initialize this palette.
935
g_system->setPalette(palette, 0, 256);
986
g_system->getPaletteManager()->setPalette(palette, 0, 256);
937
988
// Draw 256 Rectangles, each 1 pixel wide and 10 pixels long
938
989
// one for 0-255 color range other for 0-127-255 range
979
1030
GFXTestSuite::setCustomColor(255, 0, 0);
980
1031
Testsuite::clearScreen();
982
if(Testsuite::handleInteractiveInput("Did you saw a rotation in colors of rectangles displayed on screen?", "Yes", "No", kOptionRight)) {
1033
if(Testsuite::handleInteractiveInput("Did you see a rotation in colors of rectangles displayed on screen?", "Yes", "No", kOptionRight)) {
989
bool GFXtests::cursorTrails() {
1040
TestExitStatus GFXtests::cursorTrails() {
990
1041
Common::String info = "With some shake offset the cursor was known to leave trails in the GUI\n"
991
1042
"Here we set some offset and ask user to check for mouse trails, \n"
992
1043
"the test is passed when there are no trails";
994
1045
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
995
1046
Testsuite::logPrintf("Info! Skipping test : Cursor Trails\n");
1047
return kTestSkipped;
1049
TestExitStatus passed = kTestFailed;
999
1050
g_system->setShakePos(25);
1000
1051
g_system->updateScreen();
1001
1052
if (Testsuite::handleInteractiveInput("Does the cursor leaves trails while moving?", "Yes", "No", kOptionRight)) {
1053
passed = kTestPassed;
1004
1055
g_system->setShakePos(0);
1005
1056
g_system->updateScreen();
1009
bool GFXtests::pixelFormats() {
1060
TestExitStatus GFXtests::pixelFormats() {
1010
1061
Testsuite::clearScreen();
1011
1062
Common::String info = "Testing pixel formats. Here we iterate over all the supported pixel formats and display some colors using them\n"
1012
1063
"This may take long, especially if the backend supports many pixel formats";
1014
1065
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
1015
Testsuite::logPrintf("Info! Skipping test : focus Rectangle\n");
1066
Testsuite::logPrintf("Info! Skipping test : Pixel Formats\n");
1067
return kTestSkipped;
1019
1070
Common::List<Graphics::PixelFormat> pfList = g_system->getSupportedFormats();
1055
1106
Common::Point pt(0, 170);
1056
1107
Common::String msg;
1057
// XXX: Can use snprintf?
1058
msg = Common::String::printf("Testing Pixel Formats, %d of %d", numFormatsTested, pfList.size());
1108
msg = Common::String::format("Testing Pixel Formats, %d of %d", numFormatsTested, pfList.size());
1059
1109
Testsuite::writeOnScreen(msg, pt, true);
1061
1111
// CopyRectToScreen could have been used, but that may involve writing code which
1065
1115
Graphics::Surface *screen = g_system->lockScreen();
1067
// Draw 6 rectangles centred at (50, 160), piled over one another
1117
// Draw 6 rectangles centered at (50, 160), piled over one another
1068
1118
// each with color in colors[]
1069
1119
for (int i = 0; i < 6; i++) {
1070
1120
screen->fillRect(Common::Rect::center(160, 20 + i * 10, 100, 10), colors[i]);
1091
1141
Testsuite::clearScreen();
1093
1143
if (numFailed) {
1094
Testsuite::logDetailedPrintf("Pixel Format test: Failed : %d, Passed : %d, Ignored %d\n", numFailed, numPassed, numFormatsTested - (numPassed + numFailed));
1144
Testsuite::logDetailedPrintf("Pixel Format test: Failed : %d, Passed : %d, Ignored %d\n",numFailed, numPassed, numFormatsTested - (numPassed + numFailed));
1101
1151
} // End of namespace Testbed