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

Classes

struct  CleanUpData
 

Public Types

enum  FlushBits { kDiscard_FlushBit = 0x2 }
 Flags that affect flush() behavior. More...
 
enum  PixelOpsFlags { kDontFlush_PixelOpsFlag = 0x1, kFlushWrites_PixelOp = 0x2, kUnpremul_PixelOpsFlag = 0x4 }
 These flags can be used with the read/write pixels functions below. More...
 
typedef void(* PFCleanUpFunc )(const GrContext *context, void *info)
 Callback function to allow classes to cleanup on GrContext destruction. More...
 

Public Member Functions

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...
 
void setResourceCacheLimits (int maxResources, size_t maxResourceBytes)
 Specify the GPU resource cache limits. More...
 
GrTextureProvidertextureProvider ()
 
const GrTextureProvidertextureProvider () const
 
void freeGpuResources ()
 Frees GPU created by the context. More...
 
void purgeAllUnlockedResources ()
 Purge all the unlocked resources from the cache. 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< GrDrawContextmakeDrawContext (SkBackingFit fit, int width, int height, GrPixelConfig config, sk_sp< SkColorSpace > colorSpace, int sampleCnt=0, GrSurfaceOrigin origin=kDefault_GrSurfaceOrigin, const SkSurfaceProps *surfaceProps=nullptr, SkBudgeted=SkBudgeted::kYes)
 Create both a GrRenderTarget and a matching GrDrawContext to wrap it. More...
 
void flush (int flagsBitfield=0)
 Call to ensure all drawing to the context has been issued to the underlying 3D API. More...
 
void flushIfNecessary ()
 
bool readSurfacePixels (GrSurface *surface, int left, int top, int width, int height, GrPixelConfig config, void *buffer, size_t rowBytes=0, uint32_t pixelOpsFlags=0)
 Reads a rectangle of pixels from a surface. More...
 
bool writeSurfacePixels (GrSurface *surface, int left, int top, int width, int height, GrPixelConfig config, const void *buffer, size_t rowBytes, uint32_t pixelOpsFlags=0)
 Writes a rectangle of pixels to a surface. More...
 
bool copySurface (GrSurface *dst, GrSurface *src, const SkIRect &srcRect, const SkIPoint &dstPoint)
 Copies a rectangle of texels from src to dst. More...
 
bool copySurface (GrSurface *dst, GrSurface *src)
 Helper that copies the whole surface but fails when the two surfaces are not identically sized. More...
 
void flushSurfaceWrites (GrSurface *surface)
 After this returns any pending writes to the surface will have been issued to the backend 3D API.
 
void flushSurfaceIO (GrSurface *surface)
 After this returns any pending reads or writes to the surface will have been issued to the backend 3D API.
 
void prepareSurfaceForExternalIO (GrSurface *)
 Finalizes all pending reads and writes to the surface and also performs an MSAA resolve if necessary. More...
 
uint32_t uniqueID ()
 An ID associated with this context, guaranteed to be unique.
 
GrGpu * getGpu ()
 
const GrGpu * getGpu () const
 
GrBatchFontCache * getBatchFontCache ()
 
GrTextBlobCache * getTextBlobCache ()
 
bool abandoned () const
 
GrResourceProvider * resourceProvider ()
 
const GrResourceProvider * resourceProvider () const
 
GrResourceCache * getResourceCache ()
 
void getTestTarget (GrTestTarget *, sk_sp< GrDrawContext >)
 
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 GrBatchAtlasConfig *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...
 
GrTexturegetFontAtlasTexture (GrMaskFormat format)
 Get pointer to atlas texture for given mask format.
 
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)
 
static GrContextCreateMockContext ()
 Only defined in test apps.
 

Private Types

typedef SkRefCnt INHERITED
 

Private Member Functions

GrDrawingManager * drawingManager ()
 
bool init (GrBackend, GrBackendContext, const GrContextOptions &options)
 
void initMockContext ()
 
void initCommon (const GrContextOptions &)
 
sk_sp< GrFragmentProcessorcreatePMToUPMEffect (GrTexture *, const GrSwizzle &, const SkMatrix &) const
 These functions create premul <-> unpremul effects if it is possible to generate a pair of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. More...
 
sk_sp< GrFragmentProcessorcreateUPMToPMEffect (GrTexture *, const GrSwizzle &, const SkMatrix &) const
 
void testPMConversionsIfNecessary (uint32_t flags)
 Called before either of the above two functions to determine the appropriate fragment processors for conversions. More...
 
bool didFailPMUPMConversionTest () const
 Returns true if we've already determined that createPMtoUPMEffect and createUPMToPMEffect will fail. More...
 

Static Private Member Functions

static void OverBudgetCB (void *data)
 This callback allows the resource cache to callback into the GrContext when the cache is still over budget after a purge.
 
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
 
union {
   GrResourceProvider *   fResourceProvider
 
   GrTextureProvider *   fTextureProvider
 
}; 
 
SkAutoTUnref
< GrContextThreadSafeProxy
fThreadSafeProxy
 
GrBatchFontCache * fBatchFontCache
 
SkAutoTDelete< GrTextBlobCache > fTextBlobCache
 
bool fFlushToReduceCacheSize
 
bool fDidTestPMConversions
 
int fPMToUPMConversion
 
int fUPMToPMConversion
 
SkMutex fReadPixelsMutex
 
SkMutex fTestPMConversionsMutex
 
GrSingleOwner fSingleOwner
 
SkTDArray< CleanUpDatafCleanUpData
 
const uint32_t fUniqueID
 
SkAutoTDelete< GrDrawingManager > fDrawingManager
 
GrAuditTrail fAuditTrail
 

Friends

class GrClipStackClip
 
class GrDrawingManager
 
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 Enumeration Documentation

Flags that affect flush() behavior.

Enumerator
kDiscard_FlushBit 

A client may reach a point where it has partially rendered a frame through a GrContext that it knows the user will never see.

This flag causes the flush to skip submission of deferred content to the 3D API during the flush.

These flags can be used with the read/write pixels functions below.

Enumerator
kDontFlush_PixelOpsFlag 

The GrContext will not be flushed before the surface read or write.

This means that the read or write may occur before previous draws have executed.

kFlushWrites_PixelOp 

Any surface writes should be flushed to the backend 3D API after the surface operation is complete.

kUnpremul_PixelOpsFlag 

The src for write or dst read is unpremultiplied.

This is only respected if both the config src and dst configs are an RGBA/BGRA 8888 format.

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.

bool GrContext::copySurface ( GrSurface dst,
GrSurface src,
const SkIRect srcRect,
const SkIPoint dstPoint 
)

Copies a rectangle of texels from src to dst.

Parameters
dstthe surface to copy to.
srcthe surface to copy from.
srcRectthe rectangle of the src that should be copied.
dstPointthe translation applied when writing the srcRect's pixels to the dst.
bool GrContext::copySurface ( GrSurface dst,
GrSurface src 
)
inline

Helper that copies the whole surface but fails when the two surfaces are not identically sized.

sk_sp<GrFragmentProcessor> GrContext::createPMToUPMEffect ( GrTexture ,
const GrSwizzle &  ,
const SkMatrix  
) const
private

These functions create premul <-> unpremul effects if it is possible to generate a pair of effects that make a readToUPM->writeToPM->readToUPM cycle invariant.

Otherwise, they return NULL. They also can perform a swizzle as part of the draw.

bool GrContext::didFailPMUPMConversionTest ( ) const
private

Returns true if we've already determined that createPMtoUPMEffect and createUPMToPMEffect will fail.

In such cases fall back to SW conversion.

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::flush ( int  flagsBitfield = 0)

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

Parameters
flagsBitfieldflags that control the flushing behavior. See FlushBits.
void GrContext::freeGpuResources ( )

Frees GPU created by the context.

Can be called to reduce GPU memory pressure.

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.
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.
sk_sp<GrDrawContext> GrContext::makeDrawContext ( SkBackingFit  fit,
int  width,
int  height,
GrPixelConfig  config,
sk_sp< SkColorSpace colorSpace,
int  sampleCnt = 0,
GrSurfaceOrigin  origin = kDefault_GrSurfaceOrigin,
const SkSurfaceProps surfaceProps = nullptr,
SkBudgeted  = SkBudgeted::kYes 
)

Create both a GrRenderTarget and a matching GrDrawContext to wrap it.

We guarantee that "asTexture" will succeed for drawContexts created via this entry point.

void GrContext::prepareSurfaceForExternalIO ( GrSurface )

Finalizes all pending reads and writes to the surface and also performs an MSAA resolve if necessary.

It is not necessary to call this before reading the render target via Skia/GrContext. GrContext will detect when it must perform a resolve before reading pixels back from the surface or using it as a texture.

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.

bool GrContext::readSurfacePixels ( GrSurface surface,
int  left,
int  top,
int  width,
int  height,
GrPixelConfig  config,
void *  buffer,
size_t  rowBytes = 0,
uint32_t  pixelOpsFlags = 0 
)

Reads a rectangle of pixels from a surface.

Parameters
surfacethe surface to read from.
leftleft edge of the rectangle to read (inclusive)
toptop edge of the rectangle to read (inclusive)
widthwidth of rectangle to read in pixels.
heightheight of rectangle to read in pixels.
configthe pixel config of the destination buffer
buffermemory to read the rectangle into.
rowBytesnumber of bytes bewtween consecutive rows. Zero means rows are tightly packed.
pixelOpsFlagssee PixelOpsFlags enum above.
Returns
true if the read succeeded, false if not. The read can fail because of an unsupported pixel configs
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 GrBatchAtlasConfig *  configs)

Specify the sizes of the GrAtlasTextContext atlases.

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

void GrContext::testPMConversionsIfNecessary ( uint32_t  flags)
private

Called before either of the above two functions to determine the appropriate fragment processors for conversions.

This must be called by readSurfacePixels before a mutex is taken, since testingvPM conversions itself will call readSurfacePixels

bool GrContext::writeSurfacePixels ( GrSurface surface,
int  left,
int  top,
int  width,
int  height,
GrPixelConfig  config,
const void *  buffer,
size_t  rowBytes,
uint32_t  pixelOpsFlags = 0 
)

Writes a rectangle of pixels to a surface.

Parameters
surfacethe surface to write to.
leftleft edge of the rectangle to write (inclusive)
toptop edge of the rectangle to write (inclusive)
widthwidth of rectangle to write in pixels.
heightheight of rectangle to write in pixels.
configthe pixel config of the source buffer
buffermemory to read pixels from
rowBytesnumber of bytes between consecutive rows. Zero means rows are tightly packed.
pixelOpsFlagssee PixelOpsFlags enum above.
Returns
true if the write succeeded, false if not. The write can fail because of an unsupported combination of surface and src configs.

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