Chromium Code Reviews| Index: include/gpu/GrContext.h |
| diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h |
| index e6fdeb89f7771db4c0f18b15241abe76c13a1927..03a64adf868bbb7cb45b3f952b40498a63fa63aa 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 |
| @@ -198,54 +217,25 @@ public: |
| * 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. |
| * |
| - * 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); |
| /** |
|
robertphillips
2015/01/30 14:47:21
Remove "the specified" ?
bsalomon
2015/01/30 15:37:39
Done.
I'd like to remove this function and just h
|
| - * 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. |
| */ |
| - 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. |