diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-11-27 16:34:52 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-11-29 15:48:51 +0100 |
commit | 335f04f7e13422ce53cbbf13cebb8283149faba8 (patch) | |
tree | 4542c71910cea2f626ac37325a32f9432f1d908b /platform/darwin/src/headless_backend_eagl.mm | |
parent | 772b9090626731101b82eccacbc3adaa71cc428c (diff) | |
download | qtlocation-mapboxgl-335f04f7e13422ce53cbbf13cebb8283149faba8.tar.gz |
[core] fold HeadlessDisplay into the headless RenderBackend implementation
Diffstat (limited to 'platform/darwin/src/headless_backend_eagl.mm')
-rw-r--r-- | platform/darwin/src/headless_backend_eagl.mm | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/platform/darwin/src/headless_backend_eagl.mm b/platform/darwin/src/headless_backend_eagl.mm index 1daaeaf54c..6bf5787f60 100644 --- a/platform/darwin/src/headless_backend_eagl.mm +++ b/platform/darwin/src/headless_backend_eagl.mm @@ -7,23 +7,26 @@ namespace mbgl { struct EAGLImpl : public HeadlessBackend::Impl { - EAGLImpl(EAGLContext* glContext_) : glContext(glContext_) { - [reinterpret_cast<EAGLContext*>(glContext) retain]; - reinterpret_cast<EAGLContext*>(glContext).multiThreaded = YES; + EAGLImpl() { + glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + if (glContext == nil) { + throw std::runtime_error("Error creating GL context object"); + } + glContext.multiThreaded = YES; } - ~EAGLImpl() { - [glContext release]; - } + // Required for ARC to deallocate correctly. + ~EAGLImpl() final = default; - void activateContext() { + void activateContext() final { [EAGLContext setCurrentContext:glContext]; } - void deactivateContext() { + void deactivateContext() final { [EAGLContext setCurrentContext:nil]; } +private: EAGLContext* glContext = nullptr; }; @@ -40,17 +43,9 @@ gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) { return reinterpret_cast<gl::ProcAddress>(symbol); } -bool HeadlessBackend::hasDisplay() { - return true; -} - void HeadlessBackend::createContext() { - EAGLContext* glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - if (glContext == nil) { - throw std::runtime_error("Error creating GL context object"); - } - - impl.reset(new EAGLImpl(glContext)); + assert(!hasContext()); + impl = std::make_unique<EAGLImpl>(); } } // namespace mbgl |