aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/GrResourceCacheBench.cpp4
-rw-r--r--debugger/QT/SkGLWidget.cpp2
-rw-r--r--example/HelloWorld.cpp2
-rw-r--r--example/SkiaSDLExample.cpp3
-rw-r--r--experimental/GLFWTest/glfw_main.cpp4
-rw-r--r--experimental/SkV8Example/SkV8Example.cpp3
-rw-r--r--experimental/iOSSampleApp/SkSampleUIView.mm3
-rw-r--r--include/gpu/GrContext.h17
-rw-r--r--include/gpu/gl/GrGLInterface.h4
-rw-r--r--samplecode/SampleApp.cpp3
-rw-r--r--site/user/api/canvas.md2
-rw-r--r--site/user/special/vulkan.md4
-rw-r--r--src/gpu/GrContext.cpp69
-rw-r--r--src/gpu/gl/GrGLGpu.cpp8
-rw-r--r--src/gpu/gl/GrGLGpu.h2
-rw-r--r--src/gpu/mock/GrMockGpu.cpp13
-rw-r--r--src/gpu/mock/GrMockGpu.h1
-rw-r--r--src/gpu/vk/GrVkGpu.cpp15
-rw-r--r--src/gpu/vk/GrVkGpu.h2
-rw-r--r--tests/EGLImageTest.cpp8
-rw-r--r--tests/GpuSampleLocationsTest.cpp2
-rw-r--r--tests/ResourceCacheTest.cpp2
-rw-r--r--tools/fiddle/egl_context.cpp2
-rw-r--r--tools/fiddle/mesa_context.cpp4
-rw-r--r--tools/gpu/GrContextFactory.cpp9
-rw-r--r--tools/gpu/gl/GLTestContext.cpp6
-rw-r--r--tools/gpu/gl/GLTestContext.h2
-rw-r--r--tools/gpu/mock/MockTestContext.cpp6
-rw-r--r--tools/gpu/vk/VkTestContext.cpp5
-rw-r--r--tools/viewer/sk_app/GLWindowContext.cpp10
-rw-r--r--tools/viewer/sk_app/VulkanWindowContext.cpp7
-rw-r--r--tools/viewer/sk_app/WindowContext.h6
32 files changed, 166 insertions, 64 deletions
diff --git a/bench/GrResourceCacheBench.cpp b/bench/GrResourceCacheBench.cpp
index 9c9ca3551a..d78af0a9e5 100644
--- a/bench/GrResourceCacheBench.cpp
+++ b/bench/GrResourceCacheBench.cpp
@@ -69,7 +69,7 @@ protected:
}
void onDraw(int loops, SkCanvas* canvas) override {
- sk_sp<GrContext> context(GrContext::Create(kMock_GrBackend, (GrBackendContext) nullptr));
+ sk_sp<GrContext> context(GrContext::MakeMock(nullptr));
if (nullptr == context) {
return;
}
@@ -115,7 +115,7 @@ protected:
}
void onDelayedSetup() override {
- fContext.reset(GrContext::Create(kMock_GrBackend, (GrBackendContext) nullptr));
+ fContext = GrContext::MakeMock(nullptr);
if (!fContext) {
return;
}
diff --git a/debugger/QT/SkGLWidget.cpp b/debugger/QT/SkGLWidget.cpp
index a60ae0f0ba..0c65be03b5 100644
--- a/debugger/QT/SkGLWidget.cpp
+++ b/debugger/QT/SkGLWidget.cpp
@@ -42,7 +42,7 @@ void SkGLWidget::initializeGL() {
fGpuSurface = nullptr;
fCanvas = nullptr;
- fCurContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf.get()));
+ fCurContext = GrContext::MakeGL(fCurIntf.get());
}
void SkGLWidget::createRenderTarget() {
diff --git a/example/HelloWorld.cpp b/example/HelloWorld.cpp
index 464ec4429d..2375e0016f 100644
--- a/example/HelloWorld.cpp
+++ b/example/HelloWorld.cpp
@@ -70,7 +70,7 @@ bool HelloWorldWindow::setUpBackend() {
fInterface = GrGLCreateNativeInterface();
SkASSERT(NULL != fInterface);
- fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInterface);
+ fContext = GrContext::MakeGL(fInterface).release();
SkASSERT(NULL != fContext);
this->setUpGpuBackedSurface();
diff --git a/example/SkiaSDLExample.cpp b/example/SkiaSDLExample.cpp
index 813485f8a3..3c4dccccb2 100644
--- a/example/SkiaSDLExample.cpp
+++ b/example/SkiaSDLExample.cpp
@@ -187,8 +187,7 @@ int main(int argc, char** argv) {
sk_sp<const GrGLInterface> interface(GrGLCreateNativeInterface());
// setup contexts
- sk_sp<GrContext> grContext(GrContext::Create(kOpenGL_GrBackend,
- (GrBackendContext)interface.get()));
+ sk_sp<GrContext> grContext(GrContext::MakeGL(interface.get()));
SkASSERT(grContext);
// Wrap the frame buffer object attached to the screen in a Skia render target so Skia can
diff --git a/experimental/GLFWTest/glfw_main.cpp b/experimental/GLFWTest/glfw_main.cpp
index 63ea1f1d9f..6b8412ce9b 100644
--- a/experimental/GLFWTest/glfw_main.cpp
+++ b/experimental/GLFWTest/glfw_main.cpp
@@ -31,8 +31,8 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
static void init_skia(int w, int h) {
- sContext = GrContext::Create(kOpenGL_GrBackend, 0);
-
+ sContext = GrContext::MakeGL(nullptr).release();
+
GrBackendRenderTargetDesc desc;
desc.fWidth = w;
desc.fHeight = h;
diff --git a/experimental/SkV8Example/SkV8Example.cpp b/experimental/SkV8Example/SkV8Example.cpp
index a6a2a7e816..ca63e071b7 100644
--- a/experimental/SkV8Example/SkV8Example.cpp
+++ b/experimental/SkV8Example/SkV8Example.cpp
@@ -78,8 +78,7 @@ void SkV8ExampleWindow::windowSizeChanged() {
}
fCurIntf = GrGLCreateNativeInterface();
- fCurContext = GrContext::Create(
- kOpenGL_GrBackend, (GrBackendContext) fCurIntf);
+ fCurContext = GrContext::MakeGL(fCurIntf).release();
if (NULL == fCurIntf || NULL == fCurContext) {
printf("Failed to initialize GL.");
exit(1);
diff --git a/experimental/iOSSampleApp/SkSampleUIView.mm b/experimental/iOSSampleApp/SkSampleUIView.mm
index b1e04873cd..39eef5647c 100644
--- a/experimental/iOSSampleApp/SkSampleUIView.mm
+++ b/experimental/iOSSampleApp/SkSampleUIView.mm
@@ -89,8 +89,7 @@ public:
SkASSERT(NULL == fCurContext);
if (SkOSWindow::kNone_BackEndType != fBackend) {
- fCurContext = GrContext::Create(kOpenGL_GrBackend,
- (GrBackendContext) fCurIntf);
+ fCurContext = GrContext::MakeGL(fCurIntf).release();
}
if ((NULL == fCurContext || NULL == fCurIntf) &&
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index f48b8db710..b5d2f741ef 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -22,12 +22,14 @@ class GrContextPriv;
class GrContextThreadSafeProxy;
class GrDrawingManager;
struct GrDrawOpAtlasConfig;
-class GrRenderTargetContext;
class GrFragmentProcessor;
+struct GrGLInterface;
class GrGpu;
class GrIndexBuffer;
+struct GrMockOptions;
class GrOvalRenderer;
class GrPath;
+class GrRenderTargetContext;
class GrResourceEntry;
class GrResourceCache;
class GrResourceProvider;
@@ -37,6 +39,7 @@ class GrTextBlobCache;
class GrTextContext;
class GrTextureProxy;
class GrVertexBuffer;
+struct GrVkBackendContext;
class GrSwizzle;
class SkTraceMemoryDump;
@@ -51,6 +54,14 @@ public:
static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options);
static GrContext* Create(GrBackend, GrBackendContext);
+ static sk_sp<GrContext> MakeGL(const GrGLInterface*, const GrContextOptions&);
+ static sk_sp<GrContext> MakeGL(const GrGLInterface*);
+
+#ifdef SK_VULKAN
+ static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext*, const GrContextOptions&);
+ static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext*);
+#endif
+
#ifdef SK_METAL
/**
* Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice
@@ -59,8 +70,12 @@ public:
* GrContext is destroyed.
*/
static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options);
+ static sk_sp<GrContext> MakeMetal(void* device, void* queue);
#endif
+ static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
+ static sk_sp<GrContext> MakeMock(const GrMockOptions*);
+
virtual ~GrContext();
sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
diff --git a/include/gpu/gl/GrGLInterface.h b/include/gpu/gl/GrGLInterface.h
index 56e655d887..f1785326fb 100644
--- a/include/gpu/gl/GrGLInterface.h
+++ b/include/gpu/gl/GrGLInterface.h
@@ -17,8 +17,8 @@
/**
* Rather than depend on platform-specific GL headers and libraries, we require
* the client to provide a struct of GL function pointers. This struct can be
- * specified per-GrContext as a parameter to GrContext::Create. If NULL is
- * passed to Create then a "default" GL interface is created. If the default is
+ * specified per-GrContext as a parameter to GrContext::MakeGL. If NULL is
+ * passed to MakeGL then a "default" GL interface is created. If the default is
* also NULL GrContext creation will fail.
*
* The default interface is returned by GrGLDefaultInterface. This function's
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 1676fc3b13..c36e2e8604 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -276,8 +276,7 @@ public:
}
SkASSERT(nullptr == fCurContext);
- fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf,
- backendOptions.fGrContextOptions);
+ fCurContext = GrContext::MakeGL(fCurIntf, backendOptions.fGrContextOptions).release();
if (nullptr == fCurContext || nullptr == fCurIntf) {
// We need some context and interface to see results
diff --git a/site/user/api/canvas.md b/site/user/api/canvas.md
index d9e15592dc..d6aa7b6b7c 100644
--- a/site/user/api/canvas.md
+++ b/site/user/api/canvas.md
@@ -98,7 +98,7 @@ has been made current to the current thread when Skia calls are made.
// context in a platform-specific way. Alternatively, you may create your own GrGLInterface and
// initialize it however you like to attach to an alternate OpenGL implementation or intercept
// Skia's OpenGL calls.
- GrContext* context = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) interface);
+ sk_sp<GrContext> context = GrContext::MakeGL(interface);
SkImageInfo info = SkImageInfo:: MakeN32Premul(width, height);
sk_sp<SkSurface> gpuSurface(
SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
diff --git a/site/user/special/vulkan.md b/site/user/special/vulkan.md
index 8dfd26a46b..5b5c2d93f3 100644
--- a/site/user/special/vulkan.md
+++ b/site/user/special/vulkan.md
@@ -21,7 +21,7 @@ To build the Vulkan backend, set `ndk_api = 24` in `args.gn` to target Android N
Using the Vulkan Backend
------------------------
-To create a GrContext that is backed by Vulkan the client creates a Vulkan device and queue, initializes a GrVkBackendContext to describe the context, and then calls GrContext::Create:
+To create a GrContext that is backed by Vulkan the client creates a Vulkan device and queue, initializes a GrVkBackendContext to describe the context, and then calls GrContext::MakeVulkan:
<!--?prettify lang=c++?-->
sk_sp<GrVkBackendContext> vkContext = new GrVkBackendContext;
@@ -31,7 +31,7 @@ To create a GrContext that is backed by Vulkan the client creates a Vulkan devic
vkBackendContext.fInterface.reset(GrVkCreateInterface(instance, vkPhysDevice, extensionFlags);
...
- sk_sp<GrContext> context = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) vkBackendContext);
+ sk_sp<GrContext> context = GrContext::MakeVulkan(vkBackendContext);
When using the Vulkan backend the GrBackendObject field in
GrBackendRenderTargetDesc and GrBackendTextureDesc is interpeted as a pointer
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 88fe379c37..19343ac73c 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -29,9 +29,14 @@
#include "effects/GrConfigConversionEffect.h"
#include "text/GrTextBlobCache.h"
+#include "gl/GrGLGpu.h"
+#include "mock/GrMockGpu.h"
#ifdef SK_METAL
#include "mtl/GrMtlTrampoline.h"
#endif
+#ifdef SK_VULKAN
+#include "vk/GrVkGpu.h"
+#endif
#define ASSERT_OWNED_PROXY(P) \
SkASSERT(!(P) || !((P)->priv().peekTexture()) || (P)->priv().peekTexture()->getContext() == this)
@@ -66,7 +71,71 @@ GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext,
return context.release();
}
+sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface) {
+ GrContextOptions defaultOptions;
+ return MakeGL(interface, defaultOptions);
+}
+
+sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface,
+ const GrContextOptions& options) {
+ sk_sp<GrContext> context(new GrContext);
+ context->fGpu = GrGLGpu::Create(interface, options, context.get());
+ if (!context->fGpu) {
+ return nullptr;
+ }
+ context->fBackend = kOpenGL_GrBackend;
+ if (!context->init(options)) {
+ return nullptr;
+ }
+ return context;
+}
+
+sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions) {
+ GrContextOptions defaultOptions;
+ return MakeMock(mockOptions, defaultOptions);
+}
+
+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());
+ if (!context->fGpu) {
+ return nullptr;
+ }
+ context->fBackend = kMock_GrBackend;
+ if (!context->init(options)) {
+ return nullptr;
+ }
+ return context;
+}
+
+#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 GrContext);
+ context->fGpu = GrVkGpu::Create(backendContext, options, context.get());
+ if (!context->fGpu) {
+ return nullptr;
+ }
+ context->fBackend = kVulkan_GrBackend;
+ if (!context->init(options)) {
+ return nullptr;
+ }
+ return context;
+}
+#endif
+
#ifdef SK_METAL
+sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue) {
+ GrContextOptions defaultOptions;
+ return MakeMetal(device, queue, defaultOptions);
+}
+
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);
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 49be761350..0bab551bc5 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -184,8 +184,12 @@ bool GrGLGpu::BlendCoeffReferencesConstant(GrBlendCoeff coeff) {
GrGpu* GrGLGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
GrContext* context) {
- sk_sp<const GrGLInterface> glInterface(
- reinterpret_cast<const GrGLInterface*>(backendContext));
+ return Create(reinterpret_cast<const GrGLInterface*>(backendContext), 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 {
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 9b6e004bd5..5acf806c7d 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -38,6 +38,8 @@ 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);
~GrGLGpu() override;
void disconnect(DisconnectType) override;
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index 1778ee2ba5..614e627867 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -26,14 +26,19 @@ int GrMockGpu::NextExternalTextureID() {
GrGpu* GrMockGpu::Create(GrBackendContext backendContext, const GrContextOptions& contextOptions,
GrContext* context) {
+ return Create(reinterpret_cast<const GrMockOptions*>(backendContext), contextOptions, context);
+}
+
+GrGpu* GrMockGpu::Create(const GrMockOptions* mockOptions, const GrContextOptions& contextOptions,
+ GrContext* context) {
static const GrMockOptions kDefaultOptions = GrMockOptions();
- const GrMockOptions* options = reinterpret_cast<const GrMockOptions*>(backendContext);
- if (!options) {
- options = &kDefaultOptions;
+ if (!mockOptions) {
+ mockOptions = &kDefaultOptions;
}
- return new GrMockGpu(context, *options, contextOptions);
+ return new GrMockGpu(context, *mockOptions, contextOptions);
}
+
GrGpuCommandBuffer* GrMockGpu::createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
const GrGpuCommandBuffer::LoadAndStoreInfo&) {
return new GrMockGpuCommandBuffer(this);
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index e31570ad07..d29d4cfa04 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -20,6 +20,7 @@ class GrPipeline;
class GrMockGpu : public GrGpu {
public:
static GrGpu* Create(GrBackendContext, const GrContextOptions&, GrContext*);
+ static GrGpu* Create(const GrMockOptions*, const GrContextOptions&, GrContext*);
~GrMockGpu() override {}
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index d7094b7c18..d1e535ea6a 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -76,19 +76,22 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(
GrGpu* GrVkGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
GrContext* context) {
- const GrVkBackendContext* vkBackendContext =
- reinterpret_cast<const GrVkBackendContext*>(backendContext);
- if (!vkBackendContext) {
+ return Create(reinterpret_cast<const GrVkBackendContext*>(backendContext), options, context);
+}
+
+GrGpu* GrVkGpu::Create(const GrVkBackendContext* backendContext, const GrContextOptions& options,
+ GrContext* context) {
+ if (!backendContext) {
return nullptr;
} else {
- vkBackendContext->ref();
+ backendContext->ref();
}
- if (!vkBackendContext->fInterface->validate(vkBackendContext->fExtensions)) {
+ if (!backendContext->fInterface->validate(backendContext->fExtensions)) {
return nullptr;
}
- return new GrVkGpu(context, options, vkBackendContext);
+ return new GrVkGpu(context, options, backendContext);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 419e9e3ad6..7e95ca4d89 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -40,6 +40,8 @@ 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);
~GrVkGpu() override;
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 84a6bfdb7f..784ec5d99e 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -21,8 +21,9 @@
using sk_gpu_test::GLTestContext;
-static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx1, GrContext* grctx1,
- const GrGLTextureInfo* grbackendtex1, GrEGLImage image1) {
+static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx1,
+ sk_sp<GrContext> grctx1, const GrGLTextureInfo* grbackendtex1,
+ GrEGLImage image1) {
if (glctx1) {
glctx1->makeCurrent();
if (grctx1) {
@@ -31,7 +32,6 @@ static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx
GrBackendObject handle = reinterpret_cast<GrBackendObject>(grbackendtex1);
gpu1->deleteTestingOnlyBackendTexture(handle, false);
}
- grctx1->unref();
}
if (GR_EGL_NO_IMAGE != image1) {
glctx1->destroyEGLImage(image1);
@@ -63,7 +63,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) {
if (!glCtx1) {
return;
}
- GrContext* context1 = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)glCtx1->gl());
+ sk_sp<GrContext> context1 = GrContext::MakeGL(glCtx1->gl());
const GrGLTextureInfo* backendTexture1 = nullptr;
GrEGLImage image = GR_EGL_NO_IMAGE;
GrGLTextureInfo externalTexture;
diff --git a/tests/GpuSampleLocationsTest.cpp b/tests/GpuSampleLocationsTest.cpp
index 6c5d4a6d37..0f8fd7f9b3 100644
--- a/tests/GpuSampleLocationsTest.cpp
+++ b/tests/GpuSampleLocationsTest.cpp
@@ -186,7 +186,7 @@ private:
DEF_GPUTEST(GLSampleLocations, reporter, /*factory*/) {
GLTestSampleLocationsInterface testInterface;
- sk_sp<GrContext> ctx(GrContext::Create(kOpenGL_GrBackend, testInterface));
+ sk_sp<GrContext> ctx(GrContext::MakeGL(&testInterface));
// This test relies on at least 2 samples.
int supportedSample = ctx->caps()->getSampleCount(2, kRGBA_8888_GrPixelConfig);
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index b27aaea9f7..48f50a0c48 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -358,7 +358,7 @@ int TestResource::fNumAlive = 0;
class Mock {
public:
Mock(int maxCnt, size_t maxBytes) {
- fContext.reset(GrContext::Create(kMock_GrBackend, (GrBackendContext) nullptr));
+ fContext = GrContext::MakeMock(nullptr);
SkASSERT(fContext);
fContext->setResourceCacheLimits(maxCnt, maxBytes);
GrResourceCache* cache = fContext->getResourceCache();
diff --git a/tools/fiddle/egl_context.cpp b/tools/fiddle/egl_context.cpp
index 107bb4ff1a..696a86f06b 100644
--- a/tools/fiddle/egl_context.cpp
+++ b/tools/fiddle/egl_context.cpp
@@ -77,5 +77,5 @@ sk_sp<GrContext> create_grcontext(std::ostringstream &driverinfo) {
}
eglTerminate(eglDpy);
- return sk_sp<GrContext>(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)interface));
+ return sk_sp<GrContext>(GrContext::MakeGL(interface));
}
diff --git a/tools/fiddle/mesa_context.cpp b/tools/fiddle/mesa_context.cpp
index 3b3726bfdb..89902ec711 100644
--- a/tools/fiddle/mesa_context.cpp
+++ b/tools/fiddle/mesa_context.cpp
@@ -27,7 +27,5 @@ sk_sp<GrContext> create_grcontext(std::ostringstream &driverinfo) {
if (!mesa) {
return nullptr;
}
- return sk_sp<GrContext>(GrContext::Create(
- kOpenGL_GrBackend,
- reinterpret_cast<intptr_t>(mesa.get())));
+ return GrContext::MakeGL(mesa.get());
}
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index 0686b79902..b3ca1d929e 100644
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -133,8 +133,6 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
}
std::unique_ptr<TestContext> testCtx;
- GrBackendContext backendContext = 0;
- sk_sp<const GrGLInterface> glInterface;
GrBackend backend = ContextTypeBackend(type);
switch (backend) {
case kOpenGL_GrBackend: {
@@ -194,8 +192,6 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
return ContextInfo();
}
testCtx.reset(glCtx);
- glInterface.reset(SkRef(glCtx->gl()));
- backendContext = reinterpret_cast<GrBackendContext>(glInterface.get());
break;
}
#ifdef SK_VULKAN
@@ -220,7 +216,6 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard));
}
}
- backendContext = testCtx->backendContext();
break;
}
#endif
@@ -244,7 +239,6 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
if (!testCtx) {
return ContextInfo();
}
- backendContext = testCtx->backendContext();
break;
}
default:
@@ -266,9 +260,6 @@ ContextInfo GrContextFactory::getContextInfoInternal(ContextType type, ContextOv
grOptions.fAvoidStencilBuffers = true;
}
sk_sp<GrContext> grCtx = testCtx->makeGrContext(grOptions);
- if (!grCtx.get() && kMetal_GrBackend != backend) {
- grCtx.reset(GrContext::Create(backend, backendContext, grOptions));
- }
if (!grCtx.get()) {
return ContextInfo();
}
diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp
index abbb8a618c..91fa82ff9a 100644
--- a/tools/gpu/gl/GLTestContext.cpp
+++ b/tools/gpu/gl/GLTestContext.cpp
@@ -7,6 +7,7 @@
#include "GLTestContext.h"
+#include "GrContext.h"
#include "GpuTimer.h"
#include "gl/GrGLUtil.h"
@@ -286,4 +287,9 @@ GrGLint GLTestContext::createTextureRectangle(int width, int height, GrGLenum in
externalFormat, externalType, data));
return id;
}
+
+sk_sp<GrContext> GLTestContext::makeGrContext(const GrContextOptions& options) {
+ return GrContext::MakeGL(fGL.get(), options);
+}
+
} // namespace sk_gpu_test
diff --git a/tools/gpu/gl/GLTestContext.h b/tools/gpu/gl/GLTestContext.h
index f5afa31a7f..701000e24b 100644
--- a/tools/gpu/gl/GLTestContext.h
+++ b/tools/gpu/gl/GLTestContext.h
@@ -75,6 +75,8 @@ public:
}
}
+ sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override;
+
protected:
GLTestContext();
diff --git a/tools/gpu/mock/MockTestContext.cpp b/tools/gpu/mock/MockTestContext.cpp
index 56cd68cb59..68941ad4ef 100644
--- a/tools/gpu/mock/MockTestContext.cpp
+++ b/tools/gpu/mock/MockTestContext.cpp
@@ -10,6 +10,8 @@
#include "MockTestContext.h"
+#include "GrContext.h"
+
namespace {
class MockTestContext : public sk_gpu_test::TestContext {
@@ -25,6 +27,10 @@ public:
void submit() override {}
void finish() override {}
+ sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override {
+ return GrContext::MakeMock(nullptr, options);
+ }
+
protected:
void teardown() override {}
void onPlatformMakeCurrent() const override {}
diff --git a/tools/gpu/vk/VkTestContext.cpp b/tools/gpu/vk/VkTestContext.cpp
index 125ead2033..e329583a03 100644
--- a/tools/gpu/vk/VkTestContext.cpp
+++ b/tools/gpu/vk/VkTestContext.cpp
@@ -9,6 +9,7 @@
#ifdef SK_VULKAN
+#include "GrContext.h"
#include "vk/GrVkInterface.h"
#include "vk/GrVkUtil.h"
#include <vulkan/vulkan.h>
@@ -131,6 +132,10 @@ public:
void finish() override {}
+ sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override {
+ return GrContext::MakeVulkan(fVk.get(), options);
+ }
+
protected:
void teardown() override {
INHERITED::teardown();
diff --git a/tools/viewer/sk_app/GLWindowContext.cpp b/tools/viewer/sk_app/GLWindowContext.cpp
index 2f0d5dc74b..682fcbfa48 100644
--- a/tools/viewer/sk_app/GLWindowContext.cpp
+++ b/tools/viewer/sk_app/GLWindowContext.cpp
@@ -31,11 +31,10 @@ GLWindowContext::GLWindowContext(const DisplayParams& params)
void GLWindowContext::initializeContext() {
this->onInitializeContext();
- SkASSERT(nullptr == fContext);
+ SkASSERT(!fContext);
fBackendContext.reset(GrGLCreateNativeInterface());
- fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fBackendContext.get(),
- fDisplayParams.fGrContextOptions);
+ fContext = GrContext::MakeGL(fBackendContext.get(), fDisplayParams.fGrContextOptions);
if (!fContext && fDisplayParams.fMSAASampleCount) {
fDisplayParams.fMSAASampleCount /= 2;
this->initializeContext();
@@ -58,8 +57,7 @@ void GLWindowContext::destroyContext() {
if (fContext) {
// in case we have outstanding refs to this guy (lua?)
fContext->abandonContext();
- fContext->unref();
- fContext = nullptr;
+ fContext.reset();
}
fBackendContext.reset(nullptr);
@@ -83,7 +81,7 @@ sk_sp<SkSurface> GLWindowContext::getBackbufferSurface() {
fPixelConfig,
fbInfo);
- fSurface = SkSurface::MakeFromBackendRenderTarget(fContext, backendRT,
+ fSurface = SkSurface::MakeFromBackendRenderTarget(fContext.get(), backendRT,
kBottomLeft_GrSurfaceOrigin,
fDisplayParams.fColorSpace,
&fSurfaceProps);
diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp
index 261206c221..a9124d5e41 100644
--- a/tools/viewer/sk_app/VulkanWindowContext.cpp
+++ b/tools/viewer/sk_app/VulkanWindowContext.cpp
@@ -67,8 +67,7 @@ void VulkanWindowContext::initializeContext() {
GET_DEV_PROC(AcquireNextImageKHR);
GET_DEV_PROC(QueuePresentKHR);
- fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) fBackendContext.get(),
- fDisplayParams.fGrContextOptions);
+ fContext = GrContext::MakeVulkan(fBackendContext.get(), fDisplayParams.fGrContextOptions);
fSurface = fCreateVkSurfaceFn(instance);
if (VK_NULL_HANDLE == fSurface) {
@@ -280,7 +279,7 @@ void VulkanWindowContext::createBuffers(VkFormat format) {
GrBackendTexture backendTex(fWidth, fHeight, info);
- fSurfaces[i] = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext, backendTex,
+ fSurfaces[i] = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext.get(), backendTex,
kTopLeft_GrSurfaceOrigin,
fSampleCount,
fDisplayParams.fColorSpace,
@@ -412,7 +411,7 @@ void VulkanWindowContext::destroyContext() {
fSurface = VK_NULL_HANDLE;
}
- fContext->unref();
+ fContext.reset();
fBackendContext.reset(nullptr);
}
diff --git a/tools/viewer/sk_app/WindowContext.h b/tools/viewer/sk_app/WindowContext.h
index fbd2756b67..cd4c357e20 100644
--- a/tools/viewer/sk_app/WindowContext.h
+++ b/tools/viewer/sk_app/WindowContext.h
@@ -8,11 +8,11 @@
#define WindowContext_DEFINED
#include "DisplayParams.h"
+#include "GrContext.h"
#include "GrTypes.h"
#include "SkRefCnt.h"
#include "SkSurfaceProps.h"
-class GrContext;
class SkSurface;
class GrRenderTarget;
@@ -46,7 +46,7 @@ public:
}
virtual GrBackendContext getBackendContext() = 0;
- GrContext* getGrContext() const { return fContext; }
+ GrContext* getGrContext() const { return fContext.get(); }
int width() const { return fWidth; }
int height() const { return fHeight; }
@@ -56,7 +56,7 @@ public:
protected:
virtual bool isGpuContext() { return true; }
- GrContext* fContext;
+ sk_sp<GrContext> fContext;
int fWidth;
int fHeight;