From 6cf749c82c0981ec58f09f079aa57c0daac67c59 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 6 Aug 2014 21:04:57 +0200 Subject: [PATCH] Add the call to bcm_host_init/deinit() on raspberry pi. --- CMakeLists.txt | 24 ++++++++++++++++++++++-- src/sdlmain.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fef7a7d..f6fe71e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,10 +7,14 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -Wall -Wextra option(WITH_BUILTIN_PHYSFS "Force using the version of PhysFS accompanying the code even if a system library is available" OFF) option(FORCE_OPENGLES "Try to chose the openGL ES renderer if available. Enable this on Raspberry Pi" OFF) +option(RASPBERRY_PI "Compile for Raspberry Pi" OFF) -if (FORCE_OPENGLES) +if (FORCE_OPENGLES OR RASPBERRY_PI) add_definitions(-DFORCE_OPENGLES) -endif (FORCE_OPENGLES) + if (RASPBERRY_PI) + add_definitions(-DRASPBERRY_PI) + endif(RASPBERRY_PI) +endif (FORCE_OPENGLES OR RASPBERRY_PI) include(FindPkgConfig) PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) @@ -35,6 +39,16 @@ add_definitions( -DWITH_VERBOSE_COLLIDER ) +if (RASPBERRY_PI) + message(STATUS "Will build for Raspberry Pi") + include_directories(SYSTEM + /opt/vc/include + ) + link_directories( + /opt/vc/lib + ) +endif (RASPBERRY_PI) + include_directories(SYSTEM ${SDL2_INCLUDE_DIR} ${PNG_INCLUDE_DIRS} @@ -93,3 +107,9 @@ target_link_libraries(${PROJECT_NAME} ${PHYSFS_LIBRARY} ${PNG_LIBRARIES} ) + +if (RASPBERRY_PI) + target_link_libraries(${PROJECT_NAME} + bcm_host + ) +endif(RASPBERRY_PI) diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index 4d3f84c..1f33b8e 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -28,6 +28,10 @@ #include #include +#if defined(RASPBERRY_PI) +#include +#endif + namespace cloonel { namespace { ///---------------------------------------------------------------------- @@ -74,6 +78,9 @@ namespace cloonel { SizeRatio sizeratio; ObserversManager resChangeNotifList; bool initialized; +#if defined(RASPBERRY_PI) + bool bcmInitialized; +#endif }; ///------------------------------------------------------------------------ @@ -83,12 +90,19 @@ namespace cloonel { m_localData(new LocalData) { m_localData->sizeratio.SetOriginal(static_cast(parReferenceRes), static_cast(parRes)); + m_localData->initialized = false; +#if defined(RASPBERRY_PI) + m_localData->bcmInitialized = false; +#endif } ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ SDLMain::~SDLMain() noexcept { ClearIFN(*m_localData); +#if defined(RASPBERRY_PI) + assert(not m_localData->bcmInitialized); +#endif } ///------------------------------------------------------------------------ @@ -109,6 +123,12 @@ namespace cloonel { throw std::runtime_error(SDL_GetError()); parInitSDL.initialized = true; +#if defined(RASPBERRY_PI) + assert(not parInitSDL.bcmInitialized); + bcm_host_init(); + parInitSDL.bcmInitialized = true; +#endif + #if defined(FORCE_OPENGLES) SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); #endif @@ -134,8 +154,16 @@ namespace cloonel { SDL_DestroyRenderer(parInitSDL.renderer); if (parInitSDL.window) SDL_DestroyWindow(parInitSDL.window); - if (parInitSDL.initialized) + if (parInitSDL.initialized) { + parInitSDL.initialized = false; SDL_Quit(); + } +#if defined(RASPBERRY_PI) + if (parInitSDL.bcmInitialized) { + parInitSDL.bcmInitialized = false; + bcm_host_deinit(); + } +#endif } ///------------------------------------------------------------------------