[core] fold HeadlessDisplay into the headless RenderBackend implementation

This commit is contained in:
Konstantin Käfer
2017-11-27 16:34:52 +01:00
parent 772b909062
commit 335f04f7e1
17 changed files with 288 additions and 445 deletions

View File

@@ -8,10 +8,18 @@
namespace mbgl {
struct OSMesaImpl : public HeadlessBackend::Impl {
OSMesaImpl(OSMesaContext glContext_) : glContext(glContext_) {
OSMesaImpl() {
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
glContext = OSMesaCreateContextExt(OSMESA_RGBA, 16, 0, 0, nullptr);
#else
glContext = OSMesaCreateContext(OSMESA_RGBA, nullptr);
#endif
if (glContext == nullptr) {
throw std::runtime_error("Error creating GL context object.");
}
}
~OSMesaImpl() {
~OSMesaImpl() final {
OSMesaDestroyContext(glContext);
}
@@ -21,6 +29,7 @@ struct OSMesaImpl : public HeadlessBackend::Impl {
}
}
private:
OSMesaContext glContext = nullptr;
GLubyte fakeBuffer = 0;
};
@@ -29,23 +38,9 @@ gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) {
return OSMesaGetProcAddress(name);
}
bool HeadlessBackend::hasDisplay() {
return true;
};
void HeadlessBackend::createContext() {
assert(!hasContext());
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
OSMesaContext glContext = OSMesaCreateContextExt(OSMESA_RGBA, 16, 0, 0, nullptr);
#else
OSMesaContext glContext = OSMesaCreateContext(OSMESA_RGBA, nullptr);
#endif
if (glContext == nullptr) {
throw std::runtime_error("Error creating GL context object.");
}
impl.reset(new OSMesaImpl(glContext));
impl = std::make_unique<OSMesaImpl>();
}
} // namespace mbgl

View File

@@ -1,5 +1,4 @@
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/gl/headless_display.hpp>
#include <mbgl/gl/context.hpp>
#include <mbgl/renderer/backend_scope.hpp>
@@ -36,9 +35,6 @@ void HeadlessBackend::activate() {
active = true;
if (!hasContext()) {
if (!hasDisplay()) {
throw std::runtime_error("Display is not set");
}
createContext();
}

View File

@@ -7,8 +7,6 @@
namespace mbgl {
class HeadlessDisplay;
class HeadlessBackend : public RendererBackend {
public:
HeadlessBackend(Size = { 256, 256 });
@@ -35,11 +33,9 @@ private:
void deactivate() override;
bool hasContext() const { return bool(impl); }
bool hasDisplay();
void createContext();
std::shared_ptr<HeadlessDisplay> display;
std::unique_ptr<Impl> impl;
Size size;

View File

@@ -1,15 +0,0 @@
#include <mbgl/gl/headless_display.hpp>
namespace mbgl {
class HeadlessDisplay::Impl {};
HeadlessDisplay::HeadlessDisplay() {
// no-op
}
HeadlessDisplay::~HeadlessDisplay() {
// no-op
}
} // namespace mbgl

View File

@@ -1,34 +0,0 @@
#pragma once
#include <memory>
namespace mbgl {
class HeadlessDisplay {
public:
static std::shared_ptr<HeadlessDisplay> create() {
static std::weak_ptr<HeadlessDisplay> instance;
auto shared = instance.lock();
if (!shared) {
instance = shared = std::shared_ptr<HeadlessDisplay>(new HeadlessDisplay());
}
return shared;
}
~HeadlessDisplay();
template <typename DisplayAttribute>
DisplayAttribute attribute() const;
private:
HeadlessDisplay();
class Impl;
std::unique_ptr<Impl> impl;
};
} // namespace mbgl