Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Automatically initialize the video system and create a renderer to si…

…mplify use.
  • Loading branch information
slouken committed Oct 28, 2009
1 parent 5b559d4 commit a1c1e588a492f3332d1053f95540ffc04f640311
Showing with 232 additions and 71 deletions.
  1. +1 −0 src/video/SDL_sysvideo.h
  2. +62 −70 src/video/SDL_video.c
  3. +4 −1 test/Makefile.in
  4. +165 −0 test/testspriteminimal.c
@@ -396,6 +396,7 @@ extern VideoBootStrap PND_bootstrap;
#endif

#define SDL_CurrentDisplay (_this->displays[_this->current_display])
#define SDL_CurrentRenderer (SDL_CurrentDisplay.current_renderer)

extern SDL_VideoDevice *SDL_GetVideoDevice();
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
@@ -754,8 +754,10 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
SDL_Window *windows;

if (!_this) {
SDL_UninitializedVideo();
return 0;
/* Initialize the video system if needed */
if (SDL_VideoInit(NULL, 0) < 0) {
return 0;
}
}
if (flags & SDL_WINDOW_OPENGL) {
if (!_this->GL_CreateContext) {
@@ -926,15 +928,28 @@ SDL_GetWindowFromID(SDL_WindowID windowID)
SDL_UninitializedVideo();
return NULL;
}
for (i = 0; i < _this->num_displays; ++i) {
SDL_VideoDisplay *display = &_this->displays[i];
for (j = 0; j < display->num_windows; ++j) {
SDL_Window *window = &display->windows[j];
if (window->id == windowID) {
if (windowID) {
for (i = 0; i < _this->num_displays; ++i) {
SDL_VideoDisplay *display = &_this->displays[i];
for (j = 0; j < display->num_windows; ++j) {
SDL_Window *window = &display->windows[j];
if (window->id == windowID) {
return window;
}
}
}
} else {
/* Just return the first active window */
for (i = 0; i < _this->num_displays; ++i) {
SDL_VideoDisplay *display = &_this->displays[i];
for (j = 0; j < display->num_windows; ++j) {
SDL_Window *window = &display->windows[j];
return window;
}
}
}
/* Couldn't find the window with the requested ID */
SDL_SetError("Invalid window ID");
return NULL;
}

@@ -951,6 +966,23 @@ SDL_GetDisplayFromWindow(SDL_Window * window)
return &_this->displays[window->display];
}

static __inline__ SDL_Renderer *
SDL_GetCurrentRenderer()
{
SDL_Renderer *renderer;

if (!_this) {
SDL_UninitializedVideo();
return NULL;
}
if (!SDL_CurrentRenderer) {
if (SDL_CreateRenderer(0, -1, 0) < 0) {
return NULL;
}
}
return SDL_CurrentRenderer;
}

Uint32
SDL_GetWindowFlags(SDL_WindowID windowID)
{
@@ -1506,31 +1538,29 @@ SDL_SelectRenderer(SDL_WindowID windowID)
return -1;
}
renderer = window->renderer;
if (!renderer) {
SDL_SetError("Renderer hasn't been created yet");
return -1;
}
if (renderer->ActivateRenderer) {
if (renderer->ActivateRenderer(renderer) < 0) {
if (renderer) {
if (renderer->ActivateRenderer) {
if (renderer->ActivateRenderer(renderer) < 0) {
return -1;
}
}
SDL_CurrentDisplay.current_renderer = renderer;
} else {
if (SDL_CreateRenderer(windowID, -1, 0) < 0) {
return -1;
}
}
SDL_CurrentDisplay.current_renderer = renderer;
return 0;
}

int
SDL_GetRendererInfo(SDL_RendererInfo * info)
{
if (!_this) {
SDL_UninitializedVideo();
return -1;
}
if (!SDL_CurrentDisplay.current_renderer) {
SDL_SetError("There is no current renderer");
SDL_Renderer *renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return -1;
}
*info = SDL_CurrentDisplay.current_renderer->info;
*info = renderer->info;
return 0;
}

@@ -1541,11 +1571,7 @@ SDL_CreateTexture(Uint32 format, int access, int w, int h)
SDL_Renderer *renderer;
SDL_Texture *texture;

if (!_this) {
SDL_UninitializedVideo();
return 0;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return 0;
}
@@ -1599,9 +1625,8 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
}
fmt = surface->format;

renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
SDL_SetError("No current renderer available");
return 0;
}

@@ -2234,11 +2259,7 @@ SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_Renderer *renderer;

if (!_this) {
SDL_UninitializedVideo();
return -1;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return -1;
}
@@ -2258,11 +2279,7 @@ SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
{
SDL_Renderer *renderer;

if (!_this) {
SDL_UninitializedVideo();
return -1;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return -1;
}
@@ -2286,11 +2303,7 @@ SDL_SetRenderDrawBlendMode(int blendMode)
{
SDL_Renderer *renderer;

if (!_this) {
SDL_UninitializedVideo();
return -1;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return -1;
}
@@ -2307,11 +2320,7 @@ SDL_GetRenderDrawBlendMode(int *blendMode)
{
SDL_Renderer *renderer;

if (!_this) {
SDL_UninitializedVideo();
return -1;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return -1;
}
@@ -2325,11 +2334,7 @@ SDL_RenderPoint(int x, int y)
SDL_Renderer *renderer;
SDL_Window *window;

if (!_this) {
SDL_UninitializedVideo();
return -1;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return -1;
}
@@ -2355,11 +2360,7 @@ SDL_RenderLine(int x1, int y1, int x2, int y2)
return SDL_RenderPoint(x1, y1);
}

if (!_this) {
SDL_UninitializedVideo();
return -1;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return -1;
}
@@ -2386,11 +2387,7 @@ SDL_RenderFill(const SDL_Rect * rect)
SDL_Window *window;
SDL_Rect real_rect;

if (!_this) {
SDL_UninitializedVideo();
return -1;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
return -1;
}
@@ -2422,9 +2419,8 @@ SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
SDL_Rect real_srcrect;
SDL_Rect real_dstrect;

renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer) {
SDL_SetError("No current renderer available");
return -1;
}
if (!texture) {
@@ -2483,11 +2479,7 @@ SDL_RenderPresent(void)
{
SDL_Renderer *renderer;

if (!_this) {
SDL_UninitializedVideo();
return;
}
renderer = SDL_CurrentDisplay.current_renderer;
renderer = SDL_GetCurrentRenderer();
if (!renderer || !renderer->RenderPresent) {
return;
}
@@ -7,7 +7,7 @@ EXE = @EXE@
CFLAGS = @CFLAGS@
LIBS = @LIBS@

TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testresample$(EXE) testaudioinfo$(EXE) testmultiaudio$(EXE) testpower$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testintersections$(EXE) testdraw2$(EXE) testdyngl$(EXE) testdyngles$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testgl2$(EXE) testgles$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testsprite2$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) testwm2$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE) testhaptic$(EXE) testmmousetablet$(EXE) testatomic$(EXE) testime$(EXE)
TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmmousetablet$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)

all: Makefile $(TARGETS)

@@ -107,6 +107,9 @@ testplatform$(EXE): $(srcdir)/testplatform.c
testsem$(EXE): $(srcdir)/testsem.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS)

testspriteminimal$(EXE): $(srcdir)/testspriteminimal.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@

testsprite$(EXE): $(srcdir)/testsprite.c
$(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@

0 comments on commit a1c1e58

Please sign in to comment.