Add support for creating a shared vulkan test context
authorGreg Daniel <egdaniel@google.com>
Mon, 15 May 2017 17:50:35 +0000 (13:50 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Mon, 15 May 2017 18:12:59 +0000 (18:12 +0000)
Bug: skia:
Change-Id: I997c6269e4676bf4cedddcd87e71d107053678bb
Reviewed-on: https://skia-review.googlesource.com/16905
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>

tools/gpu/GrContextFactory.cpp
tools/gpu/vk/VkTestContext.cpp
tools/gpu/vk/VkTestContext.h

index e02bc1b3712ed9e69dcaef6563361c4a580ce6f1..5aa57853b55a3c9fc3bec1e2c54cc9754b4fb82a 100644 (file)
@@ -189,16 +189,14 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
             break;
         }
 #ifdef SK_VULKAN
-        case kVulkan_GrBackend:
-            if (masterContext) {
-                // Shared contexts not supported yet
-                return ContextInfo();
-            }
+        case kVulkan_GrBackend: {
+            VkTestContext* vkSharedContext = masterContext
+                    ? static_cast<VkTestContext*>(masterContext->fTestContext) : nullptr;
             SkASSERT(kVulkan_ContextType == type);
             if (ContextOverrides::kRequireNVPRSupport & overrides) {
                 return ContextInfo();
             }
-            testCtx.reset(CreatePlatformVkTestContext());
+            testCtx.reset(CreatePlatformVkTestContext(vkSharedContext));
             if (!testCtx) {
                 return ContextInfo();
             }
@@ -214,6 +212,7 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
             }
             backendContext = testCtx->backendContext();
             break;
+        }
 #endif
         default:
             return ContextInfo();
index 0f4e508354493a55862e355d532e3017f1af52f8..125ead2033e14285cfde50a3a97ca9dc274f8b55 100644 (file)
@@ -108,9 +108,14 @@ GR_STATIC_ASSERT(sizeof(VkFence) <= sizeof(sk_gpu_test::PlatformFence));
 // TODO: Implement swap buffers and finish
 class VkTestContextImpl : public sk_gpu_test::VkTestContext {
 public:
-    static VkTestContext* Create() {
-        sk_sp<const GrVkBackendContext> backendContext(
-                GrVkBackendContext::Create(vkGetInstanceProcAddr, vkGetDeviceProcAddr));
+    static VkTestContext* Create(VkTestContext* sharedContext) {
+        sk_sp<const GrVkBackendContext> backendContext;
+        if (sharedContext) {
+            backendContext = sharedContext->getVkBackendContext();
+        } else {
+            backendContext.reset(GrVkBackendContext::Create(vkGetInstanceProcAddr,
+                                                            vkGetDeviceProcAddr));
+        }
         if (!backendContext) {
             return nullptr;
         }
@@ -147,7 +152,9 @@ private:
 }  // anonymous namespace
 
 namespace sk_gpu_test {
-VkTestContext* CreatePlatformVkTestContext() { return VkTestContextImpl::Create(); }
+VkTestContext* CreatePlatformVkTestContext(VkTestContext* sharedContext) {
+    return VkTestContextImpl::Create(sharedContext);
+}
 }  // namespace sk_gpu_test
 
 #endif
index ecec17b7dc08f6d4a31b2f128707fae1d0bd8a22..85acb0e716ffde0fb79ce95c641367e8306ae04f 100644 (file)
@@ -22,6 +22,10 @@ public:
         return reinterpret_cast<GrBackendContext>(fVk.get());
     }
 
+    sk_sp<const GrVkBackendContext> getVkBackendContext() {
+        return fVk;
+    }
+
     bool isValid() const override { return NULL != this->vk(); }
 
     const GrVkInterface* vk() const { return fVk->fInterface.get(); }
@@ -38,7 +42,7 @@ private:
 /**
  * Creates Vk context object bound to the native Vk library.
  */
-VkTestContext* CreatePlatformVkTestContext();
+VkTestContext* CreatePlatformVkTestContext(VkTestContext*);
 
 }  // namespace sk_gpu_test