Following kkaefer's view changes

This commit is contained in:
John Firebaugh
2015-04-21 15:02:30 -07:00
parent 75ae956b0e
commit 6c7a01a503
11 changed files with 18 additions and 73 deletions

View File

@@ -825,8 +825,8 @@ 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);
void NativeMapView::resize(uint16_t width, uint16_t height, float ratio, uint16_t, uint16_t) {
map.resize(width, height, ratio);
}
}

View File

@@ -107,6 +107,7 @@ public:
void resetNorth();
// Size
void resize(uint16_t width, uint16_t height, float ratio = 1);
uint16_t getWidth() const;
uint16_t getHeight() const;
@@ -146,10 +147,6 @@ public:
private:
void triggerUpdate(Update update = Update::Nothing);
// 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);
const std::unique_ptr<Environment> env;
std::unique_ptr<EnvironmentScope> scope;
View &view;

View File

@@ -45,10 +45,6 @@ public:
// or map->renderSync() from the main thread must be called as a result of this)
virtual void invalidate(std::function<void()> render) = 0;
// Called from the render (=GL) thread. Signals that the contents of the contents
// may be discarded. The default is a no-op.
virtual void discard();
// Reads the pixel data from the current framebuffer. If your View implementation
// doesn't support reading from the framebuffer, return a null pointer.
virtual std::unique_ptr<StillImage> readStillImage();
@@ -60,10 +56,6 @@ public:
MapChange change,
Duration delay = Duration::zero());
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

@@ -35,7 +35,6 @@ public:
void deactivate() override;
void notify() override;
void invalidate(std::function<void()> render) override;
void discard() override;
std::unique_ptr<StillImage> readStillImage() override;
private:
@@ -57,12 +56,7 @@ private:
float pixelRatio = 0;
};
// These are the values that represent the state of the current framebuffer.
Dimensions current;
// These are the values that will be used after the next discard() event.
std::mutex prospectiveMutex;
Dimensions prospective;
Dimensions dimensions;
#if MBGL_USE_CGL
CGLContextObj glContext = nullptr;

View File

@@ -223,7 +223,7 @@ void GLFWView::onResize(GLFWwindow *window, int width, int height ) {
int fbWidth, fbHeight;
glfwGetFramebufferSize(window, &fbWidth, &fbHeight);
view->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width), fbWidth, fbHeight);
view->map->resize(width, height, static_cast<float>(fbWidth) / static_cast<float>(width));
}
void GLFWView::onMouseClick(GLFWwindow *window, int button, int action, int modifiers) {

View File

@@ -150,30 +150,19 @@ bool HeadlessView::isActive() {
return std::this_thread::get_id() == thread;
}
void HeadlessView::resize(const uint16_t width, const uint16_t height, const float pixelRatio) {
std::lock_guard<std::mutex> lock(prospectiveMutex);
prospective = { width, height, pixelRatio };
}
HeadlessView::Dimensions::Dimensions(uint16_t width_, uint16_t height_, float pixelRatio_)
: width(width_), height(height_), pixelRatio(pixelRatio_) {
}
void HeadlessView::discard() {
assert(isActive());
void HeadlessView::resize(const uint16_t width, const uint16_t height, const float pixelRatio) {
activate();
{ // Obtain the new values.
std::lock_guard<std::mutex> lock(prospectiveMutex);
if (current.pixelWidth() == prospective.pixelWidth() && current.pixelHeight() == prospective.pixelHeight()) {
return;
}
current = prospective;
}
dimensions = { width, height, pixelRatio };
clearBuffers();
const unsigned int w = current.width * current.pixelRatio;
const unsigned int h = current.height * current.pixelRatio;
const unsigned int w = dimensions.width * dimensions.pixelRatio;
const unsigned int h = dimensions.height * dimensions.pixelRatio;
// Create depth/stencil buffer
MBGL_CHECK_ERROR(glGenRenderbuffersEXT(1, &fboDepthStencil));
@@ -209,14 +198,14 @@ void HeadlessView::discard() {
throw std::runtime_error(error.str());
}
View::resize(current.width, current.height, current.pixelRatio, w, h);
deactivate();
}
std::unique_ptr<StillImage> HeadlessView::readStillImage() {
assert(isActive());
const unsigned int w = current.pixelWidth();
const unsigned int h = current.pixelHeight();
const unsigned int w = dimensions.pixelWidth();
const unsigned int h = dimensions.pixelHeight();
auto image = util::make_unique<StillImage>();
image->width = w;
@@ -305,7 +294,6 @@ void HeadlessView::activate() {
#endif
loadExtensions();
discard();
}
void HeadlessView::deactivate() {

View File

@@ -278,7 +278,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
mbglFileCache = new mbgl::SQLiteCache(defaultCacheDatabase());
mbglFileSource = new mbgl::DefaultFileSource(mbglFileCache);
mbglMap = new mbgl::Map(*mbglView, *mbglFileSource);
mbglView->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor, _glView.drawableWidth, _glView.drawableHeight);
mbglMap->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor);
// Notify map object when network reachability status changes.
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -623,7 +623,7 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr;
{
if ( ! self.glSnapshotView || self.glSnapshotView.hidden)
{
mbglView->resize(rect.size.width, rect.size.height, view.contentScaleFactor, view.drawableWidth, view.drawableHeight);
mbglMap->resize(rect.size.width, rect.size.height, view.contentScaleFactor);
CGFloat zoomFactor = mbglMap->getMaxZoom() - mbglMap->getMinZoom() + 1;
CGFloat cpuFactor = (CGFloat)[[NSProcessInfo processInfo] processorCount];
@@ -2528,11 +2528,6 @@ 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 invalidate(std::function<void()>) override
{
[nativeView performSelectorOnMainThread:@selector(invalidate)

View File

@@ -174,11 +174,7 @@ std::string Map::getStyleJSON() const {
#pragma mark - Size
void Map::resize(uint16_t width, uint16_t height, float ratio) {
resize(width, height, ratio, width * ratio, height * ratio);
}
void Map::resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight) {
if (data->transform.resize(width, height, ratio, fbWidth, fbHeight)) {
if (data->transform.resize(width, height, ratio, width * ratio, height * ratio)) {
triggerUpdate();
}
}

View File

@@ -200,11 +200,6 @@ void MapContext::update() {
painter->setDebug(data.getDebug());
}
if (u & static_cast<UpdateType>(Update::RenderStill)) {
// Triggers a view resize.
view.discard();
}
if (style) {
if (u & static_cast<UpdateType>(Update::DefaultTransitionDuration)) {
style->setDefaultTransitionDuration(data.getDefaultTransitionDuration());
@@ -233,8 +228,6 @@ void MapContext::update() {
void MapContext::render() {
assert(Environment::currentlyOn(ThreadType::Map));
view.discard();
// Cleanup OpenGL objects that we abandoned since the last render call.
env.performCleanup();

View File

@@ -11,19 +11,10 @@ void View::initialize(Map *map_) {
map = map_;
}
void View::discard() {
// no-op
}
std::unique_ptr<StillImage> View::readStillImage() {
return nullptr;
}
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);
}
void View::notifyMapChange(MapChange, Duration) {
// no-op
}

View File

@@ -141,16 +141,15 @@ TEST_P(HeadlessTest, render) {
}
}
HeadlessView view(display);
HeadlessView view(display, width, height, pixelRatio);
DefaultFileSource fileSource(nullptr);
Map map(view, fileSource);
map.resize(width, height, pixelRatio);
map.start(MapMode::Still);
map.setClasses(classes);
map.setStyleJSON(style, "test/suite");
view.resize(width, height, pixelRatio);
map.setLatLngZoom(mbgl::LatLng(latitude, longitude), zoom);
map.setBearing(bearing);