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
|
|
|
|
|
2012-08-01 20:08:47 +00:00
|
|
|
#include "GrClipData.h"
|
2013-09-18 13:00:55 +00:00
|
|
|
#include "GrColor.h"
|
2012-10-17 12:53:54 +00:00
|
|
|
#include "GrPaint.h"
|
2012-12-10 19:10:17 +00:00
|
|
|
#include "GrPathRendererChain.h"
|
2012-08-23 18:09:54 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2012-10-17 12:53:54 +00:00
|
|
|
#include "GrTexture.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"
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2013-09-06 16:57:29 +00:00
|
|
|
class GrAARectRenderer;
|
2012-03-05 20:41:22 +00:00
|
|
|
class GrAutoScratchTexture;
|
2012-03-30 14:35:04 +00:00
|
|
|
class GrDrawState;
|
2011-08-17 13:42:46 +00:00
|
|
|
class GrDrawTarget;
|
2011-02-22 20:59:41 +00:00
|
|
|
class GrFontCache;
|
2014-09-23 16:50:21 +00:00
|
|
|
class GrFragmentProcessor;
|
2011-05-02 21:14:59 +00:00
|
|
|
class GrGpu;
|
2014-06-19 17:19:29 +00:00
|
|
|
class GrGpuTraceMarker;
|
2011-08-17 13:42:46 +00:00
|
|
|
class GrIndexBuffer;
|
2011-02-22 20:59:41 +00:00
|
|
|
class GrIndexBufferAllocPool;
|
|
|
|
class GrInOrderDrawBuffer;
|
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;
|
2011-08-17 13:42:46 +00:00
|
|
|
class GrPathRenderer;
|
2011-07-26 20:45:30 +00:00
|
|
|
class GrResourceEntry;
|
|
|
|
class GrResourceCache;
|
2014-08-21 20:02:13 +00:00
|
|
|
class GrResourceCache2;
|
2011-08-08 17:01:14 +00:00
|
|
|
class GrStencilBuffer;
|
2013-08-21 19:27:48 +00:00
|
|
|
class GrTestTarget;
|
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;
|
2011-07-26 20:45:30 +00:00
|
|
|
class GrVertexBufferAllocPool;
|
2014-06-11 17:30:05 +00:00
|
|
|
class GrStrokeInfo;
|
2012-05-23 13:19:12 +00:00
|
|
|
class GrSoftwarePathRenderer;
|
2012-12-17 21:16:45 +00:00
|
|
|
class SkStrokeRec;
|
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-06-26 20:16:17 +00:00
|
|
|
SK_DECLARE_INST_COUNT(GrContext)
|
|
|
|
|
2014-08-12 14:26:25 +00:00
|
|
|
struct Options {
|
|
|
|
Options() : fDrawPathToCompressedTexture(false) { }
|
|
|
|
|
|
|
|
// EXPERIMENTAL
|
|
|
|
// May be removed in the future, or may become standard depending
|
|
|
|
// on the outcomes of a variety of internal tests.
|
|
|
|
bool fDrawPathToCompressedTexture;
|
|
|
|
};
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
2012-10-25 18:43:28 +00:00
|
|
|
* Creates a GrContext for a backend context.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2014-08-12 14:26:25 +00:00
|
|
|
static GrContext* Create(GrBackend, GrBackendContext, const Options* opts = NULL);
|
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
|
|
|
/**
|
2014-07-28 20:48:36 +00:00
|
|
|
* 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. 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();
|
|
|
|
void contextDestroyed() { this->abandonContext(); } // legacy alias
|
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;
|
|
|
|
SK_ATTR_DEPRECATED("This function has been renamed to getResourceCacheLimits().")
|
|
|
|
void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const {
|
|
|
|
this->getResourceCacheLimits(maxTextures, maxTextureBytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
SK_ATTR_DEPRECATED("Use getResourceCacheUsage().")
|
|
|
|
size_t getGpuTextureCacheBytes() const {
|
|
|
|
size_t bytes;
|
|
|
|
this->getResourceCacheUsage(NULL, &bytes);
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
SK_ATTR_DEPRECATED("Use getResourceCacheUsage().")
|
|
|
|
int getGpuTextureCacheResourceCount() const {
|
|
|
|
int count;
|
|
|
|
this->getResourceCacheUsage(&count, NULL);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
SK_ATTR_DEPRECATED("This function has been renamed to setResourceCacheLimits().")
|
|
|
|
void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes) {
|
|
|
|
this->setResourceCacheLimits(maxTextures, maxTextureBytes);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2012-06-22 15:15:59 +00:00
|
|
|
/**
|
2014-05-09 14:29:32 +00:00
|
|
|
* This method should be called whenever a GrResource is unreffed or
|
|
|
|
* switched from exclusive to non-exclusive. This
|
|
|
|
* gives the resource cache a chance to discard unneeded resources.
|
|
|
|
* Note: this entry point will be removed once totally ref-driven
|
|
|
|
* cache maintenance is implemented.
|
2012-06-22 15:15:59 +00:00
|
|
|
*/
|
2014-05-09 14:29:32 +00:00
|
|
|
void purgeCache();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a custom resource in the cache, based on the specified key.
|
|
|
|
*/
|
2014-07-25 15:35:45 +00:00
|
|
|
void addResourceToCache(const GrResourceKey&, GrGpuResource*);
|
2012-06-22 15:15:59 +00:00
|
|
|
|
2014-03-19 21:19:16 +00:00
|
|
|
/**
|
2014-05-09 14:29:32 +00:00
|
|
|
* Finds a resource in the cache, based on the specified key. This is intended for use in
|
|
|
|
* conjunction with addResourceToCache(). The return value will be NULL if not found. The
|
|
|
|
* caller must balance with a call to unref().
|
2014-03-19 21:19:16 +00:00
|
|
|
*/
|
2014-07-25 15:35:45 +00:00
|
|
|
GrGpuResource* findAndRefCachedResource(const GrResourceKey&);
|
2014-03-19 21:19:16 +00:00
|
|
|
|
2014-06-24 07:12:27 +00:00
|
|
|
/**
|
|
|
|
* Creates a new text rendering context that is optimal for the
|
|
|
|
* render target and the context. Caller assumes the ownership
|
|
|
|
* of the returned object. The returned object must be deleted
|
|
|
|
* before the context is destroyed.
|
|
|
|
*/
|
|
|
|
GrTextContext* createTextContext(GrRenderTarget*,
|
|
|
|
const SkDeviceProperties&,
|
|
|
|
bool enableDistanceFieldFonts);
|
|
|
|
|
2011-03-30 21:26:44 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Textures
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2011-12-12 16:10:08 +00:00
|
|
|
/**
|
2013-01-24 14:46:47 +00:00
|
|
|
* Creates a new entry, based on the specified key and texture and returns it. The caller owns a
|
|
|
|
* ref on the returned texture which must be balanced by a call to unref.
|
2011-12-12 16:10:08 +00:00
|
|
|
*
|
2012-10-15 14:25:31 +00:00
|
|
|
* @param params The texture params used to draw a texture may help determine
|
2012-07-25 21:27:09 +00:00
|
|
|
* the cache entry used. (e.g. different versions may exist
|
|
|
|
* for different wrap modes on GPUs with limited NPOT
|
|
|
|
* texture support). NULL implies clamp wrap modes.
|
2011-12-12 16:10:08 +00:00
|
|
|
* @param desc Description of the texture properties.
|
2014-06-02 14:38:14 +00:00
|
|
|
* @param cacheID Cache-specific properties (e.g., texture gen ID)
|
2011-12-12 16:10:08 +00:00
|
|
|
* @param srcData Pointer to the pixel values.
|
|
|
|
* @param rowBytes The number of bytes between rows of the texture. Zero
|
2014-06-02 14:38:14 +00:00
|
|
|
* implies tightly packed rows. For compressed pixel configs, this
|
|
|
|
* field is ignored.
|
2013-10-24 17:44:27 +00:00
|
|
|
* @param cacheKey (optional) If non-NULL, we'll write the cache key we used to cacheKey.
|
2011-12-12 16:10:08 +00:00
|
|
|
*/
|
2012-09-09 14:44:15 +00:00
|
|
|
GrTexture* createTexture(const GrTextureParams* params,
|
|
|
|
const GrTextureDesc& desc,
|
2012-12-20 15:13:01 +00:00
|
|
|
const GrCacheID& cacheID,
|
2014-05-29 19:26:48 +00:00
|
|
|
const void* srcData,
|
2013-10-24 17:44:27 +00:00
|
|
|
size_t rowBytes,
|
|
|
|
GrResourceKey* cacheKey = NULL);
|
2011-07-26 20:45:30 +00:00
|
|
|
/**
|
2013-01-24 14:46:47 +00:00
|
|
|
* Search for an entry based on key and dimensions. If found, ref it and return it. The return
|
|
|
|
* value will be NULL if not found. The caller must balance with a call to unref.
|
2011-12-12 16:10:08 +00:00
|
|
|
*
|
2012-07-25 21:27:09 +00:00
|
|
|
* @param desc Description of the texture properties.
|
2012-12-20 15:13:01 +00:00
|
|
|
* @param cacheID Cache-specific properties (e.g., texture gen ID)
|
2012-10-15 14:25:31 +00:00
|
|
|
* @param params The texture params used to draw a texture may help determine
|
2012-07-25 21:27:09 +00:00
|
|
|
* the cache entry used. (e.g. different versions may exist
|
|
|
|
* for different wrap modes on GPUs with limited NPOT
|
|
|
|
* texture support). NULL implies clamp wrap modes.
|
2011-07-26 20:45:30 +00:00
|
|
|
*/
|
2013-01-24 14:46:47 +00:00
|
|
|
GrTexture* findAndRefTexture(const GrTextureDesc& desc,
|
|
|
|
const GrCacheID& cacheID,
|
|
|
|
const GrTextureParams* params);
|
2011-11-30 14:13:48 +00:00
|
|
|
/**
|
|
|
|
* Determines whether a texture is in the cache. If the texture is found it
|
|
|
|
* will not be locked or returned. This call does not affect the priority of
|
|
|
|
* the texture for deletion.
|
|
|
|
*/
|
2012-06-07 12:08:45 +00:00
|
|
|
bool isTextureInCache(const GrTextureDesc& desc,
|
2012-12-20 15:13:01 +00:00
|
|
|
const GrCacheID& cacheID,
|
2012-07-25 21:27:09 +00:00
|
|
|
const GrTextureParams* params) const;
|
2011-07-26 20:45:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enum that determines how closely a returned scratch texture must match
|
|
|
|
* a provided GrTextureDesc.
|
|
|
|
*/
|
|
|
|
enum ScratchTexMatch {
|
|
|
|
/**
|
|
|
|
* Finds a texture that exactly matches the descriptor.
|
|
|
|
*/
|
|
|
|
kExact_ScratchTexMatch,
|
|
|
|
/**
|
|
|
|
* Finds a texture that approximately matches the descriptor. Will be
|
|
|
|
* at least as large in width and height as desc specifies. If desc
|
|
|
|
* specifies that texture is a render target then result will be a
|
|
|
|
* render target. If desc specifies a render target and doesn't set the
|
|
|
|
* no stencil flag then result will have a stencil. Format and aa level
|
|
|
|
* will always match.
|
|
|
|
*/
|
|
|
|
kApprox_ScratchTexMatch
|
|
|
|
};
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
/**
|
2011-04-25 15:51:06 +00:00
|
|
|
* Returns a texture matching the desc. It's contents are unknown. Subsequent
|
|
|
|
* requests with the same descriptor are not guaranteed to return the same
|
|
|
|
* texture. The same texture is guaranteed not be returned again until it is
|
2013-01-24 14:46:47 +00:00
|
|
|
* unlocked. Call must be balanced with an unlockTexture() call. The caller
|
|
|
|
* owns a ref on the returned texture and must balance with a call to unref.
|
2011-04-26 13:18:16 +00:00
|
|
|
*
|
|
|
|
* Textures created by createAndLockTexture() hide the complications of
|
2012-08-23 18:09:54 +00:00
|
|
|
* tiling non-power-of-two textures on APIs that don't support this (e.g.
|
2012-10-15 14:25:31 +00:00
|
|
|
* unextended GLES2). Tiling a NPOT texture created by lockScratchTexture on
|
2011-04-26 13:18:16 +00:00
|
|
|
* such an API will create gaps in the tiling pattern. This includes clamp
|
2014-10-07 19:07:38 +00:00
|
|
|
* mode. (This may be addressed in a future update.)
|
|
|
|
*/
|
|
|
|
GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch match);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When done with an entry, call unlockScratchTexture(entry) on it, which returns
|
|
|
|
* it to the cache, where it may be purged. This does not unref the texture.
|
2014-09-30 13:54:17 +00:00
|
|
|
*/
|
2014-10-07 19:07:38 +00:00
|
|
|
void unlockScratchTexture(GrTexture* texture);
|
2014-09-30 13:54:17 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
|
|
|
* Creates a texture that is outside the cache. Does not count against
|
|
|
|
* cache's budget.
|
|
|
|
*/
|
2012-06-07 12:08:45 +00:00
|
|
|
GrTexture* createUncachedTexture(const GrTextureDesc& desc,
|
2011-02-22 20:59:41 +00:00
|
|
|
void* srcData,
|
|
|
|
size_t rowBytes);
|
|
|
|
|
|
|
|
/**
|
2012-07-25 21:27:09 +00:00
|
|
|
* Returns true if the specified use of an indexed texture is supported.
|
|
|
|
* Support may depend upon whether the texture params indicate that the
|
|
|
|
* texture will be tiled. Passing NULL for the texture params indicates
|
|
|
|
* clamp mode.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2012-07-25 21:27:09 +00:00
|
|
|
bool supportsIndex8PixelConfig(const GrTextureParams*,
|
2011-08-23 20:54:07 +00:00
|
|
|
int width,
|
|
|
|
int height) const;
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
/**
|
2012-10-15 14:25:31 +00:00
|
|
|
* Return the max width or height of a texture supported by the current GPU.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2011-06-13 17:58:13 +00:00
|
|
|
int getMaxTextureSize() const;
|
|
|
|
|
2013-07-25 15:32:06 +00:00
|
|
|
/**
|
2013-07-26 07:00:58 +00:00
|
|
|
* Temporarily override the true max texture size. Note: an override
|
2013-07-25 15:32:06 +00:00
|
|
|
* larger then the true max texture size will have no effect.
|
|
|
|
* This entry point is mainly meant for testing texture size dependent
|
|
|
|
* features and is only available if defined outside of Skia (see
|
|
|
|
* bleed GM.
|
|
|
|
*/
|
|
|
|
void setMaxTextureSizeOverride(int maxTextureSizeOverride);
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Render targets
|
|
|
|
|
|
|
|
/**
|
2011-04-11 17:58:48 +00:00
|
|
|
* Sets the render target.
|
2013-05-28 17:25:49 +00:00
|
|
|
* @param target the render target to set.
|
2011-04-11 17:58:48 +00:00
|
|
|
*/
|
2013-05-28 17:25:49 +00:00
|
|
|
void setRenderTarget(GrRenderTarget* target) {
|
|
|
|
fRenderTarget.reset(SkSafeRef(target));
|
|
|
|
}
|
2011-04-11 17:58:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current render target.
|
2013-05-28 17:25:49 +00:00
|
|
|
* @return the currently bound render target.
|
2011-04-11 17:58:48 +00:00
|
|
|
*/
|
2013-05-28 17:25:49 +00:00
|
|
|
const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
|
|
|
|
GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); }
|
2011-04-11 17:58:48 +00:00
|
|
|
|
2012-04-10 19:26:38 +00:00
|
|
|
/**
|
|
|
|
* Can the provided configuration act as a color render target?
|
|
|
|
*/
|
2013-10-15 14:18:16 +00:00
|
|
|
bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const;
|
2012-04-10 19:26:38 +00:00
|
|
|
|
2013-03-19 13:58:55 +00:00
|
|
|
/**
|
|
|
|
* Return the max width or height of a render target supported by the
|
|
|
|
* current GPU.
|
|
|
|
*/
|
|
|
|
int getMaxRenderTargetSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the max sample count for a render target. It will be 0 if MSAA
|
|
|
|
* is not supported.
|
|
|
|
*/
|
|
|
|
int getMaxSampleCount() const;
|
|
|
|
|
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-04-11 17:58:48 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2012-10-25 18:43:28 +00:00
|
|
|
// Backend Surfaces
|
2011-04-11 17:58:48 +00:00
|
|
|
|
|
|
|
/**
|
2011-11-07 13:29:52 +00:00
|
|
|
* Wraps an existing texture with a GrTexture object.
|
|
|
|
*
|
|
|
|
* OpenGL: if the object is a texture Gr may change its GL texture params
|
|
|
|
* when it is drawn.
|
|
|
|
*
|
|
|
|
* @param desc description of the object to create.
|
|
|
|
*
|
|
|
|
* @return GrTexture object or NULL on failure.
|
|
|
|
*/
|
2012-10-25 18:43:28 +00:00
|
|
|
GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc);
|
2011-11-07 13:29:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps an existing render target with a GrRenderTarget object. It is
|
2012-10-25 18:43:28 +00:00
|
|
|
* similar to wrapBackendTexture but can be used to draw into surfaces
|
2011-11-07 13:29:52 +00:00
|
|
|
* that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
|
|
|
|
* the client will resolve to a texture).
|
|
|
|
*
|
|
|
|
* @param desc description of the object to create.
|
|
|
|
*
|
|
|
|
* @return GrTexture object or NULL on failure.
|
|
|
|
*/
|
2012-10-25 18:43:28 +00:00
|
|
|
GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc);
|
2011-11-07 13:29:52 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Matrix state
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current transformation matrix.
|
|
|
|
* @return the current matrix.
|
|
|
|
*/
|
2013-05-28 17:25:49 +00:00
|
|
|
const SkMatrix& getMatrix() const { return fViewMatrix; }
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the transformation matrix.
|
|
|
|
* @param m the matrix to set.
|
|
|
|
*/
|
2013-05-28 17:25:49 +00:00
|
|
|
void setMatrix(const SkMatrix& m) { fViewMatrix = m; }
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2012-10-08 14:48:36 +00:00
|
|
|
/**
|
|
|
|
* Sets the current transformation matrix to identity.
|
|
|
|
*/
|
2013-05-28 17:25:49 +00:00
|
|
|
void setIdentityMatrix() { fViewMatrix.reset(); }
|
2012-10-08 14:48:36 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
|
|
|
* Concats the current matrix. The passed matrix is applied before the
|
|
|
|
* current matrix.
|
|
|
|
* @param m the matrix to concat.
|
|
|
|
*/
|
2013-05-28 17:25:49 +00:00
|
|
|
void concatMatrix(const SkMatrix& m) { fViewMatrix.preConcat(m); }
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Clip state
|
|
|
|
/**
|
|
|
|
* Gets the current clip.
|
|
|
|
* @return the current clip.
|
|
|
|
*/
|
2013-05-28 17:25:49 +00:00
|
|
|
const GrClipData* getClip() const { return fClip; }
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the clip.
|
2012-07-26 18:52:16 +00:00
|
|
|
* @param clipData the clip to set.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2013-05-28 17:25:49 +00:00
|
|
|
void setClip(const GrClipData* clipData) { fClip = clipData; }
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Draws
|
|
|
|
|
|
|
|
/**
|
2011-04-27 19:55:29 +00:00
|
|
|
* Clear the entire or rect of the render target, ignoring any clips.
|
|
|
|
* @param rect the rect to clear or the whole thing if rect is NULL.
|
|
|
|
* @param color the color to clear to.
|
2013-10-31 21:44:25 +00:00
|
|
|
* @param canIgnoreRect allows partial clears to be converted to whole
|
|
|
|
* clears on platforms for which that is cheap
|
2012-06-21 20:15:48 +00:00
|
|
|
* @param target if non-NULL, the render target to clear otherwise clear
|
|
|
|
* the current render target
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2013-10-31 21:44:25 +00:00
|
|
|
void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect,
|
2012-06-21 20:15:48 +00:00
|
|
|
GrRenderTarget* target = NULL);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw everywhere (respecting the clip) with the paint.
|
|
|
|
*/
|
|
|
|
void drawPaint(const GrPaint& paint);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the rect using a paint.
|
|
|
|
* @param paint describes how to color pixels.
|
2014-06-11 17:30:05 +00:00
|
|
|
* @param strokeInfo the stroke information (width, join, cap), and.
|
|
|
|
* the dash information (intervals, count, phase).
|
|
|
|
* If strokeInfo == NULL, then the rect is filled.
|
2013-11-06 10:08:21 +00:00
|
|
|
* Otherwise, if stroke width == 0, then the stroke
|
2013-11-07 07:02:19 +00:00
|
|
|
* is always a single pixel thick, else the rect is
|
2013-11-06 10:08:21 +00:00
|
|
|
* mitered/beveled stroked based on stroke width.
|
2011-02-22 20:59:41 +00:00
|
|
|
* The rects coords are used to access the paint (through texture matrix)
|
|
|
|
*/
|
|
|
|
void drawRect(const GrPaint& paint,
|
2013-07-17 21:39:42 +00:00
|
|
|
const SkRect&,
|
2014-08-04 16:21:30 +00:00
|
|
|
const GrStrokeInfo* strokeInfo = NULL);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
/**
|
2013-03-20 19:19:53 +00:00
|
|
|
* Maps a rect of local coordinates onto the a rect of destination
|
2014-08-04 16:21:30 +00:00
|
|
|
* coordinates. The localRect is stretched over the dstRect. The dstRect is
|
|
|
|
* transformed by the context's matrix. An additional optional matrix can be
|
|
|
|
* provided to transform the local rect.
|
2011-02-22 20:59:41 +00:00
|
|
|
*
|
2013-03-20 19:19:53 +00:00
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param dstRect the destination rect to draw.
|
|
|
|
* @param localRect rect of local coordinates to be mapped onto dstRect
|
|
|
|
* @param localMatrix Optional matrix to transform localRect.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
|
|
|
void drawRectToRect(const GrPaint& paint,
|
2013-07-17 21:39:42 +00:00
|
|
|
const SkRect& dstRect,
|
|
|
|
const SkRect& localRect,
|
2013-03-20 19:19:53 +00:00
|
|
|
const SkMatrix* localMatrix = NULL);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2013-04-25 15:27:00 +00:00
|
|
|
/**
|
|
|
|
* Draw a roundrect using a paint.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param rrect the roundrect to draw
|
2014-06-11 17:30:05 +00:00
|
|
|
* @param strokeInfo the stroke information (width, join, cap) and
|
|
|
|
* the dash information (intervals, count, phase).
|
2013-04-25 15:27:00 +00:00
|
|
|
*/
|
2014-06-11 17:30:05 +00:00
|
|
|
void drawRRect(const GrPaint& paint, const SkRRect& rrect, const GrStrokeInfo& strokeInfo);
|
2014-04-09 21:26:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for drawing an SkPath consisting of nested rrects using a paint.
|
|
|
|
* Does not support stroking. The result is undefined if outer does not contain
|
|
|
|
* inner.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param outer the outer roundrect
|
|
|
|
* @param inner the inner roundrect
|
|
|
|
*/
|
|
|
|
void drawDRRect(const GrPaint& paint, const SkRRect& outer, const SkRRect& inner);
|
|
|
|
|
2013-04-25 15:27:00 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
2011-03-03 13:54:13 +00:00
|
|
|
* Draws a path.
|
2011-02-22 20:59:41 +00:00
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
2011-05-16 17:21:57 +00:00
|
|
|
* @param path the path to draw
|
2014-06-11 17:30:05 +00:00
|
|
|
* @param strokeInfo the stroke information (width, join, cap) and
|
|
|
|
* the dash information (intervals, count, phase).
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2014-06-11 17:30:05 +00:00
|
|
|
void drawPath(const GrPaint& paint, const SkPath& path, const GrStrokeInfo& strokeInfo);
|
2011-05-16 17:21:57 +00:00
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
/**
|
|
|
|
* Draws vertices with a paint.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
|
|
|
* @param primitiveType primitives type to draw.
|
|
|
|
* @param vertexCount number of vertices.
|
|
|
|
* @param positions array of vertex positions, required.
|
|
|
|
* @param texCoords optional array of texture coordinates used
|
|
|
|
* to access the paint.
|
|
|
|
* @param colors optional array of per-vertex colors, supercedes
|
|
|
|
* the paint's color field.
|
|
|
|
* @param indices optional array of indices. If NULL vertices
|
|
|
|
* are drawn non-indexed.
|
|
|
|
* @param indexCount if indices is non-null then this is the
|
|
|
|
* number of indices.
|
|
|
|
*/
|
|
|
|
void drawVertices(const GrPaint& paint,
|
|
|
|
GrPrimitiveType primitiveType,
|
|
|
|
int vertexCount,
|
2014-03-28 17:58:28 +00:00
|
|
|
const SkPoint positions[],
|
|
|
|
const SkPoint texs[],
|
2011-02-22 20:59:41 +00:00
|
|
|
const GrColor colors[],
|
|
|
|
const uint16_t indices[],
|
|
|
|
int indexCount);
|
|
|
|
|
2012-04-27 13:05:21 +00:00
|
|
|
/**
|
|
|
|
* Draws an oval.
|
|
|
|
*
|
|
|
|
* @param paint describes how to color pixels.
|
2013-01-22 13:34:01 +00:00
|
|
|
* @param oval the bounding rect of the oval.
|
2014-06-11 17:30:05 +00:00
|
|
|
* @param strokeInfo the stroke information (width, join, cap) and
|
|
|
|
* the dash information (intervals, count, phase).
|
2012-04-27 13:05:21 +00:00
|
|
|
*/
|
|
|
|
void drawOval(const GrPaint& paint,
|
2013-07-17 21:39:42 +00:00
|
|
|
const SkRect& oval,
|
2014-06-11 17:30:05 +00:00
|
|
|
const GrStrokeInfo& strokeInfo);
|
2012-04-27 13:05:21 +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
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Reads a rectangle of pixels from a render target.
|
2012-08-20 19:22:38 +00:00
|
|
|
* @param target the render target to read from. NULL means the current render target.
|
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
|
|
|
|
* pixel config or because no render target is currently set and NULL was passed for
|
|
|
|
* target.
|
2011-04-05 17:08:27 +00:00
|
|
|
*/
|
|
|
|
bool readRenderTargetPixels(GrRenderTarget* target,
|
|
|
|
int left, int top, int width, int height,
|
2012-08-20 19:22:38 +00:00
|
|
|
GrPixelConfig config, void* buffer,
|
|
|
|
size_t rowBytes = 0,
|
|
|
|
uint32_t pixelOpsFlags = 0);
|
2011-11-16 20:36:03 +00:00
|
|
|
|
|
|
|
/**
|
2012-10-15 14:25:31 +00:00
|
|
|
* Copy the src pixels [buffer, row bytes, pixel config] into a render target at the specified
|
2012-08-20 19:22:38 +00:00
|
|
|
* rectangle.
|
|
|
|
* @param target the render target to write into. NULL means the current render target.
|
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 the rectangle from.
|
2012-10-12 14:51:52 +00:00
|
|
|
* @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly
|
2012-08-20 19:22:38 +00:00
|
|
|
* packed.
|
|
|
|
* @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
|
|
|
|
* unsupported combination of target and pixel configs.
|
2011-11-16 20:36:03 +00:00
|
|
|
*/
|
2013-02-06 18:17:50 +00:00
|
|
|
bool writeRenderTargetPixels(GrRenderTarget* target,
|
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 = 0,
|
|
|
|
uint32_t pixelOpsFlags = 0);
|
2011-04-05 17:08:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a rectangle of pixels from a texture.
|
2011-11-16 20:36:03 +00:00
|
|
|
* @param texture the texture 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-10-12 14:51:52 +00:00
|
|
|
* @param rowBytes number of bytes between consecutive rows. Zero means rows are tightly
|
2012-08-20 19:22:38 +00:00
|
|
|
* 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
|
|
|
|
* pixel config.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2011-11-16 20:36:03 +00:00
|
|
|
bool readTexturePixels(GrTexture* texture,
|
2011-04-05 17:08:27 +00:00
|
|
|
int left, int top, int width, int height,
|
2011-11-16 20:36:03 +00:00
|
|
|
GrPixelConfig config, void* buffer,
|
2012-08-20 19:22:38 +00:00
|
|
|
size_t rowBytes = 0,
|
|
|
|
uint32_t pixelOpsFlags = 0);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
|
|
|
/**
|
2011-11-16 20:36:03 +00:00
|
|
|
* Writes a rectangle of pixels to a texture.
|
|
|
|
* @param texture the render target to read from.
|
|
|
|
* @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
|
|
|
|
* unsupported combination of texture and pixel configs.
|
2011-02-22 20:59:41 +00:00
|
|
|
*/
|
2013-02-06 18:17:50 +00:00
|
|
|
bool writeTexturePixels(GrTexture* texture,
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves a render target that has MSAA. The intermediate MSAA buffer is
|
2012-10-15 14:25:31 +00:00
|
|
|
* down-sampled to the associated GrTexture (accessible via
|
2012-01-31 13:35:56 +00:00
|
|
|
* GrRenderTarget::asTexture()). Any pending draws to the render target will
|
|
|
|
* be executed before the resolve.
|
|
|
|
*
|
|
|
|
* This is only necessary when a client wants to access the object directly
|
2012-10-25 18:43:28 +00:00
|
|
|
* using the backend API directly. GrContext will detect when it must
|
2012-01-31 13:35:56 +00:00
|
|
|
* perform a resolve to a GrTexture used as the source of a draw or before
|
|
|
|
* reading pixels back from a GrTexture or GrRenderTarget.
|
|
|
|
*/
|
2014-03-28 16:08:05 +00:00
|
|
|
void resolveRenderTarget(GrRenderTarget*);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides a perfomance hint that the render target's contents are allowed
|
|
|
|
* to become undefined.
|
|
|
|
*/
|
|
|
|
void discardRenderTarget(GrRenderTarget*);
|
2012-01-31 13:35:56 +00:00
|
|
|
|
2013-10-02 18:19:17 +00:00
|
|
|
#ifdef SK_DEVELOPER
|
|
|
|
void dumpFontCache() const;
|
|
|
|
#endif
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Helpers
|
|
|
|
|
2013-09-18 13:00:55 +00:00
|
|
|
class AutoRenderTarget : public ::SkNoncopyable {
|
2011-02-22 20:59:41 +00:00
|
|
|
public:
|
|
|
|
AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
|
|
|
|
fPrevTarget = context->getRenderTarget();
|
2013-09-09 13:38:37 +00:00
|
|
|
SkSafeRef(fPrevTarget);
|
2012-08-27 12:53:13 +00:00
|
|
|
context->setRenderTarget(target);
|
|
|
|
fContext = context;
|
|
|
|
}
|
|
|
|
AutoRenderTarget(GrContext* context) {
|
|
|
|
fPrevTarget = context->getRenderTarget();
|
2013-09-09 13:38:37 +00:00
|
|
|
SkSafeRef(fPrevTarget);
|
2012-08-27 12:53:13 +00:00
|
|
|
fContext = context;
|
2011-02-22 20:59:41 +00:00
|
|
|
}
|
|
|
|
~AutoRenderTarget() {
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fContext) {
|
2011-02-22 20:59:41 +00:00
|
|
|
fContext->setRenderTarget(fPrevTarget);
|
|
|
|
}
|
2013-09-09 13:38:37 +00:00
|
|
|
SkSafeUnref(fPrevTarget);
|
2011-02-22 20:59:41 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
GrContext* fContext;
|
|
|
|
GrRenderTarget* fPrevTarget;
|
|
|
|
};
|
|
|
|
|
2012-07-11 18:53:23 +00:00
|
|
|
/**
|
2012-10-12 14:51:52 +00:00
|
|
|
* Save/restore the view-matrix in the context. It can optionally adjust a paint to account
|
|
|
|
* for a coordinate system change. Here is an example of how the paint param can be used:
|
|
|
|
*
|
2014-09-23 16:50:21 +00:00
|
|
|
* A GrPaint is setup with GrProcessors. The stages will have access to the pre-matrix source
|
2012-10-12 14:51:52 +00:00
|
|
|
* geometry positions when the draw is executed. Later on a decision is made to transform the
|
2012-10-24 19:07:10 +00:00
|
|
|
* geometry to device space on the CPU. The effects now need to know that the space in which
|
|
|
|
* the geometry will be specified has changed.
|
2012-10-12 14:51:52 +00:00
|
|
|
*
|
|
|
|
* Note that when restore is called (or in the destructor) the context's matrix will be
|
|
|
|
* restored. However, the paint will not be restored. The caller must make a copy of the
|
|
|
|
* paint if necessary. Hint: use SkTCopyOnFirstWrite if the AutoMatrix is conditionally
|
|
|
|
* initialized.
|
2012-07-11 18:53:23 +00:00
|
|
|
*/
|
2013-09-18 13:00:55 +00:00
|
|
|
class AutoMatrix : public ::SkNoncopyable {
|
2012-07-11 18:53:23 +00:00
|
|
|
public:
|
|
|
|
AutoMatrix() : fContext(NULL) {}
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2012-10-12 14:51:52 +00:00
|
|
|
~AutoMatrix() { this->restore(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes by pre-concat'ing the context's current matrix with the preConcat param.
|
|
|
|
*/
|
2012-11-01 18:02:54 +00:00
|
|
|
void setPreConcat(GrContext* context, const SkMatrix& preConcat, GrPaint* paint = NULL) {
|
2014-09-05 20:34:00 +00:00
|
|
|
SkASSERT(context);
|
2012-10-12 14:51:52 +00:00
|
|
|
|
|
|
|
this->restore();
|
2012-10-13 02:01:56 +00:00
|
|
|
|
2012-10-12 14:51:52 +00:00
|
|
|
fContext = context;
|
|
|
|
fMatrix = context->getMatrix();
|
|
|
|
this->preConcat(preConcat, paint);
|
2012-07-11 18:53:23 +00:00
|
|
|
}
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2012-10-12 14:51:52 +00:00
|
|
|
/**
|
|
|
|
* Sets the context's matrix to identity. Returns false if the inverse matrix is required to
|
|
|
|
* update a paint but the matrix cannot be inverted.
|
|
|
|
*/
|
|
|
|
bool setIdentity(GrContext* context, GrPaint* paint = NULL) {
|
2014-09-05 20:34:00 +00:00
|
|
|
SkASSERT(context);
|
2012-10-12 14:51:52 +00:00
|
|
|
|
|
|
|
this->restore();
|
2012-10-13 02:01:56 +00:00
|
|
|
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2013-03-20 19:19:53 +00:00
|
|
|
if (!paint->localCoordChangeInverse(context->getMatrix())) {
|
2012-10-12 14:51:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fMatrix = context->getMatrix();
|
|
|
|
fContext = context;
|
|
|
|
context->setIdentityMatrix();
|
|
|
|
return true;
|
2012-07-11 18:53:23 +00:00
|
|
|
}
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2012-10-12 14:51:52 +00:00
|
|
|
/**
|
|
|
|
* Replaces the context's matrix with a new matrix. Returns false if the inverse matrix is
|
|
|
|
* required to update a paint but the matrix cannot be inverted.
|
|
|
|
*/
|
2012-11-01 18:02:54 +00:00
|
|
|
bool set(GrContext* context, const SkMatrix& newMatrix, GrPaint* paint = NULL) {
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2012-10-12 14:51:52 +00:00
|
|
|
if (!this->setIdentity(context, paint)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this->preConcat(newMatrix, paint);
|
|
|
|
} else {
|
|
|
|
this->restore();
|
|
|
|
fContext = context;
|
|
|
|
fMatrix = context->getMatrix();
|
|
|
|
context->setMatrix(newMatrix);
|
2012-07-11 18:53:23 +00:00
|
|
|
}
|
2012-10-12 14:51:52 +00:00
|
|
|
return true;
|
2012-07-11 18:53:23 +00:00
|
|
|
}
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2012-10-12 14:51:52 +00:00
|
|
|
/**
|
|
|
|
* If this has been initialized then the context's matrix will be further updated by
|
|
|
|
* pre-concat'ing the preConcat param. The matrix that will be restored remains unchanged.
|
|
|
|
* The paint is assumed to be relative to the context's matrix at the time this call is
|
|
|
|
* made, not the matrix at the time AutoMatrix was first initialized. In other words, this
|
|
|
|
* performs an incremental update of the paint.
|
|
|
|
*/
|
2012-11-01 18:02:54 +00:00
|
|
|
void preConcat(const SkMatrix& preConcat, GrPaint* paint = NULL) {
|
2014-09-05 20:34:00 +00:00
|
|
|
if (paint) {
|
2013-03-20 19:19:53 +00:00
|
|
|
paint->localCoordChange(preConcat);
|
2012-07-11 18:53:23 +00:00
|
|
|
}
|
2012-10-12 14:51:52 +00:00
|
|
|
fContext->concatMatrix(preConcat);
|
2012-07-11 18:53:23 +00:00
|
|
|
}
|
2012-08-27 12:53:13 +00:00
|
|
|
|
2012-10-12 14:51:52 +00:00
|
|
|
/**
|
|
|
|
* Returns false if never initialized or the inverse matrix was required to update a paint
|
|
|
|
* but the matrix could not be inverted.
|
|
|
|
*/
|
2014-09-05 20:34:00 +00:00
|
|
|
bool succeeded() const { return SkToBool(fContext); }
|
2012-10-12 14:51:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this has been initialized then the context's original matrix is restored.
|
|
|
|
*/
|
|
|
|
void restore() {
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fContext) {
|
2012-07-11 18:53:23 +00:00
|
|
|
fContext->setMatrix(fMatrix);
|
2012-10-12 14:51:52 +00:00
|
|
|
fContext = NULL;
|
2012-07-11 18:53:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GrContext* fContext;
|
2012-11-01 18:02:54 +00:00
|
|
|
SkMatrix fMatrix;
|
2012-07-11 18:53:23 +00:00
|
|
|
};
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2013-09-18 13:00:55 +00:00
|
|
|
class AutoClip : public ::SkNoncopyable {
|
2012-07-11 20:57:46 +00:00
|
|
|
public:
|
2012-08-27 12:53:13 +00:00
|
|
|
// This enum exists to require a caller of the constructor to acknowledge that the clip will
|
|
|
|
// initially be wide open. It also could be extended if there are other desirable initial
|
|
|
|
// clip states.
|
|
|
|
enum InitialClip {
|
|
|
|
kWideOpen_InitialClip,
|
|
|
|
};
|
|
|
|
|
2012-10-02 02:01:24 +00:00
|
|
|
AutoClip(GrContext* context, InitialClip initialState)
|
2012-10-01 18:25:13 +00:00
|
|
|
: fContext(context) {
|
2013-08-17 00:02:59 +00:00
|
|
|
SkASSERT(kWideOpen_InitialClip == initialState);
|
2012-08-27 12:53:13 +00:00
|
|
|
fNewClipData.fClipStack = &fNewClipStack;
|
2012-10-01 18:25:13 +00:00
|
|
|
|
|
|
|
fOldClip = context->getClip();
|
2012-08-27 12:53:13 +00:00
|
|
|
context->setClip(&fNewClipData);
|
|
|
|
}
|
|
|
|
|
2013-07-17 21:39:42 +00:00
|
|
|
AutoClip(GrContext* context, const SkRect& newClipRect)
|
2012-07-11 20:57:46 +00:00
|
|
|
: fContext(context)
|
2012-07-26 18:52:16 +00:00
|
|
|
, fNewClipStack(newClipRect) {
|
|
|
|
fNewClipData.fClipStack = &fNewClipStack;
|
|
|
|
|
2012-07-11 20:57:46 +00:00
|
|
|
fOldClip = fContext->getClip();
|
2012-07-26 18:52:16 +00:00
|
|
|
fContext->setClip(&fNewClipData);
|
2012-07-11 20:57:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~AutoClip() {
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fContext) {
|
2012-07-11 20:57:46 +00:00
|
|
|
fContext->setClip(fOldClip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2012-07-26 18:52:16 +00:00
|
|
|
GrContext* fContext;
|
|
|
|
const GrClipData* fOldClip;
|
|
|
|
|
2012-07-31 19:15:58 +00:00
|
|
|
SkClipStack fNewClipStack;
|
2012-07-26 18:52:16 +00:00
|
|
|
GrClipData fNewClipData;
|
2012-07-11 20:57:46 +00:00
|
|
|
};
|
|
|
|
|
2012-08-27 12:53:13 +00:00
|
|
|
class AutoWideOpenIdentityDraw {
|
|
|
|
public:
|
|
|
|
AutoWideOpenIdentityDraw(GrContext* ctx, GrRenderTarget* rt)
|
|
|
|
: fAutoClip(ctx, AutoClip::kWideOpen_InitialClip)
|
2012-10-12 14:51:52 +00:00
|
|
|
, fAutoRT(ctx, rt) {
|
|
|
|
fAutoMatrix.setIdentity(ctx);
|
|
|
|
// should never fail with no paint param.
|
2013-08-17 00:02:59 +00:00
|
|
|
SkASSERT(fAutoMatrix.succeeded());
|
2012-08-27 12:53:13 +00:00
|
|
|
}
|
2012-10-12 14:51:52 +00:00
|
|
|
|
2012-08-27 12:53:13 +00:00
|
|
|
private:
|
|
|
|
AutoClip fAutoClip;
|
|
|
|
AutoRenderTarget fAutoRT;
|
|
|
|
AutoMatrix fAutoMatrix;
|
|
|
|
};
|
|
|
|
|
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; }
|
2011-02-22 20:59:41 +00:00
|
|
|
GrFontCache* getFontCache() { return fFontCache; }
|
2014-04-03 00:34:27 +00:00
|
|
|
GrLayerCache* getLayerCache() { return fLayerCache.get(); }
|
2013-06-13 17:44:07 +00:00
|
|
|
GrDrawTarget* getTextTarget();
|
2011-02-22 20:59:41 +00:00
|
|
|
const GrIndexBuffer* getQuadIndexBuffer() const;
|
2014-05-09 14:29:32 +00:00
|
|
|
GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; }
|
2014-08-21 20:02:13 +00:00
|
|
|
GrResourceCache2* getResourceCache2() { return fResourceCache2; }
|
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
|
|
|
|
void getTestTarget(GrTestTarget*);
|
|
|
|
|
2014-06-19 17:19:29 +00:00
|
|
|
void addGpuTraceMarker(const GrGpuTraceMarker* marker);
|
|
|
|
void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
|
|
|
|
|
2011-08-08 17:01:14 +00:00
|
|
|
/**
|
2012-10-15 14:25:31 +00:00
|
|
|
* Stencil buffers add themselves to the cache using addStencilBuffer. findStencilBuffer is
|
|
|
|
* called to check the cache for a SB that matches an RT's criteria.
|
2011-08-08 17:01:14 +00:00
|
|
|
*/
|
2012-09-09 14:44:15 +00:00
|
|
|
void addStencilBuffer(GrStencilBuffer* sb);
|
|
|
|
GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2012-12-10 19:10:17 +00:00
|
|
|
GrPathRenderer* getPathRenderer(
|
|
|
|
const SkPath& path,
|
2012-12-17 21:16:45 +00:00
|
|
|
const SkStrokeRec& stroke,
|
2012-12-10 19:10:17 +00:00
|
|
|
const GrDrawTarget* target,
|
|
|
|
bool allowSW,
|
2014-02-11 16:30:21 +00:00
|
|
|
GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType,
|
2012-12-10 19:10:17 +00:00
|
|
|
GrPathRendererChain::StencilSupport* stencilSupport = NULL);
|
2012-05-22 20:28:23 +00:00
|
|
|
|
2014-08-12 14:26:25 +00:00
|
|
|
/**
|
|
|
|
* This returns a copy of the the GrContext::Options that was passed to the
|
|
|
|
* constructor of this class.
|
|
|
|
*/
|
|
|
|
const Options& getOptions() const { return fOptions; }
|
|
|
|
|
2012-08-31 13:07:37 +00:00
|
|
|
#if GR_CACHE_STATS
|
2012-08-22 10:57:05 +00:00
|
|
|
void printCacheStats() const;
|
|
|
|
#endif
|
|
|
|
|
2014-09-18 20:52:08 +00:00
|
|
|
class GPUStats {
|
|
|
|
public:
|
|
|
|
#if GR_GPU_STATS
|
|
|
|
GPUStats() { this->reset(); }
|
|
|
|
|
|
|
|
void reset() { fRenderTargetBinds = 0; fShaderCompilations = 0; }
|
|
|
|
|
|
|
|
int renderTargetBinds() const { return fRenderTargetBinds; }
|
|
|
|
void incRenderTargetBinds() { fRenderTargetBinds++; }
|
|
|
|
int shaderCompilations() const { return fShaderCompilations; }
|
|
|
|
void incShaderCompilations() { fShaderCompilations++; }
|
|
|
|
private:
|
|
|
|
int fRenderTargetBinds;
|
|
|
|
int fShaderCompilations;
|
|
|
|
#else
|
|
|
|
void incRenderTargetBinds() {}
|
|
|
|
void incShaderCompilations() {}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#if GR_GPU_STATS
|
|
|
|
const GPUStats* gpuStats() const;
|
|
|
|
#endif
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
private:
|
2012-08-16 18:36:06 +00:00
|
|
|
// Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer.
|
|
|
|
enum BufferedDraw {
|
|
|
|
kYes_BufferedDraw,
|
|
|
|
kNo_BufferedDraw,
|
2011-02-22 20:59:41 +00:00
|
|
|
};
|
2012-08-16 18:36:06 +00:00
|
|
|
BufferedDraw fLastDrawWasBuffered;
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2013-05-28 17:25:49 +00:00
|
|
|
GrGpu* fGpu;
|
|
|
|
SkMatrix fViewMatrix;
|
|
|
|
SkAutoTUnref<GrRenderTarget> fRenderTarget;
|
|
|
|
const GrClipData* fClip; // TODO: make this ref counted
|
|
|
|
GrDrawState* fDrawState;
|
2012-03-30 14:35:04 +00:00
|
|
|
|
2014-05-09 14:29:32 +00:00
|
|
|
GrResourceCache* fResourceCache;
|
2014-08-21 20:02:13 +00:00
|
|
|
GrResourceCache2* fResourceCache2;
|
2013-05-28 17:25:49 +00:00
|
|
|
GrFontCache* fFontCache;
|
2014-04-03 00:34:27 +00:00
|
|
|
SkAutoTDelete<GrLayerCache> fLayerCache;
|
2011-03-25 12:31:16 +00:00
|
|
|
|
2013-05-28 17:25:49 +00:00
|
|
|
GrPathRendererChain* fPathRendererChain;
|
|
|
|
GrSoftwarePathRenderer* fSoftwarePathRenderer;
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2013-05-28 17:25:49 +00:00
|
|
|
GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
|
|
|
|
GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
|
|
|
|
GrInOrderDrawBuffer* fDrawBuffer;
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2013-10-04 16:23:58 +00:00
|
|
|
// Set by OverbudgetCB() to request that GrContext flush before exiting a draw.
|
|
|
|
bool fFlushToReduceCacheSize;
|
|
|
|
|
2013-05-28 17:25:49 +00:00
|
|
|
GrAARectRenderer* fAARectRenderer;
|
|
|
|
GrOvalRenderer* fOvalRenderer;
|
2011-03-25 12:31:16 +00:00
|
|
|
|
2013-05-28 17:25:49 +00:00
|
|
|
bool fDidTestPMConversions;
|
|
|
|
int fPMToUPMConversion;
|
|
|
|
int fUPMToPMConversion;
|
2012-08-27 12:53:13 +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;
|
|
|
|
|
2013-07-26 07:00:58 +00:00
|
|
|
int fMaxTextureSizeOverride;
|
2012-09-24 19:33:59 +00:00
|
|
|
|
2014-08-12 14:26:25 +00:00
|
|
|
const Options fOptions;
|
|
|
|
|
|
|
|
GrContext(const Options&); // init must be called after the constructor.
|
2013-02-25 20:12:45 +00:00
|
|
|
bool init(GrBackend, GrBackendContext);
|
2011-04-25 12:43:45 +00:00
|
|
|
|
2011-03-30 21:26:44 +00:00
|
|
|
void setupDrawBuffer();
|
|
|
|
|
2013-06-13 19:34:18 +00:00
|
|
|
class AutoRestoreEffects;
|
2013-10-04 16:23:58 +00:00
|
|
|
class AutoCheckFlush;
|
2012-08-17 14:06:49 +00:00
|
|
|
/// Sets the paint and returns the target to draw into. The paint can be NULL in which case the
|
|
|
|
/// draw state is left unmodified.
|
2013-10-04 16:23:58 +00:00
|
|
|
GrDrawTarget* prepareToDraw(const GrPaint*, BufferedDraw, AutoRestoreEffects*, AutoCheckFlush*);
|
2011-02-22 20:59:41 +00:00
|
|
|
|
2013-05-02 13:11:22 +00:00
|
|
|
void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path,
|
2014-06-11 17:30:05 +00:00
|
|
|
const GrStrokeInfo& stroke);
|
2013-01-22 13:34:01 +00:00
|
|
|
|
2012-08-13 18:00:36 +00:00
|
|
|
GrTexture* createResizedTexture(const GrTextureDesc& desc,
|
2012-12-20 15:13:01 +00:00
|
|
|
const GrCacheID& cacheID,
|
2014-05-29 19:26:48 +00:00
|
|
|
const void* srcData,
|
2012-08-13 18:00:36 +00:00
|
|
|
size_t rowBytes,
|
2013-07-25 18:49:07 +00:00
|
|
|
bool filter);
|
2012-08-13 18:00:36 +00:00
|
|
|
|
2014-10-07 19:07:38 +00:00
|
|
|
// Needed so GrTexture's returnToCache helper function can call
|
|
|
|
// addExistingTextureToCache
|
|
|
|
friend class GrTexture;
|
|
|
|
friend class GrStencilAndCoverPathRenderer;
|
|
|
|
friend class GrStencilAndCoverTextContext;
|
|
|
|
|
|
|
|
// Add an existing texture to the texture cache. This is intended solely
|
|
|
|
// for use with textures released from an GrAutoScratchTexture.
|
|
|
|
void addExistingTextureToCache(GrTexture* texture);
|
2012-06-26 20:16:17 +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.
|
|
|
|
*/
|
2014-09-23 16:50:21 +00:00
|
|
|
const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&);
|
|
|
|
const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&);
|
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
|
|
|
|
* when the cache is still overbudget after a purge.
|
|
|
|
*/
|
|
|
|
static bool OverbudgetCB(void* data);
|
|
|
|
|
2013-09-09 13:38:37 +00:00
|
|
|
typedef SkRefCnt INHERITED;
|
2011-02-22 20:59:41 +00:00
|
|
|
};
|
|
|
|
|
2011-07-12 19:44:51 +00:00
|
|
|
/**
|
2014-10-07 19:07:38 +00:00
|
|
|
* Gets and locks a scratch texture from a descriptor using either exact or approximate criteria.
|
|
|
|
* Unlocks texture in the destructor.
|
2011-07-12 19:44:51 +00:00
|
|
|
*/
|
2014-09-30 19:18:44 +00:00
|
|
|
class SK_API GrAutoScratchTexture : public ::SkNoncopyable {
|
2011-07-12 19:44:51 +00:00
|
|
|
public:
|
2011-07-26 20:45:30 +00:00
|
|
|
GrAutoScratchTexture()
|
2012-08-16 14:49:16 +00:00
|
|
|
: fContext(NULL)
|
|
|
|
, fTexture(NULL) {
|
2011-07-12 19:44:51 +00:00
|
|
|
}
|
2011-07-26 20:45:30 +00:00
|
|
|
|
|
|
|
GrAutoScratchTexture(GrContext* context,
|
|
|
|
const GrTextureDesc& desc,
|
2014-10-07 19:07:38 +00:00
|
|
|
GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch)
|
2012-08-16 14:49:16 +00:00
|
|
|
: fContext(NULL)
|
|
|
|
, fTexture(NULL) {
|
2014-10-07 19:07:38 +00:00
|
|
|
this->set(context, desc, match);
|
2011-07-26 20:45:30 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-07-26 20:45:30 +00:00
|
|
|
~GrAutoScratchTexture() {
|
2012-06-22 12:01:30 +00:00
|
|
|
this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fContext && fTexture) {
|
2014-10-07 19:07:38 +00:00
|
|
|
fContext->unlockScratchTexture(fTexture);
|
2013-01-24 14:46:47 +00:00
|
|
|
fTexture->unref();
|
2012-08-16 14:49:16 +00:00
|
|
|
fTexture = NULL;
|
2011-07-12 19:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-14 14:45:44 +00:00
|
|
|
|
2014-10-07 19:07:38 +00:00
|
|
|
/*
|
|
|
|
* When detaching a texture we do not unlock it in the texture cache but
|
|
|
|
* we do set the returnToCache flag. In this way the texture remains
|
|
|
|
* "locked" in the texture cache until it is freed and recycled in
|
|
|
|
* GrTexture::internal_dispose. In reality, the texture has been removed
|
|
|
|
* from the cache (because this is in AutoScratchTexture) and by not
|
|
|
|
* calling unlockScratchTexture we simply don't re-add it. It will be
|
|
|
|
* reattached in GrTexture::internal_dispose.
|
|
|
|
*
|
|
|
|
* Note that the caller is assumed to accept and manage the ref to the
|
|
|
|
* returned texture.
|
|
|
|
*/
|
|
|
|
GrTexture* detach();
|
2012-06-22 12:41:43 +00:00
|
|
|
|
2011-07-26 20:45:30 +00:00
|
|
|
GrTexture* set(GrContext* context,
|
|
|
|
const GrTextureDesc& desc,
|
2014-10-07 19:07:38 +00:00
|
|
|
GrContext::ScratchTexMatch match = GrContext::kApprox_ScratchTexMatch) {
|
2012-06-22 12:01:30 +00:00
|
|
|
this->reset();
|
|
|
|
|
2011-07-26 20:45:30 +00:00
|
|
|
fContext = context;
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fContext) {
|
2014-10-07 19:07:38 +00:00
|
|
|
fTexture = fContext->lockAndRefScratchTexture(desc, match);
|
2012-08-16 14:49:16 +00:00
|
|
|
if (NULL == fTexture) {
|
2011-07-26 20:45:30 +00:00
|
|
|
fContext = NULL;
|
|
|
|
}
|
2012-08-16 14:49:16 +00:00
|
|
|
return fTexture;
|
2011-07-26 20:45:30 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 14:49:16 +00:00
|
|
|
GrTexture* texture() { return fTexture; }
|
|
|
|
|
2011-07-12 19:44:51 +00:00
|
|
|
private:
|
2011-07-26 20:45:30 +00:00
|
|
|
GrContext* fContext;
|
2012-08-16 14:49:16 +00:00
|
|
|
GrTexture* fTexture;
|
2011-07-12 19:44:51 +00:00
|
|
|
};
|
|
|
|
|
2011-02-22 20:59:41 +00:00
|
|
|
#endif
|