| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrTextureProvider_DEFINED | 8 #ifndef GrTextureProvider_DEFINED |
| 9 #define GrTextureProvider_DEFINED | 9 #define GrTextureProvider_DEFINED |
| 10 | 10 |
| 11 #include "GrTexture.h" | 11 #include "GrTexture.h" |
| 12 #include "SkImageFilter.h" | 12 #include "SkImageFilter.h" |
| 13 | 13 |
| 14 class GrSingleOwner; | |
| 15 | |
| 16 class SK_API GrTextureProvider { | 14 class SK_API GrTextureProvider { |
| 17 public: | 15 public: |
| 18 /////////////////////////////////////////////////////////////////////////// | 16 /////////////////////////////////////////////////////////////////////////// |
| 19 // Textures | 17 // Textures |
| 20 | 18 |
| 21 /** | 19 /** |
| 22 * Creates a new texture in the resource cache and returns it. The caller ow
ns a | 20 * Creates a new texture in the resource cache and returns it. The caller ow
ns a |
| 23 * ref on the returned texture which must be balanced by a call to unref. | 21 * ref on the returned texture which must be balanced by a call to unref. |
| 24 * | 22 * |
| 25 * @param desc Description of the texture properties. | 23 * @param desc Description of the texture properties. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 return this->createTexture(desc, budgeted, NULL, 0); | 35 return this->createTexture(desc, budgeted, NULL, 0); |
| 38 } | 36 } |
| 39 | 37 |
| 40 /** Assigns a unique key to the texture. The texture will be findable via th
is key using | 38 /** Assigns a unique key to the texture. The texture will be findable via th
is key using |
| 41 findTextureByUniqueKey(). If an existing texture has this key, it's key
will be removed. */ | 39 findTextureByUniqueKey(). If an existing texture has this key, it's key
will be removed. */ |
| 42 void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) { | 40 void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) { |
| 43 this->assignUniqueKeyToResource(key, texture); | 41 this->assignUniqueKeyToResource(key, texture); |
| 44 } | 42 } |
| 45 | 43 |
| 46 /** Finds a texture by unique key. If the texture is found it is ref'ed and
returned. */ | 44 /** Finds a texture by unique key. If the texture is found it is ref'ed and
returned. */ |
| 47 GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key); | 45 GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key) { |
| 46 GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key); |
| 47 if (resource) { |
| 48 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); |
| 49 SkASSERT(texture); |
| 50 return texture; |
| 51 } |
| 52 return NULL; |
| 53 } |
| 48 | 54 |
| 49 /** | 55 /** |
| 50 * Determines whether a texture is associated with the unique key. If the te
xture is found it | 56 * Determines whether a texture is associated with the unique key. If the te
xture is found it |
| 51 * will not be locked or returned. This call does not affect the priority of
the resource for | 57 * will not be locked or returned. This call does not affect the priority of
the resource for |
| 52 * deletion. | 58 * deletion. |
| 53 */ | 59 */ |
| 54 bool existsTextureWithUniqueKey(const GrUniqueKey& key) const { | 60 bool existsTextureWithUniqueKey(const GrUniqueKey& key) const { |
| 55 return this->existsResourceWithUniqueKey(key); | 61 return this->existsResourceWithUniqueKey(key); |
| 56 } | 62 } |
| 57 | 63 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 * similar to wrapBackendTexture but can be used to draw into surfaces | 127 * similar to wrapBackendTexture but can be used to draw into surfaces |
| 122 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that | 128 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that |
| 123 * the client will resolve to a texture). Currently wrapped render targets | 129 * the client will resolve to a texture). Currently wrapped render targets |
| 124 * always use the kBorrow_GrWrapOwnership semantics. | 130 * always use the kBorrow_GrWrapOwnership semantics. |
| 125 * | 131 * |
| 126 * @return GrTexture object or NULL on failure. | 132 * @return GrTexture object or NULL on failure. |
| 127 */ | 133 */ |
| 128 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& de
sc); | 134 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& de
sc); |
| 129 | 135 |
| 130 protected: | 136 protected: |
| 131 GrTextureProvider(GrGpu* gpu, GrResourceCache* cache, GrSingleOwner* singleO
wner); | 137 GrTextureProvider(GrGpu* gpu, GrResourceCache* cache) : fCache(cache), fGpu(
gpu) {} |
| 132 | 138 |
| 133 /** | 139 /** |
| 134 * Assigns a unique key to a resource. If the key is associated with another
resource that | 140 * Assigns a unique key to a resource. If the key is associated with another
resource that |
| 135 * association is removed and replaced by this resource. | 141 * association is removed and replaced by this resource. |
| 136 */ | 142 */ |
| 137 void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*); | 143 void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*); |
| 138 | 144 |
| 139 /** | 145 /** |
| 140 * Finds a resource in the cache, based on the specified key. This is intend
ed for use in | 146 * Finds a resource in the cache, based on the specified key. This is intend
ed for use in |
| 141 * conjunction with addResourceToCache(). The return value will be NULL if n
ot found. The | 147 * conjunction with addResourceToCache(). The return value will be NULL if n
ot found. The |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 const GrGpu* gpu() const { return fGpu; } | 179 const GrGpu* gpu() const { return fGpu; } |
| 174 | 180 |
| 175 bool isAbandoned() const { | 181 bool isAbandoned() const { |
| 176 SkASSERT(SkToBool(fGpu) == SkToBool(fCache)); | 182 SkASSERT(SkToBool(fGpu) == SkToBool(fCache)); |
| 177 return !SkToBool(fCache); | 183 return !SkToBool(fCache); |
| 178 } | 184 } |
| 179 | 185 |
| 180 private: | 186 private: |
| 181 GrResourceCache* fCache; | 187 GrResourceCache* fCache; |
| 182 GrGpu* fGpu; | 188 GrGpu* fGpu; |
| 183 | |
| 184 // In debug builds we guard against improper thread handling | |
| 185 SkDEBUGCODE(mutable GrSingleOwner* fSingleOwner;) | |
| 186 }; | 189 }; |
| 187 | 190 |
| 188 #endif | 191 #endif |
| OLD | NEW |