make Map::resize() private

they can only be called by View::resize
This commit is contained in:
Konstantin Käfer
2015-02-05 14:58:20 +01:00
parent 0151fe6c01
commit fb44fc81bd
12 changed files with 57 additions and 73 deletions

View File

@@ -326,18 +326,6 @@ void JNICALL nativeSwapped(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
nativeMapView->getMap().swapped();
}
void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height,
jfloat ratio) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResize");
assert(nativeMapViewPtr != 0);
assert(width >= 0);
assert(height >= 0);
assert(width <= UINT16_MAX);
assert(height <= UINT16_MAX);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().resize(width, height, ratio);
}
void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height,
jfloat ratio, jint fbWidth, jint fbHeight) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResize");
@@ -351,7 +339,7 @@ void JNICALL nativeResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint
assert(fbWidth <= UINT16_MAX);
assert(fbHeight <= UINT16_MAX);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().resize(width, height, ratio, fbWidth, fbHeight);
nativeMapView->resize(width, height, ratio, fbWidth, fbHeight);
}
void JNICALL nativeRemoveClass(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring clazz) {
@@ -1014,7 +1002,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
// NOTE: if you get java.lang.UnsatisfiedLinkError you likely forgot to set the size of the
// array correctly (too large)
std::array<JNINativeMethod, 67> methods = {{ // Can remove the extra brace in C++14
std::array<JNINativeMethod, 66> methods = {{ // Can remove the extra brace in C++14
{"nativeCreate", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J",
reinterpret_cast<void *>(&nativeCreate)},
{"nativeDestroy", "(J)V", reinterpret_cast<void *>(&nativeDestroy)},
@@ -1035,10 +1023,6 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
{"nativeTerminate", "(J)V", reinterpret_cast<void *>(&nativeTerminate)},
{"nativeNeedsSwap", "(J)Z", reinterpret_cast<void *>(&nativeNeedsSwap)},
{"nativeSwapped", "(J)V", reinterpret_cast<void *>(&nativeSwapped)},
{"nativeResize", "(JIIF)V",
reinterpret_cast<void *>(
static_cast<void JNICALL (*)(JNIEnv *, jobject, jlong, jint, jint, jfloat)>(
&nativeResize))},
{"nativeResize", "(JIIFII)V",
reinterpret_cast<void *>(static_cast<void JNICALL (
*)(JNIEnv *, jobject, jlong, jint, jint, jfloat, jint, jint)>(&nativeResize))},

View File

@@ -823,5 +823,10 @@ void NativeMapView::updateFps() {
}
env = nullptr;
}
void NativeMapView::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) {
View::resize(width, height, ratio, fbWidth, fbHeight);
}
}
}

View File

@@ -113,32 +113,6 @@ class NativeMapView {
nativeSwapped(mNativeMapViewPtr);
}
public void resize(int width, int height) {
resize(width, height, 1.0f);
}
public void resize(int width, int height, float ratio) {
if (width < 0) {
throw new IllegalArgumentException("width cannot be negative.");
}
if (height < 0) {
throw new IllegalArgumentException("height cannot be negative.");
}
if (width > 65535) {
throw new IllegalArgumentException(
"width cannot be greater than 65535.");
}
if (height > 65535) {
throw new IllegalArgumentException(
"height cannot be greater than 65535.");
}
nativeResize(mNativeMapViewPtr, width, height, ratio);
}
public void resize(int width, int height, float ratio, int fbWidth,
int fbHeight) {
if (width < 0) {
@@ -476,9 +450,6 @@ class NativeMapView {
private native void nativeSwapped(long nativeMapViewPtr);
private native void nativeResize(long nativeMapViewPtr, int width,
int height, float ratio);
private native void nativeResize(long nativeMapViewPtr, int width,
int height, float ratio, int fbWidth, int fbHeight);

View File

@@ -49,6 +49,8 @@ public:
void enableFps(bool enable);
void updateFps();
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
private:
EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs);

View File

@@ -43,6 +43,8 @@ struct exception : std::runtime_error {
};
class Map : private util::noncopyable {
friend class View;
public:
explicit Map(View&, FileSource&);
~Map();
@@ -80,10 +82,6 @@ public:
bool needsSwap();
void swapped();
// Size
void resize(uint16_t width, uint16_t height, float ratio = 1);
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
// Styling
void addClass(const std::string&);
void removeClass(const std::string&);
@@ -152,6 +150,10 @@ public:
inline std::chrono::steady_clock::time_point getTime() const { return animationTime; }
private:
// This may only be called by the View object.
void resize(uint16_t width, uint16_t height, float ratio = 1);
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
util::ptr<Sprite> getSprite();
uv::worker& getWorker();

View File

@@ -46,6 +46,10 @@ public:
// Must not be called from the render thread.
virtual void notifyMapChange(MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero()) = 0;
protected:
// Resizes the view
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight);
protected:
mbgl::Map *map = nullptr;
};

View File

@@ -20,11 +20,11 @@ public:
void notify();
void notifyMapChange(mbgl::MapChange change, std::chrono::steady_clock::duration delay = std::chrono::steady_clock::duration::zero());
static void key(GLFWwindow *window, int key, int scancode, int action, int mods);
static void scroll(GLFWwindow *window, double xoffset, double yoffset);
static void resize(GLFWwindow *window, int width, int height);
static void mouseClick(GLFWwindow *window, int button, int action, int modifiers);
static void mouseMove(GLFWwindow *window, double x, double y);
static void onKey(GLFWwindow *window, int key, int scancode, int action, int mods);
static void onScroll(GLFWwindow *window, double xoffset, double yoffset);
static void onResize(GLFWwindow *window, int width, int height);
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
static void onMouseMove(GLFWwindow *window, double x, double y);
static void eventloop(void *arg);

View File

@@ -62,14 +62,14 @@ void GLFWView::initialize(mbgl::Map *map_) {
int width, height;
glfwGetWindowSize(window, &width, &height);
resize(window, width, height);
onResize(window, width, height);
glfwSetCursorPosCallback(window, mouseMove);
glfwSetMouseButtonCallback(window, mouseClick);
glfwSetWindowSizeCallback(window, resize);
glfwSetFramebufferSizeCallback(window, resize);
glfwSetScrollCallback(window, scroll);
glfwSetKeyCallback(window, key);
glfwSetCursorPosCallback(window, onMouseMove);
glfwSetMouseButtonCallback(window, onMouseClick);
glfwSetWindowSizeCallback(window, onResize);
glfwSetFramebufferSizeCallback(window, onResize);
glfwSetScrollCallback(window, onScroll);
glfwSetKeyCallback(window, onKey);
const std::string extensions = reinterpret_cast<const char *>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)));
{
@@ -157,7 +157,7 @@ void GLFWView::initialize(mbgl::Map *map_) {
glfwMakeContextCurrent(nullptr);
}
void GLFWView::key(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) {
void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, int mods) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
if (action == GLFW_RELEASE) {
@@ -190,7 +190,7 @@ void GLFWView::key(GLFWwindow *window, int key, int /*scancode*/, int action, in
}
}
void GLFWView::scroll(GLFWwindow *window, double /*xOffset*/, double yOffset) {
void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
double delta = yOffset * 40;
@@ -213,16 +213,16 @@ void GLFWView::scroll(GLFWwindow *window, double /*xOffset*/, double yOffset) {
view->map->scaleBy(scale, view->lastX, view->lastY);
}
void GLFWView::resize(GLFWwindow *window, int width, int height ) {
void GLFWView::onResize(GLFWwindow *window, int width, int height ) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
int fbWidth, fbHeight;
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
view->map->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width), fbWidth, fbHeight);
view->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width), fbWidth, fbHeight);
}
void GLFWView::mouseClick(GLFWwindow *window, int button, int action, int modifiers) {
void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modifiers) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
if (button == GLFW_MOUSE_BUTTON_RIGHT ||
@@ -249,7 +249,7 @@ void GLFWView::mouseClick(GLFWwindow *window, int button, int action, int modifi
}
}
void GLFWView::mouseMove(GLFWwindow *window, double x, double y) {
void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) {
GLFWView *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
if (view->tracking) {
double dx = x - view->lastX;

View File

@@ -131,7 +131,7 @@ void HeadlessView::createContext() {
#endif
}
void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
void HeadlessView::resize(const uint16_t width, const uint16_t height, const float pixelRatio) {
clearBuffers();
width_ = width;
@@ -177,6 +177,8 @@ void HeadlessView::resize(uint16_t width, uint16_t height, float pixelRatio) {
throw std::runtime_error(error.str());
}
View::resize(width, height, pixelRatio, w, h);
deactivate();
}

View File

@@ -239,7 +239,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
mbglFileCache = new mbgl::SQLiteCache(defaultCacheDatabase());
mbglFileSource = new mbgl::DefaultFileSource(mbglFileCache);
mbglMap = new mbgl::Map(*mbglView, *mbglFileSource);
mbglMap->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor, _glView.drawableWidth, _glView.drawableHeight);
mbglView->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor, _glView.drawableWidth, _glView.drawableHeight);
// Notify map object when network reachability status changes.
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -489,7 +489,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
mbglMap->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight);
mbglView->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight);
}
- (void)layoutSubviews
@@ -1631,6 +1631,10 @@ class MBGLView : public mbgl::View
[EAGLContext setCurrentContext:nil];
}
void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) {
View::resize(width, height, ratio, fbWidth, fbHeight);
}
void swap()
{
[nativeView performSelectorOnMainThread:@selector(swap)

11
src/mbgl/map/view.cpp Normal file
View File

@@ -0,0 +1,11 @@
#include <mbgl/map/view.hpp>
#include <mbgl/map/map.hpp>
namespace mbgl {
void View::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) {
assert(map);
map->resize(width, height, ratio, fbWidth, fbHeight);
}
}

View File

@@ -146,7 +146,6 @@ TEST_P(HeadlessTest, render) {
map.setStyleJSON(style, "test/suite");
view.resize(width, height, pixelRatio);
map.resize(width, height, pixelRatio);
map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom);
map.setBearing(bearing);