Skia
2DGraphicsLibrary
|
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 | |
GrContextThreadSafeProxy * | threadSafeProxy () |
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... | |
GrTextureProvider * | textureProvider () |
const GrTextureProvider * | textureProvider () const |
void | freeGpuResources () |
Frees GPU created by the context. More... | |
void | purgeAllUnlockedResources () |
Purge all the unlocked resources from the cache. More... | |
const GrCaps * | caps () 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< GrDrawContext > | 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. 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... | |
GrTexture * | getFontAtlasTexture (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 GrContext * | Create (GrBackend, GrBackendContext, const GrContextOptions &options) |
Creates a GrContext for a backend context. | |
static GrContext * | Create (GrBackend, GrBackendContext) |
static GrContext * | CreateMockContext () |
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< GrFragmentProcessor > | createPMToUPMEffect (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< GrFragmentProcessor > | createUPMToPMEffect (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 GrCaps * | fCaps |
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< CleanUpData > | fCleanUpData |
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... | |
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.
enum GrContext::FlushBits |
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. |
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.
|
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.
dst | the surface to copy to. |
src | the surface to copy from. |
srcRect | the rectangle of the src that should be copied. |
dstPoint | the translation applied when writing the srcRect's pixels to the dst. |
Helper that copies the whole surface but fails when the two surfaces are not identically sized.
|
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.
|
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.
flagsBitfield | flags 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.
config | the configuration of the render target. |
dpi | the display density in dots per inch. |
void GrContext::getResourceCacheLimits | ( | int * | maxResources, |
size_t * | maxResourceBytes | ||
) | const |
Return the current GPU resource cache limits.
maxResources | If non-null, returns maximum number of resources that can be held in the cache. |
maxResourceBytes | If 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.
resourceCount | If non-null, returns the number of resources that are held in the cache. |
maxResourceBytes | If 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.
surface | the surface to read from. |
left | left edge of the rectangle to read (inclusive) |
top | top edge of the rectangle to read (inclusive) |
width | width of rectangle to read in pixels. |
height | height of rectangle to read in pixels. |
config | the pixel config of the destination buffer |
buffer | memory to read the rectangle into. |
rowBytes | number of bytes bewtween consecutive rows. Zero means rows are tightly packed. |
pixelOpsFlags | see PixelOpsFlags enum above. |
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.
maxResources | The maximum number of resources that can be held in the cache. |
maxResourceBytes | The 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
|
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.
surface | the surface to write to. |
left | left edge of the rectangle to write (inclusive) |
top | top edge of the rectangle to write (inclusive) |
width | width of rectangle to write in pixels. |
height | height of rectangle to write in pixels. |
config | the pixel config of the source buffer |
buffer | memory to read pixels from |
rowBytes | number of bytes between consecutive rows. Zero means rows are tightly packed. |
pixelOpsFlags | see PixelOpsFlags enum above. |