2020-06-30 13:27:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrDirectContext_DEFINED
|
|
|
|
#define GrDirectContext_DEFINED
|
|
|
|
|
|
|
|
#include "include/gpu/GrContext.h"
|
|
|
|
|
|
|
|
class GrAtlasManager;
|
|
|
|
|
2020-07-14 16:57:39 +00:00
|
|
|
class SK_API GrDirectContext : public GrContext {
|
2020-06-30 13:27:52 +00:00
|
|
|
public:
|
2020-07-13 20:13:31 +00:00
|
|
|
#ifdef SK_GL
|
|
|
|
/**
|
|
|
|
* Creates a GrDirectContext for a backend context. If no GrGLInterface is provided then the
|
|
|
|
* result of GrGLMakeNativeInterface() is used if it succeeds.
|
|
|
|
*/
|
|
|
|
static sk_sp<GrDirectContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
|
|
|
|
static sk_sp<GrDirectContext> MakeGL(sk_sp<const GrGLInterface>);
|
|
|
|
static sk_sp<GrDirectContext> MakeGL(const GrContextOptions&);
|
|
|
|
static sk_sp<GrDirectContext> MakeGL();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SK_VULKAN
|
|
|
|
/**
|
|
|
|
* The Vulkan context (VkQueue, VkDevice, VkInstance) must be kept alive until the returned
|
|
|
|
* GrDirectContext is destroyed. This also means that any objects created with this
|
|
|
|
* GrDirectContext (e.g. SkSurfaces, SkImages, etc.) must also be released as they may hold
|
|
|
|
* refs on the GrDirectContext. Once all these objects and the GrDirectContext are released,
|
|
|
|
* then it is safe to delete the vulkan objects.
|
|
|
|
*/
|
|
|
|
static sk_sp<GrDirectContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&);
|
|
|
|
static sk_sp<GrDirectContext> MakeVulkan(const GrVkBackendContext&);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SK_METAL
|
|
|
|
/**
|
|
|
|
* Makes a GrDirectContext which uses Metal as the backend. The device parameter is an
|
|
|
|
* MTLDevice and queue is an MTLCommandQueue which should be used by the backend. These objects
|
|
|
|
* must have a ref on them which can be transferred to Ganesh which will release the ref
|
|
|
|
* when the GrDirectContext is destroyed.
|
|
|
|
*/
|
|
|
|
static sk_sp<GrDirectContext> MakeMetal(void* device, void* queue, const GrContextOptions&);
|
|
|
|
static sk_sp<GrDirectContext> MakeMetal(void* device, void* queue);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SK_DIRECT3D
|
|
|
|
/**
|
|
|
|
* Makes a GrDirectContext which uses Direct3D as the backend. The Direct3D context
|
|
|
|
* must be kept alive until the returned GrDirectContext is first destroyed or abandoned.
|
|
|
|
*/
|
|
|
|
static sk_sp<GrDirectContext> MakeDirect3D(const GrD3DBackendContext&, const GrContextOptions&);
|
|
|
|
static sk_sp<GrDirectContext> MakeDirect3D(const GrD3DBackendContext&);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SK_DAWN
|
|
|
|
static sk_sp<GrDirectContext> MakeDawn(const wgpu::Device&,
|
|
|
|
const GrContextOptions&);
|
|
|
|
static sk_sp<GrDirectContext> MakeDawn(const wgpu::Device&);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static sk_sp<GrDirectContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
|
|
|
|
static sk_sp<GrDirectContext> MakeMock(const GrMockOptions*);
|
2020-06-30 13:27:52 +00:00
|
|
|
|
|
|
|
~GrDirectContext() override;
|
|
|
|
|
|
|
|
void abandonContext() override;
|
|
|
|
|
|
|
|
void releaseResourcesAndAbandonContext() override;
|
|
|
|
|
|
|
|
void freeGpuResources() override;
|
|
|
|
|
|
|
|
protected:
|
2020-07-13 20:13:31 +00:00
|
|
|
GrDirectContext(GrBackendApi backend, const GrContextOptions& options);
|
|
|
|
|
2020-06-30 13:27:52 +00:00
|
|
|
bool init() override;
|
|
|
|
|
2020-08-10 16:11:58 +00:00
|
|
|
GrAtlasManager* onGetAtlasManager() override { return fAtlasManager.get(); }
|
2020-06-30 13:27:52 +00:00
|
|
|
|
2020-06-30 17:28:00 +00:00
|
|
|
GrDirectContext* asDirectContext() override { return this; }
|
|
|
|
|
2020-06-30 13:27:52 +00:00
|
|
|
private:
|
2020-08-10 16:11:58 +00:00
|
|
|
std::unique_ptr<GrAtlasManager> fAtlasManager;
|
2020-06-30 13:27:52 +00:00
|
|
|
|
|
|
|
typedef GrContext INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|