summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-10-08 15:31:41 -0400
committerMike Morris <michael.patrick.morris@gmail.com>2014-10-08 15:31:41 -0400
commita1bc8c766d6e204a44e2c7171a80330e123b582b (patch)
tree9432d1128dfb13316695d1d320464fa0dcbfe1d2 /common
parent799ca683dfe1913618a965773103b88d41244bcd (diff)
downloadqtlocation-mapboxgl-a1bc8c766d6e204a44e2c7171a80330e123b582b.tar.gz
add HeadlessView::readPixels, fixes #480
Diffstat (limited to 'common')
-rw-r--r--common/headless_view.cpp30
-rw-r--r--common/headless_view.hpp5
2 files changed, 28 insertions, 7 deletions
diff --git a/common/headless_view.cpp b/common/headless_view.cpp
index d19db57483..9775da1d57 100644
--- a/common/headless_view.cpp
+++ b/common/headless_view.cpp
@@ -7,7 +7,8 @@
namespace mbgl {
-HeadlessView::HeadlessView() : display_(std::make_shared<HeadlessDisplay>()) {
+HeadlessView::HeadlessView()
+ : display_(std::make_shared<HeadlessDisplay>()) {
createContext();
}
@@ -43,8 +44,12 @@ void HeadlessView::createContext() {
void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
clear_buffers();
- width *= pixelRatio;
- height *= pixelRatio;
+ width_ = width;
+ height_ = height;
+ pixelRatio_ = pixelRatio;
+
+ const unsigned int w = width_ * pixelRatio_;
+ const unsigned int h = height_ * pixelRatio_;
#if MBGL_USE_CGL
make_active();
@@ -52,12 +57,12 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
// Create depth/stencil buffer
glGenRenderbuffersEXT(1, &fbo_depth_stencil);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_depth_stencil);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, width, height);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, w, h);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glGenRenderbuffersEXT(1, &fbo_color);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, fbo_color);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height);
+ glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, w, h);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
glGenFramebuffersEXT(1, &fbo);
@@ -87,11 +92,24 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
#endif
#if MBGL_USE_GLX
- x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), width, height, 32);
+ x_pixmap = XCreatePixmap(x_display, DefaultRootWindow(x_display), w, h, 32);
glx_pixmap = glXCreateGLXPixmap(x_display, x_info, x_pixmap);
#endif
}
+const std::unique_ptr<uint32_t[]>* HeadlessView::readPixels() {
+ const unsigned int w = width_ * pixelRatio_;
+ const unsigned int h = height_ * pixelRatio_;
+
+ const std::unique_ptr<uint32_t[]> pixels(new uint32_t[w * h]);
+
+ make_active();
+ glReadPixels(0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, pixels.get());
+ make_inactive();
+
+ return &pixels;
+}
+
void HeadlessView::clear_buffers() {
#if MBGL_USE_CGL
make_active();
diff --git a/common/headless_view.hpp b/common/headless_view.hpp
index 13a5b01099..b59366349e 100644
--- a/common/headless_view.hpp
+++ b/common/headless_view.hpp
@@ -26,6 +26,7 @@ public:
void createContext();
void resize(uint16_t width, uint16_t height, float pixelRatio);
+ const std::unique_ptr<uint32_t[]>* readPixels();
void notify_map_change(MapChange change, timestamp delay = 0);
void make_active();
@@ -36,9 +37,11 @@ public:
private:
void clear_buffers();
-
private:
std::shared_ptr<HeadlessDisplay> display_;
+ uint16_t width_;
+ uint16_t height_;
+ float pixelRatio_;
#if MBGL_USE_CGL
CGLContextObj gl_context;