diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index f9bd78c6fe..bb3c79e43e 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -1471,9 +1471,7 @@ void FrontendRenderer::Routine::Do() while (availableTime > 0); } - if (m_renderer.IsRenderingEnabled()) - context->present(); - + context->present(); frameTime = timer.ElapsedSeconds(); timer.Reset(); diff --git a/iphone/Maps/Classes/EAGLView.h b/iphone/Maps/Classes/EAGLView.h index 600ce61de8..dffcb6f167 100644 --- a/iphone/Maps/Classes/EAGLView.h +++ b/iphone/Maps/Classes/EAGLView.h @@ -28,5 +28,6 @@ namespace dp - (CGPoint)viewPoint2GlobalPoint:(CGPoint)pt; - (CGPoint)globalPoint2ViewPoint:(CGPoint)pt; - (void)initialize; +- (void)setPresentAvailable:(BOOL)available; @end diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm index 6b8c1bcbcf..eb9dc73d01 100644 --- a/iphone/Maps/Classes/EAGLView.mm +++ b/iphone/Maps/Classes/EAGLView.mm @@ -173,4 +173,9 @@ double getExactDPI(double contentScaleFactor) return CGPointMake(ptP.x / scaleFactor, ptP.y / scaleFactor); } +- (void)setPresentAvailable:(BOOL)available +{ + static_cast(m_factory.get())->setPresentAvailable(available); +} + @end diff --git a/iphone/Maps/Classes/MapViewController.h b/iphone/Maps/Classes/MapViewController.h index c5c694c871..4cd5ba4d1e 100644 --- a/iphone/Maps/Classes/MapViewController.h +++ b/iphone/Maps/Classes/MapViewController.h @@ -21,6 +21,8 @@ namespace search { struct AddressInfo; } - (void)onTerminate; - (void)onEnterForeground; - (void)onEnterBackground; +- (void)onGetFocus; +- (void)onLoseFocus; - (void)setMapStyle:(MapStyle)mapStyle; diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index f98c82f85b..4fbde4b7b9 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -362,6 +362,16 @@ NSString * const kReportSegue = @"Map2ReportSegue"; GetFramework().EnterForeground(); } +- (void)onGetFocus +{ + [(EAGLView *)self.view setPresentAvailable:YES]; +} + +- (void)onLoseFocus +{ + [(EAGLView *)self.view setPresentAvailable:NO]; +} + - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 02a2647da2..8c676df85a 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -559,6 +559,7 @@ using namespace osm_auth_ios; - (void)applicationWillResignActive:(UIApplication *)application { + [self.mapViewController onLoseFocus]; [self.mapViewController.appWallAd close]; [RouteState save]; GetFramework().SetRenderingEnabled(false); @@ -585,6 +586,7 @@ using namespace osm_auth_ios; { if (application.applicationState == UIApplicationStateBackground) return; + [self.mapViewController onGetFocus]; [self handleURLs]; [self restoreRouteState]; [[Statistics instance] applicationDidBecomeActive]; diff --git a/iphone/Maps/Platform/opengl/iosOGLContext.h b/iphone/Maps/Platform/opengl/iosOGLContext.h index 24f905f551..41127e68df 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContext.h +++ b/iphone/Maps/Platform/opengl/iosOGLContext.h @@ -6,6 +6,8 @@ #import #import +#include "std/atomic.hpp" + class iosOGLContext : public dp::OGLContext { public: @@ -16,6 +18,8 @@ public: virtual void present(); virtual void setDefaultFramebuffer(); virtual void resize(int w, int h); + + void setPresentAvailable(bool available); private: CAEAGLLayer * m_layer; @@ -32,4 +36,6 @@ private: GLuint m_depthBufferId; GLuint m_frameBufferId; //@} buffers + + atomic m_presentAvailable; }; \ No newline at end of file diff --git a/iphone/Maps/Platform/opengl/iosOGLContext.mm b/iphone/Maps/Platform/opengl/iosOGLContext.mm index 0ec7e221de..e881c67426 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContext.mm +++ b/iphone/Maps/Platform/opengl/iosOGLContext.mm @@ -12,6 +12,7 @@ iosOGLContext::iosOGLContext(CAEAGLLayer * layer, iosOGLContext * contextToShare , m_renderBufferId(0) , m_depthBufferId(0) , m_frameBufferId(0) + , m_presentAvailable(true) { if (contextToShareWith != NULL) { @@ -36,16 +37,23 @@ void iosOGLContext::makeCurrent() initBuffers(); } +void iosOGLContext::setPresentAvailable(bool available) +{ + m_presentAvailable = available; +} + void iosOGLContext::present() { ASSERT(m_nativeContext != NULL, ()); ASSERT(m_renderBufferId, ()); - + GLenum const discards[] = { GL_DEPTH_ATTACHMENT, GL_COLOR_ATTACHMENT0 }; GLCHECK(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards)); glBindRenderbuffer(GL_RENDERBUFFER, m_renderBufferId); - [m_nativeContext presentRenderbuffer: GL_RENDERBUFFER]; + + if (m_presentAvailable) + [m_nativeContext presentRenderbuffer: GL_RENDERBUFFER]; GLCHECK(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discards + 1)); } diff --git a/iphone/Maps/Platform/opengl/iosOGLContextFactory.h b/iphone/Maps/Platform/opengl/iosOGLContextFactory.h index 928454ffcb..bcec895726 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContextFactory.h +++ b/iphone/Maps/Platform/opengl/iosOGLContextFactory.h @@ -14,6 +14,8 @@ public: virtual bool isDrawContextCreated() const; virtual bool isUploadContextCreated() const; + + void setPresentAvailable(bool available); private: CAEAGLLayer * m_layer; diff --git a/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm b/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm index 501f3c3ccf..60751ff34c 100644 --- a/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm +++ b/iphone/Maps/Platform/opengl/iosOGLContextFactory.mm @@ -35,3 +35,9 @@ bool iosOGLContextFactory::isUploadContextCreated() const { return m_uploadContext != nullptr; } + +void iosOGLContextFactory::setPresentAvailable(bool available) +{ + if (m_drawContext != nullptr) + m_drawContext->setPresentAvailable(available); +}