2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrContext_DEFINED
|
|
|
|
#define GrContext_DEFINED
|
|
|
|
|
2015-11-11 21:18:11 +00:00
|
|
|
#include "GrCaps.h"
|
2015-02-23 22:44:57 +00:00
|
|
|
#include "GrClip.h"
|
2013-09-18 13:00:55 +00:00
|
|
|
#include "GrColor.h"
|
2012-10-17 12:53:54 +00:00
|
|
|
#include "GrPaint.h"
|
2012-08-23 18:09:54 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2015-04-30 21:18:54 +00:00
|
|
|
#include "GrTextureProvider.h"
|
2013-09-18 13:00:55 +00:00
|
|
|
#include "SkMatrix.h"
|
2014-06-12 17:24:21 +00:00
|
|
|
#include "SkPathEffect.h"
|
2013-09-18 13:00:55 +00:00
|
|
|
#include "SkTypes.h"
|
2016-01-08 15:19:47 +00:00
|
|
|
#include "../private/GrAuditTrail.h"
|
2016-01-06 16:26:09 +00:00
|
|
|
#include "../private/GrSingleOwner.h"
|
|
|
|
#include "../private/SkMutex.h"
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2015-08-19 15:16:43 +00:00
|
|
|
struct GrBatchAtlasConfig;
|
2015-03-31 20:32:05 +00:00
|
|
|
class GrBatchFontCache;
|
2015-05-22 21:01:46 +00:00
|
|
|
struct GrContextOptions;
|
2015-10-17 14:43:27 +00:00
|
|
|
class GrDrawingManager;
|
2015-05-26 18:38:03 +00:00
|
|
|
class GrDrawContext;
|
2011-08-17 13:42:46 +00:00
|
|
|
class GrDrawTarget;
|
2014-09-23 16:50:21 +00:00
|
|
|
class GrFragmentProcessor;
|
2011-05-02 21:14:59 +00:00
|
|
|
class GrGpu;
|
2011-08-17 13:42:46 +00:00
|
|
|
class GrIndexBuffer;
|
2014-04-03 00:34:27 +00:00
|
|
|
class GrLayerCache;
|
2013-03-22 18:34:09 +00:00
|
|
|
class GrOvalRenderer;
|
2013-11-01 15:23:44 +00:00
|
|
|
class GrPath;
|
2015-01-22 18:16:09 +00:00
|
|
|
class GrPipelineBuilder;
|
2011-07-26 20:45:30 +00:00
|
|
|
class GrResourceEntry;
|
2015-02-11 18:49:59 +00:00
|
|
|
class GrResourceCache;
|
2015-04-30 21:18:54 +00:00
|
|
|
class GrResourceProvider;
|
2013-08-21 19:27:48 +00:00
|
|
|
class GrTestTarget;
|
2015-04-08 16:08:31 +00:00
|
|
|
class GrTextBlobCache;
|
2014-06-24 07:12:27 +00:00
|
|
|
class GrTextContext;
|
2012-10-17 12:53:54 +00:00
|
|
|
class GrTextureParams;
|
2011-08-17 13:42:46 +00:00
|
|
|
class GrVertexBuffer;
|
2014-06-11 17:30:05 +00:00
|
|
|
class GrStrokeInfo;
|
2015-09-15 21:16:10 +00:00
|
|
|
class SkTraceMemoryDump;
|
2011-07-26 20:45:30 +00:00
|
|
|
|
2013-09-09 13:38:37 +00:00
|
|
|
class SK_API GrContext : public SkRefCnt {
|
2011-02-22 20:59:41 +00:00
|
|
|
public:
|
|
|
|
/**
|
2012-10-25 18:43:28 +00:00
|
|
|
* Creates a GrContext for a backend context.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2015-05-22 21:01:46 +00:00
|
|
|
static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options);
|
|
|
|
static GrContext* Create(GrBackend, GrBackendContext);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2014-11-05 22:47:41 +00:00
|
|
|
/**
|
|
|
|
* Only defined in test apps.
|
|
|
|
*/
|
|
|
|
static GrContext* CreateMockContext();
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
virtual ~GrContext();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2013-06-28 18:57:35 +00:00
|
|
|
* The flag bits, state, is dpendent on which backend is used by the
|
|
|
|
* context, either GL or D3D (possible in future).
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2013-06-28 18:57:35 +00:00
|
|
|
void resetContext(uint32_t state = kAll_GrBackendState);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2012-09-24 19:33:59 +00:00
|
|
|
/**
|
|
|
|
* Callback function to allow classes to cleanup on GrContext destruction.
|
|
|
|
* The 'info' field is filled in with the 'info' passed to addCleanUp.
|
|
|
|
*/
|
|
|
|
typedef void (*PFCleanUpFunc)(const GrContext* context, void* info);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void addCleanUp(PFCleanUpFunc cleanUp, void* info) {
|
|
|
|
CleanUpData* entry = fCleanUpData.push();
|
|
|
|
|
|
|
|
entry->fFunc = cleanUp;
|
|
|
|
entry->fInfo = info;
|
|
|
|
}
|
|
|
|
|
2011-03-30 21:26:44 +00:00
|
|
|
/**
|
2015-06-26 18:45:03 +00:00
|
|
|
* Abandons all GPU resources and assumes the underlying backend 3D API
|
2014-07-28 20:48:36 +00:00
|
|
|
* 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. Should be called even when GrContext is no longer going to
|
|
|
|
* be used for two reasons:
|
2011-03-30 21:26:44 +00:00
|
|
|
* 1) ~GrContext will not try to free the objects in the 3D API.
|
2014-07-28 20:48:36 +00:00
|
|
|
* 2) Any GrGpuResources created by this GrContext that outlive
|
|
|
|
* will be marked as invalid (GrGpuResource::wasDestroyed()) and
|
|
|
|
* when they're destroyed no 3D API calls will be made.
|
|
|
|
* Content drawn since the last GrContext::flush() may be lost. After this
|
|
|
|
* function is called the only valid action on the GrContext or
|
|
|
|
* GrGpuResources it created is to destroy them.
|
2011-03-30 21:26:44 +00:00
|
|
|
*/
|
2014-07-28 20:48:36 +00:00
|
|
|
void abandonContext();
|
2011-06-08 22:55:10 +00:00
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Resource Cache
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current GPU resource cache limits.
|
|
|
|
*
|
|
|
|
* @param maxResources If non-null, returns maximum number of resources that
|
|
|
|
* can be held in the cache.
|
|
|
|
* @param maxResourceBytes If non-null, returns maximum number of bytes of
|
|
|
|
* video memory that can be held in the cache.
|
|
|
|
*/
|
|
|
|
void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current GPU resource cache usage.
|
|
|
|
*
|
|
|
|
* @param resourceCount If non-null, returns the number of resources that are held in the
|
|
|
|
* cache.
|
|
|
|
* @param maxResourceBytes If non-null, returns the total number of bytes of video memory held
|
|
|
|
* in the cache.
|
|
|
|
*/
|
|
|
|
void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param maxResources The maximum number of resources that can be held in
|
|
|
|
* the cache.
|
|
|
|
* @param maxResourceBytes The maximum number of bytes of video memory
|
|
|
|
* that can be held in the cache.
|
|
|
|
*/
|
|
|
|
void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
|
|
|
|
|
2015-04-30 21:18:54 +00:00
|
|
|
GrTextureProvider* textureProvider() { return fTextureProvider; }
|
|
|
|
const GrTextureProvider* textureProvider() const { return fTextureProvider; }
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
2012-10-15 14:25:31 +00:00
|
|
|
* Frees GPU created by the context. Can be called to reduce GPU memory
|
2011-03-30 21:26:44 +00:00
|
|
|
* pressure.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2011-03-30 21:26:44 +00:00
|
|
|
void freeGpuResources();
|
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
/**
|
|
|
|
* 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 purgeAllUnlockedResources();
|
|
|
|
|
2015-05-29 15:02:10 +00:00
|
|
|
/** Access the context capabilities */
|
|
|
|
const GrCaps* caps() const { return fCaps; }
|
2013-03-19 13:58:55 +00:00
|
|
|
|
2014-03-10 07:40:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the recommended sample count for a render target when using this
|
|
|
|
* context.
|
|
|
|
*
|
|
|
|
* @param config the configuration of the render target.
|
|
|
|
* @param dpi the display density in dots per inch.
|
|
|
|
*
|
|
|
|
* @return 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.
|
|
|
|
*/
|
|
|
|
int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
2015-06-26 18:45:03 +00:00
|
|
|
* Returns a helper object to orchestrate draws.
|
2015-10-17 14:43:27 +00:00
|
|
|
* Callers assume the creation ref of the drawContext
|
2015-06-17 12:43:33 +00:00
|
|
|
* NULL will be returned if the context has been abandoned.
|
|
|
|
*
|
2015-10-15 15:01:48 +00:00
|
|
|
* @param rt the render target receiving the draws
|
2015-07-07 17:05:18 +00:00
|
|
|
* @param surfaceProps the surface properties (mainly defines text drawing)
|
2011-02-22 20:59:41 +00:00
|
|
|
*
|
2015-05-26 18:38:03 +00:00
|
|
|
* @return a draw context
|
2014-12-18 15:47:16 +00:00
|
|
|
*/
|
2015-10-17 14:43:27 +00:00
|
|
|
GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps = NULL);
|
2015-10-16 16:07:06 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Misc.
|
|
|
|
|
2011-03-10 14:13:19 +00:00
|
|
|
/**
|
|
|
|
* Flags that affect flush() behavior.
|
|
|
|
*/
|
|
|
|
enum FlushBits {
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
kDiscard_FlushBit = 0x2,
|
|
|
|
};
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
|
|
|
* Call to ensure all drawing to the context has been issued to the
|
|
|
|
* underlying 3D API.
|
2011-03-10 14:13:19 +00:00
|
|
|
* @param flagsBitfield flags that control the flushing behavior. See
|
|
|
|
* FlushBits.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2011-03-30 21:26:44 +00:00
|
|
|
void flush(int flagsBitfield = 0);
|
2011-11-16 20:36:03 +00:00
|
|
|
|
2015-05-26 18:38:03 +00:00
|
|
|
void flushIfNecessary() {
|
2015-11-11 21:18:11 +00:00
|
|
|
if (fFlushToReduceCacheSize || this->caps()->immediateFlush()) {
|
2015-05-26 18:38:03 +00:00
|
|
|
this->flush();
|
2015-06-26 18:45:03 +00:00
|
|
|
}
|
2015-05-26 18:38:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 19:22:38 +00:00
|
|
|
/**
|
|
|
|
* These flags can be used with the read/write pixels functions below.
|
|
|
|
*/
|
|
|
|
enum PixelOpsFlags {
|
2014-10-07 12:56:02 +00:00
|
|
|
/** 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. */
|
2012-08-20 19:22:38 +00:00
|
|
|
kDontFlush_PixelOpsFlag = 0x1,
|
2014-10-07 12:56:02 +00:00
|
|
|
/** Any surface writes should be flushed to the backend 3D API after the surface operation
|
|
|
|
is complete */
|
|
|
|
kFlushWrites_PixelOp = 0x2,
|
2012-08-20 19:22:38 +00:00
|
|
|
/** 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. */
|
2014-10-07 12:56:02 +00:00
|
|
|
kUnpremul_PixelOpsFlag = 0x4,
|
2012-08-20 19:22:38 +00:00
|
|
|
};
|
|
|
|
|
2011-04-05 17:08:27 +00:00
|
|
|
/**
|
2015-07-16 15:23:13 +00:00
|
|
|
* Reads a rectangle of pixels from a surface.
|
|
|
|
* @param surface the surface to read from.
|
2011-04-05 17:08:27 +00:00
|
|
|
* @param left left edge of the rectangle to read (inclusive)
|
|
|
|
* @param top top edge of the rectangle to read (inclusive)
|
|
|
|
* @param width width of rectangle to read in pixels.
|
|
|
|
* @param height height of rectangle to read in pixels.
|
|
|
|
* @param config the pixel config of the destination buffer
|
|
|
|
* @param buffer memory to read the rectangle into.
|
2012-08-20 19:22:38 +00:00
|
|
|
* @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly
|
|
|
|
* packed.
|
|
|
|
* @param pixelOpsFlags see PixelOpsFlags enum above.
|
2011-04-05 17:08:27 +00:00
|
|
|
*
|
2012-08-20 19:22:38 +00:00
|
|
|
* @return true if the read succeeded, false if not. The read can fail because of an unsupported
|
2015-07-16 15:23:13 +00:00
|
|
|
* pixel configs
|
2011-04-05 17:08:27 +00:00
|
|
|
*/
|
2015-07-16 15:23:13 +00:00
|
|
|
bool readSurfacePixels(GrSurface* surface,
|
|
|
|
int left, int top, int width, int height,
|
|
|
|
GrPixelConfig config, void* buffer,
|
|
|
|
size_t rowBytes = 0,
|
|
|
|
uint32_t pixelOpsFlags = 0);
|
2011-11-16 20:36:03 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-13 19:32:55 +00:00
|
|
|
* Writes a rectangle of pixels to a surface.
|
|
|
|
* @param surface the surface to write to.
|
2011-11-16 20:36:03 +00:00
|
|
|
* @param left left edge of the rectangle to write (inclusive)
|
|
|
|
* @param top top edge of the rectangle to write (inclusive)
|
|
|
|
* @param width width of rectangle to write in pixels.
|
|
|
|
* @param height height of rectangle to write in pixels.
|
|
|
|
* @param config the pixel config of the source buffer
|
|
|
|
* @param buffer memory to read pixels from
|
2012-10-12 14:51:52 +00:00
|
|
|
* @param rowBytes number of bytes between consecutive rows. Zero
|
2011-11-16 20:36:03 +00:00
|
|
|
* means rows are tightly packed.
|
2012-08-20 19:22:38 +00:00
|
|
|
* @param pixelOpsFlags see PixelOpsFlags enum above.
|
2013-02-06 18:17:50 +00:00
|
|
|
* @return true if the write succeeded, false if not. The write can fail because of an
|
2014-10-13 19:32:55 +00:00
|
|
|
* unsupported combination of surface and src configs.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2014-10-13 19:32:55 +00:00
|
|
|
bool writeSurfacePixels(GrSurface* surface,
|
2011-11-16 20:36:03 +00:00
|
|
|
int left, int top, int width, int height,
|
|
|
|
GrPixelConfig config, const void* buffer,
|
2012-08-20 19:22:38 +00:00
|
|
|
size_t rowBytes,
|
|
|
|
uint32_t pixelOpsFlags = 0);
|
|
|
|
|
2011-12-02 19:11:17 +00:00
|
|
|
/**
|
2014-10-07 12:56:02 +00:00
|
|
|
* Copies a rectangle of texels from src to dst.
|
2012-12-07 19:14:45 +00:00
|
|
|
* bounds.
|
2014-10-07 12:56:02 +00:00
|
|
|
* @param dst the surface to copy to.
|
|
|
|
* @param src the surface to copy from.
|
|
|
|
* @param srcRect the rectangle of the src that should be copied.
|
|
|
|
* @param dstPoint the translation applied when writing the srcRect's pixels to the dst.
|
|
|
|
* @param pixelOpsFlags see PixelOpsFlags enum above. (kUnpremul_PixelOpsFlag is not allowed).
|
|
|
|
*/
|
|
|
|
void copySurface(GrSurface* dst,
|
|
|
|
GrSurface* src,
|
|
|
|
const SkIRect& srcRect,
|
|
|
|
const SkIPoint& dstPoint,
|
|
|
|
uint32_t pixelOpsFlags = 0);
|
|
|
|
|
|
|
|
/** Helper that copies the whole surface but fails when the two surfaces are not identically
|
|
|
|
sized. */
|
|
|
|
bool copySurface(GrSurface* dst, GrSurface* src) {
|
|
|
|
if (NULL == dst || NULL == src || dst->width() != src->width() ||
|
|
|
|
dst->height() != src->height()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this->copySurface(dst, src, SkIRect::MakeWH(dst->width(), dst->height()),
|
|
|
|
SkIPoint::Make(0,0));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* After this returns any pending writes to the surface will have been issued to the backend 3D API.
|
2011-12-02 19:11:17 +00:00
|
|
|
*/
|
2014-10-07 12:56:02 +00:00
|
|
|
void flushSurfaceWrites(GrSurface* surface);
|
2012-01-31 13:35:56 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-30 18:37:35 +00:00
|
|
|
* Finalizes all pending reads and writes to the surface and also performs an MSAA resolve
|
|
|
|
* if necessary.
|
2012-01-31 13:35:56 +00:00
|
|
|
*
|
2014-11-03 22:28:32 +00:00
|
|
|
* 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.
|
2012-01-31 13:35:56 +00:00
|
|
|
*/
|
2015-06-30 18:37:35 +00:00
|
|
|
void prepareSurfaceForExternalIO(GrSurface*);
|
2014-03-28 16:08:05 +00:00
|
|
|
|
2015-05-07 15:23:19 +00:00
|
|
|
/**
|
|
|
|
* An ID associated with this context, guaranteed to be unique.
|
|
|
|
*/
|
|
|
|
uint32_t uniqueID() { return fUniqueID; }
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Functions intended for internal use only.
|
|
|
|
GrGpu* getGpu() { return fGpu; }
|
2011-08-23 20:54:07 +00:00
|
|
|
const GrGpu* getGpu() const { return fGpu; }
|
2015-03-31 20:32:05 +00:00
|
|
|
GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; }
|
2014-04-03 00:34:27 +00:00
|
|
|
GrLayerCache* getLayerCache() { return fLayerCache.get(); }
|
2015-04-08 16:08:31 +00:00
|
|
|
GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; }
|
2015-10-17 14:43:27 +00:00
|
|
|
bool abandoned() const;
|
2015-04-30 21:18:54 +00:00
|
|
|
GrResourceProvider* resourceProvider() { return fResourceProvider; }
|
|
|
|
const GrResourceProvider* resourceProvider() const { return fResourceProvider; }
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* getResourceCache() { return fResourceCache; }
|
2012-06-06 18:21:18 +00:00
|
|
|
|
2013-08-21 19:27:48 +00:00
|
|
|
// Called by tests that draw directly to the context via GrDrawTarget
|
2015-11-16 19:02:05 +00:00
|
|
|
void getTestTarget(GrTestTarget*, GrRenderTarget* rt);
|
2013-08-21 19:27:48 +00:00
|
|
|
|
2015-12-02 17:05:37 +00:00
|
|
|
/** Reset GPU stats */
|
|
|
|
void resetGpuStats() const ;
|
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
/** Prints cache stats to the string if GR_CACHE_STATS == 1. */
|
|
|
|
void dumpCacheStats(SkString*) const;
|
2015-12-02 22:08:25 +00:00
|
|
|
void dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
|
2012-08-22 10:57:05 +00:00
|
|
|
void printCacheStats() const;
|
2014-09-18 20:52:08 +00:00
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
/** Prints GPU stats to the string if GR_GPU_STATS == 1. */
|
|
|
|
void dumpGpuStats(SkString*) const;
|
2015-12-02 22:08:25 +00:00
|
|
|
void dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) const;
|
2015-02-03 02:26:03 +00:00
|
|
|
void printGpuStats() const;
|
2014-09-18 20:52:08 +00:00
|
|
|
|
2015-08-03 17:17:44 +00:00
|
|
|
/** Specify the TextBlob cache limit. If the current cache exceeds this limit it will purge.
|
|
|
|
this is for testing only */
|
|
|
|
void setTextBlobCacheLimit_ForTesting(size_t bytes);
|
|
|
|
|
2015-08-19 15:16:43 +00:00
|
|
|
/** Specify the sizes of the GrAtlasTextContext atlases. The configs pointer below should be
|
|
|
|
to an array of 3 entries */
|
|
|
|
void setTextContextAtlasSizes_ForTesting(const GrBatchAtlasConfig* configs);
|
|
|
|
|
2015-09-15 21:16:10 +00:00
|
|
|
/** Enumerates all cached GPU resources and dumps their memory to traceMemoryDump. */
|
|
|
|
void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
|
|
|
|
|
2015-12-09 02:53:44 +00:00
|
|
|
/** Get pointer to atlas texture for given mask format */
|
|
|
|
GrTexture* getFontAtlasTexture(GrMaskFormat format);
|
2015-11-08 16:07:24 +00:00
|
|
|
|
2016-01-11 18:39:11 +00:00
|
|
|
GrAuditTrail* getAuditTrail() { return &fAuditTrail; }
|
2016-01-08 15:19:47 +00:00
|
|
|
|
2016-01-11 21:29:31 +00:00
|
|
|
/** This is only useful for debug purposes */
|
|
|
|
SkDEBUGCODE(GrSingleOwner* debugSingleOwner() const { return &fSingleOwner; } )
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
private:
|
2013-05-28 17:25:49 +00:00
|
|
|
GrGpu* fGpu;
|
2015-05-29 15:02:10 +00:00
|
|
|
const GrCaps* fCaps;
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* fResourceCache;
|
2015-04-30 21:18:54 +00:00
|
|
|
// this union exists because the inheritance of GrTextureProvider->GrResourceProvider
|
|
|
|
// is in a private header.
|
2015-06-26 18:45:03 +00:00
|
|
|
union {
|
2015-04-30 21:18:54 +00:00
|
|
|
GrResourceProvider* fResourceProvider;
|
|
|
|
GrTextureProvider* fTextureProvider;
|
|
|
|
};
|
|
|
|
|
2015-03-31 20:32:05 +00:00
|
|
|
GrBatchFontCache* fBatchFontCache;
|
2014-04-03 00:34:27 +00:00
|
|
|
SkAutoTDelete<GrLayerCache> fLayerCache;
|
2015-04-08 16:08:31 +00:00
|
|
|
SkAutoTDelete<GrTextBlobCache> fTextBlobCache;
|
2011-03-25 12:31:16 +00:00
|
|
|
|
2014-11-13 21:33:28 +00:00
|
|
|
// Set by OverbudgetCB() to request that GrContext flush before exiting a draw.
|
|
|
|
bool fFlushToReduceCacheSize;
|
2013-05-28 17:25:49 +00:00
|
|
|
bool fDidTestPMConversions;
|
|
|
|
int fPMToUPMConversion;
|
|
|
|
int fUPMToPMConversion;
|
2015-09-10 15:12:46 +00:00
|
|
|
// The sw backend may call GrContext::readSurfacePixels on multiple threads
|
|
|
|
// We may transfer the responsibilty for using a mutex to the sw backend
|
|
|
|
// when there are fewer code paths that lead to a readSurfacePixels call
|
|
|
|
// from the sw backend. readSurfacePixels is reentrant in one case - when performing
|
|
|
|
// the PM conversions test. To handle this we do the PM conversions test outside
|
|
|
|
// of fReadPixelsMutex and use a separate mutex to guard it. When it re-enters
|
|
|
|
// readSurfacePixels it will grab fReadPixelsMutex and release it before the outer
|
|
|
|
// readSurfacePixels proceeds to grab it.
|
|
|
|
// TODO: Stop pretending to make GrContext thread-safe for sw rasterization and provide
|
|
|
|
// a mechanism to make a SkPicture safe for multithreaded sw rasterization.
|
|
|
|
SkMutex fReadPixelsMutex;
|
|
|
|
SkMutex fTestPMConversionsMutex;
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2016-01-06 16:26:09 +00:00
|
|
|
// In debug builds we guard against improper thread handling
|
2016-01-08 18:09:13 +00:00
|
|
|
// This guard is passed to the GrDrawingManager and, from there to all the
|
|
|
|
// GrDrawContexts. It is also passed to the GrTextureProvider and SkGpuDevice.
|
|
|
|
mutable GrSingleOwner fSingleOwner;
|
2016-01-06 16:26:09 +00:00
|
|
|
|
2012-09-24 19:33:59 +00:00
|
|
|
struct CleanUpData {
|
|
|
|
PFCleanUpFunc fFunc;
|
|
|
|
void* fInfo;
|
|
|
|
};
|
|
|
|
|
2013-07-25 15:32:06 +00:00
|
|
|
SkTDArray<CleanUpData> fCleanUpData;
|
|
|
|
|
2015-05-07 15:23:19 +00:00
|
|
|
const uint32_t fUniqueID;
|
2014-08-12 14:26:25 +00:00
|
|
|
|
2015-10-17 14:43:27 +00:00
|
|
|
SkAutoTDelete<GrDrawingManager> fDrawingManager;
|
|
|
|
|
2016-01-08 15:19:47 +00:00
|
|
|
GrAuditTrail fAuditTrail;
|
|
|
|
|
2015-10-29 19:12:21 +00:00
|
|
|
// TODO: have the CMM use drawContexts and rm this friending
|
|
|
|
friend class GrClipMaskManager; // the CMM is friended just so it can call 'drawingManager'
|
2015-11-11 20:01:09 +00:00
|
|
|
friend class GrDrawingManager; // for access to drawingManager for ProgramUnitTest
|
2015-10-29 19:12:21 +00:00
|
|
|
GrDrawingManager* drawingManager() { return fDrawingManager; }
|
|
|
|
|
2015-05-22 21:01:46 +00:00
|
|
|
GrContext(); // init must be called after the constructor.
|
|
|
|
bool init(GrBackend, GrBackendContext, const GrContextOptions& options);
|
2015-05-26 18:38:03 +00:00
|
|
|
|
2014-11-05 22:47:41 +00:00
|
|
|
void initMockContext();
|
2015-11-30 21:27:47 +00:00
|
|
|
void initCommon(const GrContextOptions&);
|
2011-04-25 12:43:45 +00:00
|
|
|
|
2013-01-29 07:05:52 +00:00
|
|
|
/**
|
2013-01-28 14:26:09 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2015-10-06 15:40:50 +00:00
|
|
|
const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB,
|
|
|
|
const SkMatrix&) const;
|
|
|
|
const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB,
|
|
|
|
const SkMatrix&) const;
|
2015-09-10 15:12:46 +00:00
|
|
|
/** Called before either of the above two functions to determine the appropriate fragment
|
2015-10-06 15:40:50 +00:00
|
|
|
processors for conversions. This must be called by readSurfacePixels before a mutex is
|
|
|
|
taken, since testingvPM conversions itself will call readSurfacePixels */
|
2015-09-10 15:12:46 +00:00
|
|
|
void testPMConversionsIfNecessary(uint32_t flags);
|
2015-07-29 13:08:46 +00:00
|
|
|
/** Returns true if we've already determined that createPMtoUPMEffect and createUPMToPMEffect
|
|
|
|
will fail. In such cases fall back to SW conversion. */
|
|
|
|
bool didFailPMUPMConversionTest() const;
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2013-07-10 10:14:35 +00:00
|
|
|
/**
|
|
|
|
* This callback allows the resource cache to callback into the GrContext
|
2014-11-14 20:10:14 +00:00
|
|
|
* when the cache is still over budget after a purge.
|
2013-07-10 10:14:35 +00:00
|
|
|
*/
|
2014-11-14 20:10:14 +00:00
|
|
|
static void OverBudgetCB(void* data);
|
2013-07-10 10:14:35 +00:00
|
|
|
|
2015-04-10 14:01:30 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static void TextBlobCacheOverBudgetCB(void* data);
|
|
|
|
|
2013-09-09 13:38:37 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2011-02-22 20:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|