feat: add v2 multi-plane field ingress
This commit is contained in:
@@ -1124,10 +1124,21 @@ jni::jboolean NativeMapView::setStyleLayerFloatProperty(JNIEnv& env,
|
||||
auto* layer = map->getStyle().getLayer(jni::Make<std::string>(env, layerId));
|
||||
if (!layer) return false;
|
||||
const auto property = jni::Make<std::string>(env, propertyName);
|
||||
if (property == "weather-color-field-value-source") {
|
||||
auto* weatherColorLayer = dynamic_cast<mbgl::style::WeatherColorLayer*>(layer);
|
||||
if (!weatherColorLayer || (value != 0.0f && value != 1.0f)) {
|
||||
mbgl::Log::Error(mbgl::Event::JNI, "ParticleField: event=FIELD_VALUE_SOURCE_SET result=REJECTED");
|
||||
return false;
|
||||
}
|
||||
weatherColorLayer->setFieldValueSource(value == 0.0f ? mbgl::style::FieldValueSource::Scalar
|
||||
: mbgl::style::FieldValueSource::VectorMagnitude);
|
||||
return true;
|
||||
}
|
||||
if (property != "raster-particle-time-mix" && property != "raster-particle-particle-count" &&
|
||||
property != "raster-particle-line-width" && property != "raster-particle-particle-length" &&
|
||||
property != "raster-particle-particle-opacity" && property != "raster-particle-trail-opacity" &&
|
||||
property != "raster-particle-trail-fade" && property != "raster-particle-speed-color-enabled") {
|
||||
property != "raster-particle-trail-fade" && property != "raster-particle-speed-color-enabled" &&
|
||||
property != "raster-particle-advection-scale") {
|
||||
mbgl::Log::Error(mbgl::Event::JNI, "ParticleGPU: event=STYLE_PROPERTY_SET result=UNSUPPORTED_PROPERTY");
|
||||
return false;
|
||||
}
|
||||
@@ -1163,6 +1174,9 @@ jni::jboolean NativeMapView::setStyleLayerFloatProperty(JNIEnv& env,
|
||||
particleLayer->setTrailOpacity(value);
|
||||
} else if (property == "raster-particle-trail-fade") {
|
||||
particleLayer->setTrailFade(value);
|
||||
} else if (property == "raster-particle-advection-scale") {
|
||||
if (value <= 0.0f) return false;
|
||||
particleLayer->setAdvectionScale(value);
|
||||
} else {
|
||||
if (value != 0.0f && value != 1.0f) {
|
||||
mbgl::Log::Error(mbgl::Event::JNI, "ParticleGPU: event=STYLE_PROPERTY_SET result=INVALID_COLOR_MODE");
|
||||
@@ -1327,6 +1341,51 @@ jni::jint NativeMapView::submitRasterArraySourceHostField(JNIEnv& env,
|
||||
return static_cast<jni::jint>(result);
|
||||
}
|
||||
|
||||
jni::jint NativeMapView::submitRasterArraySourceHostFieldV2(JNIEnv& env,
|
||||
const jni::String& sourceId,
|
||||
const jni::String& metadata,
|
||||
const jni::Array<jbyte>& packedPlanes,
|
||||
const jni::jboolean scalarPresent,
|
||||
const jni::jint scalarLength,
|
||||
const jni::jboolean vectorPresent,
|
||||
const jni::jint vectorLength,
|
||||
const jni::jint validityLength) {
|
||||
const auto id = jni::Make<std::string>(env, sourceId);
|
||||
auto* source = dynamic_cast<mbgl::style::RasterArraySource*>(map->getStyle().getSource(id));
|
||||
if (!source) return static_cast<jni::jint>(mbgl::style::RasterArrayHostFieldSubmitResult::RejectedSourceMode);
|
||||
NullCheck(env, &packedPlanes);
|
||||
if (scalarLength < 0 || vectorLength < 0 || validityLength <= 0 || (!scalarPresent && scalarLength != 0) ||
|
||||
(!vectorPresent && vectorLength != 0) || (scalarPresent && scalarLength == 0) ||
|
||||
(vectorPresent && vectorLength == 0) || (!scalarPresent && !vectorPresent)) {
|
||||
return static_cast<jni::jint>(mbgl::style::RasterArrayHostFieldSubmitResult::RejectedAdapter);
|
||||
}
|
||||
const uint64_t total = static_cast<uint64_t>(scalarLength) + static_cast<uint64_t>(vectorLength) +
|
||||
static_cast<uint64_t>(validityLength);
|
||||
if (total != packedPlanes.Length(env)) {
|
||||
return static_cast<jni::jint>(mbgl::style::RasterArrayHostFieldSubmitResult::RejectedAdapter);
|
||||
}
|
||||
std::vector<char> packed(total);
|
||||
if (!packed.empty()) jni::GetArrayRegion(env, *packedPlanes, 0, packed.size(), reinterpret_cast<jbyte*>(packed.data()));
|
||||
size_t offset = 0;
|
||||
const auto take = [&packed, &offset](const size_t length) {
|
||||
std::vector<char> result(packed.begin() + static_cast<std::ptrdiff_t>(offset),
|
||||
packed.begin() + static_cast<std::ptrdiff_t>(offset + length));
|
||||
offset += length;
|
||||
return result;
|
||||
};
|
||||
mbgl::particle::ParticleFieldPayloadBundle payloads{
|
||||
.scalar = scalarPresent ? std::optional<std::vector<char>>(take(static_cast<size_t>(scalarLength))) : std::nullopt,
|
||||
.vector = vectorPresent ? std::optional<std::vector<char>>(take(static_cast<size_t>(vectorLength))) : std::nullopt,
|
||||
.validity = take(static_cast<size_t>(validityLength)),
|
||||
};
|
||||
const auto result = source->submitHostField(jni::Make<std::string>(env, metadata), payloads);
|
||||
mbgl::Log::Info(mbgl::Event::JNI,
|
||||
"ParticleField: event=HOST_FIELD_V2_SUBMIT_BRIDGE sourceId=" + id + " scalar=" +
|
||||
(scalarPresent ? "present" : "absent") + " vector=" + (vectorPresent ? "present" : "absent") +
|
||||
" result=" + mbgl::style::rasterArrayHostFieldSubmitResultName(result));
|
||||
return static_cast<jni::jint>(result);
|
||||
}
|
||||
|
||||
jni::jboolean NativeMapView::clearRasterArraySourceHostFields(JNIEnv& env, const jni::String& sourceId) {
|
||||
const auto id = jni::Make<std::string>(env, sourceId);
|
||||
auto* source = dynamic_cast<mbgl::style::RasterArraySource*>(map->getStyle().getSource(id));
|
||||
@@ -1761,6 +1820,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&NativeMapView::advanceRasterArraySourceFieldWindow, "nativeAdvanceRasterArraySourceFieldWindow"),
|
||||
METHOD(&NativeMapView::repeatRasterArraySourceFieldWindow, "nativeRepeatRasterArraySourceFieldWindow"),
|
||||
METHOD(&NativeMapView::submitRasterArraySourceHostField, "nativeSubmitRasterArraySourceHostField"),
|
||||
METHOD(&NativeMapView::submitRasterArraySourceHostFieldV2, "nativeSubmitRasterArraySourceHostFieldV2"),
|
||||
METHOD(&NativeMapView::clearRasterArraySourceHostFields, "nativeClearRasterArraySourceHostFields"),
|
||||
METHOD(&NativeMapView::seekRasterArraySourceTimelineToTimestamp, "nativeSeekRasterArraySourceTimelineToTimestamp"),
|
||||
METHOD(&NativeMapView::controlRasterArraySourceTimeline, "nativeControlRasterArraySourceTimeline"),
|
||||
|
||||
Reference in New Issue
Block a user