从Android内核中拆分一些JNI c++代码
Unraveling some JNI C++ code from the Android core
我对c++和JNI不是很有经验,所以我对这段代码的某些部分有真正的麻烦(这是Android框架的一部分,更准确地说来自Surface
类的CPP源):
static void Surface_unlockCanvasAndPost(
JNIEnv* env, jobject clazz, jobject argCanvas)
{
jobject canvas = env->GetObjectField(clazz, so.canvas);
if (canvas != argCanvas) {
doThrow(env, "java/lang/IllegalArgumentException", NULL);
return;
}
const sp<Surface>& surface(getSurface(env, clazz));
if (!Surface::isValid(surface))
return;
// detach the canvas from the surface
SkCanvas* nativeCanvas =
(SkCanvas*) env->GetIntField(canvas, no.native_canvas);
int saveCount = env->GetIntField(clazz, so.saveCount);
nativeCanvas->restoreToCount(saveCount);
nativeCanvas->setBitmapDevice(SkBitmap());
env->SetIntField(clazz, so.saveCount, 0);
// unlock surface
status_t err = surface->unlockAndPost();
if (err < 0) {
doThrow(env, "java/lang/IllegalArgumentException", NULL);
}
}
特别让我烦恼的是:
const sp<Surface>& surface(getSurface(env, clazz));
这让我很困惑。没有等号,这些模板让人更难理解。
谁能帮我弄清楚这行代码?
这是引用的构造函数调用语法-这样写有点模糊,就像写int i(23);
而不是int i = 23;
一样,但它实际上相当于写const sp<Surface>& surface = getSurface(env, clazz);
.
相关文章:
- 通过JNI传递数据数组的最快方法是什么
- 为 NewObjectA() 函数创建 jvalues 的参数数组时出错 - JNI Invocation API
- 将 C# DLL 导入 C++ 以用于 JNI
- 用C++包装 Java 库 (JNI)
- 如何通过 JNI 将 C 字符串表情符号传递给 Java
- JNI从Android调用C++方法
- JVM 如何执行 JNI
- React Native (Android):无法通过 JNI 在 jobject 中返回字符串
- 如何将字符串数组返回到 java JNI
- JNI 日期值转换问题,在C++中获取不同的长整型值
- JNI,使用两个 .so 文件时出错,其中一个文件需要另一个文件
- Winapi - SetWindowLongPtr in ShutdownBlockReason创建/销毁JNI本机代码
- 将预编译的 C 共享库与 JNI/NDK 结合使用
- JNI 在应用程序中检测到错误:在为 innerclass 调用 NewObject 时使用了无效的 jobject
- 使用 jni 将返回带有模板的对象的 Java 代码转换为 c++
- 无法将DefineClass(JNI)与Qt资源一起使用
- 使用本机 JNI 静态方法实现C++ Java 运行时错误
- 从C++调用dll实现的JNI
- 如何在JNI中从线程内部调用JAVA方法
- 如何从 C/C++ 在 JNI for Java 中创建 UTF16 字符串?