Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[core][node] Support ImageSource#8968

Merged
asheemmamoowala merged 8 commits into
masterfrom
1350-image-source
Jun 1, 2017
Merged

[core][node] Support ImageSource#8968
asheemmamoowala merged 8 commits into
masterfrom
1350-image-source

Conversation

@asheemmamoowala
Copy link
Copy Markdown
Contributor

@asheemmamoowala asheemmamoowala commented May 12, 2017

Add support for ImageSource to mbgl-core. The current source passes existing render tests and can be verified with the macos app/mbgl-glfw.

Remaining Tasks

  • Improve render transform
  • Fix image flip when crossing date line 🙃
  • ImageSource API improvements
  • iOS/Android/Qt Bindings ? ⛷ (Working on a separate PR)
  • Offline support
  • rebase 💥

//cc @jfirebaugh @ivovandongen @kkaefer

@asheemmamoowala asheemmamoowala added GL JS parity For feature parity with Mapbox GL JS ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels May 12, 2017
Comment thread cmake/core-files.cmake Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 on subdirectories for buckets and layer. Can you submit that as an independent PR so that it's easily reviewable independently? Will also help minimize potential merge conflicts as these files are getting touched a lot right now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for unique_ptr here; LatLng is a value class.

Comment thread include/mbgl/util/geo.hpp Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to add offline support for image sources -- it should download and store the image in the offline database.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offline support added in 3506bb5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace.

Comment thread cmake/core-files.cmake Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bogus file add

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be const

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace: We're using for (std::size_t i = 0; i < arrayLength(*coordinatesValue); i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move the string into the constructor

Comment thread src/mbgl/style/sources/image_source.cpp Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We're not indenting namespaces

Comment thread src/mbgl/renderer/render_item.hpp Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace: RenderSource* source;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace ;)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be either a non-const value (to enable move), or a const & to avoid two copies.

Comment thread test/src/mbgl/test/conversion_stubs.hpp Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreachable code

@asheemmamoowala asheemmamoowala force-pushed the 1350-image-source branch 3 times, most recently from 8da5ce5 to ffff1c6 Compare May 18, 2017 23:29

class ImageSource : public Source {
public:
ImageSource(std::string id, const std::vector<LatLng>);
Copy link
Copy Markdown
Contributor

@incanus incanus May 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this isn't a LatLngBounds? Similarly, it's very hard to discern the coordinate order this way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently an image source can be associated with any quadrilateral, not necessarily a rectangle.

mbgl tends to use std::array to represent fixed-length collections in style values (cf. padding and offsets). As @incanus points out, a struct with named fields would be another option that would avoid corner-swapping problems, although maybe we could make it so that the input order doesn’t matter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@incanus - thats an excellent point. Ive tried to wrap around that in the SDKs in the draft API PR. If the Quad struct makes sense, I think it might make more sense to move it into native.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there would have to be separate types for mbgl and for the iOS/macOS SDK, because the iOS/macOS SDKs can’t expose any C++ to the public.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mbgl tends to use std::array to represent fixed-length collections

Correct -- the type should be std::array<LatLng, 4>.

@incanus
Copy link
Copy Markdown
Contributor

incanus commented May 25, 2017

Quick & dirty iOS bindings for a near-term use case I have, per chat with @asheemmamoowala:

1350-image-source...jrm-ios-image-source-hack

@kkaefer kkaefer added Core The cross-platform C++ core, aka mbgl Node.js node-mapbox-gl-native labels May 30, 2017
@asheemmamoowala asheemmamoowala removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label May 30, 2017
@asheemmamoowala asheemmamoowala changed the title WIP: [core][node] Support ImageSource [core][node] Support ImageSource May 30, 2017
Copy link
Copy Markdown
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close! In addition to the changes requested below, please enable the relevant integration tests in mapbox-gl-js, open a PR there, and update the submodule pin here.

template <class V>
optional<LatLng> operator() (const V& value, Error& error) const {
if (!isArray(value) || arrayLength(value) < 2 ) {
error = { "coordinate array must contain numeric longtitude and latitude values" };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo for "longitude".


std::vector<LatLng> coordinates;
coordinates.reserve(4);
for( std::size_t i=0; i < arrayLength(*coordinatesValue); i++) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace. Also can use fixed upper bound. for (std::size_t i = 0; i < 4; i++)


class ImageSource : public Source {
public:
ImageSource(std::string id, const std::vector<LatLng>);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mbgl tends to use std::array to represent fixed-length collections

Correct -- the type should be std::array<LatLng, 4>.


inline optional<double> toDouble(const mbgl::android::Value& value) {
if (value.isNumber()) {
auto num = value.toDouble();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return value.toDouble();

ImageSource(std::string id, const std::vector<LatLng>);
~ImageSource() override;

const std::string& getURL() const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return type should be optional<std::string>, matching {Vector,Raster}Source::getURL and reflecting the possibility of absence.

setupBucket(geomCoords);
}

void RenderImageSource::setupBucket(GeometryCoordinates& geomCoords) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only called from updateTiles -- inline it there.

@@ -0,0 +1,71 @@
#pragma once

#include <mbgl/renderer/buckets/raster_bucket.hpp>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forward declare RasterBucket (and define ~RenderImageSource in the .cpp file) instead.

#include <mbgl/renderer/render_source.hpp>
#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/style/sources/image_source_impl.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

#include <mbgl/renderer/render_tile.hpp>
#include <mbgl/style/sources/image_source_impl.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/util/image.hpp>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

#include <mbgl/style/sources/image_source_impl.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/optional.hpp>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused.

@1ec5
Copy link
Copy Markdown
Contributor

1ec5 commented Jun 1, 2017

This PR along with #9110 fixes #1350.

@1ec5 1ec5 mentioned this pull request Jun 1, 2017
Copy link
Copy Markdown
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge once CI is passing. The current failure is:

==12458== Invalid write of size 4
==12458==    at 0x5D79AF: std::vector<unsigned int, std::allocator<unsigned int> >::push_back(unsigned int const&) (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test)
==12458==    by 0x5D7872: mbgl::gl::detail::TextureDeleter::operator()(unsigned int) const (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test)
==12458==    by 0x49B1BC: mbgl::RasterBucket::~RasterBucket() (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test)
==12458==    by 0x498189: Buckets_RasterBucket_Test::TestBody() (in /home/travis/build/mapbox/mapbox-gl-native/build/qt-linux-x86_64/Release/mbgl-test)

Which indicates that in the RasterBucket test, the declaration order for the bucket and the context should be switched, so that the context is still alive when the bucket is destroyed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Core The cross-platform C++ core, aka mbgl GL JS parity For feature parity with Mapbox GL JS Node.js node-mapbox-gl-native

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants