src/video/android/SDL_androidvideo.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 04 Jan 2011 20:36:39 -0800
changeset 4960 0ab2492f2e17
parent 4716 f2c2a33a1a38
child 4963 604077962776
permissions -rw-r--r--
Fixed 2D video on Android
There was a dummy renderer left in there which was overriding the OpenGL ES renderer.
paul@4701
     1
/*
paul@4701
     2
    SDL - Simple DirectMedia Layer
paul@4701
     3
    Copyright (C) 1997-2010 Sam Lantinga
paul@4701
     4
paul@4701
     5
    This library is free software; you can redistribute it and/or
paul@4701
     6
    modify it under the terms of the GNU Lesser General Public
paul@4701
     7
    License as published by the Free Software Foundation; either
paul@4701
     8
    version 2.1 of the License, or (at your option) any later version.
paul@4701
     9
paul@4701
    10
    This library is distributed in the hope that it will be useful,
paul@4701
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@4701
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
paul@4701
    13
    Lesser General Public License for more details.
paul@4701
    14
paul@4701
    15
    You should have received a copy of the GNU Lesser General Public
paul@4701
    16
    License along with this library; if not, write to the Free Software
paul@4701
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
paul@4701
    18
paul@4701
    19
    Sam Lantinga
paul@4701
    20
    slouken@libsdl.org
paul@4701
    21
*/
paul@4701
    22
#include "SDL_config.h"
paul@4701
    23
paul@4701
    24
/* Android SDL video driver implementation
paul@4701
    25
*/
paul@4701
    26
paul@4701
    27
#include "SDL_video.h"
paul@4701
    28
#include "SDL_mouse.h"
paul@4701
    29
#include "../SDL_sysvideo.h"
paul@4701
    30
#include "../SDL_pixels_c.h"
paul@4701
    31
#include "../../events/SDL_events_c.h"
paul@4701
    32
paul@4701
    33
#include "SDL_androidvideo.h"
paul@4703
    34
#include "SDL_androidevents.h"
paul@4701
    35
paul@4701
    36
#define ANDROID_VID_DRIVER_NAME "Android"
paul@4701
    37
paul@4701
    38
/* Initialization/Query functions */
paul@4701
    39
static int Android_VideoInit(_THIS);
paul@4701
    40
static int Android_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
paul@4701
    41
static void Android_VideoQuit(_THIS);
paul@4701
    42
paul@4701
    43
/* GL functions (SDL_androidgl.c) */
paul@4701
    44
extern int Android_GL_LoadLibrary(_THIS, const char *path);
paul@4701
    45
extern void *Android_GL_GetProcAddress(_THIS, const char *proc);
paul@4701
    46
extern void Android_GL_UnloadLibrary(_THIS);
paul@4701
    47
//extern int *Android_GL_GetVisual(_THIS, Display * display, int screen);
paul@4701
    48
extern SDL_GLContext Android_GL_CreateContext(_THIS, SDL_Window * window);
paul@4701
    49
extern int Android_GL_MakeCurrent(_THIS, SDL_Window * window,
paul@4701
    50
                              SDL_GLContext context);
paul@4701
    51
extern int Android_GL_SetSwapInterval(_THIS, int interval);
paul@4701
    52
extern int Android_GL_GetSwapInterval(_THIS);
paul@4701
    53
extern void Android_GL_SwapWindow(_THIS, SDL_Window * window);
paul@4701
    54
extern void Android_GL_DeleteContext(_THIS, SDL_GLContext context);
paul@4701
    55
paul@4701
    56
/* Android driver bootstrap functions */
paul@4701
    57
paul@4701
    58
paul@4716
    59
//These are filled in with real values in Android_SetScreenResolution on 
paul@4716
    60
//init (before SDL_Main())
paul@4716
    61
static int iScreenWidth = 320;
paul@4716
    62
static int iScreenHeight = 240;
paul@4716
    63
paul@4716
    64
paul@4701
    65
static int
paul@4701
    66
Android_Available(void)
paul@4701
    67
{
paul@4701
    68
    return 1;
paul@4701
    69
}
paul@4701
    70
paul@4701
    71
static void
paul@4701
    72
Android_DeleteDevice(SDL_VideoDevice * device)
paul@4701
    73
{
paul@4701
    74
    SDL_free(device);
paul@4701
    75
}
paul@4701
    76
paul@4701
    77
static SDL_VideoDevice *
paul@4701
    78
Android_CreateDevice(int devindex)
paul@4701
    79
{
paul@4701
    80
    printf("Creating video device\n");
paul@4701
    81
    SDL_VideoDevice *device;
paul@4701
    82
paul@4701
    83
    /* Initialize all variables that we clean on shutdown */
paul@4701
    84
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
paul@4701
    85
    if (!device) {
paul@4701
    86
        SDL_OutOfMemory();
paul@4701
    87
        if (device) {
paul@4701
    88
            SDL_free(device);
paul@4701
    89
        }
paul@4701
    90
        return (0);
paul@4701
    91
    }
paul@4701
    92
paul@4701
    93
    /* Set the function pointers */
paul@4701
    94
    device->VideoInit = Android_VideoInit;
paul@4701
    95
    device->VideoQuit = Android_VideoQuit;
paul@4701
    96
    device->SetDisplayMode = Android_SetDisplayMode;
paul@4701
    97
    device->PumpEvents = Android_PumpEvents;
paul@4701
    98
   
paul@4701
    99
    device->free = Android_DeleteDevice;
paul@4701
   100
paul@4701
   101
    /* GL pointers */
paul@4701
   102
    device->GL_LoadLibrary = Android_GL_LoadLibrary;
paul@4701
   103
    device->GL_GetProcAddress = Android_GL_GetProcAddress;
paul@4701
   104
    device->GL_UnloadLibrary = Android_GL_UnloadLibrary;
paul@4701
   105
    device->GL_CreateContext = Android_GL_CreateContext;
paul@4701
   106
    device->GL_MakeCurrent = Android_GL_MakeCurrent;
paul@4701
   107
    device->GL_SetSwapInterval = Android_GL_SetSwapInterval;
paul@4701
   108
    device->GL_GetSwapInterval = Android_GL_GetSwapInterval;
paul@4701
   109
    device->GL_SwapWindow = Android_GL_SwapWindow;
paul@4701
   110
    device->GL_DeleteContext = Android_GL_DeleteContext;
paul@4701
   111
paul@4701
   112
    return device;
paul@4701
   113
}
paul@4701
   114
paul@4701
   115
VideoBootStrap Android_bootstrap = {
paul@4701
   116
    ANDROID_VID_DRIVER_NAME, "SDL Android video driver",
paul@4701
   117
    Android_Available, Android_CreateDevice
paul@4701
   118
};
paul@4701
   119
paul@4701
   120
paul@4701
   121
int
paul@4701
   122
Android_VideoInit(_THIS)
paul@4701
   123
{
paul@4701
   124
    SDL_DisplayMode mode;
paul@4701
   125
paul@4701
   126
    /* Use a fake 32-bpp desktop mode */
paul@4701
   127
    mode.format = SDL_PIXELFORMAT_RGB888;
paul@4716
   128
    mode.w = iScreenWidth;
paul@4716
   129
    mode.h = iScreenHeight;
paul@4701
   130
    mode.refresh_rate = 0;
paul@4701
   131
    mode.driverdata = NULL;
paul@4701
   132
    if (SDL_AddBasicVideoDisplay(&mode) < 0) {
paul@4701
   133
        return -1;
paul@4701
   134
    }
paul@4701
   135
paul@4701
   136
    SDL_zero(mode);
paul@4701
   137
    SDL_AddDisplayMode(&_this->displays[0], &mode);
paul@4701
   138
paul@4713
   139
    Android_InitEvents();
paul@4713
   140
paul@4701
   141
    /* We're done! */
paul@4701
   142
    return 0;
paul@4701
   143
}
paul@4701
   144
paul@4701
   145
static int
paul@4701
   146
Android_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
paul@4701
   147
{
paul@4701
   148
    return 0;
paul@4701
   149
}
paul@4701
   150
paul@4701
   151
void
paul@4701
   152
Android_VideoQuit(_THIS)
paul@4701
   153
{
paul@4701
   154
}
paul@4701
   155
paul@4701
   156
paul@4716
   157
void Android_SetScreenResolution(int width, int height){
paul@4716
   158
    iScreenWidth = width;
paul@4716
   159
    iScreenHeight = height;   
paul@4716
   160
}
paul@4716
   161
paul@4716
   162
paul@4701
   163
paul@4701
   164
/* vi: set ts=4 sw=4 expandtab: */