Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2528)

Unified Diff: tools/viewer/sk_app/android/VulkanWindowContext_android.cpp

Issue 2169543002: Use Windowing system-specific WindowContext factories. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: more xlib Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/viewer/sk_app/android/VulkanWindowContext_android.cpp
diff --git a/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp b/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp
index 15dc0b02f049a44c873814ab3376976f0307e289..68f2051f3aa636ef9730b335dc372cb7f5c18eb2 100644
--- a/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp
+++ b/tools/viewer/sk_app/android/VulkanWindowContext_android.cpp
@@ -6,43 +6,47 @@
* found in the LICENSE file.
*/
+#include "WindowContextFactory_android.h"
#include "../VulkanWindowContext.h"
-#include "WindowContext_android.h"
-
-#include "vk/GrVkInterface.h"
-#include "vk/GrVkUtil.h"
namespace sk_app {
-VkSurfaceKHR VulkanWindowContext::createVkSurface(VkInstance instance, void* platformData) {
- static PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = nullptr;
- if (!createAndroidSurfaceKHR) {
- createAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr(instance,
- "vkCreateAndroidSurfaceKHR");
- }
-
- if (!platformData) {
- return VK_NULL_HANDLE;
+namespace window_context_factory {
+
+WindowContext* NewVulkanForAndroid(ANativeWindow* window, const DisplayParams& params) {
+ auto createVkSurface = [window] (VkInstance instance) -> VkSurfaceKHR {
+ static PFN_vkCreateAndroidSurfaceKHR createAndroidSurfaceKHR = nullptr;
+ if (!createAndroidSurfaceKHR) {
+ createAndroidSurfaceKHR = (PFN_vkCreateAndroidSurfaceKHR)vkGetInstanceProcAddr(
+ instance, "vkCreateAndroidSurfaceKHR");
+ }
+
+ if (!window) {
+ return VK_NULL_HANDLE;
+ }
+ VkSurfaceKHR surface;
+
+ VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo;
+ memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR));
+ surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
+ surfaceCreateInfo.pNext = nullptr;
+ surfaceCreateInfo.flags = 0;
+ surfaceCreateInfo.window = window;
+
+ VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo,
+ nullptr, &surface);
+ return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE;
+ };
+
+ auto canPresent = [](VkInstance, VkPhysicalDevice, uint32_t) { return true; };
+
+ WindowContext* ctx = new VulkanWindowContext(params, createVkSurface, canPresent);
+ if (!ctx->isValid()) {
+ delete ctx;
+ return nullptr;
}
- ContextPlatformData_android* androidPlatformData =
- reinterpret_cast<ContextPlatformData_android*>(platformData);
- VkSurfaceKHR surface;
-
- VkAndroidSurfaceCreateInfoKHR surfaceCreateInfo;
- memset(&surfaceCreateInfo, 0, sizeof(VkAndroidSurfaceCreateInfoKHR));
- surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
- surfaceCreateInfo.pNext = nullptr;
- surfaceCreateInfo.flags = 0;
- surfaceCreateInfo.window = androidPlatformData->fNativeWindow;
-
- VkResult res = createAndroidSurfaceKHR(instance, &surfaceCreateInfo,
- nullptr, &surface);
- return (VK_SUCCESS == res) ? surface : VK_NULL_HANDLE;
-}
-
-bool VulkanWindowContext::canPresent(VkInstance instance, VkPhysicalDevice physDev,
- uint32_t queueFamilyIndex, void*) {
- return true;
+ return ctx;
}
-} // namespace sk_app
+} // namespace window_context_factory
+} // namespace sk_app

Powered by Google App Engine
This is Rietveld 408576698