2017-03-07 9 views
2

내가 인터넷에서 찾은 모든 리소스는 기본 활동을 생성하고 vkAndroidSurfaceKHR을 생성하기위한 android_app-> 창을 초기화하는 것으로 초기화하십시오. 그래서 저는 표면 생성을 위해이 창을 제공하는 창 관리자를 가질 수 있는지 알고 싶습니다.창을 가져 오기 위해 기본 활동을 만들어야합니까? 또는 탄탄한 응용 프로그램을 위해 android devices에서 창 관리자로부터 제공 할 수 있습니까?

+0

는 잘 모르겠어요 "이 창을 제공하는 창 관리자가 있습니까?"라는 의미입니다. vkCreateAndroidSurfaceKHR에 전달 된 ANativeWindow는 대개 NativeActivity 윈도우이거나 (Java) Surface 객체 (https://developer.android.com/reference/android/view/Surface.html)에서 가져옵니다. 일반적으로 이것은 SurfaceView에서 나옵니다. 그러나 Surface를 가져 오는 다른 방법이 있습니다. –

답변

0

간단한 Java 응용 프로그램에서 vkAndroidSurfaceKHR을 만들려면 android.view.View의 인스턴스를 가져 와서 ANativeWindow_fromSurface (env, win)에 대한 기본 호출을 수행합니다. 참고 View 및 해당 하위 클래스는 GPU에서 OpenGL 및 Vulkan과 같은 3D 콘텐츠를 그릴 수 있습니다. 내가 라인 9100 주위에 내 api이 방법을했다

,

/** 
* Get display handles for Android and AWT Canvas 
* @param win - a java.awt.Canvas instance or a android.view.Surface 
* @param displayHandles - return native surface handle 
* 
* @return true if all goes Ok. 
*/ 
protected static native boolean getDisplayHandles0(Object win, long[] displayHandles);/* 

#ifdef VK_USE_PLATFORM_ANDROID_KHR 
    ANativeWindow* window;  
    // Return the ANativeWindow associated with a Java Surface object, 
    // for interacting with it through native code. This acquires a reference 
    // on the ANativeWindow that is returned; be sure to use ANativeWindow_release() 
    // when done with it so that it doesn't leak. 
    window = ANativeWindow_fromSurface(env, win); 
    displayHandles[0] = reinterpret_cast<jlong>(window); 
    return JNI_TRUE; 
#else 
... 
#endif 
*/ 
} 
나는 또한 같은 위의 소스에서, 라인 10370 주위에 다른 방법이 구현

:

/** 
* 
* @see http://www.javaworld.com/article/2075263/core-java/embed-java-code-into-your-native-apps.html 
* 
* @param instance - Vulkan instance 
* @param nativeWindow - instance of android.view.Surface or java.awt.Canvas 
* @param pAllocatorHandle - native handle to a VkAllocationCallbacks 
* @param pSurface 
* @return 
*/ 
protected static native int vkCreateWindowSurface0(long instance, 
                Object nativeWindow, 
                long pAllocatorHandle, 
                long[] pSurface, 
                long[] awtDrawingSurface);/* 

VkAllocationCallbacks* pAllocator = reinterpret_cast<VkAllocationCallbacks*>(pAllocatorHandle); 
VkInstance vkInstance = reinterpret_cast<VkInstance>(instance); 
VkSurfaceKHR* _pSurface = new VkSurfaceKHR[1]; 
VkResult res = VkResult::VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; 

#ifdef VK_USE_PLATFORM_ANDROID_KHR  
    ANativeWindow* window = NULL; 
    window = ANativeWindow_fromSurface(env, nativeWindow); 
    if (window == NULL) 
     return VkResult::VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; 

    VkAndroidSurfaceCreateInfoKHR info; 
    info.sType = VkStructureType::VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; 
    info.pNext = NULL; 
    info.flags = 0; 
    info.window = window; 
    res = vkCreateAndroidSurfaceKHR(vkInstance, &info, pAllocator, _pSurface); 
#else 
... 
#endif 

if(res >= 0){ 
    pSurface[0] = reinterpret_cast<jlong>(_pSurface[0]);   
}else{ 
    pSurface[0] = (jlong)0; 
    fprintf(stderr,"Failed to create Vulkan SurfaceKHR."); 
} 

delete[] _pSurface;   
return res; 
} 
+0

jniGen을 사용 했으므로 원시 코드와 Java 코드가 섞여 있습니다. –