Fixed 2D video on Android
authorSam Lantinga <slouken@libsdl.org>
Tue, 04 Jan 2011 20:36:39 -0800
changeset 49600ab2492f2e17
parent 4959 16fec41375a6
child 4961 c92950635837
Fixed 2D video on Android
There was a dummy renderer left in there which was overriding the OpenGL ES renderer.
Makefile.android
include/SDL_config_android.h
src/video/android/SDL_androidrender.c
src/video/android/SDL_androidrender.h
src/video/android/SDL_androidvideo.c
     1.1 --- a/Makefile.android	Tue Jan 04 20:30:54 2011 -0800
     1.2 +++ b/Makefile.android	Tue Jan 04 20:36:39 2011 -0800
     1.3 @@ -28,6 +28,7 @@
     1.4  	src/video/*.c \
     1.5  	src/power/*.c \
     1.6  	src/audio/android/*.c \
     1.7 +	src/audio/dummy/*.c \
     1.8  	src/video/android/*.c \
     1.9  	src/joystick/android/*.c \
    1.10  	src/haptic/dummy/*.c \
     2.1 --- a/include/SDL_config_android.h	Tue Jan 04 20:30:54 2011 -0800
     2.2 +++ b/include/SDL_config_android.h	Tue Jan 04 20:36:39 2011 -0800
     2.3 @@ -55,8 +55,6 @@
     2.4  #define HAVE_SIGNAL_H	1
     2.5  
     2.6  /* C library functions */
     2.7 -#define HAVE_ATAN	1
     2.8 -#define HAVE_ATAN2	1
     2.9  #define HAVE_MALLOC	1
    2.10  #define HAVE_CALLOC	1
    2.11  #define HAVE_REALLOC	1
    2.12 @@ -95,6 +93,9 @@
    2.13  #define HAVE_SSCANF	1
    2.14  #define HAVE_SNPRINTF	1
    2.15  #define HAVE_VSNPRINTF	1
    2.16 +#define HAVE_M_PI	1
    2.17 +#define HAVE_ATAN	1
    2.18 +#define HAVE_ATAN2	1
    2.19  #define HAVE_CEIL	1
    2.20  #define HAVE_COPYSIGN	1
    2.21  #define HAVE_COS	1
    2.22 @@ -117,15 +118,16 @@
    2.23  typedef unsigned int size_t;
    2.24  //typedef unsigned long uintptr_t;
    2.25  
    2.26 +/* Enable various audio drivers */
    2.27  #define SDL_AUDIO_DRIVER_ANDROID	1
    2.28 +#define SDL_AUDIO_DRIVER_DUMMY	1
    2.29  
    2.30 -#define SDL_CDROM_DISABLED 1
    2.31 +/* Enable various input drivers */
    2.32 +#define SDL_JOYSTICK_ANDROID	1
    2.33 +#define SDL_HAPTIC_DUMMY	1
    2.34  
    2.35 -#define SDL_HAPTIC_DISABLED 1
    2.36 -
    2.37 -#define SDL_JOYSTICK_ANDROID 1
    2.38 -
    2.39 -#define SDL_LOADSO_DISABLED 1
    2.40 +/* Enable various shared object loading systems */
    2.41 +#define SDL_LOADSO_DUMMY	1
    2.42  
    2.43  /* Enable various threading systems */
    2.44  #define SDL_THREAD_PTHREAD	1
    2.45 @@ -134,14 +136,11 @@
    2.46  /* Enable various timer systems */
    2.47  #define SDL_TIMER_UNIX	1
    2.48  
    2.49 +/* Enable various video drivers */
    2.50  #define SDL_VIDEO_DRIVER_ANDROID 1
    2.51  
    2.52 -#define HAVE_STDIO_H 1
    2.53 -#define HAVE_SYS_TYPES_H 1
    2.54 -
    2.55 -#define HAVE_M_PI 1
    2.56 -
    2.57 -#define SDL_VIDEO_RENDER_OGL_ES 1
    2.58 +/* Enable OpenGL ES */
    2.59 +#define SDL_VIDEO_OPENGL_ES	1
    2.60 +#define SDL_VIDEO_RENDER_OGL_ES	1
    2.61  
    2.62  #endif /* _SDL_config_minimal_h */
    2.63 -
     3.1 --- a/src/video/android/SDL_androidrender.c	Tue Jan 04 20:30:54 2011 -0800
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,344 +0,0 @@
     3.4 -/*
     3.5 -    SDL - Simple DirectMedia Layer
     3.6 -    Copyright (C) 1997-2010 Sam Lantinga
     3.7 -
     3.8 -    This library is free software; you can redistribute it and/or
     3.9 -    modify it under the terms of the GNU Lesser General Public
    3.10 -    License as published by the Free Software Foundation; either
    3.11 -    version 2.1 of the License, or (at your option) any later version.
    3.12 -
    3.13 -    This library is distributed in the hope that it will be useful,
    3.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 -    Lesser General Public License for more details.
    3.17 -
    3.18 -    You should have received a copy of the GNU Lesser General Public
    3.19 -    License along with this library; if not, write to the Free Software
    3.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 -
    3.22 -    Sam Lantinga
    3.23 -    slouken@libsdl.org
    3.24 -*/
    3.25 -#include "SDL_config.h"
    3.26 -
    3.27 -#include "SDL_video.h"
    3.28 -#include "../SDL_sysvideo.h"
    3.29 -#include "../SDL_yuv_sw_c.h"
    3.30 -#include "../SDL_renderer_sw.h"
    3.31 -
    3.32 -
    3.33 -/* SDL surface based renderer implementation */
    3.34 -
    3.35 -static SDL_Renderer *Android_CreateRenderer(SDL_Window * window,
    3.36 -                                              Uint32 flags);
    3.37 -static int Android_RenderDrawPoints(SDL_Renderer * renderer,
    3.38 -                                      const SDL_Point * points, int count);
    3.39 -static int Android_RenderDrawLines(SDL_Renderer * renderer,
    3.40 -                                     const SDL_Point * points, int count);
    3.41 -static int Android_RenderDrawRects(SDL_Renderer * renderer,
    3.42 -                                     const SDL_Rect ** rects, int count);
    3.43 -static int Android_RenderFillRects(SDL_Renderer * renderer,
    3.44 -                                     const SDL_Rect ** rects, int count);
    3.45 -static int Android_RenderCopy(SDL_Renderer * renderer,
    3.46 -                                SDL_Texture * texture,
    3.47 -                                const SDL_Rect * srcrect,
    3.48 -                                const SDL_Rect * dstrect);
    3.49 -static int Android_RenderReadPixels(SDL_Renderer * renderer,
    3.50 -                                      const SDL_Rect * rect,
    3.51 -                                      Uint32 format,
    3.52 -                                      void * pixels, int pitch);
    3.53 -static int Android_RenderWritePixels(SDL_Renderer * renderer,
    3.54 -                                       const SDL_Rect * rect,
    3.55 -                                       Uint32 format,
    3.56 -                                       const void * pixels, int pitch);
    3.57 -static void Android_RenderPresent(SDL_Renderer * renderer);
    3.58 -static void Android_DestroyRenderer(SDL_Renderer * renderer);
    3.59 -
    3.60 -
    3.61 -SDL_RenderDriver Android_RenderDriver = {
    3.62 -    Android_CreateRenderer,
    3.63 -    {
    3.64 -     "dummy",
    3.65 -     (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
    3.66 -      SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
    3.67 -      SDL_RENDERER_PRESENTDISCARD),
    3.68 -     }
    3.69 -};
    3.70 -
    3.71 -typedef struct
    3.72 -{
    3.73 -    int current_screen;
    3.74 -    SDL_Surface *screens[3];
    3.75 -} Android_RenderData;
    3.76 -
    3.77 -SDL_Renderer *
    3.78 -Android_CreateRenderer(SDL_Window * window, Uint32 flags)
    3.79 -{
    3.80 -    SDL_VideoDisplay *display = window->display;
    3.81 -    SDL_DisplayMode *displayMode = &display->current_mode;
    3.82 -    SDL_Renderer *renderer;
    3.83 -    Android_RenderData *data;
    3.84 -    int i, n;
    3.85 -    int bpp;
    3.86 -    Uint32 Rmask, Gmask, Bmask, Amask;
    3.87 -
    3.88 -    if (!SDL_PixelFormatEnumToMasks
    3.89 -        (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
    3.90 -        SDL_SetError("Unknown display format");
    3.91 -        return NULL;
    3.92 -    }
    3.93 -
    3.94 -    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
    3.95 -    if (!renderer) {
    3.96 -        SDL_OutOfMemory();
    3.97 -        return NULL;
    3.98 -    }
    3.99 -
   3.100 -    data = (Android_RenderData *) SDL_malloc(sizeof(*data));
   3.101 -    if (!data) {
   3.102 -        Android_DestroyRenderer(renderer);
   3.103 -        SDL_OutOfMemory();
   3.104 -        return NULL;
   3.105 -    }
   3.106 -    SDL_zerop(data);
   3.107 -
   3.108 -    renderer->RenderDrawPoints = Android_RenderDrawPoints;
   3.109 -    renderer->RenderDrawLines = Android_RenderDrawLines;
   3.110 -    renderer->RenderDrawRects = Android_RenderDrawRects;
   3.111 -    renderer->RenderFillRects = Android_RenderFillRects;
   3.112 -    renderer->RenderCopy = Android_RenderCopy;
   3.113 -    renderer->RenderReadPixels = Android_RenderReadPixels;
   3.114 -    renderer->RenderWritePixels = Android_RenderWritePixels;
   3.115 -    renderer->RenderPresent = Android_RenderPresent;
   3.116 -    renderer->DestroyRenderer = Android_DestroyRenderer;
   3.117 -    renderer->info.name = Android_RenderDriver.info.name;
   3.118 -    renderer->info.flags = 0;
   3.119 -    renderer->window = window;
   3.120 -    renderer->driverdata = data;
   3.121 -    Setup_SoftwareRenderer(renderer);
   3.122 -
   3.123 -    if (flags & SDL_RENDERER_PRESENTFLIP2) {
   3.124 -        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
   3.125 -        n = 2;
   3.126 -    } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
   3.127 -        renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
   3.128 -        n = 3;
   3.129 -    } else {
   3.130 -        renderer->info.flags |= SDL_RENDERER_PRESENTCOPY;
   3.131 -        n = 1;
   3.132 -    }
   3.133 -    for (i = 0; i < n; ++i) {
   3.134 -        data->screens[i] =
   3.135 -            SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
   3.136 -                                 Bmask, Amask);
   3.137 -        if (!data->screens[i]) {
   3.138 -            Android_DestroyRenderer(renderer);
   3.139 -            return NULL;
   3.140 -        }
   3.141 -        SDL_SetSurfacePalette(data->screens[i], display->palette);
   3.142 -    }
   3.143 -    data->current_screen = 0;
   3.144 -
   3.145 -    return renderer;
   3.146 -}
   3.147 -
   3.148 -static int
   3.149 -Android_RenderDrawPoints(SDL_Renderer * renderer,
   3.150 -                           const SDL_Point * points, int count)
   3.151 -{
   3.152 -    Android_RenderData *data =
   3.153 -        (Android_RenderData *) renderer->driverdata;
   3.154 -    SDL_Surface *target = data->screens[data->current_screen];
   3.155 -
   3.156 -    if (renderer->blendMode == SDL_BLENDMODE_NONE ||
   3.157 -        renderer->blendMode == SDL_BLENDMODE_MASK) {
   3.158 -        Uint32 color = SDL_MapRGBA(target->format,
   3.159 -                                   renderer->r, renderer->g, renderer->b,
   3.160 -                                   renderer->a);
   3.161 -
   3.162 -        return SDL_DrawPoints(target, points, count, color);
   3.163 -    } else {
   3.164 -        return SDL_BlendPoints(target, points, count, renderer->blendMode,
   3.165 -                               renderer->r, renderer->g, renderer->b,
   3.166 -                               renderer->a);
   3.167 -    }
   3.168 -}
   3.169 -
   3.170 -static int
   3.171 -Android_RenderDrawLines(SDL_Renderer * renderer,
   3.172 -                          const SDL_Point * points, int count)
   3.173 -{
   3.174 -    Android_RenderData *data =
   3.175 -        (Android_RenderData *) renderer->driverdata;
   3.176 -    SDL_Surface *target = data->screens[data->current_screen];
   3.177 -
   3.178 -    if (renderer->blendMode == SDL_BLENDMODE_NONE ||
   3.179 -        renderer->blendMode == SDL_BLENDMODE_MASK) {
   3.180 -        Uint32 color = SDL_MapRGBA(target->format,
   3.181 -                                   renderer->r, renderer->g, renderer->b,
   3.182 -                                   renderer->a);
   3.183 -
   3.184 -        return SDL_DrawLines(target, points, count, color);
   3.185 -    } else {
   3.186 -        return SDL_BlendLines(target, points, count, renderer->blendMode,
   3.187 -                              renderer->r, renderer->g, renderer->b,
   3.188 -                              renderer->a);
   3.189 -    }
   3.190 -}
   3.191 -
   3.192 -static int
   3.193 -Android_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
   3.194 -                          int count)
   3.195 -{
   3.196 -    Android_RenderData *data =
   3.197 -        (Android_RenderData *) renderer->driverdata;
   3.198 -    SDL_Surface *target = data->screens[data->current_screen];
   3.199 -
   3.200 -    if (renderer->blendMode == SDL_BLENDMODE_NONE ||
   3.201 -        renderer->blendMode == SDL_BLENDMODE_MASK) {
   3.202 -        Uint32 color = SDL_MapRGBA(target->format,
   3.203 -                                   renderer->r, renderer->g, renderer->b,
   3.204 -                                   renderer->a);
   3.205 -
   3.206 -        return SDL_DrawRects(target, rects, count, color);
   3.207 -    } else {
   3.208 -        return SDL_BlendRects(target, rects, count,
   3.209 -                              renderer->blendMode,
   3.210 -                              renderer->r, renderer->g, renderer->b,
   3.211 -                              renderer->a);
   3.212 -    }
   3.213 -}
   3.214 -
   3.215 -static int
   3.216 -Android_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
   3.217 -                          int count)
   3.218 -{
   3.219 -    Android_RenderData *data =
   3.220 -        (Android_RenderData *) renderer->driverdata;
   3.221 -    SDL_Surface *target = data->screens[data->current_screen];
   3.222 -
   3.223 -    if (renderer->blendMode == SDL_BLENDMODE_NONE ||
   3.224 -        renderer->blendMode == SDL_BLENDMODE_MASK) {
   3.225 -        Uint32 color = SDL_MapRGBA(target->format,
   3.226 -                                   renderer->r, renderer->g, renderer->b,
   3.227 -                                   renderer->a);
   3.228 -
   3.229 -        return SDL_FillRects(target, rects, count, color);
   3.230 -    } else {
   3.231 -        return SDL_BlendFillRects(target, rects, count,
   3.232 -                                  renderer->blendMode,
   3.233 -                                  renderer->r, renderer->g, renderer->b,
   3.234 -                                  renderer->a);
   3.235 -    }
   3.236 -}
   3.237 -
   3.238 -static int
   3.239 -Android_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   3.240 -                     const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   3.241 -{
   3.242 -    Android_RenderData *data =
   3.243 -        (Android_RenderData *) renderer->driverdata;
   3.244 -    SDL_Window *window = renderer->window;
   3.245 -    SDL_VideoDisplay *display = window->display;
   3.246 -
   3.247 -    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   3.248 -        SDL_Surface *target = data->screens[data->current_screen];
   3.249 -        void *pixels =
   3.250 -            (Uint8 *) target->pixels + dstrect->y * target->pitch +
   3.251 -            dstrect->x * target->format->BytesPerPixel;
   3.252 -        return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
   3.253 -                                   srcrect, display->current_mode.format,
   3.254 -                                   dstrect->w, dstrect->h, pixels,
   3.255 -                                   target->pitch);
   3.256 -    } else {
   3.257 -        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   3.258 -        SDL_Surface *target = data->screens[data->current_screen];
   3.259 -        SDL_Rect real_srcrect = *srcrect;
   3.260 -        SDL_Rect real_dstrect = *dstrect;
   3.261 -
   3.262 -        return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect);
   3.263 -    }
   3.264 -}
   3.265 -
   3.266 -static int
   3.267 -Android_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   3.268 -                           Uint32 format, void * pixels, int pitch)
   3.269 -{
   3.270 -    Android_RenderData *data =
   3.271 -        (Android_RenderData *) renderer->driverdata;
   3.272 -    SDL_Window *window = renderer->window;
   3.273 -    SDL_VideoDisplay *display = window->display;
   3.274 -    SDL_Surface *screen = data->screens[data->current_screen];
   3.275 -    Uint32 screen_format = display->current_mode.format;
   3.276 -    Uint8 *screen_pixels = (Uint8 *) screen->pixels +
   3.277 -                            rect->y * screen->pitch +
   3.278 -                            rect->x * screen->format->BytesPerPixel;
   3.279 -    int screen_pitch = screen->pitch;
   3.280 -
   3.281 -    return SDL_ConvertPixels(rect->w, rect->h,
   3.282 -                             screen_format, screen_pixels, screen_pitch,
   3.283 -                             format, pixels, pitch);
   3.284 -}
   3.285 -
   3.286 -static int
   3.287 -Android_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   3.288 -                            Uint32 format, const void * pixels, int pitch)
   3.289 -{
   3.290 -    Android_RenderData *data =
   3.291 -        (Android_RenderData *) renderer->driverdata;
   3.292 -    SDL_Window *window = renderer->window;
   3.293 -    SDL_VideoDisplay *display = window->display;
   3.294 -    SDL_Surface *screen = data->screens[data->current_screen];
   3.295 -    Uint32 screen_format = display->current_mode.format;
   3.296 -    Uint8 *screen_pixels = (Uint8 *) screen->pixels +
   3.297 -                            rect->y * screen->pitch +
   3.298 -                            rect->x * screen->format->BytesPerPixel;
   3.299 -    int screen_pitch = screen->pitch;
   3.300 -
   3.301 -    return SDL_ConvertPixels(rect->w, rect->h,
   3.302 -                             format, pixels, pitch,
   3.303 -                             screen_format, screen_pixels, screen_pitch);
   3.304 -}
   3.305 -
   3.306 -static void
   3.307 -Android_RenderPresent(SDL_Renderer * renderer)
   3.308 -{
   3.309 -    static int frame_number;
   3.310 -    Android_RenderData *data =
   3.311 -        (Android_RenderData *) renderer->driverdata;
   3.312 -
   3.313 -    /* Send the data to the display */
   3.314 -    if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
   3.315 -        char file[128];
   3.316 -        SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
   3.317 -                     renderer->window->id, ++frame_number);
   3.318 -        SDL_SaveBMP(data->screens[data->current_screen], file);
   3.319 -    }
   3.320 -
   3.321 -    /* Update the flipping chain, if any */
   3.322 -    if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
   3.323 -        data->current_screen = (data->current_screen + 1) % 2;
   3.324 -    } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) {
   3.325 -        data->current_screen = (data->current_screen + 1) % 3;
   3.326 -    }
   3.327 -}
   3.328 -
   3.329 -static void
   3.330 -Android_DestroyRenderer(SDL_Renderer * renderer)
   3.331 -{
   3.332 -    Android_RenderData *data =
   3.333 -        (Android_RenderData *) renderer->driverdata;
   3.334 -    int i;
   3.335 -
   3.336 -    if (data) {
   3.337 -        for (i = 0; i < SDL_arraysize(data->screens); ++i) {
   3.338 -            if (data->screens[i]) {
   3.339 -                SDL_FreeSurface(data->screens[i]);
   3.340 -            }
   3.341 -        }
   3.342 -        SDL_free(data);
   3.343 -    }
   3.344 -    SDL_free(renderer);
   3.345 -}
   3.346 -
   3.347 -/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/android/SDL_androidrender.h	Tue Jan 04 20:30:54 2011 -0800
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,28 +0,0 @@
     4.4 -/*
     4.5 -    SDL - Simple DirectMedia Layer
     4.6 -    Copyright (C) 1997-2010 Sam Lantinga
     4.7 -
     4.8 -    This library is free software; you can redistribute it and/or
     4.9 -    modify it under the terms of the GNU Lesser General Public
    4.10 -    License as published by the Free Software Foundation; either
    4.11 -    version 2.1 of the License, or (at your option) any later version.
    4.12 -
    4.13 -    This library is distributed in the hope that it will be useful,
    4.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 -    Lesser General Public License for more details.
    4.17 -
    4.18 -    You should have received a copy of the GNU Lesser General Public
    4.19 -    License along with this library; if not, write to the Free Software
    4.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 -
    4.22 -    Sam Lantinga
    4.23 -    slouken@libsdl.org
    4.24 -*/
    4.25 -#include "SDL_config.h"
    4.26 -
    4.27 -/* SDL surface based renderer implementation */
    4.28 -
    4.29 -extern SDL_RenderDriver Android_RenderDriver;
    4.30 -
    4.31 -/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/video/android/SDL_androidvideo.c	Tue Jan 04 20:30:54 2011 -0800
     5.2 +++ b/src/video/android/SDL_androidvideo.c	Tue Jan 04 20:36:39 2011 -0800
     5.3 @@ -32,7 +32,6 @@
     5.4  
     5.5  #include "SDL_androidvideo.h"
     5.6  #include "SDL_androidevents.h"
     5.7 -#include "SDL_androidrender.h"
     5.8  
     5.9  #define ANDROID_VID_DRIVER_NAME "Android"
    5.10  
    5.11 @@ -133,7 +132,6 @@
    5.12      if (SDL_AddBasicVideoDisplay(&mode) < 0) {
    5.13          return -1;
    5.14      }
    5.15 -    SDL_AddRenderDriver(&_this->displays[0], &Android_RenderDriver);
    5.16  
    5.17      SDL_zero(mode);
    5.18      SDL_AddDisplayMode(&_this->displays[0], &mode);