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

ページの作成:「.NET for Android(旧:Xamarin.Android)でVulkanを動かすのにSurfaceViewのANativeWindowを取得する必要がある。.NETだとANativeWindow_fromSurface…」
 
編集の要約なし
 
(同じ利用者による、間の7版が非表示)
1行目: 1行目:
.NET for Android(旧:Xamarin.Android)で[[Vulkan]]を動かすのにSurfaceViewのANativeWindowを取得する必要がある。.NETだとANativeWindow_fromSurfaceをP/Invokeで簡単に呼び出せるのが便利。
[[.NET for Android]](旧:Xamarin.Android)で[[Vulkan]]を動かすのにSurfaceViewのANativeWindowを取得する必要があった。


<source lnag="csharp">
以下でうまくいった。
 
<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 ANativeWindowFromSurfaceView(SurfaceView surfaceView) {
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]]