testautomation_render.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197
  1. /**
  2. * Original code: automated SDL platform test written by Edgar Simo "bobbens"
  3. * Extended and extensively updated by aschiffler at ferzkopp dot net
  4. */
  5. #include <SDL3/SDL.h>
  6. #include <SDL3/SDL_test.h>
  7. #include "testautomation_images.h"
  8. #include "testautomation_suites.h"
  9. /* ================= Test Case Implementation ================== */
  10. #define TESTRENDER_SCREEN_W 80
  11. #define TESTRENDER_SCREEN_H 60
  12. #define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888
  13. #define RENDER_COLOR_CLEAR 0xFF000000
  14. #define RENDER_COLOR_GREEN 0xFF00FF00
  15. #define ALLOWABLE_ERROR_OPAQUE 0
  16. #define ALLOWABLE_ERROR_BLENDED 0
  17. #define CHECK_FUNC(FUNC, PARAMS) \
  18. { \
  19. bool result = FUNC PARAMS; \
  20. if (!result) { \
  21. SDLTest_AssertCheck(result, "Validate result from %s, expected: true, got: false, %s", #FUNC, SDL_GetError()); \
  22. } \
  23. }
  24. /* Test window and renderer */
  25. static SDL_Window *window = NULL;
  26. static SDL_Renderer *renderer = NULL;
  27. /* Prototypes for helper functions */
  28. static int clearScreen(void);
  29. static void compare(SDL_Surface *reference, int allowable_error);
  30. static void compare2x(SDL_Surface *reference, int allowable_error);
  31. static SDL_Texture *loadTestFace(void);
  32. static bool isSupported(int code);
  33. static bool hasDrawColor(void);
  34. /**
  35. * Create software renderer for tests
  36. */
  37. static void SDLCALL InitCreateRenderer(void **arg)
  38. {
  39. int width = 320, height = 240;
  40. const char *renderer_name = NULL;
  41. renderer = NULL;
  42. window = SDL_CreateWindow("render_testCreateRenderer", width, height, 0);
  43. SDLTest_AssertPass("SDL_CreateWindow()");
  44. SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
  45. if (window == NULL) {
  46. return;
  47. }
  48. renderer = SDL_CreateRenderer(window, renderer_name);
  49. SDLTest_AssertPass("SDL_CreateRenderer()");
  50. SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result: %s", renderer != NULL ? "success" : SDL_GetError());
  51. if (renderer == NULL) {
  52. SDL_DestroyWindow(window);
  53. return;
  54. }
  55. }
  56. /**
  57. * Destroy renderer for tests
  58. */
  59. static void SDLCALL CleanupDestroyRenderer(void *arg)
  60. {
  61. if (renderer) {
  62. SDL_DestroyRenderer(renderer);
  63. renderer = NULL;
  64. SDLTest_AssertPass("SDL_DestroyRenderer()");
  65. }
  66. if (window) {
  67. SDL_DestroyWindow(window);
  68. window = NULL;
  69. SDLTest_AssertPass("SDL_DestroyWindow");
  70. }
  71. }
  72. /**
  73. * Tests call to SDL_GetNumRenderDrivers
  74. *
  75. * \sa SDL_GetNumRenderDrivers
  76. */
  77. static int SDLCALL render_testGetNumRenderDrivers(void *arg)
  78. {
  79. int n;
  80. n = SDL_GetNumRenderDrivers();
  81. SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n);
  82. return TEST_COMPLETED;
  83. }
  84. /**
  85. * Tests the SDL primitives for rendering.
  86. *
  87. * \sa SDL_SetRenderDrawColor
  88. * \sa SDL_RenderFillRect
  89. * \sa SDL_RenderLine
  90. *
  91. */
  92. static int SDLCALL render_testPrimitives(void *arg)
  93. {
  94. int ret;
  95. int x, y;
  96. SDL_FRect rect;
  97. SDL_Surface *referenceSurface = NULL;
  98. int checkFailCount1;
  99. int checkFailCount2;
  100. /* Clear surface. */
  101. clearScreen();
  102. /* Need drawcolor or just skip test. */
  103. SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor");
  104. /* Draw a rectangle. */
  105. rect.x = 40.0f;
  106. rect.y = 0.0f;
  107. rect.w = 40.0f;
  108. rect.h = 80.0f;
  109. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 13, 73, 200, SDL_ALPHA_OPAQUE))
  110. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  111. /* Draw a rectangle with negative width and height. */
  112. rect.x = 10.0f + 60.0f;
  113. rect.y = 10.0f + 40.0f;
  114. rect.w = -60.0f;
  115. rect.h = -40.0f;
  116. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 200, 0, 100, SDL_ALPHA_OPAQUE))
  117. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  118. /* Draw a rectangle with zero width and height. */
  119. rect.x = 10.0f;
  120. rect.y = 10.0f;
  121. rect.w = 0.0f;
  122. rect.h = 0.0f;
  123. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 0, 0, SDL_ALPHA_OPAQUE))
  124. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  125. /* Draw some points like so:
  126. * X.X.X.X..
  127. * .X.X.X.X.
  128. * X.X.X.X.. */
  129. checkFailCount1 = 0;
  130. checkFailCount2 = 0;
  131. for (y = 0; y < 3; y++) {
  132. for (x = y % 2; x < TESTRENDER_SCREEN_W; x += 2) {
  133. ret = SDL_SetRenderDrawColor(renderer, (Uint8)(x * y), (Uint8)(x * y / 2), (Uint8)(x * y / 3), SDL_ALPHA_OPAQUE);
  134. if (!ret) {
  135. checkFailCount1++;
  136. }
  137. ret = SDL_RenderPoint(renderer, (float)x, (float)y);
  138. if (!ret) {
  139. checkFailCount2++;
  140. }
  141. }
  142. }
  143. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
  144. SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", checkFailCount2);
  145. /* Draw some lines. */
  146. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  147. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 30.0f, TESTRENDER_SCREEN_W, 30.0f))
  148. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 55, 55, 5, SDL_ALPHA_OPAQUE))
  149. CHECK_FUNC(SDL_RenderLine, (renderer, 40.0f, 30.0f, 40.0f, 60.0f))
  150. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 5, 105, 105, SDL_ALPHA_OPAQUE))
  151. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 29.0f, 29.0f))
  152. CHECK_FUNC(SDL_RenderLine, (renderer, 29.0f, 30.0f, 0.0f, 59.0f))
  153. CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 0.0f, 50.0f, 29.0f))
  154. CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 59.0f, 50.0f, 30.0f))
  155. /* See if it's the same. */
  156. referenceSurface = SDLTest_ImagePrimitives();
  157. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  158. /* Make current */
  159. SDL_RenderPresent(renderer);
  160. /* Clean up. */
  161. SDL_DestroySurface(referenceSurface);
  162. referenceSurface = NULL;
  163. return TEST_COMPLETED;
  164. }
  165. /**
  166. * Tests the SDL primitives for rendering within a viewport.
  167. *
  168. * \sa SDL_SetRenderDrawColor
  169. * \sa SDL_RenderFillRect
  170. * \sa SDL_RenderLine
  171. *
  172. */
  173. static int SDLCALL render_testPrimitivesWithViewport(void *arg)
  174. {
  175. SDL_Rect viewport;
  176. SDL_Surface *surface;
  177. /* Clear surface. */
  178. clearScreen();
  179. viewport.x = 2;
  180. viewport.y = 2;
  181. viewport.w = 2;
  182. viewport.h = 2;
  183. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport));
  184. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 255, 255, SDL_ALPHA_OPAQUE))
  185. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 1.0f, 1.0f));
  186. viewport.x = 3;
  187. viewport.y = 3;
  188. viewport.w = 1;
  189. viewport.h = 1;
  190. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport));
  191. surface = SDL_RenderReadPixels(renderer, NULL);
  192. if (surface) {
  193. Uint8 r, g, b, a;
  194. CHECK_FUNC(SDL_ReadSurfacePixel, (surface, 0, 0, &r, &g, &b, &a));
  195. SDLTest_AssertCheck(r == 0xFF && g == 0xFF && b == 0xFF && a == 0xFF, "Validate diagonal line drawing with viewport, expected 0xFFFFFFFF, got 0x%.2x%.2x%.2x%.2x", r, g, b, a);
  196. SDL_DestroySurface(surface);
  197. } else {
  198. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  199. }
  200. return TEST_COMPLETED;
  201. }
  202. /**
  203. * Tests some blitting routines.
  204. *
  205. * \sa SDL_RenderTexture
  206. * \sa SDL_DestroyTexture
  207. */
  208. static int SDLCALL render_testBlit(void *arg)
  209. {
  210. int ret;
  211. SDL_FRect rect;
  212. SDL_Texture *tface;
  213. SDL_Surface *referenceSurface = NULL;
  214. int i, j, ni, nj;
  215. int checkFailCount1;
  216. /* Clear surface. */
  217. clearScreen();
  218. /* Need drawcolor or just skip test. */
  219. SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor)");
  220. /* Create face surface. */
  221. tface = loadTestFace();
  222. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  223. if (tface == NULL) {
  224. return TEST_ABORTED;
  225. }
  226. /* Constant values. */
  227. rect.w = (float)tface->w;
  228. rect.h = (float)tface->h;
  229. ni = TESTRENDER_SCREEN_W - tface->w;
  230. nj = TESTRENDER_SCREEN_H - tface->h;
  231. /* Loop blit. */
  232. checkFailCount1 = 0;
  233. for (j = 0; j <= nj; j += 4) {
  234. for (i = 0; i <= ni; i += 4) {
  235. /* Blitting. */
  236. rect.x = (float)i;
  237. rect.y = (float)j;
  238. ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
  239. if (!ret) {
  240. checkFailCount1++;
  241. }
  242. }
  243. }
  244. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount1);
  245. /* See if it's the same */
  246. referenceSurface = SDLTest_ImageBlit();
  247. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  248. /* Make current */
  249. SDL_RenderPresent(renderer);
  250. /* Clean up. */
  251. SDL_DestroyTexture(tface);
  252. SDL_DestroySurface(referenceSurface);
  253. referenceSurface = NULL;
  254. return TEST_COMPLETED;
  255. }
  256. /**
  257. * Tests tiled blitting routines.
  258. */
  259. static int SDLCALL render_testBlitTiled(void *arg)
  260. {
  261. int ret;
  262. SDL_FRect rect;
  263. SDL_Texture *tface;
  264. SDL_Surface *referenceSurface = NULL;
  265. SDL_Surface *referenceSurface2x = NULL;
  266. /* Create face surface. */
  267. tface = loadTestFace();
  268. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  269. if (tface == NULL) {
  270. return TEST_ABORTED;
  271. }
  272. SDL_SetTextureScaleMode(tface, SDL_SCALEMODE_NEAREST); /* So 2x scaling is pixel perfect */
  273. /* Tiled blit - 1.0 scale */
  274. {
  275. /* Clear surface. */
  276. clearScreen();
  277. /* Tiled blit. */
  278. rect.x = 0.0f;
  279. rect.y = 0.0f;
  280. rect.w = (float)TESTRENDER_SCREEN_W;
  281. rect.h = (float)TESTRENDER_SCREEN_H;
  282. ret = SDL_RenderTextureTiled(renderer, tface, NULL, 1.0f, &rect);
  283. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTextureTiled, expected: true, got: %i", ret);
  284. /* See if it's the same */
  285. referenceSurface = SDLTest_ImageBlitTiled();
  286. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  287. /* Make current */
  288. SDL_RenderPresent(renderer);
  289. }
  290. /* Tiled blit - 2.0 scale */
  291. {
  292. /* Clear surface. */
  293. clearScreen();
  294. /* Tiled blit. */
  295. rect.x = 0.0f;
  296. rect.y = 0.0f;
  297. rect.w = (float)TESTRENDER_SCREEN_W * 2;
  298. rect.h = (float)TESTRENDER_SCREEN_H * 2;
  299. ret = SDL_RenderTextureTiled(renderer, tface, NULL, 2.0f, &rect);
  300. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTextureTiled, expected: true, got: %i", ret);
  301. /* See if it's the same */
  302. referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format);
  303. SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST);
  304. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret);
  305. compare2x(referenceSurface2x, ALLOWABLE_ERROR_OPAQUE);
  306. /* Make current */
  307. SDL_RenderPresent(renderer);
  308. }
  309. /* Clean up. */
  310. SDL_DestroyTexture(tface);
  311. SDL_DestroySurface(referenceSurface);
  312. SDL_DestroySurface(referenceSurface2x);
  313. referenceSurface = NULL;
  314. return TEST_COMPLETED;
  315. }
  316. static const Uint8 COLOR_SEPARATION = 85;
  317. static void Fill9GridReferenceSurface(SDL_Surface *surface, int left_width, int right_width, int top_height, int bottom_height)
  318. {
  319. SDL_Rect rect;
  320. // Upper left
  321. rect.x = 0;
  322. rect.y = 0;
  323. rect.w = left_width;
  324. rect.h = top_height;
  325. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  326. // Top
  327. rect.x = left_width;
  328. rect.y = 0;
  329. rect.w = surface->w - left_width - right_width;
  330. rect.h = top_height;
  331. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  332. // Upper right
  333. rect.x = surface->w - right_width;
  334. rect.y = 0;
  335. rect.w = right_width;
  336. rect.h = top_height;
  337. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  338. // Left
  339. rect.x = 0;
  340. rect.y = top_height;
  341. rect.w = left_width;
  342. rect.h = surface->h - top_height - bottom_height;
  343. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  344. // Center
  345. rect.x = left_width;
  346. rect.y = top_height;
  347. rect.w = surface->w - right_width - left_width;
  348. rect.h = surface->h - top_height - bottom_height;
  349. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  350. // Right
  351. rect.x = surface->w - right_width;
  352. rect.y = top_height;
  353. rect.w = right_width;
  354. rect.h = surface->h - top_height - bottom_height;
  355. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  356. // Lower left
  357. rect.x = 0;
  358. rect.y = surface->h - bottom_height;
  359. rect.w = left_width;
  360. rect.h = bottom_height;
  361. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  362. // Bottom
  363. rect.x = left_width;
  364. rect.y = surface->h - bottom_height;
  365. rect.w = surface->w - left_width - right_width;
  366. rect.h = bottom_height;
  367. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  368. // Lower right
  369. rect.x = surface->w - right_width;
  370. rect.y = surface->h - bottom_height;
  371. rect.w = right_width;
  372. rect.h = bottom_height;
  373. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  374. }
  375. /**
  376. * Tests 9-grid blitting.
  377. */
  378. static int SDLCALL render_testBlit9Grid(void *arg)
  379. {
  380. SDL_Surface *referenceSurface = NULL;
  381. SDL_Surface *source = NULL;
  382. SDL_Texture *texture;
  383. int x, y;
  384. SDL_FRect rect;
  385. int ret = 0;
  386. /* Create source surface */
  387. source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
  388. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  389. for (y = 0; y < 3; ++y) {
  390. for (x = 0; x < 3; ++x) {
  391. SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
  392. }
  393. }
  394. texture = SDL_CreateTextureFromSurface(renderer, source);
  395. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  396. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  397. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret);
  398. /* 9-grid blit - 1.0 scale */
  399. {
  400. SDLTest_Log("9-grid blit - 1.0 scale");
  401. /* Create reference surface */
  402. SDL_DestroySurface(referenceSurface);
  403. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  404. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  405. Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1);
  406. /* Clear surface. */
  407. clearScreen();
  408. /* Tiled blit. */
  409. rect.x = 0.0f;
  410. rect.y = 0.0f;
  411. rect.w = (float)TESTRENDER_SCREEN_W;
  412. rect.h = (float)TESTRENDER_SCREEN_H;
  413. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, &rect);
  414. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret);
  415. /* See if it's the same */
  416. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  417. /* Make current */
  418. SDL_RenderPresent(renderer);
  419. }
  420. /* 9-grid blit - 2.0 scale */
  421. {
  422. SDLTest_Log("9-grid blit - 2.0 scale");
  423. /* Create reference surface */
  424. SDL_DestroySurface(referenceSurface);
  425. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  426. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  427. Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2);
  428. /* Clear surface. */
  429. clearScreen();
  430. /* Tiled blit. */
  431. rect.x = 0.0f;
  432. rect.y = 0.0f;
  433. rect.w = (float)TESTRENDER_SCREEN_W;
  434. rect.h = (float)TESTRENDER_SCREEN_H;
  435. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, &rect);
  436. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret);
  437. /* See if it's the same */
  438. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  439. /* Make current */
  440. SDL_RenderPresent(renderer);
  441. }
  442. /* Clean up. */
  443. SDL_DestroySurface(source);
  444. SDL_DestroyTexture(texture);
  445. /* Create complex source surface */
  446. source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32);
  447. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  448. SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  449. SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  450. SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  451. SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  452. SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  453. SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  454. SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  455. SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  456. SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  457. SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  458. SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  459. SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  460. SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  461. SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  462. SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  463. SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  464. SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  465. SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  466. SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  467. SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  468. SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  469. SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  470. SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  471. SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  472. SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  473. texture = SDL_CreateTextureFromSurface(renderer, source);
  474. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  475. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  476. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret);
  477. /* complex 9-grid blit - 1.0 scale */
  478. {
  479. SDLTest_Log("complex 9-grid blit - 1.0 scale");
  480. /* Create reference surface */
  481. SDL_DestroySurface(referenceSurface);
  482. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  483. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  484. Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2);
  485. /* Clear surface. */
  486. clearScreen();
  487. /* Tiled blit. */
  488. rect.x = 0.0f;
  489. rect.y = 0.0f;
  490. rect.w = (float)TESTRENDER_SCREEN_W;
  491. rect.h = (float)TESTRENDER_SCREEN_H;
  492. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 1.0f, &rect);
  493. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret);
  494. /* See if it's the same */
  495. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  496. /* Make current */
  497. SDL_RenderPresent(renderer);
  498. }
  499. /* complex 9-grid blit - 2.0 scale */
  500. {
  501. SDLTest_Log("complex 9-grid blit - 2.0 scale");
  502. /* Create reference surface */
  503. SDL_DestroySurface(referenceSurface);
  504. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  505. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  506. Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4);
  507. /* Clear surface. */
  508. clearScreen();
  509. /* Tiled blit. */
  510. rect.x = 0.0f;
  511. rect.y = 0.0f;
  512. rect.w = (float)TESTRENDER_SCREEN_W;
  513. rect.h = (float)TESTRENDER_SCREEN_H;
  514. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 2.0f, &rect);
  515. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret);
  516. /* See if it's the same */
  517. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  518. /* Make current */
  519. SDL_RenderPresent(renderer);
  520. }
  521. /* Clean up. */
  522. SDL_DestroySurface(referenceSurface);
  523. SDL_DestroySurface(source);
  524. SDL_DestroyTexture(texture);
  525. return TEST_COMPLETED;
  526. }
  527. /**
  528. * Tests tiled 9-grid blitting.
  529. */
  530. static int SDLCALL render_testBlit9GridTiled(void *arg)
  531. {
  532. SDL_Surface *referenceSurface = NULL;
  533. SDL_Surface *source = NULL;
  534. SDL_Texture *texture;
  535. int x, y;
  536. SDL_FRect rect;
  537. int ret = 0;
  538. /* Create source surface */
  539. source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
  540. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  541. for (y = 0; y < 3; ++y) {
  542. for (x = 0; x < 3; ++x) {
  543. SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
  544. }
  545. }
  546. texture = SDL_CreateTextureFromSurface(renderer, source);
  547. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  548. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  549. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret);
  550. /* Tiled 9-grid blit - 1.0 scale */
  551. {
  552. SDLTest_Log("tiled 9-grid blit - 1.0 scale");
  553. /* Create reference surface */
  554. SDL_DestroySurface(referenceSurface);
  555. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  556. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  557. Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1);
  558. /* Clear surface. */
  559. clearScreen();
  560. /* Tiled blit. */
  561. rect.x = 0.0f;
  562. rect.y = 0.0f;
  563. rect.w = (float)TESTRENDER_SCREEN_W;
  564. rect.h = (float)TESTRENDER_SCREEN_H;
  565. ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, &rect, 1.0f);
  566. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret);
  567. /* See if it's the same */
  568. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  569. /* Make current */
  570. SDL_RenderPresent(renderer);
  571. }
  572. /* Tiled 9-grid blit - 2.0 scale */
  573. {
  574. SDLTest_Log("tiled 9-grid blit - 2.0 scale");
  575. /* Create reference surface */
  576. SDL_DestroySurface(referenceSurface);
  577. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  578. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  579. Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2);
  580. /* Clear surface. */
  581. clearScreen();
  582. /* Tiled blit. */
  583. rect.x = 0.0f;
  584. rect.y = 0.0f;
  585. rect.w = (float)TESTRENDER_SCREEN_W;
  586. rect.h = (float)TESTRENDER_SCREEN_H;
  587. ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, &rect, 2.0f);
  588. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret);
  589. /* See if it's the same */
  590. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  591. /* Make current */
  592. SDL_RenderPresent(renderer);
  593. }
  594. /* Clean up. */
  595. SDL_DestroySurface(source);
  596. SDL_DestroyTexture(texture);
  597. /* Create complex source surface */
  598. source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32);
  599. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  600. SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  601. SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  602. SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  603. SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  604. SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  605. SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  606. SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  607. SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  608. SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  609. SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  610. SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  611. SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  612. SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  613. SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  614. SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  615. SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  616. SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  617. SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  618. SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  619. SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  620. SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  621. SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  622. SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  623. SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  624. SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  625. texture = SDL_CreateTextureFromSurface(renderer, source);
  626. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  627. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  628. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret);
  629. /* complex tiled 9-grid blit - 1.0 scale */
  630. {
  631. SDLTest_Log("complex tiled 9-grid blit - 1.0 scale");
  632. /* Create reference surface */
  633. SDL_DestroySurface(referenceSurface);
  634. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  635. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  636. Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2);
  637. /* Clear surface. */
  638. clearScreen();
  639. /* Tiled blit. */
  640. rect.x = 0.0f;
  641. rect.y = 0.0f;
  642. rect.w = (float)TESTRENDER_SCREEN_W;
  643. rect.h = (float)TESTRENDER_SCREEN_H;
  644. ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 1.0f, &rect, 1.0f);
  645. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret);
  646. /* See if it's the same */
  647. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  648. /* Make current */
  649. SDL_RenderPresent(renderer);
  650. }
  651. /* complex tiled 9-grid blit - 2.0 scale */
  652. {
  653. SDLTest_Log("complex tiled 9-grid blit - 2.0 scale");
  654. /* Create reference surface */
  655. SDL_DestroySurface(referenceSurface);
  656. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  657. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  658. Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4);
  659. /* Clear surface. */
  660. clearScreen();
  661. /* Tiled blit. */
  662. rect.x = 0.0f;
  663. rect.y = 0.0f;
  664. rect.w = (float)TESTRENDER_SCREEN_W;
  665. rect.h = (float)TESTRENDER_SCREEN_H;
  666. ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 2.0f, &rect, 2.0f);
  667. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret);
  668. /* See if it's the same */
  669. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  670. /* Make current */
  671. SDL_RenderPresent(renderer);
  672. }
  673. /* Clean up. */
  674. SDL_DestroySurface(referenceSurface);
  675. SDL_DestroySurface(source);
  676. SDL_DestroyTexture(texture);
  677. return TEST_COMPLETED;
  678. }
  679. /**
  680. * Blits doing color tests.
  681. *
  682. * \sa SDL_SetTextureColorMod
  683. * \sa SDL_RenderTexture
  684. * \sa SDL_DestroyTexture
  685. */
  686. static int SDLCALL render_testBlitColor(void *arg)
  687. {
  688. int ret;
  689. SDL_FRect rect;
  690. SDL_Texture *tface;
  691. SDL_Surface *referenceSurface = NULL;
  692. int i, j, ni, nj;
  693. int checkFailCount1;
  694. int checkFailCount2;
  695. /* Clear surface. */
  696. clearScreen();
  697. /* Create face surface. */
  698. tface = loadTestFace();
  699. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  700. if (tface == NULL) {
  701. return TEST_ABORTED;
  702. }
  703. /* Constant values. */
  704. rect.w = (float)tface->w;
  705. rect.h = (float)tface->h;
  706. ni = TESTRENDER_SCREEN_W - tface->w;
  707. nj = TESTRENDER_SCREEN_H - tface->h;
  708. /* Test blitting with color mod. */
  709. checkFailCount1 = 0;
  710. checkFailCount2 = 0;
  711. for (j = 0; j <= nj; j += 4) {
  712. for (i = 0; i <= ni; i += 4) {
  713. /* Set color mod. */
  714. ret = SDL_SetTextureColorMod(tface, (Uint8)((255 / nj) * j), (Uint8)((255 / ni) * i), (Uint8)((255 / nj) * j));
  715. if (!ret) {
  716. checkFailCount1++;
  717. }
  718. /* Blitting. */
  719. rect.x = (float)i;
  720. rect.y = (float)j;
  721. ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
  722. if (!ret) {
  723. checkFailCount2++;
  724. }
  725. }
  726. }
  727. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
  728. SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount2);
  729. /* See if it's the same. */
  730. referenceSurface = SDLTest_ImageBlitColor();
  731. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  732. /* Make current */
  733. SDL_RenderPresent(renderer);
  734. /* Clean up. */
  735. SDL_DestroyTexture(tface);
  736. SDL_DestroySurface(referenceSurface);
  737. referenceSurface = NULL;
  738. return TEST_COMPLETED;
  739. }
  740. typedef enum TestRenderOperation
  741. {
  742. TEST_RENDER_POINT,
  743. TEST_RENDER_LINE,
  744. TEST_RENDER_RECT,
  745. TEST_RENDER_COPY_XRGB,
  746. TEST_RENDER_COPY_ARGB,
  747. } TestRenderOperation;
  748. /**
  749. * Helper that tests a specific operation and blend mode, -1 for color mod, -2 for alpha mod
  750. */
  751. static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFormat dst_format)
  752. {
  753. /* Allow up to 2 delta from theoretical value to account for rounding error.
  754. * We allow 2 rounding errors because the software renderer breaks drawing operations into alpha multiplication and a separate blend operation.
  755. */
  756. const int MAXIMUM_ERROR = 2;
  757. int ret;
  758. SDL_Texture *src = NULL;
  759. SDL_Texture *dst;
  760. SDL_Surface *result;
  761. Uint8 srcR = 10, srcG = 128, srcB = 240, srcA = 100;
  762. Uint8 dstR = 128, dstG = 128, dstB = 128, dstA = 128;
  763. Uint8 expectedR, expectedG, expectedB, expectedA;
  764. Uint8 actualR, actualG, actualB, actualA;
  765. int deltaR, deltaG, deltaB, deltaA;
  766. const char *operation = "UNKNOWN";
  767. const char *mode_name = "UNKNOWN";
  768. /* Create dst surface */
  769. dst = SDL_CreateTexture(renderer, dst_format, SDL_TEXTUREACCESS_TARGET, 3, 3);
  770. SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
  771. if (dst == NULL) {
  772. return;
  773. }
  774. if (SDL_ISPIXELFORMAT_ALPHA(dst_format)) {
  775. SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
  776. ret = SDL_GetTextureBlendMode(dst, &blendMode);
  777. SDLTest_AssertCheck(ret == true, "Verify result from SDL_GetTextureBlendMode(), expected: true, got: %i", ret);
  778. SDLTest_AssertCheck(blendMode == SDL_BLENDMODE_BLEND, "Verify alpha texture blend mode, expected %d, got %" SDL_PRIu32, SDL_BLENDMODE_BLEND, blendMode);
  779. }
  780. /* Set as render target */
  781. SDL_SetRenderTarget(renderer, dst);
  782. /* Clear surface. */
  783. if (!SDL_ISPIXELFORMAT_ALPHA(dst_format)) {
  784. dstA = 255;
  785. }
  786. ret = SDL_SetRenderDrawColor(renderer, dstR, dstG, dstB, dstA);
  787. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawColor(), expected: true, got: %i", ret);
  788. ret = SDL_RenderClear(renderer);
  789. SDLTest_AssertPass("Call to SDL_RenderClear()");
  790. SDLTest_AssertCheck(ret == true, "Verify result from SDL_RenderClear, expected: true, got: %i", ret);
  791. if (op == TEST_RENDER_COPY_XRGB || op == TEST_RENDER_COPY_ARGB) {
  792. Uint8 pixels[4];
  793. /* Create src surface */
  794. src = SDL_CreateTexture(renderer, op == TEST_RENDER_COPY_XRGB ? SDL_PIXELFORMAT_RGBX32 : SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 1, 1);
  795. SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
  796. if (src == NULL) {
  797. return;
  798. }
  799. /* Clear surface. */
  800. if (op == TEST_RENDER_COPY_XRGB) {
  801. srcA = 255;
  802. }
  803. pixels[0] = srcR;
  804. pixels[1] = srcG;
  805. pixels[2] = srcB;
  806. pixels[3] = srcA;
  807. SDL_UpdateTexture(src, NULL, pixels, sizeof(pixels));
  808. /* Set blend mode. */
  809. if (mode >= 0) {
  810. ret = SDL_SetTextureBlendMode(src, (SDL_BlendMode)mode);
  811. SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()");
  812. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: true, got: %i", mode, ret);
  813. } else {
  814. ret = SDL_SetTextureBlendMode(src, SDL_BLENDMODE_BLEND);
  815. SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()");
  816. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: true, got: %i", mode, ret);
  817. }
  818. } else {
  819. /* Set draw color */
  820. ret = SDL_SetRenderDrawColor(renderer, srcR, srcG, srcB, srcA);
  821. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawColor(), expected: true, got: %i", ret);
  822. /* Set blend mode. */
  823. if (mode >= 0) {
  824. ret = SDL_SetRenderDrawBlendMode(renderer, (SDL_BlendMode)mode);
  825. SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()");
  826. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: true, got: %i", mode, ret);
  827. } else {
  828. ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
  829. SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()");
  830. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: true, got: %i", mode, ret);
  831. }
  832. }
  833. /* Test blend mode. */
  834. #define FLOAT(X) ((float)X / 255.0f)
  835. switch (mode) {
  836. case -1:
  837. mode_name = "color modulation";
  838. ret = SDL_SetTextureColorMod(src, srcR, srcG, srcB);
  839. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_SetTextureColorMod, expected: true, got: %i", ret);
  840. expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  841. expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  842. expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  843. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  844. break;
  845. case -2:
  846. mode_name = "alpha modulation";
  847. ret = SDL_SetTextureAlphaMod(src, srcA);
  848. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_SetTextureAlphaMod, expected: true, got: %i", ret);
  849. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstR) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  850. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstG) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  851. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstB) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  852. expectedA = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstA) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  853. break;
  854. case SDL_BLENDMODE_NONE:
  855. mode_name = "SDL_BLENDMODE_NONE";
  856. expectedR = srcR;
  857. expectedG = srcG;
  858. expectedB = srcB;
  859. expectedA = SDL_ISPIXELFORMAT_ALPHA(dst_format) ? srcA : 255;
  860. break;
  861. case SDL_BLENDMODE_BLEND:
  862. mode_name = "SDL_BLENDMODE_BLEND";
  863. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  864. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  865. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  866. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  867. break;
  868. case SDL_BLENDMODE_BLEND_PREMULTIPLIED:
  869. mode_name = "SDL_BLENDMODE_BLEND_PREMULTIPLIED";
  870. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  871. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  872. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  873. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  874. break;
  875. case SDL_BLENDMODE_ADD:
  876. mode_name = "SDL_BLENDMODE_ADD";
  877. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  878. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  879. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  880. expectedA = dstA;
  881. break;
  882. case SDL_BLENDMODE_ADD_PREMULTIPLIED:
  883. mode_name = "SDL_BLENDMODE_ADD_PREMULTIPLIED";
  884. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  885. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  886. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  887. expectedA = dstA;
  888. break;
  889. case SDL_BLENDMODE_MOD:
  890. mode_name = "SDL_BLENDMODE_MOD";
  891. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  892. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  893. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  894. expectedA = dstA;
  895. break;
  896. case SDL_BLENDMODE_MUL:
  897. mode_name = "SDL_BLENDMODE_MUL";
  898. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  899. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  900. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  901. expectedA = dstA;
  902. break;
  903. default:
  904. SDLTest_LogError("Invalid blending mode: %d", mode);
  905. return;
  906. }
  907. switch (op) {
  908. case TEST_RENDER_POINT:
  909. operation = "render point";
  910. ret = SDL_RenderPoint(renderer, 0.0f, 0.0f);
  911. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", ret);
  912. break;
  913. case TEST_RENDER_LINE:
  914. operation = "render line";
  915. ret = SDL_RenderLine(renderer, 0.0f, 0.0f, 2.0f, 2.0f);
  916. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderLine, expected: true, got: %i", ret);
  917. break;
  918. case TEST_RENDER_RECT:
  919. operation = "render rect";
  920. ret = SDL_RenderFillRect(renderer, NULL);
  921. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderFillRect, expected: 0, got: %i", ret);
  922. break;
  923. case TEST_RENDER_COPY_XRGB:
  924. case TEST_RENDER_COPY_ARGB:
  925. operation = (op == TEST_RENDER_COPY_XRGB) ? "render XRGB" : "render ARGB";
  926. ret = SDL_RenderTexture(renderer, src, NULL, NULL);
  927. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderTexture, expected: true, got: %i", ret);
  928. break;
  929. default:
  930. SDLTest_LogError("Invalid blending operation: %d", op);
  931. return;
  932. }
  933. result = SDL_RenderReadPixels(renderer, NULL);
  934. SDL_ReadSurfacePixel(result, 0, 0, &actualR, &actualG, &actualB, &actualA);
  935. deltaR = SDL_abs((int)actualR - expectedR);
  936. deltaG = SDL_abs((int)actualG - expectedG);
  937. deltaB = SDL_abs((int)actualB - expectedB);
  938. deltaA = SDL_abs((int)actualA - expectedA);
  939. SDLTest_AssertCheck(
  940. deltaR <= MAXIMUM_ERROR &&
  941. deltaG <= MAXIMUM_ERROR &&
  942. deltaB <= MAXIMUM_ERROR &&
  943. deltaA <= MAXIMUM_ERROR,
  944. "Checking %s %s operation results, expected %d,%d,%d,%d, got %d,%d,%d,%d",
  945. operation, mode_name,
  946. expectedR, expectedG, expectedB, expectedA, actualR, actualG, actualB, actualA);
  947. /* Clean up */
  948. SDL_DestroySurface(result);
  949. SDL_DestroyTexture(src);
  950. SDL_DestroyTexture(dst);
  951. }
  952. static void testBlendMode(int mode)
  953. {
  954. const TestRenderOperation operations[] = {
  955. TEST_RENDER_POINT,
  956. TEST_RENDER_LINE,
  957. TEST_RENDER_RECT,
  958. TEST_RENDER_COPY_XRGB,
  959. TEST_RENDER_COPY_ARGB
  960. };
  961. const SDL_PixelFormat dst_formats[] = {
  962. SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
  963. };
  964. int i, j;
  965. for (i = 0; i < SDL_arraysize(operations); ++i) {
  966. for (j = 0; j < SDL_arraysize(dst_formats); ++j) {
  967. TestRenderOperation op = operations[i];
  968. if (mode < 0) {
  969. if (op != TEST_RENDER_COPY_XRGB && op != TEST_RENDER_COPY_ARGB) {
  970. /* Unsupported mode for this operation */
  971. continue;
  972. }
  973. }
  974. testBlendModeOperation(op, mode, dst_formats[j]);
  975. }
  976. }
  977. }
  978. /**
  979. * Tests render operations with blend modes
  980. */
  981. static int SDLCALL render_testBlendModes(void *arg)
  982. {
  983. testBlendMode(-1);
  984. testBlendMode(-2);
  985. testBlendMode(SDL_BLENDMODE_NONE);
  986. testBlendMode(SDL_BLENDMODE_BLEND);
  987. testBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
  988. testBlendMode(SDL_BLENDMODE_ADD);
  989. testBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
  990. testBlendMode(SDL_BLENDMODE_MOD);
  991. testBlendMode(SDL_BLENDMODE_MUL);
  992. return TEST_COMPLETED;
  993. }
  994. /**
  995. * Test viewport
  996. */
  997. static int SDLCALL render_testViewport(void *arg)
  998. {
  999. SDL_Surface *referenceSurface;
  1000. SDL_Rect viewport;
  1001. viewport.x = TESTRENDER_SCREEN_W / 3;
  1002. viewport.y = TESTRENDER_SCREEN_H / 3;
  1003. viewport.w = TESTRENDER_SCREEN_W / 2;
  1004. viewport.h = TESTRENDER_SCREEN_H / 2;
  1005. /* Create expected result */
  1006. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  1007. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  1008. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  1009. /* Clear surface. */
  1010. clearScreen();
  1011. /* Set the viewport and do a fill operation */
  1012. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  1013. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1014. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  1015. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  1016. /* Check to see if final image matches. */
  1017. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1018. /*
  1019. * Verify that clear ignores the viewport
  1020. */
  1021. /* Create expected result */
  1022. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
  1023. /* Clear surface. */
  1024. clearScreen();
  1025. /* Set the viewport and do a clear operation */
  1026. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  1027. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1028. CHECK_FUNC(SDL_RenderClear, (renderer))
  1029. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  1030. /* Check to see if final image matches. */
  1031. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1032. /* Make current */
  1033. SDL_RenderPresent(renderer);
  1034. SDL_DestroySurface(referenceSurface);
  1035. return TEST_COMPLETED;
  1036. }
  1037. static int SDLCALL render_testRGBSurfaceNoAlpha(void* arg)
  1038. {
  1039. SDL_Surface *surface;
  1040. SDL_Renderer *software_renderer;
  1041. SDL_Surface *surface2;
  1042. SDL_Texture *texture2;
  1043. bool result;
  1044. SDL_FRect dest_rect;
  1045. SDL_FPoint point;
  1046. const SDL_PixelFormatDetails *format_details;
  1047. Uint8 r, g, b, a;
  1048. SDLTest_AssertPass("About to call SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_RGBX32)");
  1049. surface = SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_RGBX32);
  1050. SDLTest_AssertCheck(surface != NULL, "Returned surface must be not NULL");
  1051. if (surface == NULL) {
  1052. return TEST_ABORTED;
  1053. }
  1054. SDLTest_AssertPass("About to call SDL_GetPixelFormatDetails(surface->format)");
  1055. format_details = SDL_GetPixelFormatDetails(surface->format);
  1056. SDLTest_AssertCheck(format_details != NULL, "Result must be non-NULL, is %p", format_details);
  1057. if (format_details == NULL) {
  1058. SDL_DestroySurface(surface);
  1059. return TEST_ABORTED;
  1060. }
  1061. SDLTest_AssertCheck(format_details->bits_per_pixel == 32, "format_details->bits_per_pixel is %d, should be %d", format_details->bits_per_pixel, 32);
  1062. SDLTest_AssertCheck(format_details->bytes_per_pixel == 4, "format_details->bytes_per_pixel is %d, should be %d", format_details->bytes_per_pixel, 4);
  1063. SDLTest_AssertPass("About to call SDL_CreateSoftwareRenderer(surface)");
  1064. software_renderer = SDL_CreateSoftwareRenderer(surface);
  1065. SDLTest_AssertCheck(software_renderer != NULL, "Returned renderer must be not NULL");
  1066. if (software_renderer == NULL) {
  1067. SDL_DestroySurface(surface);
  1068. return TEST_ABORTED;
  1069. }
  1070. SDLTest_AssertPass("About to call SDL_CreateSurface(16, 16, SDL_PIXELFORMAT_RGBX32)");
  1071. surface2 = SDL_CreateSurface(16, 16, SDL_PIXELFORMAT_RGBX32);
  1072. SDLTest_AssertCheck(surface2 != NULL, "Returned surface must be not NULL");
  1073. if (surface2 == NULL) {
  1074. SDL_DestroySurface(surface);
  1075. SDL_DestroyRenderer(software_renderer);
  1076. return TEST_ABORTED;
  1077. }
  1078. SDLTest_AssertPass("About to call SDL_FillRect(surface2, NULL, 0)");
  1079. result = SDL_FillSurfaceRect(surface2, NULL, SDL_MapRGB(SDL_GetPixelFormatDetails(surface2->format), NULL, 0, 0, 0));
  1080. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1081. SDLTest_AssertPass("About to call SDL_CreateTextureFromSurface(software_renderer, surface2)");
  1082. texture2 = SDL_CreateTextureFromSurface(software_renderer, surface2);
  1083. SDLTest_AssertCheck(texture2 != NULL, "Returned texture is not NULL");
  1084. SDLTest_AssertPass("About to call SDL_SetRenderDrawColor(renderer, 0xaa, 0xbb, 0xcc, 0x0)");
  1085. result = SDL_SetRenderDrawColor(software_renderer, 0xaa, 0xbb, 0xcc, 0x0);
  1086. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1087. SDLTest_AssertPass("About to call SDL_RenderClear(renderer)");
  1088. result = SDL_RenderClear(software_renderer);
  1089. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1090. SDLTest_AssertPass("About to call SDL_SetRenderDrawColor(renderer, 0x0, 0x0, 0x0, 0x0)");
  1091. result = SDL_SetRenderDrawColor(software_renderer, 0x0, 0x0, 0x0, 0x0);
  1092. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1093. dest_rect.x = 32;
  1094. dest_rect.y = 32;
  1095. dest_rect.w = (float)surface2->w;
  1096. dest_rect.h = (float)surface2->h;
  1097. point.x = 0;
  1098. point.y = 0;
  1099. SDLTest_AssertPass("About to call SDL_RenderCopy(software_renderer, texture, NULL, &{%g, %g, %g, %g})",
  1100. dest_rect.x, dest_rect.h, dest_rect.w, dest_rect.h);
  1101. result = SDL_RenderTextureRotated(software_renderer, texture2, NULL, &dest_rect, 180, &point, SDL_FLIP_NONE);
  1102. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1103. SDLTest_AssertPass("About to call SDL_RenderPresent(software_renderer)");
  1104. SDL_RenderPresent(software_renderer);
  1105. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(0, 0)");
  1106. result = SDL_ReadSurfacePixel(surface, 0, 0, &r, &g, &b, &a);
  1107. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1108. SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE,
  1109. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1110. r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE);
  1111. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(15, 15)");
  1112. result = SDL_ReadSurfacePixel(surface, 15, 15, &r, &g, &b, &a);
  1113. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1114. SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE,
  1115. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1116. r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE);
  1117. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(16, 16)");
  1118. result = SDL_ReadSurfacePixel(surface, 16, 16, &r, &g, &b, &a);
  1119. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1120. SDLTest_AssertCheck(r == 0x00 && g == 0x00 && b == 0x00 && a == SDL_ALPHA_OPAQUE,
  1121. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1122. r, g, b, a, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
  1123. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(31, 31)");
  1124. result = SDL_ReadSurfacePixel(surface, 31, 31, &r, &g, &b, &a);
  1125. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1126. SDLTest_AssertCheck(r == 0x00 && g == 0x00 && b == 0x00 && a == SDL_ALPHA_OPAQUE,
  1127. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1128. r, g, b, a, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
  1129. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(32, 32)");
  1130. result = SDL_ReadSurfacePixel(surface, 32, 32, &r, &g, &b, &a);
  1131. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1132. SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE,
  1133. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1134. r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE);
  1135. SDL_DestroyTexture(texture2);
  1136. SDL_DestroySurface(surface2);
  1137. SDL_DestroyRenderer(software_renderer);
  1138. SDL_DestroySurface(surface);
  1139. return TEST_COMPLETED;
  1140. }
  1141. /**
  1142. * Test clip rect
  1143. */
  1144. static int SDLCALL render_testClipRect(void *arg)
  1145. {
  1146. SDL_Surface *referenceSurface;
  1147. SDL_Rect cliprect;
  1148. cliprect.x = TESTRENDER_SCREEN_W / 3;
  1149. cliprect.y = TESTRENDER_SCREEN_H / 3;
  1150. cliprect.w = TESTRENDER_SCREEN_W / 2;
  1151. cliprect.h = TESTRENDER_SCREEN_H / 2;
  1152. /* Create expected result */
  1153. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  1154. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  1155. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &cliprect, RENDER_COLOR_GREEN))
  1156. /* Clear surface. */
  1157. clearScreen();
  1158. /* Set the cliprect and do a fill operation */
  1159. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
  1160. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1161. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  1162. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
  1163. /* Check to see if final image matches. */
  1164. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1165. /*
  1166. * Verify that clear ignores the cliprect
  1167. */
  1168. /* Create expected result */
  1169. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
  1170. /* Clear surface. */
  1171. clearScreen();
  1172. /* Set the cliprect and do a clear operation */
  1173. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
  1174. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1175. CHECK_FUNC(SDL_RenderClear, (renderer))
  1176. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
  1177. /* Check to see if final image matches. */
  1178. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1179. /* Make current */
  1180. SDL_RenderPresent(renderer);
  1181. SDL_DestroySurface(referenceSurface);
  1182. return TEST_COMPLETED;
  1183. }
  1184. /**
  1185. * Test logical size
  1186. */
  1187. static int SDLCALL render_testLogicalSize(void *arg)
  1188. {
  1189. SDL_Surface *referenceSurface;
  1190. SDL_Rect viewport;
  1191. SDL_FRect rect;
  1192. int w, h;
  1193. int set_w, set_h;
  1194. SDL_RendererLogicalPresentation set_presentation_mode;
  1195. SDL_FRect set_rect;
  1196. const int factor = 2;
  1197. viewport.x = ((TESTRENDER_SCREEN_W / 4) / factor) * factor;
  1198. viewport.y = ((TESTRENDER_SCREEN_H / 4) / factor) * factor;
  1199. viewport.w = ((TESTRENDER_SCREEN_W / 2) / factor) * factor;
  1200. viewport.h = ((TESTRENDER_SCREEN_H / 2) / factor) * factor;
  1201. /* Create expected result */
  1202. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  1203. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  1204. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  1205. /* Clear surface. */
  1206. clearScreen();
  1207. /* Set the logical size and do a fill operation */
  1208. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  1209. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor, SDL_LOGICAL_PRESENTATION_LETTERBOX))
  1210. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
  1211. SDLTest_AssertCheck(
  1212. set_w == (w / factor) &&
  1213. set_h == (h / factor) &&
  1214. set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX,
  1215. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
  1216. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  1217. SDLTest_AssertCheck(
  1218. set_rect.x == 0.0f &&
  1219. set_rect.y == 0.0f &&
  1220. set_rect.w == 320.0f &&
  1221. set_rect.h == 240.0f,
  1222. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  1223. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1224. rect.x = (float)viewport.x / factor;
  1225. rect.y = (float)viewport.y / factor;
  1226. rect.w = (float)viewport.w / factor;
  1227. rect.h = (float)viewport.h / factor;
  1228. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  1229. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
  1230. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
  1231. SDLTest_AssertCheck(
  1232. set_w == 0 &&
  1233. set_h == 0 &&
  1234. set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED,
  1235. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
  1236. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  1237. SDLTest_AssertCheck(
  1238. set_rect.x == 0.0f &&
  1239. set_rect.y == 0.0f &&
  1240. set_rect.w == 320.0f &&
  1241. set_rect.h == 240.0f,
  1242. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  1243. /* Check to see if final image matches. */
  1244. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1245. /* Clear surface. */
  1246. clearScreen();
  1247. /* Set the logical size and viewport and do a fill operation */
  1248. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  1249. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor, SDL_LOGICAL_PRESENTATION_LETTERBOX))
  1250. viewport.x = (TESTRENDER_SCREEN_W / 4) / factor;
  1251. viewport.y = (TESTRENDER_SCREEN_H / 4) / factor;
  1252. viewport.w = (TESTRENDER_SCREEN_W / 2) / factor;
  1253. viewport.h = (TESTRENDER_SCREEN_H / 2) / factor;
  1254. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  1255. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1256. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  1257. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  1258. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
  1259. /* Check to see if final image matches. */
  1260. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1261. /*
  1262. * Test a logical size that isn't the same aspect ratio as the window
  1263. */
  1264. viewport.x = (TESTRENDER_SCREEN_W / 4);
  1265. viewport.y = 0;
  1266. viewport.w = TESTRENDER_SCREEN_W;
  1267. viewport.h = TESTRENDER_SCREEN_H;
  1268. /* Create expected result */
  1269. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  1270. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  1271. /* Clear surface. */
  1272. clearScreen();
  1273. /* Set the logical size and do a fill operation */
  1274. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  1275. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer,
  1276. w - 2 * (TESTRENDER_SCREEN_W / 4),
  1277. h,
  1278. SDL_LOGICAL_PRESENTATION_LETTERBOX))
  1279. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
  1280. SDLTest_AssertCheck(
  1281. set_w == w - 2 * (TESTRENDER_SCREEN_W / 4) &&
  1282. set_h == h &&
  1283. set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX,
  1284. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
  1285. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  1286. SDLTest_AssertCheck(
  1287. set_rect.x == 20.0f &&
  1288. set_rect.y == 0.0f &&
  1289. set_rect.w == 280.0f &&
  1290. set_rect.h == 240.0f,
  1291. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  1292. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1293. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  1294. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
  1295. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
  1296. SDLTest_AssertCheck(
  1297. set_w == 0 &&
  1298. set_h == 0 &&
  1299. set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED,
  1300. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
  1301. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  1302. SDLTest_AssertCheck(
  1303. set_rect.x == 0.0f &&
  1304. set_rect.y == 0.0f &&
  1305. set_rect.w == 320.0f &&
  1306. set_rect.h == 240.0f,
  1307. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  1308. /* Check to see if final image matches. */
  1309. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1310. /* Clear surface. */
  1311. clearScreen();
  1312. /* Make current */
  1313. SDL_RenderPresent(renderer);
  1314. SDL_DestroySurface(referenceSurface);
  1315. return TEST_COMPLETED;
  1316. }
  1317. /**
  1318. * @brief Tests setting and getting texture scale mode.
  1319. *
  1320. * \sa
  1321. * http://wiki.libsdl.org/SDL2/SDL_SetTextureScaleMode
  1322. * http://wiki.libsdl.org/SDL2/SDL_GetTextureScaleMode
  1323. */
  1324. static int SDLCALL render_testGetSetTextureScaleMode(void *arg)
  1325. {
  1326. const struct {
  1327. const char *name;
  1328. SDL_ScaleMode mode;
  1329. } modes[] = {
  1330. { "SDL_SCALEMODE_NEAREST", SDL_SCALEMODE_NEAREST },
  1331. { "SDL_SCALEMODE_LINEAR", SDL_SCALEMODE_LINEAR },
  1332. { "SDL_SCALEMODE_PIXELART", SDL_SCALEMODE_PIXELART },
  1333. };
  1334. size_t i;
  1335. for (i = 0; i < SDL_arraysize(modes); i++) {
  1336. SDL_Texture *texture;
  1337. bool result;
  1338. SDL_ScaleMode actual_mode = SDL_SCALEMODE_NEAREST;
  1339. SDL_ClearError();
  1340. SDLTest_AssertPass("About to call SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 16, 16)");
  1341. texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 16, 16);
  1342. SDLTest_AssertCheck(texture != NULL, "SDL_CreateTexture must return a non-NULL texture");
  1343. SDLTest_AssertPass("About to call SDL_SetTextureScaleMode(texture, %s)", modes[i].name);
  1344. result = SDL_SetTextureScaleMode(texture, modes[i].mode);
  1345. SDLTest_AssertCheck(result == true, "SDL_SetTextureScaleMode returns %d, expected %d", result, true);
  1346. SDLTest_AssertPass("About to call SDL_GetTextureScaleMode(texture)");
  1347. result = SDL_GetTextureScaleMode(texture, &actual_mode);
  1348. SDLTest_AssertCheck(result == true, "SDL_SetTextureScaleMode returns %d, expected %d", result, true);
  1349. SDLTest_AssertCheck(actual_mode == modes[i].mode, "SDL_GetTextureScaleMode must return %s (%d), actual=%d",
  1350. modes[i].name, modes[i].mode, actual_mode);
  1351. }
  1352. return TEST_COMPLETED;
  1353. }
  1354. /* Helper functions */
  1355. /**
  1356. * Checks to see if functionality is supported. Helper function.
  1357. */
  1358. static bool isSupported(int code)
  1359. {
  1360. return (code != false);
  1361. }
  1362. /**
  1363. * Test to see if we can vary the draw color. Helper function.
  1364. *
  1365. * \sa SDL_SetRenderDrawColor
  1366. * \sa SDL_GetRenderDrawColor
  1367. */
  1368. static bool hasDrawColor(void)
  1369. {
  1370. int ret, fail;
  1371. Uint8 r, g, b, a;
  1372. fail = 0;
  1373. /* Set color. */
  1374. ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100);
  1375. if (!isSupported(ret)) {
  1376. fail = 1;
  1377. }
  1378. ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
  1379. if (!isSupported(ret)) {
  1380. fail = 1;
  1381. }
  1382. /* Restore natural. */
  1383. ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  1384. if (!isSupported(ret)) {
  1385. fail = 1;
  1386. }
  1387. /* Something failed, consider not available. */
  1388. if (fail) {
  1389. return false;
  1390. }
  1391. /* Not set properly, consider failed. */
  1392. else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) {
  1393. return false;
  1394. }
  1395. return true;
  1396. }
  1397. /**
  1398. * Loads the test image 'Face' as texture. Helper function.
  1399. *
  1400. * \sa SDL_CreateTextureFromSurface
  1401. */
  1402. static SDL_Texture *
  1403. loadTestFace(void)
  1404. {
  1405. SDL_Surface *face;
  1406. SDL_Texture *tface;
  1407. face = SDLTest_ImageFace();
  1408. if (!face) {
  1409. return NULL;
  1410. }
  1411. tface = SDL_CreateTextureFromSurface(renderer, face);
  1412. if (!tface) {
  1413. SDLTest_LogError("SDL_CreateTextureFromSurface() failed with error: %s", SDL_GetError());
  1414. }
  1415. SDL_DestroySurface(face);
  1416. return tface;
  1417. }
  1418. /**
  1419. * Compares screen pixels with image pixels. Helper function.
  1420. *
  1421. * \param referenceSurface Image to compare against.
  1422. * \param allowable_error allowed difference from the reference image
  1423. *
  1424. * \sa SDL_RenderReadPixels
  1425. * \sa SDL_CreateSurfaceFrom
  1426. * \sa SDL_DestroySurface
  1427. */
  1428. static void compare(SDL_Surface *referenceSurface, int allowable_error)
  1429. {
  1430. int ret;
  1431. SDL_Rect rect;
  1432. SDL_Surface *surface, *testSurface;
  1433. /* Explicitly specify the rect in case the window isn't the expected size... */
  1434. rect.x = 0;
  1435. rect.y = 0;
  1436. rect.w = TESTRENDER_SCREEN_W;
  1437. rect.h = TESTRENDER_SCREEN_H;
  1438. surface = SDL_RenderReadPixels(renderer, &rect);
  1439. if (!surface) {
  1440. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  1441. return;
  1442. }
  1443. testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
  1444. SDL_DestroySurface(surface);
  1445. if (!testSurface) {
  1446. SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
  1447. return;
  1448. }
  1449. /* Compare surface. */
  1450. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error);
  1451. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  1452. /* Clean up. */
  1453. SDL_DestroySurface(testSurface);
  1454. }
  1455. static void compare2x(SDL_Surface *referenceSurface, int allowable_error)
  1456. {
  1457. int ret;
  1458. SDL_Rect rect;
  1459. SDL_Surface *surface, *testSurface;
  1460. /* Explicitly specify the rect in case the window isn't the expected size... */
  1461. rect.x = 0;
  1462. rect.y = 0;
  1463. rect.w = TESTRENDER_SCREEN_W * 2;
  1464. rect.h = TESTRENDER_SCREEN_H * 2;
  1465. surface = SDL_RenderReadPixels(renderer, &rect);
  1466. if (!surface) {
  1467. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  1468. return;
  1469. }
  1470. testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
  1471. SDL_DestroySurface(surface);
  1472. if (!testSurface) {
  1473. SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
  1474. return;
  1475. }
  1476. /* Compare surface. */
  1477. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error);
  1478. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  1479. /* Clean up. */
  1480. SDL_DestroySurface(testSurface);
  1481. }
  1482. /**
  1483. * Clears the screen. Helper function.
  1484. *
  1485. * \sa SDL_SetRenderDrawColor
  1486. * \sa SDL_RenderClear
  1487. * \sa SDL_RenderPresent
  1488. * \sa SDL_SetRenderDrawBlendMode
  1489. */
  1490. static int
  1491. clearScreen(void)
  1492. {
  1493. int ret;
  1494. /* Make current */
  1495. SDL_RenderPresent(renderer);
  1496. /* Set color. */
  1497. ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  1498. SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawColor, expected: true, got: %i", ret);
  1499. /* Clear screen. */
  1500. ret = SDL_RenderClear(renderer);
  1501. SDLTest_AssertCheck(ret == true, "Validate result from SDL_RenderClear, expected: true, got: %i", ret);
  1502. /* Set defaults. */
  1503. ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
  1504. SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawBlendMode, expected: true, got: %i", ret);
  1505. ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
  1506. SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawColor, expected: true, got: %i", ret);
  1507. return 0;
  1508. }
  1509. /**
  1510. * Tests geometry UV clamping
  1511. */
  1512. static int SDLCALL render_testUVClamping(void *arg)
  1513. {
  1514. SDL_Vertex vertices[6];
  1515. SDL_Vertex *verts = vertices;
  1516. SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f };
  1517. SDL_FRect rect;
  1518. float min_U = -0.5f;
  1519. float max_U = 1.5f;
  1520. float min_V = -0.5f;
  1521. float max_V = 1.5f;
  1522. SDL_Texture *tface;
  1523. SDL_Surface *referenceSurface = NULL;
  1524. /* Clear surface. */
  1525. clearScreen();
  1526. /* Create face surface. */
  1527. tface = loadTestFace();
  1528. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  1529. if (tface == NULL) {
  1530. return TEST_ABORTED;
  1531. }
  1532. rect.w = (float)tface->w * 2;
  1533. rect.h = (float)tface->h * 2;
  1534. rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2;
  1535. rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2;
  1536. /*
  1537. * 0--1
  1538. * | /|
  1539. * |/ |
  1540. * 3--2
  1541. *
  1542. * Draw sprite2 as triangles that can be recombined as rect by software renderer
  1543. */
  1544. /* 0 */
  1545. verts->position.x = rect.x;
  1546. verts->position.y = rect.y;
  1547. verts->color = color;
  1548. verts->tex_coord.x = min_U;
  1549. verts->tex_coord.y = min_V;
  1550. verts++;
  1551. /* 1 */
  1552. verts->position.x = rect.x + rect.w;
  1553. verts->position.y = rect.y;
  1554. verts->color = color;
  1555. verts->tex_coord.x = max_U;
  1556. verts->tex_coord.y = min_V;
  1557. verts++;
  1558. /* 2 */
  1559. verts->position.x = rect.x + rect.w;
  1560. verts->position.y = rect.y + rect.h;
  1561. verts->color = color;
  1562. verts->tex_coord.x = max_U;
  1563. verts->tex_coord.y = max_V;
  1564. verts++;
  1565. /* 0 */
  1566. verts->position.x = rect.x;
  1567. verts->position.y = rect.y;
  1568. verts->color = color;
  1569. verts->tex_coord.x = min_U;
  1570. verts->tex_coord.y = min_V;
  1571. verts++;
  1572. /* 2 */
  1573. verts->position.x = rect.x + rect.w;
  1574. verts->position.y = rect.y + rect.h;
  1575. verts->color = color;
  1576. verts->tex_coord.x = max_U;
  1577. verts->tex_coord.y = max_V;
  1578. verts++;
  1579. /* 3 */
  1580. verts->position.x = rect.x;
  1581. verts->position.y = rect.y + rect.h;
  1582. verts->color = color;
  1583. verts->tex_coord.x = min_U;
  1584. verts->tex_coord.y = max_V;
  1585. verts++;
  1586. /* Set texture address mode to clamp */
  1587. SDL_SetRenderTextureAddressMode(renderer, SDL_TEXTURE_ADDRESS_CLAMP, SDL_TEXTURE_ADDRESS_CLAMP);
  1588. /* Blit sprites as triangles onto the screen */
  1589. SDL_RenderGeometry(renderer, tface, vertices, 6, NULL, 0);
  1590. /* See if it's the same */
  1591. referenceSurface = SDLTest_ImageClampedSprite();
  1592. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1593. /* Make current */
  1594. SDL_RenderPresent(renderer);
  1595. /* Clean up. */
  1596. SDL_DestroyTexture(tface);
  1597. SDL_DestroySurface(referenceSurface);
  1598. referenceSurface = NULL;
  1599. return TEST_COMPLETED;
  1600. }
  1601. /**
  1602. * Tests geometry UV wrapping
  1603. */
  1604. static int SDLCALL render_testUVWrapping(void *arg)
  1605. {
  1606. SDL_Vertex vertices[6];
  1607. SDL_Vertex *verts = vertices;
  1608. SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f };
  1609. SDL_FRect rect;
  1610. float min_U = -0.5f;
  1611. float max_U = 1.5f;
  1612. float min_V = -0.5f;
  1613. float max_V = 1.5f;
  1614. SDL_Texture *tface;
  1615. SDL_Surface *referenceSurface = NULL;
  1616. /* Clear surface. */
  1617. clearScreen();
  1618. /* Create face surface. */
  1619. tface = loadTestFace();
  1620. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  1621. if (tface == NULL) {
  1622. return TEST_ABORTED;
  1623. }
  1624. rect.w = (float)tface->w * 2;
  1625. rect.h = (float)tface->h * 2;
  1626. rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2;
  1627. rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2;
  1628. /*
  1629. * 0--1
  1630. * | /|
  1631. * |/ |
  1632. * 3--2
  1633. *
  1634. * Draw sprite2 as triangles that can be recombined as rect by software renderer
  1635. */
  1636. /* 0 */
  1637. verts->position.x = rect.x;
  1638. verts->position.y = rect.y;
  1639. verts->color = color;
  1640. verts->tex_coord.x = min_U;
  1641. verts->tex_coord.y = min_V;
  1642. verts++;
  1643. /* 1 */
  1644. verts->position.x = rect.x + rect.w;
  1645. verts->position.y = rect.y;
  1646. verts->color = color;
  1647. verts->tex_coord.x = max_U;
  1648. verts->tex_coord.y = min_V;
  1649. verts++;
  1650. /* 2 */
  1651. verts->position.x = rect.x + rect.w;
  1652. verts->position.y = rect.y + rect.h;
  1653. verts->color = color;
  1654. verts->tex_coord.x = max_U;
  1655. verts->tex_coord.y = max_V;
  1656. verts++;
  1657. /* 0 */
  1658. verts->position.x = rect.x;
  1659. verts->position.y = rect.y;
  1660. verts->color = color;
  1661. verts->tex_coord.x = min_U;
  1662. verts->tex_coord.y = min_V;
  1663. verts++;
  1664. /* 2 */
  1665. verts->position.x = rect.x + rect.w;
  1666. verts->position.y = rect.y + rect.h;
  1667. verts->color = color;
  1668. verts->tex_coord.x = max_U;
  1669. verts->tex_coord.y = max_V;
  1670. verts++;
  1671. /* 3 */
  1672. verts->position.x = rect.x;
  1673. verts->position.y = rect.y + rect.h;
  1674. verts->color = color;
  1675. verts->tex_coord.x = min_U;
  1676. verts->tex_coord.y = max_V;
  1677. verts++;
  1678. /* Blit sprites as triangles onto the screen */
  1679. SDL_RenderGeometry(renderer, tface, vertices, 6, NULL, 0);
  1680. /* See if it's the same */
  1681. referenceSurface = SDLTest_ImageWrappingSprite();
  1682. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1683. /* Make current */
  1684. SDL_RenderPresent(renderer);
  1685. /* Clean up. */
  1686. SDL_DestroyTexture(tface);
  1687. SDL_DestroySurface(referenceSurface);
  1688. referenceSurface = NULL;
  1689. return TEST_COMPLETED;
  1690. }
  1691. /**
  1692. * Tests texture state changes
  1693. */
  1694. static int SDLCALL render_testTextureState(void *arg)
  1695. {
  1696. const Uint8 pixels[8] = {
  1697. 0x00, 0x00, 0x00, 0xFF,
  1698. 0xFF, 0xFF, 0xFF, 0xFF
  1699. };
  1700. const SDL_Color expected[] = {
  1701. /* Step 0: plain copy */
  1702. { 0x00, 0x00, 0x00, 0xFF },
  1703. { 0xFF, 0xFF, 0xFF, 0xFF },
  1704. /* Step 1: color mod to red */
  1705. { 0x00, 0x00, 0x00, 0xFF },
  1706. { 0xFF, 0x00, 0x00, 0xFF },
  1707. /* Step 2: alpha mod to 128 (cleared to green) */
  1708. { 0x00, 0x7F, 0x00, 0xFF },
  1709. { 0x80, 0xFF, 0x80, 0xFF },
  1710. /* Step 3: nearest stretch */
  1711. { 0xFF, 0xFF, 0xFF, 0xFF },
  1712. { 0x00, 0xFF, 0x00, 0xFF },
  1713. /* Step 4: linear stretch */
  1714. { 0x80, 0x80, 0x80, 0xFF },
  1715. { 0x00, 0xFF, 0x00, 0xFF },
  1716. };
  1717. SDL_Texture *texture;
  1718. SDL_Rect rect;
  1719. SDL_FRect dst;
  1720. int i;
  1721. /* Clear surface to green */
  1722. SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE);
  1723. SDL_RenderClear(renderer);
  1724. /* Create 2-pixel surface. */
  1725. texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 2, 1);
  1726. SDLTest_AssertCheck(texture != NULL, "Verify SDL_CreateTexture() result");
  1727. if (texture == NULL) {
  1728. return TEST_ABORTED;
  1729. }
  1730. SDL_UpdateTexture(texture, NULL, pixels, sizeof(pixels));
  1731. dst.x = 0.0f;
  1732. dst.y = 0.0f;
  1733. dst.w = 2.0f;
  1734. dst.h = 1.0f;
  1735. /* Step 0: plain copy */
  1736. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1737. dst.y += 1;
  1738. /* Step 1: color mod to red */
  1739. SDL_SetTextureColorMod(texture, 0xFF, 0x00, 0x00);
  1740. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1741. SDL_SetTextureColorMod(texture, 0xFF, 0xFF, 0xFF);
  1742. dst.y += 1;
  1743. /* Step 2: alpha mod to 128 */
  1744. SDL_SetTextureAlphaMod(texture, 0x80);
  1745. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1746. SDL_SetTextureAlphaMod(texture, 0xFF);
  1747. dst.y += 1;
  1748. /* Step 3: nearest stretch */
  1749. dst.w = 1;
  1750. SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  1751. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1752. dst.y += 1;
  1753. /* Step 4: linear stretch */
  1754. dst.w = 1;
  1755. SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_LINEAR);
  1756. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1757. dst.y += 1;
  1758. /* Verify results */
  1759. rect.x = 0;
  1760. rect.y = 0;
  1761. rect.w = 2;
  1762. rect.h = 1;
  1763. for (i = 0; i < SDL_arraysize(expected); ) {
  1764. const int MAX_DELTA = 1;
  1765. SDL_Color actual;
  1766. int deltaR, deltaG, deltaB, deltaA;
  1767. SDL_Surface *surface = SDL_RenderReadPixels(renderer, &rect);
  1768. SDL_ReadSurfacePixel(surface, 0, 0, &actual.r, &actual.g, &actual.b, &actual.a);
  1769. deltaR = (actual.r - expected[i].r);
  1770. deltaG = (actual.g - expected[i].g);
  1771. deltaB = (actual.b - expected[i].b);
  1772. deltaA = (actual.a - expected[i].a);
  1773. SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA &&
  1774. SDL_abs(deltaG) <= MAX_DELTA &&
  1775. SDL_abs(deltaB) <= MAX_DELTA &&
  1776. SDL_abs(deltaA) <= MAX_DELTA,
  1777. "Validate left pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2,
  1778. expected[i].r, expected[i].g, expected[i].b, expected[i].a,
  1779. actual.r, actual.g, actual.b, actual.a);
  1780. ++i;
  1781. SDL_ReadSurfacePixel(surface, 1, 0, &actual.r, &actual.g, &actual.b, &actual.a);
  1782. deltaR = (actual.r - expected[i].r);
  1783. deltaG = (actual.g - expected[i].g);
  1784. deltaB = (actual.b - expected[i].b);
  1785. deltaA = (actual.a - expected[i].a);
  1786. SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA &&
  1787. SDL_abs(deltaG) <= MAX_DELTA &&
  1788. SDL_abs(deltaB) <= MAX_DELTA &&
  1789. SDL_abs(deltaA) <= MAX_DELTA,
  1790. "Validate right pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2,
  1791. expected[i].r, expected[i].g, expected[i].b, expected[i].a,
  1792. actual.r, actual.g, actual.b, actual.a);
  1793. ++i;
  1794. SDL_DestroySurface(surface);
  1795. rect.y += 1;
  1796. }
  1797. /* Clean up. */
  1798. SDL_DestroyTexture(texture);
  1799. return TEST_COMPLETED;
  1800. }
  1801. /* ================= Test References ================== */
  1802. /* Render test cases */
  1803. static const SDLTest_TestCaseReference renderTestGetNumRenderDrivers = {
  1804. render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED
  1805. };
  1806. static const SDLTest_TestCaseReference renderTestPrimitives = {
  1807. render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED
  1808. };
  1809. static const SDLTest_TestCaseReference renderTestPrimitivesWithViewport = {
  1810. render_testPrimitivesWithViewport, "render_testPrimitivesWithViewport", "Tests rendering primitives within a viewport", TEST_ENABLED
  1811. };
  1812. static const SDLTest_TestCaseReference renderTestBlit = {
  1813. render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED
  1814. };
  1815. static const SDLTest_TestCaseReference renderTestBlitTiled = {
  1816. render_testBlitTiled, "render_testBlitTiled", "Tests tiled blitting", TEST_ENABLED
  1817. };
  1818. static const SDLTest_TestCaseReference renderTestBlit9Grid = {
  1819. render_testBlit9Grid, "render_testBlit9Grid", "Tests 9-grid blitting", TEST_ENABLED
  1820. };
  1821. static const SDLTest_TestCaseReference renderTestBlit9GridTiled = {
  1822. render_testBlit9GridTiled, "render_testBlit9GridTiled", "Tests tiled 9-grid blitting", TEST_ENABLED
  1823. };
  1824. static const SDLTest_TestCaseReference renderTestBlitColor = {
  1825. render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED
  1826. };
  1827. static const SDLTest_TestCaseReference renderTestBlendModes = {
  1828. render_testBlendModes, "render_testBlendModes", "Tests rendering blend modes", TEST_ENABLED
  1829. };
  1830. static const SDLTest_TestCaseReference renderTestViewport = {
  1831. render_testViewport, "render_testViewport", "Tests viewport", TEST_ENABLED
  1832. };
  1833. static const SDLTest_TestCaseReference renderTestClipRect = {
  1834. render_testClipRect, "render_testClipRect", "Tests clip rect", TEST_ENABLED
  1835. };
  1836. static const SDLTest_TestCaseReference renderTestLogicalSize = {
  1837. render_testLogicalSize, "render_testLogicalSize", "Tests logical size", TEST_ENABLED
  1838. };
  1839. static const SDLTest_TestCaseReference renderTestUVClamping = {
  1840. render_testUVClamping, "render_testUVClamping", "Tests geometry UV clamping", TEST_ENABLED
  1841. };
  1842. static const SDLTest_TestCaseReference renderTestUVWrapping = {
  1843. render_testUVWrapping, "render_testUVWrapping", "Tests geometry UV wrapping", TEST_ENABLED
  1844. };
  1845. static const SDLTest_TestCaseReference renderTestTextureState = {
  1846. render_testTextureState, "render_testTextureState", "Tests texture state changes", TEST_ENABLED
  1847. };
  1848. static const SDLTest_TestCaseReference renderTestGetSetTextureScaleMode = {
  1849. render_testGetSetTextureScaleMode, "render_testGetSetTextureScaleMode", "Tests setting/getting texture scale mode", TEST_ENABLED
  1850. };
  1851. static const SDLTest_TestCaseReference renderTestRGBSurfaceNoAlpha = {
  1852. render_testRGBSurfaceNoAlpha, "render_testRGBSurfaceNoAlpha", "Tests RGB surface with no alpha using software renderer", TEST_ENABLED
  1853. };
  1854. /* Sequence of Render test cases */
  1855. static const SDLTest_TestCaseReference *renderTests[] = {
  1856. &renderTestGetNumRenderDrivers,
  1857. &renderTestPrimitives,
  1858. &renderTestPrimitivesWithViewport,
  1859. &renderTestBlit,
  1860. &renderTestBlitTiled,
  1861. &renderTestBlit9Grid,
  1862. &renderTestBlit9GridTiled,
  1863. &renderTestBlitColor,
  1864. &renderTestBlendModes,
  1865. &renderTestViewport,
  1866. &renderTestClipRect,
  1867. &renderTestLogicalSize,
  1868. &renderTestUVClamping,
  1869. &renderTestUVWrapping,
  1870. &renderTestTextureState,
  1871. &renderTestGetSetTextureScaleMode,
  1872. &renderTestRGBSurfaceNoAlpha,
  1873. NULL
  1874. };
  1875. /* Render test suite (global) */
  1876. SDLTest_TestSuiteReference renderTestSuite = {
  1877. "Render",
  1878. InitCreateRenderer,
  1879. renderTests,
  1880. CleanupDestroyRenderer
  1881. };