From bad4c96603ad50c7e8f51ab15e80d47f0220f62b Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Tue, 11 Nov 2014 14:59:01 -0800 Subject: [PATCH 01/47] "skip install" for lib Xcode targets for easier app archiving --- gyp/mbgl-core.gypi | 1 + gyp/mbgl-ios.gypi | 1 + 2 files changed, 2 insertions(+) diff --git a/gyp/mbgl-core.gypi b/gyp/mbgl-core.gypi index 46ff76274..022480350 100644 --- a/gyp/mbgl-core.gypi +++ b/gyp/mbgl-core.gypi @@ -37,6 +37,7 @@ 'xcode_settings': { 'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags_cc)' ], 'OTHER_CFLAGS': [ '<@(cflags)' ], + 'SKIP_INSTALL': 'YES' }, }, { 'cflags_cc': [ '<@(cflags_cc)' ], diff --git a/gyp/mbgl-ios.gypi b/gyp/mbgl-ios.gypi index 5566ca3a3..dd1c9c0c2 100644 --- a/gyp/mbgl-ios.gypi +++ b/gyp/mbgl-ios.gypi @@ -12,6 +12,7 @@ 'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0', 'CLANG_ENABLE_OBJC_ARC': 'YES', 'CODE_SIGN_IDENTITY': 'iPhone Developer', + 'SKIP_INSTALL': 'YES' }, 'configurations': { 'Release': { From 9051ae17cf65339546b6328896f3d2854b16c861 Mon Sep 17 00:00:00 2001 From: artemp Date: Mon, 17 Nov 2014 11:40:27 +0100 Subject: [PATCH 02/47] fix png_reader --- platform/default/png_reader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index 33d17a1b8..76437dec3 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -248,7 +248,7 @@ void png_reader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char // alloc row pointers const std::unique_ptr rows(new png_bytep[height_]); for (unsigned row = 0; row < height_; ++row) - rows[row] = (png_bytep)image + row * width_ ; + rows[row] = (png_bytep)image + row * width_ * 4 ; png_read_image(png_ptr, rows.get()); } else @@ -263,7 +263,7 @@ void png_reader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char png_read_row(png_ptr,row.get(),0); if (i >= y0 && i < (y0 + h)) { - std::copy(&row[x0 * 4], &row[x0 * 4] + w, image + i * width_* 4); + std::copy(&row[x0 * 4], &row[x0 * 4] + w * 4, image + i * width_* 4); } } } From 08357cfcf86ad0b6c8e8563767110ed50cbb2f56 Mon Sep 17 00:00:00 2001 From: artemp Date: Mon, 17 Nov 2014 12:21:58 +0100 Subject: [PATCH 03/47] image-readers: only register readers that are used create_png_reader(char const* data, size_t size) create_jpeg_reader(char const* data, size_t size) --- platform/default/jpeg_reader.cpp | 10 ++-------- platform/default/png_reader.cpp | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/platform/default/jpeg_reader.cpp b/platform/default/jpeg_reader.cpp index d56c10af2..f1e9d0fdf 100644 --- a/platform/default/jpeg_reader.cpp +++ b/platform/default/jpeg_reader.cpp @@ -71,18 +71,12 @@ private: namespace { -image_reader* create_jpeg_reader(std::string const& file) -{ - return new jpeg_reader(file); -} - -image_reader* create_jpeg_reader2(char const* data, size_t size) +image_reader* create_jpeg_reader(char const* data, size_t size) { return new jpeg_reader(data, size); } -const static bool registered = register_image_reader("jpeg",create_jpeg_reader); -const static bool registered2 = register_image_reader("jpeg",create_jpeg_reader2); +const static bool registered = register_image_reader("jpeg",create_jpeg_reader); } // ctors diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index 76437dec3..838344286 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -61,19 +61,13 @@ private: namespace { - -image_reader* create_png_reader(std::string const& file) -{ - return new png_reader(file); -} - -image_reader* create_png_reader2(char const * data, std::size_t size) +image_reader* create_png_reader(char const * data, std::size_t size) { return new png_reader(data, size); } const static bool registered = register_image_reader("png",create_png_reader); -const static bool registered2 = register_image_reader("png", create_png_reader2); + } From 0547ae118424d68e60aeaa1911be53427afa9e4a Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Mon, 17 Nov 2014 11:53:58 -0800 Subject: [PATCH 04/47] add note about access token & where to find Linux binary --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 022377e99..75a648678 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,8 @@ Or proceed to building the debug application with: make linux +Be sure to setup an access token per below before running `build/Release/mapbox-gl`. + # Troubleshooting From 759a5e65cf853d679650339e26fef25141ab1901 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 19 Nov 2014 13:06:47 +0100 Subject: [PATCH 05/47] simplify image_readers creation implementation * remove static callbacks registration * link png_reader/jpeg_reader into mbgl-linux lib --- gyp/mbgl-linux.gypi | 3 + include/mbgl/util/factory.hpp | 55 ------------- include/mbgl/util/image_reader.hpp | 7 -- include/mbgl/util/jpeg_reader.hpp | 69 ++++++++++++++++ include/mbgl/util/png_reader.hpp | 62 ++++++++++++++ include/mbgl/util/singleton.hpp | 126 ----------------------------- linux/mapboxgl-app.gyp | 2 - platform/default/image_reader.cpp | 16 +++- platform/default/jpeg_reader.cpp | 87 ++------------------ platform/default/png_reader.cpp | 75 +---------------- test/test.gyp | 1 - 11 files changed, 156 insertions(+), 347 deletions(-) delete mode 100644 include/mbgl/util/factory.hpp create mode 100644 include/mbgl/util/jpeg_reader.hpp create mode 100644 include/mbgl/util/png_reader.hpp delete mode 100644 include/mbgl/util/singleton.hpp diff --git a/gyp/mbgl-linux.gypi b/gyp/mbgl-linux.gypi index a66a80ebf..aee928685 100644 --- a/gyp/mbgl-linux.gypi +++ b/gyp/mbgl-linux.gypi @@ -8,6 +8,7 @@ 'variables': { 'cflags_cc': [ '<@(png_cflags)', + '<@(jpeg_cflags)', '<@(uv_cflags)', '<@(curl_cflags)', '<@(nu_cflags)', @@ -32,6 +33,8 @@ '../platform/default/http_request_baton_curl.cpp', '../platform/default/image.cpp', '../platform/default/image_reader.cpp', + '../platform/default/png_reader.cpp', + '../platform/default/jpeg_reader.cpp', ], 'include_dirs': [ '../include', diff --git a/include/mbgl/util/factory.hpp b/include/mbgl/util/factory.hpp deleted file mode 100644 index 1ffcac6f9..000000000 --- a/include/mbgl/util/factory.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef MBGL_UTIL_FACTORY_HPP -#define MBGL_UTIL_FACTORY_HPP - -// stl -#include -#include -#include - -namespace mbgl { namespace util { - -template -< -typename product_type, -typename key_type, -typename ...Args > -class factory -{ -public: - using product_creator = product_type* (*) (Args...); - using product_map = std::map; - static product_map map_; - static std::mutex mutex_; -public: - - static bool register_product(key_type const& key, product_creator creator) - { - std::unique_lock lock(mutex_); - return map_.insert(typename product_map::value_type(key,creator)).second; - } - - static bool unregister_product(const key_type& key) - { - std::unique_lock lock(mutex_); - return map_.erase(key)==1; - } - - static product_type* create_object(key_type const& key, Args...args) - { - typename product_map::const_iterator pos=map_.find(key); - if (pos!=map_.end()) - { - return (pos->second)(args...); - } - return 0; - } -}; - -template -typename factory::product_map factory::map_; -template -typename std::mutex factory::mutex_; - -}} - -#endif diff --git a/include/mbgl/util/image_reader.hpp b/include/mbgl/util/image_reader.hpp index 144127b76..589653ec5 100644 --- a/include/mbgl/util/image_reader.hpp +++ b/include/mbgl/util/image_reader.hpp @@ -1,7 +1,6 @@ #ifndef MBGL_UTIL_IMAGE_READER_HPP #define MBGL_UTIL_IMAGE_READER_HPP -#include "factory.hpp" #include "noncopyable.hpp" // stl #include @@ -35,12 +34,6 @@ struct image_reader : private noncopyable virtual ~image_reader() {} }; -template -bool register_image_reader(std::string const& type, image_reader* (* fun)(Args...)) -{ - return factory::register_product(type, fun); -} - image_reader* get_image_reader(char const* data, size_t size); }} diff --git a/include/mbgl/util/jpeg_reader.hpp b/include/mbgl/util/jpeg_reader.hpp new file mode 100644 index 000000000..77356007d --- /dev/null +++ b/include/mbgl/util/jpeg_reader.hpp @@ -0,0 +1,69 @@ +#ifndef MBGL_UTIL_JPEG_READER_HPP +#define MBGL_UTIL_JPEG_READER_HPP + +#include "image_reader.hpp" + +// jpeg +extern "C" +{ +#include +} + +#include + +namespace mbgl { namespace util { + +template +class jpeg_reader : public image_reader +{ +public: + using source_type = T; + using input_stream = boost::iostreams::stream; + const static unsigned BUF_SIZE = 4096; +private: + struct jpeg_stream_wrapper + { + jpeg_source_mgr manager; + input_stream * stream; + JOCTET buffer[BUF_SIZE]; + }; + + struct jpeg_info_guard + { + jpeg_info_guard(jpeg_decompress_struct * cinfo) + : i_(cinfo) {} + + ~jpeg_info_guard() + { + jpeg_destroy_decompress(i_); + } + jpeg_decompress_struct * i_; + }; + +private: + source_type source_; + input_stream stream_; + unsigned width_; + unsigned height_; +public: + jpeg_reader(char const* data, size_t size); + ~jpeg_reader(); + unsigned width() const; + unsigned height() const; + inline bool has_alpha() const { return false; } + inline bool premultiplied_alpha() const { return true; } + void read(unsigned x,unsigned y, unsigned w, unsigned h, char *image); +private: + void init(); + static void on_error(j_common_ptr cinfo); + static void on_error_message(j_common_ptr cinfo); + static void init_source(j_decompress_ptr cinfo); + static boolean fill_input_buffer(j_decompress_ptr cinfo); + static void skip(j_decompress_ptr cinfo, long count); + static void term(j_decompress_ptr cinfo); + static void attach_stream(j_decompress_ptr cinfo, input_stream* in); +}; + +}} + +#endif // MBGL_UTIL_JPEG_READER_HPP diff --git a/include/mbgl/util/png_reader.hpp b/include/mbgl/util/png_reader.hpp new file mode 100644 index 000000000..3d6e1db51 --- /dev/null +++ b/include/mbgl/util/png_reader.hpp @@ -0,0 +1,62 @@ +#ifndef MBGL_UTIL_PNG_READER_HPP +#define MBGL_UTIL_PNG_READER_HPP + +#include "mbgl/util/image_reader.hpp" + +extern "C" +{ +#include +} + +#include +#include + +#include + +namespace mbgl { namespace util { + +template +class png_reader : public image_reader +{ + using source_type = T; + using input_stream = boost::iostreams::stream; + + struct png_struct_guard + { + png_struct_guard(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) + : p_(png_ptr_ptr), + i_(info_ptr_ptr) {} + + ~png_struct_guard() + { + png_destroy_read_struct(p_,i_,0); + } + png_structpp p_; + png_infopp i_; + }; + +private: + source_type source_; + input_stream stream_; + unsigned width_; + unsigned height_; + int bit_depth_; + int color_type_; + bool has_alpha_; +public: + png_reader(char const* data, std::size_t size); + ~png_reader(); + unsigned width() const; + unsigned height() const; + inline bool has_alpha() const { return has_alpha_; } + bool premultiplied_alpha() const { return false; } //http://www.libpng.org/pub/png/spec/1.1/PNG-Rationale.html + void read(unsigned x,unsigned y, unsigned width, unsigned height, char * image); +private: + void init(); + static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length); +}; + + +}} + +#endif // MBGL_UTIL_PNG_READER_HPP diff --git a/include/mbgl/util/singleton.hpp b/include/mbgl/util/singleton.hpp deleted file mode 100644 index a1c1e3ebf..000000000 --- a/include/mbgl/util/singleton.hpp +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef MBGL_UTIL_SINGLETON_HPP -#define MBGL_UTIL_SINGLETON_HPP - -// stl -#include // std::runtime_error -#include // std::atexit -#include // operator new -#define SINGLETON_THREADSAFE -#ifdef SINGLETON_THREADSAFE -#include -#endif - -namespace mbgl { namespace util { - -template -class CreateUsingNew -{ -public: - static T* create() - { - return new T; - } - static void destroy(T* obj) - { - delete obj; - } -}; - -template -class CreateStatic -{ -private: - union MaxAlign - { - char t_[sizeof(T)]; - short int shortInt_; - int int_; - long int longInt_; - float float_; - double double_; - long double longDouble_; - struct Test; - int Test::* pMember_; - int (Test::*pMemberFn_)(int); - }; - -public: - - static T* create() - { - static MaxAlign staticMemory; - return new(&staticMemory) T; - } - static void destroy(volatile T* obj) - { - obj->~T(); - } -}; - -template class CreatePolicy=CreateStatic> class singleton -{ - friend class CreatePolicy; - static T* pInstance_; - static bool destroyed_; - singleton(const singleton &rhs); - singleton& operator=(const singleton&); - - static void onDeadReference() - { - throw std::runtime_error("dead reference!"); - } - - static void DestroySingleton() - { - CreatePolicy::destroy(pInstance_); - pInstance_ = 0; - destroyed_ = true; - } - -protected: - -#ifdef SINGLETON_THREADSAFE - static std::mutex mutex_; -#endif - singleton() {} - public: - static T& instance() - { - if (! pInstance_) - { -#ifdef SINGLETON_THREADSAFE - std::unique_lock lock(mutex_); -#endif - if (! pInstance_) - { - if (destroyed_) - { - destroyed_ = false; - onDeadReference(); - } - else - { - pInstance_ = CreatePolicy::create(); - // register destruction - std::atexit(&DestroySingleton); - } - } - } - return *pInstance_; - } -}; - -#ifdef SINGLETON_THREADSAFE - template class CreatePolicy> std::mutex singleton::mutex_; -#endif - - template class CreatePolicy> T* singleton::pInstance_=0; - template class CreatePolicy> bool singleton::destroyed_=false; - -}} - -#endif // diff --git a/linux/mapboxgl-app.gyp b/linux/mapboxgl-app.gyp index dbcc4b447..fbeabd74e 100644 --- a/linux/mapboxgl-app.gyp +++ b/linux/mapboxgl-app.gyp @@ -12,8 +12,6 @@ '../platform/default/settings_json.cpp', '../platform/default/glfw_view.cpp', '../platform/default/log_stderr.cpp', - '../platform/default/png_reader.cpp', - '../platform/default/jpeg_reader.cpp', ], 'xcode_settings': { 'OTHER_CPLUSPLUSFLAGS':[ diff --git a/platform/default/image_reader.cpp b/platform/default/image_reader.cpp index 53ab5758a..599ccb13a 100644 --- a/platform/default/image_reader.cpp +++ b/platform/default/image_reader.cpp @@ -1,5 +1,9 @@ #include "mbgl/util/image_reader.hpp" +#include "mbgl/util/png_reader.hpp" +#include "mbgl/util/jpeg_reader.hpp" + #include +#include namespace mbgl { namespace util { @@ -43,10 +47,16 @@ image_reader* get_image_reader(char const* data, size_t size) boost::optional type = type_from_bytes(data,size); if (type) { - return factory::create_object(*type, data,size); + if (*type == "png") + { + return new png_reader(data, size); + } + else if (*type == "jpeg") + { + return new jpeg_reader(data, size); + } } - else - throw image_reader_exception("image_reader: can't determine type from input data"); + throw image_reader_exception("image_reader: can't determine type from input data"); } }} diff --git a/platform/default/jpeg_reader.cpp b/platform/default/jpeg_reader.cpp index f1e9d0fdf..b722c08fa 100644 --- a/platform/default/jpeg_reader.cpp +++ b/platform/default/jpeg_reader.cpp @@ -1,15 +1,9 @@ -#include "mbgl/util/image_reader.hpp" - -// jpeg -extern "C" -{ -#include -} +#include "mbgl/util/jpeg_reader.hpp" // boost #include #include -#include + // std #include @@ -17,80 +11,7 @@ extern "C" namespace mbgl { namespace util { -template -class jpeg_reader : public image_reader -{ -public: - using source_type = T; - using input_stream = boost::iostreams::stream; - const static unsigned BUF_SIZE = 4096; -private: - struct jpeg_stream_wrapper - { - jpeg_source_mgr manager; - input_stream * stream; - JOCTET buffer[BUF_SIZE]; - }; - - struct jpeg_info_guard - { - jpeg_info_guard(jpeg_decompress_struct * cinfo) - : i_(cinfo) {} - - ~jpeg_info_guard() - { - jpeg_destroy_decompress(i_); - } - jpeg_decompress_struct * i_; - }; - -private: - source_type source_; - input_stream stream_; - unsigned width_; - unsigned height_; -public: - explicit jpeg_reader(std::string const& file_name); - explicit jpeg_reader(char const* data, size_t size); - ~jpeg_reader(); - unsigned width() const; - unsigned height() const; - inline bool has_alpha() const { return false; } - inline bool premultiplied_alpha() const { return true; } - void read(unsigned x,unsigned y, unsigned w, unsigned h, char *image); -private: - void init(); - static void on_error(j_common_ptr cinfo); - static void on_error_message(j_common_ptr cinfo); - static void init_source(j_decompress_ptr cinfo); - static boolean fill_input_buffer(j_decompress_ptr cinfo); - static void skip(j_decompress_ptr cinfo, long count); - static void term(j_decompress_ptr cinfo); - static void attach_stream(j_decompress_ptr cinfo, input_stream* in); -}; - -namespace -{ -image_reader* create_jpeg_reader(char const* data, size_t size) -{ - return new jpeg_reader(data, size); -} - -const static bool registered = register_image_reader("jpeg",create_jpeg_reader); -} - -// ctors -template -jpeg_reader::jpeg_reader(std::string const& file_name) - : source_(file_name,std::ios_base::in | std::ios_base::binary), - stream_(source_), - width_(0), - height_(0) -{ - if (!stream_) throw image_reader_exception("cannot open image file "+ file_name); - init(); -} - +// ctor template jpeg_reader::jpeg_reader(char const* data, size_t size) : source_(data, size), @@ -277,4 +198,6 @@ void jpeg_reader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char jpeg_finish_decompress(&cinfo); } +template class jpeg_reader; + }} diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index 838344286..4d0abce04 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -1,4 +1,4 @@ -#include "mbgl/util/image_reader.hpp" +#include "mbgl/util/png_reader.hpp" #include extern "C" { @@ -16,61 +16,6 @@ extern "C" namespace mbgl { namespace util { -template -class png_reader : public image_reader -{ - using source_type = T; - using input_stream = boost::iostreams::stream; - - struct png_struct_guard - { - png_struct_guard(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) - : p_(png_ptr_ptr), - i_(info_ptr_ptr) {} - - ~png_struct_guard() - { - png_destroy_read_struct(p_,i_,0); - } - png_structpp p_; - png_infopp i_; - }; - -private: - - source_type source_; - input_stream stream_; - unsigned width_; - unsigned height_; - int bit_depth_; - int color_type_; - bool has_alpha_; -public: - explicit png_reader(std::string const& file_name); - png_reader(char const* data, std::size_t size); - ~png_reader(); - unsigned width() const; - unsigned height() const; - inline bool has_alpha() const { return has_alpha_; } - bool premultiplied_alpha() const { return false; } //http://www.libpng.org/pub/png/spec/1.1/PNG-Rationale.html - void read(unsigned x,unsigned y, unsigned width, unsigned height, char * image); -private: - void init(); - static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length); -}; - -namespace -{ -image_reader* create_png_reader(char const * data, std::size_t size) -{ - return new png_reader(data, size); -} - -const static bool registered = register_image_reader("png",create_png_reader); - -} - - void user_error_fn(png_structp /*png_ptr*/, png_const_charp error_msg) { throw image_reader_exception(std::string("failed to read invalid png: '") + error_msg + "'"); @@ -94,21 +39,6 @@ void png_reader::png_read_data(png_structp png_ptr, png_bytep data, png_size_ } } -template -png_reader::png_reader(std::string const& file_name) - : source_(file_name,std::ios_base::in | std::ios_base::binary), - stream_(source_), - width_(0), - height_(0), - bit_depth_(0), - color_type_(0), - has_alpha_(false) -{ - if (!source_.is_open()) throw image_reader_exception("PNG reader: cannot open file '"+ file_name + "'"); - if (!stream_) throw image_reader_exception("PNG reader: cannot open file '"+ file_name + "'"); - init(); -} - template png_reader::png_reader(char const* data, std::size_t size) : source_(data,size), @@ -263,4 +193,7 @@ void png_reader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char } png_read_end(png_ptr,0); } + +template class png_reader; + }} diff --git a/test/test.gyp b/test/test.gyp index fecb6ed93..86dbcc08a 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -163,7 +163,6 @@ 'type': 'executable', 'sources': [ './headless.cpp', - '../platform/default/png_reader.cpp', './fixtures/fixture_log.cpp', ], 'conditions': [ From f7e813238da85270a974e4a045242af2dda0fda0 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 19 Nov 2014 16:17:52 +0100 Subject: [PATCH 06/47] ensure all exceptions are caught in Image ctor --- platform/default/image.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/default/image.cpp b/platform/default/image.cpp index 96d01ab71..9a76ef33f 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -84,12 +84,19 @@ Image::Image(std::string const& data) } catch (image_reader_exception const& ex) { - fprintf(stderr, "ImageReader: %s\n", ex.what()); + fprintf(stderr, "Image: %s\n", ex.what()); img.reset(); width = 0; height = 0; } + catch (...) // catch the rest + { + fprintf(stderr, "Image: exception in constructor"); + img.reset(); + width = 0; + height = 0; + } } } From 04cea00d5dba694387e308215227f20eac0668c7 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 19 Nov 2014 16:31:16 +0100 Subject: [PATCH 07/47] return unique_ptr from get_image_reader --- include/mbgl/util/image_reader.hpp | 2 +- platform/default/image.cpp | 2 +- platform/default/image_reader.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/mbgl/util/image_reader.hpp b/include/mbgl/util/image_reader.hpp index 589653ec5..4bdaf420f 100644 --- a/include/mbgl/util/image_reader.hpp +++ b/include/mbgl/util/image_reader.hpp @@ -34,7 +34,7 @@ struct image_reader : private noncopyable virtual ~image_reader() {} }; -image_reader* get_image_reader(char const* data, size_t size); +std::unique_ptr get_image_reader(char const* data, size_t size); }} diff --git a/platform/default/image.cpp b/platform/default/image.cpp index 9a76ef33f..8d0374c64 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -76,7 +76,7 @@ Image::Image(std::string const& data) { try { - std::unique_ptr reader(get_image_reader(data.c_str(), data.size())); + auto reader = get_image_reader(data.c_str(), data.size()); width = reader->width(); height = reader->height(); img = ::std::unique_ptr(new char[width * height * 4]()); diff --git a/platform/default/image_reader.cpp b/platform/default/image_reader.cpp index 599ccb13a..71b8e0991 100644 --- a/platform/default/image_reader.cpp +++ b/platform/default/image_reader.cpp @@ -1,3 +1,4 @@ +#include "mbgl/util/std.hpp" #include "mbgl/util/image_reader.hpp" #include "mbgl/util/png_reader.hpp" #include "mbgl/util/jpeg_reader.hpp" @@ -42,18 +43,18 @@ inline boost::optional type_from_bytes(char const* data, size_t siz return result_type(); } -image_reader* get_image_reader(char const* data, size_t size) +std::unique_ptr get_image_reader(char const* data, size_t size) { boost::optional type = type_from_bytes(data,size); if (type) { if (*type == "png") { - return new png_reader(data, size); + return std::make_unique>(data, size); } else if (*type == "jpeg") { - return new jpeg_reader(data, size); + return std::make_unique>(data, size); } } throw image_reader_exception("image_reader: can't determine type from input data"); From 813586d1d413e58110c4311190a8677aec3ca2bb Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 19 Nov 2014 16:49:26 +0100 Subject: [PATCH 08/47] move std.hpp include into image_reader.hpp (g++) --- include/mbgl/util/image_reader.hpp | 3 ++- platform/default/image_reader.cpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/mbgl/util/image_reader.hpp b/include/mbgl/util/image_reader.hpp index 4bdaf420f..a35830cf5 100644 --- a/include/mbgl/util/image_reader.hpp +++ b/include/mbgl/util/image_reader.hpp @@ -1,7 +1,8 @@ #ifndef MBGL_UTIL_IMAGE_READER_HPP #define MBGL_UTIL_IMAGE_READER_HPP -#include "noncopyable.hpp" +#include +#include // stl #include #include diff --git a/platform/default/image_reader.cpp b/platform/default/image_reader.cpp index 71b8e0991..86dae78fb 100644 --- a/platform/default/image_reader.cpp +++ b/platform/default/image_reader.cpp @@ -1,4 +1,3 @@ -#include "mbgl/util/std.hpp" #include "mbgl/util/image_reader.hpp" #include "mbgl/util/png_reader.hpp" #include "mbgl/util/jpeg_reader.hpp" From f89c9753ddf9cf31b84e6fd8677291908e146083 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 19 Nov 2014 16:56:53 +0100 Subject: [PATCH 09/47] image-readers: move concrete implementations headers into platform/default --- include/mbgl/{util => platform/default}/image_reader.hpp | 0 include/mbgl/{util => platform/default}/jpeg_reader.hpp | 2 +- include/mbgl/{util => platform/default}/png_reader.hpp | 2 +- platform/default/image.cpp | 3 ++- platform/default/image_reader.cpp | 6 +++--- platform/default/jpeg_reader.cpp | 2 +- platform/default/png_reader.cpp | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) rename include/mbgl/{util => platform/default}/image_reader.hpp (100%) rename include/mbgl/{util => platform/default}/jpeg_reader.hpp (97%) rename include/mbgl/{util => platform/default}/png_reader.hpp (96%) diff --git a/include/mbgl/util/image_reader.hpp b/include/mbgl/platform/default/image_reader.hpp similarity index 100% rename from include/mbgl/util/image_reader.hpp rename to include/mbgl/platform/default/image_reader.hpp diff --git a/include/mbgl/util/jpeg_reader.hpp b/include/mbgl/platform/default/jpeg_reader.hpp similarity index 97% rename from include/mbgl/util/jpeg_reader.hpp rename to include/mbgl/platform/default/jpeg_reader.hpp index 77356007d..964e4731e 100644 --- a/include/mbgl/util/jpeg_reader.hpp +++ b/include/mbgl/platform/default/jpeg_reader.hpp @@ -1,7 +1,7 @@ #ifndef MBGL_UTIL_JPEG_READER_HPP #define MBGL_UTIL_JPEG_READER_HPP -#include "image_reader.hpp" +#include // jpeg extern "C" diff --git a/include/mbgl/util/png_reader.hpp b/include/mbgl/platform/default/png_reader.hpp similarity index 96% rename from include/mbgl/util/png_reader.hpp rename to include/mbgl/platform/default/png_reader.hpp index 3d6e1db51..f6b5aaf9c 100644 --- a/include/mbgl/util/png_reader.hpp +++ b/include/mbgl/platform/default/png_reader.hpp @@ -1,7 +1,7 @@ #ifndef MBGL_UTIL_PNG_READER_HPP #define MBGL_UTIL_PNG_READER_HPP -#include "mbgl/util/image_reader.hpp" +#include extern "C" { diff --git a/platform/default/image.cpp b/platform/default/image.cpp index 8d0374c64..558f33cb8 100644 --- a/platform/default/image.cpp +++ b/platform/default/image.cpp @@ -7,7 +7,8 @@ #include #include #include -#include + +#include // Check png library version. const static bool png_version_check = []() { diff --git a/platform/default/image_reader.cpp b/platform/default/image_reader.cpp index 86dae78fb..2e2842d19 100644 --- a/platform/default/image_reader.cpp +++ b/platform/default/image_reader.cpp @@ -1,6 +1,6 @@ -#include "mbgl/util/image_reader.hpp" -#include "mbgl/util/png_reader.hpp" -#include "mbgl/util/jpeg_reader.hpp" +#include +#include +#include #include #include diff --git a/platform/default/jpeg_reader.cpp b/platform/default/jpeg_reader.cpp index b722c08fa..18350c3e7 100644 --- a/platform/default/jpeg_reader.cpp +++ b/platform/default/jpeg_reader.cpp @@ -1,4 +1,4 @@ -#include "mbgl/util/jpeg_reader.hpp" +#include // boost #include diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index 4d0abce04..e9f38a9d3 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -1,4 +1,4 @@ -#include "mbgl/util/png_reader.hpp" +#include #include extern "C" { From b45b855b411b04e8d91df4e08a0e4e6b29cb8123 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 20 Nov 2014 13:08:04 -0500 Subject: [PATCH 10/47] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75a648678..998618f7b 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Install GCC 4.8+ if you are running Ubuntu 13.10 or older. Alternatively, you ca Ensure you have git and other build essentials: - sudo apt-get install git build-essential zlib1g-dev automake \ + sudo apt-get install curl git build-essential zlib1g-dev automake \ libtool xutils-dev make cmake pkg-config python-pip \ libcurl4-openssl-dev libpng-dev libsqlite3-dev From aaa1e3a6f1a69749371f51bbe96a1908e4bf09e2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 22 Oct 2014 14:59:12 -0700 Subject: [PATCH 11/47] Remove rotation constraints This should be an iOS SDK option, not hard coded into low-level renderering. Fixes #458 --- include/mbgl/map/map.hpp | 1 - include/mbgl/map/transform.hpp | 1 - src/map/map.cpp | 4 ---- src/map/transform.cpp | 12 ------------ 4 files changed, 18 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 43402fe2e..ad33865cd 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -115,7 +115,6 @@ public: void resetNorth(); void startRotating(); void stopRotating(); - bool canRotate(); // Debug void setDebug(bool value); diff --git a/include/mbgl/map/transform.hpp b/include/mbgl/map/transform.hpp index e3604edd8..a42b7aa10 100644 --- a/include/mbgl/map/transform.hpp +++ b/include/mbgl/map/transform.hpp @@ -51,7 +51,6 @@ public: double getAngle() const; void startRotating(); void stopRotating(); - bool canRotate(); // Transitions bool needsTransition() const; diff --git a/src/map/map.cpp b/src/map/map.cpp index 6e9e47fd5..3daaa8798 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -551,10 +551,6 @@ void Map::stopRotating() { update(); } -bool Map::canRotate() { - return transform.canRotate(); -} - #pragma mark - Toggles diff --git a/src/map/transform.cpp b/src/map/transform.cpp index 25aacd483..03e06f984 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -14,7 +14,6 @@ using namespace mbgl; const double D2R = M_PI / 180.0; const double M2PI = 2 * M_PI; -const double MIN_ROTATE_SCALE = 8; Transform::Transform(View &view_) : view(view_) @@ -37,7 +36,6 @@ bool Transform::resize(const uint16_t w, const uint16_t h, const float ratio, current.pixelRatio = final.pixelRatio = ratio; current.framebuffer[0] = final.framebuffer[0] = fb_w; current.framebuffer[1] = final.framebuffer[1] = fb_h; - if (!canRotate() && current.angle) _setAngle(0); constrain(current.scale, current.y); view.notify_map_change(MapChangeRegionDidChange); @@ -286,9 +284,6 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl constrain(final.scale, final.y); - // Undo rotation at low zooms. - if (!canRotate() && current.angle) _setAngle(0); - if (duration == 0) { current.scale = final.scale; current.x = final.x; @@ -398,9 +393,6 @@ void Transform::_setAngle(double new_angle, const timestamp duration) { final.angle = new_angle; - // Prevent rotation at low zooms. - if (!canRotate()) final.angle = 0; - if (duration == 0) { current.angle = final.angle; } else { @@ -449,10 +441,6 @@ void Transform::_clearRotating() { } } -bool Transform::canRotate() { - return (current.scale > MIN_ROTATE_SCALE); -} - #pragma mark - Transition bool Transform::needsTransition() const { From 545292b6f9d461d439972a204ff747f4902dd4d1 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 20 Nov 2014 15:29:10 -0800 Subject: [PATCH 12/47] Fix OS X build --- ios/mapbox-gl-cocoa | 2 +- scripts/travis_before_install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/mapbox-gl-cocoa b/ios/mapbox-gl-cocoa index f801f5b9f..c937adfca 160000 --- a/ios/mapbox-gl-cocoa +++ b/ios/mapbox-gl-cocoa @@ -1 +1 @@ -Subproject commit f801f5b9fa9ca0e55c379f95295bc13338b19110 +Subproject commit c937adfcaee5c73b2b79dae6aa617102010ac0c9 diff --git a/scripts/travis_before_install.sh b/scripts/travis_before_install.sh index 2af2f7ae0..78c0799f6 100755 --- a/scripts/travis_before_install.sh +++ b/scripts/travis_before_install.sh @@ -42,7 +42,7 @@ elif [[ ${TRAVIS_OS_NAME} == "osx" ]]; then # install OS X dependencies # mapbox_time "install_build_tools" \ - brew install autoconf automake libtool makedepend cmake pkg-config node git boost + brew install makedepend git mapbox_time "install_awscli" \ sudo pip install awscli From 4af232dcf347723969aad01d7347ff2cdd8cf575 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 21 Nov 2014 11:28:56 +0100 Subject: [PATCH 13/47] image_readers: premultiply alpha --- include/mbgl/platform/default/png_reader.hpp | 2 +- platform/default/png_reader.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/mbgl/platform/default/png_reader.hpp b/include/mbgl/platform/default/png_reader.hpp index f6b5aaf9c..db20d85e2 100644 --- a/include/mbgl/platform/default/png_reader.hpp +++ b/include/mbgl/platform/default/png_reader.hpp @@ -49,7 +49,7 @@ public: unsigned width() const; unsigned height() const; inline bool has_alpha() const { return has_alpha_; } - bool premultiplied_alpha() const { return false; } //http://www.libpng.org/pub/png/spec/1.1/PNG-Rationale.html + bool premultiplied_alpha() const { return true; } // png_set_alpha_mode(png, PNG_ALPHA_PREMULTIPLIED, 2.2) void read(unsigned x,unsigned y, unsigned width, unsigned height, char * image); private: void init(); diff --git a/platform/default/png_reader.cpp b/platform/default/png_reader.cpp index e9f38a9d3..507db715a 100644 --- a/platform/default/png_reader.cpp +++ b/platform/default/png_reader.cpp @@ -157,6 +157,7 @@ void png_reader::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char double gamma; if (png_get_gAMA(png_ptr, info_ptr, &gamma)) png_set_gamma(png_ptr, 2.2, gamma); + png_set_alpha_mode(png_ptr, PNG_ALPHA_PREMULTIPLIED, 2.2); if (x0 == 0 && y0 == 0 && w >= width_ && h >= height_) { From a9b20fc09a51d62d471d8234387d07a838b4ca76 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 21 Nov 2014 12:50:34 -0800 Subject: [PATCH 14/47] Remove other rotation constraint (fixes #463) --- src/map/transform.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/map/transform.cpp b/src/map/transform.cpp index 03e06f984..d05d1f744 100644 --- a/src/map/transform.cpp +++ b/src/map/transform.cpp @@ -66,12 +66,6 @@ void Transform::_moveBy(const double dx, const double dy, const timestamp durati constrain(final.scale, final.y); - // Un-rotate when rotated and panning far enough to show off-world in corners. - double w = final.scale * util::tileSize / 2; - double m = std::sqrt(std::pow((current.width / 2), 2) + pow((current.height / 2), 2)); - double x = std::abs(sqrt(std::pow(final.x, 2) + std::pow(final.y, 2))); - if (current.angle && w - x < m) _setAngle(0); - if (duration == 0) { current.x = final.x; current.y = final.y; From 9e971095d3561f7af5b0016614035a8b4e479b81 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 20 Nov 2014 17:13:35 -0800 Subject: [PATCH 15/47] Pass FileSource by reference --- include/mbgl/map/sprite.hpp | 4 ++-- include/mbgl/text/glyph_store.hpp | 9 +++------ src/map/map.cpp | 6 +++--- src/map/sprite.cpp | 8 ++++---- src/text/glyph_store.cpp | 8 ++++---- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/include/mbgl/map/sprite.hpp b/include/mbgl/map/sprite.hpp index 454ebd888..d4b54ba1b 100644 --- a/include/mbgl/map/sprite.hpp +++ b/include/mbgl/map/sprite.hpp @@ -34,11 +34,11 @@ public: class Sprite : public std::enable_shared_from_this, private util::noncopyable { private: struct Key {}; - void load(const util::ptr &fileSource); + void load(FileSource& fileSource); public: Sprite(const Key &, const std::string& base_url, float pixelRatio); - static util::ptr Create(const std::string& base_url, float pixelRatio, const util::ptr &fileSource); + static util::ptr Create(const std::string& base_url, float pixelRatio, FileSource& fileSource); const SpritePosition &getSpritePosition(const std::string& name) const; diff --git a/include/mbgl/text/glyph_store.hpp b/include/mbgl/text/glyph_store.hpp index f8a7cb4d0..95ab92f30 100644 --- a/include/mbgl/text/glyph_store.hpp +++ b/include/mbgl/text/glyph_store.hpp @@ -48,7 +48,7 @@ private: class GlyphPBF { public: - GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const util::ptr &fileSource); + GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, FileSource& fileSource); private: GlyphPBF(const GlyphPBF &) = delete; @@ -71,7 +71,7 @@ private: // Manages Glyphrange PBF loading. class GlyphStore { public: - GlyphStore(const util::ptr &fileSource); + GlyphStore(FileSource& fileSource); // Block until all specified GlyphRanges of the specified font stack are loaded. void waitForGlyphRanges(const std::string &fontStack, const std::set &glyphRanges); @@ -86,11 +86,8 @@ private: FontStack &createFontStack(const std::string &fontStack); -public: std::string glyphURL; - -private: - const util::ptr fileSource; + FileSource& fileSource; std::unordered_map>> ranges; std::unordered_map> stacks; std::mutex mtx; diff --git a/src/map/map.cpp b/src/map/map.cpp index 3daaa8798..73867b229 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -346,7 +346,7 @@ void Map::setStyleJSON(std::string newStyleJSON, const std::string &base) { style->loadJSON((const uint8_t *)styleJSON.c_str()); if (!fileSource) { fileSource = std::make_shared(**loop, platform::defaultCacheDatabase()); - glyphStore = std::make_shared(fileSource); + glyphStore = std::make_shared(*fileSource); } fileSource->setBase(base); glyphStore->setURL(util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken())); @@ -370,7 +370,7 @@ util::ptr Map::getSprite() { const float pixelRatio = state.getPixelRatio(); const std::string &sprite_url = style->getSpriteURL(); if (!sprite || sprite->pixelRatio != pixelRatio) { - sprite = Sprite::Create(sprite_url, pixelRatio, fileSource); + sprite = Sprite::Create(sprite_url, pixelRatio, *fileSource); } return sprite; @@ -649,7 +649,7 @@ void Map::updateTiles() { void Map::prepare() { if (!fileSource) { fileSource = std::make_shared(**loop, platform::defaultCacheDatabase()); - glyphStore = std::make_shared(fileSource); + glyphStore = std::make_shared(*fileSource); } if (!style) { diff --git a/src/map/sprite.cpp b/src/map/sprite.cpp index ad1a8e770..82073619d 100644 --- a/src/map/sprite.cpp +++ b/src/map/sprite.cpp @@ -22,7 +22,7 @@ SpritePosition::SpritePosition(uint16_t x_, uint16_t y_, uint16_t width_, uint16 sdf(sdf_) { } -util::ptr Sprite::Create(const std::string& base_url, float pixelRatio, const util::ptr &fileSource) { +util::ptr Sprite::Create(const std::string& base_url, float pixelRatio, FileSource& fileSource) { util::ptr sprite(std::make_shared(Key(), base_url, pixelRatio)); sprite->load(fileSource); return sprite; @@ -51,7 +51,7 @@ Sprite::operator bool() const { // Note: This is a separate function that must be called exactly once after creation // The reason this isn't part of the constructor is that calling shared_from_this() in // the constructor fails. -void Sprite::load(const util::ptr &fileSource) { +void Sprite::load(FileSource& fileSource) { if (!valid) { // Treat a non-existent sprite as a successfully loaded empty sprite. loadedImage = true; @@ -62,7 +62,7 @@ void Sprite::load(const util::ptr &fileSource) { util::ptr sprite = shared_from_this(); - fileSource->request(ResourceType::JSON, jsonURL)->onload([sprite](const Response &res) { + fileSource.request(ResourceType::JSON, jsonURL)->onload([sprite](const Response &res) { if (res.code == 200) { sprite->body = res.data; sprite->parseJSON(); @@ -75,7 +75,7 @@ void Sprite::load(const util::ptr &fileSource) { } }); - fileSource->request(ResourceType::Image, spriteURL)->onload([sprite](const Response &res) { + fileSource.request(ResourceType::Image, spriteURL)->onload([sprite](const Response &res) { if (res.code == 200) { sprite->image = res.data; sprite->parseImage(); diff --git a/src/text/glyph_store.cpp b/src/text/glyph_store.cpp index 5619c4f93..737bad35d 100644 --- a/src/text/glyph_store.cpp +++ b/src/text/glyph_store.cpp @@ -137,7 +137,7 @@ void FontStack::lineWrap(Shaping &shaping, const float lineHeight, const float m align(shaping, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight, line); } -GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, const util::ptr &fileSource) +GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, FileSource& fileSource) : future(promise.get_future().share()) { // Load the glyph set URL @@ -148,8 +148,8 @@ GlyphPBF::GlyphPBF(const std::string &glyphURL, const std::string &fontStack, Gl }); // The prepare call jumps back to the main thread. - fileSource->prepare([&, url, fileSource] { - auto request = fileSource->request(ResourceType::Glyphs, url); + fileSource.prepare([&, url] { + auto request = fileSource.request(ResourceType::Glyphs, url); request->onload([&, url](const Response &res) { if (res.code != 200) { // Something went wrong with loading the glyph pbf. Pass on the error to the future listeners. @@ -228,7 +228,7 @@ void GlyphPBF::parse(FontStack &stack) { data.clear(); } -GlyphStore::GlyphStore(const util::ptr &fileSource_) : fileSource(fileSource_) {} +GlyphStore::GlyphStore(FileSource& fileSource_) : fileSource(fileSource_) {} void GlyphStore::setURL(const std::string &url) { glyphURL = url; From c3940cf08251f9fc9bfce4911e7b24f5985ae105 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 20 Nov 2014 19:25:38 -0800 Subject: [PATCH 16/47] Eliminate Map::getFileSource --- include/mbgl/map/map.hpp | 1 - include/mbgl/map/source.hpp | 9 +++++---- include/mbgl/map/tile_data.hpp | 3 ++- src/map/map.cpp | 4 ++-- src/map/source.cpp | 16 ++++++++-------- src/map/tile_data.cpp | 4 ++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index ad33865cd..ab5311741 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -126,7 +126,6 @@ public: public: inline const TransformState &getState() const { return state; } - inline util::ptr getFileSource() const { return fileSource; } inline util::ptr