diff options
author | 2015-02-02 13:00:10 -0800 | |
---|---|---|
committer | 2015-02-02 13:00:10 -0800 | |
commit | 37f9a2694c15f08e361ebda74fe9f0fffbf452aa (patch) | |
tree | 2bbbb36f91b31cc203fa375939ab2d4a4a5117f0 /include | |
parent | 52edc4d05380c88de5b334479ad8e537ef2b4925 (diff) |
Move npot resizing out of GrContext and simplify GrContext texture functions.
Committed: https://skia.googlesource.com/skia/+/8a8100349105c8c6de39fcb34e47679da7a67f54
Committed: https://skia.googlesource.com/skia/+/6c96672491b04cb782bce8fee778124df66524a0
Review URL: https://codereview.chromium.org/882223003
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrContext.h | 101 | ||||
-rw-r--r-- | include/gpu/GrPaint.h | 14 | ||||
-rw-r--r-- | include/gpu/GrResourceKey.h | 1 | ||||
-rw-r--r-- | include/gpu/GrTypes.h | 16 |
4 files changed, 57 insertions, 75 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index e6fdeb89f7..88a31484ed 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -169,10 +169,10 @@ public: */ void purgeAllUnlockedResources(); - /** - * Stores a custom resource in the cache, based on the specified key. + /** Sets a content key on the resource. The resource must not already have a content key and + * the key must not already be in use for this to succeed. */ - void addResourceToCache(const GrContentKey&, GrGpuResource*); + bool addResourceToCache(const GrContentKey&, GrGpuResource*); /** * Finds a resource in the cache, based on the specified key. This is intended for use in @@ -181,6 +181,25 @@ public: */ GrGpuResource* findAndRefCachedResource(const GrContentKey&); + /** Helper for casting resource to a texture. Caller must be sure that the resource cached + with the key is either NULL or a texture and not another resource type. */ + GrTexture* findAndRefCachedTexture(const GrContentKey& key) { + GrGpuResource* resource = this->findAndRefCachedResource(key); + if (resource) { + GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); + SkASSERT(texture); + return texture; + } + return NULL; + } + + /** + * Determines whether a resource is in the cache. If the resource is found it + * will not be locked or returned. This call does not affect the priority of + * the resource for deletion. + */ + bool isResourceInCache(const GrContentKey& key) const; + /** * Creates a new text rendering context that is optimal for the * render target and the context. Caller assumes the ownership @@ -195,57 +214,28 @@ public: // Textures /** - * Creates a new entry, based on the specified key and texture and returns it. The caller owns a + * Creates a new texture in the resource cache and returns it. The caller owns a * ref on the returned texture which must be balanced by a call to unref. * - * TODO: Move resizing logic out of GrContext and have the caller set the content key on the - * returned texture rather than take it as a param. - * - * @param params The texture params used to draw a texture may help determine - * 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. * @param desc Description of the texture properties. - * @param key Key to associate with the texture. * @param srcData Pointer to the pixel values. * @param rowBytes The number of bytes between rows of the texture. Zero * implies tightly packed rows. For compressed pixel configs, this * field is ignored. - * @param outKey (optional) If non-NULL, we'll write the cache key we used to cacheKey. this - * may differ from key on GPUs that don't support tiling NPOT textures. - */ - GrTexture* createTexture(const GrTextureParams* params, - const GrSurfaceDesc& desc, - const GrContentKey& key, - const void* srcData, - size_t rowBytes, - GrContentKey* outKey = NULL); - /** - * 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. - * - * TODO: Remove this function and do lookups generically. - * - * @param desc Description of the texture properties. - * @param key key to use for texture look up. - * @param params The texture params used to draw a texture may help determine - * 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. - */ - GrTexture* findAndRefTexture(const GrSurfaceDesc& desc, - const GrContentKey& key, - const GrTextureParams* params); - /** - * 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. + */ + GrTexture* createTexture(const GrSurfaceDesc& desc, const void* srcData, size_t rowBytes); + + GrTexture* createTexture(const GrSurfaceDesc& desc) { + return this->createTexture(desc, NULL, 0); + } + + /** + * Creates a texture that is outside the cache. Does not count against + * cache's budget. * - * TODO: Remove this function and do cache checks generically. + * TODO: Add a budgeted param to createTexture and remove this function. */ - bool isTextureInCache(const GrSurfaceDesc& desc, - const GrContentKey& key, - const GrTextureParams* params) const; + GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, void* srcData, size_t rowBytes); /** * Enum that determines how closely a returned scratch texture must match @@ -284,26 +274,9 @@ public: bool internalFlag = false); /** - * Creates a texture that is outside the cache. Does not count against - * cache's budget. - * - * Textures created by createTexture() hide the complications of - * tiling non-power-of-two textures on APIs that don't support this (e.g. - * unextended GLES2). NPOT uncached textures are not tilable on such APIs. - */ - GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, - void* srcData, - size_t rowBytes); - - /** - * 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. + * Returns true if index8 textures are supported. */ - bool supportsIndex8PixelConfig(const GrTextureParams*, - int width, - int height) const; + bool supportsIndex8PixelConfig() const; /** * Return the max width or height of a texture supported by the current GPU. diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h index 8163f6e4d8..64b51d2c65 100644 --- a/include/gpu/GrPaint.h +++ b/include/gpu/GrPaint.h @@ -25,23 +25,15 @@ * created by subclassing GrProcessor. * * The primitive color computation starts with the color specified by setColor(). This color is the - * input to the first color stage. Each color stage feeds its output to the next color stage. The - * final color stage's output color is input to the color filter specified by - * setXfermodeColorFilter which produces the final source color, S. + * input to the first color stage. Each color stage feeds its output to the next color stage. * * Fractional pixel coverage follows a similar flow. The coverage is initially the value specified * by setCoverage(). This is input to the first coverage stage. Coverage stages are chained * together in the same manner as color stages. The output of the last stage is modulated by any * fractional coverage produced by anti-aliasing. This last step produces the final coverage, C. * - * setBlendFunc() specifies blending coefficients for S (described above) and D, the initial value - * of the destination pixel, labeled Bs and Bd respectively. The final value of the destination - * pixel is then D' = (1-C)*D + C*(Bd*D + Bs*S). - * - * Note that the coverage is applied after the blend. This is why they are computed as distinct - * values. - * - * TODO: Encapsulate setXfermodeColorFilter in a GrProcessor and remove from GrPaint. + * setXPFactory is used to control blending between the output color and dest. It also implements + * the application of fractional coverage from the coverage pipeline. */ class GrPaint { public: diff --git a/include/gpu/GrResourceKey.h b/include/gpu/GrResourceKey.h index 4c76b68c2d..e09a2c710f 100644 --- a/include/gpu/GrResourceKey.h +++ b/include/gpu/GrResourceKey.h @@ -220,6 +220,7 @@ public: Builder(GrContentKey* key, const GrContentKey& innerKey, Domain domain, int extraData32Cnt) : INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + extraData32Cnt) { + SkASSERT(&innerKey != key); // add the inner key to the end of the key so that op[] can be indexed normally. uint32_t* innerKeyData = &this->operator[](extraData32Cnt); const uint32_t* srcData = innerKey.data(); diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h index f4fb3ab43f..7532984ebe 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -302,6 +302,22 @@ static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) { } } +/** If the pixel config is compressed, return an equivalent uncompressed format. */ +static inline GrPixelConfig GrMakePixelConfigUncompressed(GrPixelConfig config) { + switch (config) { + case kIndex_8_GrPixelConfig: + case kETC1_GrPixelConfig: + case kASTC_12x12_GrPixelConfig: + return kRGBA_8888_GrPixelConfig; + case kLATC_GrPixelConfig: + case kR11_EAC_GrPixelConfig: + return kAlpha_8_GrPixelConfig; + default: + SkASSERT(!GrPixelConfigIsCompressed(config)); + return config; + } +} + // Returns true if the pixel config is 32 bits per pixel static inline bool GrPixelConfigIs8888(GrPixelConfig config) { switch (config) { |