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 /** | 172 /** Sets a content key on the resource. The resource must not already have a
content key and |
173 * Stores a custom resource in the cache, based on the specified key. | 173 * the key must not already be in use for this to succeed. |
174 */ | 174 */ |
175 void addResourceToCache(const GrContentKey&, GrGpuResource*); | 175 bool 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 |
184 /** | 203 /** |
185 * Creates a new text rendering context that is optimal for the | 204 * Creates a new text rendering context that is optimal for the |
186 * render target and the context. Caller assumes the ownership | 205 * render target and the context. Caller assumes the ownership |
187 * of the returned object. The returned object must be deleted | 206 * of the returned object. The returned object must be deleted |
188 * before the context is destroyed. | 207 * before the context is destroyed. |
189 */ | 208 */ |
190 GrTextContext* createTextContext(GrRenderTarget*, | 209 GrTextContext* createTextContext(GrRenderTarget*, |
191 const SkDeviceProperties&, | 210 const SkDeviceProperties&, |
192 bool enableDistanceFieldFonts); | 211 bool enableDistanceFieldFonts); |
193 | 212 |
194 /////////////////////////////////////////////////////////////////////////// | 213 /////////////////////////////////////////////////////////////////////////// |
195 // Textures | 214 // Textures |
196 | 215 |
197 /** | 216 /** |
198 * Creates a new entry, based on the specified key and texture and returns i
t. The caller owns a | 217 * Creates a new texture in the resource cache and returns it. The caller ow
ns a |
199 * ref on the returned texture which must be balanced by a call to unref. | 218 * ref on the returned texture which must be balanced by a call to unref. |
200 * | 219 * |
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. | |
208 * @param desc Description of the texture properties. | 220 * @param desc Description of the texture properties. |
209 * @param key Key to associate with the texture. | |
210 * @param srcData Pointer to the pixel values. | 221 * @param srcData Pointer to the pixel values. |
211 * @param rowBytes The number of bytes between rows of the texture. Zero | 222 * @param rowBytes The number of bytes between rows of the texture. Zero |
212 * implies tightly packed rows. For compressed pixel config
s, this | 223 * implies tightly packed rows. For compressed pixel config
s, this |
213 * field is ignored. | 224 * 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. | |
216 */ | 225 */ |
217 GrTexture* createTexture(const GrTextureParams* params, | 226 GrTexture* createTexture(const GrSurfaceDesc& desc, const void* srcData, siz
e_t rowBytes); |
218 const GrSurfaceDesc& desc, | 227 |
219 const GrContentKey& key, | 228 GrTexture* createTexture(const GrSurfaceDesc& desc) { |
220 const void* srcData, | 229 return this->createTexture(desc, NULL, 0); |
221 size_t rowBytes, | 230 } |
222 GrContentKey* outKey = NULL); | 231 |
223 /** | 232 /** |
224 * Search for an entry based on key and dimensions. If found, ref it and ret
urn it. The return | 233 * Creates a texture that is outside the cache. Does not count against |
225 * value will be NULL if not found. The caller must balance with a call to u
nref. | 234 * cache's budget. |
226 * | 235 * |
227 * TODO: Remove this function and do lookups generically. | 236 * TODO: Add a budgeted param to createTexture and remove this function. |
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. | |
235 */ | 237 */ |
236 GrTexture* findAndRefTexture(const GrSurfaceDesc& desc, | 238 GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, void* srcData, s
ize_t rowBytes); |
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; | |
249 | 239 |
250 /** | 240 /** |
251 * Enum that determines how closely a returned scratch texture must match | 241 * Enum that determines how closely a returned scratch texture must match |
252 * a provided GrSurfaceDesc. | 242 * a provided GrSurfaceDesc. |
253 */ | 243 */ |
254 enum ScratchTexMatch { | 244 enum ScratchTexMatch { |
255 /** | 245 /** |
256 * Finds a texture that exactly matches the descriptor. | 246 * Finds a texture that exactly matches the descriptor. |
257 */ | 247 */ |
258 kExact_ScratchTexMatch, | 248 kExact_ScratchTexMatch, |
(...skipping 18 matching lines...) Expand all Loading... |
277 * tiling non-power-of-two textures on APIs that don't support this (e.g. | 267 * tiling non-power-of-two textures on APIs that don't support this (e.g. |
278 * unextended GLES2). NPOT scratch textures are not tilable on such APIs. | 268 * unextended GLES2). NPOT scratch textures are not tilable on such APIs. |
279 * | 269 * |
280 * internalFlag is a temporary workaround until changes in the internal | 270 * internalFlag is a temporary workaround until changes in the internal |
281 * architecture are complete. Use the default value. | 271 * architecture are complete. Use the default value. |
282 */ | 272 */ |
283 GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match, | 273 GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match, |
284 bool internalFlag = false); | 274 bool internalFlag = false); |
285 | 275 |
286 /** | 276 /** |
287 * Creates a texture that is outside the cache. Does not count against | 277 * Returns true if index8 textures are supported. |
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. | |
293 */ | 278 */ |
294 GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, | 279 bool supportsIndex8PixelConfig() const; |
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; | |
307 | 280 |
308 /** | 281 /** |
309 * Return the max width or height of a texture supported by the current GPU
. | 282 * Return the max width or height of a texture supported by the current GPU
. |
310 */ | 283 */ |
311 int getMaxTextureSize() const; | 284 int getMaxTextureSize() const; |
312 | 285 |
313 /** | 286 /** |
314 * Temporarily override the true max texture size. Note: an override | 287 * Temporarily override the true max texture size. Note: an override |
315 * larger then the true max texture size will have no effect. | 288 * larger then the true max texture size will have no effect. |
316 * This entry point is mainly meant for testing texture size dependent | 289 * This entry point is mainly meant for testing texture size dependent |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 /** | 870 /** |
898 * This callback allows the resource cache to callback into the GrContext | 871 * This callback allows the resource cache to callback into the GrContext |
899 * when the cache is still over budget after a purge. | 872 * when the cache is still over budget after a purge. |
900 */ | 873 */ |
901 static void OverBudgetCB(void* data); | 874 static void OverBudgetCB(void* data); |
902 | 875 |
903 typedef SkRefCnt INHERITED; | 876 typedef SkRefCnt INHERITED; |
904 }; | 877 }; |
905 | 878 |
906 #endif | 879 #endif |
OLD | NEW |