all repos — mgba @ aac1add766e8bacaa27af86b710b00cd5f67c358

mGBA Game Boy Advance Emulator

GB Video: Support mAVStream.postVideoFrame
Jeffrey Pfau jeffrey@endrift.com
Mon, 15 Feb 2016 22:04:19 -0800
commit

aac1add766e8bacaa27af86b710b00cd5f67c358

parent

245a13af63adec5b26e087950e1bb5f649f872fb

2 files changed, 40 insertions(+), 1 deletions(-)

jump to
M src/gb/renderers/software.csrc/gb/renderers/software.c

@@ -29,7 +29,7 @@ renderer->d.writePalette = GBVideoSoftwareRendererWritePalette,

renderer->d.drawRange = GBVideoSoftwareRendererDrawRange; renderer->d.finishScanline = GBVideoSoftwareRendererFinishScanline; renderer->d.finishFrame = GBVideoSoftwareRendererFinishFrame; - renderer->d.getPixels = 0; + renderer->d.getPixels = GBVideoSoftwareRendererGetPixels; renderer->d.putPixels = 0; renderer->temporaryBuffer = 0;

@@ -311,3 +311,35 @@ renderer->row[x] = p | ((tileDataUpper & 1) << 1) | (tileDataLower & 1);

} } } + +static void GBVideoSoftwareRendererGetPixels(struct GBVideoRenderer* renderer, unsigned* stride, const void** pixels) { + struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer; + // TODO: Share with GBAVideoSoftwareRendererGetPixels +#ifdef COLOR_16_BIT + *stride = GB_VIDEO_HORIZONTAL_PIXELS; + if (!softwareRenderer->temporaryBuffer) { + softwareRenderer->temporaryBuffer = anonymousMemoryMap(GB_VIDEO_HORIZONTAL_PIXELS * GB_VIDEO_VERTICAL_PIXELS * 4); + } + *pixels = softwareRenderer->temporaryBuffer; + unsigned y, x; + for (y = 0; y < GB_VIDEO_VERTICAL_PIXELS; ++y) { + for (x = 0; x < GB_VIDEO_HORIZONTAL_PIXELS; ++x) { + color_t inColor = softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y + x]; + uint32_t outColor; +#ifdef COLOR_5_6_5 + outColor = (inColor & 0x1F) << 19; + outColor |= (inColor & 0x7C0) << 5; + outColor |= (inColor & 0xF800) >> 8; +#else + outColor = (inColor & 0x1F) << 3; + outColor |= (inColor & 0x3E0) << 6; + outColor |= (inColor & 0x7C00) << 9; +#endif + softwareRenderer->temporaryBuffer[GB_VIDEO_HORIZONTAL_PIXELS * y + x] = outColor; + } + } +#else + *stride = softwareRenderer->outputBufferStride; + *pixels = softwareRenderer->outputBuffer; +#endif +}
M src/gb/video.csrc/gb/video.c

@@ -122,6 +122,13 @@ if (thread && thread->frameCallback) {

thread->frameCallback(thread); } + if (video->p->stream && video->p->stream->postVideoFrame) { + const color_t* pixels; + unsigned stride; + video->renderer->getPixels(video->renderer, &stride, (const void**) &pixels); + video->p->stream->postVideoFrame(video->p->stream, pixels, stride); + } + if (GBRegisterSTATIsVblankIRQ(video->stat) || GBRegisterSTATIsOAMIRQ(video->stat)) { video->p->memory.io[REG_IF] |= (1 << GB_IRQ_LCDSTAT); }