summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-04-21 14:52:19 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-04-24 15:52:28 -0700
commit5dd98df50ba1210b1eef0d8d6655713a725f2995 (patch)
treeb289bb3cbad5d1c3076816f4891a057d6089fc93 /platform
parent6f708ac5458fe332e25ca398431928b7ff5ba404 (diff)
downloadqtlocation-mapboxgl-5dd98df50ba1210b1eef0d8d6655713a725f2995.tar.gz
[all] Rationalize style::Image
A style has a collection of images, just as it has collections of sources and layers. * Name things appropriately * Use std::unique_ptr
Diffstat (limited to 'platform')
-rwxr-xr-xplatform/android/src/native_map_view.cpp12
-rw-r--r--platform/darwin/src/MGLStyle.mm8
-rw-r--r--platform/glfw/glfw_view.cpp12
-rw-r--r--platform/glfw/glfw_view.hpp3
-rw-r--r--platform/ios/src/MGLMapView.mm7
-rw-r--r--platform/ios/src/UIImage+MGLAdditions.h6
-rw-r--r--platform/ios/src/UIImage+MGLAdditions.mm14
-rw-r--r--platform/macos/src/MGLMapView.mm5
-rw-r--r--platform/macos/src/NSImage+MGLAdditions.h6
-rw-r--r--platform/macos/src/NSImage+MGLAdditions.mm12
-rw-r--r--platform/node/src/node_map.cpp4
-rw-r--r--platform/qt/src/qmapboxgl.cpp10
12 files changed, 48 insertions, 51 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 5418a9e42a..1e2464f1a0 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -25,7 +25,7 @@
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
#include <mbgl/util/projection.hpp>
-#include <mbgl/sprite/sprite_image.hpp>
+#include <mbgl/style/image.hpp>
#include <mbgl/style/filter.hpp>
// Java -> C++ conversion
@@ -735,12 +735,12 @@ void NativeMapView::addAnnotationIcon(JNIEnv& env, jni::String symbol, jint w, j
}
jni::GetArrayRegion(env, *jpixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get()));
- auto iconImage = std::make_shared<mbgl::SpriteImage>(std::move(premultipliedImage), float(scale));
- map->addAnnotationIcon(symbolName, iconImage);
+ map->addAnnotationImage(symbolName,
+ std::make_unique<mbgl::style::Image>(std::move(premultipliedImage), float(scale)));
}
jdouble NativeMapView::getTopOffsetPixelsForAnnotationSymbol(JNIEnv& env, jni::String symbolName) {
- return map->getTopOffsetPixelsForAnnotationIcon(jni::Make<std::string>(env, symbolName));
+ return map->getTopOffsetPixelsForAnnotationImage(jni::Make<std::string>(env, symbolName));
}
jlong NativeMapView::getTransitionDuration(JNIEnv&) {
@@ -1036,9 +1036,9 @@ void NativeMapView::addImage(JNIEnv& env, jni::String name, jni::jint w, jni::ji
}
jni::GetArrayRegion(env, *pixels, 0, size, reinterpret_cast<jbyte*>(premultipliedImage.data.get()));
- auto spriteImage = std::make_unique<mbgl::SpriteImage>(std::move(premultipliedImage), float(scale));
- map->addImage(jni::Make<std::string>(env, name), std::move(spriteImage));
+ map->addImage(jni::Make<std::string>(env, name),
+ std::make_unique<mbgl::style::Image>(std::move(premultipliedImage), float(scale)));
}
void NativeMapView::removeImage(JNIEnv& env, jni::String name) {
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm
index 0912993825..a4cf8d9cce 100644
--- a/platform/darwin/src/MGLStyle.mm
+++ b/platform/darwin/src/MGLStyle.mm
@@ -26,7 +26,7 @@
#include <mbgl/map/map.hpp>
#include <mbgl/util/default_styles.hpp>
-#include <mbgl/sprite/sprite_image.hpp>
+#include <mbgl/style/image.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
@@ -538,7 +538,7 @@ static NSURL *MGLStyleURL_emerald;
format:@"Cannot assign image %@ to a nil name.", image];
}
- self.mapView.mbglMap->addImage([name UTF8String], image.mgl_spriteImage);
+ self.mapView.mbglMap->addImage([name UTF8String], image.mgl_styleImage);
}
- (void)removeImageForName:(NSString *)name
@@ -558,8 +558,8 @@ static NSURL *MGLStyleURL_emerald;
format:@"Cannot get image with nil name."];
}
- auto spriteImage = self.mapView.mbglMap->getImage([name UTF8String]);
- return spriteImage ? [[MGLImage alloc] initWithMGLSpriteImage:spriteImage] : nil;
+ auto styleImage = self.mapView.mbglMap->getImage([name UTF8String]);
+ return styleImage ? [[MGLImage alloc] initWithMGLStyleImage:styleImage] : nil;
}
#pragma mark Style transitions
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 5e9083f503..f4ade26885 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -1,7 +1,7 @@
#include "glfw_view.hpp"
#include <mbgl/annotation/annotation.hpp>
-#include <mbgl/sprite/sprite_image.hpp>
+#include <mbgl/style/image.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
@@ -124,7 +124,7 @@ GLFWView::~GLFWView() {
void GLFWView::setMap(mbgl::Map *map_) {
map = map_;
- map->addAnnotationIcon("default_marker", makeSpriteImage(22, 22, 1));
+ map->addAnnotationImage("default_marker", makeImage(22, 22, 1));
}
void GLFWView::updateAssumedState() {
@@ -258,8 +258,8 @@ mbgl::Point<double> GLFWView::makeRandomPoint() const {
return { latLng.longitude(), latLng.latitude() };
}
-std::shared_ptr<const mbgl::SpriteImage>
-GLFWView::makeSpriteImage(int width, int height, float pixelRatio) {
+std::unique_ptr<mbgl::style::Image>
+GLFWView::makeImage(int width, int height, float pixelRatio) {
const int r = 255 * (double(std::rand()) / RAND_MAX);
const int g = 255 * (double(std::rand()) / RAND_MAX);
const int b = 255 * (double(std::rand()) / RAND_MAX);
@@ -284,7 +284,7 @@ GLFWView::makeSpriteImage(int width, int height, float pixelRatio) {
}
}
- return std::make_shared<mbgl::SpriteImage>(std::move(image), pixelRatio);
+ return std::make_unique<mbgl::style::Image>(std::move(image), pixelRatio);
}
void GLFWView::nextOrientation() {
@@ -301,7 +301,7 @@ void GLFWView::addRandomCustomPointAnnotations(int count) {
for (int i = 0; i < count; i++) {
static int spriteID = 1;
const auto name = std::string{ "marker-" } + mbgl::util::toString(spriteID++);
- map->addAnnotationIcon(name, makeSpriteImage(22, 22, 1));
+ map->addAnnotationImage(name, makeImage(22, 22, 1));
spriteIDs.push_back(name);
annotationIDs.push_back(map->addAnnotation(mbgl::SymbolAnnotation { makeRandomPoint(), name }));
}
diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp
index bc50eba819..09b8847ff2 100644
--- a/platform/glfw/glfw_view.hpp
+++ b/platform/glfw/glfw_view.hpp
@@ -65,8 +65,7 @@ private:
mbgl::Color makeRandomColor() const;
mbgl::Point<double> makeRandomPoint() const;
- static std::shared_ptr<const mbgl::SpriteImage>
- makeSpriteImage(int width, int height, float pixelRatio);
+ static std::unique_ptr<mbgl::style::Image> makeImage(int width, int height, float pixelRatio);
void nextOrientation();
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 01611e03f2..42079baf94 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -8,7 +8,6 @@
#include <mbgl/map/map.hpp>
#include <mbgl/map/view.hpp>
#include <mbgl/annotation/annotation.hpp>
-#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/map/camera.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/platform.hpp>
@@ -16,6 +15,7 @@
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/storage/default_file_source.hpp>
#include <mbgl/storage/network_status.hpp>
+#include <mbgl/style/image.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/map/backend.hpp>
@@ -3451,8 +3451,7 @@ public:
annotationImage.delegate = self;
// add sprite
- std::shared_ptr<mbgl::SpriteImage> sprite(annotationImage.image.mgl_spriteImage);
- _mbglMap->addAnnotationIcon(iconIdentifier.UTF8String, sprite);
+ _mbglMap->addAnnotationImage(iconIdentifier.UTF8String, annotationImage.image.mgl_styleImage);
// Create a slop area with a “radius” equal in size to the annotation
// image’s alignment rect, allowing the eventual tap to be on any point
@@ -4096,7 +4095,7 @@ public:
// Remove the old icon from the style.
if ( ! [iconIdentifier isEqualToString:fallbackIconIdentifier]) {
- _mbglMap->removeAnnotationIcon(iconIdentifier.UTF8String);
+ _mbglMap->removeAnnotationImage(iconIdentifier.UTF8String);
}
if (annotationImage.image)
diff --git a/platform/ios/src/UIImage+MGLAdditions.h b/platform/ios/src/UIImage+MGLAdditions.h
index f291a302c9..642355d412 100644
--- a/platform/ios/src/UIImage+MGLAdditions.h
+++ b/platform/ios/src/UIImage+MGLAdditions.h
@@ -1,14 +1,14 @@
#import <UIKit/UIKit.h>
-#include <mbgl/sprite/sprite_image.hpp>
+#include <mbgl/style/image.hpp>
NS_ASSUME_NONNULL_BEGIN
@interface UIImage (MGLAdditions)
-- (nullable instancetype)initWithMGLSpriteImage:(const mbgl::SpriteImage *)spriteImage;
+- (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)styleImage;
-- (std::unique_ptr<mbgl::SpriteImage>)mgl_spriteImage;
+- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage;
@end
diff --git a/platform/ios/src/UIImage+MGLAdditions.mm b/platform/ios/src/UIImage+MGLAdditions.mm
index d99a1f73ed..db64d78232 100644
--- a/platform/ios/src/UIImage+MGLAdditions.mm
+++ b/platform/ios/src/UIImage+MGLAdditions.mm
@@ -4,16 +4,16 @@
@implementation UIImage (MGLAdditions)
-- (nullable instancetype)initWithMGLSpriteImage:(const mbgl::SpriteImage *)spriteImage
+- (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)styleImage
{
- CGImageRef image = CGImageFromMGLPremultipliedImage(spriteImage->image.clone());
+ CGImageRef image = CGImageFromMGLPremultipliedImage(styleImage->image.clone());
if (!image) {
return nil;
}
- if (self = [self initWithCGImage:image scale:spriteImage->pixelRatio orientation:UIImageOrientationUp])
+ if (self = [self initWithCGImage:image scale:styleImage->pixelRatio orientation:UIImageOrientationUp])
{
- if (spriteImage->sdf)
+ if (styleImage->sdf)
{
self = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
@@ -22,10 +22,10 @@
return self;
}
-- (std::unique_ptr<mbgl::SpriteImage>)mgl_spriteImage {
+- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage {
BOOL isTemplate = self.renderingMode == UIImageRenderingModeAlwaysTemplate;
- return std::make_unique<mbgl::SpriteImage>(MGLPremultipliedImageFromCGImage(self.CGImage),
- float(self.scale), isTemplate);
+ return std::make_unique<mbgl::style::Image>(MGLPremultipliedImageFromCGImage(self.CGImage),
+ float(self.scale), isTemplate);
}
@end
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index cf3a5afe7f..a36766b745 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -28,7 +28,7 @@
#import <mbgl/util/default_thread_pool.hpp>
#import <mbgl/map/backend.hpp>
#import <mbgl/map/backend_scope.hpp>
-#import <mbgl/sprite/sprite_image.hpp>
+#import <mbgl/style/image.hpp>
#import <mbgl/storage/default_file_source.hpp>
#import <mbgl/storage/network_status.hpp>
#import <mbgl/math/wrap.hpp>
@@ -1949,8 +1949,7 @@ public:
return;
}
- std::shared_ptr<mbgl::SpriteImage> sprite(annotationImage.image.mgl_spriteImage);
- _mbglMap->addAnnotationIcon(iconIdentifier.UTF8String, sprite);
+ _mbglMap->addAnnotationImage(iconIdentifier.UTF8String, annotationImage.image.mgl_styleImage);
// Create a slop area with a “radius” equal to the annotation image’s entire
// size, allowing the eventual click to be on any point within this image.
diff --git a/platform/macos/src/NSImage+MGLAdditions.h b/platform/macos/src/NSImage+MGLAdditions.h
index c6a80e372d..d3cc80615b 100644
--- a/platform/macos/src/NSImage+MGLAdditions.h
+++ b/platform/macos/src/NSImage+MGLAdditions.h
@@ -1,6 +1,6 @@
#import <Cocoa/Cocoa.h>
-#include <mbgl/sprite/sprite_image.hpp>
+#include <mbgl/style/image.hpp>
NS_ASSUME_NONNULL_BEGIN
@@ -8,9 +8,9 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable instancetype)initWithMGLPremultipliedImage:(mbgl::PremultipliedImage&&)image;
-- (nullable instancetype)initWithMGLSpriteImage:(const mbgl::SpriteImage *)spriteImage;
+- (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)image;
-- (std::unique_ptr<mbgl::SpriteImage>)mgl_spriteImage;
+- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage;
@end
diff --git a/platform/macos/src/NSImage+MGLAdditions.mm b/platform/macos/src/NSImage+MGLAdditions.mm
index 397e291431..91c4f7bf66 100644
--- a/platform/macos/src/NSImage+MGLAdditions.mm
+++ b/platform/macos/src/NSImage+MGLAdditions.mm
@@ -15,22 +15,22 @@
return self;
}
-- (nullable instancetype)initWithMGLSpriteImage:(const mbgl::SpriteImage *)spriteImage {
- CGImageRef image = CGImageFromMGLPremultipliedImage(spriteImage->image.clone());
+- (nullable instancetype)initWithMGLStyleImage:(const mbgl::style::Image *)styleImage {
+ CGImageRef image = CGImageFromMGLPremultipliedImage(styleImage->image.clone());
if (!image) {
return nil;
}
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithCGImage:image];
CGImageRelease(image);
- if (self = [self initWithSize:NSMakeSize(spriteImage->getWidth(), spriteImage->getHeight())]) {
+ if (self = [self initWithSize:NSMakeSize(styleImage->getWidth(), styleImage->getHeight())]) {
[self addRepresentation:rep];
- [self setTemplate:spriteImage->sdf];
+ [self setTemplate:styleImage->sdf];
}
return self;
}
-- (std::unique_ptr<mbgl::SpriteImage>)mgl_spriteImage {
+- (std::unique_ptr<mbgl::style::Image>)mgl_styleImage {
// Create a bitmap image representation from the image, respecting backing
// scale factor and any resizing done on the image at runtime.
// http://www.cocoabuilder.com/archive/cocoa/82430-nsimage-getting-raw-bitmap-data.html#82431
@@ -40,7 +40,7 @@
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),
+ return std::make_unique<mbgl::style::Image>(std::move(cPremultipliedImage),
(float)(rep.pixelsWide / self.size.width),
[self isTemplate]);
}
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index 6c4b7345f1..ab49ca6405 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -9,7 +9,7 @@
#include <mbgl/style/conversion/source.hpp>
#include <mbgl/style/conversion/layer.hpp>
#include <mbgl/style/conversion/filter.hpp>
-#include <mbgl/sprite/sprite_image.hpp>
+#include <mbgl/style/image.hpp>
#include <mbgl/map/backend_scope.hpp>
#include <mbgl/map/query.hpp>
@@ -684,7 +684,7 @@ void NodeMap::AddImage(const Nan::FunctionCallbackInfo<v8::Value>& info) {
std::copy(imageDataBuffer, imageDataBuffer + imageLength, data.get());
mbgl::PremultipliedImage cPremultipliedImage({ imageWidth, imageHeight}, std::move(data));
- nodeMap->map->addImage(*Nan::Utf8String(info[0]), std::make_unique<mbgl::SpriteImage>(std::move(cPremultipliedImage), pixelRatio));
+ nodeMap->map->addImage(*Nan::Utf8String(info[0]), std::make_unique<mbgl::style::Image>(std::move(cPremultipliedImage), pixelRatio));
}
void NodeMap::RemoveImage(const Nan::FunctionCallbackInfo<v8::Value>& info) {
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index fa4f56373c..dedff24c54 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -15,7 +15,7 @@
#include <mbgl/style/layers/custom_layer.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/style/transition_options.hpp>
-#include <mbgl/sprite/sprite_image.hpp>
+#include <mbgl/style/image.hpp>
#include <mbgl/storage/network_status.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/constants.hpp>
@@ -88,7 +88,7 @@ mbgl::Size sanitizedSize(const QSize& size) {
};
};
-std::unique_ptr<const mbgl::SpriteImage> toSpriteImage(const QImage &sprite) {
+std::unique_ptr<mbgl::style::Image> toStyleImage(const QImage &sprite) {
const QImage swapped = sprite
.rgbSwapped()
.convertToFormat(QImage::Format_ARGB32_Premultiplied);
@@ -96,7 +96,7 @@ std::unique_ptr<const mbgl::SpriteImage> toSpriteImage(const QImage &sprite) {
auto img = std::make_unique<uint8_t[]>(swapped.byteCount());
memcpy(img.get(), swapped.constBits(), swapped.byteCount());
- return std::make_unique<mbgl::SpriteImage>(
+ return std::make_unique<mbgl::style::Image>(
mbgl::PremultipliedImage(
{ static_cast<uint32_t>(swapped.width()), static_cast<uint32_t>(swapped.height()) },
std::move(img)),
@@ -1114,7 +1114,7 @@ void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &icon)
{
if (icon.isNull()) return;
- d_ptr->mapObj->addAnnotationIcon(name.toStdString(), toSpriteImage(icon));
+ d_ptr->mapObj->addAnnotationImage(name.toStdString(), toStyleImage(icon));
}
/*!
@@ -1414,7 +1414,7 @@ void QMapboxGL::addImage(const QString &id, const QImage &image)
{
if (image.isNull()) return;
- d_ptr->mapObj->addImage(id.toStdString(), toSpriteImage(image));
+ d_ptr->mapObj->addImage(id.toStdString(), toStyleImage(image));
}
/*!