[core] Eliminate manual HeadlessBackend activation management
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}};
|
||||
|
||||
|
||||
@@ -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();
|
||||
OffscreenView view(context, { 512, 256 });
|
||||
view.bind();
|
||||
|
||||
// First, draw red to the bound FBO.
|
||||
context.clear(Color::red(), {}, {});
|
||||
// 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();
|
||||
// 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(), {}, {});
|
||||
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));
|
||||
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);
|
||||
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();
|
||||
// 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);
|
||||
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));
|
||||
// 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);
|
||||
}
|
||||
|
||||
context.reset();
|
||||
image = view.readStillImage();
|
||||
test::checkImage("test/fixtures/offscreen_texture/render-to-fbo-composited", image, 0, 0.1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user