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
|
|
|
|
|
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc676856c4db0122ff3bcb49d90b0e7b1115.
Reason for revert: Fixed g3
Original change's description:
> Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
>
> This reverts commit ff13ffbeacec5335cfdb84c8a9d20bb78e10da58.
>
> Reason for revert: Blink in g3
>
> Original change's description:
> > Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit 89bdc90ac877dc8cd49c86c35a20d9df0d3b9016.
> >
> > Reason for revert: Fix metal
> >
> > Original change's description:
> > > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> > >
> > > This reverts commit d2daa94edeca88281796524fae45f38f11a7bef2.
> > >
> > > Reason for revert: Metaru
> > >
> > > Original change's description:
> > > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > > >
> > > > Woo!
> > > >
> > > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > > Docs-Preview: https://skia.org/?cl=317436
> > > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > > Commit-Queue: Adlai Holler <adlai@google.com>
> > >
> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> > >
> > > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > > No-Presubmit: true
> > > No-Tree-Checks: true
> > > No-Try: true
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > > Reviewed-by: Adlai Holler <adlai@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> >
> > Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> > Docs-Preview: https://skia.org/?cl=318759
> > Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> > Commit-Queue: Adlai Holler <adlai@google.com>
> > Reviewed-by: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
> Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>
TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e
Docs-Preview: https://skia.org/?cl=322437
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
2020-10-06 18:04:35 +00:00
|
|
|
#include "include/private/GrContext.h"
|
2020-06-30 13:27:52 +00:00
|
|
|
|
|
|
|
class GrAtlasManager;
|
2020-08-10 20:30:36 +00:00
|
|
|
class GrSmallPathAtlasMgr;
|
2020-06-30 13:27:52 +00:00
|
|
|
|
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;
|
|
|
|
|
2020-10-09 13:49:42 +00:00
|
|
|
/**
|
|
|
|
* The context normally assumes that no outsider is setting state
|
|
|
|
* within the underlying 3D API's context/device/whatever. This call informs
|
|
|
|
* the context that the state was modified and it should resend. Shouldn't
|
|
|
|
* be called frequently for good performance.
|
|
|
|
* The flag bits, state, is dependent on which backend is used by the
|
|
|
|
* context, either GL or D3D (possible in future).
|
|
|
|
*/
|
|
|
|
void resetContext(uint32_t state = kAll_GrBackendState);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the backend is GrBackendApi::kOpenGL, then all texture unit/target combinations for which
|
|
|
|
* the context has modified the bound texture will have texture id 0 bound. This does not
|
|
|
|
* flush the context. Calling resetContext() does not change the set that will be bound
|
|
|
|
* to texture id 0 on the next call to resetGLTextureBindings(). After this is called
|
|
|
|
* all unit/target combinations are considered to have unmodified bindings until the context
|
|
|
|
* subsequently modifies them (meaning if this is called twice in a row with no intervening
|
|
|
|
* context usage then the second call is a no-op.)
|
|
|
|
*/
|
|
|
|
void resetGLTextureBindings();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abandons all GPU resources and assumes the underlying backend 3D API context is no longer
|
|
|
|
* usable. Call this if you have lost the associated GPU context, and thus internal texture,
|
|
|
|
* buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the
|
|
|
|
* GrContext and any of its created resource objects will not make backend 3D API calls. Content
|
|
|
|
* rendered but not previously flushed may be lost. After this function is called all subsequent
|
|
|
|
* calls on the GrContext will fail or be no-ops.
|
|
|
|
*
|
|
|
|
* The typical use case for this function is that the underlying 3D context was lost and further
|
|
|
|
* API calls may crash.
|
|
|
|
*
|
|
|
|
* For Vulkan, even if the device becomes lost, the VkQueue, VkDevice, or VkInstance used to
|
|
|
|
* create the context must be kept alive even after abandoning the context. Those objects must
|
|
|
|
* live for the lifetime of the context object itself. The reason for this is so that
|
|
|
|
* we can continue to delete any outstanding GrBackendTextures/RenderTargets which must be
|
|
|
|
* cleaned up even in a device lost state.
|
|
|
|
*/
|
2020-06-30 13:27:52 +00:00
|
|
|
void abandonContext() override;
|
|
|
|
|
2020-10-09 13:49:42 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the context was abandoned or if the if the backend specific context has
|
|
|
|
* gotten into an unrecoverarble, lost state (e.g. in Vulkan backend if we've gotten a
|
|
|
|
* VK_ERROR_DEVICE_LOST). If the backend context is lost, this call will also abandon the
|
|
|
|
* GrContext.
|
|
|
|
*/
|
|
|
|
bool abandoned() override;
|
|
|
|
|
2020-10-12 16:38:33 +00:00
|
|
|
// TODO: Remove this from public after migrating Chrome.
|
|
|
|
sk_sp<GrContextThreadSafeProxy> threadSafeProxy();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the underlying 3D API reported an out-of-memory error. If this returns true it is
|
|
|
|
* reset and will return false until another out-of-memory error is reported by the 3D API. If
|
|
|
|
* the context is abandoned then this will report false.
|
|
|
|
*
|
|
|
|
* Currently this is implemented for:
|
|
|
|
*
|
|
|
|
* OpenGL [ES] - Note that client calls to glGetError() may swallow GL_OUT_OF_MEMORY errors and
|
|
|
|
* therefore hide the error from Skia. Also, it is not advised to use this in combination with
|
|
|
|
* enabling GrContextOptions::fSkipGLErrorChecks. That option may prevent the context from ever
|
|
|
|
* checking the GL context for OOM.
|
|
|
|
*
|
|
|
|
* Vulkan - Reports true if VK_ERROR_OUT_OF_HOST_MEMORY or VK_ERROR_OUT_OF_DEVICE_MEMORY has
|
|
|
|
* occurred.
|
|
|
|
*/
|
|
|
|
bool oomed();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is similar to abandonContext() however the underlying 3D context is not yet lost and
|
|
|
|
* the context will cleanup all allocated resources before returning. After returning it will
|
|
|
|
* assume that the underlying context may no longer be valid.
|
|
|
|
*
|
|
|
|
* The typical use case for this function is that the client is going to destroy the 3D context
|
|
|
|
* but can't guarantee that context will be destroyed first (perhaps because it may be ref'ed
|
|
|
|
* elsewhere by either the client or Skia objects).
|
|
|
|
*
|
|
|
|
* For Vulkan, even if the device becomes lost, the VkQueue, VkDevice, or VkInstance used to
|
|
|
|
* create the context must be alive before calling releaseResourcesAndAbandonContext.
|
|
|
|
*/
|
|
|
|
void releaseResourcesAndAbandonContext();
|
2020-06-30 13:27:52 +00:00
|
|
|
|
|
|
|
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-08-10 20:30:36 +00:00
|
|
|
GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() override;
|
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
|
|
|
|
2020-08-11 19:18:46 +00:00
|
|
|
std::unique_ptr<GrSmallPathAtlasMgr> fSmallPathAtlasMgr;
|
2020-08-10 20:30:36 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GrContext;
|
2020-06-30 13:27:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|