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
bleege committed Aug 5, 2015
2 parents 49445b7 + 5eebda7 commit af89714
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .mason
Submodule .mason updated 1 files
+3 −2 mason.sh
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ endif

#### All platforms targets #####################################################

.PHONY: linux xlinux run-linux run-xlinux
.PHONY: linux run-linux run-valgrind-linux
linux: ; $(RUN) Makefile/linuxapp
run-linux: linux ; (cd build/linux-x86_64/$(BUILDTYPE) && ./mapbox-gl)
run-valgrind-linux: linux
(cd build/linux-x86_64/$(BUILDTYPE) && valgrind --leak-check=full --suppressions=../../../scripts/valgrind.sup ./mapbox-gl)

.PHONY: android android-lib
# Builds a particular android architecture.
Expand Down
8 changes: 4 additions & 4 deletions android/cpp/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,14 @@ void JNICALL nativeUpdate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeUpdate");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().update();
nativeMapView->getMap().update(mbgl::Update::Repaint);
}

void JNICALL nativeOnInvalidate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jboolean inProgress) {
void JNICALL nativeOnInvalidate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeOnInvalidate");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->onInvalidate(inProgress);
nativeMapView->onInvalidate();
}

void JNICALL nativeViewResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height) {
Expand Down Expand Up @@ -1440,7 +1440,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
{"nativePause", "(J)V", reinterpret_cast<void *>(&nativePause)},
{"nativeResume", "(J)V", reinterpret_cast<void *>(&nativeResume)},
{"nativeUpdate", "(J)V", reinterpret_cast<void *>(&nativeUpdate)},
{"nativeOnInvalidate", "(JZ)V", reinterpret_cast<void *>(&nativeOnInvalidate)},
{"nativeOnInvalidate", "(J)V", reinterpret_cast<void *>(&nativeOnInvalidate)},
{"nativeViewResize", "(JII)V",
reinterpret_cast<void *>(static_cast<void JNICALL (
*)(JNIEnv *, jobject, jlong, jint, jint)>(&nativeViewResize))},
Expand Down
9 changes: 4 additions & 5 deletions android/cpp/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ void NativeMapView::updateFps() {
env = nullptr;
}

void NativeMapView::onInvalidate(bool inProgress) {
void NativeMapView::onInvalidate() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::onInvalidate()");

const bool dirty = !clean.test_and_set();
Expand All @@ -776,10 +776,8 @@ void NativeMapView::onInvalidate(bool inProgress) {

map.setSourceTileCacheSize(cacheSize);

const bool needsRerender = map.renderSync();
if (!inProgress) {
map.nudgeTransitions(needsRerender);
}
map.renderSync();
map.nudgeTransitions();
}
}

Expand All @@ -792,6 +790,7 @@ void NativeMapView::resizeView(int w, int h) {
void NativeMapView::resizeFramebuffer(int w, int h) {
fbWidth = w;
fbHeight = h;
map.update(mbgl::Update::Repaint);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,8 +1365,7 @@ protected void onInvalidate() {
post(new Runnable() {
@Override
public void run() {
boolean inProgress = mRotateGestureDetector.isInProgress() || mScaleGestureDetector.isInProgress();
mNativeMapView.invalidate(inProgress);
mNativeMapView.invalidate();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public void update() {
nativeUpdate(mNativeMapViewPtr);
}

public void invalidate(boolean inProgress) {
nativeOnInvalidate(mNativeMapViewPtr, inProgress);
public void invalidate() {
nativeOnInvalidate(mNativeMapViewPtr);
}

public void resizeView(int width, int height) {
Expand Down Expand Up @@ -463,7 +463,7 @@ private native void nativeCreateSurface(long nativeMapViewPtr,

private native void nativeUpdate(long nativeMapViewPtr);

private native void nativeOnInvalidate(long nativeMapViewPtr, boolean inProgress);
private native void nativeOnInvalidate(long nativeMapViewPtr);

private native void nativeViewResize(long nativeMapViewPtr, int width, int height);

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/android/native_map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class NativeMapView : public mbgl::View, private mbgl::util::noncopyable {
void enableFps(bool enable);
void updateFps();

void onInvalidate(bool inProgress);
void onInvalidate();

void resizeView(int width, int height);
void resizeFramebuffer(int width, int height);
Expand Down
10 changes: 5 additions & 5 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class Map : private util::noncopyable {
using StillImageCallback = std::function<void(std::exception_ptr, std::unique_ptr<const StillImage>)>;
void renderStill(StillImageCallback callback);

// Triggers a synchronous or asynchronous render.
bool renderSync();
// Triggers a synchronous render.
void renderSync();

// Nudges transitions one step, possibly notifying of the need for a rerender.
void nudgeTransitions(bool forceRerender);
// Nudges transitions one step, possibly notifying of the need for a rerender, if any.
void nudgeTransitions();

// Notifies the Map thread that the state has changed and an update might be necessary.
void update(Update update = Update::Nothing);
void update(Update update);

// Styling
void addClass(const std::string&);
Expand Down
1 change: 1 addition & 0 deletions include/mbgl/map/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class Update : UpdateType {
Classes = 1 << 3,
Zoom = 1 << 4,
RenderStill = 1 << 5,
Repaint = 1 << 6,
};

}
Expand Down
9 changes: 3 additions & 6 deletions platform/default/glfw_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void GLFWView::onFramebufferResize(GLFWwindow *window, int width, int height) {
view->fbWidth = width;
view->fbHeight = height;

view->map->update();
view->map->update(mbgl::Update::Repaint);
}

void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modifiers) {
Expand Down Expand Up @@ -336,11 +336,8 @@ void GLFWView::run() {
glfwWaitEvents();
const bool dirty = !clean.test_and_set();
if (dirty) {
const bool needsRerender = map->renderSync();
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
if (!view->tracking || !view->rotating) {
map->nudgeTransitions(needsRerender);
}
map->renderSync();
map->nudgeTransitions();
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions platform/default/png_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char *

#ifdef PNG_ALPHA_PREMULTIPLIED
png_set_alpha_mode(png_ptr, PNG_ALPHA_PREMULTIPLIED, PNG_GAMMA_LINEAR);
#else
// TODO: Manually premultiply the image data.
#endif

if (x0 == 0 && y0 == 0 && w >= width_ && h >= height_)
Expand All @@ -180,6 +178,19 @@ void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char *
for (unsigned row = 0; row < height_; ++row)
rows[row] = (png_bytep)image + row * width_ * 4 ;
png_read_image(png_ptr, rows.get());

#ifndef PNG_ALPHA_PREMULTIPLIED
// Manually premultiply the image if libpng didn't do it for us.
for (unsigned row = 0; row < height_; ++row) {
for (unsigned x = 0; x < width_; x++) {
png_byte* ptr = &(rows[row][x * 4]);
const float a = ptr[3] / 255.0f;
ptr[0] *= a;
ptr[1] *= a;
ptr[2] *= a;
}
}
#endif
}
else
{
Expand All @@ -193,6 +204,7 @@ void PngReader<T>::read(unsigned x0, unsigned y0, unsigned w, unsigned h, char *
png_read_row(png_ptr,row.get(),0);
if (i >= y0 && i < (y0 + h))
{
// TODO: premultiply this
std::copy(&row[x0 * 4], &row[x0 * 4] + w * 4, image + i * width_* 4);
}
}
Expand Down
10 changes: 2 additions & 8 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -710,17 +710,11 @@ - (void)glkView:(__unused GLKView *)view drawInRect:(__unused CGRect)rect

_mbglMap->setSourceTileCacheSize(cacheSize);

bool needsRerender = _mbglMap->renderSync();
_mbglMap->renderSync();

[self updateUserLocationAnnotationView];

// don't nudge transitions if in the midst of a gesture.
if (self.pan.state == UIGestureRecognizerStateChanged ||
self.pinch.state == UIGestureRecognizerStateChanged ||
self.rotate.state == UIGestureRecognizerStateChanged ||
self.quickZoom.state == UIGestureRecognizerStateChanged) return;

_mbglMap->nudgeTransitions(needsRerender);
_mbglMap->nudgeTransitions();
}
}

Expand Down
46 changes: 22 additions & 24 deletions src/mbgl/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,34 @@ void Map::renderStill(StillImageCallback callback) {
FrameData{ view.getFramebufferSize() }, callback);
}

bool Map::renderSync() {
void Map::renderSync() {
if (renderState == RenderState::never) {
view.notifyMapChange(MapChangeWillStartRenderingMap);
}

view.notifyMapChange(MapChangeWillStartRenderingFrame);

MapContext::RenderResult result = context->invokeSync<MapContext::RenderResult>(
&MapContext::renderSync, transform->getState(), FrameData{ view.getFramebufferSize() });
const bool fullyLoaded = context->invokeSync<bool>(
&MapContext::renderSync, transform->getState(), FrameData { view.getFramebufferSize() });

view.notifyMapChange(result.fullyLoaded ?
view.notifyMapChange(fullyLoaded ?
MapChangeDidFinishRenderingFrameFullyRendered :
MapChangeDidFinishRenderingFrame);

if (!result.fullyLoaded) {
if (!fullyLoaded) {
renderState = RenderState::partial;
} else if (renderState != RenderState::fully) {
renderState = RenderState::fully;
view.notifyMapChange(MapChangeDidFinishRenderingMapFullyRendered);
}

return result.needsRerender;
}

void Map::nudgeTransitions(bool forceRerender) {
if (transform->needsTransition()) {
update(Update(transform->updateTransitions(Clock::now())));
} else if (forceRerender) {
update();
void Map::nudgeTransitions() {
UpdateType update_ = transform->updateTransitions(Clock::now());
if (data->getNeedsRepaint()) {
update_ |= static_cast<UpdateType>(Update::Repaint);
}
update(Update(update_));
}

void Map::update(Update update_) {
Expand Down Expand Up @@ -110,24 +108,24 @@ std::string Map::getStyleJSON() const {

void Map::cancelTransitions() {
transform->cancelTransitions();
update();
update(Update::Repaint);
}

void Map::setGestureInProgress(bool inProgress) {
transform->setGestureInProgress(inProgress);
update();
update(Update::Repaint);
}

#pragma mark - Position

void Map::moveBy(double dx, double dy, const Duration& duration) {
transform->moveBy(dx, dy, duration);
update();
update(Update::Repaint);
}

void Map::setLatLng(LatLng latLng, const Duration& duration) {
transform->setLatLng(latLng, duration);
update();
update(Update::Repaint);
}

LatLng Map::getLatLng() const {
Expand Down Expand Up @@ -249,17 +247,17 @@ uint16_t Map::getHeight() const {

void Map::rotateBy(double sx, double sy, double ex, double ey, const Duration& duration) {
transform->rotateBy(sx, sy, ex, ey, duration);
update();
update(Update::Repaint);
}

void Map::setBearing(double degrees, const Duration& duration) {
transform->setAngle(-degrees * M_PI / 180, duration);
update();
update(Update::Repaint);
}

void Map::setBearing(double degrees, double cx, double cy) {
transform->setAngle(-degrees * M_PI / 180, cx, cy);
update();
update(Update::Repaint);
}

double Map::getBearing() const {
Expand All @@ -268,7 +266,7 @@ double Map::getBearing() const {

void Map::resetNorth() {
transform->setAngle(0, std::chrono::milliseconds(500));
update();
update(Update::Repaint);
}


Expand Down Expand Up @@ -365,12 +363,12 @@ void Map::removeSprite(const std::string& name) {

void Map::setDebug(bool value) {
data->setDebug(value);
update();
update(Update::Repaint);
}

void Map::toggleDebug() {
data->toggleDebug();
update();
update(Update::Repaint);
}

bool Map::getDebug() const {
Expand All @@ -379,12 +377,12 @@ bool Map::getDebug() const {

void Map::setCollisionDebug(bool value) {
data->setCollisionDebug(value);
update();
update(Update::Repaint);
}

void Map::toggleCollisionDebug() {
data->toggleCollisionDebug();
update();
update(Update::Repaint);
}

bool Map::getCollisionDebug() const {
Expand Down
Loading

0 comments on commit af89714

Please sign in to comment.