forked from organicmaps/organicmaps
Merge pull request #2602 from rokuz/present-call-safety
[ios]Improved safety of present invocations
This commit is contained in:
commit
97e264dff1
10 changed files with 41 additions and 8 deletions
|
@ -1485,9 +1485,7 @@ void FrontendRenderer::Routine::Do()
|
|||
while (availableTime > 0);
|
||||
}
|
||||
|
||||
if (m_renderer.IsRenderingEnabled())
|
||||
context->present();
|
||||
|
||||
context->present();
|
||||
frameTime = timer.ElapsedSeconds();
|
||||
timer.Reset();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace dp
|
||||
{
|
||||
class OGLContextFactory;
|
||||
class ThreadSafeFactory;
|
||||
}
|
||||
|
||||
// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
|
||||
|
@ -14,7 +14,7 @@ namespace dp
|
|||
// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
|
||||
@interface EAGLView : UIView
|
||||
{
|
||||
drape_ptr<dp::OGLContextFactory> m_factory;
|
||||
drape_ptr<dp::ThreadSafeFactory> m_factory;
|
||||
// Do not call onSize from layoutSubViews when real size wasn't changed.
|
||||
// It's possible when we add/remove subviews (bookmark balloons) and it hangs the map without this check
|
||||
CGRect lastViewSize;
|
||||
|
@ -28,5 +28,6 @@ namespace dp
|
|||
- (CGPoint)viewPoint2GlobalPoint:(CGPoint)pt;
|
||||
- (CGPoint)globalPoint2ViewPoint:(CGPoint)pt;
|
||||
- (void)initialize;
|
||||
- (void)setPresentAvailable:(BOOL)available;
|
||||
|
||||
@end
|
||||
|
|
|
@ -99,7 +99,7 @@ double getExactDPI(double contentScaleFactor)
|
|||
p.m_visualScale = dp::VisualScale(getExactDPI(self.contentScaleFactor));
|
||||
|
||||
[self.widgetsManager setupWidgets:p];
|
||||
GetFramework().CreateDrapeEngine(make_ref<dp::OGLContextFactory>(m_factory), move(p));
|
||||
GetFramework().CreateDrapeEngine(make_ref(m_factory), move(p));
|
||||
|
||||
_drapeEngineCreated = YES;
|
||||
|
||||
|
@ -173,4 +173,9 @@ double getExactDPI(double contentScaleFactor)
|
|||
return CGPointMake(ptP.x / scaleFactor, ptP.y / scaleFactor);
|
||||
}
|
||||
|
||||
- (void)setPresentAvailable:(BOOL)available
|
||||
{
|
||||
m_factory->CastFactory<iosOGLContextFactory>()->setPresentAvailable(available);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace search { struct AddressInfo; }
|
|||
- (void)onTerminate;
|
||||
- (void)onEnterForeground;
|
||||
- (void)onEnterBackground;
|
||||
- (void)onGetFocus:(BOOL)isOnFocus;
|
||||
|
||||
- (void)setMapStyle:(MapStyle)mapStyle;
|
||||
|
||||
|
|
|
@ -365,6 +365,11 @@ NSString * const kReportSegue = @"Map2ReportSegue";
|
|||
GetFramework().EnterForeground();
|
||||
}
|
||||
|
||||
- (void)onGetFocus:(BOOL)isOnFocus
|
||||
{
|
||||
[(EAGLView *)self.view setPresentAvailable:isOnFocus];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
|
|
@ -559,6 +559,7 @@ using namespace osm_auth_ios;
|
|||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application
|
||||
{
|
||||
[self.mapViewController onGetFocus: NO];
|
||||
[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: YES];
|
||||
[self handleURLs];
|
||||
[self restoreRouteState];
|
||||
[[Statistics instance] applicationDidBecomeActive];
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
|
||||
#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<bool> m_presentAvailable;
|
||||
};
|
|
@ -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,22 @@ 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));
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ public:
|
|||
|
||||
virtual bool isDrawContextCreated() const;
|
||||
virtual bool isUploadContextCreated() const;
|
||||
|
||||
void setPresentAvailable(bool available);
|
||||
|
||||
private:
|
||||
CAEAGLLayer * m_layer;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue