summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/map/map.hpp8
-rw-r--r--include/mbgl/platform/default/glfw_view.hpp4
-rw-r--r--include/mbgl/platform/default/offscreen_view.hpp6
-rw-r--r--include/mbgl/sprite/sprite_image.hpp4
-rw-r--r--include/mbgl/util/image.hpp36
-rw-r--r--include/mbgl/util/size.hpp32
6 files changed, 61 insertions, 29 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index b1c840e68d..6656bccd51 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -6,6 +6,7 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/util/size.hpp>
#include <mbgl/annotation/annotation.hpp>
#include <mbgl/style/transition_options.hpp>
@@ -33,7 +34,7 @@ class Layer;
class Map : private util::noncopyable {
public:
explicit Map(Backend&,
- std::array<uint16_t, 2> size,
+ Size size,
float pixelRatio,
FileSource&,
Scheduler&,
@@ -136,9 +137,8 @@ public:
ViewportMode getViewportMode() const;
// Size
- void setSize(const std::array<uint16_t, 2>&);
- uint16_t getWidth() const;
- uint16_t getHeight() const;
+ void setSize(Size);
+ Size getSize() const;
// Projection
double getMetersPerPixelAtLatitude(double lat, double zoom) const;
diff --git a/include/mbgl/platform/default/glfw_view.hpp b/include/mbgl/platform/default/glfw_view.hpp
index e832cd70d1..c640f188f9 100644
--- a/include/mbgl/platform/default/glfw_view.hpp
+++ b/include/mbgl/platform/default/glfw_view.hpp
@@ -34,8 +34,8 @@ public:
// mbgl::View implementation
void updateViewBinding();
void bind() override;
- std::array<uint16_t, 2> getSize() const;
- std::array<uint16_t, 2> getFramebufferSize() const;
+ mbgl::Size getSize() const;
+ mbgl::Size getFramebufferSize() const;
// mbgl::Backend implementation
void activate() override;
diff --git a/include/mbgl/platform/default/offscreen_view.hpp b/include/mbgl/platform/default/offscreen_view.hpp
index 034aa3aaf3..0e839e14cc 100644
--- a/include/mbgl/platform/default/offscreen_view.hpp
+++ b/include/mbgl/platform/default/offscreen_view.hpp
@@ -14,17 +14,17 @@ class Context;
class OffscreenView : public View {
public:
- OffscreenView(gl::Context&, std::array<uint16_t, 2> size = {{ 256, 256 }});
+ OffscreenView(gl::Context&, Size size = { 256, 256 });
void bind() override;
PremultipliedImage readStillImage();
- std::array<uint16_t, 2> getSize() const;
+public:
+ const Size size;
private:
gl::Context& context;
- std::array<uint16_t, 2> size;
optional<gl::Framebuffer> framebuffer;
optional<gl::Renderbuffer<gl::RenderbufferType::RGBA>> color;
optional<gl::Renderbuffer<gl::RenderbufferType::DepthStencil>> depthStencil;
diff --git a/include/mbgl/sprite/sprite_image.hpp b/include/mbgl/sprite/sprite_image.hpp
index 7900b90b66..05d9871bf9 100644
--- a/include/mbgl/sprite/sprite_image.hpp
+++ b/include/mbgl/sprite/sprite_image.hpp
@@ -22,8 +22,8 @@ public:
// Whether this image should be interpreted as a signed distance field icon.
const bool sdf;
- float getWidth() const { return image.width / pixelRatio; }
- float getHeight() const { return image.height / pixelRatio; }
+ float getWidth() const { return image.size.width / pixelRatio; }
+ float getHeight() const { return image.size.height / pixelRatio; }
};
} // namespace mbgl
diff --git a/include/mbgl/util/image.hpp b/include/mbgl/util/image.hpp
index 795d1f9d1a..3dbab27f41 100644
--- a/include/mbgl/util/image.hpp
+++ b/include/mbgl/util/image.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/util/size.hpp>
#include <string>
#include <memory>
@@ -18,39 +19,38 @@ class Image : private util::noncopyable {
public:
Image() = default;
- Image(uint16_t w, uint16_t h)
- : width(w),
- height(h),
- data(std::make_unique<uint8_t[]>(size())) {}
+ Image(Size size_)
+ : size(std::move(size_)),
+ data(std::make_unique<uint8_t[]>(bytes())) {}
- Image(uint16_t w, uint16_t h, std::unique_ptr<uint8_t[]> data_)
- : width(w),
- height(h),
+ Image(Size size_, std::unique_ptr<uint8_t[]> data_)
+ : size(std::move(size_)),
data(std::move(data_)) {}
Image(Image&& o)
- : width(o.width),
- height(o.height),
+ : size(o.size),
data(std::move(o.data)) {}
Image& operator=(Image&& o) {
- width = o.width;
- height = o.height;
+ size = o.size;
data = std::move(o.data);
return *this;
}
bool operator==(const Image& rhs) const {
- return width == rhs.width && height == rhs.height &&
- std::equal(data.get(), data.get() + size(), rhs.data.get(),
- rhs.data.get() + rhs.size());
+ return size == rhs.size &&
+ std::equal(data.get(), data.get() + bytes(), rhs.data.get(),
+ rhs.data.get() + rhs.bytes());
}
- size_t stride() const { return static_cast<size_t>(width) * 4; }
- size_t size() const { return static_cast<size_t>(width) * height * 4; }
+ bool valid() const {
+ return size && data.get() != nullptr;
+ }
+
+ size_t stride() const { return static_cast<size_t>(size.width) * 4; }
+ size_t bytes() const { return stride() * size.height; }
- uint16_t width = 0;
- uint16_t height = 0;
+ Size size;
std::unique_ptr<uint8_t[]> data;
};
diff --git a/include/mbgl/util/size.hpp b/include/mbgl/util/size.hpp
new file mode 100644
index 0000000000..c0e2fd8180
--- /dev/null
+++ b/include/mbgl/util/size.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <cstdint>
+#include <array>
+
+namespace mbgl {
+
+class Size {
+public:
+ constexpr Size() : width(0), height(0) {
+ }
+
+ constexpr Size(const uint32_t width_, const uint32_t height_) : width(width_), height(height_) {
+ }
+
+ constexpr operator bool() const {
+ return width > 0 && height > 0;
+ }
+
+ uint32_t width;
+ uint32_t height;
+};
+
+constexpr inline bool operator==(const Size& a, const Size& b) {
+ return a.width == b.width && a.height == b.height;
+}
+
+constexpr inline bool operator!=(const Size& a, const Size& b) {
+ return !(a == b);
+}
+
+} // namespace mbgl