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

Unified Diff: tools/viewer/sk_app/unix/VulkanWindowContext_unix.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/unix/VulkanWindowContext_unix.cpp
diff --git a/tools/viewer/sk_app/unix/VulkanWindowContext_unix.cpp b/tools/viewer/sk_app/unix/VulkanWindowContext_unix.cpp
index 02bf516b22fd63e3e621b982c00c54a024d9b91c..b94e8edc2090539c84dcbed84242d9558e809d71 100644
--- a/tools/viewer/sk_app/unix/VulkanWindowContext_unix.cpp
+++ b/tools/viewer/sk_app/unix/VulkanWindowContext_unix.cpp
@@ -6,70 +6,74 @@
* found in the LICENSE file.
*/
-#include "../VulkanWindowContext.h"
-#include "Window_unix.h"
#include "vk/GrVkInterface.h"
#include "vk/GrVkUtil.h"
#include <X11/Xlib-xcb.h>
-namespace sk_app {
-
-// Platform dependant call
-VkSurfaceKHR VulkanWindowContext::createVkSurface(VkInstance instance, void* platformData) {
- static PFN_vkCreateXcbSurfaceKHR createXcbSurfaceKHR = nullptr;
- if (!createXcbSurfaceKHR) {
- createXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) vkGetInstanceProcAddr(instance,
- "vkCreateXcbSurfaceKHR");
- }
-
- if (!platformData) {
- return VK_NULL_HANDLE;
- }
- ContextPlatformData_unix* unixPlatformData =
- reinterpret_cast<ContextPlatformData_unix*>(platformData);
-
-
- VkSurfaceKHR surface;
+#include "WindowContextFactory_unix.h"
+#include "../VulkanWindowContext.h"
- VkXcbSurfaceCreateInfoKHR surfaceCreateInfo;
- memset(&surfaceCreateInfo, 0, sizeof(VkXcbSurfaceCreateInfoKHR));
- surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
- surfaceCreateInfo.pNext = nullptr;
- surfaceCreateInfo.flags = 0;
- surfaceCreateInfo.connection = XGetXCBConnection(unixPlatformData->fDisplay);
- surfaceCreateInfo.window = unixPlatformData->fWindow;
+namespace sk_app {
- VkResult res = createXcbSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
- if (VK_SUCCESS != res) {
- return VK_NULL_HANDLE;
+namespace window_context_factory {
+
+WindowContext* NewVulkanForXlib(const XlibWindowInfo& info, const DisplayParams& displayParams) {
+ auto createVkSurface = [&info](VkInstance instance) -> VkSurfaceKHR {
+ static PFN_vkCreateXcbSurfaceKHR createXcbSurfaceKHR = nullptr;
+ if (!createXcbSurfaceKHR) {
+ createXcbSurfaceKHR =
+ (PFN_vkCreateXcbSurfaceKHR) vkGetInstanceProcAddr(instance,
+ "vkCreateXcbSurfaceKHR");
+ }
+
+ VkSurfaceKHR surface;
+
+ VkXcbSurfaceCreateInfoKHR surfaceCreateInfo;
+ memset(&surfaceCreateInfo, 0, sizeof(VkXcbSurfaceCreateInfoKHR));
+ surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
+ surfaceCreateInfo.pNext = nullptr;
+ surfaceCreateInfo.flags = 0;
+ surfaceCreateInfo.connection = XGetXCBConnection(info.fDisplay);
+ surfaceCreateInfo.window = info.fWindow;
+
+ VkResult res = createXcbSurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
+ if (VK_SUCCESS != res) {
+ return VK_NULL_HANDLE;
+ }
+
+ return surface;
+ };
+
+ auto canPresent = [&info](VkInstance instance, VkPhysicalDevice physDev,
+ uint32_t queueFamilyIndex) {
+ static PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
+ getPhysicalDeviceXcbPresentationSupportKHR = nullptr;
+ if (!getPhysicalDeviceXcbPresentationSupportKHR) {
+ getPhysicalDeviceXcbPresentationSupportKHR =
+ (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)
+ vkGetInstanceProcAddr(instance,
+ "vkGetPhysicalDeviceXcbPresentationSupportKHR");
+ }
+
+
+ Display* display = info.fDisplay;
+ VisualID visualID = info.fVisualInfo->visualid;
+ VkBool32 check = getPhysicalDeviceXcbPresentationSupportKHR(physDev,
+ queueFamilyIndex,
+ XGetXCBConnection(display),
+ visualID);
+ return (VK_FALSE != check);
+ };
+ WindowContext* context = new VulkanWindowContext(displayParams, createVkSurface, canPresent);
+ if (!context->isValid()) {
+ delete context;
+ return nullptr;
}
-
- return surface;
+ return context;
}
-// Platform dependant call
-bool VulkanWindowContext::canPresent(VkInstance instance, VkPhysicalDevice physDev,
- uint32_t queueFamilyIndex, void* platformData) {
- static PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
- getPhysicalDeviceXcbPresentationSupportKHR = nullptr;
- if (!getPhysicalDeviceXcbPresentationSupportKHR) {
- getPhysicalDeviceXcbPresentationSupportKHR =
- (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) vkGetInstanceProcAddr(instance,
- "vkGetPhysicalDeviceXcbPresentationSupportKHR");
- }
-
- ContextPlatformData_unix* unixPlatformData =
- reinterpret_cast<ContextPlatformData_unix*>(platformData);
-
- Display* display = unixPlatformData->fDisplay;
- VisualID visualID = unixPlatformData->fVisualInfo->visualid;
- VkBool32 check = getPhysicalDeviceXcbPresentationSupportKHR(physDev,
- queueFamilyIndex,
- XGetXCBConnection(display),
- visualID);
- return (VK_FALSE != check);
-}
+} // namespace VulkanWindowContextFactory
-} // namespace sk_app
+} // namespace sk_app
« no previous file with comments | « tools/viewer/sk_app/unix/GLWindowContext_unix.cpp ('k') | tools/viewer/sk_app/unix/WindowContextFactory_unix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698