「.NET for AndroidでSurfaceViewのANativeWindowを取得する」の版間の差分

提供: MonoBook
ナビゲーションに移動 検索に移動
 
(相違点なし)

2024年4月23日 (火) 05:31時点における最新版

.NET for Android(旧:Xamarin.Android)でVulkanを動かすのにSurfaceViewのANativeWindowを取得する必要があった。

以下でうまくいった。 .NETだとANativeWindow_fromSurfaceをP/Invokeで簡単に呼び出せるのが便利。

[DllImport("android", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr ANativeWindow_fromSurface(IntPtr env, IntPtr surface);

public static IntPtr GetANativeWindowFromSurfaceView(SurfaceView surfaceView) {
    Surface surface = surfaceView.Holder.Surface;
    IntPtr surfacePtr = JNIEnv.ToLocalJniHandle(surface);
    IntPtr aNativeWindow = ANativeWindow_fromSurface(JNIEnv.Handle, surfacePtr);
    return aNativeWindow;
}