test/testautomation_render.c
changeset 6769 b49778d885cd
parent 6763 9cbd31a3450b
child 6772 5229a117ef97
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testautomation_render.c	Sat Dec 22 17:24:42 2012 -0800
     1.3 @@ -0,0 +1,1025 @@
     1.4 +/**
     1.5 + * Original code: automated SDL platform test written by Edgar Simo "bobbens"
     1.6 + * Extended and extensively updated by aschiffler at ferzkopp dot net
     1.7 + */
     1.8 +
     1.9 +#include <stdio.h>
    1.10 +
    1.11 +#include "SDL.h"
    1.12 +#include "SDL_test.h"
    1.13 +
    1.14 +/* ================= Test Case Implementation ================== */
    1.15 +
    1.16 +#define TESTRENDER_SCREEN_W     80
    1.17 +#define TESTRENDER_SCREEN_H     60
    1.18 +
    1.19 +#define RENDER_COMPARE_FORMAT  SDL_PIXELFORMAT_ARGB8888
    1.20 +#define RENDER_COMPARE_AMASK   0xff000000 /**< Alpha bit mask. */
    1.21 +#define RENDER_COMPARE_RMASK   0x00ff0000 /**< Red bit mask. */
    1.22 +#define RENDER_COMPARE_GMASK   0x0000ff00 /**< Green bit mask. */
    1.23 +#define RENDER_COMPARE_BMASK   0x000000ff /**< Blue bit mask. */
    1.24 +
    1.25 +#define ALLOWABLE_ERROR_OPAQUE	0
    1.26 +#define ALLOWABLE_ERROR_BLENDED	64
    1.27 +
    1.28 +SDL_Window *window = NULL;
    1.29 +SDL_Renderer *renderer = NULL;
    1.30 +
    1.31 +/* Prototypes for helper functions */
    1.32 +
    1.33 +static int _clearScreen (void);
    1.34 +static void _compare(const char *msg, SDL_Surface *s, int allowable_error);
    1.35 +static int _hasTexAlpha(void);
    1.36 +static int _hasTexColor(void);
    1.37 +static SDL_Texture *_loadTestFace(void);
    1.38 +static int _hasBlendModes(void);
    1.39 +static int _hasDrawColor(void);
    1.40 +static int _isSupported(int code);
    1.41 +
    1.42 +/**
    1.43 + * Create software renderer for tests
    1.44 + */
    1.45 +void InitCreateRenderer(void *arg)
    1.46 +{
    1.47 +  int posX = 100, posY = 100, width = 320, height = 240;
    1.48 +  renderer = NULL;
    1.49 +  window = SDL_CreateWindow("render_testCreateRenderer", posX, posY, width, height, 0);
    1.50 +  SDLTest_AssertPass("SDL_CreateWindow()");
    1.51 +  SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
    1.52 +  if (window == NULL) {
    1.53 +      return;
    1.54 +  }
    1.55 +  
    1.56 +  renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    1.57 +  SDLTest_AssertPass("SDL_CreateRenderer()");
    1.58 +  SDLTest_AssertCheck(renderer != 0, "Check SDL_CreateRenderer result");
    1.59 +  if (renderer == 0) {
    1.60 +      SDL_DestroyWindow(window);
    1.61 +      return;
    1.62 +  }
    1.63 +}
    1.64 +
    1.65 +/*
    1.66 + * Destroy renderer for tests  
    1.67 + */
    1.68 +void CleanupDestroyRenderer(void *arg)
    1.69 +{
    1.70 +  if (renderer != NULL) {  
    1.71 +     SDL_DestroyRenderer(renderer);
    1.72 +     SDLTest_AssertPass("SDL_DestroyRenderer()");
    1.73 +  }
    1.74 +  
    1.75 +  if (window != NULL) {  
    1.76 +     SDL_DestroyWindow(window);
    1.77 +     SDLTest_AssertPass("SDL_DestroyWindow");
    1.78 +  }
    1.79 +}
    1.80 +
    1.81 +
    1.82 +/**
    1.83 + * @brief Tests call to SDL_GetNumRenderDrivers
    1.84 + *
    1.85 + * \sa
    1.86 + * http://wiki.libsdl.org/moin.cgi/SDL_GetNumRenderDrivers
    1.87 + */
    1.88 +int
    1.89 +render_testGetNumRenderDrivers(void *arg)
    1.90 +{
    1.91 +  int n;
    1.92 +  n = SDL_GetNumRenderDrivers();
    1.93 +  SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n);
    1.94 +  return TEST_COMPLETED;
    1.95 +}
    1.96 +
    1.97 +
    1.98 +/**
    1.99 + * @brief Tests the SDL primitives for rendering.
   1.100 + *
   1.101 + * \sa
   1.102 + * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
   1.103 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect
   1.104 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderDrawLine
   1.105 + *
   1.106 + */
   1.107 +int render_testPrimitives (void *arg)
   1.108 +{
   1.109 +   int ret;
   1.110 +   int x, y;
   1.111 +   SDL_Rect rect;
   1.112 +   int checkFailCount1;
   1.113 +   int checkFailCount2;
   1.114 +
   1.115 +   /* Need drawcolour or just skip test. */
   1.116 +   SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor");
   1.117 +
   1.118 +   /* Draw a rectangle. */
   1.119 +   rect.x = 40;
   1.120 +   rect.y = 0;
   1.121 +   rect.w = 40;
   1.122 +   rect.h = 80;
   1.123 +
   1.124 +   ret = SDL_SetRenderDrawColor(renderer, 13, 73, 200, SDL_ALPHA_OPAQUE );
   1.125 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.126 +
   1.127 +   ret = SDL_RenderFillRect(renderer, &rect );
   1.128 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
   1.129 +
   1.130 +   /* Draw a rectangle. */
   1.131 +   rect.x = 10;
   1.132 +   rect.y = 10;
   1.133 +   rect.w = 60;
   1.134 +   rect.h = 40;
   1.135 +   ret = SDL_SetRenderDrawColor(renderer, 200, 0, 100, SDL_ALPHA_OPAQUE );
   1.136 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.137 +
   1.138 +   ret = SDL_RenderFillRect(renderer, &rect );
   1.139 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
   1.140 +
   1.141 +   /* Draw some points like so:
   1.142 +    * X.X.X.X..
   1.143 +    * .X.X.X.X.
   1.144 +    * X.X.X.X.. */
   1.145 +   checkFailCount1 = 0;
   1.146 +   checkFailCount2 = 0;
   1.147 +   for (y=0; y<3; y++) {
   1.148 +      for (x = y % 2; x<TESTRENDER_SCREEN_W; x+=2) {
   1.149 +         ret = SDL_SetRenderDrawColor(renderer, x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE );
   1.150 +         if (ret != 0) checkFailCount1++;
   1.151 +
   1.152 +         ret = SDL_RenderDrawPoint(renderer, x, y );
   1.153 +         if (ret != 0) checkFailCount2++;
   1.154 +      }
   1.155 +   }
   1.156 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
   1.157 +   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount2);
   1.158 +
   1.159 +   /* Draw some lines. */
   1.160 +   ret = SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE );
   1.161 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor");
   1.162 +
   1.163 +   ret = SDL_RenderDrawLine(renderer, 0, 30, TESTRENDER_SCREEN_W, 30 );
   1.164 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
   1.165 +
   1.166 +   ret = SDL_SetRenderDrawColor(renderer, 55, 55, 5, SDL_ALPHA_OPAQUE );
   1.167 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.168 +
   1.169 +   ret = SDL_RenderDrawLine(renderer, 40, 30, 40, 60 );
   1.170 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
   1.171 +
   1.172 +   ret = SDL_SetRenderDrawColor(renderer, 5, 105, 105, SDL_ALPHA_OPAQUE );
   1.173 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.174 +
   1.175 +   ret = SDL_RenderDrawLine(renderer, 0, 0, 29, 29 );
   1.176 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
   1.177 +
   1.178 +   ret = SDL_RenderDrawLine(renderer, 29, 30, 0, 59 );
   1.179 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
   1.180 +
   1.181 +   ret = SDL_RenderDrawLine(renderer, 79, 0, 50, 29 );
   1.182 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
   1.183 +
   1.184 +   ret = SDL_RenderDrawLine(renderer, 79, 59, 50, 30 );
   1.185 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
   1.186 +
   1.187 +   /* See if it's the same. */
   1.188 +   _compare( "Primitives output not the same.", SDLTest_ImagePrimitives(), ALLOWABLE_ERROR_OPAQUE );
   1.189 +
   1.190 +   return TEST_COMPLETED;
   1.191 +}
   1.192 +
   1.193 +/**
   1.194 + * @brief Tests the SDL primitives with alpha for rendering.
   1.195 + *
   1.196 + * \sa
   1.197 + * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
   1.198 + * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
   1.199 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect
   1.200 + */
   1.201 +int render_testPrimitivesBlend (void *arg)
   1.202 +{
   1.203 +   int ret;
   1.204 +   int i, j;
   1.205 +   SDL_Rect rect;
   1.206 +   int checkFailCount1;
   1.207 +   int checkFailCount2;
   1.208 +   int checkFailCount3;
   1.209 +
   1.210 +   /* Need drawcolour and blendmode or just skip test. */
   1.211 +   SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor");
   1.212 +   SDLTest_AssertCheck(_hasBlendModes(), "_hasBlendModes");
   1.213 +
   1.214 +   /* Create some rectangles for each blend mode. */
   1.215 +   ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0 );
   1.216 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.217 +
   1.218 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
   1.219 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
   1.220 +
   1.221 +   ret = SDL_RenderFillRect(renderer, NULL );
   1.222 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
   1.223 +
   1.224 +   rect.x = 10;
   1.225 +   rect.y = 25;
   1.226 +   rect.w = 40;
   1.227 +   rect.h = 25;
   1.228 +   ret = SDL_SetRenderDrawColor(renderer, 240, 10, 10, 75 );
   1.229 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.230 +
   1.231 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD );
   1.232 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
   1.233 +
   1.234 +   ret = SDL_RenderFillRect(renderer, &rect );
   1.235 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
   1.236 +
   1.237 +   rect.x = 30;
   1.238 +   rect.y = 40;
   1.239 +   rect.w = 45;
   1.240 +   rect.h = 15;
   1.241 +   ret = SDL_SetRenderDrawColor(renderer, 10, 240, 10, 100 );
   1.242 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.243 +
   1.244 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND );
   1.245 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
   1.246 +
   1.247 +   ret = SDL_RenderFillRect(renderer, &rect );
   1.248 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
   1.249 +
   1.250 +   rect.x = 25;
   1.251 +   rect.y = 25;
   1.252 +   rect.w = 25;
   1.253 +   rect.h = 25;
   1.254 +   ret = SDL_SetRenderDrawColor(renderer, 10, 10, 240, 125 );
   1.255 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.256 +
   1.257 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
   1.258 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
   1.259 +
   1.260 +   ret = SDL_RenderFillRect(renderer, &rect );
   1.261 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
   1.262 +
   1.263 +
   1.264 +   /* Draw blended lines, lines for everyone. */
   1.265 +   checkFailCount1 = 0;
   1.266 +   checkFailCount2 = 0;
   1.267 +   checkFailCount3 = 0;
   1.268 +   for (i=0; i<TESTRENDER_SCREEN_W; i+=2)  {
   1.269 +      ret = SDL_SetRenderDrawColor(renderer, 60+2*i, 240-2*i, 50, 3*i );
   1.270 +      if (ret != 0) checkFailCount1++;
   1.271 +
   1.272 +      ret = SDL_SetRenderDrawBlendMode(renderer,(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
   1.273 +            (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
   1.274 +      if (ret != 0) checkFailCount2++;
   1.275 +
   1.276 +      ret = SDL_RenderDrawLine(renderer, 0, 0, i, 59 );
   1.277 +      if (ret != 0) checkFailCount3++;
   1.278 +   }
   1.279 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
   1.280 +   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
   1.281 +   SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawLine, expected: 0, got: %i", checkFailCount3);
   1.282 +   
   1.283 +   checkFailCount1 = 0;
   1.284 +   checkFailCount2 = 0;
   1.285 +   checkFailCount3 = 0;
   1.286 +   for (i=0; i<TESTRENDER_SCREEN_H; i+=2)  {
   1.287 +      ret = SDL_SetRenderDrawColor(renderer, 60+2*i, 240-2*i, 50, 3*i );
   1.288 +      if (ret != 0) checkFailCount1++;
   1.289 +
   1.290 +      ret = SDL_SetRenderDrawBlendMode(renderer,(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
   1.291 +            (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
   1.292 +      if (ret != 0) checkFailCount2++;
   1.293 +
   1.294 +      ret = SDL_RenderDrawLine(renderer, 0, 0, 79, i );
   1.295 +      if (ret != 0) checkFailCount3++;
   1.296 +   }
   1.297 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
   1.298 +   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
   1.299 +   SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawLine, expected: 0, got: %i", checkFailCount3);
   1.300 +
   1.301 +   /* Draw points. */
   1.302 +   checkFailCount1 = 0;
   1.303 +   checkFailCount2 = 0;
   1.304 +   checkFailCount3 = 0;
   1.305 +   for (j=0; j<TESTRENDER_SCREEN_H; j+=3) {
   1.306 +      for (i=0; i<TESTRENDER_SCREEN_W; i+=3) {
   1.307 +         ret = SDL_SetRenderDrawColor(renderer, j*4, i*3, j*4, i*3 );
   1.308 +         if (ret != 0) checkFailCount1++;
   1.309 +
   1.310 +         ret = SDL_SetRenderDrawBlendMode(renderer, ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
   1.311 +               ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
   1.312 +         if (ret != 0) checkFailCount2++;
   1.313 +
   1.314 +         ret = SDL_RenderDrawPoint(renderer, i, j );
   1.315 +         if (ret != 0) checkFailCount3++;
   1.316 +      }
   1.317 +   }   
   1.318 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
   1.319 +   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
   1.320 +   SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount3);
   1.321 +
   1.322 +   /* See if it's the same. */
   1.323 +   _compare( "Blended primitives output not the same.", SDLTest_ImagePrimitivesBlend(), ALLOWABLE_ERROR_BLENDED );
   1.324 +
   1.325 +    return TEST_COMPLETED;
   1.326 +}
   1.327 +
   1.328 +
   1.329 +
   1.330 +/**
   1.331 + * @brief Tests some blitting routines.
   1.332 + *
   1.333 + * \sa
   1.334 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
   1.335 + * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
   1.336 + */
   1.337 +int
   1.338 +render_testBlit(void *arg)
   1.339 +{
   1.340 +   int ret;
   1.341 +   SDL_Rect rect;
   1.342 +   SDL_Texture *tface;
   1.343 +   Uint32 tformat;
   1.344 +   int taccess, tw, th;
   1.345 +   int i, j, ni, nj;
   1.346 +   int checkFailCount1;
   1.347 +
   1.348 +
   1.349 +   /* Need drawcolour or just skip test. */
   1.350 +   SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor)");
   1.351 +
   1.352 +   /* Create face surface. */
   1.353 +   tface = _loadTestFace();
   1.354 +   SDLTest_AssertCheck(tface != NULL,  "Verify _loadTestFace() result");
   1.355 +   if (tface == NULL) {
   1.356 +       return TEST_ABORTED;
   1.357 +   }
   1.358 +
   1.359 +   /* Constant values. */
   1.360 +   ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
   1.361 +   SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
   1.362 +   rect.w = tw;
   1.363 +   rect.h = th;
   1.364 +   ni     = TESTRENDER_SCREEN_W - tw;
   1.365 +   nj     = TESTRENDER_SCREEN_H - th;
   1.366 +
   1.367 +   /* Loop blit. */
   1.368 +   checkFailCount1 = 0;
   1.369 +   for (j=0; j <= nj; j+=4) {
   1.370 +      for (i=0; i <= ni; i+=4) {
   1.371 +         /* Blitting. */
   1.372 +         rect.x = i;
   1.373 +         rect.y = j;
   1.374 +         ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
   1.375 +         if (ret != 0) checkFailCount1++;
   1.376 +      }
   1.377 +   }
   1.378 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
   1.379 +
   1.380 +   /* Clean up. */
   1.381 +   SDL_DestroyTexture( tface );
   1.382 +
   1.383 +   /* See if it's the same */
   1.384 +   _compare( "Blit output not the same.", SDLTest_ImageBlit(), ALLOWABLE_ERROR_OPAQUE );
   1.385 +
   1.386 +   return TEST_COMPLETED;
   1.387 +}
   1.388 +
   1.389 +
   1.390 +/**
   1.391 + * @brief Blits doing colour tests.
   1.392 + *
   1.393 + * \sa
   1.394 + * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
   1.395 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
   1.396 + * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
   1.397 + */
   1.398 +int
   1.399 +render_testBlitColor (void *arg)
   1.400 +{
   1.401 +   int ret;
   1.402 +   SDL_Rect rect;
   1.403 +   SDL_Texture *tface;
   1.404 +   Uint32 tformat;
   1.405 +   int taccess, tw, th;
   1.406 +   int i, j, ni, nj;
   1.407 +   int checkFailCount1;
   1.408 +   int checkFailCount2;
   1.409 +
   1.410 +   /* Create face surface. */
   1.411 +   tface = _loadTestFace();
   1.412 +   SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
   1.413 +   if (tface == NULL) {
   1.414 +       return TEST_ABORTED;
   1.415 +   }
   1.416 +
   1.417 +   /* Constant values. */
   1.418 +   ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
   1.419 +   SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
   1.420 +   rect.w = tw;
   1.421 +   rect.h = th;
   1.422 +   ni     = TESTRENDER_SCREEN_W - tw;
   1.423 +   nj     = TESTRENDER_SCREEN_H - th;
   1.424 +
   1.425 +   /* Test blitting with colour mod. */
   1.426 +   checkFailCount1 = 0;
   1.427 +   checkFailCount2 = 0;
   1.428 +   for (j=0; j <= nj; j+=4) {
   1.429 +      for (i=0; i <= ni; i+=4) {
   1.430 +         /* Set colour mod. */
   1.431 +         ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
   1.432 +         if (ret != 0) checkFailCount1++;
   1.433 +
   1.434 +         /* Blitting. */
   1.435 +         rect.x = i;
   1.436 +         rect.y = j;
   1.437 +         ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
   1.438 +         if (ret != 0) checkFailCount2++;
   1.439 +      }
   1.440 +   }
   1.441 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
   1.442 +   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
   1.443 +
   1.444 +   /* Clean up. */
   1.445 +   SDL_DestroyTexture( tface );
   1.446 +
   1.447 +   /* See if it's the same. */
   1.448 +   _compare( "Blit output not the same (using SDL_SetTextureColorMod).",
   1.449 +            SDLTest_ImageBlitColor(), ALLOWABLE_ERROR_OPAQUE );
   1.450 +
   1.451 +   return TEST_COMPLETED;
   1.452 +}
   1.453 +
   1.454 +
   1.455 +/**
   1.456 + * @brief Tests blitting with alpha.
   1.457 + *
   1.458 + * \sa
   1.459 + * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
   1.460 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
   1.461 + * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
   1.462 + */
   1.463 +int
   1.464 +render_testBlitAlpha (void *arg)
   1.465 +{
   1.466 +   int ret;
   1.467 +   SDL_Rect rect;
   1.468 +   SDL_Texture *tface;
   1.469 +   Uint32 tformat;
   1.470 +   int taccess, tw, th;
   1.471 +   int i, j, ni, nj;
   1.472 +   int checkFailCount1;
   1.473 +   int checkFailCount2;
   1.474 +
   1.475 +
   1.476 +   /* Need alpha or just skip test. */
   1.477 +   SDLTest_AssertCheck(_hasTexAlpha(), "_hasTexAlpha");
   1.478 +
   1.479 +   /* Create face surface. */
   1.480 +   tface = _loadTestFace();
   1.481 +   SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
   1.482 +   if (tface == NULL) {
   1.483 +       return TEST_ABORTED;
   1.484 +   }
   1.485 +
   1.486 +   /* Constant values. */
   1.487 +   ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
   1.488 +   SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
   1.489 +   rect.w = tw;
   1.490 +   rect.h = th;
   1.491 +   ni     = TESTRENDER_SCREEN_W - tw;
   1.492 +   nj     = TESTRENDER_SCREEN_H - th;
   1.493 +
   1.494 +   /* Test blitting with alpha mod. */
   1.495 +   checkFailCount1 = 0;
   1.496 +   checkFailCount2 = 0;
   1.497 +   for (j=0; j <= nj; j+=4) {
   1.498 +      for (i=0; i <= ni; i+=4) {
   1.499 +         /* Set alpha mod. */
   1.500 +         ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i );
   1.501 +         if (ret != 0) checkFailCount1++;
   1.502 +
   1.503 +         /* Blitting. */
   1.504 +         rect.x = i;
   1.505 +         rect.y = j;
   1.506 +         ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
   1.507 +         if (ret != 0) checkFailCount2++;
   1.508 +      }
   1.509 +   }   
   1.510 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
   1.511 +   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
   1.512 +
   1.513 +   /* Clean up. */
   1.514 +   SDL_DestroyTexture( tface );
   1.515 +
   1.516 +   /* See if it's the same. */
   1.517 +   _compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).",
   1.518 +            SDLTest_ImageBlitAlpha(), ALLOWABLE_ERROR_BLENDED );
   1.519 +
   1.520 +   return TEST_COMPLETED;
   1.521 +}
   1.522 +
   1.523 +/* Helper functions */
   1.524 +
   1.525 +/**
   1.526 + * @brief Tests a blend mode.
   1.527 + *
   1.528 + * \sa
   1.529 + * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureBlendMode
   1.530 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
   1.531 + */
   1.532 +static void
   1.533 +_testBlitBlendMode( SDL_Texture * tface, int mode )
   1.534 +{
   1.535 +   int ret;
   1.536 +   Uint32 tformat;
   1.537 +   int taccess, tw, th;
   1.538 +   int i, j, ni, nj;
   1.539 +   SDL_Rect rect;
   1.540 +   int checkFailCount1;
   1.541 +   int checkFailCount2;
   1.542 +
   1.543 +   /* Clear surface. */
   1.544 +   _clearScreen();
   1.545 +
   1.546 +   /* Constant values. */
   1.547 +   ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
   1.548 +   SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
   1.549 +   rect.w = tw;
   1.550 +   rect.h = th;
   1.551 +   ni     = TESTRENDER_SCREEN_W - tw;
   1.552 +   nj     = TESTRENDER_SCREEN_H - th;
   1.553 +
   1.554 +   /* Test blend mode. */
   1.555 +   checkFailCount1 = 0;
   1.556 +   checkFailCount2 = 0;
   1.557 +   for (j=0; j <= nj; j+=4) {
   1.558 +      for (i=0; i <= ni; i+=4) {
   1.559 +         /* Set blend mode. */
   1.560 +         ret = SDL_SetTextureBlendMode( tface, (SDL_BlendMode)mode );
   1.561 +         if (ret != 0) checkFailCount1++;
   1.562 +
   1.563 +         /* Blitting. */
   1.564 +         rect.x = i;
   1.565 +         rect.y = j;
   1.566 +         ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
   1.567 +         if (ret != 0) checkFailCount2++;
   1.568 +      }
   1.569 +   }
   1.570 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureBlendMode, expected: 0, got: %i", checkFailCount1);
   1.571 +   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
   1.572 +}
   1.573 +
   1.574 +
   1.575 +/**
   1.576 + * @brief Tests some more blitting routines.
   1.577 + *
   1.578 + * \sa
   1.579 + * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
   1.580 + * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
   1.581 + * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureBlendMode
   1.582 + * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
   1.583 + */
   1.584 +int
   1.585 +render_testBlitBlend (void *arg)
   1.586 +{
   1.587 +   int ret;
   1.588 +   SDL_Rect rect;
   1.589 +   SDL_Texture *tface;
   1.590 +   Uint32 tformat;
   1.591 +   int taccess, tw, th;
   1.592 +   int i, j, ni, nj;
   1.593 +   int mode;
   1.594 +   int checkFailCount1;
   1.595 +   int checkFailCount2;
   1.596 +   int checkFailCount3;
   1.597 +   int checkFailCount4;
   1.598 +
   1.599 +   SDLTest_AssertCheck(_hasBlendModes(), "_hasBlendModes");
   1.600 +   SDLTest_AssertCheck(_hasTexColor(), "_hasTexColor");
   1.601 +   SDLTest_AssertCheck(_hasTexAlpha(), "_hasTexAlpha");
   1.602 +
   1.603 +   /* Create face surface. */
   1.604 +   tface = _loadTestFace();
   1.605 +   SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
   1.606 +   if (tface == NULL) {
   1.607 +       return TEST_ABORTED;
   1.608 +   }
   1.609 +
   1.610 +   /* Constant values. */
   1.611 +   ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
   1.612 +   SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
   1.613 +   rect.w = tw;
   1.614 +   rect.h = th;
   1.615 +   ni = TESTRENDER_SCREEN_W - tw;
   1.616 +   nj = TESTRENDER_SCREEN_H - th;
   1.617 +
   1.618 +   /* Set alpha mod. */
   1.619 +   ret = SDL_SetTextureAlphaMod( tface, 100 );
   1.620 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetTextureAlphaMod, expected: 0, got: %i", ret);
   1.621 +
   1.622 +   /* Test None. */
   1.623 +   _testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
   1.624 +   /* See if it's the same. */
   1.625 +   _compare( "Blit blending output not the same (using SDL_BLENDMODE_NONE).",
   1.626 +            SDLTest_ImageBlitBlendNone(), ALLOWABLE_ERROR_OPAQUE ); 
   1.627 +
   1.628 +
   1.629 +   /* Test Blend. */
   1.630 +   _testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
   1.631 +   _compare( "Blit blending output not the same (using SDL_BLENDMODE_BLEND).",
   1.632 +            SDLTest_ImageBlitBlend(), ALLOWABLE_ERROR_BLENDED );
   1.633 +
   1.634 +
   1.635 +   /* Test Add. */
   1.636 +   _testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
   1.637 +   _compare( "Blit blending output not the same (using SDL_BLENDMODE_ADD).",
   1.638 +            SDLTest_ImageBlitBlendAdd(), ALLOWABLE_ERROR_BLENDED );
   1.639 +
   1.640 +   /* Test Mod. */
   1.641 +   _testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
   1.642 +   _compare( "Blit blending output not the same (using SDL_BLENDMODE_MOD).",
   1.643 +            SDLTest_ImageBlitBlendMod(), ALLOWABLE_ERROR_BLENDED );
   1.644 +
   1.645 +   /* Clear surface. */
   1.646 +   _clearScreen();
   1.647 +
   1.648 +   /* Loop blit. */
   1.649 +   checkFailCount1 = 0;
   1.650 +   checkFailCount2 = 0;
   1.651 +   checkFailCount3 = 0;
   1.652 +   checkFailCount4 = 0;
   1.653 +   for (j=0; j <= nj; j+=4) {
   1.654 +      for (i=0; i <= ni; i+=4) {
   1.655 +
   1.656 +         /* Set colour mod. */
   1.657 +         ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
   1.658 +         if (ret != 0) checkFailCount1++;
   1.659 +
   1.660 +         /* Set alpha mod. */
   1.661 +         ret = SDL_SetTextureAlphaMod( tface, (100/ni)*i );
   1.662 +         if (ret != 0) checkFailCount2++;
   1.663 +
   1.664 +         /* Crazy blending mode magic. */
   1.665 +         mode = (i/4*j/4) % 4;
   1.666 +         if (mode==0) mode = SDL_BLENDMODE_NONE;
   1.667 +         else if (mode==1) mode = SDL_BLENDMODE_BLEND;
   1.668 +         else if (mode==2) mode = SDL_BLENDMODE_ADD;
   1.669 +         else if (mode==3) mode = SDL_BLENDMODE_MOD;
   1.670 +         ret = SDL_SetTextureBlendMode( tface, (SDL_BlendMode)mode );
   1.671 +         if (ret != 0) checkFailCount3++;
   1.672 +
   1.673 +         /* Blitting. */
   1.674 +         rect.x = i;
   1.675 +         rect.y = j;
   1.676 +         ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
   1.677 +         if (ret != 0) checkFailCount4++;
   1.678 +      }
   1.679 +   }
   1.680 +   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
   1.681 +   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount2);
   1.682 +   SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetTextureBlendMode, expected: 0, got: %i", checkFailCount3);
   1.683 +   SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount4);
   1.684 +
   1.685 +   /* Clean up. */
   1.686 +   SDL_DestroyTexture( tface );
   1.687 +
   1.688 +   /* Check to see if matches. */
   1.689 +   _compare( "Blit blending output not the same (using SDL_BLENDMODE_*).",
   1.690 +            SDLTest_ImageBlitBlendAll(), ALLOWABLE_ERROR_BLENDED);
   1.691 +
   1.692 +   return TEST_COMPLETED;
   1.693 +}
   1.694 +
   1.695 +
   1.696 +
   1.697 +/**
   1.698 + * @brief Checks to see if functionality is supported. Helper function.
   1.699 + */
   1.700 +static int
   1.701 +_isSupported( int code )
   1.702 +{
   1.703 +   return (code == 0);
   1.704 +}
   1.705 +
   1.706 +/**
   1.707 + * @brief Test to see if we can vary the draw colour. Helper function.
   1.708 + *
   1.709 + * \sa
   1.710 + * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
   1.711 + * http://wiki.libsdl.org/moin.cgi/SDL_GetRenderDrawColor
   1.712 + */
   1.713 +static int
   1.714 +_hasDrawColor (void)
   1.715 +{
   1.716 +   int ret, fail;
   1.717 +   Uint8 r, g, b, a;
   1.718 +
   1.719 +   fail = 0;
   1.720 +
   1.721 +   /* Set colour. */
   1.722 +   ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100 );
   1.723 +   if (!_isSupported(ret))
   1.724 +      fail = 1;
   1.725 +   ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a );
   1.726 +   if (!_isSupported(ret))
   1.727 +      fail = 1;
   1.728 +   /* Restore natural. */
   1.729 +   ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE );
   1.730 +   if (!_isSupported(ret))
   1.731 +      fail = 1;
   1.732 +
   1.733 +   /* Something failed, consider not available. */
   1.734 +   if (fail)
   1.735 +      return 0;
   1.736 +   /* Not set properly, consider failed. */
   1.737 +   else if ((r != 100) || (g != 100) || (b != 100) || (a != 100))
   1.738 +      return 0;
   1.739 +   return 1;
   1.740 +}
   1.741 +
   1.742 +/**
   1.743 + * @brief Test to see if we can vary the blend mode. Helper function.
   1.744 + *
   1.745 + * \sa
   1.746 + * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
   1.747 + * http://wiki.libsdl.org/moin.cgi/SDL_GetRenderDrawBlendMode
   1.748 + */
   1.749 +static int
   1.750 +_hasBlendModes (void)
   1.751 +{
   1.752 +   int fail;
   1.753 +   int ret;
   1.754 +   SDL_BlendMode mode;
   1.755 +
   1.756 +   fail = 0;
   1.757 +
   1.758 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND );
   1.759 +   if (!_isSupported(ret))
   1.760 +      fail = 1;
   1.761 +   ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
   1.762 +   if (!_isSupported(ret))
   1.763 +      fail = 1;
   1.764 +   ret = (mode != SDL_BLENDMODE_BLEND);
   1.765 +   if (!_isSupported(ret))
   1.766 +      fail = 1;
   1.767 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD );
   1.768 +   if (!_isSupported(ret))
   1.769 +      fail = 1;
   1.770 +   ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
   1.771 +   if (!_isSupported(ret))
   1.772 +      fail = 1;
   1.773 +   ret = (mode != SDL_BLENDMODE_ADD);
   1.774 +   if (!_isSupported(ret))
   1.775 +      fail = 1;
   1.776 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_MOD );
   1.777 +   if (!_isSupported(ret))
   1.778 +      fail = 1;
   1.779 +   ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
   1.780 +   if (!_isSupported(ret))
   1.781 +      fail = 1;
   1.782 +   ret = (mode != SDL_BLENDMODE_MOD);
   1.783 +   if (!_isSupported(ret))
   1.784 +      fail = 1;
   1.785 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
   1.786 +   if (!_isSupported(ret))
   1.787 +      fail = 1;
   1.788 +   ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
   1.789 +   if (!_isSupported(ret))
   1.790 +      fail = 1;
   1.791 +   ret = (mode != SDL_BLENDMODE_NONE);
   1.792 +   if (!_isSupported(ret))
   1.793 +      fail = 1;
   1.794 +
   1.795 +   return !fail;
   1.796 +}
   1.797 +
   1.798 +
   1.799 +/**
   1.800 + * @brief Loads the test image 'Face' as texture. Helper function.
   1.801 + *
   1.802 + * \sa
   1.803 + * http://wiki.libsdl.org/moin.cgi/SDL_CreateTextureFromSurface
   1.804 + */
   1.805 +static SDL_Texture *
   1.806 +_loadTestFace(void)
   1.807 +{
   1.808 +   SDL_Surface *face;
   1.809 +   SDL_Texture *tface;
   1.810 +
   1.811 +   face = SDLTest_ImageFace();
   1.812 +   if (face == NULL) {
   1.813 +      return NULL;
   1.814 +   }
   1.815 +   
   1.816 +   tface = SDL_CreateTextureFromSurface(renderer, face);
   1.817 +   if (tface == NULL) {
   1.818 +       SDLTest_LogError("SDL_CreateTextureFromSurface() failed with error: %s", SDL_GetError());
   1.819 +   }
   1.820 +
   1.821 +   SDL_FreeSurface(face);
   1.822 +
   1.823 +   return tface;
   1.824 +}
   1.825 +
   1.826 +
   1.827 +/**
   1.828 + * @brief Test to see if can set texture colour mode. Helper function.
   1.829 + *
   1.830 + * \sa
   1.831 + * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
   1.832 + * http://wiki.libsdl.org/moin.cgi/SDL_GetTextureColorMod
   1.833 + * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
   1.834 + */
   1.835 +static int
   1.836 +_hasTexColor (void)
   1.837 +{
   1.838 +   int fail;
   1.839 +   int ret;
   1.840 +   SDL_Texture *tface;
   1.841 +   Uint8 r, g, b;
   1.842 +
   1.843 +   /* Get test face. */
   1.844 +   tface = _loadTestFace();
   1.845 +   if (tface == 0)
   1.846 +      return 0;
   1.847 +
   1.848 +   /* See if supported. */
   1.849 +   fail = 0;
   1.850 +   ret = SDL_SetTextureColorMod( tface, 100, 100, 100 );
   1.851 +   if (!_isSupported(ret))
   1.852 +      fail = 1;
   1.853 +   ret = SDL_GetTextureColorMod( tface, &r, &g, &b );
   1.854 +   if (!_isSupported(ret))
   1.855 +      fail = 1;
   1.856 +
   1.857 +   /* Clean up. */
   1.858 +   SDL_DestroyTexture( tface );
   1.859 +
   1.860 +   if (fail)
   1.861 +      return 0;
   1.862 +   else if ((r != 100) || (g != 100) || (b != 100))
   1.863 +      return 0;
   1.864 +   return 1;
   1.865 +}
   1.866 +
   1.867 +/**
   1.868 + * @brief Test to see if we can vary the alpha of the texture. Helper function.
   1.869 + *
   1.870 + * \sa
   1.871 + *  http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
   1.872 + *  http://wiki.libsdl.org/moin.cgi/SDL_GetTextureAlphaMod
   1.873 + *  http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
   1.874 + */
   1.875 +static int
   1.876 +_hasTexAlpha(void)
   1.877 +{
   1.878 +   int fail;
   1.879 +   int ret;
   1.880 +   SDL_Texture *tface;
   1.881 +   Uint8 a;
   1.882 +
   1.883 +   /* Get test face. */
   1.884 +   tface = _loadTestFace();
   1.885 +   if (tface == 0)
   1.886 +      return 0;
   1.887 +
   1.888 +   /* See if supported. */
   1.889 +   fail = 0;
   1.890 +   ret = SDL_SetTextureAlphaMod( tface, 100 );
   1.891 +   if (!_isSupported(ret))
   1.892 +      fail = 1;
   1.893 +   ret = SDL_GetTextureAlphaMod( tface, &a );
   1.894 +   if (!_isSupported(ret))
   1.895 +      fail = 1;
   1.896 +
   1.897 +   /* Clean up. */
   1.898 +   SDL_DestroyTexture( tface );
   1.899 +
   1.900 +   if (fail)
   1.901 +      return 0;
   1.902 +   else if (a != 100)
   1.903 +      return 0;
   1.904 +   return 1;
   1.905 +}
   1.906 +
   1.907 +static _renderCompareCount = 0;
   1.908 +
   1.909 +/**
   1.910 + * @brief Compares screen pixels with image pixels. Helper function.
   1.911 + *
   1.912 + * @param msg Message on failure.
   1.913 + * @param s Image to compare against.
   1.914 + * @return 0 on success.
   1.915 + *
   1.916 + * \sa
   1.917 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderReadPixels
   1.918 + * http://wiki.libsdl.org/moin.cgi/SDL_CreateRGBSurfaceFrom
   1.919 + * http://wiki.libsdl.org/moin.cgi/SDL_FreeSurface
   1.920 + */
   1.921 +static void
   1.922 +_compare(const char *msg, SDL_Surface *s, int allowable_error)
   1.923 +{
   1.924 +   int ret;
   1.925 +   SDL_Rect rect;
   1.926 +   Uint8 pix[4*80*60];
   1.927 +   SDL_Surface *testsur;
   1.928 +   char imageFilename[128];
   1.929 +   char referenceFilename[128];
   1.930 +
   1.931 +   /* Read pixels. */
   1.932 +   /* Explicitly specify the rect in case the window isn't expected size... */
   1.933 +   rect.x = 0;
   1.934 +   rect.y = 0;
   1.935 +   rect.w = 80;
   1.936 +   rect.h = 60;
   1.937 +   ret = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pix, 80*4 );
   1.938 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", ret);
   1.939 +
   1.940 +   /* Create surface. */
   1.941 +   testsur = SDL_CreateRGBSurfaceFrom( pix, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4,
   1.942 +                                       RENDER_COMPARE_RMASK, RENDER_COMPARE_GMASK, RENDER_COMPARE_BMASK, RENDER_COMPARE_AMASK);
   1.943 +   SDLTest_AssertCheck(testsur != NULL, "Verify result from SDL_CreateRGBSurfaceFrom");
   1.944 +
   1.945 +   /* Compare surface. */
   1.946 +   ret = SDLTest_CompareSurfaces( testsur, s, allowable_error );
   1.947 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.948 +
   1.949 +   _renderCompareCount++;
   1.950 +   if (ret != 0) {
   1.951 +      SDL_snprintf(imageFilename, 127, "image%i.bmp", _renderCompareCount);
   1.952 +      SDL_SaveBMP(testsur, imageFilename);
   1.953 +      SDL_snprintf(referenceFilename, 127, "reference%i.bmp", _renderCompareCount);
   1.954 +      SDL_SaveBMP(s, referenceFilename);
   1.955 +      SDLTest_LogError("Surfaces from failed comparison saved as %s and %s", imageFilename, referenceFilename);
   1.956 +   }
   1.957 +
   1.958 +   /* Clean up. */
   1.959 +   SDL_FreeSurface( testsur );
   1.960 +}
   1.961 +
   1.962 +/**
   1.963 + * @brief Clears the screen. Helper function.
   1.964 + *
   1.965 + * \sa
   1.966 + * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
   1.967 + * http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect
   1.968 + * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
   1.969 + */
   1.970 +static int
   1.971 +_clearScreen(void)
   1.972 +{
   1.973 +   int ret;
   1.974 +
   1.975 +   /* Set colour. */
   1.976 +   ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE );
   1.977 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.978 +
   1.979 +   /* Clear screen. */
   1.980 +   ret = SDL_RenderFillRect(renderer, NULL );
   1.981 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
   1.982 +
   1.983 +   /* Set defaults. */
   1.984 +   ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
   1.985 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
   1.986 +
   1.987 +   ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE );
   1.988 +   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
   1.989 +
   1.990 +   return 0;
   1.991 +}
   1.992 +
   1.993 +/* ================= Test References ================== */
   1.994 +
   1.995 +/* Render test cases */
   1.996 +static const SDLTest_TestCaseReference renderTest1 =
   1.997 +		{ (SDLTest_TestCaseFp)render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED };
   1.998 +
   1.999 +static const SDLTest_TestCaseReference renderTest2 =
  1.1000 +		{ (SDLTest_TestCaseFp)render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED };
  1.1001 +
  1.1002 +static const SDLTest_TestCaseReference renderTest3 =
  1.1003 +		{ (SDLTest_TestCaseFp)render_testPrimitivesBlend, "render_testPrimitivesBlend", "Tests rendering primitives with blending", TEST_ENABLED };
  1.1004 +
  1.1005 +static const SDLTest_TestCaseReference renderTest4 =
  1.1006 +		{ (SDLTest_TestCaseFp)render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED };
  1.1007 +
  1.1008 +static const SDLTest_TestCaseReference renderTest5 =
  1.1009 +		{ (SDLTest_TestCaseFp)render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED };
  1.1010 +
  1.1011 +static const SDLTest_TestCaseReference renderTest6 =
  1.1012 +		{ (SDLTest_TestCaseFp)render_testBlitAlpha, "render_testBlitAlpha", "Tests blitting with alpha", TEST_ENABLED };
  1.1013 +
  1.1014 +static const SDLTest_TestCaseReference renderTest7 =
  1.1015 +		{  (SDLTest_TestCaseFp)render_testBlitBlend, "render_testBlitBlend", "Tests blitting with blending", TEST_ENABLED };
  1.1016 +
  1.1017 +/* Sequence of Render test cases */
  1.1018 +static const SDLTest_TestCaseReference *renderTests[] =  {
  1.1019 +	&renderTest1, &renderTest2, &renderTest3, &renderTest4, &renderTest5, &renderTest6, &renderTest7, NULL
  1.1020 +};
  1.1021 +
  1.1022 +/* Render test suite (global) */
  1.1023 +SDLTest_TestSuiteReference renderTestSuite = {
  1.1024 +	"Render",
  1.1025 +	InitCreateRenderer,
  1.1026 +	renderTests,
  1.1027 +	CleanupDestroyRenderer
  1.1028 +};