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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 If non-null, returns the number of resources that a re held in the | |
robertphillips
2014/05/08 19:12:35
extra space?
bsalomon
2014/05/09 15:23:52
Done.
| |
126 * cache. | |
robertphillips
2014/05/08 19:12:35
just resourceBytes
"returns The" -> "returns the"
bsalomon
2014/05/09 15:23:52
Done.
| |
127 * @param maxResourceBytes If non-null, returns The total number of bytes o f video memory held | |
128 * in the cache. | |
129 */ | |
130 void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const; | |
131 | |
132 SK_ATTR_DEPRECATED("Use getResourceCacheUsage()."); | |
133 size_t getGpuTextureCacheBytes() const { | |
134 size_t bytes; | |
135 this->getResourceCacheUsage(NULL, &bytes); | |
136 return bytes; | |
137 } | |
138 | |
139 SK_ATTR_DEPRECATED("Use getResourceCacheUsage()."); | |
140 int getGpuTextureCacheResourceCount() const { | |
141 int count; | |
142 this->getResourceCacheUsage(&count, NULL); | |
143 return count; | |
144 } | |
145 | |
146 /** | |
147 * Specify the GPU resource cache limits. If the current cache exceeds eith er | |
148 * of these, it will be purged (LRU) to keep the cache within these limits. | |
149 * | |
150 * @param maxResources The maximum number of resources that can be held in | |
151 * the cache. | |
152 * @param maxResourceBytes The maximum number of bytes of video memory | |
153 * that can be held in the cache. | |
154 */ | |
155 void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); | |
156 SK_ATTR_DEPRECATED("This function has been renamed to setResourceCacheLimits ()."); | |
157 void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes) { | |
158 this->setResourceCacheLimits(maxTextures, maxTextureBytes); | |
159 } | |
160 | |
105 /** | 161 /** |
106 * Frees GPU created by the context. Can be called to reduce GPU memory | 162 * Frees GPU created by the context. Can be called to reduce GPU memory |
107 * pressure. | 163 * pressure. |
108 */ | 164 */ |
109 void freeGpuResources(); | 165 void freeGpuResources(); |
110 | 166 |
111 /** | 167 /** |
112 * Returns the number of bytes of GPU memory hosted by the texture cache. | 168 * This method should be called whenever a GrResource is unreffed or |
169 * switched from exclusive to non-exclusive. This | |
170 * gives the resource cache a chance to discard unneeded resources. | |
171 * Note: this entry point will be removed once totally ref-driven | |
172 * cache maintenance is implemented. | |
113 */ | 173 */ |
114 size_t getGpuTextureCacheBytes() const; | 174 void purgeCache(); |
115 | 175 |
116 /** | 176 /** |
117 * Returns the number of resources hosted by the texture cache. | 177 * Purge all the unlocked resources from the cache. |
178 * This entry point is mainly meant for timing texture uploads | |
179 * and is not defined in normal builds of Skia. | |
118 */ | 180 */ |
119 int getGpuTextureCacheResourceCount() const; | 181 void purgeAllUnlockedResources(); |
182 | |
183 /** | |
184 * Stores a custom resource in the cache, based on the specified key. | |
185 */ | |
186 void addResourceToCache(const GrResourceKey&, GrCacheable*); | |
187 | |
188 /** | |
189 * Finds a resource in the cache, based on the specified key. This is intend ed for use in | |
190 * conjunction with addResourceToCache(). The return value will be NULL if n ot found. The | |
191 * caller must balance with a call to unref(). | |
192 */ | |
193 GrCacheable* findAndRefCachedResource(const GrResourceKey&); | |
120 | 194 |
121 /////////////////////////////////////////////////////////////////////////// | 195 /////////////////////////////////////////////////////////////////////////// |
122 // Textures | 196 // Textures |
123 | 197 |
124 /** | 198 /** |
125 * Creates a new entry, based on the specified key and texture and returns i t. The caller owns a | 199 * 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. | 200 * ref on the returned texture which must be balanced by a call to unref. |
127 * | 201 * |
128 * @param params The texture params used to draw a texture may help deter mine | 202 * @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 | 203 * the cache entry used. (e.g. different versions may exist |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 */ | 275 */ |
202 GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch ma tch); | 276 GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch ma tch); |
203 | 277 |
204 /** | 278 /** |
205 * When done with an entry, call unlockScratchTexture(entry) on it, which r eturns | 279 * 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 . | 280 * it to the cache, where it may be purged. This does not unref the texture . |
207 */ | 281 */ |
208 void unlockScratchTexture(GrTexture* texture); | 282 void unlockScratchTexture(GrTexture* texture); |
209 | 283 |
210 /** | 284 /** |
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 | 285 * Creates a texture that is outside the cache. Does not count against |
228 * cache's budget. | 286 * cache's budget. |
229 */ | 287 */ |
230 GrTexture* createUncachedTexture(const GrTextureDesc& desc, | 288 GrTexture* createUncachedTexture(const GrTextureDesc& desc, |
231 void* srcData, | 289 void* srcData, |
232 size_t rowBytes); | 290 size_t rowBytes); |
233 | 291 |
234 /** | 292 /** |
235 * Returns true if the specified use of an indexed texture is supported. | 293 * Returns true if the specified use of an indexed texture is supported. |
236 * Support may depend upon whether the texture params indicate that the | 294 * Support may depend upon whether the texture params indicate that the |
237 * texture will be tiled. Passing NULL for the texture params indicates | 295 * texture will be tiled. Passing NULL for the texture params indicates |
238 * clamp mode. | 296 * clamp mode. |
239 */ | 297 */ |
240 bool supportsIndex8PixelConfig(const GrTextureParams*, | 298 bool supportsIndex8PixelConfig(const GrTextureParams*, |
241 int width, | 299 int width, |
242 int height) const; | 300 int height) const; |
243 | 301 |
244 /** | 302 /** |
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 . | 303 * Return the max width or height of a texture supported by the current GPU . |
267 */ | 304 */ |
268 int getMaxTextureSize() const; | 305 int getMaxTextureSize() const; |
269 | 306 |
270 /** | 307 /** |
271 * Temporarily override the true max texture size. Note: an override | 308 * Temporarily override the true max texture size. Note: an override |
272 * larger then the true max texture size will have no effect. | 309 * larger then the true max texture size will have no effect. |
273 * This entry point is mainly meant for testing texture size dependent | 310 * This entry point is mainly meant for testing texture size dependent |
274 * features and is only available if defined outside of Skia (see | 311 * features and is only available if defined outside of Skia (see |
275 * bleed GM. | 312 * bleed GM. |
(...skipping 11 matching lines...) Expand all Loading... | |
287 fRenderTarget.reset(SkSafeRef(target)); | 324 fRenderTarget.reset(SkSafeRef(target)); |
288 } | 325 } |
289 | 326 |
290 /** | 327 /** |
291 * Gets the current render target. | 328 * Gets the current render target. |
292 * @return the currently bound render target. | 329 * @return the currently bound render target. |
293 */ | 330 */ |
294 const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } | 331 const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
295 GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } | 332 GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } |
296 | 333 |
297 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } | |
298 | |
299 /** | 334 /** |
300 * Can the provided configuration act as a color render target? | 335 * Can the provided configuration act as a color render target? |
301 */ | 336 */ |
302 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const; | 337 bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const; |
303 | 338 |
304 /** | 339 /** |
305 * Return the max width or height of a render target supported by the | 340 * Return the max width or height of a render target supported by the |
306 * current GPU. | 341 * current GPU. |
307 */ | 342 */ |
308 int getMaxRenderTargetSize() const; | 343 int getMaxRenderTargetSize() const; |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 }; | 903 }; |
869 | 904 |
870 /////////////////////////////////////////////////////////////////////////// | 905 /////////////////////////////////////////////////////////////////////////// |
871 // Functions intended for internal use only. | 906 // Functions intended for internal use only. |
872 GrGpu* getGpu() { return fGpu; } | 907 GrGpu* getGpu() { return fGpu; } |
873 const GrGpu* getGpu() const { return fGpu; } | 908 const GrGpu* getGpu() const { return fGpu; } |
874 GrFontCache* getFontCache() { return fFontCache; } | 909 GrFontCache* getFontCache() { return fFontCache; } |
875 GrLayerCache* getLayerCache() { return fLayerCache.get(); } | 910 GrLayerCache* getLayerCache() { return fLayerCache.get(); } |
876 GrDrawTarget* getTextTarget(); | 911 GrDrawTarget* getTextTarget(); |
877 const GrIndexBuffer* getQuadIndexBuffer() const; | 912 const GrIndexBuffer* getQuadIndexBuffer() const; |
913 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } | |
878 | 914 |
879 // Called by tests that draw directly to the context via GrDrawTarget | 915 // Called by tests that draw directly to the context via GrDrawTarget |
880 void getTestTarget(GrTestTarget*); | 916 void getTestTarget(GrTestTarget*); |
881 | 917 |
882 // Functions for managing gpu trace markers | 918 // Functions for managing gpu trace markers |
883 bool isGpuTracingEnabled() const { return fGpuTracingEnabled; } | 919 bool isGpuTracingEnabled() const { return fGpuTracingEnabled; } |
884 void enableGpuTracing() { fGpuTracingEnabled = true; } | 920 void enableGpuTracing() { fGpuTracingEnabled = true; } |
885 void disableGpuTracing() { fGpuTracingEnabled = false; } | 921 void disableGpuTracing() { fGpuTracingEnabled = false; } |
886 | 922 |
887 /** | 923 /** |
888 * Stencil buffers add themselves to the cache using addStencilBuffer. findS tencilBuffer is | 924 * 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. | 925 * called to check the cache for a SB that matches an RT's criteria. |
890 */ | 926 */ |
891 void addStencilBuffer(GrStencilBuffer* sb); | 927 void addStencilBuffer(GrStencilBuffer* sb); |
892 GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); | 928 GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); |
893 | 929 |
894 GrPathRenderer* getPathRenderer( | 930 GrPathRenderer* getPathRenderer( |
895 const SkPath& path, | 931 const SkPath& path, |
896 const SkStrokeRec& stroke, | 932 const SkStrokeRec& stroke, |
897 const GrDrawTarget* target, | 933 const GrDrawTarget* target, |
898 bool allowSW, | 934 bool allowSW, |
899 GrPathRendererChain::DrawType drawType = GrPathRendererChain ::kColor_DrawType, | 935 GrPathRendererChain::DrawType drawType = GrPathRendererChain ::kColor_DrawType, |
900 GrPathRendererChain::StencilSupport* stencilSupport = NULL); | 936 GrPathRendererChain::StencilSupport* stencilSupport = NULL); |
901 | 937 |
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 | 938 #if GR_CACHE_STATS |
915 void printCacheStats() const; | 939 void printCacheStats() const; |
916 #endif | 940 #endif |
917 | 941 |
918 private: | 942 private: |
919 // Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer. | 943 // Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer. |
920 enum BufferedDraw { | 944 enum BufferedDraw { |
921 kYes_BufferedDraw, | 945 kYes_BufferedDraw, |
922 kNo_BufferedDraw, | 946 kNo_BufferedDraw, |
923 }; | 947 }; |
924 BufferedDraw fLastDrawWasBuffered; | 948 BufferedDraw fLastDrawWasBuffered; |
925 | 949 |
926 GrGpu* fGpu; | 950 GrGpu* fGpu; |
927 SkMatrix fViewMatrix; | 951 SkMatrix fViewMatrix; |
928 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 952 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
929 const GrClipData* fClip; // TODO: make this ref counted | 953 const GrClipData* fClip; // TODO: make this ref counted |
930 GrDrawState* fDrawState; | 954 GrDrawState* fDrawState; |
931 | 955 |
932 GrResourceCache* fTextureCache; | 956 GrResourceCache* fResourceCache; |
933 GrFontCache* fFontCache; | 957 GrFontCache* fFontCache; |
934 SkAutoTDelete<GrLayerCache> fLayerCache; | 958 SkAutoTDelete<GrLayerCache> fLayerCache; |
935 | 959 |
936 GrPathRendererChain* fPathRendererChain; | 960 GrPathRendererChain* fPathRendererChain; |
937 GrSoftwarePathRenderer* fSoftwarePathRenderer; | 961 GrSoftwarePathRenderer* fSoftwarePathRenderer; |
938 | 962 |
939 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; | 963 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; |
940 GrIndexBufferAllocPool* fDrawBufferIBAllocPool; | 964 GrIndexBufferAllocPool* fDrawBufferIBAllocPool; |
941 GrInOrderDrawBuffer* fDrawBuffer; | 965 GrInOrderDrawBuffer* fDrawBuffer; |
942 | 966 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 } | 1124 } |
1101 | 1125 |
1102 GrTexture* texture() { return fTexture; } | 1126 GrTexture* texture() { return fTexture; } |
1103 | 1127 |
1104 private: | 1128 private: |
1105 GrContext* fContext; | 1129 GrContext* fContext; |
1106 GrTexture* fTexture; | 1130 GrTexture* fTexture; |
1107 }; | 1131 }; |
1108 | 1132 |
1109 #endif | 1133 #endif |
OLD | NEW |