all repos — mgba @ c035d97286707f6f5de10789e1dd8a7ca3e5f8e5

mGBA Game Boy Advance Emulator

Make libPNG/zlib optional dependencies
Jeffrey Pfau jeffrey@endrift.com
Tue, 30 Sep 2014 01:43:43 -0700
commit

c035d97286707f6f5de10789e1dd8a7ca3e5f8e5

parent

834395d5d92b614795088a789d2bdf97eb24375e

M CMakeLists.txtCMakeLists.txt

@@ -6,6 +6,7 @@ set(CMAKE_C_FLAGS_RELEASE "-O3 -Wall -Wextra -std=gnu99")

set(USE_CLI_DEBUGGER ON CACHE BOOL "Whether or not to enable the CLI-mode ARM debugger") set(USE_GDB_STUB ON CACHE BOOL "Whether or not to enable the GDB stub ARM debugger") set(USE_FFMPEG ON CACHE BOOL "Whether or not to enable FFmpeg support") +set(USE_PNG ON CACHE BOOL "Whether or not to enable PNG support") set(BUILD_SDL ON CACHE BOOL "Build SDL frontend") set(BUILD_PERF ON CACHE BOOL "Build performance profiling tool") file(GLOB ARM_SRC ${CMAKE_SOURCE_DIR}/src/arm/*.c)

@@ -107,9 +108,12 @@ list(APPEND UTIL_SRC "${CMAKE_SOURCE_DIR}/src/platform/ffmpeg/ffmpeg-encoder.c")

list(APPEND DEPENDENCY_LIB ${LIBAVCODEC_LIBRARIES} ${LIBAVFORMAT_LIBRARIES} ${LIBAVUTIL_LIBRARIES}) endif() -find_package(PNG REQUIRED) -find_package(ZLIB REQUIRED) -list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES}) +if(USE_PNG) + find_package(PNG REQUIRED) + find_package(ZLIB REQUIRED) + add_definitions(-DUSE_PNG) + list(APPEND DEPENDENCY_LIB ${PNG_LIBRARIES} ${ZLIB_LIBRARIES}) +endif() add_library(${BINARY_NAME} SHARED ${ARM_SRC} ${GBA_SRC} ${DEBUGGER_SRC} ${RENDERER_SRC} ${UTIL_SRC} ${VFS_SRC} ${OS_SRC}) target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB})
M src/gba/gba-serialize.csrc/gba/gba-serialize.c

@@ -7,12 +7,15 @@ #include "gba-thread.h"

#include "gba-video.h" #include "util/memory.h" -#include "util/png-io.h" #include "util/vfs.h" #include <fcntl.h> + +#ifdef USE_PNG +#include "util/png-io.h" #include <png.h> #include <zlib.h> +#endif const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000;

@@ -113,6 +116,7 @@ }

return vf; } +#ifdef USE_PNG static bool _savePNGState(struct GBA* gba, struct VFile* vf) { unsigned stride; void* pixels = 0;

@@ -168,6 +172,7 @@ gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, pixels);

GBASyncPostFrame(gba->sync); return true; } +#endif bool GBASaveState(struct GBA* gba, struct VDir* dir, int slot, bool screenshot) { struct VFile* vf = _getStateVf(gba, dir, slot, true);

@@ -198,23 +203,28 @@ return false;

} GBASerialize(gba, state); vf->unmap(vf, state, sizeof(struct GBASerializedState)); - } else { + return true; + } + #ifdef USE_PNG + else { return _savePNGState(gba, vf); } - return true; + #endif + return false; } bool GBALoadStateNamed(struct GBA* gba, struct VFile* vf) { - if (!isPNG(vf)) { - struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ); - if (!state) { - return false; - } - GBADeserialize(gba, state); - vf->unmap(vf, state, sizeof(struct GBASerializedState)); - } else { + #ifdef USE_PNG + if (isPNG(vf)) { return _loadPNGState(gba, vf); } + #endif + struct GBASerializedState* state = vf->map(vf, sizeof(struct GBASerializedState), MAP_READ); + if (!state) { + return false; + } + GBADeserialize(gba, state); + vf->unmap(vf, state, sizeof(struct GBASerializedState)); return true; }
M src/gba/gba-thread.csrc/gba/gba-thread.c

@@ -520,6 +520,7 @@ return TlsGetValue(_contextKey);

} #endif +#ifdef USE_PNG void GBAThreadTakeScreenshot(struct GBAThread* threadContext) { unsigned stride; void* pixels = 0;

@@ -531,6 +532,7 @@ PNGWritePixels(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, stride, pixels);

PNGWriteClose(png, info); vf->close(vf); } +#endif void GBASyncPostFrame(struct GBASync* sync) { if (!sync) {
M src/gba/gba-thread.hsrc/gba/gba-thread.h

@@ -112,7 +112,9 @@ void GBAThreadTogglePause(struct GBAThread* threadContext);

void GBAThreadPauseFromThread(struct GBAThread* threadContext); struct GBAThread* GBAThreadGetContext(void); +#ifdef USE_PNG void GBAThreadTakeScreenshot(struct GBAThread* threadContext); +#endif void GBASyncPostFrame(struct GBASync* sync); bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
M src/util/png-io.csrc/util/png-io.c

@@ -1,5 +1,7 @@

#include "util/png-io.h" +#ifdef USE_PNG + #include "vfs.h" static void _pngWrite(png_structp png, png_bytep buffer, png_size_t size) {

@@ -177,3 +179,5 @@

void PNGReadClose(png_structp png, png_infop info, png_infop end) { png_destroy_read_struct(&png, &info, &end); } + +#endif
M src/util/png-io.hsrc/util/png-io.h

@@ -3,6 +3,8 @@ #define PNG_IO_H

#include "common.h" +#ifdef USE_PNG + #include <png.h> struct VFile;

@@ -29,3 +31,5 @@ bool PNGReadFooter(png_structp png, png_infop end);

void PNGReadClose(png_structp png, png_infop info, png_infop end); #endif + +#endif