Skia
2D Graphics Library
GrContext Class Referenceabstract

#include <GrContext.h>

Inheritance diagram for GrContext:

Public Member Functions

 ~GrContext () override
 
sk_sp< GrContextThreadSafeProxythreadSafeProxy ()
 
void resetContext (uint32_t state=kAll_GrBackendState)
 The GrContext normally assumes that no outsider is setting state within the underlying 3D API's context/device/whatever. More...
 
void resetGLTextureBindings ()
 If the backend is GrBackendApi::kOpenGL, then all texture unit/target combinations for which the GrContext has modified the bound texture will have texture id 0 bound. More...
 
void abandonContext () override
 Abandons all GPU resources and assumes the underlying backend 3D API context is no longer usable. More...
 
bool abandoned () override
 Returns true if the context was abandoned or if the if the backend specific context has gotten into an unrecoverarble, lost state (e.g. More...
 
virtual void releaseResourcesAndAbandonContext ()
 This is similar to abandonContext() however the underlying 3D context is not yet lost and the GrContext will cleanup all allocated resources before returning. More...
 
void getResourceCacheLimits (int *maxResources, size_t *maxResourceBytes) const
 DEPRECATED Return the current GPU resource cache limits. More...
 
size_t getResourceCacheLimit () const
 Return the current GPU resource cache limit in bytes. More...
 
void getResourceCacheUsage (int *resourceCount, size_t *resourceBytes) const
 Gets the current GPU resource cache usage. More...
 
size_t getResourceCachePurgeableBytes () const
 Gets the number of bytes in the cache consumed by purgeable (e.g. More...
 
void setResourceCacheLimits (int maxResources, size_t maxResourceBytes)
 DEPRECATED Specify the GPU resource cache limits. More...
 
void setResourceCacheLimit (size_t maxResourceBytes)
 Specify the GPU resource cache limit. More...
 
virtual void freeGpuResources ()
 Frees GPU created by the context. More...
 
void performDeferredCleanup (std::chrono::milliseconds msNotUsed)
 Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are otherwise marked for deletion, regardless of whether the context is under budget. More...
 
void purgeResourcesNotUsedInMs (std::chrono::milliseconds msNotUsed)
 
void purgeUnlockedResources (size_t bytesToPurge, bool preferScratchResources)
 Purge unlocked resources from the cache until the the provided byte count has been reached or we have purged all unlocked resources. More...
 
void purgeUnlockedResources (bool scratchResourcesOnly)
 This entry point is intended for instances where an app has been backgrounded or suspended. More...
 
int maxTextureSize () const
 Gets the maximum supported texture size. More...
 
int maxRenderTargetSize () const
 Gets the maximum supported render target size. More...
 
bool colorTypeSupportedAsImage (SkColorType) const
 Can a SkImage be created with the given color type. More...
 
bool colorTypeSupportedAsSurface (SkColorType colorType) const
 Can a SkSurface be created with the given color type. More...
 
int maxSurfaceSampleCountForColorType (SkColorType) const
 Gets the maximum supported sample count for a color type. More...
 
bool wait (int numSemaphores, const GrBackendSemaphore *waitSemaphores)
 Inserts a list of GPU semaphores that the current GPU-backed API must wait on before executing any more commands on the GPU. More...
 
void flush ()
 Call to ensure all drawing to the context has been issued to the underlying 3D API. More...
 
GrSemaphoresSubmitted flush (const GrFlushInfo &info)
 Call to ensure all drawing to the context has been issued to the underlying 3D API. More...
 
GrSemaphoresSubmitted flush (const GrFlushInfo &, const GrPrepareForExternalIORequests &)
 Call to ensure all drawing to the context has been issued to the underlying 3D API. More...
 
GrSemaphoresSubmitted flush (GrFlushFlags flags, int numSemaphores, GrBackendSemaphore signalSemaphores[], GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 Deprecated. More...
 
GrSemaphoresSubmitted flushAndSignalSemaphores (int numSemaphores, GrBackendSemaphore signalSemaphores[])
 Deprecated. More...
 
void checkAsyncWorkCompletion ()
 Checks whether any asynchronous work is complete and if so calls related callbacks. More...
 
GrContextPriv priv ()
 
const GrContextPriv priv () const
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. More...
 
bool supportsDistanceFieldText () const
 
void storeVkPipelineCacheData ()
 
GrBackendFormat defaultBackendFormat (SkColorType ct, GrRenderable renderable) const
 
GrBackendTexture createBackendTexture (int width, int height, const GrBackendFormat &, GrMipMapped, GrRenderable, GrProtected=GrProtected::kNo)
 
GrBackendTexture createBackendTexture (int width, int height, SkColorType, GrMipMapped, GrRenderable, GrProtected=GrProtected::kNo)
 
GrBackendTexture createBackendTexture (const SkSurfaceCharacterization &characterization)
 
GrBackendTexture createBackendTexture (int width, int height, const GrBackendFormat &, const SkColor4f &color, GrMipMapped, GrRenderable, GrProtected=GrProtected::kNo)
 
GrBackendTexture createBackendTexture (int width, int height, SkColorType, const SkColor4f &color, GrMipMapped, GrRenderable, GrProtected=GrProtected::kNo)
 
GrBackendTexture createBackendTexture (const SkSurfaceCharacterization &characterization, const SkColor4f &color)
 
GrBackendTexture createBackendTexture (const SkPixmap srcData[], int numLevels, GrRenderable, GrProtected)
 
GrBackendTexture createBackendTexture (const SkPixmap &srcData, GrRenderable renderable, GrProtected isProtected)
 
GrBackendFormat compressedBackendFormat (SkImage::CompressionType compression) const
 
GrBackendTexture createCompressedBackendTexture (int width, int height, const GrBackendFormat &, const SkColor4f &color, GrMipMapped, GrProtected=GrProtected::kNo)
 
GrBackendTexture createCompressedBackendTexture (int width, int height, SkImage::CompressionType, const SkColor4f &color, GrMipMapped, GrProtected=GrProtected::kNo)
 
GrBackendTexture createCompressedBackendTexture (int width, int height, const GrBackendFormat &, const void *data, size_t dataSize, GrMipMapped, GrProtected=GrProtected::kNo)
 
GrBackendTexture createCompressedBackendTexture (int width, int height, SkImage::CompressionType, const void *data, size_t dataSize, GrMipMapped, GrProtected=GrProtected::kNo)
 
void deleteBackendTexture (GrBackendTexture)
 
bool precompileShader (const SkData &key, const SkData &data)
 

Static Public Member Functions

static sk_sp< GrContextMakeVulkan (const GrVkBackendContext &, const GrContextOptions &)
 The Vulkan context (VkQueue, VkDevice, VkInstance) must be kept alive until the returned GrContext is first destroyed or abandoned. More...
 
static sk_sp< GrContextMakeVulkan (const GrVkBackendContext &)
 
static sk_sp< GrContextMakeMock (const GrMockOptions *, const GrContextOptions &)
 
static sk_sp< GrContextMakeMock (const GrMockOptions *)
 
static size_t ComputeImageSize (sk_sp< SkImage > image, GrMipMapped, bool useNextPow2=false)
 

Protected Member Functions

 GrContext (GrBackendApi, const GrContextOptions &, int32_t contextID=SK_InvalidGenID)
 
bool init (sk_sp< const GrCaps >) override
 
GrContextasDirectContext () override
 
virtual GrAtlasManager * onGetAtlasManager ()=0
 

Protected Attributes

sk_sp< GrContextThreadSafeProxyfThreadSafeProxy
 

Friends

class GrContextPriv
 

Constructor & Destructor Documentation

◆ ~GrContext()

GrContext::~GrContext ( )
override

◆ GrContext()

GrContext::GrContext ( GrBackendApi  ,
const GrContextOptions ,
int32_t  contextID = SK_InvalidGenID 
)
protected

Member Function Documentation

◆ abandonContext()

void GrContext::abandonContext ( )
override

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 GrContext must be alive before calling abandonContext.

◆ abandoned()

bool GrContext::abandoned ( )
override

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.

◆ asDirectContext()

GrContext* GrContext::asDirectContext ( )
inlineoverrideprotected

◆ checkAsyncWorkCompletion()

void GrContext::checkAsyncWorkCompletion ( )

Checks whether any asynchronous work is complete and if so calls related callbacks.

◆ colorTypeSupportedAsImage()

bool GrContext::colorTypeSupportedAsImage ( SkColorType  ) const

Can a SkImage be created with the given color type.

◆ colorTypeSupportedAsSurface()

bool GrContext::colorTypeSupportedAsSurface ( SkColorType  colorType) const
inline

Can a SkSurface be created with the given color type.

To check whether MSAA is supported use maxSurfaceSampleCountForColorType().

◆ compressedBackendFormat()

GrBackendFormat GrContext::compressedBackendFormat ( SkImage::CompressionType  compression) const
inline

◆ ComputeImageSize()

static size_t GrContext::ComputeImageSize ( sk_sp< SkImage image,
GrMipMapped  ,
bool  useNextPow2 = false 
)
static

◆ createBackendTexture() [1/8]

GrBackendTexture GrContext::createBackendTexture ( int  width,
int  height,
const GrBackendFormat ,
GrMipMapped  ,
GrRenderable  ,
GrProtected  = GrProtected::kNo 
)

◆ createBackendTexture() [2/8]

GrBackendTexture GrContext::createBackendTexture ( int  width,
int  height,
SkColorType  ,
GrMipMapped  ,
GrRenderable  ,
GrProtected  = GrProtected::kNo 
)

◆ createBackendTexture() [3/8]

GrBackendTexture GrContext::createBackendTexture ( const SkSurfaceCharacterization characterization)

◆ createBackendTexture() [4/8]

GrBackendTexture GrContext::createBackendTexture ( int  width,
int  height,
const GrBackendFormat ,
const SkColor4f color,
GrMipMapped  ,
GrRenderable  ,
GrProtected  = GrProtected::kNo 
)

◆ createBackendTexture() [5/8]

GrBackendTexture GrContext::createBackendTexture ( int  width,
int  height,
SkColorType  ,
const SkColor4f color,
GrMipMapped  ,
GrRenderable  ,
GrProtected  = GrProtected::kNo 
)

◆ createBackendTexture() [6/8]

GrBackendTexture GrContext::createBackendTexture ( const SkSurfaceCharacterization characterization,
const SkColor4f color 
)

◆ createBackendTexture() [7/8]

GrBackendTexture GrContext::createBackendTexture ( const SkPixmap  srcData[],
int  numLevels,
GrRenderable  ,
GrProtected   
)

◆ createBackendTexture() [8/8]

GrBackendTexture GrContext::createBackendTexture ( const SkPixmap srcData,
GrRenderable  renderable,
GrProtected  isProtected 
)
inline

◆ createCompressedBackendTexture() [1/4]

GrBackendTexture GrContext::createCompressedBackendTexture ( int  width,
int  height,
const GrBackendFormat ,
const SkColor4f color,
GrMipMapped  ,
GrProtected  = GrProtected::kNo 
)

◆ createCompressedBackendTexture() [2/4]

GrBackendTexture GrContext::createCompressedBackendTexture ( int  width,
int  height,
SkImage::CompressionType  ,
const SkColor4f color,
GrMipMapped  ,
GrProtected  = GrProtected::kNo 
)

◆ createCompressedBackendTexture() [3/4]

GrBackendTexture GrContext::createCompressedBackendTexture ( int  width,
int  height,
const GrBackendFormat ,
const void *  data,
size_t  dataSize,
GrMipMapped  ,
GrProtected  = GrProtected::kNo 
)

◆ createCompressedBackendTexture() [4/4]

GrBackendTexture GrContext::createCompressedBackendTexture ( int  width,
int  height,
SkImage::CompressionType  ,
const void *  data,
size_t  dataSize,
GrMipMapped  ,
GrProtected  = GrProtected::kNo 
)

◆ defaultBackendFormat()

GrBackendFormat GrContext::defaultBackendFormat ( SkColorType  ct,
GrRenderable  renderable 
) const
inline

◆ deleteBackendTexture()

void GrContext::deleteBackendTexture ( GrBackendTexture  )

◆ dumpMemoryStatistics()

void GrContext::dumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump) const

Enumerates all cached GPU resources and dumps their memory to traceMemoryDump.

◆ flush() [1/4]

void GrContext::flush ( )
inline

Call to ensure all drawing to the context has been issued to the underlying 3D API.

◆ flush() [2/4]

GrSemaphoresSubmitted GrContext::flush ( const GrFlushInfo info)
inline

Call to ensure all drawing to the context has been issued to the underlying 3D API.

If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not have created or added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with the GrFlushInfo. However, any pending commands to the context will still be flushed. It should be emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were no semaphores submitted to the GPU. A caller should only take this as a failure if they passed in semaphores to be submitted.

◆ flush() [3/4]

GrSemaphoresSubmitted GrContext::flush ( const GrFlushInfo ,
const GrPrepareForExternalIORequests  
)

Call to ensure all drawing to the context has been issued to the underlying 3D API.

If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not have created or added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with the GrFlushInfo. However, any pending commands to the context will still be flushed. It should be emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were no semaphores submitted to the GPU. A caller should only take this as a failure if they passed in semaphores to be submitted.

If the GrPrepareForExternalIORequests contains valid gpu backed SkSurfaces or SkImages, Skia will put the underlying backend objects into a state that is ready for external uses. See declaration of GrPreopareForExternalIORequests for more details.

◆ flush() [4/4]

GrSemaphoresSubmitted GrContext::flush ( GrFlushFlags  flags,
int  numSemaphores,
GrBackendSemaphore  signalSemaphores[],
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)
inline

Deprecated.

◆ flushAndSignalSemaphores()

GrSemaphoresSubmitted GrContext::flushAndSignalSemaphores ( int  numSemaphores,
GrBackendSemaphore  signalSemaphores[] 
)
inline

Deprecated.

◆ freeGpuResources()

virtual void GrContext::freeGpuResources ( )
virtual

Frees GPU created by the context.

Can be called to reduce GPU memory pressure.

◆ getResourceCacheLimit()

size_t GrContext::getResourceCacheLimit ( ) const

Return the current GPU resource cache limit in bytes.

◆ getResourceCacheLimits()

void GrContext::getResourceCacheLimits ( int *  maxResources,
size_t *  maxResourceBytes 
) const

DEPRECATED Return the current GPU resource cache limits.

Parameters
maxResourcesIf non-null, will be set to -1.
maxResourceBytesIf non-null, returns maximum number of bytes of video memory that can be held in the cache.

◆ getResourceCachePurgeableBytes()

size_t GrContext::getResourceCachePurgeableBytes ( ) const

Gets the number of bytes in the cache consumed by purgeable (e.g.

unlocked) resources.

◆ getResourceCacheUsage()

void GrContext::getResourceCacheUsage ( int *  resourceCount,
size_t *  resourceBytes 
) const

Gets the current GPU resource cache usage.

Parameters
resourceCountIf non-null, returns the number of resources that are held in the cache.
maxResourceBytesIf non-null, returns the total number of bytes of video memory held in the cache.

◆ init()

bool GrContext::init ( sk_sp< const GrCaps >  )
overrideprotected

◆ MakeMock() [1/2]

static sk_sp<GrContext> GrContext::MakeMock ( const GrMockOptions *  ,
const GrContextOptions  
)
static

◆ MakeMock() [2/2]

static sk_sp<GrContext> GrContext::MakeMock ( const GrMockOptions *  )
static

◆ MakeVulkan() [1/2]

static sk_sp<GrContext> GrContext::MakeVulkan ( const GrVkBackendContext &  ,
const GrContextOptions  
)
static

The Vulkan context (VkQueue, VkDevice, VkInstance) must be kept alive until the returned GrContext is first destroyed or abandoned.

◆ MakeVulkan() [2/2]

static sk_sp<GrContext> GrContext::MakeVulkan ( const GrVkBackendContext &  )
static

◆ maxRenderTargetSize()

int GrContext::maxRenderTargetSize ( ) const

Gets the maximum supported render target size.

◆ maxSurfaceSampleCountForColorType()

int GrContext::maxSurfaceSampleCountForColorType ( SkColorType  ) const

Gets the maximum supported sample count for a color type.

1 is returned if only non-MSAA rendering is supported for the color type. 0 is returned if rendering to this color type is not supported at all.

◆ maxTextureSize()

int GrContext::maxTextureSize ( ) const

Gets the maximum supported texture size.

◆ onGetAtlasManager()

virtual GrAtlasManager* GrContext::onGetAtlasManager ( )
protectedpure virtual

◆ performDeferredCleanup()

void GrContext::performDeferredCleanup ( std::chrono::milliseconds  msNotUsed)

Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are otherwise marked for deletion, regardless of whether the context is under budget.

◆ precompileShader()

bool GrContext::precompileShader ( const SkData key,
const SkData data 
)

◆ priv() [1/2]

GrContextPriv GrContext::priv ( )

◆ priv() [2/2]

const GrContextPriv GrContext::priv ( ) const

◆ purgeResourcesNotUsedInMs()

void GrContext::purgeResourcesNotUsedInMs ( std::chrono::milliseconds  msNotUsed)
inline

◆ purgeUnlockedResources() [1/2]

void GrContext::purgeUnlockedResources ( size_t  bytesToPurge,
bool  preferScratchResources 
)

Purge unlocked resources from the cache until the the provided byte count has been reached or we have purged all unlocked resources.

The default policy is to purge in LRU order, but can be overridden to prefer purging scratch resources (in LRU order) prior to purging other resource types.

Parameters
maxBytesToPurgethe desired number of bytes to be purged.
preferScratchResourcesIf true scratch resources will be purged prior to other resource types.

◆ purgeUnlockedResources() [2/2]

void GrContext::purgeUnlockedResources ( bool  scratchResourcesOnly)

This entry point is intended for instances where an app has been backgrounded or suspended.

If 'scratchResourcesOnly' is true all unlocked scratch resources will be purged but the unlocked resources with persistent data will remain. If 'scratchResourcesOnly' is false then all unlocked resources will be purged. In either case, after the unlocked resources are purged a separate pass will be made to ensure that resource usage is under budget (i.e., even if 'scratchResourcesOnly' is true some resources with persistent data may be purged to be under budget).

Parameters
scratchResourcesOnlyIf true only unlocked scratch resources will be purged prior enforcing the budget requirements.

◆ releaseResourcesAndAbandonContext()

virtual void GrContext::releaseResourcesAndAbandonContext ( )
virtual

This is similar to abandonContext() however the underlying 3D context is not yet lost and the GrContext 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 GrContext 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 GrContext must be alive before calling releaseResourcesAndAbandonContext.

◆ resetContext()

void GrContext::resetContext ( uint32_t  state = kAll_GrBackendState)

The GrContext 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 dpendent on which backend is used by the context, either GL or D3D (possible in future).

◆ resetGLTextureBindings()

void GrContext::resetGLTextureBindings ( )

If the backend is GrBackendApi::kOpenGL, then all texture unit/target combinations for which the GrContext has modified the bound texture will have texture id 0 bound.

This does not flush the GrContext. 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 GrContext subsequently modifies them (meaning if this is called twice in a row with no intervening GrContext usage then the second call is a no-op.)

◆ setResourceCacheLimit()

void GrContext::setResourceCacheLimit ( size_t  maxResourceBytes)

Specify the GPU resource cache limit.

If the cache currently exceeds this limit, it will be purged (LRU) to keep the cache within the limit.

Parameters
maxResourceBytesThe maximum number of bytes of video memory that can be held in the cache.

◆ setResourceCacheLimits()

void GrContext::setResourceCacheLimits ( int  maxResources,
size_t  maxResourceBytes 
)

DEPRECATED Specify the GPU resource cache limits.

If the current cache exceeds the maxResourceBytes limit, it will be purged (LRU) to keep the cache within the limit.

Parameters
maxResourcesUnused.
maxResourceBytesThe maximum number of bytes of video memory that can be held in the cache.

◆ storeVkPipelineCacheData()

void GrContext::storeVkPipelineCacheData ( )

◆ supportsDistanceFieldText()

bool GrContext::supportsDistanceFieldText ( ) const

◆ threadSafeProxy()

sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy ( )

◆ wait()

bool GrContext::wait ( int  numSemaphores,
const GrBackendSemaphore waitSemaphores 
)

Inserts a list of GPU semaphores that the current GPU-backed API must wait on before executing any more commands on the GPU.

Skia will take ownership of the underlying semaphores and delete them once they have been signaled and waited on. If this call returns false, then the GPU back-end will not wait on any passed in semaphores, and the client will still own the semaphores.

Friends And Related Function Documentation

◆ GrContextPriv

friend class GrContextPriv
friend

Member Data Documentation

◆ fThreadSafeProxy

sk_sp<GrContextThreadSafeProxy> GrContext::fThreadSafeProxy
protected

The documentation for this class was generated from the following file: