Commit Graph

75 Commits

Author SHA1 Message Date
Thiago Marcos P. Santos
c6e58515fc Keep updating until all the tiles are State::parsed
This is needed because of a race that can occur now that we
requests Glyphs from the Map Thread:

The glyph might arrive at the moment a tile is being parsed
and they won't be notified again of any new data, remaining
forever at the partial state.
2015-07-16 19:38:38 +03:00
Konstantin Käfer
675ddddee7 Make pixelRatio constant across a Map object lifetime
also moves framebuffer size out of TransformState into its own object
2015-07-08 10:40:05 +02:00
Minh Nguyễn
4c1f325bf6 Moved raster zoom threshold to the .5’s
Fixes #963.
2015-07-07 12:14:26 -07:00
Thiago Marcos P. Santos
f6b8dd4be9 Add simple static method to retrieve the current loop
In the lines of how we do for getting information of the
current thread.
2015-07-06 15:54:51 +03:00
John Firebaugh
f5f19d0eb0 External synchronization for AnnotationManager 2015-07-02 10:12:04 -07:00
John Firebaugh
117322d349 Don't inherit for code reuse 2015-07-02 10:12:04 -07:00
John Firebaugh
1da2c3f840 Remove unnecessary virtual methods from TileData 2015-07-02 10:12:03 -07:00
John Firebaugh
fc64e97bce Simplify RunLoop
Instead of transforming between return value and callback, pass
the wrapped callback on to the invoked function as the last argument.

This eliminates the need for multiple invokeWithArgument overloads
and permits invoked functions to be asynchronous.
2015-07-01 16:12:12 -07:00
John Firebaugh
db1202e8e3 Don't pass Worker& around so much 2015-07-01 15:21:11 -07:00
John Firebaugh
ee46378583 Reduce number of arguments in Source::update pathway 2015-07-01 15:21:08 -07:00
John Firebaugh
4eff674c1d Revert "Do not hold a reference to the Style at the [Live|Vector]TileData"
This reverts commit 044454417b.
2015-07-01 15:21:08 -07:00
John Firebaugh
e87a36444f Move getMin/MaxZoom to TransformState 2015-06-26 10:32:07 -07:00
Thiago Marcos P. Santos
be4cb6786b Make the FileSource available from the ThreadContext
For now we set the FileSource for the Worker context
but in the future after fixing #1664 we can assert()
that FileSource are set only for the Map thread context.
2015-06-25 16:26:21 +03:00
John Firebaugh
eb52f86ee1 Fix an order-of-operations issue with tileLoadingCompleteCallback
==7466== Invalid read of size 8
==7466==    at 0x5F1D0B: mbgl::TransformState::getAngle() const (transform_state.cpp:159)
==7466==    by 0x700CD2: mbgl::Source::tileLoadingCompleteCallback(mbgl::TileID const&, mbgl::TransformState const&, bool) (source.cpp:574)

==7466==  Address 0xf1d1508 is 56 bytes inside a block of size 120 free'd
==7466==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7466==    by 0x70AD61: std::_Function_base::_Base_manager<std::_Bind<std::_Mem_fn<void (mbgl::Source::*)(mbgl::TileID const&, mbgl::TransformState const&, bool)> ()(mbgl::Source*, mbgl::TileID, mbgl::TransformState, bool)> >::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==7466==    by 0x7080EB: std::_Function_base::_Base_manager<std::_Bind<std::_Mem_fn<void (mbgl::Source::*)(mbgl::TileID const&, mbgl::TransformState const&, bool)> ()(mbgl::Source*, mbgl::TileID, mbgl::TransformState, bool)> >::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==7466==    by 0x535033: _ZNSt8functionIFvvEEaSEDn (functional:2277)
==7466==    by 0x56A3F5: mbgl::WorkTask::cancel() (work_task.cpp:34)
==7466==    by 0x56146C: mbgl::WorkRequest::~WorkRequest() (work_request.cpp:13)
==7466==    by 0x50C5E0: std::default_delete<mbgl::WorkRequest>::operator()(mbgl::WorkRequest*) const (unique_ptr.h:76)
==7466==    by 0x50C411: std::unique_ptr<mbgl::WorkRequest, std::default_delete<mbgl::WorkRequest> >::reset(mbgl::WorkRequest*) (unique_ptr.h:344)
==7466==    by 0x50C374: std::unique_ptr<mbgl::WorkRequest, std::default_delete<mbgl::WorkRequest> >::operator=(std::unique_ptr<mbgl::WorkRequest, std::default_delete<mbgl::WorkRequest> >&&) (unique_ptr.h:251)
==7466==    by 0x743136: mbgl::TileData::reparse(mbgl::Worker&, std::function<void ()()>) (tile_data.cpp:89)
==7466==    by 0x6FEA7C: mbgl::Source::handlePartialTile(mbgl::TileID const&, mbgl::Worker&) (source.cpp:250)
==7466==    by 0x700338: mbgl::Source::update(mbgl::MapData&, mbgl::TransformState const&, mbgl::Style&, mbgl::GlyphAtlas&, mbgl::GlyphStore&, mbgl::SpriteAtlas&, mbgl::util::ptr<mbgl::Sprite>, mbgl::TexturePool&, bool) (source.cpp:438)
==7466==    by 0x68C1A5: mbgl::Style::update(mbgl::MapData&, mbgl::TransformState const&, mbgl::TexturePool&) (style.cpp:82)
==7466==    by 0x548F5C: (anonymous namespace)::MockMapContext::update() (resource_loading.cpp:51)
==7466==    by 0x548FA3: (anonymous namespace)::MockMapContext::onTileDataChanged() (resource_loading.cpp:56)
==7466==    by 0x68CDE4: mbgl::Style::emitTileDataChanged() (style.cpp:212)
==7466==    by 0x68CBDB: mbgl::Style::onTileLoaded(bool) (style.cpp:191)
==7466==    by 0x700F38: mbgl::Source::emitTileLoaded(bool) (source.cpp:595)
==7466==    by 0x700CA2: mbgl::Source::tileLoadingCompleteCallback(mbgl::TileID const&, mbgl::TransformState const&, bool) (source.cpp:573)

The invalid `TransformState::getAngle()` read comes from the following: the
storage for `TransformState` is the [bound parameter in this
callback](https://github.com/mapbox/mapbox-gl-native/blob/5e0775d276f9ea3652bae1
23c4e85cc05ae13bd5/src/mbgl/map/source.cpp#L292-292). The callback itself is
copied into various lambda bindings and eventually winds up as the [after
callback](https://github.com/mapbox/mapbox-gl-native/blob/5e0775d276f9ea3652bae1
23c4e85cc05ae13bd5/src/mbgl/map/tile_data.cpp#L89-89) for the worker task.

On the way out, `tileLoadingCompleteCallback` gets called via this callback
binding. It first does `emitTileLoaded`, which happens to cause [a _new_ work
request to be
queued](https://github.com/mapbox/mapbox-gl-native/blob/5e0775d276f9ea3652bae123
c4e85cc05ae13bd5/src/mbgl/map/source.cpp#L250-250). This cancels the
in-progress work request, [by nulling-out the `after`
callback](https://github.com/mapbox/mapbox-gl-native/blob/5e0775d276f9ea3652bae1
23c4e85cc05ae13bd5/src/mbgl/util/work_task.cpp#L34-34). But in fact, the after
callback is still executing. The next thing it does is [call
transformState.getAngle()](https://github.com/mapbox/mapbox-gl-native/blob/5e077
5d276f9ea3652bae123c4e85cc05ae13bd5/src/mbgl/map/source.cpp#L574), but the
transformState is now gone.
2015-06-18 13:39:18 +03:00
Thiago Marcos P. Santos
044454417b Do not hold a reference to the Style at the [Live|Vector]TileData
Layers are added and removed dynamically on the Map thread when we use shape
annotations and we are iterating style.layers on the Worker thread without
any lock.

Now when we create a [Live|Vector]TileData at the Map thread we give it
a layers list (instead of the Style) and [Live|Vector]TileData will ultimately
make a copy of this list (on the Map thread, so no concurrency with
adding shape annotations).

The copy should be relatively cheap because we are using a shared pointer
for storing the layers on the list.
2015-06-18 13:39:18 +03:00
Justin R. Miller
bd0bf294bf squash of #1655: shape annotations support for core & iOS 2015-06-15 18:30:39 -07:00
John Firebaugh
a0503f3f5b Remove unused overscaling variables 2015-06-04 14:09:05 -07:00
Ansis Brammanis
1f5fb1db4a fix hangs caused by redoPlacement
After parsing a tile, it redoes placement for that tile if the angle has
changed since it started parsing. These redo calls were accidentally
done from the worker thread. Assigning the new work to `workRequest`
caused it to cancel itself.

Fix the problem by calling redoPlacement from the map thread.
2015-06-02 17:06:24 -04:00
Ansis Brammanis
ff6a5ce5bc Merge remote-tracking branch 'origin/master' into new-labelling
Conflicts:
	src/mbgl/map/source.cpp
	src/mbgl/map/source.hpp
	src/mbgl/map/tile_data.cpp
	src/mbgl/map/tile_parser.cpp
	src/mbgl/map/vector_tile_data.cpp
	src/mbgl/renderer/painter.cpp
	src/mbgl/renderer/symbol_bucket.cpp
	src/mbgl/text/glyph.hpp
	src/mbgl/text/glyph_store.cpp
	src/mbgl/text/placement.cpp
	test/suite
2015-05-28 20:01:15 -04:00
Ansis Brammanis
1e044a175c Reparse tiles when zoom level > source maxzoom
so that layout property functions are applied correctly
and so that label placement is redone

js:
https://github.com/mapbox/mapbox-gl-js/pull/1005
and
440bc02505
2015-05-28 19:17:07 -04:00
Ansis Brammanis
8962442b1b make collision debug boxes toggleable 2015-05-28 19:17:07 -04:00
Thiago Marcos P. Santos
f8cc50683a Notify tile parsing errors
The tile parsing is done in a worker thread and if it fails,
we set the tile state to "obsolete" and set an error message.

When the completion callback is fired, we check for the error
message and if it is set, we emit the error signal.

The trick here is the signal cannot be emitted directly from
the worker thread because that would violate data ownership rules.
2015-05-28 09:33:08 +03:00
Konstantin Käfer
f4707f72e0 Replace mbgl::util::make_unique<> with std::make_unique<> 2015-05-26 17:57:38 +02:00
John Firebaugh
87b1da7611 DefaultFileSource has responsibility for handling mapbox:// URLs 2015-05-26 12:14:10 +02:00
Thiago Marcos P. Santos
ac64bef87f Notify failures when loading tiles 2015-05-22 10:44:18 +03:00
Thiago Marcos P. Santos
90fd06762c Notify failures when loading the source JSON 2015-05-22 10:44:18 +03:00
Ansis Brammanis
0bd39ae44a place symbols with correct angle on initial load 2015-05-20 19:18:53 -04:00
Ansis Brammanis
d41bfa2679 redo placement when map rotates 2015-05-20 17:52:00 -04:00
Thiago Marcos P. Santos
aaaf1e4c14 Only emit tile updated signals when the tile really changes
We only emit signals when the number of buckets increase (i.e. the
new data that arrived added a new bucket to the tile).

Also, if we try to reparse a partial tile but it is not possible, we
keep the flag up for trying to reparse it again on the next update,
because the data might have arrived after the bucket that is waiting
for the data was processed but before the end of the parsing.

Fixes #1458
2015-05-18 10:42:05 +03:00
Thiago Marcos P. Santos
4e7c97466c Allow reparsing partial tiles when we have new tiles
When parsing a tile, we request resources from the network, like
sprites and glyphs.

In the rare case of the resources arriving before the tile is
parsed for the first time, if we don't mark it for being parsed
again, it can end up with a tile eternally stuck in the partial
state.
2015-05-18 10:42:05 +03:00
Thiago Marcos P. Santos
3f445e8578 Do not process partial tiles if no new resources have arrived
Partial tiles are now only processed again when there is a new resource
available. If we don't have new resources - like new glyphs - the end result
of the reparsing is the same, because no new SymbolBuckets would are created.

In my tests debugging with PowerTOP, this patch drops the CPU utilization
during the sampling period from 100ms/s to 40ms/s. The improvements on
slow connections (i.e. more time waiting for resources) are even more
noticeable.
2015-05-18 10:42:05 +03:00
John Firebaugh
a2344c36c3 Extensible GL extension support 2015-05-13 19:01:58 -07:00
John Firebaugh
b334b7ee4e Remove unnecessary use of shared_from_this()
If the request is cancelled, the response callback won't be called, and
~Source ensures that the request is cancelled. So it's safe to bind
`this` in the lambda.
2015-05-13 13:57:32 -07:00
Thiago Marcos P. Santos
41d619771e Make the state attribute private
Also add a virtual setState() method to give subclasses a chance
to intercept the change of state. This will be used by VectorTileData
to release resources when the TileData becomes immutable.
2015-05-13 09:58:19 +02:00
Thiago Marcos P. Santos
19881f8b24 Cancel all pending requests before leaving
This still has the unwanted side effect off blocking the Map thread
waiting for the workers to return (because they hold a reference
to the Map thread main loop).

Maybe the only way to solve this would be having a I/O thread for
dispatching messages.

The Request is not bound anymore to the invoker thread because the workers
will request for glyphs, but the reply will arrive at the Map thread.
2015-05-05 18:35:40 +03:00
Thiago Marcos P. Santos
1455e5e53c Add partial tile parsing
This change will add a new state to the tile called "partial" which
is a state where the tile can be rendered but some information might
be missing.

For now we skip the SymbolBucket if the Sprites are not loaded (will
also do the same for the glyphs in the future). When the Sprites are
finally loaded, we trigger another update, this time the Tile will
get completely re-rendered and change the state to "parsed".
2015-05-05 18:35:40 +03:00
Thiago Marcos P. Santos
f4baa0ba3e Notify data changes using Observer pattern
This pattern, in contrast with callbacks, allows us to clearly see
the dependency and hierarchy between the objects. It will also help
on writing unit tests as we can count how many times a notification
was triggered.
2015-05-05 18:10:20 +03:00
Konstantin Käfer
5beb635028 create the tile list statically 2015-05-04 17:33:04 +02:00
Konstantin Käfer
5f496d8f0c build render order array once instead of recursing through lots of different objects 2015-05-04 17:33:04 +02:00
John Firebaugh
cdb466e7f7 Convert Style to unique_ptr and pass by reference
Fixes #1277
Fixes #1309
2015-04-28 14:32:26 -04:00
John Firebaugh
0c280adebc Move Worker to Style
This ensures that worker tasks are entirely complete by the
time the style is destructed, and enables us to pass Style&
rather than a shared pointer.
2015-04-28 14:32:26 -04:00
John Firebaugh
7cd55a3333 Enforce that transformState belongs to Map thread 2015-04-28 14:32:23 -04:00
John Firebaugh
c2abd1d692 Log error as Error 2015-04-28 14:32:23 -04:00
John Firebaugh
ec7588f1fd Implement Style::isLoaded 2015-04-28 14:32:22 -04:00
Konstantin Käfer
7c8c45edab move activeSources to internal Map context 2015-04-28 14:32:18 -04:00
Konstantin Käfer
89167cbf8c move Transform into MapData and make source unaware of the Map object 2015-04-28 14:32:18 -04:00
Konstantin Käfer
cc8f440c84 move TransformState to MapData object 2015-04-28 14:32:17 -04:00
Justin R. Miller
b43ba4089c fixes #1308: normalize tile memory cache keys & allow dupe inserts 2015-04-22 15:35:34 -07:00
Justin R. Miller
190709c6b1 fixes #1157, #1255: cache parsed tiles in memory 2015-04-16 01:15:41 -07:00
John Firebaugh
0c087603e6 Replace uv_messenger with AsyncQueue; rewrite remaining uv_* in C++ 2015-04-09 15:30:58 -07:00