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

Commit

Permalink
[core] rename TileData::State to DataAvailability and make it private
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed May 25, 2016
1 parent 6f1477f commit b4de5f4
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 60 deletions.
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
3 changes: 1 addition & 2 deletions src/mbgl/source/source.cpp
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions src/mbgl/style/style_bucket_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <mbgl/style/filter.hpp>

#include <functional>
#include <atomic>

namespace mbgl {

Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/tile/raster_tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,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 @@ -43,14 +43,14 @@ RasterTileData::RasterTileData(const OverscaledTileID& id_,

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::parsed;
bucket.reset();
}

availableData = DataAvailability::All;

callback(error);
});
}
Expand Down
15 changes: 3 additions & 12 deletions src/mbgl/tile/tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,15 @@
namespace mbgl {

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

TileData::~TileData() = default;

const char* TileData::StateToString(const State state) {
switch (state) {
case TileData::State::loading : return "loading";
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
44 changes: 18 additions & 26 deletions src/mbgl/tile/tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@ class TransformState;

class TileData : private util::noncopyable {
public:
// loading:
// A request to the FileSource was made for the actual tile data and TileData
// is waiting for it to arrive.
//
// 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.
enum class State {
loading,
partial,
parsed,
};

static const char* StateToString(State);

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

Expand All @@ -65,15 +45,14 @@ class TileData : private util::noncopyable {
// partial state is still waiting for network resources but can also
// be rendered, although layers will be missing.
bool isRenderable() const {
return state == State::partial || state == State::parsed;
return availableData != DataAvailability::None;
}

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

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

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

protected:
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
1 change: 1 addition & 0 deletions src/mbgl/tile/tile_worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <memory>
#include <mutex>
#include <list>
#include <atomic>
#include <unordered_map>

namespace mbgl {
Expand Down
16 changes: 9 additions & 7 deletions src/mbgl/tile/vector_tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_,
if (!tile) {
// This is a 404 response. We're treating these as empty tiles.
workRequest.reset();
state = State::parsed;
availableData = DataAvailability::All;
buckets.clear();
callback(err);
return;
}

// Mark the tile as pending again if it was complete before to prevent signaling a complete
// state despite pending parse operations.
if (isComplete()) {
state = State::partial;
if (availableData == DataAvailability::All) {
availableData = DataAvailability::Some;
}

// Kick off a fresh parse of this tile. This happens when the tile is new, or
Expand All @@ -66,7 +66,8 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_,
std::exception_ptr error;
if (result.is<TileParseResultData>()) {
auto& resultBuckets = result.get<TileParseResultData>();
state = resultBuckets.complete ? State::parsed : State::partial;
availableData =
resultBuckets.complete ? DataAvailability::All : DataAvailability::Some;

// Persist the configuration we just placed so that we can later check whether we need to
// place again in case the configuration has changed.
Expand All @@ -84,7 +85,7 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_,
} else {
// This is triggered when parsing fails (e.g. due to an invalid vector tile)
error = result.get<std::exception_ptr>();
state = State::parsed;
availableData = DataAvailability::All;
}

callback(error);
Expand All @@ -109,7 +110,8 @@ bool VectorTileData::parsePending(std::function<void(std::exception_ptr)> callba
std::exception_ptr error;
if (result.is<TileParseResultData>()) {
auto& resultBuckets = result.get<TileParseResultData>();
state = resultBuckets.complete ? State::parsed : State::partial;
availableData =
resultBuckets.complete ? DataAvailability::All : DataAvailability::Some;

// Move over all buckets we received in this parse request, potentially overwriting
// existing buckets in case we got a refresh parse.
Expand All @@ -128,7 +130,7 @@ bool VectorTileData::parsePending(std::function<void(std::exception_ptr)> callba

} else {
error = result.get<std::exception_ptr>();
state = State::parsed;
availableData = DataAvailability::All;
}

callback(error);
Expand Down

0 comments on commit b4de5f4

Please sign in to comment.