Skip to content

Commit

Permalink
Test changes, refactor events
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilsnd committed Aug 28, 2024
1 parent 4691836 commit ca69dc1
Show file tree
Hide file tree
Showing 36 changed files with 241 additions and 187 deletions.
17 changes: 4 additions & 13 deletions include/mbgl/gfx/context_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@
#include <mbgl/gfx/backend.hpp>
#include <mbgl/shaders/shader_source.hpp>

#include <string_view>
#include <string>

namespace mbgl {
namespace gfx {

class ContextObserver {
public:
virtual void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type){};
virtual void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type){};
virtual void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type){};

virtual void onPreUploadTexture(gfx::Backend::Type){};
virtual void onPostUploadTexture(gfx::Backend::Type){};

virtual void onPreUploadUBO(gfx::Backend::Type){};
virtual void onPostUploadUBO(gfx::Backend::Type){};

virtual void onPreCreateRenderPipelineState(gfx::Backend::Type){};
virtual void onPostCreateRenderPipelineState(gfx::Backend::Type){};
virtual void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}
virtual void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}
virtual void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}
};

} // namespace gfx
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/map/map_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class MapObserver {
virtual void onRegisterShaders(gfx::ShaderRegistry&) {};

// Shaders compilation
virtual void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type) {}
virtual void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type) {}
virtual void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type) {}
virtual void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}
virtual void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}
virtual void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type, const std::string&) {}

// Glyph requests
virtual void onGlyphsLoaded(const FontStack&, const GlyphRange&) {}
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/renderer/renderer_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class RendererObserver {

// Entry point for custom shader registration
virtual void onRegisterShaders(gfx::ShaderRegistry&) {};
virtual void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type){};
virtual void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type){};
virtual void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type){};
virtual void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&){};
virtual void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&){};
virtual void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type, const std::string&){};

// Glyph loading
virtual void onGlyphsLoaded(const FontStack&, const GlyphRange&) {}
Expand Down
4 changes: 3 additions & 1 deletion include/mbgl/tile/tile_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

namespace mbgl {
enum class TileOperation : uint8_t {
Requested,
RequestedFromCache,
RequestedFromNetwork,
LoadFromNetwork,
LoadFromCache,
StartParse,
EndParse,
Error,
Cancelled,
NullOp,
};
} // namespace mbgl
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ class ForwardingRendererObserver : public RendererObserver {
delegate.invoke(&RendererObserver::onRemoveUnusedStyleImages, ids);
}

void onPreCompileShader(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type) override {
delegate.invoke(&RendererObserver::onPreCompileShader, id, type);
void onPreCompileShader(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type, const std::string& additionalDefines) override {
delegate.invoke(&RendererObserver::onPreCompileShader, id, type, additionalDefines);
}

void onPostCompileShader(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type) override {
delegate.invoke(&RendererObserver::onPostCompileShader, id, type);
void onPostCompileShader(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type, const std::string& additionalDefines) override {
delegate.invoke(&RendererObserver::onPostCompileShader, id, type, additionalDefines);
}

void onShaderCompileFailed(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type) override {
delegate.invoke(&RendererObserver::onShaderCompileFailed, id, type);
void onShaderCompileFailed(mbgl::shaders::BuiltIn id, mbgl::gfx::Backend::Type type, const std::string& additionalDefines) override {
delegate.invoke(&RendererObserver::onShaderCompileFailed, id, type, additionalDefines);
}

void onGlyphsLoaded(const mbgl::FontStack& stack, const mbgl::GlyphRange& range) override {
Expand Down
21 changes: 12 additions & 9 deletions platform/android/MapLibreAndroid/src/cpp/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,39 +1345,42 @@ void NativeMapView::registerNative(jni::JNIEnv& env) {
void NativeMapView::onRegisterShaders(gfx::ShaderRegistry&) {};

// Shader compilation
void NativeMapView::onPreCompileShader(shaders::BuiltIn id, gfx::Backend::Type type) {
void NativeMapView::onPreCompileShader(shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) {
assert(vm != nullptr);

android::UniqueEnv _env = android::AttachEnv();
static auto& javaClass = jni::Class<NativeMapView>::Singleton(*_env);
static auto onPreCompileShader = javaClass.GetMethod<void(jni::jint, jni::jint)>(*_env, "onPreCompileShader");
static auto onPreCompileShader = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(*_env, "onPreCompileShader");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, onPreCompileShader, static_cast<jni::jint>(id), static_cast<jni::jint>(type));
weakReference.Call(*_env, onPreCompileShader, static_cast<jni::jint>(id), static_cast<jni::jint>(type),
jni::Make<jni::String>(additionalDefines));
}
}

void NativeMapView::onPostCompileShader(shaders::BuiltIn id, gfx::Backend::Type type) {
void NativeMapView::onPostCompileShader(shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) {
assert(vm != nullptr);

android::UniqueEnv _env = android::AttachEnv();
static auto& javaClass = jni::Class<NativeMapView>::Singleton(*_env);
static auto onPostCompileShader = javaClass.GetMethod<void(jni::jint, jni::jint)>(*_env, "onPostCompileShader");
static auto onPostCompileShader = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(*_env, "onPostCompileShader");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, onPostCompileShader, static_cast<jni::jint>(id), static_cast<jni::jint>(type));
weakReference.Call(*_env, onPostCompileShader, static_cast<jni::jint>(id), static_cast<jni::jint>(type),
jni::Make<jni::String>(additionalDefines));
}
}

void NativeMapView::onShaderCompileFailed(shaders::BuiltIn id, gfx::Backend::Type type) {
void NativeMapView::onShaderCompileFailed(shaders::BuiltIn id, gfx::Backend::Type type, const std::string& additionalDefines) {
assert(vm != nullptr);

android::UniqueEnv _env = android::AttachEnv();
static auto& javaClass = jni::Class<NativeMapView>::Singleton(*_env);
static auto onShaderCompileFailed = javaClass.GetMethod<void(jni::jint, jni::jint)>(*_env, "onShaderCompileFailed");
static auto onShaderCompileFailed = javaClass.GetMethod<void(jni::jint, jni::jint, jni::String)>(*_env, "onShaderCompileFailed");
auto weakReference = javaPeer.get(*_env);
if (weakReference) {
weakReference.Call(*_env, onShaderCompileFailed, static_cast<jni::jint>(id), static_cast<jni::jint>(type));
weakReference.Call(*_env, onShaderCompileFailed, static_cast<jni::jint>(id), static_cast<jni::jint>(type),
jni::Make<jni::String>(additionalDefines));
}
}

Expand Down
6 changes: 3 additions & 3 deletions platform/android/MapLibreAndroid/src/cpp/native_map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ class NativeMapView : public MapObserver {

// Shader compilation
void onRegisterShaders(mbgl::gfx::ShaderRegistry&) override;
void onPreCompileShader(mbgl::shaders::BuiltIn, mbgl::gfx::Backend::Type) override;
void onPostCompileShader(mbgl::shaders::BuiltIn, mbgl::gfx::Backend::Type) override;
void onShaderCompileFailed(mbgl::shaders::BuiltIn, mbgl::gfx::Backend::Type) override;
void onPreCompileShader(mbgl::shaders::BuiltIn, mbgl::gfx::Backend::Type, const std::string&) override;
void onPostCompileShader(mbgl::shaders::BuiltIn, mbgl::gfx::Backend::Type, const std::string&) override;
void onShaderCompileFailed(mbgl::shaders::BuiltIn, mbgl::gfx::Backend::Type, const std::string&) override;

// Glyph requests
void onGlyphsLoaded(const mbgl::FontStack&, const mbgl::GlyphRange&) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace android {
jni::Local<jni::Object<TileOperation>> TileOperation::Create(jni::JNIEnv& env, mbgl::TileOperation op) {
static auto& _class = jni::Class<mbgl::android::TileOperation>::Singleton(env);
switch (op) {
case mbgl::TileOperation::Requested:
return _class.Get(env, _class.GetStaticField<jni::Object<TileOperation>>(env, "Requested"));
case mbgl::TileOperation::RequestedFromNetwork:
return _class.Get(env, _class.GetStaticField<jni::Object<TileOperation>>(env, "RequestedFromNetwork"));
case mbgl::TileOperation::RequestedFromCache:
return _class.Get(env, _class.GetStaticField<jni::Object<TileOperation>>(env, "RequestedFromCache"));
case mbgl::TileOperation::LoadFromCache:
return _class.Get(env, _class.GetStaticField<jni::Object<TileOperation>>(env, "LoadFromCache"));
case mbgl::TileOperation::LoadFromNetwork:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ public boolean onCanRemoveUnusedStyleImage(String imageId) {
}

@Override
public void onPreCompileShader(int id, int type) {
public void onPreCompileShader(int id, int type, String additionalDefines) {
try {
if (!onPreCompileShaderList.isEmpty()) {
for (MapView.OnPreCompileShaderListener listener : onPreCompileShaderList) {
listener.onPreCompileShader(id, type);
listener.onPreCompileShader(id, type, additionalDefines);
}
}
} catch (Throwable err) {
Expand All @@ -291,11 +291,11 @@ public void onPreCompileShader(int id, int type) {
}

@Override
public void onPostCompileShader(int id, int type) {
public void onPostCompileShader(int id, int type, String additionalDefines) {
try {
if (!onPostCompileShaderList.isEmpty()) {
for (MapView.OnPostCompileShaderListener listener : onPostCompileShaderList) {
listener.onPostCompileShader(id, type);
listener.onPostCompileShader(id, type, additionalDefines);
}
}
} catch (Throwable err) {
Expand All @@ -305,11 +305,11 @@ public void onPostCompileShader(int id, int type) {
}

@Override
public void onShaderCompileFailed(int id, int type) {
public void onShaderCompileFailed(int id, int type, String additionalDefines) {
try {
if (!onShaderCompileFailedList.isEmpty()) {
for (MapView.OnShaderCompileFailedListener listener : onShaderCompileFailedList) {
listener.onShaderCompileFailed(id, type);
listener.onShaderCompileFailed(id, type, additionalDefines);
}
}
} catch (Throwable err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,9 @@ public interface OnPreCompileShaderListener {
* of possible values.
* @param type of graphics backend the shader is being compiled for. See
* `mbgl::gfx::Backend::Type` for a list of possible values.
* @param additionalDefines that specify the permutaion of the shader.
*/
void onPreCompileShader(int id, int type);
void onPreCompileShader(int id, int type, String additionalDefines);
}

/**
Expand All @@ -1336,8 +1337,9 @@ public interface OnPostCompileShaderListener {
* of possible values.
* @param type of graphics backend the shader is being compiled for. See
* `mbgl::gfx::Backend::Type` for a list of possible values.
* @param additionalDefines that specify the permutation of the shader.
*/
void onPostCompileShader(int id, int type);
void onPostCompileShader(int id, int type, String additionalDefines);
}

/**
Expand All @@ -1354,8 +1356,9 @@ public interface OnShaderCompileFailedListener {
* of possible values.
* @param type of graphics backend the shader is being compiled for. See
* `mbgl::gfx::Backend::Type` for a list of possible values.
* @param additionalDefines that specify the permutation of the shader.
*/
void onShaderCompileFailed(int id, int type);
void onShaderCompileFailed(int id, int type, String additionalDefines);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1196,23 +1196,23 @@ protected void onSnapshotReady(@Nullable Bitmap mapContent) {
}

@Keep
private void onPreCompileShader(int id, int type) {
private void onPreCompileShader(int id, int type, String additionalDefines) {
if (stateCallback != null) {
stateCallback.onPreCompileShader(id, type);
stateCallback.onPreCompileShader(id, type, additionalDefines);
}
}

@Keep
private void onPostCompileShader(int id, int type) {
private void onPostCompileShader(int id, int type, String additionalDefines) {
if (stateCallback != null) {
stateCallback.onPostCompileShader(id, type);
stateCallback.onPostCompileShader(id, type, additionalDefines);
}
}

@Keep
private void onShaderCompileFailed(int id, int type) {
private void onShaderCompileFailed(int id, int type, String additionalDefines) {
if (stateCallback != null) {
stateCallback.onShaderCompileFailed(id, type);
stateCallback.onShaderCompileFailed(id, type, additionalDefines);
}
}

Expand Down Expand Up @@ -1693,11 +1693,11 @@ interface StateCallback extends StyleCallback {

boolean onCanRemoveUnusedStyleImage(String imageId);

void onPreCompileShader(int id, int type);
void onPreCompileShader(int id, int type, String additionalDefines);

void onPostCompileShader(int id, int type);
void onPostCompileShader(int id, int type, String additionalDefines);

void onShaderCompileFailed(int id, int type);
void onShaderCompileFailed(int id, int type, String additionalDefines);

void onGlyphsLoaded(String[] stack, int rangeStart, int rangeEnd);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.maplibre.android.tile;

public enum TileOperation {
Requested,
RequestedFromCache,
RequestedFromNetwork.,
LoadFromNetwork,
LoadFromCache,
StartParse,
Expand Down
12 changes: 6 additions & 6 deletions src/mbgl/map/map_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,16 @@ void Map::Impl::onRegisterShaders(gfx::ShaderRegistry& registry) {
observer.onRegisterShaders(registry);
}

void Map::Impl::onPreCompileShader(shaders::BuiltIn shaderID, gfx::Backend::Type type) {
observer.onPreCompileShader(shaderID, type);
void Map::Impl::onPreCompileShader(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) {
observer.onPreCompileShader(shaderID, type, additionalDefines);
}

void Map::Impl::onPostCompileShader(shaders::BuiltIn shaderID, gfx::Backend::Type type) {
observer.onPostCompileShader(shaderID, type);
void Map::Impl::onPostCompileShader(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) {
observer.onPostCompileShader(shaderID, type, additionalDefines);
}

void Map::Impl::onShaderCompileFailed(shaders::BuiltIn shaderID, gfx::Backend::Type type) {
observer.onShaderCompileFailed(shaderID, type);
void Map::Impl::onShaderCompileFailed(shaders::BuiltIn shaderID, gfx::Backend::Type type, const std::string& additionalDefines) {
observer.onShaderCompileFailed(shaderID, type, additionalDefines);
}

void Map::Impl::onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& ranges) {
Expand Down
6 changes: 3 additions & 3 deletions src/mbgl/map/map_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class Map::Impl final : public style::Observer, public RendererObserver {
void onRemoveUnusedStyleImages(const std::vector<std::string>&) final;
void onRegisterShaders(gfx::ShaderRegistry&) final;

void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type) final;
void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type) final;
void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type) final;
void onPreCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&) final;
void onPostCompileShader(shaders::BuiltIn, gfx::Backend::Type, const std::string&) final;
void onShaderCompileFailed(shaders::BuiltIn, gfx::Backend::Type, const std::string&) final;
void onGlyphsLoaded(const FontStack&, const GlyphRange&) final;
void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) final;
void onGlyphsRequested(const FontStack&, const GlyphRange&) final;
Expand Down
Loading

0 comments on commit ca69dc1

Please sign in to comment.