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

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

Issue 1107973004: Pull cache out of GrContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixpicturerenderer.cpp Created 5 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
« no previous file with comments | « gyp/gpu.gypi ('k') | include/gpu/GrTextureProvider.h » ('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
11 #include "GrClip.h" 11 #include "GrClip.h"
12 #include "GrColor.h" 12 #include "GrColor.h"
13 #include "GrPaint.h" 13 #include "GrPaint.h"
14 #include "GrPathRendererChain.h" 14 #include "GrPathRendererChain.h"
15 #include "GrRenderTarget.h" 15 #include "GrRenderTarget.h"
16 #include "GrTexture.h" 16 #include "GrTextureProvider.h"
17 #include "SkMatrix.h" 17 #include "SkMatrix.h"
18 #include "SkPathEffect.h" 18 #include "SkPathEffect.h"
19 #include "SkTypes.h" 19 #include "SkTypes.h"
20 20
21 class GrAARectRenderer; 21 class GrAARectRenderer;
22 class GrBatchFontCache; 22 class GrBatchFontCache;
23 class GrDrawTarget; 23 class GrDrawTarget;
24 class GrFragmentProcessor; 24 class GrFragmentProcessor;
25 class GrGpu; 25 class GrGpu;
26 class GrGpuTraceMarker; 26 class GrGpuTraceMarker;
27 class GrIndexBuffer; 27 class GrIndexBuffer;
28 class GrIndexBufferAllocPool; 28 class GrIndexBufferAllocPool;
29 class GrLayerCache; 29 class GrLayerCache;
30 class GrOvalRenderer; 30 class GrOvalRenderer;
31 class GrPath; 31 class GrPath;
32 class GrPathRenderer; 32 class GrPathRenderer;
33 class GrPipelineBuilder; 33 class GrPipelineBuilder;
34 class GrResourceEntry; 34 class GrResourceEntry;
35 class GrResourceCache; 35 class GrResourceCache;
36 class GrResourceProvider;
36 class GrTestTarget; 37 class GrTestTarget;
37 class GrTextBlobCache; 38 class GrTextBlobCache;
38 class GrTextContext; 39 class GrTextContext;
39 class GrTextureParams; 40 class GrTextureParams;
40 class GrVertexBuffer; 41 class GrVertexBuffer;
41 class GrVertexBufferAllocPool; 42 class GrVertexBufferAllocPool;
42 class GrStrokeInfo; 43 class GrStrokeInfo;
43 class GrSoftwarePathRenderer; 44 class GrSoftwarePathRenderer;
44 class SkGpuDevice; 45 class SkGpuDevice;
45 46
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 * be used for two reasons: 105 * be used for two reasons:
105 * 1) ~GrContext will not try to free the objects in the 3D API. 106 * 1) ~GrContext will not try to free the objects in the 3D API.
106 * 2) Any GrGpuResources created by this GrContext that outlive 107 * 2) Any GrGpuResources created by this GrContext that outlive
107 * will be marked as invalid (GrGpuResource::wasDestroyed()) and 108 * will be marked as invalid (GrGpuResource::wasDestroyed()) and
108 * when they're destroyed no 3D API calls will be made. 109 * when they're destroyed no 3D API calls will be made.
109 * Content drawn since the last GrContext::flush() may be lost. After this 110 * Content drawn since the last GrContext::flush() may be lost. After this
110 * function is called the only valid action on the GrContext or 111 * function is called the only valid action on the GrContext or
111 * GrGpuResources it created is to destroy them. 112 * GrGpuResources it created is to destroy them.
112 */ 113 */
113 void abandonContext(); 114 void abandonContext();
114 void contextDestroyed() { this->abandonContext(); } // legacy alias
115 115
116 /////////////////////////////////////////////////////////////////////////// 116 ///////////////////////////////////////////////////////////////////////////
117 // Resource Cache 117 // Resource Cache
118 118
119 /** 119 /**
120 * Return the current GPU resource cache limits. 120 * Return the current GPU resource cache limits.
121 * 121 *
122 * @param maxResources If non-null, returns maximum number of resources tha t 122 * @param maxResources If non-null, returns maximum number of resources tha t
123 * can be held in the cache. 123 * can be held in the cache.
124 * @param maxResourceBytes If non-null, returns maximum number of bytes of 124 * @param maxResourceBytes If non-null, returns maximum number of bytes of
(...skipping 15 matching lines...) Expand all
140 * Specify the GPU resource cache limits. If the current cache exceeds eith er 140 * Specify the GPU resource cache limits. If the current cache exceeds eith er
141 * of these, it will be purged (LRU) to keep the cache within these limits. 141 * of these, it will be purged (LRU) to keep the cache within these limits.
142 * 142 *
143 * @param maxResources The maximum number of resources that can be held in 143 * @param maxResources The maximum number of resources that can be held in
144 * the cache. 144 * the cache.
145 * @param maxResourceBytes The maximum number of bytes of video memory 145 * @param maxResourceBytes The maximum number of bytes of video memory
146 * that can be held in the cache. 146 * that can be held in the cache.
147 */ 147 */
148 void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); 148 void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
149 149
150 GrTextureProvider* textureProvider() { return fTextureProvider; }
151 const GrTextureProvider* textureProvider() const { return fTextureProvider; }
152
150 /** 153 /**
151 * Frees GPU created by the context. Can be called to reduce GPU memory 154 * Frees GPU created by the context. Can be called to reduce GPU memory
152 * pressure. 155 * pressure.
153 */ 156 */
154 void freeGpuResources(); 157 void freeGpuResources();
155 158
156 /** 159 /**
157 * This method should be called whenever a GrResource is unreffed or
158 * switched from exclusive to non-exclusive. This
159 * gives the resource cache a chance to discard unneeded resources.
160 * Note: this entry point will be removed once totally ref-driven
161 * cache maintenance is implemented.
162 */
163 void purgeCache();
164
165 /**
166 * Purge all the unlocked resources from the cache. 160 * Purge all the unlocked resources from the cache.
167 * This entry point is mainly meant for timing texture uploads 161 * This entry point is mainly meant for timing texture uploads
168 * and is not defined in normal builds of Skia. 162 * and is not defined in normal builds of Skia.
169 */ 163 */
170 void purgeAllUnlockedResources(); 164 void purgeAllUnlockedResources();
171 165
172 /** 166 //////////////////////////////////////////////////////////////////////////
173 * Sets a unique key on the resource. Upon key collision this resource takes the place of the 167 /// Texture and Render Target Queries
174 * previous resource that had the key.
175 */
176 void addResourceToCache(const GrUniqueKey&, GrGpuResource*);
177
178 /**
179 * Finds a resource in the cache, based on the specified key. This is intend ed for use in
180 * conjunction with addResourceToCache(). The return value will be NULL if n ot found. The
181 * caller must balance with a call to unref().
182 */
183 GrGpuResource* findAndRefCachedResource(const GrUniqueKey&);
184
185 /** Helper for casting resource to a texture. Caller must be sure that the r esource cached
186 with the key is either NULL or a texture and not another resource type. */
187 GrTexture* findAndRefCachedTexture(const GrUniqueKey& key) {
188 GrGpuResource* resource = this->findAndRefCachedResource(key);
189 if (resource) {
190 GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
191 SkASSERT(texture);
192 return texture;
193 }
194 return NULL;
195 }
196
197 /**
198 * Determines whether a resource is in the cache. If the resource is found i t
199 * will not be locked or returned. This call does not affect the priority of
200 * the resource for deletion.
201 */
202 bool isResourceInCache(const GrUniqueKey& key) const;
203
204 ///////////////////////////////////////////////////////////////////////////
205 // Textures
206
207 /**
208 * Creates a new texture in the resource cache and returns it. The caller ow ns a
209 * ref on the returned texture which must be balanced by a call to unref.
210 *
211 * @param desc Description of the texture properties.
212 * @param budgeted Does the texture count against the resource cache budget ?
213 * @param srcData Pointer to the pixel values (optional).
214 * @param rowBytes The number of bytes between rows of the texture. Zero
215 * implies tightly packed rows. For compressed pixel config s, this
216 * field is ignored.
217 */
218 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, const voi d* srcData,
219 size_t rowBytes);
220
221 GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted) {
222 return this->createTexture(desc, budgeted, NULL, 0);
223 }
224
225 /**
226 * DEPRECATED: use createTexture().
227 */
228 GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, void* srcData, s ize_t rowBytes) {
229 return this->createTexture(desc, false, srcData, rowBytes);
230 }
231
232 /**
233 * Enum that determines how closely a returned scratch texture must match
234 * a provided GrSurfaceDesc. TODO: Remove this. createTexture() should be us ed
235 * for exact match and refScratchTexture() should be replaced with createApp roxTexture().
236 */
237 enum ScratchTexMatch {
238 /**
239 * Finds a texture that exactly matches the descriptor.
240 */
241 kExact_ScratchTexMatch,
242 /**
243 * Finds a texture that approximately matches the descriptor. Will be
244 * at least as large in width and height as desc specifies. If desc
245 * specifies that texture is a render target then result will be a
246 * render target. If desc specifies a render target and doesn't set the
247 * no stencil flag then result will have a stencil. Format and aa level
248 * will always match.
249 */
250 kApprox_ScratchTexMatch
251 };
252
253 /**
254 * Returns a texture matching the desc. It's contents are unknown. The calle r
255 * owns a ref on the returned texture and must balance with a call to unref.
256 * It is guaranteed that the same texture will not be returned in subsequent
257 * calls until all refs to the texture are dropped.
258 *
259 * Textures created by createTexture() hide the complications of
260 * tiling non-power-of-two textures on APIs that don't support this (e.g.
261 * unextended GLES2). NPOT scratch textures are not tilable on such APIs.
262 *
263 * internalFlag is a temporary workaround until changes in the internal
264 * architecture are complete. Use the default value.
265 *
266 * TODO: Once internal flag can be removed, this should be replaced with
267 * createApproxTexture() and exact textures should be created with
268 * createTexture().
269 */
270 GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match,
271 bool internalFlag = false);
272 168
273 /** 169 /**
274 * Can the provided configuration act as a texture? 170 * Can the provided configuration act as a texture?
275 */ 171 */
276 bool isConfigTexturable(GrPixelConfig) const; 172 bool isConfigTexturable(GrPixelConfig) const;
277 173
278 /** 174 /**
279 * Can non-power-of-two textures be used with tile modes other than clamp? 175 * Can non-power-of-two textures be used with tile modes other than clamp?
280 */ 176 */
281 bool npotTextureTileSupport() const; 177 bool npotTextureTileSupport() const;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 * @param config the configuration of the render target. 214 * @param config the configuration of the render target.
319 * @param dpi the display density in dots per inch. 215 * @param dpi the display density in dots per inch.
320 * 216 *
321 * @return sample count that should be perform well and have good enough 217 * @return sample count that should be perform well and have good enough
322 * rendering quality for the display. Alternatively returns 0 if 218 * rendering quality for the display. Alternatively returns 0 if
323 * MSAA is not supported or recommended to be used by default. 219 * MSAA is not supported or recommended to be used by default.
324 */ 220 */
325 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; 221 int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
326 222
327 /////////////////////////////////////////////////////////////////////////// 223 ///////////////////////////////////////////////////////////////////////////
328 // Backend Surfaces
329
330 /**
331 * Wraps an existing texture with a GrTexture object.
332 *
333 * OpenGL: if the object is a texture Gr may change its GL texture params
334 * when it is drawn.
335 *
336 * @param desc description of the object to create.
337 *
338 * @return GrTexture object or NULL on failure.
339 */
340 GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc);
341
342 /**
343 * Wraps an existing render target with a GrRenderTarget object. It is
344 * similar to wrapBackendTexture but can be used to draw into surfaces
345 * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
346 * the client will resolve to a texture).
347 *
348 * @param desc description of the object to create.
349 *
350 * @return GrTexture object or NULL on failure.
351 */
352 GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& de sc);
353
354 ///////////////////////////////////////////////////////////////////////////
355 // Draws 224 // Draws
356 225
357 /** 226 /**
358 * Clear the entire or rect of the render target, ignoring any clips. 227 * Clear the entire or rect of the render target, ignoring any clips.
359 * @param rect the rect to clear or the whole thing if rect is NULL. 228 * @param rect the rect to clear or the whole thing if rect is NULL.
360 * @param color the color to clear to. 229 * @param color the color to clear to.
361 * @param canIgnoreRect allows partial clears to be converted to whole 230 * @param canIgnoreRect allows partial clears to be converted to whole
362 * clears on platforms for which that is cheap 231 * clears on platforms for which that is cheap
363 * @param target The render target to clear. 232 * @param target The render target to clear.
364 */ 233 */
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 */ 508 */
640 void prepareSurfaceForExternalRead(GrSurface*); 509 void prepareSurfaceForExternalRead(GrSurface*);
641 510
642 /** 511 /**
643 * Provides a perfomance hint that the render target's contents are allowed 512 * Provides a perfomance hint that the render target's contents are allowed
644 * to become undefined. 513 * to become undefined.
645 */ 514 */
646 void discardRenderTarget(GrRenderTarget*); 515 void discardRenderTarget(GrRenderTarget*);
647 516
648 /////////////////////////////////////////////////////////////////////////// 517 ///////////////////////////////////////////////////////////////////////////
518 // Legacy functions, to be removed once Chromium stops using them.
519
520 enum ScratchTexMatch {
521 kExact_ScratchTexMatch = GrTextureProvider::kExact_ScratchTexMatch,
522 kApprox_ScratchTexMatch = GrTextureProvider::kApprox_ScratchTexMatch
523 };
524
525 GrTexture* refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMatch matc h) {
526 return this->textureProvider()->refScratchTexture(
527 desc, (GrTextureProvider::ScratchTexMatch) match);
528 }
529
530 GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc) {
531 return this->textureProvider()->wrapBackendTexture(desc);
532 }
533
534 ///////////////////////////////////////////////////////////////////////////
649 // Functions intended for internal use only. 535 // Functions intended for internal use only.
650 GrGpu* getGpu() { return fGpu; } 536 GrGpu* getGpu() { return fGpu; }
651 const GrGpu* getGpu() const { return fGpu; } 537 const GrGpu* getGpu() const { return fGpu; }
652 GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; } 538 GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; }
653 GrLayerCache* getLayerCache() { return fLayerCache.get(); } 539 GrLayerCache* getLayerCache() { return fLayerCache.get(); }
654 GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; } 540 GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; }
655 GrDrawTarget* getTextTarget(); 541 GrDrawTarget* getTextTarget();
656 const GrIndexBuffer* getQuadIndexBuffer() const; 542 const GrIndexBuffer* getQuadIndexBuffer() const;
657 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } 543 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; }
544 GrResourceProvider* resourceProvider() { return fResourceProvider; }
545 const GrResourceProvider* resourceProvider() const { return fResourceProvide r; }
658 GrResourceCache* getResourceCache() { return fResourceCache; } 546 GrResourceCache* getResourceCache() { return fResourceCache; }
659 547
660 // Called by tests that draw directly to the context via GrDrawTarget 548 // Called by tests that draw directly to the context via GrDrawTarget
661 void getTestTarget(GrTestTarget*); 549 void getTestTarget(GrTestTarget*);
662 550
663 void addGpuTraceMarker(const GrGpuTraceMarker* marker); 551 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
664 void removeGpuTraceMarker(const GrGpuTraceMarker* marker); 552 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
665 553
666 GrPathRenderer* getPathRenderer( 554 GrPathRenderer* getPathRenderer(
667 const GrDrawTarget* target, 555 const GrDrawTarget* target,
(...skipping 14 matching lines...) Expand all
682 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ 570 /** Prints cache stats to the string if GR_CACHE_STATS == 1. */
683 void dumpCacheStats(SkString*) const; 571 void dumpCacheStats(SkString*) const;
684 void printCacheStats() const; 572 void printCacheStats() const;
685 573
686 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ 574 /** Prints GPU stats to the string if GR_GPU_STATS == 1. */
687 void dumpGpuStats(SkString*) const; 575 void dumpGpuStats(SkString*) const;
688 void printGpuStats() const; 576 void printGpuStats() const;
689 577
690 private: 578 private:
691 GrGpu* fGpu; 579 GrGpu* fGpu;
580 GrResourceCache* fResourceCache;
581 // this union exists because the inheritance of GrTextureProvider->GrResourc eProvider
582 // is in a private header.
583 union {
584 GrResourceProvider* fResourceProvider;
585 GrTextureProvider* fTextureProvider;
586 };
692 587
693 GrResourceCache* fResourceCache;
694 GrBatchFontCache* fBatchFontCache; 588 GrBatchFontCache* fBatchFontCache;
695 SkAutoTDelete<GrLayerCache> fLayerCache; 589 SkAutoTDelete<GrLayerCache> fLayerCache;
696 SkAutoTDelete<GrTextBlobCache> fTextBlobCache; 590 SkAutoTDelete<GrTextBlobCache> fTextBlobCache;
697 591
698 GrPathRendererChain* fPathRendererChain; 592 GrPathRendererChain* fPathRendererChain;
699 GrSoftwarePathRenderer* fSoftwarePathRenderer; 593 GrSoftwarePathRenderer* fSoftwarePathRenderer;
700 594
701 GrVertexBufferAllocPool* fDrawBufferVBAllocPool; 595 GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
702 GrIndexBufferAllocPool* fDrawBufferIBAllocPool; 596 GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
703 GrDrawTarget* fDrawBuffer; 597 GrDrawTarget* fDrawBuffer;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 GrDrawTarget* prepareToDraw(); 635 GrDrawTarget* prepareToDraw();
742 636
743 void internalDrawPath(GrDrawTarget*, 637 void internalDrawPath(GrDrawTarget*,
744 GrPipelineBuilder*, 638 GrPipelineBuilder*,
745 const SkMatrix& viewMatrix, 639 const SkMatrix& viewMatrix,
746 GrColor, 640 GrColor,
747 bool useAA, 641 bool useAA,
748 const SkPath&, 642 const SkPath&,
749 const GrStrokeInfo&); 643 const GrStrokeInfo&);
750 644
751 GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags);
752
753 /** 645 /**
754 * Creates a new text rendering context that is optimal for the 646 * Creates a new text rendering context that is optimal for the
755 * render target and the context. Caller assumes the ownership 647 * render target and the context. Caller assumes the ownership
756 * of the returned object. The returned object must be deleted 648 * of the returned object. The returned object must be deleted
757 * before the context is destroyed. 649 * before the context is destroyed.
758 * TODO we can possibly bury this behind context, but we need to be able to use the 650 * TODO we can possibly bury this behind context, but we need to be able to use the
759 * drawText_asPaths logic on SkGpuDevice 651 * drawText_asPaths logic on SkGpuDevice
760 */ 652 */
761 GrTextContext* createTextContext(GrRenderTarget*, 653 GrTextContext* createTextContext(GrRenderTarget*,
762 SkGpuDevice*, 654 SkGpuDevice*,
(...skipping 21 matching lines...) Expand all
784 */ 676 */
785 static void TextBlobCacheOverBudgetCB(void* data); 677 static void TextBlobCacheOverBudgetCB(void* data);
786 678
787 // TODO see note on createTextContext 679 // TODO see note on createTextContext
788 friend class SkGpuDevice; 680 friend class SkGpuDevice;
789 681
790 typedef SkRefCnt INHERITED; 682 typedef SkRefCnt INHERITED;
791 }; 683 };
792 684
793 #endif 685 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | include/gpu/GrTextureProvider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698