Skip to content

Commit

Permalink
Kill SDL dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
alexp-sssup committed Jun 11, 2011
1 parent 3a895c7 commit 464a16f
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 242 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ INCLUDE(FindLLVM REQUIRED)
IF(${LLVM_STRING_VERSION} VERSION_LESS 2.9)
ADD_DEFINITIONS(-DLLVM_28)
ENDIF(${LLVM_STRING_VERSION} VERSION_LESS 2.9)
INCLUDE(FindSDL REQUIRED)
INCLUDE(FindZLIB REQUIRED)
INCLUDE(FindFreetype REQUIRED)
INCLUDE(FindOpenGL REQUIRED)
Expand Down Expand Up @@ -207,7 +206,6 @@ IF(ENABLE_LIBAVCODEC)
ADD_DEFINITIONS(-DENABLE_LIBAVCODEC)
ENDIF(ENABLE_LIBAVCODEC)

INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${LLVM_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${Threads_INCLUDE_DIR})
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ELSE (CMAKE_COMPILER_IS_GNUCC)
ENDIF (CMAKE_COMPILER_IS_GNUCC)

TARGET_LINK_LIBRARIES(spark ${EXTRA_LIBS_LIBRARIES} ${ZLIB_LIBRARIES}
${Boost_LIBRARIES} ${LLVM_LIBS_CORE} ${LLVM_LIBS_JIT} ${SDL_LIBRARY}
${Boost_LIBRARIES} ${LLVM_LIBS_CORE} ${LLVM_LIBS_JIT}
${OPTIONAL_LIBRARIES} ${GTK_LIBRARIES} ${FREETYPE_LIBRARIES} ${JPEG_LIBRARIES}
${OPENGL_LIBRARIES} ${FTGL_LIBRARIES} ${GLEW_LIBRARIES} ${PCRE_LIBRARIES}
${Threads_LIBRARIES} ${XMLPP_LIBRARIES} ${CMAKE_DL_LIBS})
Expand All @@ -113,7 +113,7 @@ ENDIF(UNIX)
IF(COMPILE_LIGHTSPARK)
ADD_EXECUTABLE(lightspark main.cpp)
TARGET_LINK_LIBRARIES(lightspark spark)
TARGET_LINK_LIBRARIES(lightspark ${SDL_LIBRARY} ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES(lightspark ${Boost_LIBRARIES} ${GTK_LIBRARIES} -lX11)

IF(UNIX)
INSTALL(FILES ${PROJECT_SOURCE_DIR}/src/lightspark.frag DESTINATION ${DATADIR}/lightspark)
Expand Down
83 changes: 1 addition & 82 deletions src/backends/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "rendering.h"
#include "compat.h"

#include <SDL.h>

#ifdef COMPILE_PLUGIN
#include <gdk/gdkkeysyms.h>
#endif
Expand All @@ -41,13 +39,8 @@ InputThread::InputThread(SystemState* s):m_sys(s),terminated(false),threaded(fal

void InputThread::start(ENGINE e,void* param)
{
if(e==SDL)
{
threaded=true;
pthread_create(&t,NULL,(thread_worker)sdl_worker,this);
}
#ifdef COMPILE_PLUGIN
else if(e==GTKPLUG)
if(e==GTKPLUG)
{
npapi_params=(NPAPI_params*)param;
GtkWidget* container=npapi_params->container;
Expand Down Expand Up @@ -233,80 +226,6 @@ void InputThread::handleMouseMove(uint32_t x, uint32_t y)
}
}

void* InputThread::sdl_worker(InputThread* th)
{
sys=th->m_sys;
SDL_Event event;
while(SDL_WaitEvent(&event))
{
if(sys->isShuttingDown())
break;
switch(event.type)
{
case SDL_KEYDOWN:
{
switch(event.key.keysym.sym)
{
case SDLK_p:
th->m_sys->showProfilingData=!th->m_sys->showProfilingData;
break;
case SDLK_m:
if (!th->m_sys->audioManager->pluginLoaded())
break;
th->m_sys->audioManager->toggleMuteAll();
if(th->m_sys->audioManager->allMuted())
LOG(LOG_NO_INFO, "All sounds muted");
else
LOG(LOG_NO_INFO, "All sounds unmuted");
break;
case SDLK_q:
th->m_sys->setShutdownFlag();
if(th->m_sys->currentVm)
LOG(LOG_CALLS,_("We still miss ") << sys->currentVm->getEventQueueSize() << _(" events"));
pthread_exit(0);
break;
case SDLK_s:
th->m_sys->state.stop_FP=true;
break;
//Ignore any other keystrokes
default:
break;
}
break;
}
case SDL_MOUSEBUTTONDOWN:
{
th->handleMouseDown(event.button.x,event.button.y);
break;
}
case SDL_MOUSEBUTTONUP:
{
th->handleMouseUp(event.button.x,event.button.y);
break;
}
case SDL_MOUSEMOTION:
{
th->handleMouseMove(event.motion.x,event.motion.y);
break;
}
case SDL_VIDEORESIZE:
{
th->m_sys->getRenderThread()->requestResize(event.resize.w, event.resize.h);
break;
}
case SDL_QUIT:
{
th->m_sys->setShutdownFlag();
if(th->m_sys->currentVm)
LOG(LOG_CALLS,_("We still miss ") << sys->currentVm->getEventQueueSize() << _(" events"));
pthread_exit(0);
break;
}
}
}
return NULL;
}

void InputThread::addListener(InteractiveObject* ob)
{
Locker locker(mutexListeners);
Expand Down
1 change: 0 additions & 1 deletion src/backends/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class InputThread
pthread_t t;
bool terminated;
bool threaded;
static void* sdl_worker(InputThread*);
#ifdef COMPILE_PLUGIN
NPAPI_params* npapi_params;
static gboolean gtkplug_worker(GtkWidget *widget, GdkEvent *event, InputThread* th);
Expand Down
136 changes: 1 addition & 135 deletions src/backends/rendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include "rendering.h"
#include "compat.h"
#include <sstream>
//#include "swf.h"

#include <SDL.h>

#include <GL/glew.h>
#ifndef WIN32
Expand Down Expand Up @@ -97,10 +94,8 @@ RenderThread::RenderThread(SystemState* s):
void RenderThread::start(ENGINE e,void* params)
{
status=STARTED;
if(e==SDL)
pthread_create(&t,NULL,(thread_worker)sdl_worker,this);
#ifdef COMPILE_PLUGIN
else if(e==GTKPLUG)
if(e==GTKPLUG)
{
npapi_params=(NPAPI_params*)params;
pthread_create(&t,NULL,(thread_worker)gtkplug_worker,this);
Expand Down Expand Up @@ -757,135 +752,6 @@ void RenderThread::coreRendering(FTFont& font)
}
}

void* RenderThread::sdl_worker(RenderThread* th)
{
sys=th->m_sys;
rt=th;
SemaphoreLighter lighter(th->initialized);
RECT size=sys->getFrameSize();
int initialWidth=size.Xmax/20;
int initialHeight=size.Ymax/20;
th->windowWidth=initialWidth;
th->windowHeight=initialHeight;
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 );
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

SDL_SetVideoMode(th->windowWidth, th->windowHeight, 24, SDL_OPENGL|SDL_RESIZABLE);
SDL_WM_SetCaption("Lightspark","Lightspark");
th->commonGLInit(th->windowWidth, th->windowHeight);
th->commonGLResize();
lighter.light();

ThreadProfile* profile=sys->allocateProfiler(RGB(200,0,0));
profile->setTag("Render");
FTTextureFont font(th->fontPath.c_str());
if(font.Error())
throw RunTimeException("Unable to load font");

font.FaceSize(12);
try
{
Chronometer chronometer;
while(1)
{
sem_wait(&th->event);
if(th->m_sys->isShuttingDown())
break;
chronometer.checkpoint();

if(th->resizeNeeded)
{
if(th->windowWidth!=th->newWidth ||
th->windowHeight!=th->newHeight)
{
th->windowWidth=th->newWidth;
th->windowHeight=th->newHeight;
SDL_SetVideoMode(th->windowWidth, th->windowHeight, 24, SDL_OPENGL|SDL_RESIZABLE);
}
th->newWidth=0;
th->newHeight=0;
th->resizeNeeded=false;
th->commonGLResize();
profile->accountTime(chronometer.checkpoint());
continue;
}

if(th->newTextureNeeded)
th->handleNewTexture();

if(th->prevUploadJob)
th->finalizeUpload();

if(th->uploadNeeded)
{
th->handleUpload();
profile->accountTime(chronometer.checkpoint());
continue;
}

SDL_PumpEvents();
if(th->m_sys->isOnError())
{
glLoadIdentity();
glScalef(1.0f/th->scaleX,-1.0f/th->scaleY,1);
glTranslatef(-th->offsetX,(th->windowHeight-th->offsetY)*(-1.0f),0);
glUseProgram(0);
glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawBuffer(GL_BACK);

glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.8,0.8,0.8);

font.Render("We're sorry, Lightspark encountered a yet unsupported Flash file",
-1,FTPoint(0,th->windowHeight/2+20));

stringstream errorMsg;
errorMsg << "SWF file: " << th->m_sys->getOrigin().getParsedURL();
font.Render(errorMsg.str().c_str(),
-1,FTPoint(0,th->windowHeight/2));

errorMsg.str("");
errorMsg << "Cause: " << th->m_sys->errorCause;
font.Render(errorMsg.str().c_str(),
-1,FTPoint(0,th->windowHeight/2-20));

font.Render("Please look at the console output to copy this error",
-1,FTPoint(0,th->windowHeight/2-40));

font.Render("Press 'Q' to exit",-1,FTPoint(0,th->windowHeight/2-60));

glFlush();
SDL_GL_SwapBuffers( );
}
else
{
SDL_GL_SwapBuffers( );
th->coreRendering(font);
//Call glFlush to offload work on the GPU
glFlush();
}
profile->accountTime(chronometer.checkpoint());
th->renderNeeded=false;
}
}
catch(LightsparkException& e)
{
LOG(LOG_ERROR,_("Exception in RenderThread ") << e.cause);
sys->setError(e.cause);
}
th->commonGLDeinit();
return NULL;
}

void RenderThread::addUploadJob(ITextureUploadable* u)
{
Locker l(mutexUploadJobs);
Expand Down
1 change: 0 additions & 1 deletion src/backends/rendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ friend class DisplayObject;
pthread_t t;
enum STATUS { CREATED=0, STARTED, TERMINATED };
STATUS status;
static void* sdl_worker(RenderThread*);
#ifdef COMPILE_PLUGIN
NPAPI_params* npapi_params;
static void* gtkplug_worker(RenderThread*);
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/pluginutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace lightspark
{

enum ENGINE { NONE=0, SDL, GTKPLUG};
enum ENGINE { NONE=0, GTKPLUG};
typedef void(*helper_t)(void*);
#ifdef COMPILE_PLUGIN
struct NPAPI_params
Expand Down
18 changes: 0 additions & 18 deletions src/swf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "scripting/class.h"
#include "backends/rendering.h"

#include "SDL.h"
#include <GL/glew.h>
#ifdef ENABLE_CURL
#include <curl/curl.h>
Expand Down Expand Up @@ -460,15 +459,6 @@ void SystemState::setShutdownFlag()
void SystemState::wait()
{
sem_wait(&terminated);
if(engine==SDL)
{
SDL_Event event;
event.type = SDL_USEREVENT;
event.user.code = SHUTDOWN;
event.user.data1 = 0;
event.user.data1 = 0;
SDL_PushEvent(&event);
}
//Acquire the mutex to sure that the engines are not being started right now
Locker l(mutex);
renderThread->wait();
Expand Down Expand Up @@ -733,14 +723,6 @@ void SystemState::createEngines()
throw new UnsupportedException("Plugin engine not available when not built with COMPILE_PLUGIN");
#endif
}
else //SDL engine
{
renderThread->start(engine, NULL);
inputThread->start(engine, NULL);
//If the render rate is known start the render ticks
if(renderRate)
startRenderTicks();
}
renderThread->waitForInitialization();
l.lock();
//As we lost the lock the shutdown procesure might have started
Expand Down

0 comments on commit 464a16f

Please sign in to comment.