diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-10-26 15:22:31 -0700 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-10-27 18:30:58 -0700 |
commit | 62b56b799a7d4fcd1a8f151eed878054b862da5b (patch) | |
tree | 34d510a69f9dd1bca30e9b137feffbd1eb6495d0 /platform | |
parent | ef8017198ce8f0bd79ba5a5ed31e35a16e3433bb (diff) | |
download | qtlocation-mapboxgl-62b56b799a7d4fcd1a8f151eed878054b862da5b.tar.gz |
[core] change std::array<uint16_t, 2> to mbgl::Size
Diffstat (limited to 'platform')
-rwxr-xr-x | platform/android/src/jni.cpp | 10 | ||||
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 18 | ||||
-rw-r--r-- | platform/darwin/src/image.mm | 22 | ||||
-rw-r--r-- | platform/default/glfw_view.cpp | 21 | ||||
-rw-r--r-- | platform/default/image.cpp | 12 | ||||
-rw-r--r-- | platform/default/jpeg_reader.cpp | 2 | ||||
-rw-r--r-- | platform/default/offscreen_view.cpp | 18 | ||||
-rw-r--r-- | platform/default/png_reader.cpp | 2 | ||||
-rw-r--r-- | platform/default/webp_reader.cpp | 4 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 22 | ||||
-rw-r--r-- | platform/ios/src/UIImage+MGLAdditions.mm | 2 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 21 | ||||
-rw-r--r-- | platform/macos/src/NSImage+MGLAdditions.mm | 4 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 13 | ||||
-rw-r--r-- | platform/qt/src/image.cpp | 4 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 41 |
16 files changed, 112 insertions, 104 deletions
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 6dcd177cd6..01d3a01227 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -833,9 +833,10 @@ void nativeAddAnnotationIcon(JNIEnv *env, jni::jobject* obj, jlong nativeMapView NullCheck(*env, jpixels); std::size_t size = jni::GetArrayLength(*env, *jpixels); - mbgl::PremultipliedImage premultipliedImage(width, height); + mbgl::PremultipliedImage premultipliedImage( + { static_cast<uint32_t>(width), static_cast<uint32_t>(height) }); - if (premultipliedImage.size() != uint32_t(size)) { + if (premultipliedImage.bytes() != uint32_t(size)) { throw mbgl::util::SpriteImageException("Sprite image pixel count mismatch"); } @@ -1162,9 +1163,10 @@ void nativeAddImage(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni: // Create Pre-multiplied image from byte[] NullCheck(*env, data); std::size_t size = jni::GetArrayLength(*env, *data); - mbgl::PremultipliedImage premultipliedImage(width, height); + mbgl::PremultipliedImage premultipliedImage( + { static_cast<uint32_t>(width), static_cast<uint32_t>(height) }); - if (premultipliedImage.size() != uint32_t(size)) { + if (premultipliedImage.bytes() != uint32_t(size)) { throw mbgl::util::SpriteImageException("Sprite image pixel count mismatch"); } diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 8f594f2c0e..9943dafe36 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -83,15 +83,14 @@ NativeMapView::NativeMapView(JNIEnv *env_, jobject obj_, float pixelRatio, int a mbgl::android::apkPath); map = std::make_unique<mbgl::Map>( - *this, - std::array<uint16_t, 2>{{ static_cast<uint16_t>(width), static_cast<uint16_t>(height) }}, + *this, mbgl::Size{ static_cast<uint32_t>(width), static_cast<uint32_t>(height) }, pixelRatio, *fileSource, threadPool, MapMode::Continuous); float zoomFactor = map->getMaxZoom() - map->getMinZoom() + 1; float cpuFactor = availableProcessors; float memoryFactor = static_cast<float>(totalMemory) / 1000.0f / 1000.0f / 1000.0f; - float sizeFactor = (static_cast<float>(map->getWidth()) / mbgl::util::tileSize) * - (static_cast<float>(map->getHeight()) / mbgl::util::tileSize); + float sizeFactor = (static_cast<float>(map->getSize().width) / mbgl::util::tileSize) * + (static_cast<float>(map->getSize().height) / mbgl::util::tileSize); size_t cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5f; @@ -119,12 +118,15 @@ NativeMapView::~NativeMapView() { void NativeMapView::updateViewBinding() { getContext().bindFramebuffer.setCurrentValue(0); - getContext().viewport.setCurrentValue({ 0, 0, static_cast<uint16_t>(fbWidth), static_cast<uint16_t>(fbHeight) }); + getContext().viewport.setCurrentValue( + { 0, 0, { static_cast<uint32_t>(fbWidth), static_cast<uint32_t>(fbHeight) } }); } void NativeMapView::bind() { getContext().bindFramebuffer = 0; - getContext().viewport = { 0, 0, static_cast<uint16_t>(fbWidth), static_cast<uint16_t>(fbHeight) }; + getContext().viewport = { 0, + 0, + { static_cast<uint32_t>(fbWidth), static_cast<uint32_t>(fbHeight) } }; } void NativeMapView::activate() { @@ -201,7 +203,7 @@ void NativeMapView::render() { // take snapshot const unsigned int w = fbWidth; const unsigned int h = fbHeight; - mbgl::PremultipliedImage image { static_cast<uint16_t>(w), static_cast<uint16_t>(h) }; + 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); @@ -718,7 +720,7 @@ void NativeMapView::updateFps() { void NativeMapView::resizeView(int w, int h) { width = w; height = h; - map->setSize({{ static_cast<uint16_t>(width), static_cast<uint16_t>(height) }}); + map->setSize({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) }); } void NativeMapView::resizeFramebuffer(int w, int h) { diff --git a/platform/darwin/src/image.mm b/platform/darwin/src/image.mm index 066535a58c..3a707d4a36 100644 --- a/platform/darwin/src/image.mm +++ b/platform/darwin/src/image.mm @@ -11,7 +11,7 @@ namespace mbgl { std::string encodePNG(const PremultipliedImage& src) { - CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, src.data.get(), src.size(), NULL); + CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, src.data.get(), src.bytes(), NULL); if (!provider) { return ""; } @@ -22,9 +22,10 @@ std::string encodePNG(const PremultipliedImage& src) { return ""; } - CGImageRef image = CGImageCreate(src.width, src.height, 8, 32, 4 * src.width, color_space, - kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast, provider, NULL, false, - kCGRenderingIntentDefault); + CGImageRef image = + CGImageCreate(src.size.width, src.size.height, 8, 32, 4 * src.size.width, color_space, + kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast, provider, NULL, + false, kCGRenderingIntentDefault); if (!image) { CGColorSpaceRelease(color_space); CGDataProviderRelease(provider); @@ -92,11 +93,12 @@ PremultipliedImage decodeImage(const std::string &source_data) { throw std::runtime_error("CGColorSpaceCreateDeviceRGB failed"); } - PremultipliedImage result{ static_cast<uint16_t>(CGImageGetWidth(image)), - static_cast<uint16_t>(CGImageGetHeight(image)) }; + PremultipliedImage result({ static_cast<uint32_t>(CGImageGetWidth(image)), + static_cast<uint32_t>(CGImageGetHeight(image)) }); - CGContextRef context = CGBitmapContextCreate(result.data.get(), result.width, result.height, 8, result.stride(), - color_space, kCGImageAlphaPremultipliedLast); + CGContextRef context = + CGBitmapContextCreate(result.data.get(), result.size.width, result.size.height, 8, + result.stride(), color_space, kCGImageAlphaPremultipliedLast); if (!context) { CGColorSpaceRelease(color_space); CGImageRelease(image); @@ -107,7 +109,9 @@ PremultipliedImage decodeImage(const std::string &source_data) { CGContextSetBlendMode(context, kCGBlendModeCopy); - CGRect rect = {{ 0, 0 }, { static_cast<CGFloat>(result.width), static_cast<CGFloat>(result.height) }}; + CGRect rect = { { 0, 0 }, + { static_cast<CGFloat>(result.size.width), + static_cast<CGFloat>(result.size.height) } }; CGContextDrawImage(context, rect, image); CGContextRelease(context); diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 47551d786f..e9b32b21c8 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -132,14 +132,12 @@ void GLFWView::setMap(mbgl::Map *map_) { void GLFWView::updateViewBinding() { getContext().bindFramebuffer.setCurrentValue(0); - getContext().viewport.setCurrentValue( - { 0, 0, static_cast<uint16_t>(fbWidth), static_cast<uint16_t>(fbHeight) }); + getContext().viewport.setCurrentValue({ 0, 0, getFramebufferSize() }); } void GLFWView::bind() { getContext().bindFramebuffer = 0; - getContext().viewport = { 0, 0, static_cast<uint16_t>(fbWidth), - static_cast<uint16_t>(fbHeight) }; + getContext().viewport = { 0, 0, getFramebufferSize() }; } void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) { @@ -192,7 +190,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, view->nextOrientation(); break; case GLFW_KEY_Q: { - auto result = view->map->queryPointAnnotations({ {}, { double(view->getSize()[0]), double(view->getSize()[1]) } }); + auto result = view->map->queryPointAnnotations({ {}, { double(view->getSize().width), double(view->getSize().height) } }); printf("visible point annotations: %lu\n", result.size()); } break; case GLFW_KEY_C: @@ -267,7 +265,7 @@ GLFWView::makeSpriteImage(int width, int height, float pixelRatio) { const int w = std::ceil(pixelRatio * width); const int h = std::ceil(pixelRatio * height); - mbgl::PremultipliedImage image(w, h); + mbgl::PremultipliedImage image({ static_cast<uint32_t>(w), static_cast<uint32_t>(h) }); auto data = reinterpret_cast<uint32_t*>(image.data.get()); const int dist = (w / 2) * (w / 2); for (int y = 0; y < h; y++) { @@ -374,8 +372,7 @@ void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) { GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window)); view->width = width; view->height = height; - view->map->setSize({{ static_cast<uint16_t>(view->width), - static_cast<uint16_t>(view->height) }}); + view->map->setSize({ static_cast<uint32_t>(view->width), static_cast<uint32_t>(view->height) }); } void GLFWView::onFramebufferResize(GLFWwindow *window, int width, int height) { @@ -480,12 +477,12 @@ float GLFWView::getPixelRatio() const { return pixelRatio; } -std::array<uint16_t, 2> GLFWView::getSize() const { - return {{ static_cast<uint16_t>(width), static_cast<uint16_t>(height) }}; +mbgl::Size GLFWView::getSize() const { + return { static_cast<uint32_t>(width), static_cast<uint32_t>(height) }; } -std::array<uint16_t, 2> GLFWView::getFramebufferSize() const { - return {{ static_cast<uint16_t>(fbWidth), static_cast<uint16_t>(fbHeight) }}; +mbgl::Size GLFWView::getFramebufferSize() const { + return { static_cast<uint32_t>(fbWidth), static_cast<uint32_t>(fbHeight) }; } void GLFWView::activate() { diff --git a/platform/default/image.cpp b/platform/default/image.cpp index 890d442683..84db1e9c71 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -25,8 +25,8 @@ const static bool png_version_check __attribute__((unused)) = []() { namespace mbgl { std::string encodePNG(const PremultipliedImage& pre) { - PremultipliedImage copy { pre.width, pre.height }; - std::copy(pre.data.get(), pre.data.get() + pre.size(), copy.data.get()); + PremultipliedImage copy(pre.size); + std::copy(pre.data.get(), pre.data.get() + pre.bytes(), copy.data.get()); UnassociatedImage src = util::unpremultiply(std::move(copy)); @@ -42,8 +42,8 @@ std::string encodePNG(const PremultipliedImage& pre) { throw std::runtime_error("couldn't create info_ptr"); } - png_set_IHDR(png_ptr, info_ptr, src.width, src.height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + png_set_IHDR(png_ptr, info_ptr, src.size.width, src.size.height, 8, PNG_COLOR_TYPE_RGB_ALPHA, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); jmp_buf *jmp_context = (jmp_buf *)png_get_error_ptr(png_ptr); if (jmp_context) { @@ -61,9 +61,9 @@ std::string encodePNG(const PremultipliedImage& pre) { ptrs(size_t count) : rows(new png_bytep[count]) {} ~ptrs() { delete[] rows; } png_bytep *rows = nullptr; - } pointers(src.height); + } pointers(src.size.height); - for (size_t i = 0; i < src.height; i++) { + for (size_t i = 0; i < src.size.height; i++) { pointers.rows[i] = src.data.get() + src.stride() * i; } diff --git a/platform/default/jpeg_reader.cpp b/platform/default/jpeg_reader.cpp index 5151060a12..78c74f2fd7 100644 --- a/platform/default/jpeg_reader.cpp +++ b/platform/default/jpeg_reader.cpp @@ -119,7 +119,7 @@ PremultipliedImage decodeJPEG(const uint8_t* data, size_t size) { size_t components = cinfo.output_components; size_t rowStride = components * width; - PremultipliedImage image { static_cast<uint16_t>(width), static_cast<uint16_t>(height) }; + PremultipliedImage image({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) }); uint8_t* dst = image.data.get(); JSAMPARRAY buffer = (*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, rowStride, 1); diff --git a/platform/default/offscreen_view.cpp b/platform/default/offscreen_view.cpp index eaf87d0f87..613e00fc2b 100644 --- a/platform/default/offscreen_view.cpp +++ b/platform/default/offscreen_view.cpp @@ -7,9 +7,9 @@ namespace mbgl { -OffscreenView::OffscreenView(gl::Context& context_, std::array<uint16_t, 2> size_) - : context(context_), size(std::move(size_)) { - assert(size[0] > 0 && size[1] > 0); +OffscreenView::OffscreenView(gl::Context& context_, const Size size_) + : size(std::move(size_)), context(context_) { + assert(size); } void OffscreenView::bind() { @@ -21,17 +21,17 @@ void OffscreenView::bind() { context.bindFramebuffer = framebuffer->framebuffer; } - context.viewport = { 0, 0, size[0], size[1] }; + context.viewport = { 0, 0, size }; } PremultipliedImage OffscreenView::readStillImage() { - PremultipliedImage image { size[0], size[1] }; - MBGL_CHECK_ERROR(glReadPixels(0, 0, size[0], size[1], GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); + 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[1] - 1; i < j; i++, j--) { + 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); @@ -40,8 +40,4 @@ PremultipliedImage OffscreenView::readStillImage() { return image; } -std::array<uint16_t, 2> OffscreenView::getSize() const { - return size; -} - } // namespace mbgl diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index 5111edaa59..7c10f20667 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -80,7 +80,7 @@ PremultipliedImage decodePNG(const uint8_t* data, size_t size) { int color_type = 0; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, nullptr, nullptr, nullptr); - UnassociatedImage image { static_cast<uint16_t>(width), static_cast<uint16_t>(height) }; + UnassociatedImage image({ width, height }); if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand(png_ptr); diff --git a/platform/default/webp_reader.cpp b/platform/default/webp_reader.cpp index 6f90fe02f5..a56632157f 100644 --- a/platform/default/webp_reader.cpp +++ b/platform/default/webp_reader.cpp @@ -23,8 +23,8 @@ PremultipliedImage decodeWebP(const uint8_t* data, size_t size) { throw std::runtime_error("failed to decode WebP data"); } - UnassociatedImage image{ static_cast<uint16_t>(width), static_cast<uint16_t>(height), - std::move(webp) }; + UnassociatedImage image({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) }, + std::move(webp)); return util::premultiply(std::move(image)); } diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 41e049ad61..43f357559f 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -399,12 +399,10 @@ public: [[NSFileManager defaultManager] removeItemAtPath:fileCachePath error:NULL]; // setup mbgl map - const std::array<uint16_t, 2> size = {{ static_cast<uint16_t>(self.bounds.size.width), - static_cast<uint16_t>(self.bounds.size.height) }}; mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; const float scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale]; _mbglThreadPool = new mbgl::ThreadPool(4); - _mbglMap = new mbgl::Map(*_mbglView, size, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); + _mbglMap = new mbgl::Map(*_mbglView, self.size, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); [self validateTileCacheSize]; // start paused if in IB @@ -545,6 +543,12 @@ public: } } +- (mbgl::Size)size +{ + return { static_cast<uint32_t>(self.bounds.size.width), + static_cast<uint32_t>(self.bounds.size.height) }; +} + - (void)createGLView { if (_context) return; @@ -885,10 +889,8 @@ public: [self adjustContentInset]; - if ( ! _isTargetingInterfaceBuilder) - { - _mbglMap->setSize({{ static_cast<uint16_t>(self.bounds.size.width), - static_cast<uint16_t>(self.bounds.size.height) }}); + if (!_isTargetingInterfaceBuilder) { + _mbglMap->setSize([self size]); } if (self.attributionSheet.visible) @@ -4947,13 +4949,11 @@ public: class MBGLView : public mbgl::View, public mbgl::Backend { public: - MBGLView(MGLMapView* nativeView_) - : nativeView(nativeView_) { + MBGLView(MGLMapView* nativeView_) : nativeView(nativeView_) { } mbgl::gl::value::Viewport::Type getViewport() const { - return { 0, 0, static_cast<uint16_t>(nativeView.glView.drawableWidth), - static_cast<uint16_t>(nativeView.glView.drawableHeight) }; + return { 0, 0, nativeView.size }; } /// This function is called before we start rendering, when iOS invokes our rendering method. diff --git a/platform/ios/src/UIImage+MGLAdditions.mm b/platform/ios/src/UIImage+MGLAdditions.mm index 8ec8f9e15f..215b23faff 100644 --- a/platform/ios/src/UIImage+MGLAdditions.mm +++ b/platform/ios/src/UIImage+MGLAdditions.mm @@ -8,7 +8,7 @@ size_t width = CGImageGetWidth(cgImage); size_t height = CGImageGetHeight(cgImage); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - mbgl::PremultipliedImage cPremultipliedImage(width, height); + mbgl::PremultipliedImage cPremultipliedImage({ static_cast<uint32_t>(width), static_cast<uint32_t>(height) }); size_t bytesPerPixel = 4; size_t bytesPerRow = bytesPerPixel * width; size_t bitsPerComponent = 8; diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index ebcd8e00b0..2630a361a0 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -266,10 +266,8 @@ public: mbgl::DefaultFileSource* mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; - const std::array<uint16_t, 2> size = {{ static_cast<uint16_t>(self.bounds.size.width), - static_cast<uint16_t>(self.bounds.size.height) }}; _mbglThreadPool = new mbgl::ThreadPool(4); - _mbglMap = new mbgl::Map(*_mbglView, size, [NSScreen mainScreen].backingScaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); + _mbglMap = new mbgl::Map(*_mbglView, self.size, [NSScreen mainScreen].backingScaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::GLContextMode::Unique, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); [self validateTileCacheSize]; // Install the OpenGL layer. Interface Builder’s synchronous drawing means @@ -308,6 +306,11 @@ public: _pendingLongitude = NAN; } +- (mbgl::Size)size { + return { static_cast<uint32_t>(self.bounds.size.width), + static_cast<uint32_t>(self.bounds.size.height) }; +} + /// Adds zoom controls to the lower-right corner. - (void)installZoomControls { _zoomControls = [[NSSegmentedControl alloc] initWithFrame:NSZeroRect]; @@ -639,8 +642,7 @@ public: [self validateTileCacheSize]; } if (!_isTargetingInterfaceBuilder) { - _mbglMap->setSize({{ static_cast<uint16_t>(self.bounds.size.width), - static_cast<uint16_t>(self.bounds.size.height) }}); + _mbglMap->setSize(self.size); } } @@ -2561,8 +2563,7 @@ public: } mbgl::gl::value::Viewport::Type getViewport() const { - return { 0, 0, static_cast<uint16_t>(nativeView.bounds.size.width), - static_cast<uint16_t>(nativeView.bounds.size.height) }; + return { 0, 0, nativeView.size }; } void updateViewBinding() { @@ -2578,9 +2579,9 @@ public: mbgl::PremultipliedImage readStillImage() { NSRect bounds = [nativeView convertRectToBacking:nativeView.bounds]; - const uint16_t width = bounds.size.width; - const uint16_t height = bounds.size.height; - mbgl::PremultipliedImage image{ width, height }; + const uint32_t width = bounds.size.width; + const uint32_t height = bounds.size.height; + mbgl::PremultipliedImage image({ width, height }); MBGL_CHECK_ERROR( glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, image.data.get())); diff --git a/platform/macos/src/NSImage+MGLAdditions.mm b/platform/macos/src/NSImage+MGLAdditions.mm index 7d02271bb3..2c4b16800e 100644 --- a/platform/macos/src/NSImage+MGLAdditions.mm +++ b/platform/macos/src/NSImage+MGLAdditions.mm @@ -13,8 +13,8 @@ // Get the image’s raw pixel data as an RGBA buffer. std::string pixelString((const char *)rep.bitmapData, rep.pixelsWide * rep.pixelsHigh * 4 /* RGBA */); - mbgl::PremultipliedImage cPremultipliedImage(rep.pixelsWide, rep.pixelsHigh); - std::copy(rep.bitmapData, rep.bitmapData + cPremultipliedImage.size(), cPremultipliedImage.data.get()); + mbgl::PremultipliedImage cPremultipliedImage({ static_cast<uint32_t>(rep.pixelsWide), static_cast<uint32_t>(rep.pixelsHigh) }); + std::copy(rep.bitmapData, rep.bitmapData + cPremultipliedImage.bytes(), cPremultipliedImage.data.get()); return std::make_unique<mbgl::SpriteImage>(std::move(cPremultipliedImage), (float)(rep.pixelsWide / self.size.width)); } diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 671bf3e0fd..e630275ec0 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -356,12 +356,11 @@ void NodeMap::Render(const Nan::FunctionCallbackInfo<v8::Value>& info) { } void NodeMap::startRender(NodeMap::RenderOptions options) { - map->setSize(std::array<uint16_t, 2>{{ static_cast<uint16_t>(options.width), - static_cast<uint16_t>(options.height) }}); + map->setSize({ options.width, options.height }); - const std::array<uint16_t, 2> fbSize{{ static_cast<uint16_t>(options.width * pixelRatio), - static_cast<uint16_t>(options.height * pixelRatio) }}; - if (!view || view->getSize() != fbSize) { + const mbgl::Size fbSize{ static_cast<uint32_t>(options.width * pixelRatio), + static_cast<uint32_t>(options.height * pixelRatio) }; + if (!view || view->size != fbSize) { view.reset(); view = std::make_unique<mbgl::OffscreenView>(backend.getContext(), fbSize); } @@ -430,7 +429,7 @@ void NodeMap::renderFinished() { cb->Call(1, argv); } else if (img.data) { v8::Local<v8::Object> pixels = Nan::NewBuffer( - reinterpret_cast<char *>(img.data.get()), img.size(), + reinterpret_cast<char *>(img.data.get()), img.bytes(), // Retain the data until the buffer is deleted. [](char *, void * hint) { delete [] reinterpret_cast<uint8_t*>(hint); @@ -790,7 +789,7 @@ NodeMap::NodeMap(v8::Local<v8::Object> options) }()), backend(sharedDisplay()), map(std::make_unique<mbgl::Map>(backend, - std::array<uint16_t, 2>{{ 256, 256 }}, + mbgl::Size{ 256, 256 }, pixelRatio, *this, threadpool, diff --git a/platform/qt/src/image.cpp b/platform/qt/src/image.cpp index 3918b35208..403ca9cbd3 100644 --- a/platform/qt/src/image.cpp +++ b/platform/qt/src/image.cpp @@ -7,7 +7,7 @@ namespace mbgl { std::string encodePNG(const PremultipliedImage& pre) { - QImage image(pre.data.get(), pre.width, pre.height, + QImage image(pre.data.get(), pre.size.width, pre.size.height, QImage::Format_ARGB32_Premultiplied); QByteArray array; @@ -57,7 +57,7 @@ PremultipliedImage decodeImage(const std::string& string) { auto img = std::make_unique<uint8_t[]>(image.byteCount()); memcpy(img.get(), image.constBits(), image.byteCount()); - return { static_cast<uint16_t>(image.width()), static_cast<uint16_t>(image.height()), + return { { static_cast<uint32_t>(image.width()), static_cast<uint32_t>(image.height()) }, std::move(img) }; } } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index edda1f9599..d54f6b3409 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -122,8 +122,9 @@ std::unique_ptr<const mbgl::SpriteImage> toSpriteImage(const QImage &sprite) { memcpy(img.get(), swapped.constBits(), swapped.byteCount()); return std::make_unique<mbgl::SpriteImage>( - mbgl::PremultipliedImage{ static_cast<uint16_t>(swapped.width()), - static_cast<uint16_t>(swapped.height()), std::move(img) }, + mbgl::PremultipliedImage( + { static_cast<uint32_t>(swapped.width()), static_cast<uint32_t>(swapped.height()) }, + std::move(img)), 1.0); } @@ -611,7 +612,8 @@ void QMapboxGL::resize(const QSize& size, const QSize& framebufferSize) d_ptr->size = size; d_ptr->fbSize = framebufferSize; - d_ptr->mapObj->setSize({{ static_cast<uint16_t>(size.width()), static_cast<uint16_t>(size.height()) }}); + d_ptr->mapObj->setSize( + { static_cast<uint32_t>(size.width()), static_cast<uint32_t>(size.height()) }); } void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &sprite) @@ -824,7 +826,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin settings.cacheDatabaseMaximumSize())) , threadPool(4) , mapObj(std::make_unique<mbgl::Map>( - *this, std::array<uint16_t, 2>{{ static_cast<uint16_t>(size.width()), static_cast<uint16_t>(size.height()) }}, + *this, mbgl::Size{ static_cast<uint32_t>(size.width()), static_cast<uint32_t>(size.height()) }, pixelRatio, *fileSourceObj, threadPool, static_cast<mbgl::MapMode>(settings.mapMode()), static_cast<mbgl::GLContextMode>(settings.contextMode()), @@ -849,33 +851,38 @@ void QMapboxGLPrivate::updateFramebufferBinding(QOpenGLFramebufferObject *fbo_) if (fbo) { getContext().bindFramebuffer.setDirty(); getContext().viewport.setCurrentValue( - { 0, 0, static_cast<uint16_t>(fbo->width()), static_cast<uint16_t>(fbo->height()) }); + { 0, + 0, + { static_cast<uint32_t>(fbo->width()), static_cast<uint32_t>(fbo->height()) } }); } else { getContext().bindFramebuffer.setCurrentValue(0); - getContext().viewport.setCurrentValue({ 0, 0, static_cast<uint16_t>(fbSize.width()), - static_cast<uint16_t>(fbSize.height()) }); + getContext().viewport.setCurrentValue( + { 0, + 0, + { static_cast<uint32_t>(fbSize.width()), static_cast<uint32_t>(fbSize.height()) } }); } } -void QMapboxGLPrivate::bind() -{ +void QMapboxGLPrivate::bind() { if (fbo) { fbo->bind(); getContext().bindFramebuffer.setDirty(); - getContext().viewport = { 0, 0, static_cast<uint16_t>(fbo->width()), - static_cast<uint16_t>(fbo->height()) }; + getContext().viewport = { + 0, 0, { static_cast<uint32_t>(fbo->width()), static_cast<uint32_t>(fbo->height()) } + }; } else { getContext().bindFramebuffer = 0; - getContext().viewport = { 0, 0, static_cast<uint16_t>(fbSize.width()), - static_cast<uint16_t>(fbSize.height()) }; + getContext().viewport = { + 0, 0, { static_cast<uint32_t>(fbSize.width()), static_cast<uint32_t>(fbSize.height()) } + }; } } #else -void QMapboxGLPrivate::bind() -{ +void QMapboxGLPrivate::bind() { getContext().bindFramebuffer = 0; - getContext().viewport = { 0, 0, static_cast<uint16_t>(fbSize.width()), - static_cast<uint16_t>(fbSize.height()) }; + getContext().viewport = { + 0, 0, { static_cast<uint32_t>(fbSize.width()), static_cast<uint32_t>(fbSize.height()) } + }; } #endif |