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 |
| 126 * cache. |
| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 * @param pixelOpsFlags see PixelOpsFlags enum above. | 670 * @param pixelOpsFlags see PixelOpsFlags enum above. |
636 * @return true if the write succeeded, false if not. The write can fail bec
ause of an | 671 * @return true if the write succeeded, false if not. The write can fail bec
ause of an |
637 * unsupported combination of texture and pixel configs. | 672 * unsupported combination of texture and pixel configs. |
638 */ | 673 */ |
639 bool writeTexturePixels(GrTexture* texture, | 674 bool writeTexturePixels(GrTexture* texture, |
640 int left, int top, int width, int height, | 675 int left, int top, int width, int height, |
641 GrPixelConfig config, const void* buffer, | 676 GrPixelConfig config, const void* buffer, |
642 size_t rowBytes, | 677 size_t rowBytes, |
643 uint32_t pixelOpsFlags = 0); | 678 uint32_t pixelOpsFlags = 0); |
644 | 679 |
645 | |
646 /** | 680 /** |
647 * Copies a rectangle of texels from src to dst. The size of dst is the size
of the rectangle | 681 * Copies a rectangle of texels from src to dst. The size of dst is the size
of the rectangle |
648 * copied and topLeft is the position of the rect in src. The rectangle is c
lipped to src's | 682 * copied and topLeft is the position of the rect in src. The rectangle is c
lipped to src's |
649 * bounds. | 683 * bounds. |
650 * @param src the texture to copy from. | 684 * @param src the texture to copy from. |
651 * @param dst the render target to copy to. | 685 * @param dst the render target to copy to. |
652 * @param topLeft the point in src that will be copied to the top-left
of dst. If NULL, | 686 * @param topLeft the point in src that will be copied to the top-left
of dst. If NULL, |
653 * (0, 0) will be used. | 687 * (0, 0) will be used. |
654 */ | 688 */ |
655 void copyTexture(GrTexture* src, GrRenderTarget* dst, const SkIPoint* topLef
t = NULL); | 689 void copyTexture(GrTexture* src, GrRenderTarget* dst, const SkIPoint* topLef
t = NULL); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 }; | 902 }; |
869 | 903 |
870 /////////////////////////////////////////////////////////////////////////// | 904 /////////////////////////////////////////////////////////////////////////// |
871 // Functions intended for internal use only. | 905 // Functions intended for internal use only. |
872 GrGpu* getGpu() { return fGpu; } | 906 GrGpu* getGpu() { return fGpu; } |
873 const GrGpu* getGpu() const { return fGpu; } | 907 const GrGpu* getGpu() const { return fGpu; } |
874 GrFontCache* getFontCache() { return fFontCache; } | 908 GrFontCache* getFontCache() { return fFontCache; } |
875 GrLayerCache* getLayerCache() { return fLayerCache.get(); } | 909 GrLayerCache* getLayerCache() { return fLayerCache.get(); } |
876 GrDrawTarget* getTextTarget(); | 910 GrDrawTarget* getTextTarget(); |
877 const GrIndexBuffer* getQuadIndexBuffer() const; | 911 const GrIndexBuffer* getQuadIndexBuffer() const; |
| 912 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } |
878 | 913 |
879 // Called by tests that draw directly to the context via GrDrawTarget | 914 // Called by tests that draw directly to the context via GrDrawTarget |
880 void getTestTarget(GrTestTarget*); | 915 void getTestTarget(GrTestTarget*); |
881 | 916 |
882 // Functions for managing gpu trace markers | 917 // Functions for managing gpu trace markers |
883 bool isGpuTracingEnabled() const { return fGpuTracingEnabled; } | 918 bool isGpuTracingEnabled() const { return fGpuTracingEnabled; } |
884 void enableGpuTracing() { fGpuTracingEnabled = true; } | 919 void enableGpuTracing() { fGpuTracingEnabled = true; } |
885 void disableGpuTracing() { fGpuTracingEnabled = false; } | 920 void disableGpuTracing() { fGpuTracingEnabled = false; } |
886 | 921 |
887 /** | 922 /** |
888 * Stencil buffers add themselves to the cache using addStencilBuffer. findS
tencilBuffer is | 923 * 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. | 924 * called to check the cache for a SB that matches an RT's criteria. |
890 */ | 925 */ |
891 void addStencilBuffer(GrStencilBuffer* sb); | 926 void addStencilBuffer(GrStencilBuffer* sb); |
892 GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); | 927 GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); |
893 | 928 |
894 GrPathRenderer* getPathRenderer( | 929 GrPathRenderer* getPathRenderer( |
895 const SkPath& path, | 930 const SkPath& path, |
896 const SkStrokeRec& stroke, | 931 const SkStrokeRec& stroke, |
897 const GrDrawTarget* target, | 932 const GrDrawTarget* target, |
898 bool allowSW, | 933 bool allowSW, |
899 GrPathRendererChain::DrawType drawType = GrPathRendererChain
::kColor_DrawType, | 934 GrPathRendererChain::DrawType drawType = GrPathRendererChain
::kColor_DrawType, |
900 GrPathRendererChain::StencilSupport* stencilSupport = NULL); | 935 GrPathRendererChain::StencilSupport* stencilSupport = NULL); |
901 | 936 |
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 | 937 #if GR_CACHE_STATS |
915 void printCacheStats() const; | 938 void printCacheStats() const; |
916 #endif | 939 #endif |
917 | 940 |
918 private: | 941 private: |
919 // Used to indicate whether a draw should be performed immediately or queued
in fDrawBuffer. | 942 // Used to indicate whether a draw should be performed immediately or queued
in fDrawBuffer. |
920 enum BufferedDraw { | 943 enum BufferedDraw { |
921 kYes_BufferedDraw, | 944 kYes_BufferedDraw, |
922 kNo_BufferedDraw, | 945 kNo_BufferedDraw, |
923 }; | 946 }; |
924 BufferedDraw fLastDrawWasBuffered; | 947 BufferedDraw fLastDrawWasBuffered; |
925 | 948 |
926 GrGpu* fGpu; | 949 GrGpu* fGpu; |
927 SkMatrix fViewMatrix; | 950 SkMatrix fViewMatrix; |
928 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 951 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
929 const GrClipData* fClip; // TODO: make this ref counted | 952 const GrClipData* fClip; // TODO: make this ref counted |
930 GrDrawState* fDrawState; | 953 GrDrawState* fDrawState; |
931 | 954 |
932 GrResourceCache* fTextureCache; | 955 GrResourceCache* fResourceCache; |
933 GrFontCache* fFontCache; | 956 GrFontCache* fFontCache; |
934 SkAutoTDelete<GrLayerCache> fLayerCache; | 957 SkAutoTDelete<GrLayerCache> fLayerCache; |
935 | 958 |
936 GrPathRendererChain* fPathRendererChain; | 959 GrPathRendererChain* fPathRendererChain; |
937 GrSoftwarePathRenderer* fSoftwarePathRenderer; | 960 GrSoftwarePathRenderer* fSoftwarePathRenderer; |
938 | 961 |
939 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; | 962 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; |
940 GrIndexBufferAllocPool* fDrawBufferIBAllocPool; | 963 GrIndexBufferAllocPool* fDrawBufferIBAllocPool; |
941 GrInOrderDrawBuffer* fDrawBuffer; | 964 GrInOrderDrawBuffer* fDrawBuffer; |
942 | 965 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 } | 1123 } |
1101 | 1124 |
1102 GrTexture* texture() { return fTexture; } | 1125 GrTexture* texture() { return fTexture; } |
1103 | 1126 |
1104 private: | 1127 private: |
1105 GrContext* fContext; | 1128 GrContext* fContext; |
1106 GrTexture* fTexture; | 1129 GrTexture* fTexture; |
1107 }; | 1130 }; |
1108 | 1131 |
1109 #endif | 1132 #endif |
OLD | NEW |