aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-06-14 09:31:11 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-14 13:54:47 +0000
commit10a83da287be541c2253bec23a92f1e5e1a79ff3 (patch)
treec11c1c209c0e700b1c93c03b1262fe36e72cf5ef
parente6f2ecafaf0efecacfd4256f280e26ee74cb7e16 (diff)
Add GrContext::MakeVulkan factory that doesn't take a ref'd GrVkBackendContext.
This is the first step towards removing the ref counted ness of GrVkBackendContext. Bug: skia: Change-Id: I38f8861dd093a6a6098dd2e421c26c41185320f7 Reviewed-on: https://skia-review.googlesource.com/134783 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
-rw-r--r--include/gpu/GrContext.h4
-rw-r--r--src/gpu/GrDirectContext.cpp36
2 files changed, 40 insertions, 0 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 525e5d77b8..5a2ba4780f 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -68,6 +68,10 @@ public:
static sk_sp<GrContext> MakeGL();
#ifdef SK_VULKAN
+ static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&);
+ static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&);
+ // These calls that take an sk_sp GrVkBackendContext are deprecated. Use the previous calls and
+ // set fOwnsInstanceAndDevice to false on the GrVkBackendContext.
static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>, const GrContextOptions&);
static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>);
#endif
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index 8e214db74f..d0406dd6f6 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -147,6 +147,42 @@ sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions,
}
#ifdef SK_VULKAN
+sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext& backendContext) {
+ GrContextOptions defaultOptions;
+ return MakeVulkan(backendContext, defaultOptions);
+}
+
+sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext& backendContext,
+ const GrContextOptions& options) {
+ sk_sp<GrContext> context(new GrDirectContext(kVulkan_GrBackend));
+
+ sk_sp<GrVkBackendContext> backendContextRef(new GrVkBackendContext());
+ backendContextRef->fInstance = backendContext.fInstance;
+ backendContextRef->fPhysicalDevice = backendContext.fPhysicalDevice;
+ backendContextRef->fDevice = backendContext.fDevice;
+ backendContextRef->fQueue = backendContext.fQueue;
+ backendContextRef->fGraphicsQueueIndex = backendContext.fGraphicsQueueIndex;
+ backendContextRef->fMinAPIVersion = backendContext.fMinAPIVersion;
+ backendContextRef->fExtensions = backendContext.fExtensions;
+ backendContextRef->fFeatures = backendContext.fFeatures;
+ backendContextRef->fInterface = backendContext.fInterface;
+ backendContextRef->fMemoryAllocator = backendContext.fMemoryAllocator;
+
+ SkASSERT(!backendContext.fOwnsInstanceAndDevice);
+ backendContextRef->fOwnsInstanceAndDevice = false;
+
+ context->fGpu = GrVkGpu::Make(std::move(backendContextRef), options, context.get());
+ if (!context->fGpu) {
+ return nullptr;
+ }
+
+ context->fCaps = context->fGpu->refCaps();
+ if (!context->init(options)) {
+ return nullptr;
+ }
+ return context;
+}
+
sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext) {
GrContextOptions defaultOptions;
return MakeVulkan(std::move(backendContext), defaultOptions);