mirror of https://github.com/mgba-emu/mgba.git
Move screenshot function to gba-thread.h
This commit is contained in:
parent
b4d90e7e84
commit
f39d7e3640
|
@ -7,6 +7,7 @@
|
|||
#include "debugger/debugger.h"
|
||||
|
||||
#include "util/patch.h"
|
||||
#include "util/png-io.h"
|
||||
#include "util/vfs.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
@ -518,6 +519,18 @@ struct GBAThread* GBAThreadGetContext(void) {
|
|||
}
|
||||
#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) {
|
||||
return;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#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__)
|
||||
|
@ -18,8 +17,6 @@
|
|||
#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) {
|
||||
return false;
|
||||
|
@ -82,7 +79,7 @@ static void _GBASDLHandleKeypress(struct GBAThread* context, struct GBASDLEvents
|
|||
case SDLK_F12:
|
||||
if (event->type == SDL_KEYDOWN) {
|
||||
GBAThreadInterrupt(context);
|
||||
_takeScreenshot(context);
|
||||
GBAThreadTakeScreenshot(context);
|
||||
GBAThreadContinue(context);
|
||||
}
|
||||
return;
|
||||
|
@ -261,15 +258,3 @@ void GBASDLHandleEvent(struct GBAThread* context, struct GBASDLEvents* sdlContex
|
|||
_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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue