summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/gfx/renderer_backend.hpp14
-rw-r--r--include/mbgl/gl/renderer_backend.hpp2
-rw-r--r--include/mbgl/renderer/mode.hpp18
-rw-r--r--include/mbgl/renderer/renderer.hpp2
-rwxr-xr-xplatform/android/src/android_renderer_backend.cpp3
-rw-r--r--platform/android/src/map_renderer.cpp3
-rw-r--r--platform/darwin/src/MGLRendererConfiguration.h4
-rw-r--r--platform/darwin/src/MGLRendererConfiguration.mm4
-rw-r--r--platform/default/include/mbgl/gl/headless_backend.hpp2
-rw-r--r--platform/default/include/mbgl/gl/headless_frontend.hpp14
-rw-r--r--platform/default/src/mbgl/gl/headless_backend.cpp4
-rw-r--r--platform/default/src/mbgl/gl/headless_frontend.cpp24
-rw-r--r--platform/default/src/mbgl/map/map_snapshotter.cpp15
-rw-r--r--platform/glfw/glfw_gl_backend.cpp3
-rw-r--r--platform/ios/src/MGLMapView.mm11
-rw-r--r--platform/macos/src/MGLMapView.mm11
-rw-r--r--platform/qt/src/qmapboxgl.cpp4
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.cpp3
-rw-r--r--platform/qt/src/qmapboxgl_renderer_backend.cpp5
-rw-r--r--platform/qt/src/qmapboxgl_renderer_backend.hpp2
-rw-r--r--src/core-files.json1
-rw-r--r--src/mbgl/gfx/renderer_backend.cpp4
-rw-r--r--src/mbgl/gl/renderer_backend.cpp4
-rw-r--r--src/mbgl/renderer/paint_parameters.cpp2
-rw-r--r--src/mbgl/renderer/paint_parameters.hpp3
-rw-r--r--src/mbgl/renderer/renderer.cpp8
-rw-r--r--src/mbgl/renderer/renderer_impl.cpp12
-rw-r--r--src/mbgl/renderer/renderer_impl.hpp9
-rw-r--r--test/gl/context.test.cpp2
-rw-r--r--test/renderer/backend_scope.test.cpp5
-rw-r--r--test/text/local_glyph_rasterizer.test.cpp2
31 files changed, 104 insertions, 96 deletions
diff --git a/include/mbgl/gfx/renderer_backend.hpp b/include/mbgl/gfx/renderer_backend.hpp
index 032c7021da..29f6b43a8f 100644
--- a/include/mbgl/gfx/renderer_backend.hpp
+++ b/include/mbgl/gfx/renderer_backend.hpp
@@ -12,10 +12,15 @@ class Context;
class Renderable;
class BackendScope;
-// TODO: Rename to "Device"
+// We can make some optimizations if we know that the drawing context is not shared with other code.
+enum class ContextMode : bool {
+ Unique,
+ Shared,
+};
+
class RendererBackend {
protected:
- explicit RendererBackend();
+ explicit RendererBackend(ContextMode);
public:
virtual ~RendererBackend();
@@ -25,6 +30,10 @@ public:
// Returns the device's context.
Context& getContext();
+ bool contextIsShared() const {
+ return contextMode == ContextMode::Shared;
+ }
+
// Returns a reference to the default surface that should be rendered on.
virtual Renderable& getDefaultRenderable() = 0;
@@ -44,6 +53,7 @@ protected:
protected:
std::unique_ptr<Context> context;
+ const ContextMode contextMode;
std::once_flag initialized;
friend class BackendScope;
diff --git a/include/mbgl/gl/renderer_backend.hpp b/include/mbgl/gl/renderer_backend.hpp
index 7ef8759477..ba87e4ce4f 100644
--- a/include/mbgl/gl/renderer_backend.hpp
+++ b/include/mbgl/gl/renderer_backend.hpp
@@ -14,7 +14,7 @@ using FramebufferID = uint32_t;
class RendererBackend : public gfx::RendererBackend {
public:
- RendererBackend();
+ RendererBackend(gfx::ContextMode);
~RendererBackend() override;
// Returns the backend's context which manages OpenGL state.
diff --git a/include/mbgl/renderer/mode.hpp b/include/mbgl/renderer/mode.hpp
deleted file mode 100644
index 6ff42d8058..0000000000
--- a/include/mbgl/renderer/mode.hpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-
-#include <cstdint>
-
-namespace mbgl {
-
-using EnumType = uint32_t;
-
-// We can avoid redundant GL calls when it is known that the GL context is not
-// being shared. In a shared GL context case, we need to make sure that the
-// correct GL configurations are in use - they might have changed between render
-// calls.
-enum class GLContextMode : EnumType {
- Unique,
- Shared,
-};
-
-} // namespace mbgl
diff --git a/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp
index aa06210804..f50946aed1 100644
--- a/include/mbgl/renderer/renderer.hpp
+++ b/include/mbgl/renderer/renderer.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/renderer/query.hpp>
-#include <mbgl/renderer/mode.hpp>
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/geojson.hpp>
@@ -26,7 +25,6 @@ class RendererBackend;
class Renderer {
public:
Renderer(gfx::RendererBackend&, float pixelRatio_, Scheduler&,
- GLContextMode = GLContextMode::Unique,
const optional<std::string> programCacheDir = {},
const optional<std::string> localFontFamily = {});
~Renderer();
diff --git a/platform/android/src/android_renderer_backend.cpp b/platform/android/src/android_renderer_backend.cpp
index 09c9e85ad5..3fba0b83da 100755
--- a/platform/android/src/android_renderer_backend.cpp
+++ b/platform/android/src/android_renderer_backend.cpp
@@ -27,7 +27,8 @@ private:
};
AndroidRendererBackend::AndroidRendererBackend()
- : mbgl::gfx::Renderable({ 64, 64 }, std::make_unique<AndroidGLRenderableResource>(*this)) {
+ : gl::RendererBackend(gfx::ContextMode::Unique),
+ mbgl::gfx::Renderable({ 64, 64 }, std::make_unique<AndroidGLRenderableResource>(*this)) {
}
AndroidRendererBackend::~AndroidRendererBackend() = default;
diff --git a/platform/android/src/map_renderer.cpp b/platform/android/src/map_renderer.cpp
index 7fefa457b1..36d23c1849 100644
--- a/platform/android/src/map_renderer.cpp
+++ b/platform/android/src/map_renderer.cpp
@@ -175,8 +175,7 @@ void MapRenderer::onSurfaceCreated(JNIEnv&) {
// Create the new backend and renderer
backend = std::make_unique<AndroidRendererBackend>();
- renderer = std::make_unique<Renderer>(*backend, pixelRatio, *threadPool,
- GLContextMode::Unique, programCacheDir, localIdeographFontFamily);
+ renderer = std::make_unique<Renderer>(*backend, pixelRatio, *threadPool, programCacheDir, localIdeographFontFamily);
rendererRef = std::make_unique<ActorRef<Renderer>>(*renderer, mailbox);
// Set the observer on the new Renderer implementation
diff --git a/platform/darwin/src/MGLRendererConfiguration.h b/platform/darwin/src/MGLRendererConfiguration.h
index ef7122ec51..ee5aaef174 100644
--- a/platform/darwin/src/MGLRendererConfiguration.h
+++ b/platform/darwin/src/MGLRendererConfiguration.h
@@ -1,7 +1,6 @@
#import "MGLFoundation.h"
#import <Foundation/Foundation.h>
-#include <mbgl/renderer/mode.hpp>
#include <mbgl/util/optional.hpp>
NS_ASSUME_NONNULL_BEGIN
@@ -16,9 +15,6 @@ MGL_EXPORT
/** Returns an instance of the current renderer configuration. */
@property (class, nonatomic, readonly) MGLRendererConfiguration *currentConfiguration;
-/** The GL context mode to use. Defaults to `mbgl::GLContextMode::Unique` */
-@property (nonatomic, readonly) mbgl::GLContextMode contextMode;
-
/** The scale factor to use.
Based on the native scale where available, otherwise the standard screen scale. */
diff --git a/platform/darwin/src/MGLRendererConfiguration.mm b/platform/darwin/src/MGLRendererConfiguration.mm
index 78201987fe..d616e93eb2 100644
--- a/platform/darwin/src/MGLRendererConfiguration.mm
+++ b/platform/darwin/src/MGLRendererConfiguration.mm
@@ -57,10 +57,6 @@ static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPr
return self;
}
-- (mbgl::GLContextMode)contextMode {
- return mbgl::GLContextMode::Unique;
-}
-
- (const float)scaleFactor {
#if TARGET_OS_IPHONE
return [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale];
diff --git a/platform/default/include/mbgl/gl/headless_backend.hpp b/platform/default/include/mbgl/gl/headless_backend.hpp
index 9135c269be..b2141e9540 100644
--- a/platform/default/include/mbgl/gl/headless_backend.hpp
+++ b/platform/default/include/mbgl/gl/headless_backend.hpp
@@ -11,7 +11,7 @@ namespace gl {
class HeadlessBackend final : public gl::RendererBackend, public gfx::Renderable {
public:
- HeadlessBackend(Size = { 256, 256 });
+ HeadlessBackend(Size = { 256, 256 }, gfx::ContextMode = gfx::ContextMode::Unique);
~HeadlessBackend() override;
gfx::Renderable& getDefaultRenderable() override;
diff --git a/platform/default/include/mbgl/gl/headless_frontend.hpp b/platform/default/include/mbgl/gl/headless_frontend.hpp
index 2e9378bf8f..ff733f423d 100644
--- a/platform/default/include/mbgl/gl/headless_frontend.hpp
+++ b/platform/default/include/mbgl/gl/headless_frontend.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/map/camera.hpp>
-#include <mbgl/renderer/mode.hpp>
#include <mbgl/renderer/renderer_frontend.hpp>
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/util/async_task.hpp>
@@ -22,8 +21,17 @@ class RendererBackend;
class HeadlessFrontend : public RendererFrontend {
public:
- HeadlessFrontend(float pixelRatio_, Scheduler&, const optional<std::string> programCacheDir = {}, GLContextMode mode = GLContextMode::Unique, const optional<std::string> localFontFamily = {});
- HeadlessFrontend(Size, float pixelRatio_, Scheduler&, const optional<std::string> programCacheDir = {}, GLContextMode mode = GLContextMode::Unique, const optional<std::string> localFontFamily = {});
+ HeadlessFrontend(float pixelRatio_,
+ Scheduler&,
+ const optional<std::string> programCacheDir = {},
+ gfx::ContextMode mode = gfx::ContextMode::Unique,
+ const optional<std::string> localFontFamily = {});
+ HeadlessFrontend(Size,
+ float pixelRatio_,
+ Scheduler&,
+ const optional<std::string> programCacheDir = {},
+ gfx::ContextMode mode = gfx::ContextMode::Unique,
+ const optional<std::string> localFontFamily = {});
~HeadlessFrontend() override;
void reset() override;
diff --git a/platform/default/src/mbgl/gl/headless_backend.cpp b/platform/default/src/mbgl/gl/headless_backend.cpp
index cbf451d80b..7362adcb9e 100644
--- a/platform/default/src/mbgl/gl/headless_backend.cpp
+++ b/platform/default/src/mbgl/gl/headless_backend.cpp
@@ -31,8 +31,8 @@ public:
gl::Framebuffer framebuffer;
};
-HeadlessBackend::HeadlessBackend(Size size_)
- : mbgl::gfx::Renderable(size_, nullptr) {
+HeadlessBackend::HeadlessBackend(const Size size_, const gfx::ContextMode contextMode_)
+ : mbgl::gl::RendererBackend(contextMode_), mbgl::gfx::Renderable(size_, nullptr) {
}
HeadlessBackend::~HeadlessBackend() {
diff --git a/platform/default/src/mbgl/gl/headless_frontend.cpp b/platform/default/src/mbgl/gl/headless_frontend.cpp
index 406c197904..7e56996f63 100644
--- a/platform/default/src/mbgl/gl/headless_frontend.cpp
+++ b/platform/default/src/mbgl/gl/headless_frontend.cpp
@@ -9,15 +9,25 @@
namespace mbgl {
-HeadlessFrontend::HeadlessFrontend(float pixelRatio_, Scheduler& scheduler, const optional<std::string> programCacheDir, GLContextMode mode, const optional<std::string> localFontFamily)
- : HeadlessFrontend({ 256, 256 }, pixelRatio_, scheduler, programCacheDir, mode, localFontFamily) {
-}
-
-HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, Scheduler& scheduler, const optional<std::string> programCacheDir, GLContextMode mode, const optional<std::string> localFontFamily)
+HeadlessFrontend::HeadlessFrontend(float pixelRatio_,
+ Scheduler& scheduler,
+ const optional<std::string> programCacheDir,
+ const gfx::ContextMode contextMode,
+ const optional<std::string> localFontFamily)
+ : HeadlessFrontend(
+ { 256, 256 }, pixelRatio_, scheduler, programCacheDir, contextMode, localFontFamily) {
+}
+
+HeadlessFrontend::HeadlessFrontend(Size size_,
+ float pixelRatio_,
+ Scheduler& scheduler,
+ const optional<std::string> programCacheDir,
+ const gfx::ContextMode contextMode,
+ const optional<std::string> localFontFamily)
: size(size_),
pixelRatio(pixelRatio_),
backend({ static_cast<uint32_t>(size.width * pixelRatio),
- static_cast<uint32_t>(size.height * pixelRatio) }),
+ static_cast<uint32_t>(size.height * pixelRatio) }, contextMode),
asyncInvalidate([this] {
if (renderer && updateParameters) {
gfx::BackendScope guard { backend };
@@ -30,7 +40,7 @@ HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, Scheduler& sch
renderer->render(*updateParameters_);
}
}),
- renderer(std::make_unique<Renderer>(backend, pixelRatio, scheduler, mode, programCacheDir, localFontFamily)) {
+ renderer(std::make_unique<Renderer>(backend, pixelRatio, scheduler, programCacheDir, localFontFamily)) {
}
HeadlessFrontend::~HeadlessFrontend() = default;
diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp
index 227a61d272..dc3d263261 100644
--- a/platform/default/src/mbgl/map/map_snapshotter.cpp
+++ b/platform/default/src/mbgl/map/map_snapshotter.cpp
@@ -56,14 +56,17 @@ MapSnapshotter::Impl::Impl(std::shared_ptr<Scheduler> scheduler_,
const optional<std::string> programCacheDir,
const optional<std::string> localFontFamily,
const ResourceOptions& resourceOptions)
- : scheduler(std::move(scheduler_))
- , frontend(size, pixelRatio, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily)
- , map(frontend, MapObserver::nullObserver(), *scheduler,
- MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
- resourceOptions) {
+ : scheduler(std::move(scheduler_)),
+ frontend(
+ size, pixelRatio, *scheduler, programCacheDir, gfx::ContextMode::Unique, localFontFamily),
+ map(frontend,
+ MapObserver::nullObserver(),
+ *scheduler,
+ MapOptions().withMapMode(MapMode::Static).withSize(size).withPixelRatio(pixelRatio),
+ resourceOptions) {
if (style.first) {
map.getStyle().loadJSON(style.second);
- } else{
+ } else {
map.getStyle().loadURL(style.second);
}
diff --git a/platform/glfw/glfw_gl_backend.cpp b/platform/glfw/glfw_gl_backend.cpp
index b61e2775d5..2d622fc193 100644
--- a/platform/glfw/glfw_gl_backend.cpp
+++ b/platform/glfw/glfw_gl_backend.cpp
@@ -20,7 +20,8 @@ private:
};
GLFWGLBackend::GLFWGLBackend(GLFWwindow* window_)
- : mbgl::gfx::Renderable(
+ : mbgl::gl::RendererBackend(mbgl::gfx::ContextMode::Unique),
+ mbgl::gfx::Renderable(
[window_] {
int fbWidth, fbHeight;
glfwGetFramebufferSize(window_, &fbWidth, &fbHeight);
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 4cbe839179..4d980655cc 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -17,7 +17,6 @@
#include <mbgl/style/image.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/layers/custom_layer.hpp>
-#include <mbgl/renderer/mode.hpp>
#include <mbgl/renderer/renderer.hpp>
#import <mbgl/gl/renderer_backend.hpp>
#import <mbgl/gl/renderable_resource.hpp>
@@ -482,7 +481,7 @@ public:
MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration];
_mbglThreadPool = mbgl::sharedThreadPool();
- auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, *_mbglThreadPool, config.contextMode, config.cacheDir, config.localFontFamilyName);
+ auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, *_mbglThreadPool, config.cacheDir, config.localFontFamilyName);
BOOL enableCrossSourceCollisions = !config.perSourceCollisions;
_rendererFrontend = std::make_unique<MGLRenderFrontend>(std::move(renderer), self, *_mbglView);
@@ -6737,9 +6736,11 @@ class MBGLView : public mbgl::gl::RendererBackend,
public mbgl::gfx::Renderable,
public mbgl::MapObserver {
public:
- MBGLView(MGLMapView* nativeView_) : mbgl::gfx::Renderable(
- nativeView_.framebufferSize,
- std::make_unique<MBGLMapViewRenderable>(*this)), nativeView(nativeView_) {
+ MBGLView(MGLMapView* nativeView_)
+ : mbgl::gl::RendererBackend(mbgl::gfx::ContextMode::Unique),
+ mbgl::gfx::Renderable(nativeView_.framebufferSize,
+ std::make_unique<MBGLMapViewRenderable>(*this)),
+ nativeView(nativeView_) {
}
/// This function is called before we start rendering, when iOS invokes our rendering method.
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 589d866782..e9259cf907 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -286,7 +286,7 @@ public:
_mbglThreadPool = mbgl::sharedThreadPool();
MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration];
- auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, *_mbglThreadPool, config.contextMode, config.cacheDir, config.localFontFamilyName);
+ auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, config.scaleFactor, *_mbglThreadPool, config.cacheDir, config.localFontFamilyName);
BOOL enableCrossSourceCollisions = !config.perSourceCollisions;
_rendererFrontend = std::make_unique<MGLRenderFrontend>(std::move(renderer), self, *_mbglView, true);
@@ -3060,9 +3060,12 @@ class MGLMapViewImpl : public mbgl::gl::RendererBackend,
public mbgl::gfx::Renderable,
public mbgl::MapObserver {
public:
- MGLMapViewImpl(MGLMapView *nativeView_) : mbgl::gfx::Renderable(
- nativeView_.framebufferSize,
- std::make_unique<MGLMapViewRenderable>(*this)), nativeView(nativeView_) {}
+ MGLMapViewImpl(MGLMapView* nativeView_)
+ : mbgl::gl::RendererBackend(mbgl::gfx::ContextMode::Unique),
+ mbgl::gfx::Renderable(nativeView_.framebufferSize,
+ std::make_unique<MGLMapViewRenderable>(*this)),
+ nativeView(nativeView_) {
+ }
void onCameraWillChange(mbgl::MapObserver::CameraChangeMode mode) override {
bool animated = mode == mbgl::MapObserver::CameraChangeMode::Animated;
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 7dcc753347..e54733aba7 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -67,8 +67,8 @@
using namespace QMapbox;
// mbgl::GLContextMode
-static_assert(mbgl::underlying_type(QMapboxGLSettings::UniqueGLContext) == mbgl::underlying_type(mbgl::GLContextMode::Unique), "error");
-static_assert(mbgl::underlying_type(QMapboxGLSettings::SharedGLContext) == mbgl::underlying_type(mbgl::GLContextMode::Shared), "error");
+static_assert(mbgl::underlying_type(QMapboxGLSettings::UniqueGLContext) == mbgl::underlying_type(mbgl::gfx::ContextMode::Unique), "error");
+static_assert(mbgl::underlying_type(QMapboxGLSettings::SharedGLContext) == mbgl::underlying_type(mbgl::gfx::ContextMode::Shared), "error");
// mbgl::MapMode
static_assert(mbgl::underlying_type(QMapboxGLSettings::Continuous) == mbgl::underlying_type(mbgl::MapMode::Continuous), "error");
diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp
index d10df50149..d72b5d0f2c 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.cpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.cpp
@@ -27,7 +27,8 @@ static auto *getScheduler() {
};
QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio, mbgl::ThreadPool &tp, QMapboxGLSettings::GLContextMode mode, const QString &localFontFamily)
- : m_renderer(std::make_unique<mbgl::Renderer>(m_backend, pixelRatio, tp, static_cast<mbgl::GLContextMode>(mode), mbgl::optional<std::string> {},
+ : m_backend(static_cast<mbgl::gfx::ContextMode>(mode)),
+ m_renderer(std::make_unique<mbgl::Renderer>(m_backend, pixelRatio, tp, mbgl::optional<std::string> {},
localFontFamily.isEmpty() ? mbgl::nullopt : mbgl::optional<std::string> { localFontFamily.toStdString() }))
, m_forceScheduler(needsToForceScheduler())
{
diff --git a/platform/qt/src/qmapboxgl_renderer_backend.cpp b/platform/qt/src/qmapboxgl_renderer_backend.cpp
index 2a9706eb48..39b49fe483 100644
--- a/platform/qt/src/qmapboxgl_renderer_backend.cpp
+++ b/platform/qt/src/qmapboxgl_renderer_backend.cpp
@@ -21,8 +21,9 @@ private:
QMapboxGLRendererBackend& backend;
};
-QMapboxGLRendererBackend::QMapboxGLRendererBackend()
- : mbgl::gfx::Renderable({ 0, 0 }, std::make_unique<QMapboxGLRenderableResource>(*this)) {
+QMapboxGLRendererBackend::QMapboxGLRendererBackend(const mbgl::gfx::ContextMode contextMode_)
+ : mbgl::gl::RendererBackend(contextMode_),
+ mbgl::gfx::Renderable({ 0, 0 }, std::make_unique<QMapboxGLRenderableResource>(*this)) {
}
QMapboxGLRendererBackend::~QMapboxGLRendererBackend() = default;
diff --git a/platform/qt/src/qmapboxgl_renderer_backend.hpp b/platform/qt/src/qmapboxgl_renderer_backend.hpp
index 8d015f500d..aba8003323 100644
--- a/platform/qt/src/qmapboxgl_renderer_backend.hpp
+++ b/platform/qt/src/qmapboxgl_renderer_backend.hpp
@@ -9,7 +9,7 @@
class QMapboxGLRendererBackend final : public mbgl::gl::RendererBackend,
public mbgl::gfx::Renderable {
public:
- QMapboxGLRendererBackend();
+ QMapboxGLRendererBackend(mbgl::gfx::ContextMode);
~QMapboxGLRendererBackend() override;
void updateFramebuffer(quint32 fbo, const mbgl::Size&);
diff --git a/src/core-files.json b/src/core-files.json
index 23ccc6d631..08a6aa4aac 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -352,7 +352,6 @@
"mbgl/math/minmax.hpp": "include/mbgl/math/minmax.hpp",
"mbgl/math/wrap.hpp": "include/mbgl/math/wrap.hpp",
"mbgl/platform/gl_functions.hpp": "include/mbgl/platform/gl_functions.hpp",
- "mbgl/renderer/mode.hpp": "include/mbgl/renderer/mode.hpp",
"mbgl/renderer/query.hpp": "include/mbgl/renderer/query.hpp",
"mbgl/renderer/renderer.hpp": "include/mbgl/renderer/renderer.hpp",
"mbgl/renderer/renderer_frontend.hpp": "include/mbgl/renderer/renderer_frontend.hpp",
diff --git a/src/mbgl/gfx/renderer_backend.cpp b/src/mbgl/gfx/renderer_backend.cpp
index f0336f8b60..e6fe0c0b24 100644
--- a/src/mbgl/gfx/renderer_backend.cpp
+++ b/src/mbgl/gfx/renderer_backend.cpp
@@ -5,8 +5,8 @@
namespace mbgl {
namespace gfx {
-RendererBackend::RendererBackend() = default;
-
+RendererBackend::RendererBackend(const ContextMode contextMode_) : contextMode(contextMode_) {
+}
RendererBackend::~RendererBackend() = default;
gfx::Context& RendererBackend::getContext() {
diff --git a/src/mbgl/gl/renderer_backend.cpp b/src/mbgl/gl/renderer_backend.cpp
index ed3f38193f..9da6ceb589 100644
--- a/src/mbgl/gl/renderer_backend.cpp
+++ b/src/mbgl/gl/renderer_backend.cpp
@@ -8,7 +8,9 @@
namespace mbgl {
namespace gl {
-RendererBackend::RendererBackend() = default;
+RendererBackend::RendererBackend(const gfx::ContextMode contextMode_)
+ : gfx::RendererBackend(contextMode_) {
+}
std::unique_ptr<gfx::Context> RendererBackend::createContext() {
auto result = std::make_unique<gl::Context>(*this);
diff --git a/src/mbgl/renderer/paint_parameters.cpp b/src/mbgl/renderer/paint_parameters.cpp
index c162beaf61..51e85dd91b 100644
--- a/src/mbgl/renderer/paint_parameters.cpp
+++ b/src/mbgl/renderer/paint_parameters.cpp
@@ -8,7 +8,6 @@ namespace mbgl {
PaintParameters::PaintParameters(gfx::Context& context_,
float pixelRatio_,
- GLContextMode contextMode_,
gfx::RendererBackend& backend_,
const UpdateParameters& updateParameters,
const EvaluatedLight& evaluatedLight_,
@@ -26,7 +25,6 @@ PaintParameters::PaintParameters(gfx::Context& context_,
lineAtlas(lineAtlas_),
mapMode(updateParameters.mode),
debugOptions(updateParameters.debugOptions),
- contextMode(contextMode_),
timePoint(updateParameters.timePoint),
pixelRatio(pixelRatio_),
variableOffsets(variableOffsets_),
diff --git a/src/mbgl/renderer/paint_parameters.hpp b/src/mbgl/renderer/paint_parameters.hpp
index 1329a14404..7b0f941d23 100644
--- a/src/mbgl/renderer/paint_parameters.hpp
+++ b/src/mbgl/renderer/paint_parameters.hpp
@@ -2,7 +2,6 @@
#include <mbgl/renderer/render_pass.hpp>
#include <mbgl/renderer/render_light.hpp>
-#include <mbgl/renderer/mode.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/gfx/depth_mode.hpp>
#include <mbgl/gfx/stencil_mode.hpp>
@@ -33,7 +32,6 @@ class PaintParameters {
public:
PaintParameters(gfx::Context&,
float pixelRatio,
- GLContextMode,
gfx::RendererBackend&,
const UpdateParameters&,
const EvaluatedLight&,
@@ -57,7 +55,6 @@ public:
RenderPass pass = RenderPass::Opaque;
MapMode mapMode;
MapDebugOptions debugOptions;
- GLContextMode contextMode;
TimePoint timePoint;
float pixelRatio;
diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp
index b70d25dd86..1c6d937237 100644
--- a/src/mbgl/renderer/renderer.cpp
+++ b/src/mbgl/renderer/renderer.cpp
@@ -10,11 +10,13 @@ namespace mbgl {
Renderer::Renderer(gfx::RendererBackend& backend,
float pixelRatio_,
Scheduler& scheduler_,
- GLContextMode contextMode_,
const optional<std::string> programCacheDir_,
const optional<std::string> localFontFamily_)
- : impl(std::make_unique<Impl>(backend, pixelRatio_, scheduler_,
- contextMode_, std::move(programCacheDir_), std::move(localFontFamily_))) {
+ : impl(std::make_unique<Impl>(backend,
+ pixelRatio_,
+ scheduler_,
+ std::move(programCacheDir_),
+ std::move(localFontFamily_))) {
}
Renderer::~Renderer() {
diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp
index 2f97e4fc33..9352fae471 100644
--- a/src/mbgl/renderer/renderer_impl.cpp
+++ b/src/mbgl/renderer/renderer_impl.cpp
@@ -40,13 +40,11 @@ static RendererObserver& nullObserver() {
Renderer::Impl::Impl(gfx::RendererBackend& backend_,
float pixelRatio_,
Scheduler& scheduler_,
- GLContextMode contextMode_,
const optional<std::string> programCacheDir_,
const optional<std::string> localFontFamily_)
: backend(backend_)
, scheduler(scheduler_)
, observer(&nullObserver())
- , contextMode(contextMode_)
, pixelRatio(pixelRatio_)
, programCacheDir(std::move(programCacheDir_))
, localFontFamily(std::move(localFontFamily_))
@@ -267,9 +265,8 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
}
// Handle layers without source.
- if (layerNeedsRendering && sourceImpl.get() == sourceImpls->at(0).get()) {
- if (contextMode == GLContextMode::Unique
- && layerImpl.get() == layerImpls->at(0).get()) {
+ if (layerNeedsRendering && sourceImpl.get() == sourceImpls->at(0).get()) {
+ if (!backend.contextIsShared() && layerImpl.get() == layerImpls->at(0).get()) {
const auto& solidBackground = layer->getSolidBackground();
if (solidBackground) {
backgroundColor = *solidBackground;
@@ -358,7 +355,6 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
PaintParameters parameters {
backend.getContext(),
pixelRatio,
- contextMode,
backend,
updateParameters,
renderLight.getEvaluated(),
@@ -373,7 +369,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
// TODO: remove cast
gl::Context& glContext = static_cast<gl::Context&>(parameters.context);
- if (parameters.contextMode == GLContextMode::Shared) {
+ if (backend.contextIsShared()) {
glContext.setDirtyState();
}
@@ -428,7 +424,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
parameters.backend.getDefaultRenderable().getResource<gl::RenderableResource>().bind();
if (parameters.debugOptions & MapDebugOptions::Overdraw) {
glContext.clear(Color::black(), ClearDepth::Default, ClearStencil::Default);
- } else if (parameters.contextMode == GLContextMode::Shared) {
+ } else if (backend.contextIsShared()) {
glContext.clear({}, ClearDepth::Default, ClearStencil::Default);
} else {
glContext.clear(backgroundColor, ClearDepth::Default, ClearStencil::Default);
diff --git a/src/mbgl/renderer/renderer_impl.hpp b/src/mbgl/renderer/renderer_impl.hpp
index c8ee939e7a..dc692fb8ce 100644
--- a/src/mbgl/renderer/renderer_impl.hpp
+++ b/src/mbgl/renderer/renderer_impl.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <mbgl/renderer/mode.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/renderer/render_source_observer.hpp>
#include <mbgl/renderer/render_light.hpp>
@@ -41,8 +40,11 @@ class Renderer::Impl : public GlyphManagerObserver,
public ImageManagerObserver,
public RenderSourceObserver{
public:
- Impl(gfx::RendererBackend&, float pixelRatio_, Scheduler&, GLContextMode,
- const optional<std::string> programCacheDir, const optional<std::string> localFontFamily_);
+ Impl(gfx::RendererBackend&,
+ float pixelRatio_,
+ Scheduler&,
+ const optional<std::string> programCacheDir,
+ const optional<std::string> localFontFamily_);
~Impl() final;
void markContextLost() {
@@ -103,7 +105,6 @@ private:
RendererObserver* observer;
- const GLContextMode contextMode;
const float pixelRatio;
const optional<std::string> programCacheDir;
const optional<std::string> localFontFamily;
diff --git a/test/gl/context.test.cpp b/test/gl/context.test.cpp
index 4e41af55d1..b8fe895c44 100644
--- a/test/gl/context.test.cpp
+++ b/test/gl/context.test.cpp
@@ -90,7 +90,7 @@ TEST(GLContextMode, Shared) {
ThreadPool threadPool(4);
- HeadlessFrontend frontend { 1, threadPool, {}, GLContextMode::Shared };
+ HeadlessFrontend frontend { 1, threadPool, {}, gfx::ContextMode::Shared };
Map map(frontend, MapObserver::nullObserver(), threadPool,
MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize()),
diff --git a/test/renderer/backend_scope.test.cpp b/test/renderer/backend_scope.test.cpp
index f5c43a34a1..3646afce48 100644
--- a/test/renderer/backend_scope.test.cpp
+++ b/test/renderer/backend_scope.test.cpp
@@ -7,8 +7,11 @@
using namespace mbgl;
-class StubRendererBackend: public gl::RendererBackend {
+class StubRendererBackend : public gl::RendererBackend {
public:
+ StubRendererBackend() : gl::RendererBackend(gfx::ContextMode::Unique) {
+ }
+
void activate() override {
if (activateFunction) activateFunction();
}
diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp
index 26e4a2eb1d..f21ac0b883 100644
--- a/test/text/local_glyph_rasterizer.test.cpp
+++ b/test/text/local_glyph_rasterizer.test.cpp
@@ -34,7 +34,7 @@ namespace {
class LocalGlyphRasterizerTest {
public:
LocalGlyphRasterizerTest(const optional<std::string> fontFamily)
- : frontend(1, threadPool, optional<std::string>(), GLContextMode::Unique, fontFamily)
+ : frontend(1, threadPool, optional<std::string>(), gfx::ContextMode::Unique, fontFamily)
{
}