Core: Fix video proxy renderer creation and improve API

This commit is contained in:
Vicki Pfau 2024-09-06 23:24:04 -07:00
parent ae6cc33a5e
commit b072cb40cb
6 changed files with 38 additions and 37 deletions

View File

@ -20,7 +20,7 @@ struct GBVideoProxyRenderer {
enum GBModel model;
};
void GBVideoProxyRendererCreate(struct GBVideoProxyRenderer* renderer, struct GBVideoRenderer* backend);
void GBVideoProxyRendererCreate(struct GBVideoProxyRenderer* renderer, struct GBVideoRenderer* backend, struct mVideoLogger* logger);
void GBVideoProxyRendererShim(struct GBVideo* video, struct GBVideoProxyRenderer* renderer);
void GBVideoProxyRendererUnshim(struct GBVideo* video, struct GBVideoProxyRenderer* renderer);

View File

@ -19,7 +19,7 @@ struct GBAVideoProxyRenderer {
struct mVideoLogger* logger;
};
void GBAVideoProxyRendererCreate(struct GBAVideoProxyRenderer* renderer, struct GBAVideoRenderer* backend);
void GBAVideoProxyRendererCreate(struct GBAVideoProxyRenderer* renderer, struct GBAVideoRenderer* backend, struct mVideoLogger* logger);
void GBAVideoProxyRendererShim(struct GBAVideo* video, struct GBAVideoProxyRenderer* renderer);
void GBAVideoProxyRendererUnshim(struct GBAVideo* video, struct GBAVideoProxyRenderer* renderer);

View File

@ -1266,12 +1266,12 @@ static void _GBCoreStartVideoLog(struct mCore* core, struct mVideoLogContext* co
gbcore->logContext = context;
int channelId = mVideoLoggerAddChannel(context);
gbcore->proxyRenderer.logger = malloc(sizeof(struct mVideoLogger));
mVideoLoggerRendererCreate(gbcore->proxyRenderer.logger, false);
mVideoLoggerAttachChannel(gbcore->proxyRenderer.logger, context, channelId);
gbcore->proxyRenderer.logger->block = false;
struct mVideoLogger* logger = malloc(sizeof(*logger));
mVideoLoggerRendererCreate(logger, false);
mVideoLoggerAttachChannel(logger, context, channelId);
logger->block = false;
GBVideoProxyRendererCreate(&gbcore->proxyRenderer, &gbcore->renderer.d);
GBVideoProxyRendererCreate(&gbcore->proxyRenderer, &gbcore->renderer.d, logger);
GBVideoProxyRendererShim(&gb->video, &gbcore->proxyRenderer);
}
@ -1405,9 +1405,9 @@ static bool _GBVLPInit(struct mCore* core) {
if (!_GBCoreInit(core)) {
return false;
}
gbcore->proxyRenderer.logger = malloc(sizeof(struct mVideoLogger));
mVideoLoggerRendererCreate(gbcore->proxyRenderer.logger, true);
GBVideoProxyRendererCreate(&gbcore->proxyRenderer, NULL);
struct mVideoLogger* logger = malloc(sizeof(*logger));
mVideoLoggerRendererCreate(logger, true);
GBVideoProxyRendererCreate(&gbcore->proxyRenderer, NULL, logger);
memset(&gbcore->logCallbacks, 0, sizeof(gbcore->logCallbacks));
gbcore->logCallbacks.videoFrameStarted = _GBVLPStartFrameCallback;
gbcore->logCallbacks.context = core;

View File

@ -29,7 +29,8 @@ static void GBVideoProxyRendererPutPixels(struct GBVideoRenderer* renderer, size
static bool _parsePacket(struct mVideoLogger* logger, const struct mVideoLoggerDirtyInfo* packet);
static uint16_t* _vramBlock(struct mVideoLogger* logger, uint32_t address);
void GBVideoProxyRendererCreate(struct GBVideoProxyRenderer* renderer, struct GBVideoRenderer* backend) {
void GBVideoProxyRendererCreate(struct GBVideoProxyRenderer* renderer, struct GBVideoRenderer* backend, struct mVideoLogger* logger) {
memset(renderer, 0, sizeof(*renderer));
renderer->d.init = GBVideoProxyRendererInit;
renderer->d.deinit = GBVideoProxyRendererDeinit;
renderer->d.writeVideoRegister = GBVideoProxyRendererWriteVideoRegister;
@ -57,12 +58,13 @@ void GBVideoProxyRendererCreate(struct GBVideoProxyRenderer* renderer, struct GB
renderer->d.highlightColor = M_COLOR_WHITE;
renderer->d.highlightAmount = 0;
renderer->logger->context = renderer;
renderer->logger->parsePacket = _parsePacket;
renderer->logger->vramBlock = _vramBlock;
renderer->logger->paletteSize = 0;
renderer->logger->vramSize = GB_SIZE_VRAM;
renderer->logger->oamSize = GB_SIZE_OAM;
renderer->logger = logger;
logger->context = renderer;
logger->parsePacket = _parsePacket;
logger->vramBlock = _vramBlock;
logger->paletteSize = 0;
logger->vramSize = GB_SIZE_VRAM;
logger->oamSize = GB_SIZE_OAM;
renderer->backend = backend;
}

View File

@ -470,8 +470,7 @@ static void _GBACoreReloadConfigOption(struct mCore* core, const char* option, c
#endif
#ifndef MINIMAL_CORE
if (renderer && core->videoLogger) {
gbacore->proxyRenderer.logger = core->videoLogger;
GBAVideoProxyRendererCreate(&gbacore->proxyRenderer, renderer);
GBAVideoProxyRendererCreate(&gbacore->proxyRenderer, renderer, core->videoLogger);
renderer = &gbacore->proxyRenderer.d;
}
#endif
@ -712,8 +711,7 @@ static void _GBACoreReset(struct mCore* core) {
#endif
#ifndef MINIMAL_CORE
if (renderer && core->videoLogger) {
gbacore->proxyRenderer.logger = core->videoLogger;
GBAVideoProxyRendererCreate(&gbacore->proxyRenderer, renderer);
GBAVideoProxyRendererCreate(&gbacore->proxyRenderer, renderer, core->videoLogger);
renderer = &gbacore->proxyRenderer.d;
}
#endif
@ -1516,12 +1514,12 @@ static void _GBACoreStartVideoLog(struct mCore* core, struct mVideoLogContext* c
state->cpu.gprs[ARM_PC] = GBA_BASE_EWRAM;
int channelId = mVideoLoggerAddChannel(context);
gbacore->vlProxy.logger = malloc(sizeof(struct mVideoLogger));
mVideoLoggerRendererCreate(gbacore->vlProxy.logger, false);
mVideoLoggerAttachChannel(gbacore->vlProxy.logger, context, channelId);
gbacore->vlProxy.logger->block = false;
struct mVideoLogger* logger = malloc(sizeof(*logger));
mVideoLoggerRendererCreate(logger, false);
mVideoLoggerAttachChannel(logger, context, channelId);
logger->block = false;
GBAVideoProxyRendererCreate(&gbacore->vlProxy, gba->video.renderer);
GBAVideoProxyRendererCreate(&gbacore->vlProxy, gba->video.renderer, logger);
GBAVideoProxyRendererShim(&gba->video, &gbacore->vlProxy);
}
@ -1654,9 +1652,9 @@ static bool _GBAVLPInit(struct mCore* core) {
if (!_GBACoreInit(core)) {
return false;
}
gbacore->vlProxy.logger = malloc(sizeof(struct mVideoLogger));
mVideoLoggerRendererCreate(gbacore->vlProxy.logger, true);
GBAVideoProxyRendererCreate(&gbacore->vlProxy, NULL);
struct mVideoLogger* logger = malloc(sizeof(*logger));
mVideoLoggerRendererCreate(logger, true);
GBAVideoProxyRendererCreate(&gbacore->vlProxy, NULL, logger);
memset(&gbacore->logCallbacks, 0, sizeof(gbacore->logCallbacks));
gbacore->logCallbacks.videoFrameStarted = _GBAVLPStartFrameCallback;
gbacore->logCallbacks.context = core;

View File

@ -29,7 +29,7 @@ static void _handleEvent(struct mVideoLogger* logger, enum mVideoLoggerEvent eve
static bool _parsePacket(struct mVideoLogger* logger, const struct mVideoLoggerDirtyInfo* packet);
static uint16_t* _vramBlock(struct mVideoLogger* logger, uint32_t address);
void GBAVideoProxyRendererCreate(struct GBAVideoProxyRenderer* renderer, struct GBAVideoRenderer* backend) {
void GBAVideoProxyRendererCreate(struct GBAVideoProxyRenderer* renderer, struct GBAVideoRenderer* backend, struct mVideoLogger* logger) {
memset(renderer, 0, sizeof(*renderer));
renderer->d.init = GBAVideoProxyRendererInit;
renderer->d.reset = GBAVideoProxyRendererReset;
@ -66,13 +66,14 @@ void GBAVideoProxyRendererCreate(struct GBAVideoProxyRenderer* renderer, struct
renderer->d.highlightColor = M_COLOR_WHITE;
renderer->d.highlightAmount = 0;
renderer->logger->context = renderer;
renderer->logger->parsePacket = _parsePacket;
renderer->logger->handleEvent = _handleEvent;
renderer->logger->vramBlock = _vramBlock;
renderer->logger->paletteSize = GBA_SIZE_PALETTE_RAM;
renderer->logger->vramSize = GBA_SIZE_VRAM;
renderer->logger->oamSize = GBA_SIZE_OAM;
renderer->logger = logger;
logger->context = renderer;
logger->parsePacket = _parsePacket;
logger->handleEvent = _handleEvent;
logger->vramBlock = _vramBlock;
logger->paletteSize = GBA_SIZE_PALETTE_RAM;
logger->vramSize = GBA_SIZE_VRAM;
logger->oamSize = GBA_SIZE_OAM;
renderer->backend = backend;
}