OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 GrContext_DEFINED | 8 #ifndef GrContext_DEFINED |
9 #define GrContext_DEFINED | 9 #define GrContext_DEFINED |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 */ | 162 */ |
163 void purgeCache(); | 163 void purgeCache(); |
164 | 164 |
165 /** | 165 /** |
166 * Purge all the unlocked resources from the cache. | 166 * Purge all the unlocked resources from the cache. |
167 * This entry point is mainly meant for timing texture uploads | 167 * This entry point is mainly meant for timing texture uploads |
168 * and is not defined in normal builds of Skia. | 168 * and is not defined in normal builds of Skia. |
169 */ | 169 */ |
170 void purgeAllUnlockedResources(); | 170 void purgeAllUnlockedResources(); |
171 | 171 |
172 /** Sets a content key on the resource. The resource must not already have a
content key and | 172 /** |
173 * the key must not already be in use for this to succeed. | 173 * Stores a custom resource in the cache, based on the specified key. |
174 */ | 174 */ |
175 bool addResourceToCache(const GrContentKey&, GrGpuResource*); | 175 void addResourceToCache(const GrContentKey&, GrGpuResource*); |
176 | 176 |
177 /** | 177 /** |
178 * Finds a resource in the cache, based on the specified key. This is intend
ed for use in | 178 * Finds a resource in the cache, based on the specified key. This is intend
ed for use in |
179 * conjunction with addResourceToCache(). The return value will be NULL if n
ot found. The | 179 * conjunction with addResourceToCache(). The return value will be NULL if n
ot found. The |
180 * caller must balance with a call to unref(). | 180 * caller must balance with a call to unref(). |
181 */ | 181 */ |
182 GrGpuResource* findAndRefCachedResource(const GrContentKey&); | 182 GrGpuResource* findAndRefCachedResource(const GrContentKey&); |
183 | 183 |
184 /** Helper for casting resource to a texture. Caller must be sure that the r
esource cached | |
185 with the key is either NULL or a texture and not another resource type.
*/ | |
186 GrTexture* findAndRefCachedTexture(const GrContentKey& key) { | |
187 GrGpuResource* resource = this->findAndRefCachedResource(key); | |
188 if (resource) { | |
189 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture(); | |
190 SkASSERT(texture); | |
191 return texture; | |
192 } | |
193 return NULL; | |
194 } | |
195 | |
196 /** | |
197 * Determines whether a resource is in the cache. If the resource is found i
t | |
198 * will not be locked or returned. This call does not affect the priority of | |
199 * the resource for deletion. | |
200 */ | |
201 bool isResourceInCache(const GrContentKey& key) const; | |
202 | |
203 /** | 184 /** |
204 * Creates a new text rendering context that is optimal for the | 185 * Creates a new text rendering context that is optimal for the |
205 * render target and the context. Caller assumes the ownership | 186 * render target and the context. Caller assumes the ownership |
206 * of the returned object. The returned object must be deleted | 187 * of the returned object. The returned object must be deleted |
207 * before the context is destroyed. | 188 * before the context is destroyed. |
208 */ | 189 */ |
209 GrTextContext* createTextContext(GrRenderTarget*, | 190 GrTextContext* createTextContext(GrRenderTarget*, |
210 const SkDeviceProperties&, | 191 const SkDeviceProperties&, |
211 bool enableDistanceFieldFonts); | 192 bool enableDistanceFieldFonts); |
212 | 193 |
213 /////////////////////////////////////////////////////////////////////////// | 194 /////////////////////////////////////////////////////////////////////////// |
214 // Textures | 195 // Textures |
215 | 196 |
216 /** | 197 /** |
217 * Creates a new texture in the resource cache and returns it. The caller ow
ns a | 198 * Creates a new entry, based on the specified key and texture and returns i
t. The caller owns a |
218 * ref on the returned texture which must be balanced by a call to unref. | 199 * ref on the returned texture which must be balanced by a call to unref. |
219 * | 200 * |
| 201 * TODO: Move resizing logic out of GrContext and have the caller set the co
ntent key on the |
| 202 * returned texture rather than take it as a param. |
| 203 * |
| 204 * @param params The texture params used to draw a texture may help deter
mine |
| 205 * the cache entry used. (e.g. different versions may exist |
| 206 * for different wrap modes on GPUs with limited NPOT |
| 207 * texture support). NULL implies clamp wrap modes. |
220 * @param desc Description of the texture properties. | 208 * @param desc Description of the texture properties. |
| 209 * @param key Key to associate with the texture. |
221 * @param srcData Pointer to the pixel values. | 210 * @param srcData Pointer to the pixel values. |
222 * @param rowBytes The number of bytes between rows of the texture. Zero | 211 * @param rowBytes The number of bytes between rows of the texture. Zero |
223 * implies tightly packed rows. For compressed pixel config
s, this | 212 * implies tightly packed rows. For compressed pixel config
s, this |
224 * field is ignored. | 213 * field is ignored. |
| 214 * @param outKey (optional) If non-NULL, we'll write the cache key we use
d to cacheKey. this |
| 215 * may differ from key on GPUs that don't support tiling NP
OT textures. |
225 */ | 216 */ |
226 GrTexture* createTexture(const GrSurfaceDesc& desc, const void* srcData, siz
e_t rowBytes); | 217 GrTexture* createTexture(const GrTextureParams* params, |
227 | 218 const GrSurfaceDesc& desc, |
228 GrTexture* createTexture(const GrSurfaceDesc& desc) { | 219 const GrContentKey& key, |
229 return this->createTexture(desc, NULL, 0); | 220 const void* srcData, |
230 } | 221 size_t rowBytes, |
231 | 222 GrContentKey* outKey = NULL); |
232 /** | 223 /** |
233 * Creates a texture that is outside the cache. Does not count against | 224 * Search for an entry based on key and dimensions. If found, ref it and ret
urn it. The return |
234 * cache's budget. | 225 * value will be NULL if not found. The caller must balance with a call to u
nref. |
235 * | 226 * |
236 * TODO: Add a budgeted param to createTexture and remove this function. | 227 * TODO: Remove this function and do lookups generically. |
| 228 * |
| 229 * @param desc Description of the texture properties. |
| 230 * @param key key to use for texture look up. |
| 231 * @param params The texture params used to draw a texture may help deter
mine |
| 232 * the cache entry used. (e.g. different versions may exist |
| 233 * for different wrap modes on GPUs with limited NPOT |
| 234 * texture support). NULL implies clamp wrap modes. |
237 */ | 235 */ |
238 GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, void* srcData, s
ize_t rowBytes); | 236 GrTexture* findAndRefTexture(const GrSurfaceDesc& desc, |
| 237 const GrContentKey& key, |
| 238 const GrTextureParams* params); |
| 239 /** |
| 240 * Determines whether a texture is in the cache. If the texture is found it |
| 241 * will not be locked or returned. This call does not affect the priority of |
| 242 * the texture for deletion. |
| 243 * |
| 244 * TODO: Remove this function and do cache checks generically. |
| 245 */ |
| 246 bool isTextureInCache(const GrSurfaceDesc& desc, |
| 247 const GrContentKey& key, |
| 248 const GrTextureParams* params) const; |
239 | 249 |
240 /** | 250 /** |
241 * Enum that determines how closely a returned scratch texture must match | 251 * Enum that determines how closely a returned scratch texture must match |
242 * a provided GrSurfaceDesc. | 252 * a provided GrSurfaceDesc. |
243 */ | 253 */ |
244 enum ScratchTexMatch { | 254 enum ScratchTexMatch { |
245 /** | 255 /** |
246 * Finds a texture that exactly matches the descriptor. | 256 * Finds a texture that exactly matches the descriptor. |
247 */ | 257 */ |
248 kExact_ScratchTexMatch, | 258 kExact_ScratchTexMatch, |
(...skipping 18 matching lines...) Expand all Loading... |
267 * tiling non-power-of-two textures on APIs that don't support this (e.g. | 277 * tiling non-power-of-two textures on APIs that don't support this (e.g. |
268 * unextended GLES2). NPOT scratch textures are not tilable on such APIs. | 278 * unextended GLES2). NPOT scratch textures are not tilable on such APIs. |
269 * | 279 * |
270 * internalFlag is a temporary workaround until changes in the internal | 280 * internalFlag is a temporary workaround until changes in the internal |
271 * architecture are complete. Use the default value. | 281 * architecture are complete. Use the default value. |
272 */ | 282 */ |
273 GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match, | 283 GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match, |
274 bool internalFlag = false); | 284 bool internalFlag = false); |
275 | 285 |
276 /** | 286 /** |
277 * Returns true if index8 textures are supported. | 287 * Creates a texture that is outside the cache. Does not count against |
| 288 * cache's budget. |
| 289 * |
| 290 * Textures created by createTexture() hide the complications of |
| 291 * tiling non-power-of-two textures on APIs that don't support this (e.g. |
| 292 * unextended GLES2). NPOT uncached textures are not tilable on such APIs. |
278 */ | 293 */ |
279 bool supportsIndex8PixelConfig() const; | 294 GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, |
| 295 void* srcData, |
| 296 size_t rowBytes); |
| 297 |
| 298 /** |
| 299 * Returns true if the specified use of an indexed texture is supported. |
| 300 * Support may depend upon whether the texture params indicate that the |
| 301 * texture will be tiled. Passing NULL for the texture params indicates |
| 302 * clamp mode. |
| 303 */ |
| 304 bool supportsIndex8PixelConfig(const GrTextureParams*, |
| 305 int width, |
| 306 int height) const; |
280 | 307 |
281 /** | 308 /** |
282 * Return the max width or height of a texture supported by the current GPU
. | 309 * Return the max width or height of a texture supported by the current GPU
. |
283 */ | 310 */ |
284 int getMaxTextureSize() const; | 311 int getMaxTextureSize() const; |
285 | 312 |
286 /** | 313 /** |
287 * Temporarily override the true max texture size. Note: an override | 314 * Temporarily override the true max texture size. Note: an override |
288 * larger then the true max texture size will have no effect. | 315 * larger then the true max texture size will have no effect. |
289 * This entry point is mainly meant for testing texture size dependent | 316 * This entry point is mainly meant for testing texture size dependent |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 /** | 897 /** |
871 * This callback allows the resource cache to callback into the GrContext | 898 * This callback allows the resource cache to callback into the GrContext |
872 * when the cache is still over budget after a purge. | 899 * when the cache is still over budget after a purge. |
873 */ | 900 */ |
874 static void OverBudgetCB(void* data); | 901 static void OverBudgetCB(void* data); |
875 | 902 |
876 typedef SkRefCnt INHERITED; | 903 typedef SkRefCnt INHERITED; |
877 }; | 904 }; |
878 | 905 |
879 #endif | 906 #endif |
OLD | NEW |