Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GrContext Class Reference
Inheritance diagram for GrContext:
SkRefCnt SkRefCntBase

Classes

struct  CleanUpData
 

Public Types

typedef void(* PFCleanUpFunc )(const GrContext *context, void *info)
 Callback function to allow classes to cleanup on GrContext destruction. More...
 

Public Member Functions

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 addCleanUp (PFCleanUpFunc cleanUp, void *info)
 Add a function to be called from within GrContext's destructor. More...
 
void abandonContext ()
 Abandons all GPU resources and assumes the underlying backend 3D API context is not longer usable. More...
 
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
 Return the current GPU resource cache limits. 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)
 Specify the GPU resource cache limits. More...
 
void freeGpuResources ()
 Frees GPU created by the context. More...
 
void purgeAllUnlockedResources ()
 Purge all the unlocked resources from the cache. More...
 
void purgeResourcesNotUsedInMs (std::chrono::milliseconds ms)
 Purge GPU resources that haven't been used in the past 'ms' milliseconds, regardless of whether the context is currently under budget.
 
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...
 
const GrCapscaps () const
 Access the context capabilities.
 
int getRecommendedSampleCount (GrPixelConfig config, SkScalar dpi) const
 Returns the recommended sample count for a render target when using this context. More...
 
sk_sp< GrRenderTargetContext > makeDeferredRenderTargetContext (SkBackingFit fit, int width, int height, GrPixelConfig config, sk_sp< SkColorSpace > colorSpace, int sampleCnt=0, GrSurfaceOrigin origin=kBottomLeft_GrSurfaceOrigin, const SkSurfaceProps *surfaceProps=nullptr, SkBudgeted=SkBudgeted::kYes)
 
sk_sp< GrRenderTargetContext > makeDeferredRenderTargetContextWithFallback (SkBackingFit fit, int width, int height, GrPixelConfig config, sk_sp< SkColorSpace > colorSpace, int sampleCnt=0, GrSurfaceOrigin origin=kBottomLeft_GrSurfaceOrigin, const SkSurfaceProps *surfaceProps=nullptr, SkBudgeted budgeted=SkBudgeted::kYes)
 
void flush ()
 Call to ensure all drawing to the context has been issued to the underlying 3D API.
 
uint32_t uniqueID ()
 An ID associated with this context, guaranteed to be unique.
 
GrGpu * getGpu ()
 
const GrGpu * getGpu () const
 
GrAtlasGlyphCache * getAtlasGlyphCache ()
 
GrTextBlobCache * getTextBlobCache ()
 
bool abandoned () const
 
GrResourceProvider * resourceProvider ()
 
const GrResourceProvider * resourceProvider () const
 
GrResourceCache * getResourceCache ()
 
void resetGpuStats () const
 Reset GPU stats.
 
void dumpCacheStats (SkString *) const
 Prints cache stats to the string if GR_CACHE_STATS == 1. More...
 
void dumpCacheStatsKeyValuePairs (SkTArray< SkString > *keys, SkTArray< double > *values) const
 
void printCacheStats () const
 
void dumpGpuStats (SkString *) const
 Prints GPU stats to the string if GR_GPU_STATS == 1. More...
 
void dumpGpuStatsKeyValuePairs (SkTArray< SkString > *keys, SkTArray< double > *values) const
 
void printGpuStats () const
 
void setTextBlobCacheLimit_ForTesting (size_t bytes)
 Specify the TextBlob cache limit. More...
 
void setTextContextAtlasSizes_ForTesting (const GrDrawOpAtlasConfig *configs)
 Specify the sizes of the GrAtlasTextContext atlases. More...
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. More...
 
sk_sp< SkImagegetFontAtlasImage_ForTesting (GrMaskFormat format)
 Get pointer to atlas texture for given mask format. More...
 
GrAuditTrail * getAuditTrail ()
 
 SkDEBUGCODE (GrSingleOwner *debugSingleOwner() const {return &fSingleOwner;}) GrContextPriv contextPriv()
 This is only useful for debug purposes.
 
const GrContextPriv contextPriv () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 Default construct, initializing the reference count to 1.
 
virtual ~SkRefCntBase ()
 Destruct, asserting that the reference count is 1.
 
int32_t getRefCnt () const
 Return the reference count. More...
 
void validate () const
 
bool unique () const
 May return true if the caller is the only owner. More...
 
void ref () const
 Increment the reference count. More...
 
void unref () const
 Decrement the reference count. More...
 

Static Public Member Functions

static GrContextCreate (GrBackend, GrBackendContext, const GrContextOptions &options)
 Creates a GrContext for a backend context.
 
static GrContextCreate (GrBackend, GrBackendContext)
 

Private Types

typedef SkRefCnt INHERITED
 

Private Member Functions

bool init (GrBackend, GrBackendContext, const GrContextOptions &options)
 
sk_sp< GrFragmentProcessor > createPMToUPMEffect (sk_sp< GrFragmentProcessor >, bool useConfigConversionEffect)
 These functions create premul <-> unpremul effects. More...
 
sk_sp< GrFragmentProcessor > createUPMToPMEffect (sk_sp< GrFragmentProcessor >, bool useConfigConversionEffect)
 
bool validPMUPMConversionExists ()
 Returns true if createPMtoUPMEffect and createUPMToPMEffect will succeed for non-sRGB 8888 configs. More...
 

Static Private Member Functions

static void TextBlobCacheOverBudgetCB (void *data)
 A callback similar to the above for use by the TextBlobCache TODO move textblob draw calls below context so we can use the call above.
 

Private Attributes

GrGpu * fGpu
 
const GrCapsfCaps
 
GrResourceCache * fResourceCache
 
GrResourceProvider * fResourceProvider
 
sk_sp< GrContextThreadSafeProxyfThreadSafeProxy
 
GrAtlasGlyphCache * fAtlasGlyphCache
 
std::unique_ptr< GrTextBlobCache > fTextBlobCache
 
bool fDisableGpuYUVConversion
 
bool fDidTestPMConversions
 
bool fPMUPMConversionsRoundTrip
 
GrSingleOwner fSingleOwner
 
SkTDArray< CleanUpDatafCleanUpData
 
const uint32_t fUniqueID
 
std::unique_ptr< GrDrawingManager > fDrawingManager
 
GrAuditTrail fAuditTrail
 
GrBackend fBackend
 

Friends

class GrContextPriv
 

Additional Inherited Members

- Protected Member Functions inherited from SkRefCntBase
void internal_dispose_restore_refcnt_to_1 () const
 Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g. More...
 

Member Typedef Documentation

typedef void(* GrContext::PFCleanUpFunc)(const GrContext *context, void *info)

Callback function to allow classes to cleanup on GrContext destruction.

The 'info' field is filled in with the 'info' passed to addCleanUp.

Member Function Documentation

void GrContext::abandonContext ( )

Abandons all GPU resources and assumes the underlying backend 3D API context is not 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.

void GrContext::addCleanUp ( PFCleanUpFunc  cleanUp,
void *  info 
)
inline

Add a function to be called from within GrContext's destructor.

This gives classes a chance to free resources held on a per context basis. The 'info' parameter will be stored and passed to the callback function.

sk_sp<GrFragmentProcessor> GrContext::createPMToUPMEffect ( sk_sp< GrFragmentProcessor >  ,
bool  useConfigConversionEffect 
)
private

These functions create premul <-> unpremul effects.

If the second argument is 'true', they use the specialized round-trip effects from GrConfigConversionEffect, otherwise they create effects that do naive multiply or divide.

void GrContext::dumpCacheStats ( SkString ) const

Prints cache stats to the string if GR_CACHE_STATS == 1.

void GrContext::dumpGpuStats ( SkString ) const

Prints GPU stats to the string if GR_GPU_STATS == 1.

void GrContext::dumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump) const

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

void GrContext::freeGpuResources ( )

Frees GPU created by the context.

Can be called to reduce GPU memory pressure.

sk_sp<SkImage> GrContext::getFontAtlasImage_ForTesting ( GrMaskFormat  format)

Get pointer to atlas texture for given mask format.

Note that this wraps an actively mutating texture in an SkImage. This could yield unexpected results if it gets cached or used more generally.

int GrContext::getRecommendedSampleCount ( GrPixelConfig  config,
SkScalar  dpi 
) const

Returns the recommended sample count for a render target when using this context.

Parameters
configthe configuration of the render target.
dpithe display density in dots per inch.
Returns
sample count that should be perform well and have good enough rendering quality for the display. Alternatively returns 0 if MSAA is not supported or recommended to be used by default.
void GrContext::getResourceCacheLimits ( int *  maxResources,
size_t *  maxResourceBytes 
) const

Return the current GPU resource cache limits.

Parameters
maxResourcesIf non-null, returns maximum number of resources that can be held in the cache.
maxResourceBytesIf non-null, returns maximum number of bytes of video memory that can be held in the cache.
size_t GrContext::getResourceCachePurgeableBytes ( ) const

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

unlocked) resources.

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.
void GrContext::purgeAllUnlockedResources ( )

Purge all the unlocked resources from the cache.

This entry point is mainly meant for timing texture uploads and is not defined in normal builds of Skia.

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.
void GrContext::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.

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).

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).

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

Specify the GPU resource cache limits.

If the current cache exceeds either of these, it will be purged (LRU) to keep the cache within these limits.

Parameters
maxResourcesThe maximum number of resources that can be held in the cache.
maxResourceBytesThe maximum number of bytes of video memory that can be held in the cache.
void GrContext::setTextBlobCacheLimit_ForTesting ( size_t  bytes)

Specify the TextBlob cache limit.

If the current cache exceeds this limit it will purge. this is for testing only

void GrContext::setTextContextAtlasSizes_ForTesting ( const GrDrawOpAtlasConfig *  configs)

Specify the sizes of the GrAtlasTextContext atlases.

The configs pointer below should be to an array of 3 entries

bool GrContext::validPMUPMConversionExists ( )
private

Returns true if createPMtoUPMEffect and createUPMToPMEffect will succeed for non-sRGB 8888 configs.

In other words, did we find a pair of round-trip preserving conversion effects?


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