Fixed drape initialization on iOS

This commit is contained in:
r.kuznetsov 2015-09-09 16:49:51 +03:00
parent 5735727490
commit 69d0e045c0
7 changed files with 48 additions and 32 deletions

View file

@ -284,11 +284,18 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
case Message::SelectObject:
{
ref_ptr<SelectObjectMessage> msg = message;
ASSERT(m_selectionShape != nullptr, ());
if (msg->IsDismiss())
m_selectionShape->Hide();
{
// m_selectionShape can be null in case of deselection
if (m_selectionShape != nullptr)
m_selectionShape->Hide();
}
else
{
ASSERT(m_selectionShape != nullptr, ());
m_selectionShape->Show(msg->GetSelectedObject(), msg->GetPosition(), msg->IsAnim());
}
break;
}

View file

@ -21,7 +21,6 @@ namespace dp
CGRect lastViewSize;
}
- (void)initRenderPolicy;
- (void)deallocateNative;
- (CGPoint)viewPoint2GlobalPoint:(CGPoint)pt;
- (CGPoint)globalPoint2ViewPoint:(CGPoint)pt;

View file

@ -89,6 +89,8 @@ graphics::EDensity getDensityType(int exactDensityDPI, double scale)
if ((self = [super initWithCoder:coder]))
{
lastViewSize = CGRectZero;
// Setup Layer Properties
CAEAGLLayer * eaglLayer = (CAEAGLLayer *)self.layer;
@ -107,14 +109,13 @@ graphics::EDensity getDensityType(int exactDensityDPI, double scale)
return self;
}
- (void)initRenderPolicy
- (void)createDrapeEngineWithWidth:(int)width height:(int)height
{
NSLog(@"EAGLView initRenderPolicy Started");
NSLog(@"EAGLView createDrapeEngine Started");
CGRect frameRect = [UIScreen mainScreen].applicationFrame;
Framework::DrapeCreationParams p;
p.m_surfaceWidth = frameRect.size.width;
p.m_surfaceHeight = frameRect.size.height;
p.m_surfaceWidth = width;
p.m_surfaceHeight = height;
p.m_visualScale = self.contentScaleFactor;
/// @TODO (iOS developers) remove this stuff and create real logic for init and layout core widgets
@ -129,7 +130,7 @@ graphics::EDensity getDensityType(int exactDensityDPI, double scale)
GetFramework().CreateDrapeEngine(make_ref<dp::OGLContextFactory>(m_factory), move(p));
NSLog(@"EAGLView initRenderPolicy Ended");
NSLog(@"EAGLView createDrapeEngine Ended");
}
- (void)addSubview:(UIView *)view
@ -149,6 +150,14 @@ graphics::EDensity getDensityType(int exactDensityDPI, double scale)
{
int w = width * self.contentScaleFactor;
int h = height * self.contentScaleFactor;
if (GetFramework().GetDrapeEngine() == nullptr)
{
[self createDrapeEngineWithWidth:w height:h];
GetFramework().LoadState();
return;
}
GetFramework().OnSize(w, h);
/// @TODO (iOS developers) remove this stuff and create real logic for layout core widgets

View file

@ -412,8 +412,6 @@ typedef NS_ENUM(NSUInteger, UserTouchesAction)
- (void)viewDidLoad
{
[super viewDidLoad];
EAGLView * v = (EAGLView *)self.view;
[v initRenderPolicy];
self.view.clipsToBounds = YES;
[MTRGManager setMyCom:YES];
self.controlsManager = [[MWMMapViewControlsManager alloc] initWithParentController:self];
@ -505,15 +503,10 @@ typedef NS_ENUM(NSUInteger, UserTouchesAction)
m_StickyThreshold = 10;
EAGLView * v = (EAGLView *)self.view;
[v initRenderPolicy];
self.forceRoutingStateChange = ForceRoutingStateChangeNone;
self.userTouchesAction = UserTouchesActionNone;
self.menuRestoreState = MWMBottomMenuStateInactive;
// restore previous screen position
f.LoadState();
f.LoadBookmarks();
using TLocationStateModeFn = void (*)(id, SEL, location::EMyPositionMode);

View file

@ -56,10 +56,17 @@ void iosOGLContext::setDefaultFramebuffer()
glBindFramebuffer(GL_FRAMEBUFFER, m_frameBufferId);
}
void iosOGLContext::resize(int /*w*/, int /*h*/)
void iosOGLContext::resize(int w, int h)
{
if (m_needBuffers && m_hasBuffers)
{
GLint width = 0;
GLint height = 0;
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &width);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &height);
if (width == w && height == h)
return;
destroyBuffers();
initBuffers();
}

View file

@ -155,14 +155,12 @@ void Framework::SwitchMyPositionNextMode()
void Framework::InvalidateMyPosition()
{
ASSERT(m_drapeEngine != nullptr, ());
CallDrapeFunction(bind(&df::DrapeEngine::InvalidateMyPosition, _1));
}
void Framework::SetMyPositionModeListener(location::TMyPositionModeChanged const & fn)
{
ASSERT(m_drapeEngine != nullptr, ());
CallDrapeFunction(bind(&df::DrapeEngine::SetMyPositionModeListener, _1, fn));
m_myPositionListener = fn;
}
void Framework::OnUserPositionChanged(m2::PointD const & position)
@ -915,7 +913,6 @@ void Framework::EnterBackground()
ClearAllCaches();
#endif
ASSERT(m_drapeEngine != nullptr, ("Drape engine has not been initialized yet"));
if (m_drapeEngine != nullptr)
m_drapeEngine->SetRenderingEnabled(false);
}
@ -924,7 +921,7 @@ void Framework::EnterForeground()
{
m_startForegroundTime = my::Timer::LocalTime();
ASSERT(m_drapeEngine != nullptr, ("Drape engine has not been initialized yet"));
// Drape can be not initialized here in case of the first launch
if (m_drapeEngine != nullptr)
m_drapeEngine->SetRenderingEnabled(true);
}
@ -1272,6 +1269,9 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::OGLContextFactory> contextFactory,
m_drapeEngine->SetTapEventInfoListener(bind(&Framework::OnTapEvent, this, _1, _2, _3, _4));
m_drapeEngine->SetUserPositionListener(bind(&Framework::OnUserPositionChanged, this, _1));
OnSize(params.m_surfaceWidth, params.m_surfaceHeight);
m_drapeEngine->SetMyPositionModeListener(m_myPositionListener);
InvalidateMyPosition();
}
ref_ptr<df::DrapeEngine> Framework::GetDrapeEngine()

View file

@ -87,6 +87,9 @@ class Framework
#endif
protected:
using TDrapeFunction = function<void (df::DrapeEngine *)>;
using TDownloadCountryListener = function<void(storage::TIndex const &, int)>;
StringsBundle m_stringsBundle;
// The order matters here: storage::CountryInfoGetter must be
@ -100,25 +103,21 @@ protected:
routing::RoutingSession m_routingSession;
typedef vector<BookmarkCategory *>::iterator CategoryIter;
drape_ptr<StorageBridge> m_storageBridge;
drape_ptr<df::DrapeEngine> m_drapeEngine;
using TDrapeFunction = function<void (df::DrapeEngine *)>;
void CallDrapeFunction(TDrapeFunction const & fn);
double m_startForegroundTime;
void StopLocationFollow();
using TDownloadCountryListener = function<void(storage::TIndex const &, int)>;
TDownloadCountryListener m_downloadCountryListener;
storage::Storage m_storage;
shared_ptr<storage::ActiveMapsLayout> m_activeMaps;
storage::CountryTree m_globalCntTree;
location::TMyPositionModeChanged m_myPositionListener;
BookmarkManager m_bmManager;
/// This function is called by m_storage when latest local files
/// were changed.
void UpdateLatestCountryFile(platform::LocalCountryFile const & localFile);
@ -126,10 +125,12 @@ protected:
/// This function is called by m_model when the map file is deregistered.
void OnMapDeregistered(platform::LocalCountryFile const & localFile);
BookmarkManager m_bmManager;
void ClearAllCaches();
void StopLocationFollow();
void CallDrapeFunction(TDrapeFunction const & fn);
public:
Framework();
virtual ~Framework();