Core: Revise screen size/info API

This commit is contained in:
Vicki Pfau 2023-02-12 02:10:51 -08:00
parent 59ebf1c12d
commit dd531637c2
22 changed files with 125 additions and 48 deletions

View File

@ -66,7 +66,11 @@ struct mCore {
void (*loadConfig)(struct mCore*, const struct mCoreConfig*);
void (*reloadConfigOption)(struct mCore*, const char* option, const struct mCoreConfig*);
void (*desiredVideoDimensions)(const struct mCore*, unsigned* width, unsigned* height);
void (*baseVideoSize)(const struct mCore*, unsigned* width, unsigned* height);
void (*currentVideoSize)(const struct mCore*, unsigned* width, unsigned* height);
unsigned (*videoScale)(const struct mCore*);
size_t (*screenRegions)(const struct mCore*, const struct mCoreScreenRegion**);
void (*setVideoBuffer)(struct mCore*, color_t* buffer, size_t stride);
void (*setVideoGLTex)(struct mCore*, unsigned texid);

View File

@ -293,6 +293,15 @@ struct mCoreMemoryBlock {
uint32_t segmentStart;
};
struct mCoreScreenRegion {
size_t id;
const char* description;
int16_t x;
int16_t y;
int16_t w;
int16_t h;
};
enum mCoreRegisterType {
mCORE_REGISTER_GPR = 0,
mCORE_REGISTER_FPR,

View File

@ -22,6 +22,9 @@ enum {
GB_VIDEO_VBLANK_PIXELS = 10,
GB_VIDEO_VERTICAL_TOTAL_PIXELS = 154,
SGB_VIDEO_HORIZONTAL_PIXELS = 256,
SGB_VIDEO_VERTICAL_PIXELS = 224,
// TODO: Figure out exact lengths
GB_VIDEO_MODE_2_LENGTH = 80,
GB_VIDEO_MODE_3_LENGTH_BASE = 172,

View File

@ -361,7 +361,7 @@ bool mCoreTakeScreenshotVF(struct mCore* core, struct VFile* vf) {
size_t stride;
const void* pixels = 0;
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->currentVideoSize(core, &width, &height);
core->getPixels(core, &pixels, &stride);
png_structp png = PNGWriteOpen(vf);
png_infop info = PNGWriteHeader(png, width, height);

View File

@ -176,7 +176,7 @@ static bool _savePNGState(struct mCore* core, struct VFile* vf, struct mStateExt
mappedMemoryFree(state, stateSize);
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->currentVideoSize(core, &width, &height);
png_structp png = PNGWriteOpen(vf);
png_infop info = PNGWriteHeader(png, width, height);
if (!png || !info) {
@ -529,7 +529,7 @@ bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags) {
mappedMemoryFree(state, core->stateSize(core));
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->currentVideoSize(core, &width, &height);
struct mStateExtdataItem item;
if (flags & SAVESTATE_SCREENSHOT && mStateExtdataGet(&extdata, EXTDATA_SCREENSHOT, &item)) {

View File

@ -60,6 +60,15 @@ static const struct mCoreMemoryBlock _GBCMemoryBlocks[] = {
{ GB_BASE_HRAM, "hram", "HRAM", "High RAM", GB_BASE_HRAM, GB_BASE_HRAM + GB_SIZE_HRAM, GB_SIZE_HRAM, mCORE_MEMORY_RW | mCORE_MEMORY_MAPPED },
};
static const struct mCoreScreenRegion _GBScreenRegions[] = {
{ 0, "Screen", 0, 0, GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS }
};
static const struct mCoreScreenRegion _SGBScreenRegions[] = {
{ 0, "Screen", (SGB_VIDEO_HORIZONTAL_PIXELS - GB_VIDEO_HORIZONTAL_PIXELS) / 2, (SGB_VIDEO_VERTICAL_PIXELS - GB_VIDEO_VERTICAL_PIXELS) / 2, GB_VIDEO_HORIZONTAL_PIXELS, GB_VIDEO_VERTICAL_PIXELS },
{ 1, "Border", 0, 0, SGB_VIDEO_HORIZONTAL_PIXELS, SGB_VIDEO_VERTICAL_PIXELS },
};
static const struct mCoreRegisterInfo _GBRegisters[] = {
{ "b", NULL, 1, 0xFF, mCORE_REGISTER_GPR },
{ "c", NULL, 1, 0xFF, mCORE_REGISTER_GPR },
@ -355,14 +364,36 @@ static void _GBCoreReloadConfigOption(struct mCore* core, const char* option, co
}
}
static void _GBCoreDesiredVideoDimensions(const struct mCore* core, unsigned* width, unsigned* height) {
static void _GBCoreBaseVideoSize(const struct mCore* core, unsigned* width, unsigned* height) {
UNUSED(core);
*width = SGB_VIDEO_HORIZONTAL_PIXELS;
*height = SGB_VIDEO_VERTICAL_PIXELS;
}
static void _GBCoreCurrentVideoSize(const struct mCore* core, unsigned* width, unsigned* height) {
const struct GB* gb = core->board;
if (gb && (!(gb->model & GB_MODEL_SGB) || !gb->video.sgbBorders)) {
*width = GB_VIDEO_HORIZONTAL_PIXELS;
*height = GB_VIDEO_VERTICAL_PIXELS;
} else {
*width = 256;
*height = 224;
*width = SGB_VIDEO_HORIZONTAL_PIXELS;
*height = SGB_VIDEO_VERTICAL_PIXELS;
}
}
static unsigned _GBCoreVideoScale(const struct mCore* core) {
UNUSED(core);
return 1;
}
static size_t _GBCoreScreenRegions(const struct mCore* core, const struct mCoreScreenRegion** regions) {
const struct GB* gb = core->board;
if (gb && (!(gb->model & GB_MODEL_SGB) || !gb->video.sgbBorders)) {
*regions = _GBScreenRegions;
return 1;
} else {
*regions = _SGBScreenRegions;
return 2;
}
}
@ -424,7 +455,7 @@ static void _GBCoreSetAVStream(struct mCore* core, struct mAVStream* stream) {
gb->stream = stream;
if (stream && stream->videoDimensionsChanged) {
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->currentVideoSize(core, &width, &height);
stream->videoDimensionsChanged(stream, width, height);
}
if (stream && stream->audioRateChanged) {
@ -1232,7 +1263,10 @@ struct mCore* GBCoreCreate(void) {
core->setSync = _GBCoreSetSync;
core->loadConfig = _GBCoreLoadConfig;
core->reloadConfigOption = _GBCoreReloadConfigOption;
core->desiredVideoDimensions = _GBCoreDesiredVideoDimensions;
core->baseVideoSize = _GBCoreBaseVideoSize;
core->currentVideoSize = _GBCoreCurrentVideoSize;
core->videoScale = _GBCoreVideoScale;
core->screenRegions = _GBCoreScreenRegions;
core->setVideoBuffer = _GBCoreSetVideoBuffer;
core->setVideoGLTex = _GBCoreSetVideoGLTex;
core->getPixels = _GBCoreGetPixels;

View File

@ -129,6 +129,10 @@ static const struct mCoreMemoryBlock _GBAMemoryBlocksEEPROM[] = {
{ GBA_REGION_SRAM_MIRROR, "eeprom", "EEPROM", "EEPROM (8kiB)", 0, GBA_SIZE_EEPROM, GBA_SIZE_EEPROM, mCORE_MEMORY_RW },
};
static const struct mCoreScreenRegion _GBAScreenRegions[] = {
{ 0, "Screen", 0, 0, GBA_VIDEO_HORIZONTAL_PIXELS, GBA_VIDEO_VERTICAL_PIXELS }
};
static const struct mCoreRegisterInfo _GBARegisters[] = {
{ "r0", NULL, 4, 0xFFFFFFFF, mCORE_REGISTER_GPR },
{ "r1", NULL, 4, 0xFFFFFFFF, mCORE_REGISTER_GPR },
@ -422,19 +426,45 @@ static void _GBACoreReloadConfigOption(struct mCore* core, const char* option, c
}
}
static void _GBACoreDesiredVideoDimensions(const struct mCore* core, unsigned* width, unsigned* height) {
static void _GBACoreBaseVideoSize(const struct mCore* core, unsigned* width, unsigned* height) {
UNUSED(core);
*width = GBA_VIDEO_HORIZONTAL_PIXELS;
*height = GBA_VIDEO_VERTICAL_PIXELS;
}
static void _GBACoreCurrentVideoSize(const struct mCore* core, unsigned* width, unsigned* height) {
int scale = 1;
#ifdef BUILD_GLES3
const struct GBACore* gbacore = (const struct GBACore*) core;
int scale = gbacore->glRenderer.scale;
if (gbacore->glRenderer.outputTex != (unsigned) -1) {
scale = gbacore->glRenderer.scale;
}
#else
UNUSED(core);
int scale = 1;
#endif
*width = GBA_VIDEO_HORIZONTAL_PIXELS * scale;
*height = GBA_VIDEO_VERTICAL_PIXELS * scale;
}
static unsigned _GBACoreVideoScale(const struct mCore* core) {
#ifdef BUILD_GLES3
const struct GBACore* gbacore = (const struct GBACore*) core;
if (gbacore->glRenderer.outputTex != (unsigned) -1) {
return gbacore->glRenderer.scale;
}
#else
UNUSED(core);
#endif
return 1;
}
static size_t _GBACoreScreenRegions(const struct mCore* core, const struct mCoreScreenRegion** regions) {
UNUSED(core);
*regions = _GBAScreenRegions;
return 1;
}
static void _GBACoreSetVideoBuffer(struct mCore* core, color_t* buffer, size_t stride) {
struct GBACore* gbacore = (struct GBACore*) core;
gbacore->renderer.outputBuffer = buffer;
@ -500,7 +530,7 @@ static void _GBACoreSetAVStream(struct mCore* core, struct mAVStream* stream) {
gba->stream = stream;
if (stream && stream->videoDimensionsChanged) {
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->currentVideoSize(core, &width, &height);
stream->videoDimensionsChanged(stream, width, height);
}
if (stream && stream->audioRateChanged) {
@ -1358,7 +1388,10 @@ struct mCore* GBACoreCreate(void) {
core->setSync = _GBACoreSetSync;
core->loadConfig = _GBACoreLoadConfig;
core->reloadConfigOption = _GBACoreReloadConfigOption;
core->desiredVideoDimensions = _GBACoreDesiredVideoDimensions;
core->baseVideoSize = _GBACoreBaseVideoSize;
core->currentVideoSize = _GBACoreCurrentVideoSize;
core->videoScale = _GBACoreVideoScale;
core->screenRegions = _GBACoreScreenRegions;
core->setVideoBuffer = _GBACoreSetVideoBuffer;
core->setVideoGLTex = _GBACoreSetVideoGLTex;
core->getPixels = _GBACoreGetPixels;

View File

@ -496,7 +496,7 @@ static void _drawTex(struct mCore* core, bool faded, bool both) {
int wide = isWide ? 2 : 1;
unsigned corew, coreh;
core->desiredVideoDimensions(core, &corew, &coreh);
core->currentVideoSize(core, &corew, &coreh);
int w = corew;
int h = coreh;

View File

@ -83,7 +83,7 @@ bool _mExampleRun(const struct mArguments* args, Socket client) {
// Get the dimensions required for this core and send them to the client.
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->baseVideoSize(core, &width, &height);
ssize_t bufferSize = width * height * BYTES_PER_PIXEL;
uint32_t sendNO;
sendNO = htonl(width);

View File

@ -414,19 +414,13 @@ void retro_get_system_info(struct retro_system_info* info) {
void retro_get_system_av_info(struct retro_system_av_info* info) {
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->currentVideoSize(core, &width, &height);
info->geometry.base_width = width;
info->geometry.base_height = height;
#ifdef M_CORE_GB
if (core->platform(core) == mPLATFORM_GB) {
info->geometry.max_width = 256;
info->geometry.max_height = 224;
} else
#endif
{
info->geometry.max_width = width;
info->geometry.max_height = height;
}
core->baseVideoSize(core, &width, &height);
info->geometry.max_width = width;
info->geometry.max_height = height;
info->geometry.aspect_ratio = width / (double) height;
info->timing.fps = core->frequency(core) / (float) core->frameCycles(core);
@ -614,7 +608,7 @@ void retro_run(void) {
core->runFrame(core);
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->currentVideoSize(core, &width, &height);
videoCallback(outputBuffer, width, height, BYTES_PER_PIXEL * 256);
#ifdef M_CORE_GBA

View File

@ -68,7 +68,7 @@
outputBuffer = nil;
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->baseVideoSize(core, &width, &height);
outputBuffer = malloc(width * height * BYTES_PER_PIXEL);
core->setVideoBuffer(core, outputBuffer, width);
core->setAudioBufferSize(core, SAMPLES);
@ -143,14 +143,14 @@
- (OEIntRect)screenRect
{
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->currentVideoSize(core, &width, &height);
return OEIntRectMake(0, 0, width, height);
}
- (OEIntSize)bufferSize
{
unsigned width, height;
core->desiredVideoDimensions(core, &width, &height);
core->baseVideoSize(core, &width, &height);
return OEIntSizeMake(width, height);
}

View File

@ -323,7 +323,7 @@ void mPSP2Setup(struct mGUIRunner* runner) {
mInputBindAxis(&runner->core->inputMap, PSP2_INPUT, 1, &desc);
unsigned width, height;
runner->core->desiredVideoDimensions(runner->core, &width, &height);
runner->core->baseVideoSize(runner->core, &width, &height);
tex[0] = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR);
tex[1] = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR);
currentTex = 0;
@ -614,7 +614,7 @@ void mPSP2Swap(struct mGUIRunner* runner) {
void mPSP2Draw(struct mGUIRunner* runner, bool faded) {
unsigned width, height;
runner->core->desiredVideoDimensions(runner->core, &width, &height);
runner->core->currentVideoSize(runner->core, &width, &height);
if (interframeBlending) {
_drawTex(tex[!currentTex], width, height, faded, false);
}

View File

@ -235,7 +235,7 @@ class Core(object):
def desired_video_dimensions(self):
width = ffi.new("unsigned*")
height = ffi.new("unsigned*")
self._core.desiredVideoDimensions(self._core, width, height)
self._core.currentVideoSize(self._core, width, height)
return width[0], height[0]
@protected

View File

@ -266,7 +266,7 @@ mPlatform CoreController::platform() const {
QSize CoreController::screenDimensions() const {
unsigned width, height;
m_threadContext.core->desiredVideoDimensions(m_threadContext.core, &width, &height);
m_threadContext.core->currentVideoSize(m_threadContext.core, &width, &height);
return QSize(width, height);
}
@ -1186,7 +1186,7 @@ int CoreController::updateAutofire() {
void CoreController::finishFrame() {
if (!m_hwaccel) {
unsigned width, height;
m_threadContext.core->desiredVideoDimensions(m_threadContext.core, &width, &height);
m_threadContext.core->currentVideoSize(m_threadContext.core, &width, &height);
QMutexLocker locker(&m_bufferMutex);
memcpy(m_completeBuffer.data(), m_activeBuffer.constData(), width * height * BYTES_PER_PIXEL);

View File

@ -559,7 +559,7 @@ void FrameView::newVl() {
}
#endif
unsigned width, height;
m_vl->desiredVideoDimensions(m_vl, &width, &height);
m_vl->baseVideoSize(m_vl, &width, &height);
m_framebuffer = QImage(width, height, QImage::Format_RGBX8888);
m_vl->setVideoBuffer(m_vl, reinterpret_cast<color_t*>(m_framebuffer.bits()), width);
m_vl->reset(m_vl);

View File

@ -64,7 +64,7 @@ void mSDLGLRunloop(struct mSDLRenderer* renderer, void* user) {
renderer->player.windowUpdated = 0;
}
}
renderer->core->desiredVideoDimensions(renderer->core, &renderer->width, &renderer->height);
renderer->core->currentVideoSize(renderer->core, &renderer->width, &renderer->height);
if (renderer->width != v->width || renderer->height != v->height) {
renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, renderer->width);
v->setDimensions(v, renderer->width, renderer->height);

View File

@ -107,7 +107,7 @@ int main(int argc, char** argv) {
return 1;
}
renderer.core->desiredVideoDimensions(renderer.core, &renderer.width, &renderer.height);
renderer.core->baseVideoSize(renderer.core, &renderer.width, &renderer.height);
renderer.ratio = graphicsOpts.multiplier;
if (renderer.ratio == 0) {
renderer.ratio = 1;
@ -275,7 +275,7 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
if (!didFail) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
renderer->core->desiredVideoDimensions(renderer->core, &renderer->width, &renderer->height);
renderer->core->currentVideoSize(renderer->core, &renderer->width, &renderer->height);
unsigned width = renderer->width * renderer->ratio;
unsigned height = renderer->height * renderer->ratio;
if (width != (unsigned) renderer->viewportWidth && height != (unsigned) renderer->viewportHeight) {

View File

@ -28,7 +28,7 @@ bool mSDLSWInit(struct mSDLRenderer* renderer) {
SDL_WM_SetCaption(projectName, "");
unsigned width, height;
renderer->core->desiredVideoDimensions(renderer->core, &width, &height);
renderer->core->baseVideoSize(renderer->core, &width, &height);
SDL_Surface* surface = SDL_GetVideoSurface();
SDL_LockSurface(surface);

View File

@ -21,7 +21,7 @@ void mSDLSWCreate(struct mSDLRenderer* renderer) {
bool mSDLSWInit(struct mSDLRenderer* renderer) {
unsigned width, height;
renderer->core->desiredVideoDimensions(renderer->core, &width, &height);
renderer->core->baseVideoSize(renderer->core, &width, &height);
renderer->window = SDL_CreateWindow(projectName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->player.fullscreen));
SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);
renderer->player.window = renderer->window;

View File

@ -477,7 +477,7 @@ static void _drawFrame(struct mGUIRunner* runner, bool faded) {
}
unsigned width, height;
runner->core->desiredVideoDimensions(runner->core, &width, &height);
runner->core->currentVideoSize(runner->core, &width, &height);
glActiveTexture(GL_TEXTURE0);
if (usePbo) {
@ -530,7 +530,7 @@ static void _drawScreenshot(struct mGUIRunner* runner, const color_t* pixels, un
glBindTexture(GL_TEXTURE_2D, screenshotTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
runner->core->desiredVideoDimensions(runner->core, &width, &height);
runner->core->currentVideoSize(runner->core, &width, &height);
glDisable(GL_BLEND);
bool wasPbo = usePbo;
usePbo = false;

View File

@ -1032,7 +1032,7 @@ void CInemaTestRun(struct CInemaTest* test) {
return;
}
struct CInemaImage image;
core->desiredVideoDimensions(core, &image.width, &image.height);
core->baseVideoSize(core, &image.width, &image.height);
ssize_t bufferSize = image.width * image.height * BYTES_PER_PIXEL;
image.data = malloc(bufferSize);
image.stride = image.width;
@ -1075,7 +1075,7 @@ void CInemaTestRun(struct CInemaTest* test) {
for (frame = 0; frame < skip; ++frame) {
core->runFrame(core);
}
core->desiredVideoDimensions(core, &image.width, &image.height);
core->currentVideoSize(core, &image.width, &image.height);
#ifdef USE_FFMPEG
struct FFmpegDecoder decoder;
@ -1139,7 +1139,7 @@ void CInemaTestRun(struct CInemaTest* test) {
break;
}
CIlog(3, "Test frame: %u\n", frameCounter);
core->desiredVideoDimensions(core, &image.width, &image.height);
core->currentVideoSize(core, &image.width, &image.height);
uint8_t* diff = NULL;
struct CInemaImage expected = {
.data = NULL,

View File

@ -1511,7 +1511,7 @@ void _prepareForFrame(struct mGUIRunner* runner) {
}
void _drawFrame(struct mGUIRunner* runner, bool faded) {
runner->core->desiredVideoDimensions(runner->core, &corew, &coreh);
runner->core->currentVideoSize(runner->core, &corew, &coreh);
uint32_t color = 0xFFFFFF3F;
if (!faded) {
color |= 0xC0;