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

Remove TileData::State #5139

Merged
merged 7 commits into from
May 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mbgl/algorithm/update_renderables_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool tryTile(const UnwrappedTileID& renderTileID,
Renderables& renderables) {
if (renderables.find(renderTileID) == renderables.end()) {
const auto it = dataTiles.find(dataTileID);
if (it == dataTiles.end() || !it->second->isReady()) {
if (it == dataTiles.end() || !it->second->isRenderable()) {
return false;
}

Expand Down
9 changes: 6 additions & 3 deletions src/mbgl/renderer/debug_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
using namespace mbgl;

DebugBucket::DebugBucket(const OverscaledTileID& id,
const TileData::State state_,
const bool renderable_,
const bool complete_,
optional<Timestamp> modified_,
optional<Timestamp> expires_,
MapDebugOptions debugMode_)
: state(state_),
: renderable(renderable_),
complete(complete_),
modified(std::move(modified_)),
expires(std::move(expires_)),
debugMode(debugMode_) {
double baseline = 200;
if (debugMode & MapDebugOptions::ParseStatus) {
const std::string text = util::toString(id) + " - " + TileData::StateToString(state);
const std::string text = util::toString(id) + " - " +
(complete ? "complete" : renderable ? "renderable" : "pending");
fontBuffer.addText(text.c_str(), 50, baseline, 5);
baseline += 200;
}
Expand Down
7 changes: 5 additions & 2 deletions src/mbgl/renderer/debug_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ class GLObjectStore;

class DebugBucket : private util::noncopyable {
public:
DebugBucket(const OverscaledTileID& id, TileData::State,
DebugBucket(const OverscaledTileID& id,
bool renderable,
bool complete,
optional<Timestamp> modified,
optional<Timestamp> expires,
MapDebugOptions);

void drawLines(PlainShader&, gl::GLObjectStore&);
void drawPoints(PlainShader&, gl::GLObjectStore&);

const TileData::State state;
const bool renderable;
const bool complete;
const optional<Timestamp> modified;
const optional<Timestamp> expires;
const MapDebugOptions debugMode;
Expand Down
13 changes: 8 additions & 5 deletions src/mbgl/renderer/painter_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ void Painter::renderDebugText(TileData& tileData, const mat4 &matrix) {

config.depthTest = GL_FALSE;

if (!tileData.debugBucket || tileData.debugBucket->state != tileData.getState()
|| !(tileData.debugBucket->modified == tileData.modified)
|| !(tileData.debugBucket->expires == tileData.expires)
|| tileData.debugBucket->debugMode != frame.debugOptions) {
tileData.debugBucket = std::make_unique<DebugBucket>(tileData.id, tileData.getState(), tileData.modified, tileData.expires, frame.debugOptions);
if (!tileData.debugBucket || tileData.debugBucket->renderable != tileData.isRenderable() ||
tileData.debugBucket->complete != tileData.isComplete() ||
!(tileData.debugBucket->modified == tileData.modified) ||
!(tileData.debugBucket->expires == tileData.expires) ||
tileData.debugBucket->debugMode != frame.debugOptions) {
tileData.debugBucket = std::make_unique<DebugBucket>(
tileData.id, tileData.isRenderable(), tileData.isComplete(), tileData.modified,
tileData.expires, frame.debugOptions);
}

config.program = plainShader->getID();
Expand Down
5 changes: 2 additions & 3 deletions src/mbgl/source/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool Source::isLoaded() const {
if (!loaded) return false;

for (const auto& pair : tileDataMap) {
if (pair.second->getState() != TileData::State::parsed) {
if (!pair.second->isComplete()) {
return false;
}
}
Expand Down Expand Up @@ -307,8 +307,7 @@ bool Source::update(const StyleUpdateParameters& parameters) {
for (auto& pair : tileDataMap) {
const auto& dataTileID = pair.first;
auto tileData = pair.second.get();
if (parameters.shouldReparsePartialTiles &&
tileData->getState() == TileData::State::partial) {
if (parameters.shouldReparsePartialTiles && tileData->isIncomplete()) {
auto callback = std::bind(&Source::tileLoadingCallback, this, dataTileID,
std::placeholders::_1, false);

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ RenderData Style::getRenderData() const {

for (auto& pair : source->getTiles()) {
auto& tile = pair.second;
if (!tile.data.isReady()) {
if (!tile.data.isRenderable()) {
continue;
}

Expand Down
11 changes: 6 additions & 5 deletions src/mbgl/style/style_bucket_parameters.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <mbgl/map/mode.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/tile/tile_data.hpp>

#include <functional>
#include <atomic>

namespace mbgl {

Expand All @@ -21,7 +22,7 @@ class StyleBucketParameters {
public:
StyleBucketParameters(const OverscaledTileID& tileID_,
const GeometryTileLayer& layer_,
const std::atomic<TileData::State>& state_,
const std::atomic<bool>& obsolete_,
uintptr_t tileUID_,
bool& partialParse_,
SpriteStore& spriteStore_,
Expand All @@ -31,7 +32,7 @@ class StyleBucketParameters {
const MapMode mode_)
: tileID(tileID_),
layer(layer_),
state(state_),
obsolete(obsolete_),
tileUID(tileUID_),
partialParse(partialParse_),
spriteStore(spriteStore_),
Expand All @@ -41,14 +42,14 @@ class StyleBucketParameters {
mode(mode_) {}

bool cancelled() const {
return state == TileData::State::obsolete;
return obsolete;
}

void eachFilteredFeature(const Filter&, std::function<void (const GeometryTileFeature&, std::size_t index, const std::string& layerName)>);

const OverscaledTileID& tileID;
const GeometryTileLayer& layer;
const std::atomic<TileData::State>& state;
const std::atomic<bool>& obsolete;
uintptr_t tileUID;
bool& partialParse;
SpriteStore& spriteStore;
Expand Down
23 changes: 3 additions & 20 deletions src/mbgl/tile/raster_tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ RasterTileData::RasterTileData(const OverscaledTileID& id_,
: TileData(id_),
texturePool(texturePool_),
worker(worker_) {
state = State::loading;

const Resource resource =
Resource::tile(urlTemplate, pixelRatio, id.canonical.x, id.canonical.y, id.canonical.z);
req = fileSource.request(resource, [callback, this](Response res) {
Expand All @@ -29,7 +27,7 @@ RasterTileData::RasterTileData(const OverscaledTileID& id_,
modified = res.modified;
expires = res.expires;
} else if (res.noContent) {
state = State::parsed;
availableData = DataAvailability::All;
modified = res.modified;
expires = res.expires;
workRequest.reset();
Expand All @@ -39,28 +37,20 @@ RasterTileData::RasterTileData(const OverscaledTileID& id_,
modified = res.modified;
expires = res.expires;

// Only overwrite the state when we didn't have a previous tile.
if (state == State::loading) {
state = State::loaded;
}

workRequest.reset();
workRequest = worker.parseRasterTile(std::make_unique<RasterBucket>(texturePool), res.data, [this, callback] (RasterTileParseResult result) {
workRequest.reset();
if (state != State::loaded) {
return;
}

std::exception_ptr error;
if (result.is<std::unique_ptr<Bucket>>()) {
state = State::parsed;
bucket = std::move(result.get<std::unique_ptr<Bucket>>());
} else {
error = result.get<std::exception_ptr>();
state = State::obsolete;
bucket.reset();
}

availableData = DataAvailability::All;

callback(error);
});
}
Expand All @@ -76,13 +66,6 @@ Bucket* RasterTileData::getBucket(StyleLayer const&) {
}

void RasterTileData::cancel() {
if (state != State::obsolete) {
state = State::obsolete;
}
req = nullptr;
workRequest.reset();
}

bool RasterTileData::hasData() const {
return bucket.get() != nullptr;
}
1 change: 0 additions & 1 deletion src/mbgl/tile/raster_tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class RasterTileData : public TileData {

void cancel() override;
Bucket* getBucket(StyleLayer const &layer_desc) override;
bool hasData() const override;

private:
gl::TexturePool& texturePool;
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/tile/tile_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void TileCache::setSize(size_t size_) {
}

void TileCache::add(const OverscaledTileID& key, std::unique_ptr<TileData> data) {
if (!data->isReady() || !size) {
if (!data->isRenderable() || !size) {
return;
}

Expand Down Expand Up @@ -48,7 +48,7 @@ std::unique_ptr<TileData> TileCache::get(const OverscaledTileID& key) {
data = std::move(it->second);
tiles.erase(it);
orderedKeys.remove(key);
assert(data->isReady());
assert(data->isRenderable());
}

return data;
Expand Down
19 changes: 3 additions & 16 deletions src/mbgl/tile/tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,15 @@
namespace mbgl {

TileData::TileData(const OverscaledTileID& id_)
: id(id_),
state(State::initial) {
: id(id_) {
}

TileData::~TileData() = default;

const char* TileData::StateToString(const State state) {
switch (state) {
case TileData::State::initial: return "initial";
case TileData::State::invalid : return "invalid";
case TileData::State::loading : return "loading";
case TileData::State::loaded : return "loaded";
case TileData::State::obsolete : return "obsolete";
case TileData::State::parsed : return "parsed";
case TileData::State::partial : return "partial";
default: return "<unknown>";
}
}

void TileData::dumpDebugLogs() const {
Log::Info(Event::General, "TileData::id: %s", util::toString(id).c_str());
Log::Info(Event::General, "TileData::state: %s", TileData::StateToString(state));
Log::Info(Event::General, "TileData::renderable: %s", isRenderable() ? "yes" : "no");
Log::Info(Event::General, "TileData::complete: %s", isComplete() ? "yes" : "no");
}

void TileData::queryRenderedFeatures(
Expand Down
82 changes: 24 additions & 58 deletions src/mbgl/tile/tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <mbgl/text/placement_config.hpp>
#include <mbgl/tile/geometry_tile.hpp>

#include <atomic>
#include <string>
#include <memory>
#include <functional>
Expand All @@ -24,55 +23,6 @@ class TransformState;

class TileData : private util::noncopyable {
public:
// initial:
// Initial state, only used when the TileData object is created.
//
// invalid:
// FIXME: This state has a bit of overlap with 'initial' and 'obsolete'.
//
// We report TileData being 'invalid' on Source::hasTile if we don't have the
// TileData yet, then Source creates a request. This is misleading because
// the TileData object is not effectively on the 'invalid' state and will
// cause tiles on 'invalid' state to get reloaded.
//
// loading:
// A request to the FileSource was made for the actual tile data and TileData
// is waiting for it to arrive.
//
// loaded:
// The actual tile data has arrived and the tile can be parsed.
//
// partial:
// TileData is partially parsed, some buckets are still waiting for dependencies
// to arrive, but it is good for rendering. Partial tiles can also be re-parsed,
// but might remain in the same state if dependencies are still missing.
//
// parsed:
// TileData is fully parsed and its contents won't change from this point. This
// is the only state which is safe to cache this object.
//
// obsolete:
// The TileData can go to obsolete from any state, due to parsing or loading error,
// request cancellation or because the tile is no longer in use.
enum class State {
initial,
invalid,
loading,
loaded,
partial,
parsed,
obsolete
};

static const char* StateToString(State);

// Tile data considered "Ready" can be used for rendering. Data in
// partial state is still waiting for network resources but can also
// be rendered, although layers will be missing.
inline static bool isReadyState(const State& state) {
return state == State::partial || state == State::parsed;
}

TileData(const OverscaledTileID&);
virtual ~TileData();

Expand All @@ -91,15 +41,18 @@ class TileData : private util::noncopyable {
const TransformState&,
const optional<std::vector<std::string>>& layerIDs);

bool isReady() const {
return isReadyState(state);
// Tile data considered "Renderable" can be used for rendering. Data in
// partial state is still waiting for network resources but can also
// be rendered, although layers will be missing.
bool isRenderable() const {
return availableData != DataAvailability::None;
}

// Returns true when there's at least some data that we can render.
virtual bool hasData() const = 0;

State getState() const {
return state;
bool isComplete() const {
return availableData == DataAvailability::All;
}
bool isIncomplete() const {
return availableData == DataAvailability::Some;
}

void dumpDebugLogs() const;
Expand All @@ -112,7 +65,20 @@ class TileData : private util::noncopyable {
std::unique_ptr<DebugBucket> debugBucket;

protected:
std::atomic<State> state;
enum class DataAvailability : uint8_t {
// Still waiting for data to load or parse.
None,

// TileData is partially parsed, some buckets are still waiting for dependencies
// to arrive, but it is good for rendering. Partial tiles can also be re-parsed,
// but might remain in the same state if dependencies are still missing.
Some,

// TileData is fully parsed, and all buckets are available if they exist.
All,
};

DataAvailability availableData = DataAvailability::None;
};

} // namespace mbgl
Loading