Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts: Makefile platform/default/headless_view.cpp src/mbgl/map/map.cpp
This commit is contained in:
@@ -96,6 +96,7 @@ Map::Map(View& view_, FileSource& fileSource_)
|
||||
view(view_),
|
||||
#ifndef NDEBUG
|
||||
mainThread(std::this_thread::get_id()),
|
||||
mapThread(mainThread),
|
||||
#endif
|
||||
transform(view_),
|
||||
fileSource(fileSource_),
|
||||
@@ -113,7 +114,7 @@ Map::Map(View& view_, FileSource& fileSource_)
|
||||
}
|
||||
|
||||
Map::~Map() {
|
||||
if (async) {
|
||||
if (mode == Mode::Continuous) {
|
||||
stop();
|
||||
}
|
||||
|
||||
@@ -137,11 +138,11 @@ uv::worker &Map::getWorker() {
|
||||
|
||||
void Map::start(bool startPaused) {
|
||||
assert(std::this_thread::get_id() == mainThread);
|
||||
assert(!async);
|
||||
assert(mode == Mode::None);
|
||||
|
||||
// When starting map rendering in another thread, we perform async/continuously
|
||||
// updated rendering. Only in these cases, we attach the async handlers.
|
||||
async = true;
|
||||
mode = Mode::Continuous;
|
||||
|
||||
// Reset the flag.
|
||||
isStopped = false;
|
||||
@@ -212,7 +213,7 @@ void Map::start(bool startPaused) {
|
||||
void Map::stop(std::function<void ()> callback) {
|
||||
assert(std::this_thread::get_id() == mainThread);
|
||||
assert(mainThread != mapThread);
|
||||
assert(async);
|
||||
assert(mode == Mode::Continuous);
|
||||
|
||||
asyncTerminate->send();
|
||||
|
||||
@@ -234,12 +235,12 @@ void Map::stop(std::function<void ()> callback) {
|
||||
// already finished executing.
|
||||
thread.join();
|
||||
|
||||
async = false;
|
||||
mode = Mode::None;
|
||||
}
|
||||
|
||||
void Map::pause(bool waitForPause) {
|
||||
assert(std::this_thread::get_id() == mainThread);
|
||||
assert(async);
|
||||
assert(mode == Mode::Continuous);
|
||||
mutexRun.lock();
|
||||
pausing = true;
|
||||
mutexRun.unlock();
|
||||
@@ -257,7 +258,7 @@ void Map::pause(bool waitForPause) {
|
||||
|
||||
void Map::resume() {
|
||||
assert(std::this_thread::get_id() == mainThread);
|
||||
assert(async);
|
||||
assert(mode == Mode::Continuous);
|
||||
|
||||
mutexRun.lock();
|
||||
pausing = false;
|
||||
@@ -270,21 +271,22 @@ void Map::run() {
|
||||
COFFEE_TRY() {
|
||||
#endif
|
||||
|
||||
if (mode == Mode::None) {
|
||||
#ifndef NDEBUG
|
||||
if (!async) {
|
||||
mapThread = mainThread;
|
||||
}
|
||||
#endif
|
||||
mode = Mode::Static;
|
||||
}
|
||||
assert(std::this_thread::get_id() == mapThread);
|
||||
|
||||
if (async) {
|
||||
if (mode == Mode::Continuous) {
|
||||
checkForPause();
|
||||
}
|
||||
|
||||
setup();
|
||||
prepare();
|
||||
|
||||
if (async) {
|
||||
if (mode == Mode::Continuous) {
|
||||
terminating = false;
|
||||
while(!terminating) {
|
||||
uv_run(**loop, UV_RUN_DEFAULT);
|
||||
@@ -299,11 +301,13 @@ void Map::run() {
|
||||
|
||||
// If the map rendering wasn't started asynchronously, we perform one render
|
||||
// *after* all events have been processed.
|
||||
if (!async) {
|
||||
if (mode == Mode::Static) {
|
||||
render();
|
||||
#ifndef NDEBUG
|
||||
mapThread = std::thread::id();
|
||||
#endif
|
||||
mode = Mode::None;
|
||||
fileSource.clearLoop();
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
} COFFEE_CATCH() {
|
||||
@@ -334,9 +338,12 @@ void Map::checkForPause() {
|
||||
}
|
||||
|
||||
void Map::rerender() {
|
||||
// We only send render events if we want to continuously update the map
|
||||
// (== async rendering).
|
||||
if (async) {
|
||||
if (mode == Mode::Static) {
|
||||
prepare();
|
||||
} else if (mode == Mode::Continuous) {
|
||||
// We only send render events if we want to continuously update the map
|
||||
// (== async rendering).
|
||||
assert(asyncRender);
|
||||
asyncRender->send();
|
||||
}
|
||||
}
|
||||
@@ -373,7 +380,7 @@ void Map::setStyleURL(const std::string &url) {
|
||||
// TODO: Make threadsafe.
|
||||
|
||||
styleURL = url;
|
||||
if (async) {
|
||||
if (mode == Mode::Continuous) {
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
#include <mbgl/platform/platform.hpp>
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
@@ -25,35 +26,26 @@ Shader::Shader(const char *name_, const GLchar *vertSource, const GLchar *fragSo
|
||||
// Load binary shader if it exists
|
||||
bool skipCompile = false;
|
||||
if (!binaryFileName.empty() && (gl::ProgramBinary != nullptr)) {
|
||||
FILE *binaryFile = fopen(binaryFileName.c_str(), "rb");
|
||||
if (binaryFile != nullptr) {
|
||||
GLsizei binaryLength;
|
||||
GLenum binaryFormat;
|
||||
bool lengthOk = fread(&binaryLength, sizeof(binaryLength), 1, binaryFile) == 1;
|
||||
bool formatOk = fread(&binaryFormat, sizeof(binaryFormat), 1, binaryFile) == 1;
|
||||
std::ifstream binaryFile(binaryFileName, std::ios::in | std::ios::binary);
|
||||
|
||||
if (lengthOk && formatOk && binaryLength > 0) {
|
||||
std::unique_ptr<char[]> binary = mbgl::util::make_unique<char[]>(binaryLength);
|
||||
GLsizei binaryLength;
|
||||
GLenum binaryFormat;
|
||||
binaryFile.read(reinterpret_cast<char *>(&binaryLength), sizeof(binaryLength));
|
||||
binaryFile.read(reinterpret_cast<char *>(&binaryFormat), sizeof(binaryFormat));
|
||||
|
||||
if (binary != nullptr) {
|
||||
bool binaryOk = fread(binary.get(), binaryLength, 1, binaryFile) == 1;
|
||||
std::unique_ptr<char[]> binary = mbgl::util::make_unique<char[]>(binaryLength);
|
||||
binaryFile.read(binary.get(), binaryLength);
|
||||
|
||||
if (binaryOk) {
|
||||
MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength));
|
||||
MBGL_CHECK_ERROR(gl::ProgramBinary(program, binaryFormat, binary.get(), binaryLength));
|
||||
|
||||
// Check if the binary was valid
|
||||
GLint status;
|
||||
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status));
|
||||
if (status == GL_TRUE) {
|
||||
skipCompile = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(binaryFile);
|
||||
binaryFile = nullptr;
|
||||
// Check if the binary was valid
|
||||
GLint status;
|
||||
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_LINK_STATUS, &status));
|
||||
if (status == GL_TRUE) {
|
||||
skipCompile = true;
|
||||
}
|
||||
|
||||
binaryFile.close();
|
||||
}
|
||||
|
||||
GLuint vertShader = 0;
|
||||
@@ -150,7 +142,7 @@ bool Shader::compileShader(GLuint *shader, GLenum type, const GLchar *source) {
|
||||
|
||||
*shader = MBGL_CHECK_ERROR(glCreateShader(type));
|
||||
const GLchar *strings[] = { source };
|
||||
const GLsizei lengths[] = { (GLsizei)strlen(source) };
|
||||
const GLsizei lengths[] = { (GLsizei)std::strlen(source) };
|
||||
MBGL_CHECK_ERROR(glShaderSource(*shader, 1, strings, lengths));
|
||||
|
||||
MBGL_CHECK_ERROR(glCompileShader(*shader));
|
||||
@@ -189,19 +181,14 @@ Shader::~Shader() {
|
||||
MBGL_CHECK_ERROR(glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength));
|
||||
if (binaryLength > 0) {
|
||||
std::unique_ptr<char[]> binary = mbgl::util::make_unique<char[]>(binaryLength);
|
||||
if (binary != nullptr) {
|
||||
MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get()));
|
||||
MBGL_CHECK_ERROR(gl::GetProgramBinary(program, binaryLength, NULL, &binaryFormat, binary.get()));
|
||||
|
||||
// Write the binary to a file
|
||||
FILE *binaryFile = fopen(binaryFileName.c_str(), "wb");
|
||||
if (binaryFile != nullptr) {
|
||||
fwrite(&binaryLength, sizeof(binaryLength), 1, binaryFile);
|
||||
fwrite(&binaryFormat, sizeof(binaryFormat), 1, binaryFile);
|
||||
fwrite(binary.get(), binaryLength, 1, binaryFile);
|
||||
fclose(binaryFile);
|
||||
binaryFile = nullptr;
|
||||
}
|
||||
}
|
||||
// Write the binary to a file
|
||||
std::ofstream binaryFile(binaryFileName, std::ios::out | std::ios::trunc | std::ios::binary);
|
||||
binaryFile.write(reinterpret_cast<char *>(&binaryLength), sizeof(binaryLength));
|
||||
binaryFile.write(reinterpret_cast<char *>(&binaryFormat), sizeof(binaryFormat));
|
||||
binaryFile.write(binary.get(), binaryLength);
|
||||
binaryFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user