From dd950fdb22dcc3d4be06ed416c09b6fb438144c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Be=CC=81nony?= Date: Tue, 8 Dec 2015 11:04:04 +0100 Subject: [PATCH] IOS: Removes a global variable --- backends/platform/ios7/iOS7AppDelegate.h | 6 ++++++ backends/platform/ios7/iOS7AppDelegate.mm | 10 ++++++++++ backends/platform/ios7/ios7_osys_video.mm | 23 ++++++++++++----------- backends/platform/ios7/ios7_video.h | 2 -- backends/platform/ios7/ios7_video.mm | 8 +++----- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/backends/platform/ios7/iOS7AppDelegate.h b/backends/platform/ios7/iOS7AppDelegate.h index 49411698c16e..7f903a692db6 100644 --- a/backends/platform/ios7/iOS7AppDelegate.h +++ b/backends/platform/ios7/iOS7AppDelegate.h @@ -4,6 +4,12 @@ #import +@class iPhoneView; + @interface iOS7AppDelegate : NSObject + ++ (iOS7AppDelegate *)iOS7AppDelegate; ++ (iPhoneView *)iPhoneView; + @end diff --git a/backends/platform/ios7/iOS7AppDelegate.mm b/backends/platform/ios7/iOS7AppDelegate.mm index 784566228c7f..0f645e505545 100644 --- a/backends/platform/ios7/iOS7AppDelegate.mm +++ b/backends/platform/ios7/iOS7AppDelegate.mm @@ -76,6 +76,16 @@ - (void)didRotate:(NSNotification *)notification { [_view deviceOrientationChanged:screenOrientation]; } ++ (iOS7AppDelegate *)iOS7AppDelegate { + UIApplication *app = [UIApplication sharedApplication]; + return (iOS7AppDelegate *) app.delegate; +} + ++ (iPhoneView *)iPhoneView { + iOS7AppDelegate *appDelegate = [self iOS7AppDelegate]; + return appDelegate->_view; +} + @end const char *iOS7_getDocumentsDir() { diff --git a/backends/platform/ios7/ios7_osys_video.mm b/backends/platform/ios7/ios7_osys_video.mm index 4835ef5638df..e2ac189baa10 100644 --- a/backends/platform/ios7/ios7_osys_video.mm +++ b/backends/platform/ios7/ios7_osys_video.mm @@ -27,9 +27,10 @@ #include "ios7_video.h" #include "graphics/conversion.h" +#import "iOS7AppDelegate.h" void OSystem_iOS7::initVideoContext() { - _videoContext = [g_iPhoneViewInstance getVideoContext]; + _videoContext = [[iOS7AppDelegate iPhoneView] getVideoContext]; } const OSystem::GraphicsMode *OSystem_iOS7::getSupportedGraphicsModes() const { @@ -82,7 +83,7 @@ // Create the screen texture right here. We need to do this here, since // when a game requests hi-color mode, we actually set the framebuffer // to the texture buffer to avoid an additional copy step. - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(createScreenTexture) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(createScreenTexture) withObject:nil waitUntilDone: YES]; // In case the client code tries to set up a non supported mode, we will // fall back to CLUT8 and set the transaction error accordingly. @@ -119,13 +120,13 @@ OSystem::TransactionError OSystem_iOS7::endGFXTransaction() { _screenChangeCount++; updateOutputSurface(); - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES]; return _gfxTransactionError; } void OSystem_iOS7::updateOutputSurface() { - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES]; } int16 OSystem_iOS7::getHeight() { @@ -285,7 +286,7 @@ void OSystem_iOS7::setShakePos(int shakeOffset) { //printf("setShakePos(%i)\n", shakeOffset); _videoContext->shakeOffsetY = shakeOffset; - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES]; // HACK: We use this to force a redraw. _mouseDirty = true; } @@ -295,8 +296,8 @@ _videoContext->overlayVisible = true; dirtyFullOverlayScreen(); updateScreen(); - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES]; - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; } void OSystem_iOS7::hideOverlay() { @@ -304,8 +305,8 @@ _videoContext->overlayVisible = false; _dirtyOverlayRects.clear(); dirtyFullScreen(); - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES]; - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; } void OSystem_iOS7::clearOverlay() { @@ -386,7 +387,7 @@ //printf("warpMouse(%d, %d)\n", x, y); _videoContext->mouseX = x; _videoContext->mouseY = y; - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(notifyMouseMove) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(notifyMouseMove) withObject:nil waitUntilDone: YES]; _mouseDirty = true; } @@ -499,5 +500,5 @@ } } - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; } diff --git a/backends/platform/ios7/ios7_video.h b/backends/platform/ios7/ios7_video.h index 63a570d19d62..09a84b54987c 100644 --- a/backends/platform/ios7/ios7_video.h +++ b/backends/platform/ios7/ios7_video.h @@ -104,6 +104,4 @@ @end -extern iPhoneView *g_iPhoneViewInstance; - #endif diff --git a/backends/platform/ios7/ios7_video.mm b/backends/platform/ios7/ios7_video.mm index dbb750362c4c..1a2ae5ee91f2 100644 --- a/backends/platform/ios7/ios7_video.mm +++ b/backends/platform/ios7/ios7_video.mm @@ -27,8 +27,8 @@ #include "graphics/colormasks.h" #include "common/system.h" +#import "iOS7AppDelegate.h" -iPhoneView *g_iPhoneViewInstance = nil; static int g_fullWidth; static int g_fullHeight; @@ -62,12 +62,12 @@ void iOS7_updateScreen() { //printf("Mouse: (%i, %i)\n", mouseX, mouseY); if (!g_needsScreenUpdate) { g_needsScreenUpdate = 1; - [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateSurface) withObject:nil waitUntilDone: NO]; + [[iOS7AppDelegate iPhoneView] performSelectorOnMainThread:@selector(updateSurface) withObject:nil waitUntilDone: NO]; } } bool iOS7_fetchEvent(InternalEvent *event) { - return [g_iPhoneViewInstance fetchEvent:event]; + return [[iOS7AppDelegate iPhoneView] fetchEvent:event]; } uint getSizeNextPOT(uint size) { @@ -233,8 +233,6 @@ - (id)initWithFrame:(struct CGRect)frame { _contentScaleFactor = [self optimalScale]; [self setContentScaleFactor:_contentScaleFactor]; - g_iPhoneViewInstance = self; - _keyboardView = nil; _screenTexture = 0; _overlayTexture = 0;