| 1 |
/** |
| 2 |
* Test graphics display |
| 3 |
|
| 4 |
* Copyright (C) 2015 Sylvain Beucler |
| 5 |
|
| 6 |
* This file is part of GNU FreeDink |
| 7 |
|
| 8 |
* GNU FreeDink is free software: you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Affero General Public License |
| 10 |
* as published by the Free Software Foundation, either version 3 of |
| 11 |
* the License, or (at your option) any later version. |
| 12 |
|
| 13 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Affero General Public License for more details. |
| 17 |
|
| 18 |
* You should have received a copy of the GNU Affero General Public |
| 19 |
* License along with GNU FreeDink. If not, see |
| 20 |
* <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifdef HAVE_CONFIG_H |
| 24 |
#include <config.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <cxxtest/TestSuite.h> |
| 28 |
|
| 29 |
#include "IOGfxDisplaySW.h" |
| 30 |
#include "IOGfxDisplayGL2.h" |
| 31 |
#include "IOGfxSurfaceSW.h" |
| 32 |
#include "SDL_image.h" |
| 33 |
#include "freedink_xpm.h" |
| 34 |
#include "log.h" |
| 35 |
#include "ImageLoader.h" /* GFX_ref_pal */ // TODO: break dep |
| 36 |
#include "gfx_palette.h" |
| 37 |
|
| 38 |
/** |
| 39 |
* Test graphics output |
| 40 |
* Shortcomings: |
| 41 |
* - Buggy driver init |
| 42 |
* - SDL_Renderer drops all ops when window is hidden; use a visible window |
| 43 |
* - Android display is 16-bit, so use fuzzy color comparisons |
| 44 |
* - Stretched display (fullscreen and Android) use linear interpolation, so |
| 45 |
* check fuzzy pixel positions after flipStretch() |
| 46 |
* - No OpenGL ES 2.0 API to retrieve texture contents, only retrieve main buffer |
| 47 |
*/ |
| 48 |
class TestIOGfxDisplay : public CxxTest::TestSuite { |
| 49 |
public: |
| 50 |
IOGfxDisplay* display; |
| 51 |
struct { |
| 52 |
bool gl; |
| 53 |
bool truecolor; |
| 54 |
} lastDisplay; |
| 55 |
|
| 56 |
SDL_Color white; |
| 57 |
SDL_Color black; |
| 58 |
SDL_Color green; |
| 59 |
SDL_Color blue; |
| 60 |
SDL_Color dark123; |
| 61 |
|
| 62 |
|
| 63 |
TestIOGfxDisplay() { |
| 64 |
TS_ASSERT_EQUALS(SDL_InitSubSystem(SDL_INIT_VIDEO), 0); |
| 65 |
//SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG); |
| 66 |
|
| 67 |
display = NULL; |
| 68 |
lastDisplay.gl = false; |
| 69 |
lastDisplay.truecolor = false; |
| 70 |
|
| 71 |
white = {255, 255, 255, 255}; |
| 72 |
black = { 0, 0, 0, 255}; |
| 73 |
green = {255, 255, 0, 255}; |
| 74 |
blue = { 0, 0, 255, 255}; |
| 75 |
dark123 = { 1, 2, 3, 255}; |
| 76 |
} |
| 77 |
~TestIOGfxDisplay() { |
| 78 |
SDL_QuitSubSystem(SDL_INIT_VIDEO); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
void setUp() { |
| 84 |
// init palette; hopefully can be removed if we get rid of blitFormat |
| 85 |
for (int i = 0; i < 256; i++) { |
| 86 |
GFX_ref_pal[i].r = i; |
| 87 |
GFX_ref_pal[i].g = i; |
| 88 |
GFX_ref_pal[i].b = i; |
| 89 |
GFX_ref_pal[i].a = 255; |
| 90 |
} |
| 91 |
// Use a color that fail tests if RGBA->ABGR-reversed (non-symmetric) |
| 92 |
// Fully saturated green and blue to avoid fuzzy color comparisons |
| 93 |
GFX_ref_pal[1] = green; |
| 94 |
GFX_ref_pal[2] = blue; |
| 95 |
GFX_ref_pal[3] = dark123; |
| 96 |
gfx_palette_set_phys(GFX_ref_pal); |
| 97 |
} |
| 98 |
void tearDown() { |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
void openDisplay(bool gl, bool truecolor, Uint32 flags) { |
| 104 |
//log_info("* Requesting %s %s", gl?"GL2":"SW", truecolor?"truecolor":""); |
| 105 |
//flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
| 106 |
//if (gl) flags |= SDL_WINDOW_HIDDEN; // off-screen rendering |
| 107 |
//SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2"); |
| 108 |
//SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); |
| 109 |
|
| 110 |
// cache |
| 111 |
if (display && lastDisplay.gl == gl && lastDisplay.truecolor == truecolor) { |
| 112 |
display->clear(); |
| 113 |
return; |
| 114 |
} |
| 115 |
if (display) { |
| 116 |
display->close(); |
| 117 |
delete display; |
| 118 |
display = NULL; |
| 119 |
} |
| 120 |
|
| 121 |
if (gl) |
| 122 |
display = new IOGfxDisplayGL2(50, 50, truecolor, flags); |
| 123 |
else |
| 124 |
display = new IOGfxDisplaySW(50, 50, truecolor, flags); |
| 125 |
bool opened = display->open(); |
| 126 |
TS_ASSERT_EQUALS(opened, true); |
| 127 |
|
| 128 |
lastDisplay.gl = gl; |
| 129 |
lastDisplay.truecolor = truecolor; |
| 130 |
|
| 131 |
display->logDisplayInfo(); |
| 132 |
} |
| 133 |
void closeDisplay() { |
| 134 |
//SDL_Delay(1000); |
| 135 |
} |
| 136 |
|
| 137 |
void getColorAtRGBA(SDL_Surface* img, int x, int y, SDL_Color* c) { |
| 138 |
Uint32* line = (Uint32*)(&((Uint8*)img->pixels)[y*img->pitch]); |
| 139 |
SDL_GetRGBA(line[x], img->format, &c->r, &c->g, &c->b, &c->a); |
| 140 |
} |
| 141 |
|
| 142 |
void getColorAtI(SDL_Surface* img, int x, int y, SDL_Color* c) { |
| 143 |
if (img->format->BitsPerPixel == 32) { |
| 144 |
Uint32* line = (Uint32*)(&((Uint8*)img->pixels)[y*img->pitch]); |
| 145 |
SDL_GetRGBA(line[x], img->format, &c->r, &c->g, &c->b, &c->a); |
| 146 |
} else if (img->format->BitsPerPixel == 8) { |
| 147 |
c->r = c->g = c->b = ((Uint8*)img->pixels)[x + y*img->pitch]; |
| 148 |
c->a = 255; |
| 149 |
} else { |
| 150 |
c->r = c->g = c->b = c->a = 0; |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
void ctestSplash() { |
| 156 |
// A first inter-texture blit before anything else |
| 157 |
// In 2015 the splash screen (first blit+flip) was ignored/delayed |
| 158 |
SDL_Surface* img; |
| 159 |
IOGfxSurface *backbuffer, *splash; |
| 160 |
|
| 161 |
backbuffer = display->allocBuffer(50, 50); |
| 162 |
//g->flip(backbuffer); // not a single flip |
| 163 |
|
| 164 |
img = SDL_CreateRGBSurface(0, 40, 40, 8, 0, 0, 0, 0); |
| 165 |
Uint8* pixels = (Uint8*)img->pixels; |
| 166 |
SDL_SetPaletteColors(img->format->palette, GFX_ref_pal, 0, 256); |
| 167 |
// Make a bit square to cope with stretching and color interpolation |
| 168 |
pixels[0] = 1; |
| 169 |
pixels[1] = 1; |
| 170 |
pixels[2] = 1; |
| 171 |
pixels[img->pitch+0] = 1; |
| 172 |
pixels[img->pitch+1] = 1; |
| 173 |
pixels[img->pitch+2] = 1; |
| 174 |
pixels[img->pitch*2+0] = 1; |
| 175 |
pixels[img->pitch*2+1] = 1; |
| 176 |
pixels[img->pitch*2+0] = 1; |
| 177 |
//SDL_SaveBMP(img, "splash-img.bmp"); |
| 178 |
splash = display->upload(img); img = NULL; |
| 179 |
//g->flip(splash); // not a single flip |
| 180 |
|
| 181 |
SDL_Rect dstrect = {0, 0, -1, -1}; |
| 182 |
backbuffer->blit(splash, NULL, &dstrect); |
| 183 |
|
| 184 |
// Check the result: |
| 185 |
display->flipStretch(backbuffer); |
| 186 |
// Double the blit in case snapshot() reads from the backbuffer |
| 187 |
// https://bugzilla.libsdl.org/show_bug.cgi?id=3619#c4 |
| 188 |
// Kinda defeats the goal of this test... |
| 189 |
display->flipStretch(backbuffer); |
| 190 |
|
| 191 |
SDL_Surface* screenshot = display->screenshot(); |
| 192 |
//SDL_SaveBMP(screenshot, "splash-screenshot.bmp"); |
| 193 |
TS_ASSERT(screenshot != NULL); |
| 194 |
if (screenshot == NULL) |
| 195 |
return; |
| 196 |
Uint8 cr, cg, cb, ca; |
| 197 |
int x = 1, y = 1; |
| 198 |
display->surfToDisplayCoords(backbuffer, x, y); |
| 199 |
SDL_GetRGBA(((Uint32*)screenshot->pixels)[x+y*screenshot->w], |
| 200 |
screenshot->format, |
| 201 |
&cr, &cg, &cb, &ca); |
| 202 |
TS_ASSERT_EQUALS(cr, 255); |
| 203 |
TS_ASSERT_EQUALS(cg, 255); |
| 204 |
TS_ASSERT_EQUALS(cb, 0); |
| 205 |
TS_ASSERT_EQUALS(ca, 255); |
| 206 |
SDL_FreeSurface(screenshot); |
| 207 |
|
| 208 |
delete splash; |
| 209 |
delete backbuffer; |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
void ctest_alloc() { |
| 215 |
IOGfxSurface* surf = display->allocBuffer(300, 300); |
| 216 |
TS_ASSERT(surf != NULL); |
| 217 |
TS_ASSERT_EQUALS(surf->w, 300); |
| 218 |
TS_ASSERT_EQUALS(surf->h, 300); |
| 219 |
delete surf; |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
void ctest_Display_screenshot() { |
| 225 |
SDL_Surface *img, *screenshot; |
| 226 |
IOGfxSurface *backbuffer, *surf; |
| 227 |
SDL_Color cs; |
| 228 |
SDL_Rect bbbox; |
| 229 |
|
| 230 |
backbuffer = display->allocBuffer(50, 50); |
| 231 |
bbbox = { 0,0, 50,50 }; |
| 232 |
|
| 233 |
img = SDL_CreateRGBSurface(0, 39, 39, 8, 0, 0, 0, 0); |
| 234 |
Uint8* pixels = (Uint8*)img->pixels; |
| 235 |
SDL_SetPaletteColors(img->format->palette, GFX_ref_pal, 0, 256); |
| 236 |
pixels[0] = 255; |
| 237 |
pixels[1] = 1; |
| 238 |
pixels[img->pitch+0] = 3; |
| 239 |
surf = display->upload(img); img = NULL; |
| 240 |
backbuffer->blit(surf, NULL, NULL); |
| 241 |
|
| 242 |
|
| 243 |
// Check final framebuffer |
| 244 |
display->flipDebug(backbuffer); |
| 245 |
// Check that pic is not vertically flipped |
| 246 |
screenshot = display->screenshot(&bbbox); |
| 247 |
|
| 248 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 249 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 250 |
|
| 251 |
getColorAtRGBA(screenshot, 1, 0, &cs); |
| 252 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 253 |
|
| 254 |
// Check main buffer precision; not exact on Android's RGB565 |
| 255 |
getColorAtRGBA(screenshot, 0, 1, &cs); |
| 256 |
TS_ASSERT_RELATION(std::less_equal<int>, cs.r, 8); |
| 257 |
TS_ASSERT_RELATION(std::less_equal<int>, cs.g, 4); |
| 258 |
TS_ASSERT_RELATION(std::less_equal<int>, cs.b, 8); |
| 259 |
|
| 260 |
SDL_FreeSurface(screenshot); |
| 261 |
|
| 262 |
|
| 263 |
delete surf; |
| 264 |
delete backbuffer; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
void ctest_Surface_screenshot_truecolor() { |
| 270 |
SDL_Surface *img, *screenshot; |
| 271 |
IOGfxSurface *backbuffer, *surf; |
| 272 |
SDL_Color cs; |
| 273 |
SDL_Rect bbbox; |
| 274 |
|
| 275 |
|
| 276 |
backbuffer = display->allocBuffer(50, 50); |
| 277 |
bbbox = { 0,0, 50,50 }; |
| 278 |
|
| 279 |
img = SDL_CreateRGBSurface(0, 40, 40, 8, 0, 0, 0, 0); |
| 280 |
Uint8* pixels = (Uint8*)img->pixels; |
| 281 |
SDL_SetPaletteColors(img->format->palette, GFX_ref_pal, 0, 256); |
| 282 |
pixels[0] = 255; |
| 283 |
pixels[1] = 1; |
| 284 |
pixels[img->pitch+0] = 3; |
| 285 |
surf = display->upload(img); img = NULL; |
| 286 |
backbuffer->blit(surf, NULL, NULL); |
| 287 |
|
| 288 |
|
| 289 |
// Check texture directly |
| 290 |
screenshot = backbuffer->screenshot(); |
| 291 |
TS_ASSERT(screenshot != NULL); |
| 292 |
if (screenshot == NULL) |
| 293 |
return; |
| 294 |
|
| 295 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 296 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 297 |
|
| 298 |
getColorAtRGBA(screenshot, 1, 0, &cs); |
| 299 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 300 |
|
| 301 |
getColorAtRGBA(screenshot, 0, 1, &cs); |
| 302 |
TS_ASSERT_SAME_DATA(&cs, &dark123, sizeof(SDL_Color)); |
| 303 |
|
| 304 |
SDL_FreeSurface(screenshot); |
| 305 |
|
| 306 |
|
| 307 |
delete surf; |
| 308 |
delete backbuffer; |
| 309 |
} |
| 310 |
|
| 311 |
void ctest_Surface_screenshot_indexed() { |
| 312 |
SDL_Surface *img, *screenshot; |
| 313 |
IOGfxSurface *backbuffer, *surf; |
| 314 |
SDL_Color ce, cs; |
| 315 |
SDL_Rect bbbox; |
| 316 |
|
| 317 |
|
| 318 |
backbuffer = display->allocBuffer(50, 50); |
| 319 |
bbbox = { 0,0, 50,50 }; |
| 320 |
|
| 321 |
img = SDL_CreateRGBSurface(0, 40, 40, 8, 0, 0, 0, 0); |
| 322 |
Uint8* pixels = (Uint8*)img->pixels; |
| 323 |
SDL_SetPaletteColors(img->format->palette, GFX_ref_pal, 0, 256); |
| 324 |
pixels[0] = 255; |
| 325 |
pixels[1] = 1; |
| 326 |
pixels[3] = 3; |
| 327 |
surf = display->upload(img); img = NULL; |
| 328 |
backbuffer->blit(surf, NULL, NULL); |
| 329 |
|
| 330 |
|
| 331 |
// Check texture directly |
| 332 |
screenshot = backbuffer->screenshot(); |
| 333 |
TS_ASSERT(screenshot != NULL); |
| 334 |
if (screenshot == NULL) |
| 335 |
return; |
| 336 |
|
| 337 |
ce = { 255, 255, 255, 255 }; |
| 338 |
getColorAtI(screenshot, 0, 0, &cs); |
| 339 |
TS_ASSERT_SAME_DATA(&cs, &ce, sizeof(SDL_Color)); |
| 340 |
|
| 341 |
ce = { 1, 1, 1, 255 }; |
| 342 |
getColorAtI(screenshot, 1, 0, &cs); |
| 343 |
TS_ASSERT_SAME_DATA(&cs, &ce, sizeof(SDL_Color)); |
| 344 |
|
| 345 |
ce = { 3, 3, 3, 255 }; |
| 346 |
getColorAtI(screenshot, 3, 0, &cs); |
| 347 |
TS_ASSERT_SAME_DATA(&cs, &ce, sizeof(SDL_Color)); |
| 348 |
|
| 349 |
SDL_FreeSurface(screenshot); |
| 350 |
|
| 351 |
|
| 352 |
delete surf; |
| 353 |
delete backbuffer; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
void ctest_surfToDisplayCoords() { |
| 358 |
SDL_Surface* img; |
| 359 |
IOGfxSurface *surf; |
| 360 |
int x, y; |
| 361 |
|
| 362 |
img = SDL_CreateRGBSurface(0, 50, 50, 8, 0, 0, 0, 0); |
| 363 |
surf = display->upload(img); img = NULL; |
| 364 |
|
| 365 |
// Force display to 50x50 even if the system gave us something else |
| 366 |
display->onSizeChange(50, 50); |
| 367 |
|
| 368 |
x = 0; y = 0; |
| 369 |
display->surfToDisplayCoords(surf, x, y); |
| 370 |
TS_ASSERT_EQUALS(x, 0); |
| 371 |
TS_ASSERT_EQUALS(y, 0); |
| 372 |
|
| 373 |
x = 11; y = 12; |
| 374 |
display->surfToDisplayCoords(surf, x, y); |
| 375 |
TS_ASSERT_EQUALS(x, 11); |
| 376 |
TS_ASSERT_EQUALS(y, 12); |
| 377 |
|
| 378 |
display->onSizeChange(800, 480); |
| 379 |
|
| 380 |
x = 0; y = 0; |
| 381 |
display->surfToDisplayCoords(surf, x, y); |
| 382 |
TS_ASSERT_EQUALS(x, 164); |
| 383 |
TS_ASSERT_EQUALS(y, 4); |
| 384 |
|
| 385 |
x = 11; y = 12; |
| 386 |
display->surfToDisplayCoords(surf, x, y); |
| 387 |
TS_ASSERT_EQUALS(x, 270); |
| 388 |
TS_ASSERT_EQUALS(y, 120); |
| 389 |
|
| 390 |
display->onSizeChange(50, 50); |
| 391 |
|
| 392 |
delete surf; |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
void ctest_blit() { |
| 397 |
SDL_Surface *img, *screenshot; |
| 398 |
IOGfxSurface *backbuffer, *surf; |
| 399 |
SDL_Color cs; |
| 400 |
SDL_Rect bbbox; |
| 401 |
|
| 402 |
backbuffer = display->allocBuffer(50, 50); |
| 403 |
bbbox = { 0,0, 50,50 }; |
| 404 |
|
| 405 |
img = SDL_CreateRGBSurface(0, 5, 5, 8, 0, 0, 0, 0); |
| 406 |
Uint8* pixels = (Uint8*)img->pixels; |
| 407 |
SDL_SetPaletteColors(img->format->palette, GFX_ref_pal, 0, 256); |
| 408 |
SDL_SetColorKey(img, SDL_TRUE, 0); |
| 409 |
pixels[0] = 255; |
| 410 |
pixels[1] = 1; |
| 411 |
pixels[img->pitch] = 255; |
| 412 |
pixels[img->pitch+1] = 1; |
| 413 |
surf = display->upload(img); |
| 414 |
|
| 415 |
SDL_Rect dstrect = {0, 0, -1, -1}; |
| 416 |
|
| 417 |
dstrect.x = 0; dstrect.y = 0; |
| 418 |
backbuffer->blit(surf, NULL, &dstrect); |
| 419 |
display->flipDebug(backbuffer); |
| 420 |
screenshot = display->screenshot(&bbbox); |
| 421 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 422 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 423 |
getColorAtRGBA(screenshot, 1, 0, &cs); |
| 424 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 425 |
SDL_FreeSurface(screenshot); |
| 426 |
|
| 427 |
dstrect.x = 20; dstrect.y = 20; |
| 428 |
backbuffer->blit(surf, NULL, &dstrect); |
| 429 |
display->flipDebug(backbuffer); |
| 430 |
screenshot = display->screenshot(&bbbox); |
| 431 |
getColorAtRGBA(screenshot, 20, 20, &cs); |
| 432 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 433 |
getColorAtRGBA(screenshot, 21, 20, &cs); |
| 434 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 435 |
SDL_FreeSurface(screenshot); |
| 436 |
|
| 437 |
dstrect.x = -1; dstrect.y = -1; |
| 438 |
backbuffer->blit(surf, NULL, &dstrect); |
| 439 |
display->flipDebug(backbuffer); |
| 440 |
screenshot = display->screenshot(&bbbox); |
| 441 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 442 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 443 |
SDL_FreeSurface(screenshot); |
| 444 |
|
| 445 |
dstrect.x = 49; dstrect.y = 49; |
| 446 |
backbuffer->blit(surf, NULL, &dstrect); |
| 447 |
display->flipDebug(backbuffer); |
| 448 |
screenshot = display->screenshot(&bbbox); |
| 449 |
getColorAtRGBA(screenshot, 49, 49, &cs); |
| 450 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 451 |
SDL_FreeSurface(screenshot); |
| 452 |
|
| 453 |
|
| 454 |
dstrect.x = 0; dstrect.y = 0; |
| 455 |
backbuffer->blit(surf, NULL, &dstrect); |
| 456 |
display->flipDebug(backbuffer); |
| 457 |
screenshot = display->screenshot(&bbbox); |
| 458 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 459 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 460 |
SDL_FreeSurface(screenshot); |
| 461 |
dstrect.x = -2; dstrect.y = -2; |
| 462 |
backbuffer->blit(surf, NULL, &dstrect); |
| 463 |
display->flipDebug(backbuffer); |
| 464 |
screenshot = display->screenshot(&bbbox); |
| 465 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 466 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 467 |
SDL_FreeSurface(screenshot); |
| 468 |
dstrect.x = -2; dstrect.y = -2; |
| 469 |
backbuffer->blitNoColorKey(surf, NULL, &dstrect); |
| 470 |
display->flipDebug(backbuffer); |
| 471 |
screenshot = display->screenshot(&bbbox); |
| 472 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 473 |
TS_ASSERT_SAME_DATA(&cs, &black, sizeof(SDL_Color)); |
| 474 |
SDL_FreeSurface(screenshot); |
| 475 |
|
| 476 |
dstrect.x = 0; dstrect.y = 0; |
| 477 |
dstrect.w = 10; dstrect.h = 20; |
| 478 |
backbuffer->blitStretch(surf, NULL, &dstrect); |
| 479 |
display->flipDebug(backbuffer); |
| 480 |
screenshot = display->screenshot(&bbbox); |
| 481 |
getColorAtRGBA(screenshot, 0, 7, &cs); |
| 482 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 483 |
getColorAtRGBA(screenshot, 3, 7, &cs); |
| 484 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 485 |
SDL_FreeSurface(screenshot); |
| 486 |
|
| 487 |
SDL_Rect srcrect = {1,1, 1,1}; |
| 488 |
dstrect.x = 0; dstrect.y = 0; |
| 489 |
backbuffer->blit(surf, &srcrect, &dstrect); |
| 490 |
display->flipDebug(backbuffer); |
| 491 |
screenshot = display->screenshot(&bbbox); |
| 492 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 493 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 494 |
SDL_FreeSurface(screenshot); |
| 495 |
|
| 496 |
delete surf; |
| 497 |
|
| 498 |
|
| 499 |
if (display->truecolor) { |
| 500 |
// BMP typically encoded as BGR need to be uploaded with proper format |
| 501 |
img = SDL_CreateRGBSurface(0, 5, 5, 24, |
| 502 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
| 503 |
0x0000ff00, 0x00ff0000, 0xff000000, 0x00000000 |
| 504 |
#else |
| 505 |
0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 |
| 506 |
#endif |
| 507 |
); |
| 508 |
pixels = (Uint8*)img->pixels; |
| 509 |
pixels[0] = 255; pixels[1] = 0; pixels[2] = 0; |
| 510 |
pixels[3] = 255; pixels[4] = 0; pixels[5] = 0; |
| 511 |
pixels[img->pitch ] = 255; pixels[img->pitch+1] = 0; pixels[img->pitch+2] = 0; |
| 512 |
pixels[img->pitch+3] = 255; pixels[img->pitch+4] = 0; pixels[img->pitch+5] = 0; |
| 513 |
IOGfxSurface *surfRgb = display->upload(img); |
| 514 |
|
| 515 |
dstrect = {0, 0, -1, -1}; |
| 516 |
|
| 517 |
dstrect.x = 0; dstrect.y = 0; |
| 518 |
backbuffer->blit(surfRgb, NULL, &dstrect); |
| 519 |
display->flipDebug(backbuffer); |
| 520 |
screenshot = display->screenshot(&bbbox); |
| 521 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 522 |
TS_ASSERT_SAME_DATA(&cs, &blue, sizeof(SDL_Color)); |
| 523 |
SDL_FreeSurface(screenshot); |
| 524 |
|
| 525 |
delete surfRgb; |
| 526 |
} else { |
| 527 |
// Image already converted to 8-bit by |
| 528 |
// ImageLoader::loadToBlitFormat, no 24-bit |
| 529 |
} |
| 530 |
|
| 531 |
delete backbuffer; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
void ctest_fillRect() { |
| 537 |
IOGfxSurface *backbuffer; |
| 538 |
SDL_Surface *screenshot; |
| 539 |
SDL_Color cs; |
| 540 |
SDL_Rect bbbox; |
| 541 |
|
| 542 |
backbuffer = display->allocBuffer(50, 50); |
| 543 |
bbbox = { 0,0, 50,50 }; |
| 544 |
|
| 545 |
SDL_Rect dstrect = {-1, -1, -1, -1}; |
| 546 |
|
| 547 |
backbuffer->fillRect(NULL, 255, 255, 0); |
| 548 |
display->flipDebug(backbuffer); |
| 549 |
screenshot = display->screenshot(&bbbox); |
| 550 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 551 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 552 |
SDL_FreeSurface(screenshot); |
| 553 |
|
| 554 |
dstrect.x = 5; dstrect.y = 5; |
| 555 |
dstrect.w = 20; dstrect.h = 10; |
| 556 |
backbuffer->fillRect(&dstrect, 0, 0, 255); |
| 557 |
display->flipDebug(backbuffer); |
| 558 |
screenshot = display->screenshot(&bbbox); |
| 559 |
getColorAtRGBA(screenshot, 4, 4, &cs); |
| 560 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 561 |
getColorAtRGBA(screenshot, 5, 5, &cs); |
| 562 |
TS_ASSERT_SAME_DATA(&cs, &blue, sizeof(SDL_Color)); |
| 563 |
getColorAtRGBA(screenshot, 24, 14, &cs); |
| 564 |
TS_ASSERT_SAME_DATA(&cs, &blue, sizeof(SDL_Color)); |
| 565 |
getColorAtRGBA(screenshot, 25, 14, &cs); |
| 566 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 567 |
getColorAtRGBA(screenshot, 24, 15, &cs); |
| 568 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 569 |
SDL_FreeSurface(screenshot); |
| 570 |
|
| 571 |
backbuffer->vlineRGB(10, 0,49, 255,255,0); |
| 572 |
display->flipDebug(backbuffer); |
| 573 |
screenshot = display->screenshot(&bbbox); |
| 574 |
getColorAtRGBA(screenshot, 10, 0, &cs); |
| 575 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 576 |
getColorAtRGBA(screenshot, 10, 49, &cs); |
| 577 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 578 |
SDL_FreeSurface(screenshot); |
| 579 |
|
| 580 |
backbuffer->hlineRGB(0,49, 10, 255,255,0); |
| 581 |
display->flipDebug(backbuffer); |
| 582 |
screenshot = display->screenshot(&bbbox); |
| 583 |
getColorAtRGBA(screenshot, 0, 10, &cs); |
| 584 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 585 |
getColorAtRGBA(screenshot, 49, 10, &cs); |
| 586 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 587 |
SDL_FreeSurface(screenshot); |
| 588 |
|
| 589 |
delete backbuffer; |
| 590 |
} |
| 591 |
|
| 592 |
void ctest_fill_screen() { |
| 593 |
IOGfxSurface *backbuffer; |
| 594 |
SDL_Surface *screenshot; |
| 595 |
SDL_Color cs; |
| 596 |
SDL_Rect bbbox; |
| 597 |
|
| 598 |
backbuffer = display->allocBuffer(50, 50); |
| 599 |
bbbox = { 0,0, 50,50 }; |
| 600 |
|
| 601 |
backbuffer->fill_screen(0, GFX_ref_pal); |
| 602 |
display->flipDebug(backbuffer); |
| 603 |
screenshot = display->screenshot(&bbbox); |
| 604 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 605 |
TS_ASSERT_SAME_DATA(&cs, &black, sizeof(SDL_Color)); |
| 606 |
SDL_FreeSurface(screenshot); |
| 607 |
|
| 608 |
backbuffer->fill_screen(1, GFX_ref_pal); |
| 609 |
display->flipDebug(backbuffer); |
| 610 |
screenshot = display->screenshot(&bbbox); |
| 611 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 612 |
TS_ASSERT_SAME_DATA(&cs, &green, sizeof(SDL_Color)); |
| 613 |
SDL_FreeSurface(screenshot); |
| 614 |
|
| 615 |
backbuffer->fill_screen(2, GFX_ref_pal); |
| 616 |
display->flipDebug(backbuffer); |
| 617 |
screenshot = display->screenshot(&bbbox); |
| 618 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 619 |
TS_ASSERT_SAME_DATA(&cs, &blue, sizeof(SDL_Color)); |
| 620 |
SDL_FreeSurface(screenshot); |
| 621 |
|
| 622 |
// Using a /8 value to support RGB565 (Android) screens |
| 623 |
SDL_Color gray16 = {16,16,16,255}; |
| 624 |
backbuffer->fill_screen(16, GFX_ref_pal); |
| 625 |
display->flipDebug(backbuffer); |
| 626 |
screenshot = display->screenshot(&bbbox); |
| 627 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 628 |
TS_ASSERT_SAME_DATA(&cs, &gray16, sizeof(SDL_Color)); |
| 629 |
SDL_FreeSurface(screenshot); |
| 630 |
|
| 631 |
delete backbuffer; |
| 632 |
} |
| 633 |
|
| 634 |
void ctestBrightness() { |
| 635 |
SDL_Surface *img, *screenshot; |
| 636 |
IOGfxSurface *backbuffer, *surf; |
| 637 |
SDL_Color cs; |
| 638 |
SDL_Rect bbbox; |
| 639 |
|
| 640 |
backbuffer = display->allocBuffer(50, 50); |
| 641 |
bbbox = { 0,0, 50,50 }; |
| 642 |
|
| 643 |
img = SDL_CreateRGBSurface(0, 5, 5, 8, 0, 0, 0, 0); |
| 644 |
Uint8* pixels = (Uint8*)img->pixels; |
| 645 |
SDL_SetPaletteColors(img->format->palette, GFX_ref_pal, 0, 256); |
| 646 |
SDL_SetColorKey(img, SDL_TRUE, 0); |
| 647 |
pixels[0] = 255; |
| 648 |
pixels[1] = 1; |
| 649 |
pixels[img->pitch] = 255; |
| 650 |
pixels[img->pitch+1] = 1; |
| 651 |
surf = display->upload(img); |
| 652 |
|
| 653 |
SDL_Rect dstrect = {0, 0, -1, -1}; |
| 654 |
dstrect.x = 0; dstrect.y = 0; |
| 655 |
|
| 656 |
display->brightness = 0; |
| 657 |
backbuffer->blit(surf, NULL, &dstrect); |
| 658 |
display->flipDebug(backbuffer); |
| 659 |
screenshot = display->screenshot(&bbbox); |
| 660 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 661 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 662 |
getColorAtRGBA(screenshot, 1, 1, &cs); |
| 663 |
TS_ASSERT_SAME_DATA(&cs, &black, sizeof(SDL_Color)); |
| 664 |
SDL_FreeSurface(screenshot); |
| 665 |
|
| 666 |
display->brightness = 100; |
| 667 |
backbuffer->blit(surf, NULL, &dstrect); |
| 668 |
display->flipDebug(backbuffer); |
| 669 |
screenshot = display->screenshot(&bbbox); |
| 670 |
getColorAtRGBA(screenshot, 0, 0, &cs); |
| 671 |
TS_ASSERT_SAME_DATA(&cs, &white, sizeof(SDL_Color)); |
| 672 |
getColorAtRGBA(screenshot, 1, 1, &cs); |
| 673 |
TS_ASSERT_RELATION(std::less_equal<int>, cs.r, 100); |
| 674 |
TS_ASSERT_RELATION(std::less_equal<int>, cs.g, 100); |
| 675 |
TS_ASSERT_RELATION(std::greater_equal<int>, cs.r, 98); |
| 676 |
TS_ASSERT_RELATION(std::greater_equal<int>, cs.g, 97); |
| 677 |
TS_ASSERT_EQUALS(cs.b, 0); |
| 678 |
SDL_FreeSurface(screenshot); |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
void test01SplashGL2Truecolor() { |
| 683 |
openDisplay(true, true, 0); // 0 <= off-screen rendering may have bugs >( |
| 684 |
ctestSplash(); |
| 685 |
closeDisplay(); |
| 686 |
} |
| 687 |
void test_Display_screenshotGL2Truecolor() { |
| 688 |
openDisplay(true, true, 0); |
| 689 |
ctest_Display_screenshot(); |
| 690 |
closeDisplay(); |
| 691 |
} |
| 692 |
void test_Surface_screenshotGL2Truecolor() { |
| 693 |
openDisplay(true, true, 0); |
| 694 |
ctest_Surface_screenshot_truecolor(); |
| 695 |
closeDisplay(); |
| 696 |
} |
| 697 |
void test_allocGL2Truecolor() { |
| 698 |
openDisplay(true, true, 0); |
| 699 |
ctest_alloc(); |
| 700 |
closeDisplay(); |
| 701 |
} |
| 702 |
void test_surfToDisplayCoordsGL2Truecolor() { |
| 703 |
openDisplay(true, true, 0); |
| 704 |
ctest_surfToDisplayCoords(); |
| 705 |
closeDisplay(); |
| 706 |
} |
| 707 |
void test_blitGL2Truecolor() { |
| 708 |
openDisplay(true, true, 0); |
| 709 |
ctest_blit(); |
| 710 |
closeDisplay(); |
| 711 |
} |
| 712 |
void test_fill_screenGL2Truecolor() { |
| 713 |
openDisplay(true, true, 0); |
| 714 |
ctest_fill_screen(); |
| 715 |
closeDisplay(); |
| 716 |
} |
| 717 |
void test_fillRectGL2Truecolor() { |
| 718 |
openDisplay(true, true, 0); |
| 719 |
ctest_fillRect(); |
| 720 |
closeDisplay(); |
| 721 |
} |
| 722 |
void testBrightnessGL2Truecolor() { |
| 723 |
openDisplay(true, true, 0); |
| 724 |
ctestBrightness(); |
| 725 |
closeDisplay(); |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
void testSplashGL2() { |
| 730 |
openDisplay(true, false, 0); |
| 731 |
ctestSplash(); |
| 732 |
closeDisplay(); |
| 733 |
} |
| 734 |
void test_Display_screenshotGL2() { |
| 735 |
openDisplay(true, false, 0); |
| 736 |
ctest_Display_screenshot(); |
| 737 |
closeDisplay(); |
| 738 |
} |
| 739 |
void test_Surface_screenshotGL2() { |
| 740 |
openDisplay(true, false, 0); |
| 741 |
ctest_Surface_screenshot_indexed(); |
| 742 |
closeDisplay(); |
| 743 |
} |
| 744 |
void test_blitGL2() { |
| 745 |
openDisplay(true, false, 0); |
| 746 |
ctest_blit(); |
| 747 |
closeDisplay(); |
| 748 |
} |
| 749 |
void test_fillRectGL2() { |
| 750 |
openDisplay(true, false, 0); |
| 751 |
ctest_fillRect(); |
| 752 |
closeDisplay(); |
| 753 |
} |
| 754 |
void test_fill_screenGL2() { |
| 755 |
openDisplay(true, false, 0); |
| 756 |
ctest_fill_screen(); |
| 757 |
closeDisplay(); |
| 758 |
} |
| 759 |
// Needs specific palette-based test |
| 760 |
// void testBrightnessGL2Truecolor() { |
| 761 |
// openDisplay(true, true, 0); |
| 762 |
// ctestBrightness(); |
| 763 |
// closeDisplay(); |
| 764 |
// } |
| 765 |
|
| 766 |
|
| 767 |
void testSplashSWTruecolor() { |
| 768 |
openDisplay(false, true, 0); // 0 <= can't render off-screen >( |
| 769 |
ctestSplash(); |
| 770 |
closeDisplay(); |
| 771 |
} |
| 772 |
void test_Display_screenshotSWTruecolor() { |
| 773 |
openDisplay(false, true, 0); |
| 774 |
ctest_Display_screenshot(); |
| 775 |
closeDisplay(); |
| 776 |
} |
| 777 |
void test_Surface_screenshotSWTruecolor() { |
| 778 |
openDisplay(false, true, 0); |
| 779 |
ctest_Surface_screenshot_truecolor(); |
| 780 |
closeDisplay(); |
| 781 |
} |
| 782 |
void test_allocSWTruecolor() { |
| 783 |
openDisplay(false, true, 0); |
| 784 |
ctest_alloc(); |
| 785 |
closeDisplay(); |
| 786 |
} |
| 787 |
void test_blitSWTruecolor() { |
| 788 |
openDisplay(false, true, 0); |
| 789 |
ctest_blit(); |
| 790 |
closeDisplay(); |
| 791 |
} |
| 792 |
void test_fillRectSWTruecolor() { |
| 793 |
openDisplay(false, true, 0); |
| 794 |
ctest_fillRect(); |
| 795 |
closeDisplay(); |
| 796 |
} |
| 797 |
void test_fill_screenSWTruecolor() { |
| 798 |
openDisplay(false, true, 0); |
| 799 |
ctest_fill_screen(); |
| 800 |
closeDisplay(); |
| 801 |
} |
| 802 |
void testBrightnessSWTruecolor() { |
| 803 |
openDisplay(false, true, 0); |
| 804 |
ctestBrightness(); |
| 805 |
closeDisplay(); |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
void testSplashSW() { |
| 810 |
openDisplay(false, false, 0); |
| 811 |
ctestSplash(); |
| 812 |
closeDisplay(); |
| 813 |
} |
| 814 |
void test_Display_screenshotSW() { |
| 815 |
openDisplay(false, false, 0); |
| 816 |
ctest_Display_screenshot(); |
| 817 |
closeDisplay(); |
| 818 |
} |
| 819 |
void test_Surface_screenshotSW() { |
| 820 |
openDisplay(false, false, 0); |
| 821 |
ctest_Surface_screenshot_indexed(); |
| 822 |
closeDisplay(); |
| 823 |
} |
| 824 |
void test_blitSW() { |
| 825 |
openDisplay(false, false, 0); |
| 826 |
ctest_blit(); |
| 827 |
closeDisplay(); |
| 828 |
} |
| 829 |
void test_fillRectSW() { |
| 830 |
openDisplay(false, false, 0); |
| 831 |
ctest_fillRect(); |
| 832 |
closeDisplay(); |
| 833 |
} |
| 834 |
void test_fill_screenSW() { |
| 835 |
openDisplay(false, false, 0); |
| 836 |
ctest_fill_screen(); |
| 837 |
closeDisplay(); |
| 838 |
} |
| 839 |
// Needs specific palette-based test |
| 840 |
// void testBrightnessSW() { |
| 841 |
// openDisplay(false, false, 0); |
| 842 |
// ctestBrightness(); |
| 843 |
// closeDisplay(); |
| 844 |
// } |
| 845 |
}; |