diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-11-04 17:39:14 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-11-04 21:24:05 +0100 |
commit | c90a55959980f9ef9678a45b9c9ded906d637b34 (patch) | |
tree | 7bf7a9041c269934b3bb25f2b84934f29d330d8b /platform | |
parent | eed16cb1bb14c5de68e71ba7960cbe264cc08760 (diff) | |
download | qtlocation-mapboxgl-c90a55959980f9ef9678a45b9c9ded906d637b34.tar.gz |
[core] move framebuffer reading to gl::Context
Diffstat (limited to 'platform')
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 15 | ||||
-rw-r--r-- | platform/default/offscreen_view.cpp | 15 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 16 |
3 files changed, 3 insertions, 43 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 65e39b198e..0026aaa708 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -10,8 +10,6 @@ #include <sys/system_properties.h> -#include <GLES2/gl2.h> - #include <mbgl/platform/platform.hpp> #include <mbgl/platform/event.hpp> #include <mbgl/platform/log.hpp> @@ -204,18 +202,7 @@ void NativeMapView::render() { snapshot = false; // take snapshot - const unsigned int w = fbWidth; - const unsigned int h = fbHeight; - mbgl::PremultipliedImage image({ w, h }); - MBGL_CHECK_ERROR(glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); - const size_t stride = image.stride(); - auto tmp = std::make_unique<uint8_t[]>(stride); - uint8_t *rgba = image.data.get(); - for (int i = 0, j = h - 1; i < j; i++, j--) { - std::memcpy(tmp.get(), rgba + i * stride, stride); - std::memcpy(rgba + i * stride, rgba + j * stride, stride); - std::memcpy(rgba + j * stride, tmp.get(), stride); - } + auto image = getContext().readFramebuffer<mbgl::PremultipliedImage>(getFramebufferSize()); // encode and convert to jbytes std::string string = encodePNG(image); diff --git a/platform/default/offscreen_view.cpp b/platform/default/offscreen_view.cpp index 613e00fc2b..574686ebc9 100644 --- a/platform/default/offscreen_view.cpp +++ b/platform/default/offscreen_view.cpp @@ -1,6 +1,5 @@ #include <mbgl/platform/default/offscreen_view.hpp> #include <mbgl/gl/context.hpp> -#include <mbgl/gl/gl.hpp> #include <cstring> #include <cassert> @@ -25,19 +24,7 @@ void OffscreenView::bind() { } PremultipliedImage OffscreenView::readStillImage() { - PremultipliedImage image { size }; - MBGL_CHECK_ERROR(glReadPixels(0, 0, size.width, size.height, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); - - const auto stride = image.stride(); - auto tmp = std::make_unique<uint8_t[]>(stride); - uint8_t* rgba = image.data.get(); - for (int i = 0, j = size.height - 1; i < j; i++, j--) { - std::memcpy(tmp.get(), rgba + i * stride, stride); - std::memcpy(rgba + i * stride, rgba + j * stride, stride); - std::memcpy(rgba + j * stride, tmp.get(), stride); - } - - return image; + return context.readFramebuffer<PremultipliedImage>(size); } } // namespace mbgl diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 02f96ac3ff..513687f94e 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -24,7 +24,6 @@ #import <mbgl/platform/darwin/reachability.h> #import <mbgl/platform/default/thread_pool.hpp> #import <mbgl/gl/extension.hpp> -#import <mbgl/gl/gl.hpp> #import <mbgl/gl/context.hpp> #import <mbgl/map/backend.hpp> #import <mbgl/sprite/sprite_image.hpp> @@ -2608,20 +2607,7 @@ public: } mbgl::PremultipliedImage readStillImage() { - mbgl::PremultipliedImage image(nativeView.framebufferSize); - MBGL_CHECK_ERROR(glReadPixels(0, 0, image.size.width, image.size.height, GL_RGBA, - GL_UNSIGNED_BYTE, image.data.get())); - - const size_t stride = image.stride(); - auto tmp = std::make_unique<uint8_t[]>(stride); - uint8_t *rgba = image.data.get(); - for (int i = 0, j = image.size.height - 1; i < j; i++, j--) { - std::memcpy(tmp.get(), rgba + i * stride, stride); - std::memcpy(rgba + i * stride, rgba + j * stride, stride); - std::memcpy(rgba + j * stride, tmp.get(), stride); - } - - return image; + return getContext().readFramebuffer<mbgl::PremultipliedImage>(nativeView.framebufferSize); } private: |