[android] Reuse Bitmap, Paint & Canvas instances in LocalGlyphRasterizer
- Make LocalGlyphRasterizer.drawGlyphBitmap() non-static - Store and reuse Bitmap, Paint & Canvas instances
This commit is contained in:
@@ -33,19 +33,27 @@
|
||||
namespace mbgl {
|
||||
namespace android {
|
||||
|
||||
LocalGlyphRasterizer::LocalGlyphRasterizer() {
|
||||
UniqueEnv env { AttachEnv() };
|
||||
|
||||
static auto constructor = javaClass.GetConstructor(*env);
|
||||
|
||||
javaObject = javaClass.New(*env, constructor).NewGlobalRef(*env);
|
||||
}
|
||||
|
||||
PremultipliedImage LocalGlyphRasterizer::drawGlyphBitmap(const std::string& fontFamily, const bool bold, const GlyphID glyphID) {
|
||||
UniqueEnv env { AttachEnv() };
|
||||
|
||||
using Signature = jni::Object<Bitmap>(jni::String, jni::jboolean, jni::jchar);
|
||||
auto method = javaClass.GetStaticMethod<Signature>(*env, "drawGlyphBitmap");
|
||||
static auto method = javaClass.GetMethod<Signature>(*env, "drawGlyphBitmap");
|
||||
|
||||
jni::String jniFontFamily = jni::Make<jni::String>(*env, fontFamily);
|
||||
|
||||
auto javaBitmap = javaClass.Call(*env,
|
||||
method,
|
||||
jniFontFamily,
|
||||
static_cast<jni::jboolean>(bold),
|
||||
static_cast<jni::jchar>(glyphID));
|
||||
auto javaBitmap = javaObject->Call(*env,
|
||||
method,
|
||||
jniFontFamily,
|
||||
static_cast<jni::jboolean>(bold),
|
||||
static_cast<jni::jchar>(glyphID));
|
||||
jni::DeleteLocalRef(*env, jniFontFamily);
|
||||
|
||||
PremultipliedImage result = Bitmap::GetImage(*env, javaBitmap);
|
||||
@@ -77,13 +85,15 @@ public:
|
||||
std::string lowercaseFont = platform::lowercase(font);
|
||||
if (lowercaseFont.find("bold") != std::string::npos) {
|
||||
bold = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return android::LocalGlyphRasterizer::drawGlyphBitmap(*fontFamily, bold, glyphID);
|
||||
return androidLocalGlyphRasterizer.drawGlyphBitmap(*fontFamily, bold, glyphID);
|
||||
}
|
||||
|
||||
private:
|
||||
optional<std::string> fontFamily;
|
||||
android::LocalGlyphRasterizer androidLocalGlyphRasterizer;
|
||||
};
|
||||
|
||||
LocalGlyphRasterizer::LocalGlyphRasterizer(const optional<std::string> fontFamily)
|
||||
|
||||
@@ -17,14 +17,18 @@ namespace android {
|
||||
|
||||
class LocalGlyphRasterizer {
|
||||
public:
|
||||
static PremultipliedImage drawGlyphBitmap(const std::string& fontFamily, const bool bold, const char16_t glyphID);
|
||||
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/text/LocalGlyphRasterizer"; };
|
||||
|
||||
static jni::Class<LocalGlyphRasterizer> javaClass;
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
LocalGlyphRasterizer();
|
||||
|
||||
PremultipliedImage drawGlyphBitmap(const std::string& fontFamily, const bool bold, const char16_t glyphID);
|
||||
|
||||
private:
|
||||
jni::UniqueObject<LocalGlyphRasterizer> javaObject;
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
Reference in New Issue
Block a user