summaryrefslogtreecommitdiff
path: root/src/mbgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl')
-rw-r--r--src/mbgl/annotation/annotation_manager.cpp2
-rw-r--r--src/mbgl/gl/context.cpp12
-rw-r--r--src/mbgl/gl/context.hpp15
-rw-r--r--src/mbgl/gl/framebuffer.hpp5
-rw-r--r--src/mbgl/gl/renderbuffer.hpp5
-rw-r--r--src/mbgl/gl/texture.hpp5
-rw-r--r--src/mbgl/gl/value.cpp4
-rw-r--r--src/mbgl/gl/value.hpp8
-rw-r--r--src/mbgl/map/map.cpp18
-rw-r--r--src/mbgl/map/transform.cpp33
-rw-r--r--src/mbgl/map/transform.hpp2
-rw-r--r--src/mbgl/map/transform_state.cpp42
-rw-r--r--src/mbgl/map/transform_state.hpp6
-rw-r--r--src/mbgl/renderer/painter.cpp2
-rw-r--r--src/mbgl/renderer/painter_debug.cpp45
-rw-r--r--src/mbgl/renderer/painter_fill.cpp4
-rw-r--r--src/mbgl/renderer/painter_line.cpp4
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp2
-rw-r--r--src/mbgl/sprite/sprite_atlas.cpp13
-rw-r--r--src/mbgl/sprite/sprite_image.cpp2
-rw-r--r--src/mbgl/sprite/sprite_parser.cpp19
-rw-r--r--src/mbgl/sprite/sprite_parser.hpp8
-rw-r--r--src/mbgl/style/layers/custom_layer_impl.cpp4
-rw-r--r--src/mbgl/style/source_impl.cpp6
-rw-r--r--src/mbgl/util/offscreen_texture.cpp15
-rw-r--r--src/mbgl/util/offscreen_texture.hpp6
-rw-r--r--src/mbgl/util/premultiply.cpp10
-rw-r--r--src/mbgl/util/tile_cover.cpp4
28 files changed, 146 insertions, 155 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp
index dbd5f1f433..c7c13d0d2c 100644
--- a/src/mbgl/annotation/annotation_manager.cpp
+++ b/src/mbgl/annotation/annotation_manager.cpp
@@ -232,7 +232,7 @@ void AnnotationManager::removeIcon(const std::string& name) {
double AnnotationManager::getTopOffsetPixelsForIcon(const std::string& name) {
auto sprite = spriteAtlas.getSprite(name);
- return sprite ? -(sprite->image.height / sprite->pixelRatio) / 2 : 0;
+ return sprite ? -(sprite->image.size.height / sprite->pixelRatio) / 2 : 0;
}
} // namespace mbgl
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 23b28a15df..bf9bae4fe7 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -143,16 +143,14 @@ UniqueFramebuffer Context::createFramebuffer() {
return UniqueFramebuffer{ std::move(id), { this } };
}
-UniqueRenderbuffer Context::createRenderbuffer(const RenderbufferType type,
- const uint16_t width,
- const uint16_t height) {
+UniqueRenderbuffer Context::createRenderbuffer(const RenderbufferType type, const Size size) {
RenderbufferID id = 0;
MBGL_CHECK_ERROR(glGenRenderbuffers(1, &id));
UniqueRenderbuffer renderbuffer{ std::move(id), { this } };
bindRenderbuffer = renderbuffer;
MBGL_CHECK_ERROR(
- glRenderbufferStorage(GL_RENDERBUFFER, static_cast<GLenum>(type), width, height));
+ glRenderbufferStorage(GL_RENDERBUFFER, static_cast<GLenum>(type), size.width, size.height));
return renderbuffer;
}
@@ -251,7 +249,7 @@ Framebuffer Context::createFramebuffer(const Texture& color) {
}
UniqueTexture
-Context::createTexture(uint16_t width, uint16_t height, const void* data, TextureUnit unit) {
+Context::createTexture(const Size size, const void* data, TextureUnit unit) {
auto obj = createTexture();
activeTexture = unit;
texture[unit] = obj;
@@ -259,8 +257,8 @@ Context::createTexture(uint16_t width, uint16_t height, const void* data, Textur
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
- MBGL_CHECK_ERROR(
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data));
+ MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width, size.height, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, data));
return obj;
}
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index cf8bb2658b..6daf3f9bfb 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -49,10 +49,10 @@ public:
}
template <RenderbufferType type>
- Renderbuffer<type> createRenderbuffer(const std::array<uint16_t, 2>& size) {
+ Renderbuffer<type> createRenderbuffer(const Size size) {
static_assert(type == RenderbufferType::RGBA || type == RenderbufferType::DepthStencil,
"invalid renderbuffer type");
- return { size, createRenderbuffer(type, size[0], size[1]) };
+ return { size, createRenderbuffer(type, size) };
}
Framebuffer createFramebuffer(const Renderbuffer<RenderbufferType::RGBA>&,
@@ -65,13 +65,12 @@ public:
// Create a texture from an image with data.
template <typename Image>
Texture createTexture(const Image& image, TextureUnit unit = 0) {
- return { {{ image.width, image.height }},
- createTexture(image.width, image.height, image.data.get(), unit) };
+ return { image.size, createTexture(image.size, image.data.get(), unit) };
}
// Creates an empty texture with the specified dimensions.
- Texture createTexture(const std::array<uint16_t, 2>& size, TextureUnit unit = 0) {
- return { size, createTexture(size[0], size[1], nullptr, unit) };
+ Texture createTexture(const Size size, TextureUnit unit = 0) {
+ return { size, createTexture(size, nullptr, unit) };
}
void bindTexture(Texture&,
@@ -140,9 +139,9 @@ public:
private:
UniqueBuffer createVertexBuffer(const void* data, std::size_t size);
UniqueBuffer createIndexBuffer(const void* data, std::size_t size);
- UniqueTexture createTexture(uint16_t width, uint16_t height, const void* data, TextureUnit);
+ UniqueTexture createTexture(Size size, const void* data, TextureUnit);
UniqueFramebuffer createFramebuffer();
- UniqueRenderbuffer createRenderbuffer(RenderbufferType, uint16_t width, uint16_t height);
+ UniqueRenderbuffer createRenderbuffer(RenderbufferType, Size size);
void bindAttribute(const AttributeBinding&, std::size_t stride, const int8_t* offset);
friend detail::ProgramDeleter;
diff --git a/src/mbgl/gl/framebuffer.hpp b/src/mbgl/gl/framebuffer.hpp
index 880fed159e..91ed467b40 100644
--- a/src/mbgl/gl/framebuffer.hpp
+++ b/src/mbgl/gl/framebuffer.hpp
@@ -1,15 +1,14 @@
#pragma once
#include <mbgl/gl/object.hpp>
-
-#include <array>
+#include <mbgl/util/size.hpp>
namespace mbgl {
namespace gl {
class Framebuffer {
public:
- std::array<uint16_t, 2> size;
+ Size size;
gl::UniqueFramebuffer framebuffer;
};
diff --git a/src/mbgl/gl/renderbuffer.hpp b/src/mbgl/gl/renderbuffer.hpp
index 9e8993bb77..cc8ff13268 100644
--- a/src/mbgl/gl/renderbuffer.hpp
+++ b/src/mbgl/gl/renderbuffer.hpp
@@ -1,8 +1,7 @@
#pragma once
#include <mbgl/gl/object.hpp>
-
-#include <array>
+#include <mbgl/util/size.hpp>
namespace mbgl {
namespace gl {
@@ -11,7 +10,7 @@ template <RenderbufferType renderbufferType>
class Renderbuffer {
public:
using type = std::integral_constant<RenderbufferType, renderbufferType>;
- std::array<uint16_t, 2> size;
+ Size size;
gl::UniqueRenderbuffer renderbuffer;
};
diff --git a/src/mbgl/gl/texture.hpp b/src/mbgl/gl/texture.hpp
index 49e1323095..802dac9eb2 100644
--- a/src/mbgl/gl/texture.hpp
+++ b/src/mbgl/gl/texture.hpp
@@ -1,15 +1,14 @@
#pragma once
#include <mbgl/gl/object.hpp>
-
-#include <array>
+#include <mbgl/util/size.hpp>
namespace mbgl {
namespace gl {
class Texture {
public:
- std::array<uint16_t, 2> size;
+ Size size;
UniqueTexture texture;
TextureFilter filter = TextureFilter::Nearest;
TextureMipMap mipmap = TextureMipMap::No;
diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp
index 14cd03efc4..b308dc9de5 100644
--- a/src/mbgl/gl/value.cpp
+++ b/src/mbgl/gl/value.cpp
@@ -244,14 +244,14 @@ ActiveTexture::Type ActiveTexture::Get() {
const constexpr Viewport::Type Viewport::Default;
void Viewport::Set(const Type& value) {
- MBGL_CHECK_ERROR(glViewport(value.x, value.y, value.width, value.height));
+ MBGL_CHECK_ERROR(glViewport(value.x, value.y, value.size.width, value.size.height));
}
Viewport::Type Viewport::Get() {
GLint viewport[4];
MBGL_CHECK_ERROR(glGetIntegerv(GL_VIEWPORT, viewport));
return { static_cast<int32_t>(viewport[0]), static_cast<int32_t>(viewport[1]),
- static_cast<uint16_t>(viewport[2]), static_cast<uint16_t>(viewport[3]) };
+ { static_cast<uint32_t>(viewport[2]), static_cast<uint32_t>(viewport[3]) } };
}
const constexpr BindFramebuffer::Type BindFramebuffer::Default;
diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp
index 866ce389a4..becf2e63f4 100644
--- a/src/mbgl/gl/value.hpp
+++ b/src/mbgl/gl/value.hpp
@@ -2,6 +2,7 @@
#include <mbgl/gl/types.hpp>
#include <mbgl/util/color.hpp>
+#include <mbgl/util/size.hpp>
namespace mbgl {
namespace gl {
@@ -177,16 +178,15 @@ struct Viewport {
struct Type {
int32_t x;
int32_t y;
- uint16_t width;
- uint16_t height;
+ Size size;
};
- static const constexpr Type Default = { 0, 0, 0, 0 };
+ static const constexpr Type Default = { 0, 0, { 0, 0 } };
static void Set(const Type&);
static Type Get();
};
constexpr bool operator!=(const Viewport::Type& a, const Viewport::Type& b) {
- return a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height;
+ return a.x != b.x || a.y != b.y || a.size != b.size;
}
struct BindFramebuffer {
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 7b58026386..75f7788931 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -99,7 +99,7 @@ public:
};
Map::Map(Backend& backend,
- const std::array<uint16_t, 2> size,
+ const Size size,
const float pixelRatio,
FileSource& fileSource,
Scheduler& scheduler,
@@ -541,7 +541,7 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, optional
// Calculate the bounds of the possibly rotated shape with respect to the viewport.
ScreenCoordinate nePixel = {-INFINITY, -INFINITY};
ScreenCoordinate swPixel = {INFINITY, INFINITY};
- double viewportHeight = getHeight();
+ double viewportHeight = getSize().height;
for (LatLng latLng : latLngs) {
ScreenCoordinate pixel = pixelForLatLng(latLng);
swPixel.x = std::min(swPixel.x, pixel.x);
@@ -555,8 +555,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, optional
// Calculate the zoom level.
double minScale = INFINITY;
if (width > 0 || height > 0) {
- double scaleX = getWidth() / width;
- double scaleY = getHeight() / height;
+ double scaleX = double(getSize().width) / width;
+ double scaleY = double(getSize().height) / height;
if (padding && *padding) {
scaleX -= (padding->left + padding->right) / width;
scaleY -= (padding->top + padding->bottom) / height;
@@ -617,17 +617,13 @@ double Map::getMaxZoom() const {
#pragma mark - Size
-void Map::setSize(const std::array<uint16_t, 2>& size) {
+void Map::setSize(const Size size) {
impl->transform.resize(size);
impl->onUpdate(Update::Repaint);
}
-uint16_t Map::getWidth() const {
- return impl->transform.getState().getWidth();
-}
-
-uint16_t Map::getHeight() const {
- return impl->transform.getState().getHeight();
+Size Map::getSize() const {
+ return impl->transform.getState().getSize();
}
#pragma mark - Rotation
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 85805a109d..7a3f4edf0e 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -45,8 +45,8 @@ Transform::Transform(std::function<void(MapChange)> callback_,
#pragma mark - Map View
-bool Transform::resize(const std::array<uint16_t, 2> size) {
- if (state.width == size[0] && state.height == size[1]) {
+bool Transform::resize(const Size size) {
+ if (state.size == size) {
return false;
}
@@ -54,8 +54,7 @@ bool Transform::resize(const std::array<uint16_t, 2> size) {
callback(MapChangeRegionWillChange);
}
- state.width = size[0];
- state.height = size[1];
+ state.size = size;
state.constrain(state.scale, state.x, state.y);
if (callback) {
@@ -117,7 +116,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
const Point<double> endPoint = Projection::project(latLng, state.scale);
ScreenCoordinate center = getScreenCoordinate(padding);
- center.y = state.height - center.y;
+ center.y = state.size.height - center.y;
// Constrain camera options.
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
@@ -187,7 +186,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
const Point<double> endPoint = Projection::project(latLng, state.scale);
ScreenCoordinate center = getScreenCoordinate(padding);
- center.y = state.height - center.y;
+ center.y = state.size.height - center.y;
// Constrain camera options.
zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom());
@@ -203,9 +202,9 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
/// w₀: Initial visible span, measured in pixels at the initial scale.
/// Known henceforth as a <i>screenful</i>.
- double w0 = padding ? std::max(state.width, state.height)
- : std::max(state.width - padding.left - padding.right,
- state.height - padding.top - padding.bottom);
+ double w0 = padding ? std::max(state.size.width, state.size.height)
+ : std::max(state.size.width - padding.left - padding.right,
+ state.size.height - padding.top - padding.bottom);
/// w₁: Final visible span, measured in pixels with respect to the initial
/// scale.
double w1 = w0 / state.zoomScale(zoom - startZoom);
@@ -355,8 +354,8 @@ void Transform::setLatLng(const LatLng& latLng, optional<ScreenCoordinate> ancho
EdgeInsets padding;
padding.top = anchor->y;
padding.left = anchor->x;
- padding.bottom = state.height - anchor->y;
- padding.right = state.width - anchor->x;
+ padding.bottom = state.size.height - anchor->y;
+ padding.right = state.size.width - anchor->x;
if (padding) camera.padding = padding;
}
easeTo(camera, duration);
@@ -378,7 +377,7 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, optional<EdgeIn
LatLng Transform::getLatLng(optional<EdgeInsets> padding) const {
if (padding && *padding) {
- return screenCoordinateToLatLng(padding->getCenter(state.width, state.height));
+ return screenCoordinateToLatLng(padding->getCenter(state.size.width, state.size.height));
} else {
return state.getLatLng();
}
@@ -386,9 +385,9 @@ LatLng Transform::getLatLng(optional<EdgeInsets> padding) const {
ScreenCoordinate Transform::getScreenCoordinate(optional<EdgeInsets> padding) const {
if (padding && *padding) {
- return padding->getCenter(state.width, state.height);
+ return padding->getCenter(state.size.width, state.size.height);
} else {
- return { state.width / 2., state.height / 2. };
+ return { state.size.width / 2., state.size.height / 2. };
}
}
@@ -565,7 +564,7 @@ void Transform::startTransition(const CameraOptions& camera,
optional<ScreenCoordinate> anchor = camera.anchor;
LatLng anchorLatLng;
if (anchor) {
- anchor->y = state.getHeight() - anchor->y;
+ anchor->y = state.size.height - anchor->y;
anchorLatLng = state.screenCoordinateToLatLng(*anchor);
}
@@ -650,13 +649,13 @@ ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const
LatLng unwrappedLatLng = latLng.wrapped();
unwrappedLatLng.unwrapForShortestPath(getLatLng());
ScreenCoordinate point = state.latLngToScreenCoordinate(unwrappedLatLng);
- point.y = state.height - point.y;
+ point.y = state.size.height - point.y;
return point;
}
LatLng Transform::screenCoordinateToLatLng(const ScreenCoordinate& point) const {
ScreenCoordinate flippedPoint = point;
- flippedPoint.y = state.height - flippedPoint.y;
+ flippedPoint.y = state.size.height - flippedPoint.y;
return state.screenCoordinateToLatLng(flippedPoint).wrapped();
}
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index abc301b1cb..febe71035d 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -23,7 +23,7 @@ public:
ViewportMode = ViewportMode::Default);
// Map view
- bool resize(std::array<uint16_t, 2> size);
+ bool resize(Size size);
// Camera
/** Returns the current camera options. */
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 4f6bcecdb6..5dc7feffc0 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -33,15 +33,16 @@ void TransformState::getProjMatrix(mat4& projMatrix) const {
// Calculate z value of the farthest fragment that should be rendered.
double farZ = std::cos(M_PI / 2.0f - getPitch()) * topHalfSurfaceDistance + getAltitude();
- matrix::perspective(projMatrix, 2.0f * std::atan((getHeight() / 2.0f) / getAltitude()),
- double(getWidth()) / getHeight(), 0.1, farZ);
+ matrix::perspective(projMatrix, 2.0f * std::atan((size.height / 2.0f) / getAltitude()),
+ double(size.width) / size.height, 0.1, farZ);
matrix::translate(projMatrix, projMatrix, 0, 0, -getAltitude());
// After the rotateX, z values are in pixel units. Convert them to
// altitude unites. 1 altitude unit = the screen height.
const bool flippedY = viewportMode == ViewportMode::FlippedY;
- matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1.0f / (rotatedNorth() ? getWidth() : getHeight()));
+ matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1,
+ 1.0f / (rotatedNorth() ? size.width : size.height));
using NO = NorthOrientation;
switch (getNorthOrientation()) {
@@ -53,18 +54,14 @@ void TransformState::getProjMatrix(mat4& projMatrix) const {
matrix::rotate_z(projMatrix, projMatrix, getAngle() + getNorthOrientationAngle());
- matrix::translate(projMatrix, projMatrix, pixel_x() - getWidth() / 2.0f,
- pixel_y() - getHeight() / 2.0f, 0);
+ matrix::translate(projMatrix, projMatrix, pixel_x() - size.width / 2.0f,
+ pixel_y() - size.height / 2.0f, 0);
}
#pragma mark - Dimensions
-uint16_t TransformState::getWidth() const {
- return width;
-}
-
-uint16_t TransformState::getHeight() const {
- return height;
+Size TransformState::getSize() const {
+ return size;
}
#pragma mark - North Orientation
@@ -108,12 +105,12 @@ LatLng TransformState::getLatLng(LatLng::WrapMode wrapMode) const {
}
double TransformState::pixel_x() const {
- const double center = (width - Projection::worldSize(scale)) / 2;
+ const double center = (size.width - Projection::worldSize(scale)) / 2;
return center + x;
}
double TransformState::pixel_y() const {
- const double center = (height - Projection::worldSize(scale)) / 2;
+ const double center = (size.height - Projection::worldSize(scale)) / 2;
return center + y;
}
@@ -210,7 +207,7 @@ double TransformState::scaleZoom(double s) const {
}
ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng) const {
- if (width == 0 || height == 0) {
+ if (!size) {
return {};
}
@@ -219,11 +216,11 @@ ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng)
Point<double> pt = Projection::project(latLng, scale) / double(util::tileSize);
vec4 c = {{ pt.x, pt.y, 0, 1 }};
matrix::transformMat4(p, c, mat);
- return { p[0] / p[3], height - p[1] / p[3] };
+ return { p[0] / p[3], size.height - p[1] / p[3] };
}
LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, LatLng::WrapMode wrapMode) const {
- if (width == 0 || height == 0) {
+ if (!size) {
return {};
}
@@ -235,7 +232,7 @@ LatLng TransformState::screenCoordinateToLatLng(const ScreenCoordinate& point, L
if (err) throw std::runtime_error("failed to invert coordinatePointMatrix");
- double flippedY = height - point.y;
+ double flippedY = size.height - point.y;
// since we don't know the correct projected z value for the point,
// unproject two points to get a line and then find the point on that
@@ -273,7 +270,8 @@ mat4 TransformState::coordinatePointMatrix(double z) const {
mat4 TransformState::getPixelMatrix() const {
mat4 m;
matrix::identity(m);
- matrix::scale(m, m, width / 2.0f, -height / 2.0f, 1);
+ matrix::scale(m, m,
+ static_cast<double>(size.width) / 2, -static_cast<double>(size.height) / 2, 1);
matrix::translate(m, m, 1, -1, 0);
return m;
}
@@ -289,17 +287,17 @@ bool TransformState::rotatedNorth() const {
void TransformState::constrain(double& scale_, double& x_, double& y_) const {
// Constrain minimum scale to avoid zooming out far enough to show off-world areas.
scale_ = util::max(scale_,
- static_cast<double>((rotatedNorth() ? height : width) / util::tileSize),
- static_cast<double>((rotatedNorth() ? width : height) / util::tileSize));
+ static_cast<double>(rotatedNorth() ? size.height : size.width) / util::tileSize,
+ static_cast<double>(rotatedNorth() ? size.width : size.height) / util::tileSize);
// Constrain min/max pan to avoid showing off-world areas.
if (constrainMode == ConstrainMode::WidthAndHeight) {
- double max_x = (scale_ * util::tileSize - (rotatedNorth() ? height : width)) / 2;
+ double max_x = (scale_ * util::tileSize - (rotatedNorth() ? size.height : size.width)) / 2;
x_ = std::max(-max_x, std::min(x_, max_x));
}
if (constrainMode != ConstrainMode::None) {
- double max_y = (scale_ * util::tileSize - (rotatedNorth() ? width : height)) / 2;
+ double max_y = (scale_ * util::tileSize - (rotatedNorth() ? size.width : size.height)) / 2;
y_ = std::max(-max_y, std::min(y_, max_y));
}
}
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index 8a12b62a9e..6faaf4ac41 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -6,6 +6,7 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/util/mat4.hpp>
+#include <mbgl/util/size.hpp>
#include <cstdint>
#include <array>
@@ -26,8 +27,7 @@ public:
void getProjMatrix(mat4& matrix) const;
// Dimensions
- uint16_t getWidth() const;
- uint16_t getHeight() const;
+ Size getSize() const;
// North Orientation
NorthOrientation getNorthOrientation() const;
@@ -84,7 +84,7 @@ private:
NorthOrientation orientation = NorthOrientation::Upwards;
// logical dimensions
- uint16_t width = 0, height = 0;
+ Size size;
mat4 coordinatePointMatrix(double z) const;
mat4 getPixelMatrix() const;
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index fc61d6e0a0..effeb086af 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -119,7 +119,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp
// Update the default matrices to the current viewport dimensions.
state.getProjMatrix(projMatrix);
- pixelsToGLUnits = {{ 2.0f / state.getWidth(), -2.0f / state.getHeight() }};
+ pixelsToGLUnits = {{ 2.0f / state.getSize().width, -2.0f / state.getSize().height }};
if (state.getViewportMode() == ViewportMode::FlippedY) {
pixelsToGLUnits[1] *= -1;
}
diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp
index e57bb2205e..5a737369bf 100644
--- a/src/mbgl/renderer/painter_debug.cpp
+++ b/src/mbgl/renderer/painter_debug.cpp
@@ -85,7 +85,8 @@ void Painter::renderDebugFrame(const mat4 &matrix) {
tileBorderArray.bind(plainShader, tileLineStripVertexBuffer, BUFFER_OFFSET_0, context);
plainShader.u_color = { 1.0f, 0.0f, 0.0f, 1.0f };
context.lineWidth = 4.0f * frame.pixelRatio;
- MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, static_cast<GLsizei>(tileLineStripVertexBuffer.vertexCount)));
+ MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0,
+ static_cast<GLsizei>(tileLineStripVertexBuffer.vertexCount)));
}
#ifndef NDEBUG
@@ -101,28 +102,28 @@ void Painter::renderClipMasks(PaintParameters&) {
// Read the stencil buffer
const auto viewport = context.viewport.getCurrentValue();
- auto pixels = std::make_unique<uint8_t[]>(viewport.width * viewport.height);
+ auto pixels = std::make_unique<uint8_t[]>(viewport.size.width * viewport.size.height);
MBGL_CHECK_ERROR(glReadPixels(
- viewport.x, // GLint x
- viewport.y, // GLint y
- viewport.width, // GLsizei width
- viewport.height, // GLsizei height
- GL_STENCIL_INDEX, // GLenum format
- GL_UNSIGNED_BYTE, // GLenum type
- pixels.get() // GLvoid * data
+ viewport.x, // GLint x
+ viewport.y, // GLint y
+ viewport.size.width, // GLsizei width
+ viewport.size.height, // GLsizei height
+ GL_STENCIL_INDEX, // GLenum format
+ GL_UNSIGNED_BYTE, // GLenum type
+ pixels.get() // GLvoid * data
));
// Scale the Stencil buffer to cover the entire color space.
auto it = pixels.get();
- auto end = it + viewport.width * viewport.height;
+ auto end = it + viewport.size.width * viewport.size.height;
const auto factor = 255.0f / *std::max_element(it, end);
for (; it != end; ++it) {
*it *= factor;
}
MBGL_CHECK_ERROR(glWindowPos2i(viewport.x, viewport.y));
- MBGL_CHECK_ERROR(glDrawPixels(viewport.width, viewport.height, GL_LUMINANCE, GL_UNSIGNED_BYTE,
- pixels.get()));
+ MBGL_CHECK_ERROR(glDrawPixels(viewport.size.width, viewport.size.height, GL_LUMINANCE,
+ GL_UNSIGNED_BYTE, pixels.get()));
#endif // MBGL_USE_GLES2
}
#endif // NDEBUG
@@ -140,25 +141,25 @@ void Painter::renderDepthBuffer(PaintParameters&) {
// Read the stencil buffer
const auto viewport = context.viewport.getCurrentValue();
- auto pixels = std::make_unique<uint8_t[]>(viewport.width * viewport.height);
+ auto pixels = std::make_unique<uint8_t[]>(viewport.size.width * viewport.size.height);
const double base = 1.0 / (1.0 - depthRangeSize);
glPixelTransferf(GL_DEPTH_SCALE, base);
glPixelTransferf(GL_DEPTH_BIAS, 1.0 - base);
MBGL_CHECK_ERROR(glReadPixels(
- viewport.x, // GLint x
- viewport.y, // GLint y
- viewport.width, // GLsizei width
- viewport.height, // GLsizei height
- GL_DEPTH_COMPONENT, // GLenum format
- GL_UNSIGNED_BYTE, // GLenum type
- pixels.get() // GLvoid * data
+ viewport.x, // GLint x
+ viewport.y, // GLint y
+ viewport.size.width, // GLsizei width
+ viewport.size.height, // GLsizei height
+ GL_DEPTH_COMPONENT, // GLenum format
+ GL_UNSIGNED_BYTE, // GLenum type
+ pixels.get() // GLvoid * data
));
MBGL_CHECK_ERROR(glWindowPos2i(viewport.x, viewport.y));
- MBGL_CHECK_ERROR(glDrawPixels(viewport.width, viewport.height, GL_LUMINANCE, GL_UNSIGNED_BYTE,
- pixels.get()));
+ MBGL_CHECK_ERROR(glDrawPixels(viewport.size.width, viewport.size.height, GL_LUMINANCE,
+ GL_UNSIGNED_BYTE, pixels.get()));
#endif // MBGL_USE_GLES2
}
#endif // NDEBUG
diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp
index b6606ca40b..95e514298a 100644
--- a/src/mbgl/renderer/painter_fill.cpp
+++ b/src/mbgl/renderer/painter_fill.cpp
@@ -31,8 +31,8 @@ void Painter::renderFill(PaintParameters& parameters,
Color strokeColor = isOutlineColorDefined? properties.fillOutlineColor : fillColor;
const auto viewport = context.viewport.getCurrentValue();
- const std::array<GLfloat, 2> worldSize{ { static_cast<GLfloat>(viewport.width),
- static_cast<GLfloat>(viewport.height) } };
+ const std::array<GLfloat, 2> worldSize{{ static_cast<GLfloat>(viewport.size.width),
+ static_cast<GLfloat>(viewport.size.height) }};
bool pattern = !properties.fillPattern.value.from.empty();
bool outline = properties.fillAntialias && !pattern && isOutlineColorDefined;
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index 85a5786353..9880564ddc 100644
--- a/src/mbgl/renderer/painter_line.cpp
+++ b/src/mbgl/renderer/painter_line.cpp
@@ -47,8 +47,8 @@ void Painter::renderLine(PaintParameters& parameters,
// calculate how much longer the real world distance is at the top of the screen
// than at the middle of the screen.
- float topedgelength = std::sqrt(std::pow(state.getHeight(), 2.0f) / 4.0f * (1.0f + std::pow(state.getAltitude(), 2.0f)));
- float x = state.getHeight() / 2.0f * std::tan(state.getPitch());
+ float topedgelength = std::sqrt(std::pow(state.getSize().height, 2.0f) / 4.0f * (1.0f + std::pow(state.getAltitude(), 2.0f)));
+ float x = state.getSize().height / 2.0f * std::tan(state.getPitch());
float extra = (topedgelength + x) / topedgelength - 1.0f;
mat4 vtxMatrix = tile.translatedMatrix(properties.lineTranslate,
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index 2ed6facad8..a460e6a9db 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -69,7 +69,7 @@ void Painter::renderSDF(SymbolBucket& bucket,
sdfShader.u_texture = 0;
sdfShader.u_pitch = state.getPitch();
sdfShader.u_bearing = -1.0f * state.getAngle();
- sdfShader.u_aspect_ratio = (state.getWidth() * 1.0f) / (state.getHeight() * 1.0f);
+ sdfShader.u_aspect_ratio = double(state.getSize().width) / state.getSize().height;
// adjust min/max zooms for variable font sies
float zoomAdjust = std::log(fontSize / layoutSize) / std::log(2);
diff --git a/src/mbgl/sprite/sprite_atlas.cpp b/src/mbgl/sprite/sprite_atlas.cpp
index 198b0a6c57..f8417c3372 100644
--- a/src/mbgl/sprite/sprite_atlas.cpp
+++ b/src/mbgl/sprite/sprite_atlas.cpp
@@ -128,7 +128,7 @@ void SpriteAtlas::_setSprite(const std::string& name,
auto it = sprites.find(name);
if (it != sprites.end()) {
// There is already a sprite with that name in our store.
- if ((it->second->image.width != sprite->image.width || it->second->image.height != sprite->image.height)) {
+ if (it->second->image.size != sprite->image.size) {
Log::Warning(Event::Sprite, "Can't change sprite dimensions for '%s'", name.c_str());
return;
}
@@ -164,8 +164,8 @@ std::shared_ptr<const SpriteImage> SpriteAtlas::getSprite(const std::string& nam
Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(const SpriteImage& spriteImage) {
- const uint16_t pixel_width = std::ceil(spriteImage.image.width / pixelRatio);
- const uint16_t pixel_height = std::ceil(spriteImage.image.height / pixelRatio);
+ const uint16_t pixel_width = std::ceil(spriteImage.image.size.width / pixelRatio);
+ const uint16_t pixel_height = std::ceil(spriteImage.image.size.height / pixelRatio);
// Increase to next number divisible by 4, but at least 1.
// This is so we can scale down the texture coordinates and pack them
@@ -275,9 +275,10 @@ void SpriteAtlas::copy(const Holder& holder, const SpritePatternMode mode) {
const int padding = 1;
- copyBitmap(srcData, uint32_t(holder.spriteImage->image.width), 0, 0,
- dstData, pixelWidth, (holder.pos.x + padding) * pixelRatio, (holder.pos.y + padding) * pixelRatio, pixelWidth * pixelHeight,
- uint32_t(holder.spriteImage->image.width), uint32_t(holder.spriteImage->image.height), mode);
+ copyBitmap(srcData, holder.spriteImage->image.size.width, 0, 0, dstData, pixelWidth,
+ (holder.pos.x + padding) * pixelRatio, (holder.pos.y + padding) * pixelRatio,
+ pixelWidth * pixelHeight, holder.spriteImage->image.size.width,
+ holder.spriteImage->image.size.height, mode);
dirtyFlag = true;
}
diff --git a/src/mbgl/sprite/sprite_image.cpp b/src/mbgl/sprite/sprite_image.cpp
index d7e422ed1d..1579d9d89e 100644
--- a/src/mbgl/sprite/sprite_image.cpp
+++ b/src/mbgl/sprite/sprite_image.cpp
@@ -13,7 +13,7 @@ SpriteImage::SpriteImage(PremultipliedImage&& image_,
pixelRatio(pixelRatio_),
sdf(sdf_) {
- if (image.size() == 0) {
+ if (!image.valid()) {
throw util::SpriteImageException("Sprite image dimensions may not be zero");
} else if (pixelRatio <= 0) {
throw util::SpriteImageException("Sprite pixelRatio may not be <= 0");
diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp
index 34b1d875b6..8d9b35cb77 100644
--- a/src/mbgl/sprite/sprite_parser.cpp
+++ b/src/mbgl/sprite/sprite_parser.cpp
@@ -13,30 +13,31 @@
namespace mbgl {
SpriteImagePtr createSpriteImage(const PremultipliedImage& image,
- const uint16_t srcX,
- const uint16_t srcY,
- const uint16_t width,
- const uint16_t height,
+ const uint32_t srcX,
+ const uint32_t srcY,
+ const uint32_t width,
+ const uint32_t height,
const double ratio,
const bool sdf) {
// Disallow invalid parameter configurations.
if (width <= 0 || height <= 0 || width > 1024 || height > 1024 ||
ratio <= 0 || ratio > 10 ||
- srcX + width > image.width || srcY + height > image.height) {
+ srcX >= image.size.width || srcY >= image.size.height ||
+ srcX + width > image.size.width || srcY + height > image.size.height) {
Log::Error(Event::Sprite, "Can't create sprite with invalid metrics");
return nullptr;
}
- PremultipliedImage dstImage(width, height);
+ PremultipliedImage dstImage({ width, height });
auto srcData = reinterpret_cast<const uint32_t*>(image.data.get());
auto dstData = reinterpret_cast<uint32_t*>(dstImage.data.get());
// Copy from the source image into our individual sprite image
- for (uint16_t y = 0; y < height; ++y) {
+ for (uint32_t y = 0; y < height; ++y) {
const auto dstRow = y * width;
- const auto srcRow = (y + srcY) * image.width + srcX;
- for (uint16_t x = 0; x < width; ++x) {
+ const auto srcRow = (y + srcY) * image.size.width + srcX;
+ for (uint32_t x = 0; x < width; ++x) {
dstData[dstRow + x] = srcData[srcRow + x];
}
}
diff --git a/src/mbgl/sprite/sprite_parser.hpp b/src/mbgl/sprite/sprite_parser.hpp
index 6a564ce330..4a63d4858a 100644
--- a/src/mbgl/sprite/sprite_parser.hpp
+++ b/src/mbgl/sprite/sprite_parser.hpp
@@ -17,10 +17,10 @@ using SpriteImagePtr = std::shared_ptr<const SpriteImage>;
// Extracts an individual image from a spritesheet from the given location.
SpriteImagePtr createSpriteImage(const PremultipliedImage&,
- uint16_t srcX,
- uint16_t srcY,
- uint16_t srcWidth,
- uint16_t srcHeight,
+ uint32_t srcX,
+ uint32_t srcY,
+ uint32_t srcWidth,
+ uint32_t srcHeight,
double ratio,
bool sdf);
diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp
index a0686e353c..124d6b0ce9 100644
--- a/src/mbgl/style/layers/custom_layer_impl.cpp
+++ b/src/mbgl/style/layers/custom_layer_impl.cpp
@@ -48,8 +48,8 @@ void CustomLayer::Impl::render(const TransformState& state) const {
CustomLayerRenderParameters parameters;
- parameters.width = state.getWidth();
- parameters.height = state.getHeight();
+ parameters.width = state.getSize().width;
+ parameters.height = state.getSize().height;
parameters.latitude = state.getLatLng().latitude;
parameters.longitude = state.getLatLng().longitude;
parameters.zoom = state.getZoom();
diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp
index 68e2feed1b..afaa94878c 100644
--- a/src/mbgl/style/source_impl.cpp
+++ b/src/mbgl/style/source_impl.cpp
@@ -139,8 +139,8 @@ void Source::Impl::updateTiles(const UpdateParameters& parameters) {
if (type != SourceType::Raster && type != SourceType::Annotations && cache.getSize() == 0) {
size_t conservativeCacheSize =
- ((float)parameters.transformState.getWidth() / util::tileSize) *
- ((float)parameters.transformState.getHeight() / util::tileSize) *
+ ((float)parameters.transformState.getSize().width / util::tileSize) *
+ ((float)parameters.transformState.getSize().height / util::tileSize) *
(parameters.transformState.getMaxZoom() - parameters.transformState.getMinZoom() + 1) *
0.5;
cache.setSize(conservativeCacheSize);
@@ -202,7 +202,7 @@ std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRendere
for (const auto& p : parameters.geometry) {
queryGeometry.push_back(TileCoordinate::fromScreenCoordinate(
- parameters.transformState, 0, { p.x, parameters.transformState.getHeight() - p.y }).p);
+ parameters.transformState, 0, { p.x, parameters.transformState.getSize().height - p.y }).p);
}
mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry);
diff --git a/src/mbgl/util/offscreen_texture.cpp b/src/mbgl/util/offscreen_texture.cpp
index 40bb70b70e..6352e38ab7 100644
--- a/src/mbgl/util/offscreen_texture.cpp
+++ b/src/mbgl/util/offscreen_texture.cpp
@@ -7,9 +7,9 @@
namespace mbgl {
-OffscreenTexture::OffscreenTexture(gl::Context& context_, std::array<uint16_t, 2> size_)
- : context(context_), size(std::move(size_)) {
- assert(size[0] > 0 && size[1] > 0);
+OffscreenTexture::OffscreenTexture(gl::Context& context_, const Size size_)
+ : size(std::move(size_)), context(context_) {
+ assert(size);
}
void OffscreenTexture::bind() {
@@ -20,7 +20,7 @@ void OffscreenTexture::bind() {
context.bindFramebuffer = framebuffer->framebuffer;
}
- context.viewport = { 0, 0, size[0], size[1] };
+ context.viewport = { 0, 0, size };
}
gl::Texture& OffscreenTexture::getTexture() {
@@ -29,13 +29,14 @@ gl::Texture& OffscreenTexture::getTexture() {
}
PremultipliedImage OffscreenTexture::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);
diff --git a/src/mbgl/util/offscreen_texture.hpp b/src/mbgl/util/offscreen_texture.hpp
index 8928bc2434..64eb7bc565 100644
--- a/src/mbgl/util/offscreen_texture.hpp
+++ b/src/mbgl/util/offscreen_texture.hpp
@@ -14,7 +14,7 @@ class Context;
class OffscreenTexture : public View {
public:
- OffscreenTexture(gl::Context&, std::array<uint16_t, 2> size = {{ 256, 256 }});
+ OffscreenTexture(gl::Context&, Size size = { 256, 256 });
void bind() override;
@@ -22,9 +22,11 @@ public:
gl::Texture& getTexture();
+public:
+ const Size size;
+
private:
gl::Context& context;
- std::array<uint16_t, 2> size;
optional<gl::Framebuffer> framebuffer;
optional<gl::Texture> texture;
};
diff --git a/src/mbgl/util/premultiply.cpp b/src/mbgl/util/premultiply.cpp
index e0178fda33..219273d7cc 100644
--- a/src/mbgl/util/premultiply.cpp
+++ b/src/mbgl/util/premultiply.cpp
@@ -8,12 +8,11 @@ namespace util {
PremultipliedImage premultiply(UnassociatedImage&& src) {
PremultipliedImage dst;
- dst.width = src.width;
- dst.height = src.height;
+ dst.size = src.size;
dst.data = std::move(src.data);
uint8_t* data = dst.data.get();
- for (size_t i = 0; i < dst.size(); i += 4) {
+ for (size_t i = 0; i < dst.bytes(); i += 4) {
uint8_t& r = data[i + 0];
uint8_t& g = data[i + 1];
uint8_t& b = data[i + 2];
@@ -29,12 +28,11 @@ PremultipliedImage premultiply(UnassociatedImage&& src) {
UnassociatedImage unpremultiply(PremultipliedImage&& src) {
UnassociatedImage dst;
- dst.width = src.width;
- dst.height = src.height;
+ dst.size = src.size;
dst.data = std::move(src.data);
uint8_t* data = dst.data.get();
- for (size_t i = 0; i < dst.size(); i += 4) {
+ for (size_t i = 0; i < dst.bytes(); i += 4) {
uint8_t& r = data[i + 0];
uint8_t& g = data[i + 1];
uint8_t& b = data[i + 2];
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index c6bf7d362a..2fb7371aba 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -157,8 +157,8 @@ std::vector<UnwrappedTileID> tileCover(const LatLngBounds& bounds_, int32_t z) {
}
std::vector<UnwrappedTileID> tileCover(const TransformState& state, int32_t z) {
- const double w = state.getWidth();
- const double h = state.getHeight();
+ const double w = state.getSize().width;
+ const double h = state.getSize().height;
return tileCover(
TileCoordinate::fromScreenCoordinate(state, z, { 0, 0 }).p,
TileCoordinate::fromScreenCoordinate(state, z, { w, 0 }).p,