Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: include/gpu/GrContext.h

Issue 275563005: cleanup GrContext resource cache api (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix spacing Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gm/gmmain.cpp ('k') | samplecode/SampleApp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 */ 95 */
96 void contextLost(); 96 void contextLost();
97 97
98 /** 98 /**
99 * Similar to contextLost, but makes no attempt to reset state. 99 * Similar to contextLost, but makes no attempt to reset state.
100 * Use this method when GrContext destruction is pending, but 100 * Use this method when GrContext destruction is pending, but
101 * the graphics context is destroyed first. 101 * the graphics context is destroyed first.
102 */ 102 */
103 void contextDestroyed(); 103 void contextDestroyed();
104 104
105 ///////////////////////////////////////////////////////////////////////////
106 // Resource Cache
107
108 /**
109 * Return the current GPU resource cache limits.
110 *
111 * @param maxResources If non-null, returns maximum number of resources tha t
112 * can be held in the cache.
113 * @param maxResourceBytes If non-null, returns maximum number of bytes of
114 * video memory that can be held in the cache.
115 */
116 void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) con st
117 SK_ATTR_DEPRECATED("This function has been renamed to getResourceCacheLimits ().");
118 void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const {
119 this->getResourceCacheLimits(maxTextures, maxTextureBytes);
120 }
121
122 /**
123 * Gets the current GPU resource cache usage.
124 *
125 * @param resourceCount The number of resources that are held in the cache
126 * @param maxResourceBytes The total number of bytes of video memory held i n the cache.
127 */
128 void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const;
bsalomon 2014/05/08 18:26:45 It seemed like the usage getter should mirror the
129
130 SK_ATTR_DEPRECATED("Use getResourceCacheUsage().");
131 size_t getGpuTextureCacheBytes() const {
132 size_t bytes;
133 this->getResourceCacheUsage(NULL, &bytes);
134 return bytes;
135 }
136
137 SK_ATTR_DEPRECATED("Use getResourceCacheUsage().");
138 int getGpuTextureCacheResourceCount() const {
139 int count;
140 this->getResourceCacheUsage(&count, NULL);
141 return count;
142 }
143
144 /**
145 * Specify the GPU resource cache limits. If the current cache exceeds eith er
146 * of these, it will be purged (LRU) to keep the cache within these limits.
147 *
148 * @param maxResources The maximum number of resources that can be held in
149 * the cache.
150 * @param maxResourceBytes The maximum number of bytes of video memory
151 * that can be held in the cache.
152 */
153 void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
154 SK_ATTR_DEPRECATED("This function has been renamed to setResourceCacheLimits ().");
155 void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes) {
156 this->setResourceCacheLimits(maxTextures, maxTextureBytes);
157 }
158
105 /** 159 /**
106 * Frees GPU created by the context. Can be called to reduce GPU memory 160 * Frees GPU created by the context. Can be called to reduce GPU memory
107 * pressure. 161 * pressure.
108 */ 162 */
109 void freeGpuResources(); 163 void freeGpuResources();
110 164
111 /** 165 /**
112 * Returns the number of bytes of GPU memory hosted by the texture cache. 166 * This method should be called whenever a GrResource is unreffed or
167 * switched from exclusive to non-exclusive. This
168 * gives the resource cache a chance to discard unneeded resources.
169 * Note: this entry point will be removed once totally ref-driven
170 * cache maintenance is implemented.
113 */ 171 */
114 size_t getGpuTextureCacheBytes() const; 172 void purgeCache();
115 173
116 /** 174 /**
117 * Returns the number of resources hosted by the texture cache. 175 * Purge all the unlocked resources from the cache.
176 * This entry point is mainly meant for timing texture uploads
177 * and is not defined in normal builds of Skia.
118 */ 178 */
119 int getGpuTextureCacheResourceCount() const; 179 void purgeAllUnlockedResources();
180
181 /**
182 * Stores a custom resource in the cache, based on the specified key.
183 */
184 void addResourceToCache(const GrResourceKey&, GrCacheable*);
185
186 /**
187 * Finds a resource in the cache, based on the specified key. This is intend ed for use in
188 * conjunction with addResourceToCache(). The return value will be NULL if n ot found. The
189 * caller must balance with a call to unref().
190 */
191 GrCacheable* findAndRefCachedResource(const GrResourceKey&);
120 192
121 /////////////////////////////////////////////////////////////////////////// 193 ///////////////////////////////////////////////////////////////////////////
122 // Textures 194 // Textures
123 195
124 /** 196 /**
125 * Creates a new entry, based on the specified key and texture and returns i t. The caller owns a 197 * Creates a new entry, based on the specified key and texture and returns i t. The caller owns a
126 * ref on the returned texture which must be balanced by a call to unref. 198 * ref on the returned texture which must be balanced by a call to unref.
127 * 199 *
128 * @param params The texture params used to draw a texture may help deter mine 200 * @param params The texture params used to draw a texture may help deter mine
129 * the cache entry used. (e.g. different versions may exist 201 * the cache entry used. (e.g. different versions may exist
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 */ 273 */
202 GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch ma tch); 274 GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch ma tch);
203 275
204 /** 276 /**
205 * When done with an entry, call unlockScratchTexture(entry) on it, which r eturns 277 * When done with an entry, call unlockScratchTexture(entry) on it, which r eturns
206 * it to the cache, where it may be purged. This does not unref the texture . 278 * it to the cache, where it may be purged. This does not unref the texture .
207 */ 279 */
208 void unlockScratchTexture(GrTexture* texture); 280 void unlockScratchTexture(GrTexture* texture);
209 281
210 /** 282 /**
211 * This method should be called whenever a GrTexture is unreffed or
212 * switched from exclusive to non-exclusive. This
213 * gives the resource cache a chance to discard unneeded textures.
214 * Note: this entry point will be removed once totally ref-driven
215 * cache maintenance is implemented
216 */
217 void purgeCache();
218
219 /**
220 * Purge all the unlocked resources from the cache.
221 * This entry point is mainly meant for timing texture uploads
222 * and is not defined in normal builds of Skia.
223 */
224 void purgeAllUnlockedResources();
225
226 /**
227 * Creates a texture that is outside the cache. Does not count against 283 * Creates a texture that is outside the cache. Does not count against
228 * cache's budget. 284 * cache's budget.
229 */ 285 */
230 GrTexture* createUncachedTexture(const GrTextureDesc& desc, 286 GrTexture* createUncachedTexture(const GrTextureDesc& desc,
231 void* srcData, 287 void* srcData,
232 size_t rowBytes); 288 size_t rowBytes);
233 289
234 /** 290 /**
235 * Returns true if the specified use of an indexed texture is supported. 291 * Returns true if the specified use of an indexed texture is supported.
236 * Support may depend upon whether the texture params indicate that the 292 * Support may depend upon whether the texture params indicate that the
237 * texture will be tiled. Passing NULL for the texture params indicates 293 * texture will be tiled. Passing NULL for the texture params indicates
238 * clamp mode. 294 * clamp mode.
239 */ 295 */
240 bool supportsIndex8PixelConfig(const GrTextureParams*, 296 bool supportsIndex8PixelConfig(const GrTextureParams*,
241 int width, 297 int width,
242 int height) const; 298 int height) const;
243 299
244 /** 300 /**
245 * Return the current texture cache limits.
246 *
247 * @param maxTextures If non-null, returns maximum number of textures that
248 * can be held in the cache.
249 * @param maxTextureBytes If non-null, returns maximum number of bytes of
250 * texture memory that can be held in the cache.
251 */
252 void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const;
253
254 /**
255 * Specify the texture cache limits. If the current cache exceeds either
256 * of these, it will be purged (LRU) to keep the cache within these limits.
257 *
258 * @param maxTextures The maximum number of textures that can be held in
259 * the cache.
260 * @param maxTextureBytes The maximum number of bytes of texture memory
261 * that can be held in the cache.
262 */
263 void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes);
264
265 /**
266 * Return the max width or height of a texture supported by the current GPU . 301 * Return the max width or height of a texture supported by the current GPU .
267 */ 302 */
268 int getMaxTextureSize() const; 303 int getMaxTextureSize() const;
269 304
270 /** 305 /**
271 * Temporarily override the true max texture size. Note: an override 306 * Temporarily override the true max texture size. Note: an override
272 * larger then the true max texture size will have no effect. 307 * larger then the true max texture size will have no effect.
273 * This entry point is mainly meant for testing texture size dependent 308 * This entry point is mainly meant for testing texture size dependent
274 * features and is only available if defined outside of Skia (see 309 * features and is only available if defined outside of Skia (see
275 * bleed GM. 310 * bleed GM.
(...skipping 11 matching lines...) Expand all
287 fRenderTarget.reset(SkSafeRef(target)); 322 fRenderTarget.reset(SkSafeRef(target));
288 } 323 }
289 324
290 /** 325 /**
291 * Gets the current render target. 326 * Gets the current render target.
292 * @return the currently bound render target. 327 * @return the currently bound render target.
293 */ 328 */
294 const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } 329 const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
295 GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } 330 GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); }
296 331
297 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; }
298
299 /** 332 /**
300 * Can the provided configuration act as a color render target? 333 * Can the provided configuration act as a color render target?
301 */ 334 */
302 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const; 335 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const;
303 336
304 /** 337 /**
305 * Return the max width or height of a render target supported by the 338 * Return the max width or height of a render target supported by the
306 * current GPU. 339 * current GPU.
307 */ 340 */
308 int getMaxRenderTargetSize() const; 341 int getMaxRenderTargetSize() const;
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 }; 901 };
869 902
870 /////////////////////////////////////////////////////////////////////////// 903 ///////////////////////////////////////////////////////////////////////////
871 // Functions intended for internal use only. 904 // Functions intended for internal use only.
872 GrGpu* getGpu() { return fGpu; } 905 GrGpu* getGpu() { return fGpu; }
873 const GrGpu* getGpu() const { return fGpu; } 906 const GrGpu* getGpu() const { return fGpu; }
874 GrFontCache* getFontCache() { return fFontCache; } 907 GrFontCache* getFontCache() { return fFontCache; }
875 GrLayerCache* getLayerCache() { return fLayerCache.get(); } 908 GrLayerCache* getLayerCache() { return fLayerCache.get(); }
876 GrDrawTarget* getTextTarget(); 909 GrDrawTarget* getTextTarget();
877 const GrIndexBuffer* getQuadIndexBuffer() const; 910 const GrIndexBuffer* getQuadIndexBuffer() const;
911 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; }
878 912
879 // Called by tests that draw directly to the context via GrDrawTarget 913 // Called by tests that draw directly to the context via GrDrawTarget
880 void getTestTarget(GrTestTarget*); 914 void getTestTarget(GrTestTarget*);
881 915
882 // Functions for managing gpu trace markers 916 // Functions for managing gpu trace markers
883 bool isGpuTracingEnabled() const { return fGpuTracingEnabled; } 917 bool isGpuTracingEnabled() const { return fGpuTracingEnabled; }
884 void enableGpuTracing() { fGpuTracingEnabled = true; } 918 void enableGpuTracing() { fGpuTracingEnabled = true; }
885 void disableGpuTracing() { fGpuTracingEnabled = false; } 919 void disableGpuTracing() { fGpuTracingEnabled = false; }
886 920
887 /** 921 /**
888 * Stencil buffers add themselves to the cache using addStencilBuffer. findS tencilBuffer is 922 * Stencil buffers add themselves to the cache using addStencilBuffer. findS tencilBuffer is
889 * called to check the cache for a SB that matches an RT's criteria. 923 * called to check the cache for a SB that matches an RT's criteria.
890 */ 924 */
891 void addStencilBuffer(GrStencilBuffer* sb); 925 void addStencilBuffer(GrStencilBuffer* sb);
892 GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); 926 GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt);
893 927
894 GrPathRenderer* getPathRenderer( 928 GrPathRenderer* getPathRenderer(
895 const SkPath& path, 929 const SkPath& path,
896 const SkStrokeRec& stroke, 930 const SkStrokeRec& stroke,
897 const GrDrawTarget* target, 931 const GrDrawTarget* target,
898 bool allowSW, 932 bool allowSW,
899 GrPathRendererChain::DrawType drawType = GrPathRendererChain ::kColor_DrawType, 933 GrPathRendererChain::DrawType drawType = GrPathRendererChain ::kColor_DrawType,
900 GrPathRendererChain::StencilSupport* stencilSupport = NULL); 934 GrPathRendererChain::StencilSupport* stencilSupport = NULL);
901 935
902 /**
903 * Stores a custom resource in the cache, based on the specified key.
904 */
905 void addResourceToCache(const GrResourceKey&, GrCacheable*);
906
907 /**
908 * Finds a resource in the cache, based on the specified key. This is intend ed for use in
909 * conjunction with addResourceToCache(). The return value will be NULL if n ot found. The
910 * caller must balance with a call to unref().
911 */
912 GrCacheable* findAndRefCachedResource(const GrResourceKey&);
913
914 #if GR_CACHE_STATS 936 #if GR_CACHE_STATS
915 void printCacheStats() const; 937 void printCacheStats() const;
916 #endif 938 #endif
917 939
918 private: 940 private:
919 // Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer. 941 // Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer.
920 enum BufferedDraw { 942 enum BufferedDraw {
921 kYes_BufferedDraw, 943 kYes_BufferedDraw,
922 kNo_BufferedDraw, 944 kNo_BufferedDraw,
923 }; 945 };
924 BufferedDraw fLastDrawWasBuffered; 946 BufferedDraw fLastDrawWasBuffered;
925 947
926 GrGpu* fGpu; 948 GrGpu* fGpu;
927 SkMatrix fViewMatrix; 949 SkMatrix fViewMatrix;
928 SkAutoTUnref<GrRenderTarget> fRenderTarget; 950 SkAutoTUnref<GrRenderTarget> fRenderTarget;
929 const GrClipData* fClip; // TODO: make this ref counted 951 const GrClipData* fClip; // TODO: make this ref counted
930 GrDrawState* fDrawState; 952 GrDrawState* fDrawState;
931 953
932 GrResourceCache* fTextureCache; 954 GrResourceCache* fResourceCache;
933 GrFontCache* fFontCache; 955 GrFontCache* fFontCache;
934 SkAutoTDelete<GrLayerCache> fLayerCache; 956 SkAutoTDelete<GrLayerCache> fLayerCache;
935 957
936 GrPathRendererChain* fPathRendererChain; 958 GrPathRendererChain* fPathRendererChain;
937 GrSoftwarePathRenderer* fSoftwarePathRenderer; 959 GrSoftwarePathRenderer* fSoftwarePathRenderer;
938 960
939 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; 961 GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
940 GrIndexBufferAllocPool* fDrawBufferIBAllocPool; 962 GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
941 GrInOrderDrawBuffer* fDrawBuffer; 963 GrInOrderDrawBuffer* fDrawBuffer;
942 964
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 } 1122 }
1101 1123
1102 GrTexture* texture() { return fTexture; } 1124 GrTexture* texture() { return fTexture; }
1103 1125
1104 private: 1126 private:
1105 GrContext* fContext; 1127 GrContext* fContext;
1106 GrTexture* fTexture; 1128 GrTexture* fTexture;
1107 }; 1129 };
1108 1130
1109 #endif 1131 #endif
OLDNEW
« no previous file with comments | « gm/gmmain.cpp ('k') | samplecode/SampleApp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698