upgrade SDL to version 2.0.8
[platform/upstream/SDL.git] / test / testsprite2.c
index 8067990..5bb654d 100755 (executable)
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
+  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -65,22 +65,11 @@ LoadSprite(const char *file)
     /* Load the sprite image */
     temp = SDL_LoadBMP(file);
     if (temp == NULL) {
-        SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
+        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
         return (-1);
     }
     sprite_w = temp->w;
     sprite_h = temp->h;
-    SDL_SetClipRect(temp, NULL);
-    SDL_Rect clipRect, full_clipRect;
-    SDL_GetClipRect(temp,&clipRect);
-    full_clipRect.x = 0;
-    full_clipRect.y = 0;
-    full_clipRect.w = sprite_w;
-    full_clipRect.h = sprite_h;
-    if(clipRect.x != full_clipRect.x || clipRect.y != full_clipRect.y || clipRect.w != full_clipRect.w || clipRect.h != full_clipRect.h)
-    {
-       SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION ,"Couldn't set cliprect!\n");
-    }
 
     /* Set transparent pixel as the pixel at (0,0) */
     if (temp->format->palette) {
@@ -107,17 +96,16 @@ LoadSprite(const char *file)
         SDL_Renderer *renderer = state->renderers[i];
         sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
         if (!sprites[i]) {
-            SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
+            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
             SDL_FreeSurface(temp);
             return (-1);
         }
-        SDL_SetTextureBlendMode(sprites[i], blendMode);
-       SDL_BlendMode  retblendMode;
-       SDL_GetTextureBlendMode(sprites[i],&retblendMode);
-       if(blendMode != retblendMode)
-       {
-               SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Texture blend fails!\n");
-       }
+        if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
+            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
+            SDL_FreeSurface(temp);
+            SDL_DestroyTexture(sprites[i]);
+            return (-1);
+        }
     }
     SDL_FreeSurface(temp);
 
@@ -180,17 +168,6 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
     SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
     SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
 
-    SDL_Rect rect[2];
-    rect[0].x = 0;
-    rect[0].y = 0;
-    rect[0].w = 100;
-    rect[0].h = 100;
-    rect[1].x = 200;
-    rect[1].y = 200;
-    rect[1].w = 100;
-    rect[1].h = 100;
-    SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
-    SDL_RenderDrawRects(renderer,rect, 2);
 
     /* Test fill and copy */
     SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
@@ -296,7 +273,7 @@ loop()
 #endif
 }
 int
-SDL_main(int argc, char *argv[])
+main(int argc, char *argv[])
 {
     int i;
     Uint32 then, now, frames;
@@ -334,6 +311,9 @@ SDL_main(int argc, char *argv[])
                     } else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
                         blendMode = SDL_BLENDMODE_MOD;
                         consumed = 2;
+                    } else if (SDL_strcasecmp(argv[i + 1], "sub") == 0) {
+                        blendMode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT, SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT);
+                        consumed = 2;
                     }
                 }
             } else if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
@@ -371,7 +351,7 @@ SDL_main(int argc, char *argv[])
     sprites =
         (SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
     if (!sprites) {
-        SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
+        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
         quit(2);
     }
     for (i = 0; i < state->num_windows; ++i) {
@@ -383,34 +363,15 @@ SDL_main(int argc, char *argv[])
         quit(2);
     }
 
-    if(SDL_RenderTargetSupported(state->renderers[0]) == SDL_FALSE)
-    {
-       SDLTest_Log(SDL_LOG_CATEGORY_APPLICATION, "SDL_RenderTarget is not support!\n");
-    }
-    else
-    {
-       SDL_Texture* renderTargetTexture = SDL_GetRenderTarget(state->renderers[0]);
-       if(renderTargetTexture == NULL)
-       {
-               SDLTest_Log(SDL_LOG_CATEGORY_APPLICATION, "renderTargetTexture is NULL!\n");
-       }
-    }
 
-    int render_width, render_height;
-    SDL_RenderGetLogicalSize(state->renderers[0], &render_width, &render_height);
-    SDLTest_Log(SDL_LOG_CATEGORY_APPLICATION, "Render Logical size is %d * %d", render_width, render_height);
 
-    if(SDL_RenderIsClipEnabled(state->renderers[0]) == SDL_FALSE)
-    {
-       SDLTest_Log(SDL_LOG_CATEGORY_APPLICATION, "SDL_RenderIsClipEnabled is not support!\n");
-    }
 
 
     /* Allocate memory for the sprite info */
     positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
     velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
     if (!positions || !velocities) {
-        SDLTest_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
+        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
         quit(2);
     }