feat: add continuous retained render ranges
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
Some checks failed
validate-scripts / validate-scripts (push) Has been cancelled
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/renderer/retained_underlay_cache.hpp>
|
||||
#include <mbgl/renderer/particle_fast_path.hpp>
|
||||
#include <mbgl/renderer/continuous_layer_range.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -10,7 +11,7 @@ using namespace mbgl;
|
||||
|
||||
namespace {
|
||||
RetainedUnderlayKey key(Size size = {640, 480}, int32_t boundary = 4) {
|
||||
RetainedUnderlayKey result{size, boundary, {}};
|
||||
RetainedUnderlayKey result{size, 0, boundary, {}};
|
||||
result.cameraMatrix[0] = 1.0;
|
||||
result.cameraMatrix[5] = 1.0;
|
||||
result.cameraMatrix[10] = 1.0;
|
||||
@@ -128,7 +129,7 @@ TEST(RetainedUnderlayRevision, MonotonicAcrossCameraViewportStyleAndSourceChange
|
||||
RetainedUnderlayCache cache;
|
||||
auto state = revisionState();
|
||||
const auto currentKey = [&] {
|
||||
return RetainedUnderlayKey{state.viewport, *state.boundary, state.cameraMatrix};
|
||||
return RetainedUnderlayKey{state.viewport, 0, *state.boundary, state.cameraMatrix};
|
||||
};
|
||||
EXPECT_EQ(tracker.observe(state), 1u);
|
||||
EXPECT_EQ(tracker.observe(state), 1u);
|
||||
@@ -191,6 +192,134 @@ TEST(RetainedUnderlayRevision, MonotonicAcrossCameraViewportStyleAndSourceChange
|
||||
RetainedUnderlayDecision::Build);
|
||||
}
|
||||
|
||||
TEST(ContinuousLayerRange, ResolvesInclusiveSingleAndMultiLayerRanges) {
|
||||
const std::vector<std::string> layers{"bottom", "hidden-start", "middle", "hidden-end", "top"};
|
||||
auto single = resolveContinuousLayerRange({true, "middle", "middle", 1}, layers);
|
||||
ASSERT_TRUE(single.valid);
|
||||
EXPECT_EQ(single.startIndex, 2);
|
||||
EXPECT_EQ(single.endIndex, 2);
|
||||
EXPECT_EQ(single.endExclusive(), 3);
|
||||
|
||||
auto multi = resolveContinuousLayerRange({true, "hidden-start", "hidden-end", 2}, layers);
|
||||
ASSERT_TRUE(multi.valid);
|
||||
EXPECT_EQ(multi.startIndex, 1);
|
||||
EXPECT_EQ(multi.endIndex, 3);
|
||||
EXPECT_TRUE(multi.bottomPresent());
|
||||
EXPECT_TRUE(multi.topPresent(static_cast<int32_t>(layers.size())));
|
||||
}
|
||||
|
||||
TEST(ContinuousLayerRange, RejectsMissingAndReversedEndpointsWithoutStaleIndices) {
|
||||
const std::vector<std::string> layers{"a", "b", "c"};
|
||||
const auto reversed = resolveContinuousLayerRange({true, "c", "a", 1}, layers);
|
||||
EXPECT_FALSE(reversed.valid);
|
||||
EXPECT_EQ(reversed.reason, "range-order-invalid");
|
||||
|
||||
const auto missingStart = resolveContinuousLayerRange({true, "missing", "c", 2}, layers);
|
||||
EXPECT_FALSE(missingStart.valid);
|
||||
EXPECT_EQ(missingStart.startIndex, -1);
|
||||
EXPECT_EQ(missingStart.reason, "start-layer-missing");
|
||||
|
||||
const auto missingEnd = resolveContinuousLayerRange({true, "a", "missing", 3}, layers);
|
||||
EXPECT_FALSE(missingEnd.valid);
|
||||
EXPECT_EQ(missingEnd.endIndex, -1);
|
||||
EXPECT_EQ(missingEnd.reason, "end-layer-missing");
|
||||
}
|
||||
|
||||
TEST(ContinuousLayerRange, SupportsAllFourDegradedTopologies) {
|
||||
const std::vector<std::string> layers{"a", "b", "c", "d"};
|
||||
const auto three = resolveContinuousLayerRange({true, "b", "c", 1}, layers);
|
||||
EXPECT_TRUE(three.bottomPresent());
|
||||
EXPECT_TRUE(three.topPresent(4));
|
||||
|
||||
const auto bottomOnly = resolveContinuousLayerRange({true, "b", "d", 2}, layers);
|
||||
EXPECT_TRUE(bottomOnly.bottomPresent());
|
||||
EXPECT_FALSE(bottomOnly.topPresent(4));
|
||||
|
||||
const auto topOnly = resolveContinuousLayerRange({true, "a", "c", 3}, layers);
|
||||
EXPECT_FALSE(topOnly.bottomPresent());
|
||||
EXPECT_TRUE(topOnly.topPresent(4));
|
||||
|
||||
const auto continuousOnly = resolveContinuousLayerRange({true, "a", "d", 4}, layers);
|
||||
EXPECT_TRUE(continuousOnly.valid);
|
||||
EXPECT_FALSE(continuousOnly.bottomPresent());
|
||||
EXPECT_FALSE(continuousOnly.topPresent(4));
|
||||
}
|
||||
|
||||
TEST(ContinuousLayerRange, OnlyActuallyPresentRetainedRangesRequestCacheBuilds) {
|
||||
RetainedUnderlayCache bottom(RetainedRangeRole::Bottom);
|
||||
RetainedUnderlayCache top(RetainedRangeRole::Top);
|
||||
const auto countBuilds = [&](bool bottomPresent, bool topPresent) {
|
||||
const auto bottomDecision = bottom.evaluate(bottomPresent ? std::optional<RetainedUnderlayKey>(key())
|
||||
: std::nullopt,
|
||||
1, true);
|
||||
const auto topDecision = top.evaluate(topPresent ? std::optional<RetainedUnderlayKey>(key())
|
||||
: std::nullopt,
|
||||
1, true);
|
||||
return static_cast<int>(bottomDecision == RetainedUnderlayDecision::Build) +
|
||||
static_cast<int>(topDecision == RetainedUnderlayDecision::Build);
|
||||
};
|
||||
EXPECT_EQ(countBuilds(true, true), 2);
|
||||
EXPECT_EQ(countBuilds(true, false), 1);
|
||||
EXPECT_EQ(countBuilds(false, true), 1);
|
||||
EXPECT_EQ(countBuilds(false, false), 0);
|
||||
}
|
||||
|
||||
TEST(ContinuousLayerRange, ReorderAndEndpointDeletionAreResolvedFromCurrentStyle) {
|
||||
const ContinuousLayerRangeConfig config{true, "b", "c", 7};
|
||||
EXPECT_TRUE(resolveContinuousLayerRange(config, {"a", "b", "c"}).valid);
|
||||
EXPECT_FALSE(resolveContinuousLayerRange(config, {"a", "c", "b"}).valid);
|
||||
const auto deleted = resolveContinuousLayerRange(config, {"a", "b"});
|
||||
EXPECT_FALSE(deleted.valid);
|
||||
EXPECT_EQ(deleted.reason, "end-layer-missing");
|
||||
}
|
||||
|
||||
TEST(ContinuousLayerRange, RuntimeConfigurationRejectsEmptyIdsAndAdvancesMonotonically) {
|
||||
RetainedUnderlayRuntimeState state;
|
||||
EXPECT_FALSE(state.setContinuousLayerRange("", "end"));
|
||||
EXPECT_EQ(state.continuousLayerRangeConfig().revision, 0u);
|
||||
EXPECT_TRUE(state.setContinuousLayerRange("start", "end"));
|
||||
EXPECT_EQ(state.continuousLayerRangeConfig().revision, 1u);
|
||||
EXPECT_TRUE(state.setContinuousLayerRange("start", "end"));
|
||||
EXPECT_EQ(state.continuousLayerRangeConfig().revision, 1u);
|
||||
EXPECT_TRUE(state.setContinuousLayerRange("same", "same"));
|
||||
const auto config = state.continuousLayerRangeConfig();
|
||||
EXPECT_EQ(config.revision, 2u);
|
||||
EXPECT_EQ(config.startLayerId, config.endLayerId);
|
||||
}
|
||||
|
||||
TEST(ContinuousLayerRange, ExplicitConfigurationNeverMixesWithLegacyBoundary) {
|
||||
ContinuousLayerRangeResolution valid;
|
||||
valid.configured = true;
|
||||
valid.valid = true;
|
||||
valid.startIndex = 0;
|
||||
valid.endIndex = 1;
|
||||
valid.configRevision = 4;
|
||||
const auto explicitPlan = selectContinuousRenderRanges(valid, 7, 10);
|
||||
EXPECT_EQ(explicitPlan.continuousBegin, 0);
|
||||
EXPECT_EQ(explicitPlan.continuousEndExclusive, 2);
|
||||
EXPECT_FALSE(explicitPlan.bottomPresent());
|
||||
EXPECT_TRUE(explicitPlan.topPresent());
|
||||
|
||||
valid.valid = false;
|
||||
valid.reason = "start-layer-missing";
|
||||
const auto invalidPlan = selectContinuousRenderRanges(valid, 7, 10);
|
||||
EXPECT_FALSE(invalidPlan.retainedMode());
|
||||
EXPECT_FALSE(invalidPlan.bottomPresent());
|
||||
EXPECT_FALSE(invalidPlan.topPresent());
|
||||
|
||||
const ContinuousLayerRangeResolution unconfigured;
|
||||
const auto legacyPlan = selectContinuousRenderRanges(unconfigured, 7, 10);
|
||||
EXPECT_TRUE(legacyPlan.retainedMode());
|
||||
EXPECT_EQ(legacyPlan.continuousBegin, 7);
|
||||
EXPECT_FALSE(legacyPlan.topPresent());
|
||||
}
|
||||
|
||||
TEST(ContinuousLayerRange, AbsentRetainedRangesDoNotCauseFastPathMiss) {
|
||||
auto input = fastPathInput();
|
||||
input.cacheValid = true; // all zero actually-present retained ranges are valid vacuously.
|
||||
EXPECT_TRUE(evaluateParticleFastPath(input).candidate);
|
||||
}
|
||||
|
||||
TEST(RetainedUnderlayRevision, RepeatedFramesWithoutSemanticMutationDoNotAdvanceRevision) {
|
||||
RetainedUnderlayRevisionTracker tracker;
|
||||
auto state = revisionState();
|
||||
|
||||
Reference in New Issue
Block a user