Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:mapbox/mapbox-gl-native
Browse files Browse the repository at this point in the history
  • Loading branch information
incanus committed Nov 26, 2014
2 parents 913a119 + 418f50c commit 655ee50
Show file tree
Hide file tree
Showing 16 changed files with 707 additions and 136 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,14 @@ Once you're done installing the build dependencies, you can get started by runni

./configure

which downloads all other dependencies that we need to build manually with [Mason](https://github.com/mapbox/mason). There's a good chance that there already are binary files and that you don't need to compile anything.

Then, you can then proceed to build the library like:

make mbgl

Or proceed to building the debug application with:
Then, you can then proceed to build the library:

git submodule update --init
make linux

Be sure to setup an access token per below before running `build/Release/mapbox-gl`.
Set an access token as described below, and then run:

make run-linux


# Troubleshooting
Expand Down
36 changes: 22 additions & 14 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ trap finish EXIT

case ${MASON_PLATFORM} in
'ios')
SQLITE_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
;;
SQLITE_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
;;
*)
GLFW_VERSION=a21f2377
SQLITE_VERSION=system
LIBPNG_VERSION=1.6.13
LIBCURL_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
NUNICODE_VERSION=1.4
;;
GLFW_VERSION=a21f2377
SQLITE_VERSION=system
LIBPNG_VERSION=1.6.13
LIBJPEG_VERSION=v8d
LIBCURL_VERSION=system
LIBUV_VERSION=0.10.28
ZLIB_VERSION=system
BOOST_VERSION=system
NUNICODE_VERSION=1.4
;;
esac

function abort { >&2 echo -e "\033[1m\033[31m$1\033[0m"; exit 1; }
Expand Down Expand Up @@ -91,6 +92,13 @@ if [ ! -z ${LIBPNG_VERSION} ]; then
CONFIG+=" 'png_ldflags': $(quote_flags $(mason ldflags libpng ${LIBPNG_VERSION})),"$LN
fi

if [ ! -z ${LIBJPEG_VERSION} ]; then
mason install jpeg ${LIBJPEG_VERSION}
CONFIG+=" 'jpeg_static_libs': $(quote_flags $(mason static_libs jpeg ${LIBJPEG_VERSION})),"$LN
CONFIG+=" 'jpeg_cflags': $(quote_flags $(mason cflags jpeg ${LIBJPEG_VERSION})),"$LN
CONFIG+=" 'jpeg_ldflags': $(quote_flags $(mason ldflags jpeg ${LIBJPEG_VERSION})),"$LN
fi

if [ ! -z ${SQLITE_VERSION} ]; then
mason install sqlite ${SQLITE_VERSION}
CONFIG+=" 'sqlite3_static_libs': $(quote_flags $(mason static_libs sqlite ${SQLITE_VERSION})),"$LN
Expand Down
1 change: 1 addition & 0 deletions gyp/install.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
['OS == "linux"', {
'other_ldflags': [
'<@(png_static_libs)',
'<@(jpeg_static_libs)',
'<@(glfw3_static_libs)',
'<@(glfw3_ldflags)',
]
Expand Down
5 changes: 5 additions & 0 deletions gyp/mbgl-linux.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'variables': {
'cflags_cc': [
'<@(png_cflags)',
'<@(jpeg_cflags)',
'<@(uv_cflags)',
'<@(curl_cflags)',
'<@(nu_cflags)',
Expand All @@ -19,6 +20,7 @@
],
'ldflags': [
'<@(png_ldflags)',
'<@(jpeg_ldflags)',
'<@(uv_ldflags)',
'<@(curl_ldflags)',
'<@(nu_ldflags)',
Expand All @@ -30,6 +32,9 @@
'../platform/default/string_stdlib.cpp',
'../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',
Expand Down
42 changes: 42 additions & 0 deletions include/mbgl/platform/default/image_reader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef MBGL_UTIL_IMAGE_READER_HPP
#define MBGL_UTIL_IMAGE_READER_HPP

#include <mbgl/util/std.hpp>
#include <mbgl/util/noncopyable.hpp>
// stl
#include <stdexcept>
#include <string>

namespace mbgl { namespace util {

class ImageReaderException : public std::exception
{
private:
std::string message_;
public:
ImageReaderException(std::string const& message)
: message_(message) {}

~ImageReaderException() throw() {}

virtual const char* what() const throw()
{
return message_.c_str();
}
};

struct ImageReader : private noncopyable
{
virtual unsigned width() const=0;
virtual unsigned height() const=0;
virtual bool hasAlpha() const=0;
virtual bool premultipliedAlpha() const=0;
virtual void read(unsigned x,unsigned y, unsigned width, unsigned height, char* image)=0;
virtual ~ImageReader() {}
};

std::unique_ptr<ImageReader> getImageReader(char const* data, size_t size);

}}

#endif
69 changes: 69 additions & 0 deletions include/mbgl/platform/default/jpeg_reader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef MBGL_UTIL_JPEG_READER_HPP
#define MBGL_UTIL_JPEG_READER_HPP

#include <mbgl/platform/default/image_reader.hpp>

// jpeg
extern "C"
{
#include <jpeglib.h>
}

#include <boost/iostreams/stream.hpp>

namespace mbgl { namespace util {

template <typename T>
class JpegReader : public ImageReader
{
public:
using source_type = T;
using input_stream = boost::iostreams::stream<source_type>;
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:
JpegReader(char const* data, size_t size);
~JpegReader();
unsigned width() const;
unsigned height() const;
inline bool hasAlpha() const { return false; }
inline bool premultipliedAlpha() 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
62 changes: 62 additions & 0 deletions include/mbgl/platform/default/png_reader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef MBGL_UTIL_PNG_READER_HPP
#define MBGL_UTIL_PNG_READER_HPP

#include <mbgl/platform/default/image_reader.hpp>

extern "C"
{
#include <png.h>
}

#include <cstring>
#include <memory>

#include <boost/iostreams/stream.hpp>

namespace mbgl { namespace util {

template <typename T>
class PngReader : public ImageReader
{
using source_type = T;
using input_stream = boost::iostreams::stream<source_type>;

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:
PngReader(char const* data, std::size_t size);
~PngReader();
unsigned width() const;
unsigned height() const;
inline bool hasAlpha() const { return has_alpha_; }
bool premultipliedAlpha() 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();
static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
};


}}

#endif // MBGL_UTIL_PNG_READER_HPP
4 changes: 2 additions & 2 deletions include/mbgl/util/uv_detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class worker {
uv_worker_init(w, loop, count, name);
}
inline ~worker() {
uv_worker_close(w, [](uv_worker_t *worker) {
delete worker;
uv_worker_close(w, [](uv_worker_t *worker_) {
delete worker_;
});
}
inline void add(void *data, uv_worker_cb work_cb, uv_worker_after_cb after_work_cb) {
Expand Down
4 changes: 4 additions & 0 deletions linux/mapboxgl-app.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS':[
'<@(glfw3_cflags)',
'<@(png_cflags)',
'<@(jpeg_cflags)',
],
},
'cflags_cc': [
'<@(glfw3_cflags)',
'<@(png_cflags)',
'<@(jpeg_cflags)',
'-I<(boost_root)/include',
],
'variables': {
Expand Down
Loading

0 comments on commit 655ee50

Please sign in to comment.