Move screenshot function to gba-thread.h
Jeffrey Pfau jeffrey@endrift.com
Sun, 27 Jul 2014 18:21:58 -0700
3 files changed,
16 insertions(+),
16 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -7,6 +7,7 @@
#include "debugger/debugger.h" #include "util/patch.h" +#include "util/png-io.h" #include "util/vfs.h" #include <signal.h>@@ -517,6 +518,18 @@ InitOnceExecuteOnce(&_contextOnce, _createTLS, NULL, 0);
return TlsGetValue(_contextKey); } #endif + +void GBAThreadTakeScreenshot(struct GBAThread* threadContext) { + unsigned stride; + void* pixels = 0; + struct VFile* vf = threadContext->stateDir->openFile(threadContext->stateDir, "screenshot.png", O_CREAT | O_WRONLY); + threadContext->gba->video.renderer->getPixels(threadContext->gba->video.renderer, &stride, &pixels); + png_structp png = PNGWriteOpen(vf); + png_infop info = PNGWriteHeader(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); + PNGWritePixels(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, stride, pixels); + PNGWriteClose(png, info); + vf->close(vf); +} void GBASyncPostFrame(struct GBASync* sync) { if (!sync) {
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -106,6 +106,8 @@ void GBAThreadTogglePause(struct GBAThread* threadContext);
void GBAThreadPauseFromThread(struct GBAThread* threadContext); struct GBAThread* GBAThreadGetContext(void); +void GBAThreadTakeScreenshot(struct GBAThread* threadContext); + void GBASyncPostFrame(struct GBASync* sync); bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip); void GBASyncWaitFrameEnd(struct GBASync* sync);
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -6,7 +6,6 @@ #include "gba-rr.h"
#include "gba-serialize.h" #include "gba-video.h" #include "renderers/video-software.h" -#include "util/png-io.h" #include "util/vfs.h" #if SDL_VERSION_ATLEAST(2, 0, 0) && defined(__APPLE__)@@ -17,8 +16,6 @@ #endif
#define SDL_BINDING_KEY 0x53444C4B #define SDL_BINDING_BUTTON 0x53444C42 - -static void _takeScreenshot(struct GBAThread*); bool GBASDLInitEvents(struct GBASDLEvents* context) { if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {@@ -82,7 +79,7 @@ return;
case SDLK_F12: if (event->type == SDL_KEYDOWN) { GBAThreadInterrupt(context); - _takeScreenshot(context); + GBAThreadTakeScreenshot(context); GBAThreadContinue(context); } return;@@ -261,15 +258,3 @@ case SDL_JOYHATMOTION:
_GBASDLHandleJoyHat(context, &event->jhat); } } - -static void _takeScreenshot(struct GBAThread* context) { - unsigned stride; - void* pixels = 0; - struct VFile* vf = context->stateDir->openFile(context->stateDir, "screenshot.png", O_CREAT | O_WRONLY); - context->gba->video.renderer->getPixels(context->gba->video.renderer, &stride, &pixels); - png_structp png = PNGWriteOpen(vf); - png_infop info = PNGWriteHeader(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS); - PNGWritePixels(png, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, stride, pixels); - PNGWriteClose(png, info); - vf->close(vf); -}