mirror of https://github.com/mgba-emu/mgba.git
SDL: Refactor out layer recentering, fix for GB
This commit is contained in:
parent
398df56ac9
commit
05bf592dec
|
@ -74,6 +74,7 @@ struct VideoShader {
|
|||
|
||||
void VideoBackendGetFrame(const struct VideoBackend*, struct mRectangle* frame);
|
||||
void VideoBackendGetFrameSize(const struct VideoBackend*, unsigned* width, unsigned* height);
|
||||
void VideoBackendRecenter(struct VideoBackend* v, unsigned scale);
|
||||
|
||||
CXX_GUARD_END
|
||||
|
||||
|
|
|
@ -23,3 +23,23 @@ void VideoBackendGetFrameSize(const struct VideoBackend* v, unsigned* width, uns
|
|||
*width = frame.width;
|
||||
*height = frame.height;
|
||||
}
|
||||
|
||||
void VideoBackendRecenter(struct VideoBackend* v, unsigned scale) {
|
||||
static const int centeredLayers[] = {VIDEO_LAYER_BACKGROUND, -1};
|
||||
struct mRectangle frame = {0};
|
||||
v->imageSize(v, VIDEO_LAYER_IMAGE, &frame.width, &frame.height);
|
||||
if (scale == 0) {
|
||||
scale = 1;
|
||||
}
|
||||
|
||||
size_t i;
|
||||
for (i = 0; centeredLayers[i] >= 0; ++i) {
|
||||
int width, height;
|
||||
struct mRectangle dims = {0};
|
||||
v->imageSize(v, centeredLayers[i], &width, &height);
|
||||
dims.width = width * scale;
|
||||
dims.height = height * scale;
|
||||
mRectangleCenter(&frame, &dims);
|
||||
v->setLayerDimensions(v, centeredLayers[i], &dims);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -658,22 +658,7 @@ void PainterGL::recenterLayers() {
|
|||
if (!m_context) {
|
||||
return;
|
||||
}
|
||||
const static std::initializer_list<VideoLayer> centeredLayers{VIDEO_LAYER_BACKGROUND};
|
||||
int width, height;
|
||||
mRectangle frame = {0};
|
||||
m_backend->imageSize(m_backend, VIDEO_LAYER_IMAGE, &width, &height);
|
||||
frame.width = width;
|
||||
frame.height = height;
|
||||
unsigned scale = std::max(1U, m_context->videoScale());
|
||||
|
||||
for (VideoLayer l : centeredLayers) {
|
||||
mRectangle dims{};
|
||||
m_backend->imageSize(m_backend, l, &width, &height);
|
||||
dims.width = width * scale;
|
||||
dims.height = height * scale;
|
||||
mRectangleCenter(&frame, &dims);
|
||||
m_backend->setLayerDimensions(m_backend, l, &dims);
|
||||
}
|
||||
VideoBackendRecenter(m_backend, std::max(1U, m_context->videoScale()));
|
||||
}
|
||||
|
||||
void PainterGL::resize(const QSize& size) {
|
||||
|
|
|
@ -135,19 +135,11 @@ void mSDLGLCommonRunloop(struct mSDLRenderer* renderer, void* user) {
|
|||
|
||||
if (mSDLGLCommonLoadBackground(v)) {
|
||||
renderer->player.windowUpdated = true;
|
||||
|
||||
struct mRectangle frame;
|
||||
v->layerDimensions(v, VIDEO_LAYER_IMAGE, &frame);
|
||||
int i;
|
||||
for (i = 0; i < VIDEO_LAYER_IMAGE; ++i) {
|
||||
struct mRectangle dims;
|
||||
v->layerDimensions(v, i, &dims);
|
||||
mRectangleCenter(&frame, &dims);
|
||||
v->setLayerDimensions(v, i, &dims);
|
||||
}
|
||||
|
||||
VideoBackendRecenter(v, 1);
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_SetWindowSize(renderer->window, frame.width * renderer->ratio, frame.height * renderer->ratio);
|
||||
int width, height;
|
||||
v->imageSize(v, VIDEO_LAYER_IMAGE, &width, &height);
|
||||
SDL_SetWindowSize(renderer->window, width * renderer->ratio, height * renderer->ratio);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -175,6 +167,7 @@ void mSDLGLCommonRunloop(struct mSDLRenderer* renderer, void* user) {
|
|||
dims.width = renderer->width;
|
||||
dims.height = renderer->height;
|
||||
v->setLayerDimensions(v, VIDEO_LAYER_IMAGE, &dims);
|
||||
VideoBackendRecenter(v, 1);
|
||||
}
|
||||
|
||||
if (mCoreSyncWaitFrameStart(&context->impl->sync)) {
|
||||
|
|
Loading…
Reference in New Issue