diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-11-27 17:25:20 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-11-29 15:48:51 +0100 |
commit | 2eec5a19803a01e21d5793706ae69ac0d886cee5 (patch) | |
tree | fb0f1464f1e73eca49dd062dfd70770e84ec6b8b /platform/darwin/src/headless_backend_cgl.cpp | |
parent | 335f04f7e13422ce53cbbf13cebb8283149faba8 (diff) | |
download | qtlocation-mapboxgl-2eec5a19803a01e21d5793706ae69ac0d886cee5.tar.gz |
[core] move HeadlessBackend extension initialization code into Impl
Diffstat (limited to 'platform/darwin/src/headless_backend_cgl.cpp')
-rw-r--r-- | platform/darwin/src/headless_backend_cgl.cpp | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/platform/darwin/src/headless_backend_cgl.cpp b/platform/darwin/src/headless_backend_cgl.cpp index 6e19213f52..46a5beb870 100644 --- a/platform/darwin/src/headless_backend_cgl.cpp +++ b/platform/darwin/src/headless_backend_cgl.cpp @@ -65,8 +65,9 @@ public: CGLPixelFormatObj pixelFormat = nullptr; }; -struct CGLImpl : public HeadlessBackend::Impl { - CGLImpl() { +class CGLBackendImpl : public HeadlessBackend::Impl { +public: + CGLBackendImpl() { CGLError error = CGLCreateContext(cglDisplay->pixelFormat, nullptr, &glContext); if (error != kCGLNoError) { throw std::runtime_error(std::string("Error creating GL context object:") + @@ -80,10 +81,24 @@ struct CGLImpl : public HeadlessBackend::Impl { } } - ~CGLImpl() final { + ~CGLBackendImpl() final { CGLDestroyContext(glContext); } + gl::ProcAddress getExtensionFunctionPointer(const char* name) final { + static CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); + if (!framework) { + throw std::runtime_error("Failed to load OpenGL framework."); + } + + CFStringRef str = + CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII); + void* symbol = CFBundleGetFunctionPointerForName(framework, str); + CFRelease(str); + + return reinterpret_cast<gl::ProcAddress>(symbol); + } + void activateContext() final { CGLError error = CGLSetCurrentContext(glContext); if (error != kCGLNoError) { @@ -105,23 +120,9 @@ private: CGLContextObj glContext = nullptr; }; -gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) { - assert(hasContext()); - static CFBundleRef framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); - if (!framework) { - throw std::runtime_error("Failed to load OpenGL framework."); - } - - CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingASCII); - void* symbol = CFBundleGetFunctionPointerForName(framework, str); - CFRelease(str); - - return reinterpret_cast<gl::ProcAddress>(symbol); -} - -void HeadlessBackend::createContext() { - assert(!hasContext()); - impl = std::make_unique<CGLImpl>(); +void HeadlessBackend::createImpl() { + assert(!impl); + impl = std::make_unique<CGLBackendImpl>(); } } // namespace mbgl |