/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * *****************************************************************************/ #if HAVE_CONFIG_H #include "config.h" #endif #include #include #include "backend.hh" #include "fastevents.h" #include "log.hh" namespace moof { static int retain_count = 0; backend::backend() { if (retain_count++ == 0) { #if PLATFORM_WIN32 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) #else if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0) #endif { throw std::runtime_error(SDL_GetError()); } else { char name[128]; SDL_VideoDriverName(name, sizeof(name)); log_info << "initialized SDL; using video driver `" << name << "'" << std::endl; } if (FE_Init() != 0) { throw std::runtime_error(FE_GetError()); } } } backend::backend(const backend& backend) { ++retain_count; } backend& backend::operator = (const backend& backend) { ++retain_count; return *this; } backend::~backend() { if (--retain_count == 0) { log_info("shutting down SDL..."); FE_Quit(); SDL_Quit(); } } bool backend::is_initialized() { return 0 < retain_count; } } // namespace moof