summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-02-17 10:57:21 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-20 12:04:21 -0800
commit535457262011f3790069c8426e7b143f3aba26d0 (patch)
tree5b78cc5fc1d8215fb315952af4a0960b70e26b52
parented7844d08f3cffaba00cc974c4ab6b26c84dd98d (diff)
downloadqtlocation-mapboxgl-535457262011f3790069c8426e7b143f3aba26d0.tar.gz
[core] Eliminate manual HeadlessBackend activation management
-rw-r--r--platform/default/mbgl/gl/headless_backend.cpp3
-rw-r--r--platform/default/mbgl/gl/headless_backend.hpp5
-rw-r--r--test/gl/object.test.cpp4
-rw-r--r--test/map/map.test.cpp2
-rw-r--r--test/util/offscreen_texture.test.cpp88
5 files changed, 50 insertions, 52 deletions
diff --git a/platform/default/mbgl/gl/headless_backend.cpp b/platform/default/mbgl/gl/headless_backend.cpp
index 7ccf6d132b..61225d54a1 100644
--- a/platform/default/mbgl/gl/headless_backend.cpp
+++ b/platform/default/mbgl/gl/headless_backend.cpp
@@ -8,16 +8,13 @@
namespace mbgl {
HeadlessBackend::HeadlessBackend() {
- activate();
}
HeadlessBackend::HeadlessBackend(std::shared_ptr<HeadlessDisplay> display_)
: display(std::move(display_)) {
- activate();
}
HeadlessBackend::~HeadlessBackend() {
- deactivate();
}
void HeadlessBackend::activate() {
diff --git a/platform/default/mbgl/gl/headless_backend.hpp b/platform/default/mbgl/gl/headless_backend.hpp
index f566257522..e632d0feb6 100644
--- a/platform/default/mbgl/gl/headless_backend.hpp
+++ b/platform/default/mbgl/gl/headless_backend.hpp
@@ -18,8 +18,6 @@ public:
~HeadlessBackend() override;
void invalidate() override;
- void activate() override;
- void deactivate() override;
void notifyMapChange(MapChange) override;
void setMapChangeCallback(std::function<void(MapChange)>&& cb) { mapChangeCallback = std::move(cb); }
@@ -34,6 +32,9 @@ private:
// Implementation specific functions
static gl::glProc initializeExtension(const char*);
+ void activate() override;
+ void deactivate() override;
+
bool hasContext() const { return bool(impl); }
bool hasDisplay();
diff --git a/test/gl/object.test.cpp b/test/gl/object.test.cpp
index f1da93f1da..85ae457081 100644
--- a/test/gl/object.test.cpp
+++ b/test/gl/object.test.cpp
@@ -1,5 +1,6 @@
#include <mbgl/test/util.hpp>
+#include <mbgl/map/backend_scope.hpp>
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/gl/offscreen_view.hpp>
@@ -62,6 +63,7 @@ TEST(GLObject, Value) {
TEST(GLObject, Store) {
HeadlessBackend backend { test::sharedDisplay() };
OffscreenView view(backend.getContext());
+ BackendScope scope { backend };
gl::Context context;
EXPECT_TRUE(context.empty());
@@ -77,6 +79,4 @@ TEST(GLObject, Store) {
context.reset();
EXPECT_TRUE(context.empty());
-
- backend.deactivate();
}
diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp
index aec181e058..a00a4efacc 100644
--- a/test/map/map.test.cpp
+++ b/test/map/map.test.cpp
@@ -4,6 +4,7 @@
#include <mbgl/test/fixture_log_observer.hpp>
#include <mbgl/map/map.hpp>
+#include <mbgl/map/backend_scope.hpp>
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/gl/offscreen_view.hpp>
#include <mbgl/gl/context.hpp>
@@ -574,6 +575,7 @@ TEST(Map, TEST_DISABLED_ON_CI(ContinuousRendering)) {
});
}
+ BackendScope scope(backend);
map.render(view);
}};
diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp
index 31fb985394..feaabf2630 100644
--- a/test/util/offscreen_texture.test.cpp
+++ b/test/util/offscreen_texture.test.cpp
@@ -4,6 +4,7 @@
#include <mbgl/gl/context.hpp>
#include <mbgl/gl/headless_backend.hpp>
#include <mbgl/gl/offscreen_view.hpp>
+#include <mbgl/map/backend_scope.hpp>
#include <mbgl/util/offscreen_texture.hpp>
@@ -11,6 +12,7 @@ using namespace mbgl;
TEST(OffscreenTexture, EmptyRed) {
HeadlessBackend backend { test::sharedDisplay() };
+ BackendScope scope { backend };
OffscreenView view(backend.getContext(), { 512, 256 });
view.bind();
@@ -68,6 +70,7 @@ struct Buffer {
TEST(OffscreenTexture, RenderToTexture) {
HeadlessBackend backend { test::sharedDisplay() };
+ BackendScope scope { backend };
auto& context = backend.getContext();
MBGL_CHECK_ERROR(glEnable(GL_BLEND));
@@ -116,50 +119,45 @@ void main() {
Buffer triangleBuffer({ 0, 0.5, 0.5, -0.5, -0.5, -0.5 });
Buffer viewportBuffer({ -1, -1, 1, -1, -1, 1, 1, 1 });
- // Make sure the texture gets destructed before we call context.reset();
- {
- OffscreenView view(context, { 512, 256 });
- view.bind();
-
- // First, draw red to the bound FBO.
- context.clear(Color::red(), {}, {});
-
- // Then, create a texture, bind it, and render yellow to that texture. This should not
- // affect the originally bound FBO.
- OffscreenTexture texture(context, { 128, 128 });
- texture.bind();
-
- context.clear(Color(), {}, {});
-
- MBGL_CHECK_ERROR(glUseProgram(paintShader.program));
- MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer.buffer));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(paintShader.a_pos));
- MBGL_CHECK_ERROR(
- glVertexAttribPointer(paintShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
- MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3));
-
- auto image = texture.readStillImage();
- test::checkImage("test/fixtures/offscreen_texture/render-to-texture", image, 0, 0);
-
- // Now reset the FBO back to normal and retrieve the original (restored) framebuffer.
- view.bind();
-
- image = view.readStillImage();
- test::checkImage("test/fixtures/offscreen_texture/render-to-fbo", image, 0, 0);
-
- // Now, composite the Framebuffer texture we've rendered to onto the main FBO.
- context.bindTexture(texture.getTexture(), 0, gl::TextureFilter::Linear);
- MBGL_CHECK_ERROR(glUseProgram(compositeShader.program));
- MBGL_CHECK_ERROR(glUniform1i(u_texture, 0));
- MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, viewportBuffer.buffer));
- MBGL_CHECK_ERROR(glEnableVertexAttribArray(compositeShader.a_pos));
- MBGL_CHECK_ERROR(
- glVertexAttribPointer(compositeShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
- MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
-
- image = view.readStillImage();
- test::checkImage("test/fixtures/offscreen_texture/render-to-fbo-composited", image, 0, 0.1);
- }
+ OffscreenView view(context, { 512, 256 });
+ view.bind();
+
+ // First, draw red to the bound FBO.
+ context.clear(Color::red(), {}, {});
+
+ // Then, create a texture, bind it, and render yellow to that texture. This should not
+ // affect the originally bound FBO.
+ OffscreenTexture texture(context, { 128, 128 });
+ texture.bind();
+
+ context.clear(Color(), {}, {});
+
+ MBGL_CHECK_ERROR(glUseProgram(paintShader.program));
+ MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, triangleBuffer.buffer));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(paintShader.a_pos));
+ MBGL_CHECK_ERROR(
+ glVertexAttribPointer(paintShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
+ MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 3));
+
+ auto image = texture.readStillImage();
+ test::checkImage("test/fixtures/offscreen_texture/render-to-texture", image, 0, 0);
+
+ // Now reset the FBO back to normal and retrieve the original (restored) framebuffer.
+ view.bind();
- context.reset();
+ image = view.readStillImage();
+ test::checkImage("test/fixtures/offscreen_texture/render-to-fbo", image, 0, 0);
+
+ // Now, composite the Framebuffer texture we've rendered to onto the main FBO.
+ context.bindTexture(texture.getTexture(), 0, gl::TextureFilter::Linear);
+ MBGL_CHECK_ERROR(glUseProgram(compositeShader.program));
+ MBGL_CHECK_ERROR(glUniform1i(u_texture, 0));
+ MBGL_CHECK_ERROR(glBindBuffer(GL_ARRAY_BUFFER, viewportBuffer.buffer));
+ MBGL_CHECK_ERROR(glEnableVertexAttribArray(compositeShader.a_pos));
+ MBGL_CHECK_ERROR(
+ glVertexAttribPointer(compositeShader.a_pos, 2, GL_FLOAT, GL_FALSE, 0, nullptr));
+ MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
+
+ image = view.readStillImage();
+ test::checkImage("test/fixtures/offscreen_texture/render-to-fbo-composited", image, 0, 0.1);
}