「.NET for AndroidでSurfaceViewのANativeWindowを取得する」の版間の差分
Administrator (トーク | 投稿記録) ページの作成:「.NET for Android(旧:Xamarin.Android)でVulkanを動かすのにSurfaceViewのANativeWindowを取得する必要がある。.NETだとANativeWindow_fromSurface…」 |
Administrator (トーク | 投稿記録) 編集の要約なし |
||
| (同じ利用者による、間の7版が非表示) | |||
| 1行目: | 1行目: | ||
.NET for | [[.NET for Android]](旧:Xamarin.Android)で[[Vulkan]]を動かすのにSurfaceViewのANativeWindowを取得する必要があった。 | ||
<source | 以下でうまくいった。 | ||
<source lang="csharp"> | |||
[DllImport("android", CallingConvention = CallingConvention.Cdecl)] | [DllImport("android", CallingConvention = CallingConvention.Cdecl)] | ||
public static extern IntPtr ANativeWindow_fromSurface(IntPtr env, IntPtr surface); | public static extern IntPtr ANativeWindow_fromSurface(IntPtr env, IntPtr surface); | ||
public static | public static IntPtr GetANativeWindowFromSurfaceView(SurfaceView surfaceView) { | ||
Surface surface = surfaceView.Holder.Surface; | Surface surface = surfaceView.Holder.Surface; | ||
IntPtr surfacePtr = JNIEnv.ToLocalJniHandle(surface); | IntPtr surfacePtr = JNIEnv.ToLocalJniHandle(surface); | ||
| 13行目: | 15行目: | ||
</source> | </source> | ||
[[Java]]だと[[NDK]]を使わなければいけないが、[[.NET]]だとANativeWindow_fromSurfaceをP/Invokeで簡単に呼び出せるのがかなり便利。 | |||
[[category: .NET for Android]] | [[category: .NET for Android]] | ||