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

[core][node] Support ImageSource #8968

Merged
merged 8 commits into from
Jun 1, 2017
Merged

[core][node] Support ImageSource #8968

merged 8 commits into from
Jun 1, 2017

Conversation

asheemmamoowala
Copy link
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
src/mbgl/renderer/tile_parameters.hpp
src/mbgl/renderer/tile_pyramid.cpp
src/mbgl/renderer/tile_pyramid.hpp
src/mbgl/renderer/transitioning_property.hpp
src/mbgl/renderer/update_parameters.hpp

# renderer/buckets
Copy link
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.

namespace conversion {

template<>
struct Converter<std::unique_ptr<LatLng>> {
Copy link
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.

@@ -47,7 +47,7 @@ class LatLng {
wrap();
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: whitespace change.

@@ -107,6 +107,7 @@ OfflineRegionStatus OfflineDownload::getStatus() const {

case SourceType::Video:
case SourceType::Annotations:
case SourceType::Image:
break;
Copy link
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
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

@@ -176,7 +177,8 @@ void OfflineDownload::activateDownload() {

case SourceType::Video:
case SourceType::Annotations:
break;
case SourceType::Image:
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace.

@@ -74,6 +74,8 @@ set(MBGL_CORE_FILES
src/mbgl/gl/object.hpp
src/mbgl/gl/primitives.hpp
src/mbgl/gl/program.hpp
src/mbgl/gl/program_binary.cpp
src/mbgl/gl/program_binary.hpp
Copy link
Member

Choose a reason for hiding this comment

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

Bogus file add

}
//Style spec uses GeoJSON convention for specifying coordinates
optional<float> latitude = toNumber(arrayMember(value, 1));
optional<float> longitude = toNumber(arrayMember(value, 0));
Copy link
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


std::vector<std::unique_ptr<LatLng>> coordinates;
coordinates.reserve(4);
for( std::size_t i=0; i < arrayLength(*coordinatesValue); i++) {
Copy link
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++) {

return {};
}

auto result = std::make_unique<ImageSource>(id, *urlString);
Copy link
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

return impl->getURL();
}

} // namespace style
Copy link
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

const RenderLayer& layer;
std::vector<std::reference_wrapper<RenderTile>> tiles;
RenderLayer& layer;
RenderSource * source;
Copy link
Member

Choose a reason for hiding this comment

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

Whitespace: RenderSource* source;

: RenderSource(impl_),
impl(impl_),
loaded(false) {
}
Copy link
Member

Choose a reason for hiding this comment

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

Formatting

const mat4& clipMatrix,
const TransformState&) final;

void render (Painter&, PaintParameters& , const RenderLayer& ) ;
Copy link
Member

Choose a reason for hiding this comment

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

Whitespace ;)

return url;
}

void ImageSource::Impl::setCoordinates(const std::vector<LatLng> coords_) {
Copy link
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.

} else {
return {};
}
return {};
Copy link
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
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
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
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
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
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
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
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
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
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
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>.

@@ -66,6 +66,15 @@ inline optional<float> toNumber(const mbgl::android::Value& value) {
}
}

inline optional<double> toDouble(const mbgl::android::Value& value) {
if (value.isNumber()) {
auto num = value.toDouble();
Copy link
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
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
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
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
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
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
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
Contributor

1ec5 commented Jun 1, 2017

This PR along with #9110 fixes #1350.

@1ec5 1ec5 mentioned this pull request Jun 1, 2017
Copy link
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