Resize view from map thread

This commit is contained in:
John Firebaugh
2015-04-23 11:11:12 -07:00
parent a625ba8a09
commit 230027e514
11 changed files with 23 additions and 16 deletions

View File

@@ -290,7 +290,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->resize(width, height, ratio, fbWidth, fbHeight);
nativeMapView->getMap().resize(width, height, ratio);
}
void JNICALL nativeRemoveClass(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jstring clazz) {

View File

@@ -800,9 +800,5 @@ void NativeMapView::updateFps() {
env = nullptr;
}
void NativeMapView::resize(uint16_t width, uint16_t height, float ratio, uint16_t, uint16_t) {
map.resize(width, height, ratio);
}
}
}

View File

@@ -45,8 +45,6 @@ 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

@@ -40,6 +40,9 @@ public:
virtual void notify() = 0;
// Called from the render thread. The implementation should resize the framebuffer.
virtual void resize(uint16_t width, uint16_t height, float pixelRatio);
// Called from the render thread. The implementation must trigger a rerender.
// (i.e. either the passed render() function for rendering immediately on the map thread,
// or map->renderSync() from the main thread must be called as a result of this)

View File

@@ -29,11 +29,10 @@ public:
HeadlessView(std::shared_ptr<HeadlessDisplay> display, uint16_t width = 256, uint16_t height = 256, float pixelRatio = 1);
~HeadlessView();
void resize(uint16_t width, uint16_t height, float pixelRatio);
void activate() override;
void deactivate() override;
void notify() override;
void resize(uint16_t width, uint16_t height, float pixelRatio) override;
void invalidate(std::function<void()> render) override;
std::unique_ptr<StillImage> readStillImage() override;

View File

@@ -41,7 +41,9 @@ namespace mbgl {
HeadlessView::HeadlessView(uint16_t width, uint16_t height, float pixelRatio)
: display(std::make_shared<HeadlessDisplay>()) {
activate();
resize(width, height, pixelRatio);
deactivate();
}
HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display_,
@@ -49,7 +51,9 @@ HeadlessView::HeadlessView(std::shared_ptr<HeadlessDisplay> display_,
uint16_t height,
float pixelRatio)
: display(display_) {
activate();
resize(width, height, pixelRatio);
deactivate();
}
void HeadlessView::loadExtensions() {
@@ -155,8 +159,6 @@ HeadlessView::Dimensions::Dimensions(uint16_t width_, uint16_t height_, float pi
}
void HeadlessView::resize(const uint16_t width, const uint16_t height, const float pixelRatio) {
activate();
dimensions = { width, height, pixelRatio };
clearBuffers();
@@ -197,8 +199,6 @@ void HeadlessView::resize(const uint16_t width, const uint16_t height, const flo
}
throw std::runtime_error(error.str());
}
deactivate();
}
std::unique_ptr<StillImage> HeadlessView::readStillImage() {

View File

@@ -131,7 +131,7 @@ std::string Map::getStyleJSON() const {
void Map::resize(uint16_t width, uint16_t height, float ratio) {
if (data->transform.resize(width, height, ratio, width * ratio, height * ratio)) {
triggerUpdate();
context->invoke(&MapContext::resize, width, height, ratio);
}
}

View File

@@ -85,6 +85,11 @@ void MapContext::pause() {
view.activate();
}
void MapContext::resize(uint16_t width, uint16_t height, float ratio) {
view.resize(width, height, ratio);
triggerUpdate();
}
void MapContext::triggerUpdate(const Update u) {
updated |= static_cast<UpdateType>(u);
asyncUpdate->send();

View File

@@ -43,6 +43,8 @@ public:
void pause();
void render();
void resize(uint16_t width, uint16_t height, float ratio);
// Notifies the Map thread that the state has changed and an update might be necessary.
void triggerUpdate(Update = Update::Nothing);

View File

@@ -11,6 +11,10 @@ void View::initialize(Map *map_) {
map = map_;
}
void View::resize(uint16_t, uint16_t, float) {
// no-op
}
std::unique_ptr<StillImage> View::readStillImage() {
return nullptr;
}

View File

@@ -25,7 +25,7 @@ TEST(API, RepeatedRender) {
Map map(view, fileSource, MapMode::Still);
{
view.resize(128, 512, 1);
map.resize(128, 512, 1);
map.setStyleJSON(style, "test/suite");
std::promise<std::unique_ptr<const StillImage>> promise;
map.renderStill([&promise](std::unique_ptr<const StillImage> image) {
@@ -39,7 +39,7 @@ TEST(API, RepeatedRender) {
}
{
view.resize(512, 512, 2);
map.resize(512, 512, 2);
map.setStyleJSON(style, "TEST_DATA/suite");
std::promise<std::unique_ptr<const StillImage>> promise;
map.renderStill([&promise](std::unique_ptr<const StillImage> image) {