mirror of https://github.com/mgba-emu/mgba.git
Make libPNG/zlib optional dependencies
This commit is contained in:
parent
834395d5d9
commit
c035d97286
|
@ -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 @@ if(USE_FFMPEG)
|
|||
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})
|
||||
|
|
|
@ -7,12 +7,15 @@
|
|||
#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 @@ static struct VFile* _getStateVf(struct GBA* gba, struct VDir* dir, int slot, bo
|
|||
return vf;
|
||||
}
|
||||
|
||||
#ifdef USE_PNG
|
||||
static bool _savePNGState(struct GBA* gba, struct VFile* vf) {
|
||||
unsigned stride;
|
||||
void* pixels = 0;
|
||||
|
@ -168,6 +172,7 @@ static bool _loadPNGState(struct GBA* gba, struct VFile* vf) {
|
|||
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 @@ bool GBASaveStateNamed(struct GBA* gba, struct VFile* vf, bool screenshot) {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -520,6 +520,7 @@ struct GBAThread* GBAThreadGetContext(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_PNG
|
||||
void GBAThreadTakeScreenshot(struct GBAThread* threadContext) {
|
||||
unsigned stride;
|
||||
void* pixels = 0;
|
||||
|
@ -531,6 +532,7 @@ void GBAThreadTakeScreenshot(struct GBAThread* threadContext) {
|
|||
PNGWriteClose(png, info);
|
||||
vf->close(vf);
|
||||
}
|
||||
#endif
|
||||
|
||||
void GBASyncPostFrame(struct GBASync* sync) {
|
||||
if (!sync) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 @@ bool PNGReadFooter(png_structp png, png_infop end) {
|
|||
void PNGReadClose(png_structp png, png_infop info, png_infop end) {
|
||||
png_destroy_read_struct(&png, &info, &end);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#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
|
||||
|
|
Loading…
Reference in New Issue