aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-12-07 12:33:05 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-07 17:56:59 +0000
commit384fab467e2a5f1754ec26eecde946ce28046d20 (patch)
treec19ad170f2932c666c937736be71237c335e79b3 /src/gpu
parent1cfb6bc9b63e9840d198a1ea8b1a20da2bfde818 (diff)
sk_spification of GrGpu creation.
Make GrContext::MakeGL take interface as sk_sp. Make GrContext::MakeVulkan take GrVkBackendContext as sk_sp. Change-Id: I13c22a57bd281c51738f503d9ed3418d35a466df Reviewed-on: https://skia-review.googlesource.com/81842 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp26
-rw-r--r--src/gpu/GrGpu.h3
-rw-r--r--src/gpu/GrGpuFactory.cpp14
-rw-r--r--src/gpu/gl/GrGLGpu.cpp29
-rw-r--r--src/gpu/gl/GrGLGpu.h8
-rw-r--r--src/gpu/mock/GrMockGpu.cpp12
-rw-r--r--src/gpu/mock/GrMockGpu.h4
-rw-r--r--src/gpu/mtl/GrMtlGpu.h4
-rw-r--r--src/gpu/mtl/GrMtlGpu.mm6
-rw-r--r--src/gpu/mtl/GrMtlTrampoline.h9
-rw-r--r--src/gpu/mtl/GrMtlTrampoline.mm16
-rw-r--r--src/gpu/vk/GrVkGpu.cpp45
-rw-r--r--src/gpu/vk/GrVkGpu.h10
13 files changed, 91 insertions, 95 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 2b185c4ebc..e8f5c4b889 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -75,15 +75,15 @@ GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext,
return context.release();
}
-sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface) {
+sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface) {
GrContextOptions defaultOptions;
- return MakeGL(interface, defaultOptions);
+ return MakeGL(std::move(interface), defaultOptions);
}
-sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface,
+sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface,
const GrContextOptions& options) {
sk_sp<GrContext> context(new GrContext);
- context->fGpu = GrGLGpu::Create(interface, options, context.get());
+ context->fGpu = GrGLGpu::Make(std::move(interface), options, context.get());
if (!context->fGpu) {
return nullptr;
}
@@ -102,7 +102,7 @@ sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) {
sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions,
const GrContextOptions& options) {
sk_sp<GrContext> context(new GrContext);
- context->fGpu = GrMockGpu::Create(mockOptions, options, context.get());
+ context->fGpu = GrMockGpu::Make(mockOptions, options, context.get());
if (!context->fGpu) {
return nullptr;
}
@@ -114,15 +114,15 @@ sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions,
}
#ifdef SK_VULKAN
-sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext* backendContext) {
+sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext) {
GrContextOptions defaultOptions;
- return MakeVulkan(backendContext, defaultOptions);
+ return MakeVulkan(std::move(backendContext), defaultOptions);
}
-sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext* backendContext,
+sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext,
const GrContextOptions& options) {
sk_sp<GrContext> context(new GrContext);
- context->fGpu = GrVkGpu::Create(backendContext, options, context.get());
+ context->fGpu = GrVkGpu::Make(std::move(backendContext), options, context.get());
if (!context->fGpu) {
return nullptr;
}
@@ -142,7 +142,7 @@ sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue) {
sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContextOptions& options) {
sk_sp<GrContext> context(new GrContext);
- context->fGpu = GrMtlTrampoline::CreateGpu(context.get(), options, device, queue);
+ context->fGpu = GrMtlTrampoline::MakeGpu(context.get(), options, device, queue);
if (!context->fGpu) {
return nullptr;
}
@@ -164,7 +164,6 @@ static int32_t next_id() {
}
GrContext::GrContext() : fUniqueID(next_id()) {
- fGpu = nullptr;
fCaps = nullptr;
fResourceCache = nullptr;
fResourceProvider = nullptr;
@@ -178,7 +177,7 @@ bool GrContext::init(GrBackend backend, GrBackendContext backendContext,
fBackend = backend;
- fGpu = GrGpu::Create(backend, backendContext, options, this);
+ fGpu = GrGpu::Make(backend, backendContext, options, this);
if (!fGpu) {
return false;
}
@@ -189,7 +188,7 @@ bool GrContext::init(const GrContextOptions& options) {
ASSERT_SINGLE_OWNER
fCaps = SkRef(fGpu->caps());
fResourceCache = new GrResourceCache(fCaps, fUniqueID);
- fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwner);
+ fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, &fSingleOwner);
fDisableGpuYUVConversion = options.fDisableGpuYUVConversion;
fDidTestPMConversions = false;
@@ -261,7 +260,6 @@ GrContext::~GrContext() {
delete fResourceCache;
delete fAtlasGlyphCache;
- fGpu->unref();
fCaps->unref();
}
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 676b3b0811..18ea772f23 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -55,7 +55,8 @@ public:
* not supported (at compile-time or run-time) this returns nullptr. The context will not be
* fully constructed and should not be used by GrGpu until after this function returns.
*/
- static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context);
+ static sk_sp<GrGpu> Make(GrBackend, GrBackendContext, const GrContextOptions&,
+ GrContext* context);
////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrGpuFactory.cpp b/src/gpu/GrGpuFactory.cpp
index 1fc19c144a..eb3c2928b6 100644
--- a/src/gpu/GrGpuFactory.cpp
+++ b/src/gpu/GrGpuFactory.cpp
@@ -13,19 +13,19 @@
#include "vk/GrVkGpu.h"
#endif
-GrGpu* GrGpu::Create(GrBackend backend,
- GrBackendContext backendContext,
- const GrContextOptions& options,
- GrContext* context) {
+sk_sp<GrGpu> GrGpu::Make(GrBackend backend,
+ GrBackendContext backendContext,
+ const GrContextOptions& options,
+ GrContext* context) {
switch (backend) {
case kOpenGL_GrBackend:
- return GrGLGpu::Create(backendContext, options, context);
+ return GrGLGpu::Make(backendContext, options, context);
#ifdef SK_VULKAN
case kVulkan_GrBackend:
- return GrVkGpu::Create(backendContext, options, context);
+ return GrVkGpu::Make(backendContext, options, context);
#endif
case kMock_GrBackend:
- return GrMockGpu::Create(backendContext, options, context);
+ return GrMockGpu::Make(backendContext, options, context);
default:
return nullptr;
}
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 8bf6389fb6..33096160a4 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -182,29 +182,26 @@ bool GrGLGpu::BlendCoeffReferencesConstant(GrBlendCoeff coeff) {
///////////////////////////////////////////////////////////////////////////////
-
-GrGpu* GrGLGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
- GrContext* context) {
- return Create(reinterpret_cast<const GrGLInterface*>(backendContext), options, context);
+sk_sp<GrGpu> GrGLGpu::Make(GrBackendContext backendContext, const GrContextOptions& options,
+ GrContext* context) {
+ const auto* interface = reinterpret_cast<const GrGLInterface*>(backendContext);
+ return Make(sk_ref_sp(interface), options, context);
}
-GrGpu* GrGLGpu::Create(const GrGLInterface* interface, const GrContextOptions& options,
- GrContext* context) {
- sk_sp<const GrGLInterface> glInterface(interface);
- if (!glInterface) {
- glInterface.reset(GrGLDefaultInterface());
- } else {
- glInterface->ref();
- }
- if (!glInterface) {
- return nullptr;
+sk_sp<GrGpu> GrGLGpu::Make(sk_sp<const GrGLInterface> interface, const GrContextOptions& options,
+ GrContext* context) {
+ if (!interface) {
+ interface.reset(GrGLDefaultInterface());
+ if (!interface) {
+ return nullptr;
+ }
}
#ifdef USE_NSIGHT
const_cast<GrContextOptions&>(options).fSuppressPathRendering = true;
#endif
- GrGLContext* glContext = GrGLContext::Create(glInterface.get(), options);
+ GrGLContext* glContext = GrGLContext::Create(interface.get(), options);
if (glContext) {
- return new GrGLGpu(glContext, context);
+ return sk_sp<GrGpu>(new GrGLGpu(glContext, context));
}
return nullptr;
}
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 4d8b056bc7..5c26924dec 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -36,10 +36,10 @@ namespace gr_instanced { class GLInstancedRendering; }
class GrGLGpu final : public GrGpu, private GrMesh::SendToGpuImpl {
public:
- static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
- GrContext* context);
- static GrGpu* Create(const GrGLInterface*, const GrContextOptions& options,
- GrContext* context);
+ static sk_sp<GrGpu> Make(GrBackendContext backendContext, const GrContextOptions& options,
+ GrContext* context);
+ static sk_sp<GrGpu> Make(sk_sp<const GrGLInterface>, const GrContextOptions& options,
+ GrContext* context);
~GrGLGpu() override;
void disconnect(DisconnectType) override;
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index a21991fabe..5969f2f1d2 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -24,18 +24,18 @@ int GrMockGpu::NextExternalTextureID() {
return sk_atomic_dec(&gID) - 1;
}
-GrGpu* GrMockGpu::Create(GrBackendContext backendContext, const GrContextOptions& contextOptions,
- GrContext* context) {
- return Create(reinterpret_cast<const GrMockOptions*>(backendContext), contextOptions, context);
+sk_sp<GrGpu> GrMockGpu::Make(GrBackendContext backendContext,
+ const GrContextOptions& contextOptions, GrContext* context) {
+ return Make(reinterpret_cast<const GrMockOptions*>(backendContext), contextOptions, context);
}
-GrGpu* GrMockGpu::Create(const GrMockOptions* mockOptions, const GrContextOptions& contextOptions,
- GrContext* context) {
+sk_sp<GrGpu> GrMockGpu::Make(const GrMockOptions* mockOptions,
+ const GrContextOptions& contextOptions, GrContext* context) {
static const GrMockOptions kDefaultOptions = GrMockOptions();
if (!mockOptions) {
mockOptions = &kDefaultOptions;
}
- return new GrMockGpu(context, *mockOptions, contextOptions);
+ return sk_sp<GrGpu>(new GrMockGpu(context, *mockOptions, contextOptions));
}
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 574906ea3d..49a52ff183 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -20,8 +20,8 @@ class GrPipeline;
class GrMockGpu : public GrGpu {
public:
- static GrGpu* Create(GrBackendContext, const GrContextOptions&, GrContext*);
- static GrGpu* Create(const GrMockOptions*, const GrContextOptions&, GrContext*);
+ static sk_sp<GrGpu> Make(GrBackendContext, const GrContextOptions&, GrContext*);
+ static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrContext*);
~GrMockGpu() override {}
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index fb2c368102..cb2744f0aa 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -22,8 +22,8 @@ struct GrMtlBackendContext;
class GrMtlGpu : public GrGpu {
public:
- static GrGpu* Create(GrContext* context, const GrContextOptions& options,
- id<MTLDevice> device, id<MTLCommandQueue> queue);
+ static sk_sp<GrGpu> Make(GrContext* context, const GrContextOptions& options,
+ id<MTLDevice> device, id<MTLCommandQueue> queue);
~GrMtlGpu() override {}
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index a830959bdd..149e56220e 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -69,8 +69,8 @@ static bool get_feature_set(id<MTLDevice> device, MTLFeatureSet* featureSet) {
return false;
}
-GrGpu* GrMtlGpu::Create(GrContext* context, const GrContextOptions& options,
- id<MTLDevice> device, id<MTLCommandQueue> queue) {
+sk_sp<GrGpu> GrMtlGpu::Make(GrContext* context, const GrContextOptions& options,
+ id<MTLDevice> device, id<MTLCommandQueue> queue) {
if (!device || !queue) {
return nullptr;
}
@@ -78,7 +78,7 @@ GrGpu* GrMtlGpu::Create(GrContext* context, const GrContextOptions& options,
if (!get_feature_set(device, &featureSet)) {
return nullptr;
}
- return new GrMtlGpu(context, options, device, queue, featureSet);
+ return sk_sp<GrGpu>(new GrMtlGpu(context, options, device, queue, featureSet));
}
GrMtlGpu::GrMtlGpu(GrContext* context, const GrContextOptions& options,
diff --git a/src/gpu/mtl/GrMtlTrampoline.h b/src/gpu/mtl/GrMtlTrampoline.h
index 531a4ce00c..29a5bf3a1e 100644
--- a/src/gpu/mtl/GrMtlTrampoline.h
+++ b/src/gpu/mtl/GrMtlTrampoline.h
@@ -9,6 +9,7 @@
#define GrMtlTrampoline_DEFINED
#include "GrTypes.h"
+#include "SkRefCnt.h"
class GrContext;
class GrGpu;
@@ -20,10 +21,10 @@ struct GrContextOptions;
*/
class GrMtlTrampoline {
public:
- static GrGpu* CreateGpu(GrContext* context,
- const GrContextOptions& options,
- void* device,
- void* queue);
+ static sk_sp<GrGpu> MakeGpu(GrContext* context,
+ const GrContextOptions& options,
+ void* device,
+ void* queue);
};
#endif
diff --git a/src/gpu/mtl/GrMtlTrampoline.mm b/src/gpu/mtl/GrMtlTrampoline.mm
index 0f112e4da5..516ac52fe0 100644
--- a/src/gpu/mtl/GrMtlTrampoline.mm
+++ b/src/gpu/mtl/GrMtlTrampoline.mm
@@ -9,13 +9,13 @@
#include "GrMtlGpu.h"
-GrGpu* GrMtlTrampoline::CreateGpu(GrContext* context,
- const GrContextOptions& options,
- void* device,
- void* queue) {
- return GrMtlGpu::Create(context,
- options,
- (__bridge_transfer id<MTLDevice>)device,
- (__bridge_transfer id<MTLCommandQueue>)queue);
+sk_sp<GrGpu> GrMtlTrampoline::MakeGpu(GrContext* context,
+ const GrContextOptions& options,
+ void* device,
+ void* queue) {
+ return GrMtlGpu::Make(context,
+ options,
+ (__bridge_transfer id<MTLDevice>)device,
+ (__bridge_transfer id<MTLCommandQueue>)queue);
}
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index a87c344d9a..0a642346f2 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -73,40 +73,38 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(
}
#endif
-GrGpu* GrVkGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
- GrContext* context) {
- return Create(reinterpret_cast<const GrVkBackendContext*>(backendContext), options, context);
+sk_sp<GrGpu> GrVkGpu::Make(GrBackendContext backendContext, const GrContextOptions& options,
+ GrContext* context) {
+ const auto* backend = reinterpret_cast<const GrVkBackendContext*>(backendContext);
+ return Make(sk_ref_sp(backend), options, context);
}
-GrGpu* GrVkGpu::Create(const GrVkBackendContext* backendContext, const GrContextOptions& options,
- GrContext* context) {
+sk_sp<GrGpu> GrVkGpu::Make(sk_sp<const GrVkBackendContext> backendContext,
+ const GrContextOptions& options, GrContext* context) {
if (!backendContext) {
return nullptr;
- } else {
- backendContext->ref();
}
if (!backendContext->fInterface->validate(backendContext->fExtensions)) {
return nullptr;
}
- return new GrVkGpu(context, options, backendContext);
+ return sk_sp<GrGpu>(new GrVkGpu(context, options, std::move(backendContext)));
}
////////////////////////////////////////////////////////////////////////////////
GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options,
- const GrVkBackendContext* backendCtx)
- : INHERITED(context)
- , fDevice(backendCtx->fDevice)
- , fQueue(backendCtx->fQueue)
- , fResourceProvider(this)
- , fDisconnected(false) {
- fBackendContext.reset(backendCtx);
-
+ sk_sp<const GrVkBackendContext> backendCtx)
+ : INHERITED(context)
+ , fBackendContext(std::move(backendCtx))
+ , fDevice(fBackendContext->fDevice)
+ , fQueue(fBackendContext->fQueue)
+ , fResourceProvider(this)
+ , fDisconnected(false) {
#ifdef SK_ENABLE_VK_LAYERS
fCallback = VK_NULL_HANDLE;
- if (backendCtx->fExtensions & kEXT_debug_report_GrVkExtensionFlag) {
+ if (fBackendContext->fExtensions & kEXT_debug_report_GrVkExtensionFlag) {
// Setup callback creation information
VkDebugReportCallbackCreateInfoEXT callbackCreateInfo;
callbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
@@ -120,25 +118,26 @@ GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options,
callbackCreateInfo.pUserData = nullptr;
// Register the callback
- GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateDebugReportCallbackEXT(
- backendCtx->fInstance, &callbackCreateInfo, nullptr, &fCallback));
+ GR_VK_CALL_ERRCHECK(this->vkInterface(),
+ CreateDebugReportCallbackEXT(fBackendContext->fInstance,
+ &callbackCreateInfo, nullptr, &fCallback));
}
#endif
fCompiler = new SkSL::Compiler();
- fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), backendCtx->fPhysicalDevice,
- backendCtx->fFeatures, backendCtx->fExtensions));
+ fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), fBackendContext->fPhysicalDevice,
+ fBackendContext->fFeatures, fBackendContext->fExtensions));
fCaps.reset(SkRef(fVkCaps.get()));
- VK_CALL(GetPhysicalDeviceMemoryProperties(backendCtx->fPhysicalDevice, &fPhysDevMemProps));
+ VK_CALL(GetPhysicalDeviceMemoryProperties(fBackendContext->fPhysicalDevice, &fPhysDevMemProps));
const VkCommandPoolCreateInfo cmdPoolInfo = {
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType
nullptr, // pNext
VK_COMMAND_POOL_CREATE_TRANSIENT_BIT |
VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // CmdPoolCreateFlags
- backendCtx->fGraphicsQueueIndex, // queueFamilyIndex
+ fBackendContext->fGraphicsQueueIndex, // queueFamilyIndex
};
GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateCommandPool(fDevice, &cmdPoolInfo, nullptr,
&fCmdPool));
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 1d2aca3673..8e6f39195a 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -38,10 +38,10 @@ namespace SkSL {
class GrVkGpu : public GrGpu {
public:
- static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
- GrContext* context);
- static GrGpu* Create(const GrVkBackendContext*, const GrContextOptions& options,
- GrContext* context);
+ static sk_sp<GrGpu> Make(GrBackendContext backendContext, const GrContextOptions& options,
+ GrContext* context);
+ static sk_sp<GrGpu> Make(sk_sp<const GrVkBackendContext>, const GrContextOptions& options,
+ GrContext* context);
~GrVkGpu() override;
@@ -174,7 +174,7 @@ public:
private:
GrVkGpu(GrContext* context, const GrContextOptions& options,
- const GrVkBackendContext* backendContext);
+ sk_sp<const GrVkBackendContext> backendContext);
void onResetContext(uint32_t resetBits) override {}