Vulkan Surface作成 on Android
Surfaceとは
"Vulkan® 1.2.202 - A Specification (with all registered Vulkan extensions)"内で
SurfaceはWSI(Window System Integration)の章の見出しのひとつのWSI Surfaceとして紹介されている。
つまりSurfaceとはVulkanのWindow Systemの扱い方である。
"Native platform surface or window objects are abstracted by surface objects, which are represented by VkSurfaceKHR handles"
Native platform surface や window objectsはVkSurfaceによって抽象化されると書かれているので、つまり
Native platform surface や window objectsをVulkan APIで扱うためのhandle。
Android Platform
Vulkan® 1.2.202 - A Specification (with all registered Vulkan extensions)のページに
To create a VkSurfaceKHR object for an Android native windowとある。
つまりAndroidに対してはVkSurfaceはAndroid native windowに対して作成され、それ以前の描画はAndroidに委ねられている。
Android native windowとは
Native Window | Android NDK | Android Developers
ANativeWindow represents the producer end of an image queue.
とあるので、Androidカーネルにおいてqueueからimageを生成するプログラムのことという理解。user appがAPIなどで扱えたり、エンコードできるようにしたり、ディスプレイに描画するimageを生成するOSのプログラム。
実装
void createSurface(ANativeWindow* platformWindow) { VkAndroidSurfaceCreateInfoKHR createInfo{ .sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR, .pNext = nullptr, .flags = 0, .window = platformWindow}; if(vkCreateAndroidSurfaceKHR(instance, &createInfo, nullptr, &surface) != VK_SUCCESS) __android_log_print(ANDROID_LOG_ERROR, "vulkan debug messages", "failed to create Android surface %u /n", 10); }
など。